From 8a43fe6ff70982480abec178ba3fac017e437009 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 28 May 2006 13:04:16 +0000 Subject: [PATCH] Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation. --- .indent.pro | 1 + Makefile.in | 9 + UNDER_CONSTRUCTION.txt | 1 + include/SDL.h | 72 +- include/SDL_active.h | 58 - include/SDL_audio.h | 137 +- include/SDL_byteorder.h | 24 - include/SDL_cdrom.h | 84 +- include/SDL_compat.h | 126 + include/SDL_config_macos.h | 18 +- include/SDL_config_os2.h | 20 +- include/SDL_config_win32.h | 20 +- include/SDL_copying.h | 1 - include/SDL_cpuinfo.h | 29 +- include/SDL_endian.h | 147 +- include/SDL_error.h | 34 +- include/SDL_events.h | 418 +- include/SDL_getenv.h | 24 - include/SDL_joystick.h | 48 +- include/SDL_keyboard.h | 37 +- include/SDL_keysym.h | 530 +- include/SDL_loadso.h | 48 +- include/SDL_main.h | 21 +- include/SDL_mouse.h | 47 +- include/SDL_mutex.h | 51 +- include/SDL_opengl.h | 7853 ++++++++++++----- include/SDL_pixels.h | 240 + include/SDL_quit.h | 6 +- include/SDL_rwops.h | 151 +- include/SDL_stdinc.h | 226 +- include/SDL_syswm.h | 195 +- include/SDL_thread.h | 65 +- include/SDL_timer.h | 34 +- include/SDL_version.h | 93 +- include/SDL_video.h | 1032 ++- include/begin_code.h | 4 +- include/close_code.h | 1 - include/doxyfile | 1229 +++ src/SDL.c | 374 +- src/SDL_error.c | 347 +- src/SDL_error_c.h | 45 +- src/SDL_fatal.c | 126 +- src/SDL_fatal.h | 6 +- src/audio/SDL_audio.c | 1136 +-- src/audio/SDL_audio_c.h | 9 +- src/audio/SDL_audiocvt.c | 2762 +++--- src/audio/SDL_audiodev.c | 198 +- src/audio/SDL_audiodev_c.h | 4 +- src/audio/SDL_audiomem.h | 1 + src/audio/SDL_mixer.c | 371 +- src/audio/SDL_mixer_MMX.c | 226 +- src/audio/SDL_mixer_MMX.h | 6 +- src/audio/SDL_mixer_MMX_VC.c | 230 +- src/audio/SDL_mixer_MMX_VC.h | 5 +- src/audio/SDL_mixer_m68k.c | 267 +- src/audio/SDL_mixer_m68k.h | 10 +- src/audio/SDL_sysaudio.h | 123 +- src/audio/SDL_wave.c | 1078 +-- src/audio/SDL_wave.h | 38 +- src/audio/alsa/SDL_alsa_audio.c | 859 +- src/audio/alsa/SDL_alsa_audio.h | 18 +- src/audio/amigaos/SDL_ahiaudio.c | 536 +- src/audio/amigaos/SDL_ahiaudio.h | 18 +- src/audio/arts/SDL_artsaudio.c | 462 +- src/audio/arts/SDL_artsaudio.h | 27 +- src/audio/baudio/SDL_beaudio.cc | 332 +- src/audio/baudio/SDL_beaudio.h | 6 +- src/audio/bsd/SDL_bsdaudio.c | 466 +- src/audio/bsd/SDL_bsdaudio.h | 5 +- src/audio/dart/SDL_dart.c | 653 +- src/audio/dart/SDL_dart.h | 31 +- src/audio/dc/SDL_dcaudio.c | 335 +- src/audio/dc/SDL_dcaudio.h | 16 +- src/audio/dc/aica.c | 308 +- src/audio/dc/aica.h | 14 +- src/audio/disk/SDL_diskaudio.c | 201 +- src/audio/disk/SDL_diskaudio.h | 14 +- src/audio/dma/SDL_dmaaudio.c | 704 +- src/audio/dma/SDL_dmaaudio.h | 34 +- src/audio/dmedia/SDL_irixaudio.c | 279 +- src/audio/dmedia/SDL_irixaudio.h | 10 +- src/audio/dsp/SDL_dspaudio.c | 462 +- src/audio/dsp/SDL_dspaudio.h | 20 +- src/audio/dummy/SDL_dummyaudio.c | 183 +- src/audio/dummy/SDL_dummyaudio.h | 14 +- src/audio/esd/SDL_esdaudio.c | 443 +- src/audio/esd/SDL_esdaudio.h | 26 +- src/audio/macosx/SDL_coreaudio.c | 202 +- src/audio/macosx/SDL_coreaudio.h | 12 +- src/audio/macrom/SDL_romaudio.c | 480 +- src/audio/macrom/SDL_romaudio.h | 14 +- src/audio/mint/SDL_mintaudio.c | 257 +- src/audio/mint/SDL_mintaudio.h | 138 +- src/audio/mint/SDL_mintaudio_dma8.c | 418 +- src/audio/mint/SDL_mintaudio_dma8.h | 98 +- src/audio/mint/SDL_mintaudio_gsxb.c | 540 +- src/audio/mint/SDL_mintaudio_gsxb.h | 15 +- src/audio/mint/SDL_mintaudio_mcsn.c | 528 +- src/audio/mint/SDL_mintaudio_mcsn.h | 49 +- src/audio/mint/SDL_mintaudio_stfa.c | 358 +- src/audio/mint/SDL_mintaudio_stfa.h | 93 +- src/audio/mint/SDL_mintaudio_xbios.c | 677 +- src/audio/mme/SDL_mmeaudio.c | 266 +- src/audio/mme/SDL_mmeaudio.h | 9 +- src/audio/nas/SDL_nasaudio.c | 424 +- src/audio/nas/SDL_nasaudio.h | 37 +- src/audio/nto/SDL_nto_audio.c | 427 +- src/audio/nto/SDL_nto_audio.h | 7 +- src/audio/paudio/SDL_paudio.c | 756 +- src/audio/paudio/SDL_paudio.h | 26 +- src/audio/sun/SDL_sunaudio.c | 612 +- src/audio/sun/SDL_sunaudio.h | 24 +- src/audio/ums/SDL_umsaudio.c | 552 +- src/audio/ums/SDL_umsaudio.h | 4 +- src/audio/windib/SDL_dibaudio.c | 439 +- src/audio/windib/SDL_dibaudio.h | 18 +- src/audio/windx5/SDL_dx5audio.c | 1123 +-- src/audio/windx5/SDL_dx5audio.h | 18 +- src/audio/windx5/directx.h | 1 + src/cdrom/SDL_cdrom.c | 521 +- src/cdrom/SDL_syscdrom.h | 59 +- src/cdrom/aix/SDL_syscdrom.c | 801 +- src/cdrom/beos/SDL_syscdrom.cc | 577 +- src/cdrom/bsdi/SDL_syscdrom.c | 838 +- src/cdrom/dc/SDL_syscdrom.c | 194 +- src/cdrom/dummy/SDL_syscdrom.c | 11 +- src/cdrom/freebsd/SDL_syscdrom.c | 601 +- src/cdrom/linux/SDL_syscdrom.c | 770 +- src/cdrom/macos/SDL_syscdrom.c | 862 +- src/cdrom/macos/SDL_syscdrom_c.h | 170 +- src/cdrom/macosx/AudioFilePlayer.c | 313 +- src/cdrom/macosx/AudioFilePlayer.h | 167 +- src/cdrom/macosx/AudioFileReaderThread.c | 623 +- src/cdrom/macosx/CDPlayer.c | 640 +- src/cdrom/macosx/CDPlayer.h | 29 +- src/cdrom/macosx/SDLOSXCAGuard.c | 117 +- src/cdrom/macosx/SDLOSXCAGuard.h | 20 +- src/cdrom/macosx/SDL_syscdrom.c | 355 +- src/cdrom/macosx/SDL_syscdrom_c.h | 2 +- src/cdrom/mint/SDL_syscdrom.c | 432 +- src/cdrom/openbsd/SDL_syscdrom.c | 604 +- src/cdrom/os2/SDL_syscdrom.c | 564 +- src/cdrom/osf/SDL_syscdrom.c | 521 +- src/cdrom/qnx/SDL_syscdrom.c | 506 +- src/cdrom/win32/SDL_syscdrom.c | 541 +- src/cpuinfo/SDL_cpuinfo.c | 549 +- src/events/SDL_active.c | 91 - src/events/SDL_events.c | 703 +- src/events/SDL_events_c.h | 56 +- src/events/SDL_keyboard.c | 997 ++- src/events/SDL_mouse.c | 404 +- src/events/SDL_quit.c | 85 +- src/events/SDL_resize.c | 75 - src/events/SDL_sysevents.h | 11 +- .../{SDL_expose.c => SDL_windowevents.c} | 45 +- src/file/SDL_rwops.c | 850 +- src/hermes/HeadMMX.h | 71 +- src/hermes/HeadX86.h | 177 +- src/joystick/SDL_joystick.c | 807 +- src/joystick/SDL_joystick_c.h | 17 +- src/joystick/SDL_sysjoystick.h | 60 +- src/joystick/amigaos/SDL_sysjoystick.c | 246 +- src/joystick/beos/SDL_bejoystick.cc | 338 +- src/joystick/bsd/SDL_sysjoystick.c | 812 +- src/joystick/darwin/SDL_sysjoystick.c | 1256 +-- src/joystick/dc/SDL_sysjoystick.c | 237 +- src/joystick/dummy/SDL_sysjoystick.c | 37 +- src/joystick/linux/SDL_sysjoystick.c | 1771 ++-- src/joystick/macos/SDL_sysjoystick.c | 263 +- src/joystick/mint/SDL_sysjoystick.c | 1003 ++- src/joystick/os2/SDL_sysjoystick.c | 947 +- src/joystick/os2/joyos2.h | 98 +- src/joystick/riscos/SDL_sysjoystick.c | 172 +- src/joystick/win32/SDL_dxjoystick.c | 803 +- src/joystick/win32/SDL_mmjoystick.c | 632 +- src/loadso/beos/SDL_sysloadso.c | 66 +- src/loadso/dlopen/SDL_sysloadso.c | 55 +- src/loadso/dummy/SDL_sysloadso.c | 22 +- src/loadso/macos/SDL_sysloadso.c | 116 +- src/loadso/macosx/SDL_dlcompat.c | 1940 ++-- src/loadso/mint/SDL_sysloadso.c | 40 +- src/loadso/os2/SDL_sysloadso.c | 27 +- src/loadso/win32/SDL_sysloadso.c | 183 +- src/main/beos/SDL_BeApp.cc | 122 +- src/main/beos/SDL_BeApp.h | 5 +- src/main/dummy/SDL_dummy_main.c | 6 +- src/main/macos/SDL_main.c | 776 +- src/main/macosx/SDLMain.h | 4 +- src/main/macosx/SDLMain.m | 317 +- src/main/qtopia/SDL_qtopia_main.cc | 47 +- src/main/win32/SDL_win32_main.c | 454 +- src/stdlib/SDL_getenv.c | 370 +- src/stdlib/SDL_iconv.c | 1486 ++-- src/stdlib/SDL_malloc.c | 4125 ++++----- src/stdlib/SDL_qsort.c | 290 +- src/stdlib/SDL_stdlib.c | 890 +- src/stdlib/SDL_string.c | 1072 +-- src/thread/SDL_systhread.h | 13 +- src/thread/SDL_thread.c | 419 +- src/thread/SDL_thread_c.h | 16 +- src/thread/amigaos/SDL_syssem.c | 164 +- src/thread/amigaos/SDL_systhread.c | 168 +- src/thread/amigaos/SDL_systhread_c.h | 4 +- src/thread/amigaos/SDL_thread.c | 391 +- src/thread/beos/SDL_syssem.c | 176 +- src/thread/beos/SDL_systhread.c | 81 +- src/thread/beos/SDL_systhread_c.h | 6 +- src/thread/dc/SDL_syscond.c | 284 +- src/thread/dc/SDL_syscond_c.h | 2 +- src/thread/dc/SDL_sysmutex.c | 145 +- src/thread/dc/SDL_sysmutex_c.h | 2 +- src/thread/dc/SDL_syssem.c | 160 +- src/thread/dc/SDL_syssem_c.h | 2 +- src/thread/dc/SDL_systhread.c | 37 +- src/thread/dc/SDL_systhread_c.h | 3 +- src/thread/epoc/SDL_systhread_c.h | 2 +- src/thread/generic/SDL_syscond.c | 284 +- src/thread/generic/SDL_sysmutex.c | 161 +- src/thread/generic/SDL_sysmutex_c.h | 2 +- src/thread/generic/SDL_syssem.c | 265 +- src/thread/generic/SDL_systhread.c | 28 +- src/thread/generic/SDL_systhread_c.h | 1 + src/thread/irix/SDL_syssem.c | 261 +- src/thread/irix/SDL_systhread.c | 62 +- src/thread/irix/SDL_systhread_c.h | 2 +- src/thread/os2/SDL_syscond.c | 284 +- src/thread/os2/SDL_syscond_c.h | 2 +- src/thread/os2/SDL_sysmutex.c | 111 +- src/thread/os2/SDL_syssem.c | 244 +- src/thread/os2/SDL_systhread.c | 105 +- src/thread/os2/SDL_systhread_c.h | 2 +- src/thread/pth/SDL_syscond.c | 165 +- src/thread/pth/SDL_sysmutex.c | 74 +- src/thread/pth/SDL_sysmutex_c.h | 6 +- src/thread/pth/SDL_systhread.c | 98 +- src/thread/pth/SDL_systhread_c.h | 1 + src/thread/pthread/SDL_syscond.c | 196 +- src/thread/pthread/SDL_sysmutex.c | 179 +- src/thread/pthread/SDL_sysmutex_c.h | 6 +- src/thread/pthread/SDL_syssem.c | 198 +- src/thread/pthread/SDL_systhread.c | 106 +- src/thread/pthread/SDL_systhread_c.h | 1 + src/thread/riscos/SDL_syscond.c | 195 +- src/thread/riscos/SDL_sysmutex.c | 176 +- src/thread/riscos/SDL_sysmutex_c.h | 6 +- src/thread/riscos/SDL_syssem.c | 249 +- src/thread/riscos/SDL_systhread.c | 139 +- src/thread/riscos/SDL_systhread_c.h | 1 + src/thread/win32/SDL_sysmutex.c | 99 +- src/thread/win32/SDL_syssem.c | 186 +- src/thread/win32/SDL_systhread.c | 165 +- src/thread/win32/SDL_systhread_c.h | 2 +- src/thread/win32/win_ce_semaphore.c | 308 +- src/thread/win32/win_ce_semaphore.h | 21 +- src/timer/SDL_systimer.h | 9 +- src/timer/SDL_timer.c | 397 +- src/timer/SDL_timer_c.h | 9 +- src/timer/amigaos/SDL_systimer.c | 258 +- src/timer/beos/SDL_systimer.c | 73 +- src/timer/dc/SDL_systimer.c | 73 +- src/timer/dummy/SDL_systimer.c | 71 +- src/timer/macos/FastTimes.c | 438 +- src/timer/macos/FastTimes.h | 9 +- src/timer/macos/SDL_MPWtimer.c | 135 +- src/timer/macos/SDL_systimer.c | 141 +- src/timer/mint/SDL_systimer.c | 139 +- src/timer/mint/SDL_vbltimer_s.h | 5 +- src/timer/os2/SDL_systimer.c | 283 +- src/timer/riscos/SDL_systimer.c | 210 +- src/timer/unix/SDL_systimer.c | 229 +- src/timer/win32/SDL_systimer.c | 147 +- src/timer/wince/SDL_systimer.c | 201 +- src/video/SDL_RLEaccel.c | 1295 +-- src/video/SDL_RLEaccel_c.h | 13 +- src/video/SDL_blit.c | 572 +- src/video/SDL_blit.h | 72 +- src/video/SDL_blit_0.c | 822 +- src/video/SDL_blit_1.c | 680 +- src/video/SDL_blit_A.c | 2448 ++--- src/video/SDL_blit_N.c | 3332 +++---- src/video/SDL_bmp.c | 922 +- src/video/SDL_cursor.c | 1295 +-- src/video/SDL_cursor_c.h | 27 +- src/video/SDL_gamma.c | 350 +- src/video/SDL_glfuncs.h | 790 +- src/video/SDL_leaks.h | 1 + src/video/SDL_pixels.c | 1209 +-- src/video/SDL_pixels_c.h | 32 +- src/video/SDL_stretch.c | 449 +- src/video/SDL_stretch_c.h | 6 +- src/video/SDL_surface.c | 1620 ++-- src/video/SDL_sysvideo.h | 534 +- src/video/SDL_video.c | 2888 +++--- src/video/SDL_yuv.c | 194 +- src/video/SDL_yuv_mmx.c | 585 +- src/video/SDL_yuv_sw.c | 1556 ++-- src/video/SDL_yuv_sw_c.h | 13 +- src/video/SDL_yuvfuncs.h | 13 +- src/video/Xext/XME/xme.c | 505 +- src/video/Xext/Xinerama/Xinerama.c | 259 +- src/video/Xext/Xv/Xv.c | 1820 ++-- src/video/Xext/Xv/Xvlibint.h | 3 +- src/video/Xext/Xxf86dga/XF86DGA.c | 571 +- src/video/Xext/Xxf86dga/XF86DGA2.c | 1060 ++- src/video/Xext/Xxf86vm/XF86VMode.c | 1493 ++-- src/video/Xext/extensions/Xext.h | 20 +- src/video/Xext/extensions/Xinerama.h | 40 +- src/video/Xext/extensions/Xv.h | 2 +- src/video/Xext/extensions/Xvlib.h | 614 +- src/video/Xext/extensions/Xvproto.h | 814 +- src/video/Xext/extensions/extutil.h | 186 +- src/video/Xext/extensions/panoramiXext.h | 30 +- src/video/Xext/extensions/panoramiXproto.h | 238 +- src/video/Xext/extensions/xf86dga.h | 346 +- src/video/Xext/extensions/xf86dga1.h | 158 +- src/video/Xext/extensions/xf86dga1str.h | 274 +- src/video/Xext/extensions/xf86dgastr.h | 510 +- src/video/Xext/extensions/xf86vmode.h | 394 +- src/video/Xext/extensions/xf86vmstr.h | 817 +- src/video/Xext/extensions/xme.h | 41 +- src/video/aalib/SDL_aaevents.c | 317 +- src/video/aalib/SDL_aaevents_c.h | 13 +- src/video/aalib/SDL_aamouse.c | 6 +- src/video/aalib/SDL_aamouse_c.h | 1 + src/video/aalib/SDL_aavideo.c | 554 +- src/video/aalib/SDL_aavideo.h | 14 +- src/video/ataricommon/SDL_ataric2p_s.h | 51 +- src/video/ataricommon/SDL_ataridevmouse.c | 211 +- src/video/ataricommon/SDL_ataridevmouse_c.h | 7 +- src/video/ataricommon/SDL_atarieddi_s.h | 23 +- src/video/ataricommon/SDL_atarievents.c | 218 +- src/video/ataricommon/SDL_atarievents_c.h | 7 +- src/video/ataricommon/SDL_atarigl.c | 1843 ++-- src/video/ataricommon/SDL_atarigl_c.h | 90 +- src/video/ataricommon/SDL_atarikeys.h | 3 +- src/video/ataricommon/SDL_atarimxalloc.c | 28 +- src/video/ataricommon/SDL_atarimxalloc_c.h | 3 +- src/video/ataricommon/SDL_biosevents.c | 271 +- src/video/ataricommon/SDL_biosevents_c.h | 7 +- src/video/ataricommon/SDL_gemdosevents.c | 276 +- src/video/ataricommon/SDL_gemdosevents_c.h | 7 +- src/video/ataricommon/SDL_ikbdevents.c | 362 +- src/video/ataricommon/SDL_ikbdevents_c.h | 7 +- src/video/ataricommon/SDL_ikbdinterrupt_s.h | 19 +- src/video/ataricommon/SDL_xbiosevents.c | 171 +- src/video/ataricommon/SDL_xbiosevents_c.h | 7 +- src/video/ataricommon/SDL_xbiosinterrupt_s.h | 20 +- src/video/blank_cursor.h | 1 + src/video/bwindow/SDL_BView.h | 161 +- src/video/bwindow/SDL_BWin.h | 1013 ++- src/video/bwindow/SDL_lowvideo.h | 24 +- src/video/bwindow/SDL_sysevents.cc | 19 +- src/video/bwindow/SDL_sysevents_c.h | 5 +- src/video/bwindow/SDL_sysmouse.cc | 205 +- src/video/bwindow/SDL_sysmouse_c.h | 13 +- src/video/bwindow/SDL_sysvideo.cc | 1484 ++-- src/video/bwindow/SDL_syswm.cc | 40 +- src/video/bwindow/SDL_syswm_c.h | 7 +- src/video/bwindow/SDL_sysyuv.cc | 517 +- src/video/bwindow/SDL_sysyuv.h | 35 +- src/video/cybergfx/SDL_amigaevents.c | 751 +- src/video/cybergfx/SDL_amigaevents_c.h | 6 +- src/video/cybergfx/SDL_amigamouse.c | 59 +- src/video/cybergfx/SDL_amigamouse_c.h | 14 +- src/video/cybergfx/SDL_cgxaccel.c | 416 +- src/video/cybergfx/SDL_cgxgl.c | 301 +- src/video/cybergfx/SDL_cgxgl_c.h | 24 +- src/video/cybergfx/SDL_cgximage.c | 1580 ++-- src/video/cybergfx/SDL_cgximage_c.h | 23 +- src/video/cybergfx/SDL_cgxmodes.c | 383 +- src/video/cybergfx/SDL_cgxmodes_c.h | 14 +- src/video/cybergfx/SDL_cgxvideo.c | 2374 ++--- src/video/cybergfx/SDL_cgxvideo.h | 79 +- src/video/cybergfx/SDL_cgxwm.c | 34 +- src/video/cybergfx/SDL_cgxwm_c.h | 14 +- src/video/dc/SDL_dcevents.c | 218 +- src/video/dc/SDL_dcevents_c.h | 6 +- src/video/dc/SDL_dcmouse.c | 6 +- src/video/dc/SDL_dcmouse_c.h | 1 + src/video/dc/SDL_dcvideo.c | 613 +- src/video/dc/SDL_dcvideo.h | 4 +- src/video/default_cursor.h | 141 +- src/video/dga/SDL_dgaevents.c | 213 +- src/video/dga/SDL_dgaevents_c.h | 5 +- src/video/dga/SDL_dgamouse.c | 6 +- src/video/dga/SDL_dgamouse_c.h | 1 + src/video/dga/SDL_dgavideo.c | 1847 ++-- src/video/dga/SDL_dgavideo.h | 81 +- src/video/directfb/SDL_DirectFB_events.c | 282 +- src/video/directfb/SDL_DirectFB_events.h | 6 +- src/video/directfb/SDL_DirectFB_keys.h | 14 +- src/video/directfb/SDL_DirectFB_video.c | 1653 ++-- src/video/directfb/SDL_DirectFB_video.h | 37 +- src/video/directfb/SDL_DirectFB_yuv.c | 340 +- src/video/directfb/SDL_DirectFB_yuv.h | 15 +- src/video/dummy/SDL_nullevents.c | 12 +- src/video/dummy/SDL_nullevents_c.h | 6 +- src/video/dummy/SDL_nullmouse.c | 6 +- src/video/dummy/SDL_nullmouse_c.h | 1 + src/video/dummy/SDL_nullvideo.c | 282 +- src/video/dummy/SDL_nullvideo.h | 6 +- src/video/e_log.h | 135 +- src/video/e_pow.h | 447 +- src/video/e_sqrt.h | 265 +- src/video/epoc/SDL_epocevents_c.h | 12 +- src/video/epoc/SDL_epocvideo.h | 68 +- src/video/fbcon/3dfx_mmio.h | 2 +- src/video/fbcon/3dfx_regs.h | 2 +- src/video/fbcon/SDL_fb3dfx.c | 341 +- src/video/fbcon/SDL_fb3dfx.h | 3 +- src/video/fbcon/SDL_fbelo.c | 562 +- src/video/fbcon/SDL_fbelo.h | 13 +- src/video/fbcon/SDL_fbevents.c | 2251 ++--- src/video/fbcon/SDL_fbevents_c.h | 19 +- src/video/fbcon/SDL_fbkeys.h | 14 +- src/video/fbcon/SDL_fbmatrox.c | 450 +- src/video/fbcon/SDL_fbmatrox.h | 3 +- src/video/fbcon/SDL_fbmouse.c | 6 +- src/video/fbcon/SDL_fbmouse_c.h | 1 + src/video/fbcon/SDL_fbriva.c | 321 +- src/video/fbcon/SDL_fbriva.h | 3 +- src/video/fbcon/SDL_fbvideo.c | 2887 +++--- src/video/fbcon/SDL_fbvideo.h | 147 +- src/video/fbcon/matrox_mmio.h | 2 +- src/video/fbcon/matrox_regs.h | 10 +- src/video/fbcon/riva_mmio.h | 98 +- src/video/fbcon/riva_regs.h | 2 +- src/video/gapi/SDL_gapivideo.c | 1994 +++-- src/video/gapi/SDL_gapivideo.h | 150 +- src/video/gem/SDL_gemevents.c | 732 +- src/video/gem/SDL_gemevents_c.h | 6 +- src/video/gem/SDL_gemmouse.c | 182 +- src/video/gem/SDL_gemmouse_c.h | 14 +- src/video/gem/SDL_gemvideo.c | 2136 ++--- src/video/gem/SDL_gemvideo.h | 106 +- src/video/gem/SDL_gemwm.c | 111 +- src/video/gem/SDL_gemwm_c.h | 9 +- src/video/ggi/SDL_ggievents.c | 408 +- src/video/ggi/SDL_ggievents_c.h | 6 +- src/video/ggi/SDL_ggikeys.h | 14 +- src/video/ggi/SDL_ggimouse.c | 6 +- src/video/ggi/SDL_ggimouse_c.h | 1 + src/video/ggi/SDL_ggivideo.c | 576 +- src/video/ggi/SDL_ggivideo.h | 13 +- src/video/glsdl/SDL_glsdl.c | 3902 ++++---- src/video/glsdl/SDL_glsdl.h | 1 + src/video/ipod/SDL_ipodvideo.c | 885 +- src/video/ipod/SDL_ipodvideo.h | 4 +- src/video/maccommon/SDL_lowvideo.h | 46 +- src/video/maccommon/SDL_macevents.c | 1220 +-- src/video/maccommon/SDL_macevents_c.h | 9 +- src/video/maccommon/SDL_macgl.c | 262 +- src/video/maccommon/SDL_macgl_c.h | 20 +- src/video/maccommon/SDL_mackeys.h | 5 +- src/video/maccommon/SDL_macmouse.c | 137 +- src/video/maccommon/SDL_macmouse_c.h | 12 +- src/video/maccommon/SDL_macwm.c | 17 +- src/video/maccommon/SDL_macwm_c.h | 4 +- src/video/macdsp/SDL_dspvideo.c | 2165 ++--- src/video/macdsp/SDL_dspvideo.h | 26 +- src/video/macrom/SDL_romvideo.c | 1156 +-- src/video/macrom/SDL_romvideo.h | 1 + src/video/math_private.h | 43 +- src/video/mmx.h | 274 +- src/video/nanox/SDL_nxevents.c | 449 +- src/video/nanox/SDL_nxevents_c.h | 5 +- src/video/nanox/SDL_nximage.c | 231 +- src/video/nanox/SDL_nximage_c.h | 11 +- src/video/nanox/SDL_nxmodes.c | 62 +- src/video/nanox/SDL_nxmodes_c.h | 10 +- src/video/nanox/SDL_nxmouse.c | 64 +- src/video/nanox/SDL_nxmouse_c.h | 10 +- src/video/nanox/SDL_nxvideo.c | 643 +- src/video/nanox/SDL_nxvideo.h | 49 +- src/video/nanox/SDL_nxwm.c | 40 +- src/video/nanox/SDL_nxwm_c.h | 5 +- src/video/os2fslib/SDL_os2fslib.c | 4744 +++++----- src/video/os2fslib/SDL_os2fslib.h | 39 +- src/video/os2fslib/SDL_vkeys.h | 1 + src/video/photon/SDL_ph_events.c | 731 +- src/video/photon/SDL_ph_events_c.h | 5 +- src/video/photon/SDL_ph_gl.c | 409 +- src/video/photon/SDL_ph_gl.h | 16 +- src/video/photon/SDL_ph_image.c | 1181 ++- src/video/photon/SDL_ph_image_c.h | 51 +- src/video/photon/SDL_ph_modes.c | 321 +- src/video/photon/SDL_ph_modes_c.h | 18 +- src/video/photon/SDL_ph_mouse.c | 186 +- src/video/photon/SDL_ph_mouse_c.h | 18 +- src/video/photon/SDL_ph_video.c | 674 +- src/video/photon/SDL_ph_video.h | 99 +- src/video/photon/SDL_ph_wm.c | 81 +- src/video/photon/SDL_ph_wm_c.h | 13 +- src/video/photon/SDL_phyuv.c | 359 +- src/video/photon/SDL_phyuv_c.h | 26 +- src/video/picogui/SDL_pgevents.c | 129 +- src/video/picogui/SDL_pgevents_c.h | 8 +- src/video/picogui/SDL_pgvideo.c | 525 +- src/video/picogui/SDL_pgvideo.h | 12 +- src/video/ps2gs/SDL_gsevents.c | 1777 ++-- src/video/ps2gs/SDL_gsevents_c.h | 19 +- src/video/ps2gs/SDL_gskeys.h | 14 +- src/video/ps2gs/SDL_gsmouse.c | 197 +- src/video/ps2gs/SDL_gsmouse_c.h | 16 +- src/video/ps2gs/SDL_gsvideo.c | 1149 +-- src/video/ps2gs/SDL_gsvideo.h | 57 +- src/video/ps2gs/SDL_gsyuv.c | 792 +- src/video/ps2gs/SDL_gsyuv_c.h | 14 +- src/video/qtopia/SDL_QPEApp.cc | 49 +- src/video/qtopia/SDL_QPEApp.h | 5 +- src/video/qtopia/SDL_QWin.cc | 1046 ++- src/video/qtopia/SDL_QWin.h | 144 +- src/video/qtopia/SDL_lowvideo.h | 32 +- src/video/qtopia/SDL_sysevents.cc | 428 +- src/video/qtopia/SDL_sysevents_c.h | 5 +- src/video/qtopia/SDL_sysmouse.cc | 59 +- src/video/qtopia/SDL_sysmouse_c.h | 13 +- src/video/qtopia/SDL_sysvideo.cc | 696 +- src/video/qtopia/SDL_syswm.cc | 14 +- src/video/qtopia/SDL_syswm_c.h | 4 +- src/video/quartz/CGS.h | 29 +- src/video/quartz/SDL_QuartzEvents.m | 953 +- src/video/quartz/SDL_QuartzGL.m | 198 +- src/video/quartz/SDL_QuartzKeys.h | 5 +- src/video/quartz/SDL_QuartzVideo.h | 261 +- src/video/quartz/SDL_QuartzVideo.m | 1292 +-- src/video/quartz/SDL_QuartzWM.m | 391 +- src/video/quartz/SDL_QuartzWindow.h | 26 +- src/video/quartz/SDL_QuartzWindow.m | 217 +- src/video/quartz/SDL_QuartzYUV.m | 216 +- src/video/riscos/SDL_riscosFullScreenVideo.c | 1189 +-- src/video/riscos/SDL_riscosevents.c | 877 +- src/video/riscos/SDL_riscosevents_c.h | 8 +- src/video/riscos/SDL_riscosmouse.c | 511 +- src/video/riscos/SDL_riscosmouse_c.h | 28 +- src/video/riscos/SDL_riscossprite.c | 374 +- src/video/riscos/SDL_riscostask.c | 347 +- src/video/riscos/SDL_riscostask.h | 13 +- src/video/riscos/SDL_riscosvideo.c | 388 +- src/video/riscos/SDL_riscosvideo.h | 22 +- src/video/riscos/SDL_wimppoll.c | 465 +- src/video/riscos/SDL_wimpvideo.c | 789 +- src/video/svga/SDL_svgaevents.c | 632 +- src/video/svga/SDL_svgaevents_c.h | 13 +- src/video/svga/SDL_svgamouse.c | 6 +- src/video/svga/SDL_svgamouse_c.h | 1 + src/video/svga/SDL_svgavideo.c | 940 +- src/video/svga/SDL_svgavideo.h | 29 +- src/video/vgl/SDL_vglevents.c | 435 +- src/video/vgl/SDL_vglevents_c.h | 23 +- src/video/vgl/SDL_vglmouse.c | 29 +- src/video/vgl/SDL_vglmouse_c.h | 13 +- src/video/vgl/SDL_vglvideo.c | 1040 +-- src/video/vgl/SDL_vglvideo.h | 33 +- src/video/wincommon/SDL_lowvideo.h | 19 +- src/video/wincommon/SDL_sysevents.c | 1281 +-- src/video/wincommon/SDL_sysmouse.c | 340 +- src/video/wincommon/SDL_sysmouse_c.h | 16 +- src/video/wincommon/SDL_syswm.c | 449 +- src/video/wincommon/SDL_syswm_c.h | 12 +- src/video/wincommon/SDL_wingl.c | 1119 +-- src/video/wincommon/SDL_wingl_c.h | 64 +- src/video/wincommon/wmmsg.h | 2052 ++--- src/video/windib/SDL_dibevents.c | 756 +- src/video/windib/SDL_dibevents_c.h | 11 +- src/video/windib/SDL_dibvideo.c | 1712 ++-- src/video/windib/SDL_dibvideo.h | 24 +- src/video/windib/SDL_vkeys.h | 1 + src/video/windx5/SDL_dx5events.c | 1567 ++-- src/video/windx5/SDL_dx5events_c.h | 16 +- src/video/windx5/SDL_dx5video.c | 4381 ++++----- src/video/windx5/SDL_dx5video.h | 16 +- src/video/windx5/SDL_dx5yuv.c | 451 +- src/video/windx5/SDL_dx5yuv_c.h | 14 +- src/video/windx5/directx.h | 1 + src/video/wscons/SDL_wsconsevents.c | 338 +- src/video/wscons/SDL_wsconsevents_c.h | 10 +- src/video/wscons/SDL_wsconsmouse.c | 6 +- src/video/wscons/SDL_wsconsmouse_c.h | 1 + src/video/wscons/SDL_wsconsvideo.c | 966 +- src/video/wscons/SDL_wsconsvideo.h | 49 +- src/video/x11/SDL_x11dga.c | 42 +- src/video/x11/SDL_x11dga_c.h | 7 +- src/video/x11/SDL_x11dyn.c | 184 +- src/video/x11/SDL_x11dyn.h | 21 +- src/video/x11/SDL_x11events.c | 1963 ++-- src/video/x11/SDL_x11events_c.h | 15 +- src/video/x11/SDL_x11gamma.c | 121 +- src/video/x11/SDL_x11gamma_c.h | 9 +- src/video/x11/SDL_x11gl.c | 852 +- src/video/x11/SDL_x11gl_c.h | 77 +- src/video/x11/SDL_x11image.c | 442 +- src/video/x11/SDL_x11image_c.h | 27 +- src/video/x11/SDL_x11modes.c | 1052 +-- src/video/x11/SDL_x11modes_c.h | 19 +- src/video/x11/SDL_x11mouse.c | 458 +- src/video/x11/SDL_x11mouse_c.h | 16 +- src/video/x11/SDL_x11sym.h | 631 +- src/video/x11/SDL_x11video.c | 2395 ++--- src/video/x11/SDL_x11video.h | 85 +- src/video/x11/SDL_x11wm.c | 698 +- src/video/x11/SDL_x11wm_c.h | 16 +- src/video/x11/SDL_x11yuv.c | 594 +- src/video/x11/SDL_x11yuv_c.h | 14 +- src/video/xbios/SDL_xbios.c | 1519 ++-- src/video/xbios/SDL_xbios.h | 84 +- src/video/xbios/SDL_xbios_blowup.c | 62 +- src/video/xbios/SDL_xbios_blowup.h | 93 +- src/video/xbios/SDL_xbios_centscreen.c | 126 +- src/video/xbios/SDL_xbios_centscreen.h | 40 +- src/video/xbios/SDL_xbios_sb3.c | 77 +- src/video/xbios/SDL_xbios_sb3.h | 59 +- test/checkkeys.c | 226 +- test/graywin.c | 442 +- test/loopwave.c | 178 +- test/testalpha.c | 932 +- test/testbitmap.c | 324 +- test/testblitspeed.c | 455 +- test/testcdrom.c | 358 +- test/testdyngl.c | 304 +- test/testerror.c | 83 +- test/testfile.c | 348 +- test/testgamma.c | 339 +- test/testgl.c | 1351 +-- test/testhread.c | 110 +- test/testiconv.c | 118 +- test/testjoystick.c | 323 +- test/testkeys.c | 24 +- test/testlock.c | 134 +- test/testoverlay.c | 980 +- test/testoverlay2.c | 959 +- test/testpalette.c | 448 +- test/testplatform.c | 290 +- test/testsem.c | 108 +- test/testsprite.c | 528 +- test/testtimer.c | 133 +- test/testver.c | 38 +- test/testvidinfo.c | 947 +- test/testwin.c | 634 +- test/testwm.c | 658 +- test/threadwin.c | 610 +- test/torturethread.c | 125 +- 642 files changed, 119546 insertions(+), 108294 deletions(-) create mode 100644 .indent.pro create mode 100644 UNDER_CONSTRUCTION.txt delete mode 100644 include/SDL_active.h delete mode 100644 include/SDL_byteorder.h create mode 100644 include/SDL_compat.h delete mode 100644 include/SDL_getenv.h create mode 100644 include/SDL_pixels.h create mode 100644 include/doxyfile delete mode 100644 src/events/SDL_active.c delete mode 100644 src/events/SDL_resize.c rename src/events/{SDL_expose.c => SDL_windowevents.c} (57%) diff --git a/.indent.pro b/.indent.pro new file mode 100644 index 000000000..fbc40de84 --- /dev/null +++ b/.indent.pro @@ -0,0 +1 @@ +-i4 -nut -nsc -br -ce diff --git a/Makefile.in b/Makefile.in index 978b2b969..b8627bfcf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -125,6 +125,15 @@ uninstall-man: rm -f $(mandir)/man3/$$file; \ done +indent: + cd $(srcdir) && \ + find . \( \ + -name '*.h' -o \ + -name '*.c' -o \ + -name '*.cc' -o \ + -name '*.m' \) \ + -exec indent {} \; + clean: rm -rf $(objects) if test -f test/Makefile; then (cd test; $(MAKE) $@); fi diff --git a/UNDER_CONSTRUCTION.txt b/UNDER_CONSTRUCTION.txt new file mode 100644 index 000000000..cf92fce06 --- /dev/null +++ b/UNDER_CONSTRUCTION.txt @@ -0,0 +1 @@ +WARNING: This code is under construction, may not build, and is unstable! diff --git a/include/SDL.h b/include/SDL.h index 60ac26ce4..48e654114 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -20,7 +20,56 @@ slouken@libsdl.org */ -/* Main include header for the SDL library */ +/** + * \file SDL.h + * + * Main include header for the SDL library + */ +/** + * \mainpage Simple DirectMedia Layer (SDL) + +http://www.libsdl.org/ + +* \section intro_sec Introduction + +This is the Simple DirectMedia Layer, a general API that provides low +level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, +and 2D framebuffer across multiple platforms. + +The current version supports Linux, Windows, Windows CE, BeOS, MacOS, +Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. +The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, +RISC OS, SymbianOS, and OS/2, but these are not officially supported. + +SDL is written in C, but works with C++ natively, and has bindings to +several other languages, including Ada, C#, Eiffel, Erlang, Euphoria, +Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP, +Pike, Pliant, Python, Ruby, and Smalltalk. + +This library is distributed under GNU LGPL version 2, which can be +found in the file "COPYING". This license allows you to use SDL +freely in commercial programs as long as you link with the dynamic +library. + +The best way to learn how to use SDL is to check out the header files in +the "include" subdirectory and the programs in the "test" subdirectory. +The header files and test programs are well commented and always up to date. +More documentation is available in HTML format in "docs/index.html", and +a documentation wiki is available online at: + http://www.libsdl.org/cgi/docwiki.cgi + +The test programs in the "test" subdirectory are in the public domain. + +Frequently asked questions are answered online: + http://www.libsdl.org/faq.php + +If you need help with the library, or just want to discuss SDL related +issues, you can join the developers mailing list: + http://www.libsdl.org/mailing-list.php + +Enjoy! + Sam Lantinga (slouken@libsdl.org) + */ #ifndef _SDL_H #define _SDL_H @@ -40,11 +89,14 @@ #include "SDL_timer.h" #include "SDL_video.h" #include "SDL_version.h" +#include "SDL_compat.h" #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* As of version 0.5, SDL is loaded dynamically into the application */ @@ -57,8 +109,8 @@ extern "C" { #define SDL_INIT_VIDEO 0x00000020 #define SDL_INIT_CDROM 0x00000100 #define SDL_INIT_JOYSTICK 0x00000200 -#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */ -#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */ +#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */ +#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */ #define SDL_INIT_EVERYTHING 0x0000FFFF /* This function loads the SDL dynamically linked library and initializes @@ -66,29 +118,33 @@ extern "C" { * Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup * signal handlers for some commonly ignored fatal signals (like SIGSEGV) */ -extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags); +extern DECLSPEC int SDLCALL SDL_Init (Uint32 flags); /* This function initializes specific SDL subsystems */ -extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags); +extern DECLSPEC int SDLCALL SDL_InitSubSystem (Uint32 flags); /* This function cleans up specific SDL subsystems */ -extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags); +extern DECLSPEC void SDLCALL SDL_QuitSubSystem (Uint32 flags); /* This function returns mask of the specified subsystems which have been initialized. If 'flags' is 0, it returns a mask of all initialized subsystems. */ -extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags); +extern DECLSPEC Uint32 SDLCALL SDL_WasInit (Uint32 flags); /* This function cleans up all initialized subsystems and unloads the * dynamically linked library. You should call it upon all exit conditions. */ -extern DECLSPEC void SDLCALL SDL_Quit(void); +extern DECLSPEC void SDLCALL SDL_Quit (void); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_H */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_active.h b/include/SDL_active.h deleted file mode 100644 index 2cf474c5a..000000000 --- a/include/SDL_active.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ - -/* Include file for SDL application focus event handling */ - -#ifndef _SDL_active_h -#define _SDL_active_h - -#include "SDL_stdinc.h" -#include "SDL_error.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* The available application states */ -#define SDL_APPMOUSEFOCUS 0x01 /* The app has mouse coverage */ -#define SDL_APPINPUTFOCUS 0x02 /* The app has input focus */ -#define SDL_APPACTIVE 0x04 /* The application is active */ - -/* Function prototypes */ -/* - * This function returns the current state of the application, which is a - * bitwise combination of SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, and - * SDL_APPACTIVE. If SDL_APPACTIVE is set, then the user is able to - * see your application, otherwise it has been iconified or disabled. - */ -extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_active_h */ diff --git a/include/SDL_audio.h b/include/SDL_audio.h index c079aa3b3..91d533e0d 100644 --- a/include/SDL_audio.h +++ b/include/SDL_audio.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* Access to the raw audio mixing buffer for the SDL library */ +/** + * \file SDL_audio.h + * + * Access to the raw audio mixing buffer for the SDL library + */ #ifndef _SDL_audio_h #define _SDL_audio_h @@ -35,35 +39,38 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* The calculated values in this structure are calculated by SDL_OpenAudio() */ -typedef struct SDL_AudioSpec { - int freq; /* DSP frequency -- samples per second */ - Uint16 format; /* Audio data format */ - Uint8 channels; /* Number of channels: 1 mono, 2 stereo */ - Uint8 silence; /* Audio buffer silence value (calculated) */ - Uint16 samples; /* Audio buffer size in samples (power of 2) */ - Uint16 padding; /* Necessary for some compile environments */ - Uint32 size; /* Audio buffer size in bytes (calculated) */ - /* This function is called when the audio device needs more data. - 'stream' is a pointer to the audio data buffer - 'len' is the length of that buffer in bytes. - Once the callback returns, the buffer will no longer be valid. - Stereo samples are stored in a LRLRLR ordering. - */ - void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len); - void *userdata; +typedef struct SDL_AudioSpec +{ + int freq; /* DSP frequency -- samples per second */ + Uint16 format; /* Audio data format */ + Uint8 channels; /* Number of channels: 1 mono, 2 stereo */ + Uint8 silence; /* Audio buffer silence value (calculated) */ + Uint16 samples; /* Audio buffer size in samples (power of 2) */ + Uint16 padding; /* Necessary for some compile environments */ + Uint32 size; /* Audio buffer size in bytes (calculated) */ + /* This function is called when the audio device needs more data. + 'stream' is a pointer to the audio data buffer + 'len' is the length of that buffer in bytes. + Once the callback returns, the buffer will no longer be valid. + Stereo samples are stored in a LRLRLR ordering. + */ + void (SDLCALL * callback) (void *userdata, Uint8 * stream, int len); + void *userdata; } SDL_AudioSpec; /* Audio format flags (defaults to LSB byte order) */ -#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */ -#define AUDIO_S8 0x8008 /* Signed 8-bit samples */ -#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */ -#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */ -#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */ -#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */ +#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */ +#define AUDIO_S8 0x8008 /* Signed 8-bit samples */ +#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */ +#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */ +#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */ +#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */ #define AUDIO_U16 AUDIO_U16LSB #define AUDIO_S16 AUDIO_S16LSB @@ -78,18 +85,19 @@ typedef struct SDL_AudioSpec { /* A structure to hold a set of audio conversion filters and buffers */ -typedef struct SDL_AudioCVT { - int needed; /* Set to 1 if conversion possible */ - Uint16 src_format; /* Source audio format */ - Uint16 dst_format; /* Target audio format */ - double rate_incr; /* Rate conversion increment */ - Uint8 *buf; /* Buffer to hold entire audio data */ - int len; /* Length of original audio buffer */ - int len_cvt; /* Length of converted audio buffer */ - int len_mult; /* buffer must be len*len_mult big */ - double len_ratio; /* Given len, final size is len*len_ratio */ - void (SDLCALL *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format); - int filter_index; /* Current audio conversion function */ +typedef struct SDL_AudioCVT +{ + int needed; /* Set to 1 if conversion possible */ + Uint16 src_format; /* Source audio format */ + Uint16 dst_format; /* Target audio format */ + double rate_incr; /* Rate conversion increment */ + Uint8 *buf; /* Buffer to hold entire audio data */ + int len; /* Length of original audio buffer */ + int len_cvt; /* Length of converted audio buffer */ + int len_mult; /* buffer must be len*len_mult big */ + double len_ratio; /* Given len, final size is len*len_ratio */ + void (SDLCALL * filters[10]) (struct SDL_AudioCVT * cvt, Uint16 format); + int filter_index; /* Current audio conversion function */ } SDL_AudioCVT; @@ -98,20 +106,20 @@ typedef struct SDL_AudioCVT { /* These functions return the list of built in video drivers, in the * order that they are normally initialized by default. */ -extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void); -extern DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index); +extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers (void); +extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver (int index); /* These functions are used internally, and should not be used unless you * have a specific need to specify the audio driver you want to use. * You should normally use SDL_Init() or SDL_InitSubSystem(). */ -extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name); -extern DECLSPEC void SDLCALL SDL_AudioQuit(void); +extern DECLSPEC int SDLCALL SDL_AudioInit (const char *driver_name); +extern DECLSPEC void SDLCALL SDL_AudioQuit (void); /* This function returns the name of the current audio driver, or NULL * if no driver has been initialized. */ -extern DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void); +extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver (void); /* * This function opens the audio device with the desired parameters, and @@ -154,17 +162,19 @@ extern DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void); * may modify the requested size of the audio buffer, you should allocate * any local mixing buffers after you open the audio device. */ -extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained); +extern DECLSPEC int SDLCALL SDL_OpenAudio (SDL_AudioSpec * desired, + SDL_AudioSpec * obtained); /* * Get the current audio state: */ -typedef enum { - SDL_AUDIO_STOPPED = 0, - SDL_AUDIO_PLAYING, - SDL_AUDIO_PAUSED +typedef enum +{ + SDL_AUDIO_STOPPED = 0, + SDL_AUDIO_PLAYING, + SDL_AUDIO_PAUSED } SDL_audiostatus; -extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus(void); +extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus (void); /* * This function pauses and unpauses the audio callback processing. @@ -173,7 +183,7 @@ extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus(void); * data for your callback function after opening the audio device. * Silence will be written to the audio device during the pause. */ -extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on); +extern DECLSPEC void SDLCALL SDL_PauseAudio (int pause_on); /* * This function loads a WAVE from the data source, automatically freeing @@ -192,7 +202,11 @@ extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on); * wave file cannot be opened, uses an unknown data format, or is * corrupt. Currently raw and MS-ADPCM WAVE files are supported. */ -extern DECLSPEC SDL_AudioSpec * SDLCALL SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len); +extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW (SDL_RWops * src, + int freesrc, + SDL_AudioSpec * spec, + Uint8 ** audio_buf, + Uint32 * audio_len); /* Compatibility convenience function -- loads a WAV from a file */ #define SDL_LoadWAV(file, spec, audio_buf, audio_len) \ @@ -201,7 +215,7 @@ extern DECLSPEC SDL_AudioSpec * SDLCALL SDL_LoadWAV_RW(SDL_RWops *src, int frees /* * This function frees data previously allocated with SDL_LoadWAV_RW() */ -extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 *audio_buf); +extern DECLSPEC void SDLCALL SDL_FreeWAV (Uint8 * audio_buf); /* * This function takes a source format and rate and a destination format @@ -210,9 +224,13 @@ extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 *audio_buf); * to the other. * This function returns 0, or -1 if there was an error. */ -extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT *cvt, - Uint16 src_format, Uint8 src_channels, int src_rate, - Uint16 dst_format, Uint8 dst_channels, int dst_rate); +extern DECLSPEC int SDLCALL SDL_BuildAudioCVT (SDL_AudioCVT * cvt, + Uint16 src_format, + Uint8 src_channels, + int src_rate, + Uint16 dst_format, + Uint8 dst_channels, + int dst_rate); /* Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(), * created an audio buffer cvt->buf, and filled it with cvt->len bytes of @@ -222,7 +240,7 @@ extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT *cvt, * cvt->buf should be allocated after the cvt structure is initialized by * SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long. */ -extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT *cvt); +extern DECLSPEC int SDLCALL SDL_ConvertAudio (SDL_AudioCVT * cvt); /* * This takes two audio buffers of the playing audio format and mixes @@ -232,7 +250,8 @@ extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT *cvt); * This is provided for convenience -- you can mix your own audio data. */ #define SDL_MIX_MAXVOLUME 128 -extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 len, int volume); +extern DECLSPEC void SDLCALL SDL_MixAudio (Uint8 * dst, const Uint8 * src, + Uint32 len, int volume); /* * The lock manipulated by these functions protects the callback function. @@ -240,19 +259,23 @@ extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 l * callback function is not running. Do not call these from the callback * function or you will cause deadlock. */ -extern DECLSPEC void SDLCALL SDL_LockAudio(void); -extern DECLSPEC void SDLCALL SDL_UnlockAudio(void); +extern DECLSPEC void SDLCALL SDL_LockAudio (void); +extern DECLSPEC void SDLCALL SDL_UnlockAudio (void); /* * This function shuts down audio processing and closes the audio device. */ -extern DECLSPEC void SDLCALL SDL_CloseAudio(void); +extern DECLSPEC void SDLCALL SDL_CloseAudio (void); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_audio_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_byteorder.h b/include/SDL_byteorder.h deleted file mode 100644 index 3871cfed5..000000000 --- a/include/SDL_byteorder.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ - -/* DEPRECATED */ -#include "SDL_endian.h" diff --git a/include/SDL_cdrom.h b/include/SDL_cdrom.h index 5f8f0c62a..0b9ce0171 100644 --- a/include/SDL_cdrom.h +++ b/include/SDL_cdrom.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* This is the CD-audio control API for Simple DirectMedia Layer */ +/** + * \file SDL_cdrom.h + * + * This is the CD-audio control API for Simple DirectMedia Layer + */ #ifndef _SDL_cdrom_h #define _SDL_cdrom_h @@ -31,7 +35,9 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* In order to use these functions, SDL_Init() must have been called @@ -47,35 +53,38 @@ extern "C" { #define SDL_DATA_TRACK 0x04 /* The possible states which a CD-ROM drive can be in. */ -typedef enum { - CD_TRAYEMPTY, - CD_STOPPED, - CD_PLAYING, - CD_PAUSED, - CD_ERROR = -1 +typedef enum +{ + CD_TRAYEMPTY, + CD_STOPPED, + CD_PLAYING, + CD_PAUSED, + CD_ERROR = -1 } CDstatus; /* Given a status, returns true if there's a disk in the drive */ #define CD_INDRIVE(status) ((int)(status) > 0) -typedef struct SDL_CDtrack { - Uint8 id; /* Track number */ - Uint8 type; /* Data or audio track */ - Uint16 unused; - Uint32 length; /* Length, in frames, of this track */ - Uint32 offset; /* Offset, in frames, from start of disk */ +typedef struct SDL_CDtrack +{ + Uint8 id; /* Track number */ + Uint8 type; /* Data or audio track */ + Uint16 unused; + Uint32 length; /* Length, in frames, of this track */ + Uint32 offset; /* Offset, in frames, from start of disk */ } SDL_CDtrack; /* This structure is only current as of the last call to SDL_CDStatus() */ -typedef struct SDL_CD { - int id; /* Private drive identifier */ - CDstatus status; /* Current drive status */ - - /* The rest of this structure is only valid if there's a CD in drive */ - int numtracks; /* Number of tracks on disk */ - int cur_track; /* Current track position */ - int cur_frame; /* Current frame offset within current track */ - SDL_CDtrack track[SDL_MAX_TRACKS+1]; +typedef struct SDL_CD +{ + int id; /* Private drive identifier */ + CDstatus status; /* Current drive status */ + + /* The rest of this structure is only valid if there's a CD in drive */ + int numtracks; /* Number of tracks on disk */ + int cur_track; /* Current track position */ + int cur_frame; /* Current frame offset within current track */ + SDL_CDtrack track[SDL_MAX_TRACKS + 1]; } SDL_CD; /* Conversion functions from frames to Minute/Second/Frames and vice versa */ @@ -95,7 +104,7 @@ typedef struct SDL_CD { /* Returns the number of CD-ROM drives on the system, or -1 if SDL_Init() has not been called with the SDL_INIT_CDROM flag. */ -extern DECLSPEC int SDLCALL SDL_CDNumDrives(void); +extern DECLSPEC int SDLCALL SDL_CDNumDrives (void); /* Returns a human-readable, system-dependent identifier for the CD-ROM. Example: @@ -103,7 +112,7 @@ extern DECLSPEC int SDLCALL SDL_CDNumDrives(void); "E:" "/dev/disk/ide/1/master" */ -extern DECLSPEC const char * SDLCALL SDL_CDName(int drive); +extern DECLSPEC const char *SDLCALL SDL_CDName (int drive); /* Opens a CD-ROM drive for access. It returns a drive handle on success, or NULL if the drive was invalid or busy. This newly opened CD-ROM @@ -111,13 +120,13 @@ extern DECLSPEC const char * SDLCALL SDL_CDName(int drive); CD-ROM handle. Drives are numbered starting with 0. Drive 0 is the system default CD-ROM. */ -extern DECLSPEC SDL_CD * SDLCALL SDL_CDOpen(int drive); +extern DECLSPEC SDL_CD *SDLCALL SDL_CDOpen (int drive); /* This function returns the current status of the given drive. If the drive has a CD in it, the table of contents of the CD and current play position of the CD will be stored in the SDL_CD structure. */ -extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom); +extern DECLSPEC CDstatus SDLCALL SDL_CDStatus (SDL_CD * cdrom); /* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks' tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play @@ -138,34 +147,41 @@ extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom); This function returns 0, or -1 if there was an error. */ -extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom, - int start_track, int start_frame, int ntracks, int nframes); +extern DECLSPEC int SDLCALL SDL_CDPlayTracks (SDL_CD * cdrom, + int start_track, + int start_frame, int ntracks, + int nframes); /* Play the given CD starting at 'start' frame for 'length' frames. It returns 0, or -1 if there was an error. */ -extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD *cdrom, int start, int length); +extern DECLSPEC int SDLCALL SDL_CDPlay (SDL_CD * cdrom, int start, + int length); /* Pause play -- returns 0, or -1 on error */ -extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD *cdrom); +extern DECLSPEC int SDLCALL SDL_CDPause (SDL_CD * cdrom); /* Resume play -- returns 0, or -1 on error */ -extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD *cdrom); +extern DECLSPEC int SDLCALL SDL_CDResume (SDL_CD * cdrom); /* Stop play -- returns 0, or -1 on error */ -extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD *cdrom); +extern DECLSPEC int SDLCALL SDL_CDStop (SDL_CD * cdrom); /* Eject CD-ROM -- returns 0, or -1 on error */ -extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD *cdrom); +extern DECLSPEC int SDLCALL SDL_CDEject (SDL_CD * cdrom); /* Closes the handle for the CD-ROM drive */ -extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD *cdrom); +extern DECLSPEC void SDLCALL SDL_CDClose (SDL_CD * cdrom); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_video_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_compat.h b/include/SDL_compat.h new file mode 100644 index 000000000..ef2463ae3 --- /dev/null +++ b/include/SDL_compat.h @@ -0,0 +1,126 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This file contains functions for backwards compatibility with SDL 1.2 */ + +#ifndef _SDL_compat_h +#define _SDL_compat_h + +#include "SDL_syswm.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" +{ +#endif + + extern DECLSPEC char *SDLCALL SDL_AudioDriverName (char *namebuf, + int maxlen); + extern DECLSPEC char *SDLCALL SDL_VideoDriverName (char *namebuf, + int maxlen); + extern DECLSPEC int SDLCALL SDL_VideoModeOK (int width, int height, + int bpp, Uint32 flags); + extern DECLSPEC SDL_Rect **SDLCALL SDL_ListModes (SDL_PixelFormat * + format, Uint32 flags); + extern DECLSPEC SDL_Surface *SDLCALL SDL_SetVideoMode (int width, + int height, + int bpp, + Uint32 flags); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_compat_h */ + +extern DECLSPEC SDL_Surface *SDLCALL SDL_GetVideoSurface (void); + +/* These are the currently supported flags for the SDL_surface */ +/* Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */ +#define SDL_SWSURFACE 0x00000000 /* Surface is in system memory */ +#define SDL_HWSURFACE 0x00000001 /* Surface is in video memory */ +#define SDL_ASYNCBLIT 0x00000004 /* Use asynchronous blits if possible */ +/* Available for SDL_SetVideoMode() */ +#define SDL_ANYFORMAT 0x10000000 /* Allow any video depth/pixel-format */ +#define SDL_HWPALETTE 0x20000000 /* Surface has exclusive palette */ +#define SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered video mode */ +#define SDL_FULLSCREEN 0x80000000 /* Surface is a full screen display */ +#define SDL_OPENGL 0x00000002 /* Create an OpenGL rendering context */ +#define SDL_INTERNALOPENGL 0x00000008 /* SDL uses OpenGL internally for this window */ +#define SDL_RESIZABLE 0x00000010 /* This video mode may be resized */ +#define SDL_NOFRAME 0x00000020 /* No window caption or edge frame */ +/* Used internally (read-only) */ +#define SDL_HWACCEL 0x00000100 /* Blit uses hardware acceleration */ +#define SDL_SRCCOLORKEY 0x00001000 /* Blit uses a source color key */ +#define SDL_RLEACCELOK 0x00002000 /* Private flag */ +#define SDL_RLEACCEL 0x00004000 /* Surface is RLE encoded */ +#define SDL_SRCALPHA 0x00010000 /* Blit uses source alpha blending */ + +extern DECLSPEC void SDLCALL SDL_WM_SetCaption (const char *title, + const char *icon); +extern DECLSPEC void SDLCALL SDL_WM_GetCaption (char **title, char **icon); +extern DECLSPEC void SDLCALL SDL_WM_SetIcon (SDL_Surface * icon, + Uint8 * mask); +extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow (void); +extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen (SDL_Surface * surface); +typedef enum +{ + SDL_GRAB_QUERY = -1, + SDL_GRAB_OFF = 0, + SDL_GRAB_ON = 1 +} SDL_GrabMode; +extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput (SDL_GrabMode mode); + +/* The available application states */ +#define SDL_APPMOUSEFOCUS 0x01 /* The app has mouse coverage */ +#define SDL_APPINPUTFOCUS 0x02 /* The app has input focus */ +#define SDL_APPACTIVE 0x04 /* The application is active */ + +extern DECLSPEC Uint8 SDLCALL SDL_GetAppState (void); +extern DECLSPEC const SDL_version *SDLCALL SDL_Linked_Version (void); +/* flags for SDL_SetPalette() */ +#define SDL_LOGPAL 0x01 +#define SDL_PHYSPAL 0x02 + +/* + * Sets a portion of the colormap for a given 8-bit surface. + * 'flags' is one or both of: + * SDL_LOGPAL -- set logical palette, which controls how blits are mapped + * to/from the surface, + * SDL_PHYSPAL -- set physical palette, which controls how pixels look on + * the screen + * Only screens have physical palettes. Separate change of physical/logical + * palettes is only possible if the screen has SDL_HWPALETTE set. + * + * The return value is 1 if all colours could be set as requested, and 0 + * otherwise. + * + * SDL_SetColors() is equivalent to calling this function with + * flags = (SDL_LOGPAL|SDL_PHYSPAL). + */ +extern DECLSPEC int SDLCALL SDL_SetPalette (SDL_Surface * surface, int flags, + SDL_Color * colors, + int firstcolor, int ncolors); +extern DECLSPEC int SDLCALL SDL_GetWMInfo (SDL_SysWMinfo * info); diff --git a/include/SDL_config_macos.h b/include/SDL_config_macos.h index f1a34202c..efc926645 100644 --- a/include/SDL_config_macos.h +++ b/include/SDL_config_macos.h @@ -29,15 +29,15 @@ #include -typedef SInt8 int8_t; -typedef UInt8 uint8_t; -typedef SInt16 int16_t; -typedef UInt16 uint16_t; -typedef SInt32 int32_t; -typedef UInt32 uint32_t; -typedef SInt64 int64_t; -typedef UInt64 uint64_t; -typedef unsigned long uintptr_t; +typedef SInt8 int8_t; +typedef UInt8 uint8_t; +typedef SInt16 int16_t; +typedef UInt16 uint16_t; +typedef SInt32 int32_t; +typedef UInt32 uint32_t; +typedef SInt64 int64_t; +typedef UInt64 uint64_t; +typedef unsigned long uintptr_t; #define SDL_HAS_64BIT_TYPE 1 diff --git a/include/SDL_config_os2.h b/include/SDL_config_os2.h index 8cdea9ff2..c7f576d24 100644 --- a/include/SDL_config_os2.h +++ b/include/SDL_config_os2.h @@ -27,16 +27,16 @@ /* This is a set of defines to configure the SDL features */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef unsigned int size_t; -typedef unsigned long uintptr_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef unsigned int size_t; +typedef unsigned long uintptr_t; +typedef signed long long int64_t; +typedef unsigned long long uint64_t; #define SDL_HAS_64BIT_TYPE 1 diff --git a/include/SDL_config_win32.h b/include/SDL_config_win32.h index 892105054..b578f2788 100644 --- a/include/SDL_config_win32.h +++ b/include/SDL_config_win32.h @@ -28,19 +28,19 @@ /* This is a set of defines to configure the SDL features */ #ifdef _MSC_VER -typedef signed __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef signed __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef signed __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; +typedef signed __int8 int8_t; +typedef unsigned __int8 uint8_t; +typedef signed __int16 int16_t; +typedef unsigned __int16 uint16_t; +typedef signed __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; #ifndef _UINTPTR_T_DEFINED #ifdef _WIN64 -typedef unsigned __int64 uintptr_t; +typedef unsigned __int64 uintptr_t; #else -typedef unsigned int uintptr_t; +typedef unsigned int uintptr_t; #endif #define _UINTPTR_T_DEFINED #endif diff --git a/include/SDL_copying.h b/include/SDL_copying.h index 39e122db7..2f0d27a66 100644 --- a/include/SDL_copying.h +++ b/include/SDL_copying.h @@ -19,4 +19,3 @@ Sam Lantinga slouken@libsdl.org */ - diff --git a/include/SDL_cpuinfo.h b/include/SDL_cpuinfo.h index 72acbdd8b..b8e01f563 100644 --- a/include/SDL_cpuinfo.h +++ b/include/SDL_cpuinfo.h @@ -20,8 +20,11 @@ slouken@libsdl.org */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* CPU feature detection for SDL */ +/** + * \file SDL_cpuinfo.h + * + * CPU feature detection for SDL + */ #ifndef _SDL_cpuinfo_h #define _SDL_cpuinfo_h @@ -31,45 +34,51 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* This function returns true if the CPU has the RDTSC instruction */ -extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void); +extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC (void); /* This function returns true if the CPU has MMX features */ -extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void); +extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX (void); /* This function returns true if the CPU has MMX Ext. features */ -extern DECLSPEC SDL_bool SDLCALL SDL_HasMMXExt(void); +extern DECLSPEC SDL_bool SDLCALL SDL_HasMMXExt (void); /* This function returns true if the CPU has 3DNow features */ -extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void); +extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow (void); /* This function returns true if the CPU has 3DNow! Ext. features */ -extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNowExt(void); +extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNowExt (void); /* This function returns true if the CPU has SSE features */ -extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void); +extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE (void); /* This function returns true if the CPU has SSE2 features */ -extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void); +extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2 (void); /* This function returns true if the CPU has AltiVec features */ -extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void); +extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec (void); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_cpuinfo_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_endian.h b/include/SDL_endian.h index 6257a649d..61a428b49 100644 --- a/include/SDL_endian.h +++ b/include/SDL_endian.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* Functions for reading and writing endian-specific values */ +/** + * \file SDL_endian.h + * + * Functions for reading and writing endian-specific values + */ #ifndef _SDL_endian_h #define _SDL_endian_h @@ -31,7 +35,7 @@ #define SDL_LIL_ENDIAN 1234 #define SDL_BIG_ENDIAN 4321 -#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */ +#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */ #if defined(__hppa__) || \ defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ (defined(__MIPS__) && defined(__MISPEB__)) || \ @@ -47,7 +51,9 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* Use inline functions for compilers that support them, and static @@ -57,104 +63,125 @@ extern "C" { */ #if defined(__GNUC__) && defined(__i386__) && \ !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */) -static __inline__ Uint16 SDL_Swap16(Uint16 x) +static __inline__ Uint16 +SDL_Swap16 (Uint16 x) { - __asm__("xchgb %b0,%h0" : "=q" (x) : "0" (x)); - return x; + __asm__ ("xchgb %b0,%h0": "=q" (x):"0" (x)); + return x; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint16 SDL_Swap16(Uint16 x) +static __inline__ Uint16 +SDL_Swap16 (Uint16 x) { - __asm__("xchgb %b0,%h0" : "=Q" (x) : "0" (x)); - return x; + __asm__ ("xchgb %b0,%h0": "=Q" (x):"0" (x)); + return x; } #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static __inline__ Uint16 SDL_Swap16(Uint16 x) +static __inline__ Uint16 +SDL_Swap16 (Uint16 x) { - Uint16 result; + Uint16 result; - __asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x)); - return result; + __asm__ ("rlwimi %0,%2,8,16,23": "=&r" (result):"0" (x >> 8), "r" (x)); + return result; } #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) -static __inline__ Uint16 SDL_Swap16(Uint16 x) +static __inline__ Uint16 +SDL_Swap16 (Uint16 x) { - __asm__("rorw #8,%0" : "=d" (x) : "0" (x) : "cc"); - return x; + __asm__ ("rorw #8,%0": "=d" (x): "0" (x):"cc"); + return x; } #else -static __inline__ Uint16 SDL_Swap16(Uint16 x) { - return((x<<8)|(x>>8)); +static __inline__ Uint16 +SDL_Swap16 (Uint16 x) +{ + return ((x << 8) | (x >> 8)); } #endif #if defined(__GNUC__) && defined(__i386__) -static __inline__ Uint32 SDL_Swap32(Uint32 x) +static __inline__ Uint32 +SDL_Swap32 (Uint32 x) { - __asm__("bswap %0" : "=r" (x) : "0" (x)); - return x; + __asm__ ("bswap %0": "=r" (x):"0" (x)); + return x; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint32 SDL_Swap32(Uint32 x) +static __inline__ Uint32 +SDL_Swap32 (Uint32 x) { - __asm__("bswapl %0" : "=r" (x) : "0" (x)); - return x; + __asm__ ("bswapl %0": "=r" (x):"0" (x)); + return x; } #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static __inline__ Uint32 SDL_Swap32(Uint32 x) +static __inline__ Uint32 +SDL_Swap32 (Uint32 x) { - Uint32 result; + Uint32 result; - __asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x)); - __asm__("rlwimi %0,%2,8,8,15" : "=&r" (result) : "0" (result), "r" (x)); - __asm__("rlwimi %0,%2,24,0,7" : "=&r" (result) : "0" (result), "r" (x)); - return result; + __asm__ ("rlwimi %0,%2,24,16,23": "=&r" (result):"0" (x >> 24), + "r" (x)); + __asm__ ("rlwimi %0,%2,8,8,15": "=&r" (result):"0" (result), "r" (x)); + __asm__ ("rlwimi %0,%2,24,0,7": "=&r" (result):"0" (result), "r" (x)); + return result; } #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) -static __inline__ Uint32 SDL_Swap32(Uint32 x) +static __inline__ Uint32 +SDL_Swap32 (Uint32 x) { - __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) : "0" (x) : "cc"); - return x; + __asm__ ("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d" (x): "0" (x):"cc"); + return x; } #else -static __inline__ Uint32 SDL_Swap32(Uint32 x) { - return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24)); +static __inline__ Uint32 +SDL_Swap32 (Uint32 x) +{ + return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | + (x >> 24)); } #endif #ifdef SDL_HAS_64BIT_TYPE #if defined(__GNUC__) && defined(__i386__) -static __inline__ Uint64 SDL_Swap64(Uint64 x) +static __inline__ Uint64 +SDL_Swap64 (Uint64 x) { - union { - struct { Uint32 a,b; } s; - Uint64 u; - } v; - v.u = x; - __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1" - : "=r" (v.s.a), "=r" (v.s.b) - : "0" (v.s.a), "1" (v.s.b)); - return v.u; + union + { + struct + { + Uint32 a, b; + } s; + Uint64 u; + } v; + v.u = x; + __asm__ ("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r" (v.s.a), "=r" (v.s.b):"0" (v.s.a), + "1" (v.s. + b)); + return v.u; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint64 SDL_Swap64(Uint64 x) +static __inline__ Uint64 +SDL_Swap64 (Uint64 x) { - __asm__("bswapq %0" : "=r" (x) : "0" (x)); - return x; + __asm__ ("bswapq %0": "=r" (x):"0" (x)); + return x; } #else -static __inline__ Uint64 SDL_Swap64(Uint64 x) +static __inline__ Uint64 +SDL_Swap64 (Uint64 x) { - Uint32 hi, lo; - - /* Separate into high and low 32-bit values and swap them */ - lo = (Uint32)(x&0xFFFFFFFF); - x >>= 32; - hi = (Uint32)(x&0xFFFFFFFF); - x = SDL_Swap32(lo); - x <<= 32; - x |= SDL_Swap32(hi); - return(x); + Uint32 hi, lo; + + /* Separate into high and low 32-bit values and swap them */ + lo = (Uint32) (x & 0xFFFFFFFF); + x >>= 32; + hi = (Uint32) (x & 0xFFFFFFFF); + x = SDL_Swap32 (lo); + x <<= 32; + x |= SDL_Swap32 (hi); + return (x); } #endif #else @@ -185,8 +212,12 @@ static __inline__ Uint64 SDL_Swap64(Uint64 x) /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_endian_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_error.h b/include/SDL_error.h index 26d6bfaef..32e8ad166 100644 --- a/include/SDL_error.h +++ b/include/SDL_error.h @@ -20,7 +20,10 @@ slouken@libsdl.org */ -/* Simple error message routines for SDL */ +/** + * \file SDL_error.h + * Simple error message routines for SDL + */ #ifndef _SDL_error_h #define _SDL_error_h @@ -30,32 +33,39 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* Public functions */ -extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...); -extern DECLSPEC char * SDLCALL SDL_GetError(void); -extern DECLSPEC void SDLCALL SDL_ClearError(void); +extern DECLSPEC void SDLCALL SDL_SetError (const char *fmt, ...); +extern DECLSPEC char *SDLCALL SDL_GetError (void); +extern DECLSPEC void SDLCALL SDL_ClearError (void); /* Private error message function - used internally */ #define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM) #define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED) -typedef enum { - SDL_ENOMEM, - SDL_EFREAD, - SDL_EFWRITE, - SDL_EFSEEK, - SDL_UNSUPPORTED, - SDL_LASTERROR +typedef enum +{ + SDL_ENOMEM, + SDL_EFREAD, + SDL_EFWRITE, + SDL_EFSEEK, + SDL_UNSUPPORTED, + SDL_LASTERROR } SDL_errorcode; -extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code); +extern DECLSPEC void SDLCALL SDL_Error (SDL_errorcode code); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_error_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_events.h b/include/SDL_events.h index 9fe918c7b..249605bf4 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -20,14 +20,18 @@ slouken@libsdl.org */ -/* Include file for SDL event handling */ +/** + * \file SDL_events.h + * + * Include file for SDL event handling + */ #ifndef _SDL_events_h #define _SDL_events_h #include "SDL_stdinc.h" #include "SDL_error.h" -#include "SDL_active.h" +#include "SDL_video.h" #include "SDL_keyboard.h" #include "SDL_mouse.h" #include "SDL_joystick.h" @@ -36,202 +40,256 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* General keyboard/mouse state definitions */ #define SDL_RELEASED 0 #define SDL_PRESSED 1 -/* Event enumerations */ -typedef enum { - SDL_NOEVENT = 0, /* Unused (do not remove) */ - SDL_ACTIVEEVENT, /* Application loses/gains visibility */ - SDL_KEYDOWN, /* Keys pressed */ - SDL_KEYUP, /* Keys released */ - SDL_MOUSEMOTION, /* Mouse moved */ - SDL_MOUSEBUTTONDOWN, /* Mouse button pressed */ - SDL_MOUSEBUTTONUP, /* Mouse button released */ - SDL_JOYAXISMOTION, /* Joystick axis motion */ - SDL_JOYBALLMOTION, /* Joystick trackball motion */ - SDL_JOYHATMOTION, /* Joystick hat position change */ - SDL_JOYBUTTONDOWN, /* Joystick button pressed */ - SDL_JOYBUTTONUP, /* Joystick button released */ - SDL_QUIT, /* User-requested quit */ - SDL_SYSWMEVENT, /* System specific event */ - SDL_EVENT_RESERVEDA, /* Reserved for future use.. */ - SDL_EVENT_RESERVEDB, /* Reserved for future use.. */ - SDL_VIDEORESIZE, /* User resized video mode */ - SDL_VIDEOEXPOSE, /* Screen needs to be redrawn */ - SDL_EVENT_RESERVED2, /* Reserved for future use.. */ - SDL_EVENT_RESERVED3, /* Reserved for future use.. */ - SDL_EVENT_RESERVED4, /* Reserved for future use.. */ - SDL_EVENT_RESERVED5, /* Reserved for future use.. */ - SDL_EVENT_RESERVED6, /* Reserved for future use.. */ - SDL_EVENT_RESERVED7, /* Reserved for future use.. */ - /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */ - SDL_USEREVENT = 24, - /* This last event is only for bounding internal arrays - It is the number of bits in the event mask datatype -- Uint32 - */ - SDL_NUMEVENTS = 32 +/** + * \enum SDL_EventType + * + * \brief The types of events that can be delivered + */ +typedef enum +{ + SDL_NOEVENT = 0, /**< Unused (do not remove) */ + SDL_WINDOWEVENT, /**< Window state change */ + SDL_KEYDOWN, /**< Keys pressed */ + SDL_KEYUP, /**< Keys released */ + SDL_MOUSEMOTION, /**< Mouse moved */ + SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */ + SDL_MOUSEBUTTONUP, /**< Mouse button released */ + SDL_JOYAXISMOTION, /**< Joystick axis motion */ + SDL_JOYBALLMOTION, /**< Joystick trackball motion */ + SDL_JOYHATMOTION, /**< Joystick hat position change */ + SDL_JOYBUTTONDOWN, /**< Joystick button pressed */ + SDL_JOYBUTTONUP, /**< Joystick button released */ + SDL_QUIT, /**< User-requested quit */ + SDL_SYSWMEVENT, /**< System specific event */ + SDL_EVENT_RESERVED1, /**< Reserved for future use... */ + SDL_EVENT_RESERVED2, /**< Reserved for future use... */ + SDL_EVENT_RESERVED3, /**< Reserved for future use... */ + /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */ + SDL_USEREVENT = 24, + /* This last event is only for bounding internal arrays + It is the number of bits in the event mask datatype -- Uint32 + */ + SDL_NUMEVENTS = 32 } SDL_EventType; -/* Predefined event masks */ +/** + * \enum SDL_EventMask + * + * \brief Predefined event masks + */ #define SDL_EVENTMASK(X) (1<<(X)) -typedef enum { - SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT), - SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN), - SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP), - SDL_KEYEVENTMASK = SDL_EVENTMASK(SDL_KEYDOWN)| - SDL_EVENTMASK(SDL_KEYUP), - SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION), - SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN), - SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONUP), - SDL_MOUSEEVENTMASK = SDL_EVENTMASK(SDL_MOUSEMOTION)| - SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)| - SDL_EVENTMASK(SDL_MOUSEBUTTONUP), - SDL_JOYAXISMOTIONMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION), - SDL_JOYBALLMOTIONMASK = SDL_EVENTMASK(SDL_JOYBALLMOTION), - SDL_JOYHATMOTIONMASK = SDL_EVENTMASK(SDL_JOYHATMOTION), - SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK(SDL_JOYBUTTONDOWN), - SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP), - SDL_JOYEVENTMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION)| - SDL_EVENTMASK(SDL_JOYBALLMOTION)| - SDL_EVENTMASK(SDL_JOYHATMOTION)| - SDL_EVENTMASK(SDL_JOYBUTTONDOWN)| - SDL_EVENTMASK(SDL_JOYBUTTONUP), - SDL_VIDEORESIZEMASK = SDL_EVENTMASK(SDL_VIDEORESIZE), - SDL_VIDEOEXPOSEMASK = SDL_EVENTMASK(SDL_VIDEOEXPOSE), - SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT), - SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT) -} SDL_EventMask ; +typedef enum +{ + SDL_WINDOWEVENTMASK = SDL_EVENTMASK (SDL_WINDOWEVENT), + SDL_KEYDOWNMASK = SDL_EVENTMASK (SDL_KEYDOWN), + SDL_KEYUPMASK = SDL_EVENTMASK (SDL_KEYUP), + SDL_KEYEVENTMASK = SDL_EVENTMASK (SDL_KEYDOWN) | + SDL_EVENTMASK (SDL_KEYUP), + SDL_MOUSEMOTIONMASK = SDL_EVENTMASK (SDL_MOUSEMOTION), + SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN), + SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK (SDL_MOUSEBUTTONUP), + SDL_MOUSEEVENTMASK = SDL_EVENTMASK (SDL_MOUSEMOTION) | + SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN) | + SDL_EVENTMASK (SDL_MOUSEBUTTONUP), + SDL_JOYAXISMOTIONMASK = SDL_EVENTMASK (SDL_JOYAXISMOTION), + SDL_JOYBALLMOTIONMASK = SDL_EVENTMASK (SDL_JOYBALLMOTION), + SDL_JOYHATMOTIONMASK = SDL_EVENTMASK (SDL_JOYHATMOTION), + SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK (SDL_JOYBUTTONDOWN), + SDL_JOYBUTTONUPMASK = SDL_EVENTMASK (SDL_JOYBUTTONUP), + SDL_JOYEVENTMASK = SDL_EVENTMASK (SDL_JOYAXISMOTION) | + SDL_EVENTMASK (SDL_JOYBALLMOTION) | + SDL_EVENTMASK (SDL_JOYHATMOTION) | + SDL_EVENTMASK (SDL_JOYBUTTONDOWN) | SDL_EVENTMASK (SDL_JOYBUTTONUP), + SDL_QUITMASK = SDL_EVENTMASK (SDL_QUIT), + SDL_SYSWMEVENTMASK = SDL_EVENTMASK (SDL_SYSWMEVENT) +} SDL_EventMask; #define SDL_ALLEVENTS 0xFFFFFFFF -/* Application visibility event structure */ -typedef struct SDL_ActiveEvent { - Uint8 type; /* SDL_ACTIVEEVENT */ - Uint8 gain; /* Whether given states were gained or lost (1/0) */ - Uint8 state; /* A mask of the focus states */ -} SDL_ActiveEvent; - -/* Keyboard event structure */ -typedef struct SDL_KeyboardEvent { - Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */ - Uint8 which; /* The keyboard device index */ - Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ - SDL_keysym keysym; +/** + * \struct SDL_WindowEvent + * + * \brief Window state change event data + */ +typedef struct SDL_WindowEvent +{ + Uint8 type; /**< SDL_WINDOWEVENT */ + Uint8 event; /**< SDL_WindowEventID */ + int data1; /**< event dependent data */ + int data2; /**< event dependent data */ + SDL_WindowID windowID; /**< The associated window */ +} SDL_WindowEvent; + +/** + * \struct SDL_KeyboardEvent + * + * \brief Keyboard event structure + */ +typedef struct SDL_KeyboardEvent +{ + Uint8 type; /**< SDL_KEYDOWN or SDL_KEYUP */ + Uint8 which; /**< The keyboard device index */ + Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ + SDL_keysym keysym; /**< The key that was pressed or released */ + SDL_WindowID windowID; /**< The window with keyboard focus, if any */ } SDL_KeyboardEvent; -/* Mouse motion event structure */ -typedef struct SDL_MouseMotionEvent { - Uint8 type; /* SDL_MOUSEMOTION */ - Uint8 which; /* The mouse device index */ - Uint8 state; /* The current button state */ - Uint16 x, y; /* The X/Y coordinates of the mouse */ - Sint16 xrel; /* The relative motion in the X direction */ - Sint16 yrel; /* The relative motion in the Y direction */ +/** + * \struct SDL_MouseMotionEvent + * + * \brief Mouse motion event structure + */ +typedef struct SDL_MouseMotionEvent +{ + Uint8 type; /**< SDL_MOUSEMOTION */ + Uint8 which; /**< The mouse device index */ + Uint8 state; /**< The current button state */ + int x; /**< X coordinate, relative to window */ + int y; /**< Y coordinate, relative to window */ + int xrel; /**< The relative motion in the X direction */ + int yrel; /**< The relative motion in the Y direction */ + SDL_WindowID windowID; /**< The window with mouse focus, if any */ } SDL_MouseMotionEvent; -/* Mouse button event structure */ -typedef struct SDL_MouseButtonEvent { - Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ - Uint8 which; /* The mouse device index */ - Uint8 button; /* The mouse button index */ - Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ - Uint16 x, y; /* The X/Y coordinates of the mouse at press time */ +/** + * \struct SDL_MouseButtonEvent + * + * \brief Mouse button event structure + */ +typedef struct SDL_MouseButtonEvent +{ + Uint8 type; /**< SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ + Uint8 which; /**< The mouse device index */ + Uint8 button; /**< The mouse button index */ + Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ + int x; /**< X coordinate, relative to window */ + int y; /**< Y coordinate, relative to window */ + SDL_WindowID windowID; /**< The window with mouse focus, if any */ } SDL_MouseButtonEvent; -/* Joystick axis motion event structure */ -typedef struct SDL_JoyAxisEvent { - Uint8 type; /* SDL_JOYAXISMOTION */ - Uint8 which; /* The joystick device index */ - Uint8 axis; /* The joystick axis index */ - Sint16 value; /* The axis value (range: -32768 to 32767) */ +/** + * \struct SDL_JoyAxisEvent + * + * \brief Joystick axis motion event structure + */ +typedef struct SDL_JoyAxisEvent +{ + Uint8 type; /**< SDL_JOYAXISMOTION */ + Uint8 which; /**< The joystick device index */ + Uint8 axis; /**< The joystick axis index */ + int value; /**< The axis value (range: -32768 to 32767) */ } SDL_JoyAxisEvent; -/* Joystick trackball motion event structure */ -typedef struct SDL_JoyBallEvent { - Uint8 type; /* SDL_JOYBALLMOTION */ - Uint8 which; /* The joystick device index */ - Uint8 ball; /* The joystick trackball index */ - Sint16 xrel; /* The relative motion in the X direction */ - Sint16 yrel; /* The relative motion in the Y direction */ +/** + * \struct SDL_JoyBallEvent + * + * \brief Joystick trackball motion event structure + */ +typedef struct SDL_JoyBallEvent +{ + Uint8 type; /**< SDL_JOYBALLMOTION */ + Uint8 which; /**< The joystick device index */ + Uint8 ball; /**< The joystick trackball index */ + int xrel; /**< The relative motion in the X direction */ + int yrel; /**< The relative motion in the Y direction */ } SDL_JoyBallEvent; -/* Joystick hat position change event structure */ -typedef struct SDL_JoyHatEvent { - Uint8 type; /* SDL_JOYHATMOTION */ - Uint8 which; /* The joystick device index */ - Uint8 hat; /* The joystick hat index */ - Uint8 value; /* The hat position value: - SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP - SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT - SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN - Note that zero means the POV is centered. - */ +/** + * \struct SDL_JoyHatEvent + * + * \brief Joystick hat position change event structure + */ +typedef struct SDL_JoyHatEvent +{ + Uint8 type; /**< SDL_JOYHATMOTION */ + Uint8 which; /**< The joystick device index */ + Uint8 hat; /**< The joystick hat index */ + Uint8 value; /**< The hat position value: + SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP + SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT + SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN + Note that zero means the POV is centered. + */ } SDL_JoyHatEvent; -/* Joystick button event structure */ -typedef struct SDL_JoyButtonEvent { - Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */ - Uint8 which; /* The joystick device index */ - Uint8 button; /* The joystick button index */ - Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ +/** + * \struct SDL_JoyButtonEvent + * + * \brief Joystick button event structure + */ +typedef struct SDL_JoyButtonEvent +{ + Uint8 type; /**< SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */ + Uint8 which; /**< The joystick device index */ + Uint8 button; /**< The joystick button index */ + Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ } SDL_JoyButtonEvent; -/* The "window resized" event - When you get this event, you are responsible for setting a new video - mode with the new width and height. +/** + * \struct SDL_QuitEvent + * + * \brief The "quit requested" event */ -typedef struct SDL_ResizeEvent { - Uint8 type; /* SDL_VIDEORESIZE */ - int w; /* New width */ - int h; /* New height */ -} SDL_ResizeEvent; - -/* The "screen redraw" event */ -typedef struct SDL_ExposeEvent { - Uint8 type; /* SDL_VIDEOEXPOSE */ -} SDL_ExposeEvent; - -/* The "quit requested" event */ -typedef struct SDL_QuitEvent { - Uint8 type; /* SDL_QUIT */ +typedef struct SDL_QuitEvent +{ + Uint8 type; /**< SDL_QUIT */ } SDL_QuitEvent; -/* A user-defined event type */ -typedef struct SDL_UserEvent { - Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */ - int code; /* User defined event code */ - void *data1; /* User defined data pointer */ - void *data2; /* User defined data pointer */ +/** + * \struct SDL_UserEvent + * + * \brief A user-defined event type + */ +typedef struct SDL_UserEvent +{ + Uint8 type; /**< SDL_USEREVENT through SDL_NUMEVENTS-1 */ + int code; /**< User defined event code */ + void *data1; /**< User defined data pointer */ + void *data2; /**< User defined data pointer */ } SDL_UserEvent; -/* If you want to use this event, you should include SDL_syswm.h */ +/** + * \struct SDL_SysWMEvent + * + * \brief A video driver dependent system event + * + * \note If you want to use this event, you should include SDL_syswm.h + */ struct SDL_SysWMmsg; typedef struct SDL_SysWMmsg SDL_SysWMmsg; -typedef struct SDL_SysWMEvent { - Uint8 type; - SDL_SysWMmsg *msg; +typedef struct SDL_SysWMEvent +{ + Uint8 type; /**< SDL_SYSWMEVENT */ + SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */ } SDL_SysWMEvent; -/* General event structure */ -typedef union SDL_Event { - Uint8 type; - SDL_ActiveEvent active; - SDL_KeyboardEvent key; - SDL_MouseMotionEvent motion; - SDL_MouseButtonEvent button; - SDL_JoyAxisEvent jaxis; - SDL_JoyBallEvent jball; - SDL_JoyHatEvent jhat; - SDL_JoyButtonEvent jbutton; - SDL_ResizeEvent resize; - SDL_ExposeEvent expose; - SDL_QuitEvent quit; - SDL_UserEvent user; - SDL_SysWMEvent syswm; +/** + * \union SDL_Event + * + * \brief General event structure + */ +typedef union SDL_Event +{ + Uint8 type; /**< Event type, shared with all events */ + SDL_WindowEvent window; /**< Window event data */ + SDL_KeyboardEvent key; /**< Keyboard event data */ + SDL_MouseMotionEvent motion; /**< Mouse motion event data */ + SDL_MouseButtonEvent button; /**< Mouse button event data */ + SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */ + SDL_JoyBallEvent jball; /**< Joystick ball event data */ + SDL_JoyHatEvent jhat; /**< Joystick hat event data */ + SDL_JoyButtonEvent jbutton; /**< Joystick button event data */ + SDL_QuitEvent quit; /**< Quit request event data */ + SDL_UserEvent user; /**< Custom event data */ + SDL_SysWMEvent syswm; /**< System dependent window event data */ } SDL_Event; @@ -241,7 +299,7 @@ typedef union SDL_Event { This function updates the event queue and internal input device state. This should only be run in the thread that sets the video mode. */ -extern DECLSPEC void SDLCALL SDL_PumpEvents(void); +extern DECLSPEC void SDLCALL SDL_PumpEvents (void); /* Checks the event queue for messages and optionally returns them. If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to @@ -255,32 +313,34 @@ extern DECLSPEC void SDLCALL SDL_PumpEvents(void); This function returns the number of events actually stored, or -1 if there was an error. This function is thread-safe. */ -typedef enum { - SDL_ADDEVENT, - SDL_PEEKEVENT, - SDL_GETEVENT +typedef enum +{ + SDL_ADDEVENT, + SDL_PEEKEVENT, + SDL_GETEVENT } SDL_eventaction; /* */ -extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents, - SDL_eventaction action, Uint32 mask); +extern DECLSPEC int SDLCALL SDL_PeepEvents (SDL_Event * events, int numevents, + SDL_eventaction action, + Uint32 mask); /* Polls for currently pending events, and returns 1 if there are any pending events, or 0 if there are none available. If 'event' is not NULL, the next event is removed from the queue and stored in that area. */ -extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event *event); +extern DECLSPEC int SDLCALL SDL_PollEvent (SDL_Event * event); /* Waits indefinitely for the next available event, returning 1, or 0 if there was an error while waiting for events. If 'event' is not NULL, the next event is removed from the queue and stored in that area. */ -extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event *event); +extern DECLSPEC int SDLCALL SDL_WaitEvent (SDL_Event * event); /* Add an event to the event queue. This function returns 0 on success, or -1 if the event queue was full or there was some other error. */ -extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event); +extern DECLSPEC int SDLCALL SDL_PushEvent (SDL_Event * event); /* This function sets up a filter to process all events before they @@ -288,7 +348,7 @@ extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event); The filter is protypted as: */ -typedef int (SDLCALL *SDL_EventFilter)(const SDL_Event *event); +typedef int (SDLCALL * SDL_EventFilter) (const SDL_Event * event); /* If the filter returns 1, then the event will be added to the internal queue. If it returns 0, then the event will be dropped from the queue, but the @@ -305,13 +365,13 @@ typedef int (SDLCALL *SDL_EventFilter)(const SDL_Event *event); If the quit event is generated by an interrupt signal, it will bypass the internal queue and be delivered to the application at the next event poll. */ -extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter); +extern DECLSPEC void SDLCALL SDL_SetEventFilter (SDL_EventFilter filter); /* Return the current event filter - can be used to "chain" filters. If there is no event filter set, this function returns NULL. */ -extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter(void); +extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter (void); /* This function allows you to set the state of processing certain events. @@ -325,13 +385,17 @@ extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter(void); #define SDL_IGNORE 0 #define SDL_DISABLE 0 #define SDL_ENABLE 1 -extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint8 type, int state); +extern DECLSPEC Uint8 SDLCALL SDL_EventState (Uint8 type, int state); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_events_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_getenv.h b/include/SDL_getenv.h deleted file mode 100644 index 853b9ce45..000000000 --- a/include/SDL_getenv.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ - -/* DEPRECATED */ -#include "SDL_stdinc.h" diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index e4f72f1a4..771f82865 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* Include file for SDL joystick event handling */ +/** + * \file SDL_joystick.h + * + * Include file for SDL joystick event handling + */ #ifndef _SDL_joystick_h #define _SDL_joystick_h @@ -31,7 +35,9 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* In order to use these functions, SDL_Init() must have been called @@ -48,14 +54,14 @@ typedef struct _SDL_Joystick SDL_Joystick; /* * Count the number of joysticks attached to the system */ -extern DECLSPEC int SDLCALL SDL_NumJoysticks(void); +extern DECLSPEC int SDLCALL SDL_NumJoysticks (void); /* * Get the implementation dependent name of a joystick. * This can be called before any joysticks are opened. * If no name can be found, this function returns NULL. */ -extern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index); +extern DECLSPEC const char *SDLCALL SDL_JoystickName (int device_index); /* * Open a joystick for use - the index passed as an argument refers to @@ -64,46 +70,46 @@ extern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index); * * This function returns a joystick identifier, or NULL if an error occurred. */ -extern DECLSPEC SDL_Joystick * SDLCALL SDL_JoystickOpen(int device_index); +extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen (int device_index); /* * Returns 1 if the joystick has been opened, or 0 if it has not. */ -extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index); +extern DECLSPEC int SDLCALL SDL_JoystickOpened (int device_index); /* * Get the device index of an opened joystick. */ -extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick *joystick); +extern DECLSPEC int SDLCALL SDL_JoystickIndex (SDL_Joystick * joystick); /* * Get the number of general axis controls on a joystick */ -extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick); +extern DECLSPEC int SDLCALL SDL_JoystickNumAxes (SDL_Joystick * joystick); /* * Get the number of trackballs on a joystick * Joystick trackballs have only relative motion events associated * with them and their state cannot be polled. */ -extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick); +extern DECLSPEC int SDLCALL SDL_JoystickNumBalls (SDL_Joystick * joystick); /* * Get the number of POV hats on a joystick */ -extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick); +extern DECLSPEC int SDLCALL SDL_JoystickNumHats (SDL_Joystick * joystick); /* * Get the number of buttons on a joystick */ -extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick); +extern DECLSPEC int SDLCALL SDL_JoystickNumButtons (SDL_Joystick * joystick); /* * Update the current state of the open joysticks. * This is called automatically by the event loop if any joystick * events are enabled. */ -extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void); +extern DECLSPEC void SDLCALL SDL_JoystickUpdate (void); /* * Enable/disable joystick event polling. @@ -112,14 +118,15 @@ extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void); * information. * The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE. */ -extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state); +extern DECLSPEC int SDLCALL SDL_JoystickEventState (int state); /* * Get the current state of an axis control on a joystick * The state is a value ranging from -32768 to 32767. * The axis indices start at index 0. */ -extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis); +extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis (SDL_Joystick * joystick, + int axis); /* * Get the current state of a POV hat on a joystick @@ -137,31 +144,38 @@ extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int a /* * The hat indices start at index 0. */ -extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, int hat); +extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat (SDL_Joystick * joystick, + int hat); /* * Get the ball axis change since the last poll * This returns 0, or -1 if you passed it invalid parameters. * The ball indices start at index 0. */ -extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy); +extern DECLSPEC int SDLCALL SDL_JoystickGetBall (SDL_Joystick * joystick, + int ball, int *dx, int *dy); /* * Get the current state of a button on a joystick * The button indices start at index 0. */ -extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, int button); +extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton (SDL_Joystick * joystick, + int button); /* * Close a joystick previously opened with SDL_JoystickOpen() */ -extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick); +extern DECLSPEC void SDLCALL SDL_JoystickClose (SDL_Joystick * joystick); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_joystick_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_keyboard.h b/include/SDL_keyboard.h index 1ad7dcaa4..0a0cdf124 100644 --- a/include/SDL_keyboard.h +++ b/include/SDL_keyboard.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* Include file for SDL keyboard event handling */ +/** + * \file SDL_keyboard.h + * + * Include file for SDL keyboard event handling + */ #ifndef _SDL_keyboard_h #define _SDL_keyboard_h @@ -32,7 +36,9 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* Keysym structure @@ -51,11 +57,12 @@ extern "C" { An international character.. } */ -typedef struct SDL_keysym { - Uint8 scancode; /* hardware specific scancode */ - SDLKey sym; /* SDL virtual keysym */ - SDLMod mod; /* current key modifiers */ - Uint16 unicode; /* translated character */ +typedef struct SDL_keysym +{ + Uint8 scancode; /* hardware specific scancode */ + SDLKey sym; /* SDL virtual keysym */ + SDLMod mod; /* current key modifiers */ + Uint16 unicode; /* translated character */ } SDL_keysym; /* This is the mask which refers to all hotkey bindings */ @@ -70,7 +77,7 @@ typedef struct SDL_keysym { * If 'enable' is -1, the translation state is not changed. * It returns the previous state of keyboard translation. */ -extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); +extern DECLSPEC int SDLCALL SDL_EnableUNICODE (int enable); /* * Enable/Disable keyboard repeat. Keyboard repeat defaults to off. @@ -83,8 +90,8 @@ extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); /* * If 'delay' is set to 0, keyboard repeat is disabled. */ -extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); -extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); +extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat (int delay, int interval); +extern DECLSPEC void SDLCALL SDL_GetKeyRepeat (int *delay, int *interval); /* * Get a snapshot of the current state of the keyboard. @@ -93,29 +100,33 @@ extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); * Uint8 *keystate = SDL_GetKeyState(NULL); * if ( keystate[SDLK_RETURN] ) ... is pressed. */ -extern DECLSPEC Uint8 * SDLCALL SDL_GetKeyState(int *numkeys); +extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState (int *numkeys); /* * Get the current key modifier state */ -extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void); +extern DECLSPEC SDLMod SDLCALL SDL_GetModState (void); /* * Set the current key modifier state * This does not change the keyboard state, only the key modifier flags. */ -extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate); +extern DECLSPEC void SDLCALL SDL_SetModState (SDLMod modstate); /* * Get the name of an SDL virtual keysym */ -extern DECLSPEC char * SDLCALL SDL_GetKeyName(SDLKey key); +extern DECLSPEC char *SDLCALL SDL_GetKeyName (SDLKey key); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_keyboard_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_keysym.h b/include/SDL_keysym.h index ff44a035f..f660d8750 100644 --- a/include/SDL_keysym.h +++ b/include/SDL_keysym.h @@ -20,6 +20,10 @@ slouken@libsdl.org */ +/** + * \file SDL_keysym.h + */ + #ifndef _SDL_keysym_h #define _SDL_keysym_h @@ -28,279 +32,281 @@ as international virtual keycodes. We'll follow in the footsteps of X11... The names of the keys */ - -typedef enum { - /* The keyboard syms have been cleverly chosen to map to ASCII */ - SDLK_UNKNOWN = 0, - SDLK_FIRST = 0, - SDLK_BACKSPACE = 8, - SDLK_TAB = 9, - SDLK_CLEAR = 12, - SDLK_RETURN = 13, - SDLK_PAUSE = 19, - SDLK_ESCAPE = 27, - SDLK_SPACE = 32, - SDLK_EXCLAIM = 33, - SDLK_QUOTEDBL = 34, - SDLK_HASH = 35, - SDLK_DOLLAR = 36, - SDLK_AMPERSAND = 38, - SDLK_QUOTE = 39, - SDLK_LEFTPAREN = 40, - SDLK_RIGHTPAREN = 41, - SDLK_ASTERISK = 42, - SDLK_PLUS = 43, - SDLK_COMMA = 44, - SDLK_MINUS = 45, - SDLK_PERIOD = 46, - SDLK_SLASH = 47, - SDLK_0 = 48, - SDLK_1 = 49, - SDLK_2 = 50, - SDLK_3 = 51, - SDLK_4 = 52, - SDLK_5 = 53, - SDLK_6 = 54, - SDLK_7 = 55, - SDLK_8 = 56, - SDLK_9 = 57, - SDLK_COLON = 58, - SDLK_SEMICOLON = 59, - SDLK_LESS = 60, - SDLK_EQUALS = 61, - SDLK_GREATER = 62, - SDLK_QUESTION = 63, - SDLK_AT = 64, - /* - Skip uppercase letters - */ - SDLK_LEFTBRACKET = 91, - SDLK_BACKSLASH = 92, - SDLK_RIGHTBRACKET = 93, - SDLK_CARET = 94, - SDLK_UNDERSCORE = 95, - SDLK_BACKQUOTE = 96, - SDLK_a = 97, - SDLK_b = 98, - SDLK_c = 99, - SDLK_d = 100, - SDLK_e = 101, - SDLK_f = 102, - SDLK_g = 103, - SDLK_h = 104, - SDLK_i = 105, - SDLK_j = 106, - SDLK_k = 107, - SDLK_l = 108, - SDLK_m = 109, - SDLK_n = 110, - SDLK_o = 111, - SDLK_p = 112, - SDLK_q = 113, - SDLK_r = 114, - SDLK_s = 115, - SDLK_t = 116, - SDLK_u = 117, - SDLK_v = 118, - SDLK_w = 119, - SDLK_x = 120, - SDLK_y = 121, - SDLK_z = 122, - SDLK_DELETE = 127, - /* End of ASCII mapped keysyms */ - /* International keyboard syms */ - SDLK_WORLD_0 = 160, /* 0xA0 */ - SDLK_WORLD_1 = 161, - SDLK_WORLD_2 = 162, - SDLK_WORLD_3 = 163, - SDLK_WORLD_4 = 164, - SDLK_WORLD_5 = 165, - SDLK_WORLD_6 = 166, - SDLK_WORLD_7 = 167, - SDLK_WORLD_8 = 168, - SDLK_WORLD_9 = 169, - SDLK_WORLD_10 = 170, - SDLK_WORLD_11 = 171, - SDLK_WORLD_12 = 172, - SDLK_WORLD_13 = 173, - SDLK_WORLD_14 = 174, - SDLK_WORLD_15 = 175, - SDLK_WORLD_16 = 176, - SDLK_WORLD_17 = 177, - SDLK_WORLD_18 = 178, - SDLK_WORLD_19 = 179, - SDLK_WORLD_20 = 180, - SDLK_WORLD_21 = 181, - SDLK_WORLD_22 = 182, - SDLK_WORLD_23 = 183, - SDLK_WORLD_24 = 184, - SDLK_WORLD_25 = 185, - SDLK_WORLD_26 = 186, - SDLK_WORLD_27 = 187, - SDLK_WORLD_28 = 188, - SDLK_WORLD_29 = 189, - SDLK_WORLD_30 = 190, - SDLK_WORLD_31 = 191, - SDLK_WORLD_32 = 192, - SDLK_WORLD_33 = 193, - SDLK_WORLD_34 = 194, - SDLK_WORLD_35 = 195, - SDLK_WORLD_36 = 196, - SDLK_WORLD_37 = 197, - SDLK_WORLD_38 = 198, - SDLK_WORLD_39 = 199, - SDLK_WORLD_40 = 200, - SDLK_WORLD_41 = 201, - SDLK_WORLD_42 = 202, - SDLK_WORLD_43 = 203, - SDLK_WORLD_44 = 204, - SDLK_WORLD_45 = 205, - SDLK_WORLD_46 = 206, - SDLK_WORLD_47 = 207, - SDLK_WORLD_48 = 208, - SDLK_WORLD_49 = 209, - SDLK_WORLD_50 = 210, - SDLK_WORLD_51 = 211, - SDLK_WORLD_52 = 212, - SDLK_WORLD_53 = 213, - SDLK_WORLD_54 = 214, - SDLK_WORLD_55 = 215, - SDLK_WORLD_56 = 216, - SDLK_WORLD_57 = 217, - SDLK_WORLD_58 = 218, - SDLK_WORLD_59 = 219, - SDLK_WORLD_60 = 220, - SDLK_WORLD_61 = 221, - SDLK_WORLD_62 = 222, - SDLK_WORLD_63 = 223, - SDLK_WORLD_64 = 224, - SDLK_WORLD_65 = 225, - SDLK_WORLD_66 = 226, - SDLK_WORLD_67 = 227, - SDLK_WORLD_68 = 228, - SDLK_WORLD_69 = 229, - SDLK_WORLD_70 = 230, - SDLK_WORLD_71 = 231, - SDLK_WORLD_72 = 232, - SDLK_WORLD_73 = 233, - SDLK_WORLD_74 = 234, - SDLK_WORLD_75 = 235, - SDLK_WORLD_76 = 236, - SDLK_WORLD_77 = 237, - SDLK_WORLD_78 = 238, - SDLK_WORLD_79 = 239, - SDLK_WORLD_80 = 240, - SDLK_WORLD_81 = 241, - SDLK_WORLD_82 = 242, - SDLK_WORLD_83 = 243, - SDLK_WORLD_84 = 244, - SDLK_WORLD_85 = 245, - SDLK_WORLD_86 = 246, - SDLK_WORLD_87 = 247, - SDLK_WORLD_88 = 248, - SDLK_WORLD_89 = 249, - SDLK_WORLD_90 = 250, - SDLK_WORLD_91 = 251, - SDLK_WORLD_92 = 252, - SDLK_WORLD_93 = 253, - SDLK_WORLD_94 = 254, - SDLK_WORLD_95 = 255, /* 0xFF */ +typedef enum +{ + /* The keyboard syms have been cleverly chosen to map to ASCII */ + SDLK_UNKNOWN = 0, + SDLK_FIRST = 0, + SDLK_BACKSPACE = 8, + SDLK_TAB = 9, + SDLK_CLEAR = 12, + SDLK_RETURN = 13, + SDLK_PAUSE = 19, + SDLK_ESCAPE = 27, + SDLK_SPACE = 32, + SDLK_EXCLAIM = 33, + SDLK_QUOTEDBL = 34, + SDLK_HASH = 35, + SDLK_DOLLAR = 36, + SDLK_AMPERSAND = 38, + SDLK_QUOTE = 39, + SDLK_LEFTPAREN = 40, + SDLK_RIGHTPAREN = 41, + SDLK_ASTERISK = 42, + SDLK_PLUS = 43, + SDLK_COMMA = 44, + SDLK_MINUS = 45, + SDLK_PERIOD = 46, + SDLK_SLASH = 47, + SDLK_0 = 48, + SDLK_1 = 49, + SDLK_2 = 50, + SDLK_3 = 51, + SDLK_4 = 52, + SDLK_5 = 53, + SDLK_6 = 54, + SDLK_7 = 55, + SDLK_8 = 56, + SDLK_9 = 57, + SDLK_COLON = 58, + SDLK_SEMICOLON = 59, + SDLK_LESS = 60, + SDLK_EQUALS = 61, + SDLK_GREATER = 62, + SDLK_QUESTION = 63, + SDLK_AT = 64, + /* + Skip uppercase letters + */ + SDLK_LEFTBRACKET = 91, + SDLK_BACKSLASH = 92, + SDLK_RIGHTBRACKET = 93, + SDLK_CARET = 94, + SDLK_UNDERSCORE = 95, + SDLK_BACKQUOTE = 96, + SDLK_a = 97, + SDLK_b = 98, + SDLK_c = 99, + SDLK_d = 100, + SDLK_e = 101, + SDLK_f = 102, + SDLK_g = 103, + SDLK_h = 104, + SDLK_i = 105, + SDLK_j = 106, + SDLK_k = 107, + SDLK_l = 108, + SDLK_m = 109, + SDLK_n = 110, + SDLK_o = 111, + SDLK_p = 112, + SDLK_q = 113, + SDLK_r = 114, + SDLK_s = 115, + SDLK_t = 116, + SDLK_u = 117, + SDLK_v = 118, + SDLK_w = 119, + SDLK_x = 120, + SDLK_y = 121, + SDLK_z = 122, + SDLK_DELETE = 127, + /* End of ASCII mapped keysyms */ + + /* International keyboard syms */ + SDLK_WORLD_0 = 160, /* 0xA0 */ + SDLK_WORLD_1 = 161, + SDLK_WORLD_2 = 162, + SDLK_WORLD_3 = 163, + SDLK_WORLD_4 = 164, + SDLK_WORLD_5 = 165, + SDLK_WORLD_6 = 166, + SDLK_WORLD_7 = 167, + SDLK_WORLD_8 = 168, + SDLK_WORLD_9 = 169, + SDLK_WORLD_10 = 170, + SDLK_WORLD_11 = 171, + SDLK_WORLD_12 = 172, + SDLK_WORLD_13 = 173, + SDLK_WORLD_14 = 174, + SDLK_WORLD_15 = 175, + SDLK_WORLD_16 = 176, + SDLK_WORLD_17 = 177, + SDLK_WORLD_18 = 178, + SDLK_WORLD_19 = 179, + SDLK_WORLD_20 = 180, + SDLK_WORLD_21 = 181, + SDLK_WORLD_22 = 182, + SDLK_WORLD_23 = 183, + SDLK_WORLD_24 = 184, + SDLK_WORLD_25 = 185, + SDLK_WORLD_26 = 186, + SDLK_WORLD_27 = 187, + SDLK_WORLD_28 = 188, + SDLK_WORLD_29 = 189, + SDLK_WORLD_30 = 190, + SDLK_WORLD_31 = 191, + SDLK_WORLD_32 = 192, + SDLK_WORLD_33 = 193, + SDLK_WORLD_34 = 194, + SDLK_WORLD_35 = 195, + SDLK_WORLD_36 = 196, + SDLK_WORLD_37 = 197, + SDLK_WORLD_38 = 198, + SDLK_WORLD_39 = 199, + SDLK_WORLD_40 = 200, + SDLK_WORLD_41 = 201, + SDLK_WORLD_42 = 202, + SDLK_WORLD_43 = 203, + SDLK_WORLD_44 = 204, + SDLK_WORLD_45 = 205, + SDLK_WORLD_46 = 206, + SDLK_WORLD_47 = 207, + SDLK_WORLD_48 = 208, + SDLK_WORLD_49 = 209, + SDLK_WORLD_50 = 210, + SDLK_WORLD_51 = 211, + SDLK_WORLD_52 = 212, + SDLK_WORLD_53 = 213, + SDLK_WORLD_54 = 214, + SDLK_WORLD_55 = 215, + SDLK_WORLD_56 = 216, + SDLK_WORLD_57 = 217, + SDLK_WORLD_58 = 218, + SDLK_WORLD_59 = 219, + SDLK_WORLD_60 = 220, + SDLK_WORLD_61 = 221, + SDLK_WORLD_62 = 222, + SDLK_WORLD_63 = 223, + SDLK_WORLD_64 = 224, + SDLK_WORLD_65 = 225, + SDLK_WORLD_66 = 226, + SDLK_WORLD_67 = 227, + SDLK_WORLD_68 = 228, + SDLK_WORLD_69 = 229, + SDLK_WORLD_70 = 230, + SDLK_WORLD_71 = 231, + SDLK_WORLD_72 = 232, + SDLK_WORLD_73 = 233, + SDLK_WORLD_74 = 234, + SDLK_WORLD_75 = 235, + SDLK_WORLD_76 = 236, + SDLK_WORLD_77 = 237, + SDLK_WORLD_78 = 238, + SDLK_WORLD_79 = 239, + SDLK_WORLD_80 = 240, + SDLK_WORLD_81 = 241, + SDLK_WORLD_82 = 242, + SDLK_WORLD_83 = 243, + SDLK_WORLD_84 = 244, + SDLK_WORLD_85 = 245, + SDLK_WORLD_86 = 246, + SDLK_WORLD_87 = 247, + SDLK_WORLD_88 = 248, + SDLK_WORLD_89 = 249, + SDLK_WORLD_90 = 250, + SDLK_WORLD_91 = 251, + SDLK_WORLD_92 = 252, + SDLK_WORLD_93 = 253, + SDLK_WORLD_94 = 254, + SDLK_WORLD_95 = 255, /* 0xFF */ - /* Numeric keypad */ - SDLK_KP0 = 256, - SDLK_KP1 = 257, - SDLK_KP2 = 258, - SDLK_KP3 = 259, - SDLK_KP4 = 260, - SDLK_KP5 = 261, - SDLK_KP6 = 262, - SDLK_KP7 = 263, - SDLK_KP8 = 264, - SDLK_KP9 = 265, - SDLK_KP_PERIOD = 266, - SDLK_KP_DIVIDE = 267, - SDLK_KP_MULTIPLY = 268, - SDLK_KP_MINUS = 269, - SDLK_KP_PLUS = 270, - SDLK_KP_ENTER = 271, - SDLK_KP_EQUALS = 272, + /* Numeric keypad */ + SDLK_KP0 = 256, + SDLK_KP1 = 257, + SDLK_KP2 = 258, + SDLK_KP3 = 259, + SDLK_KP4 = 260, + SDLK_KP5 = 261, + SDLK_KP6 = 262, + SDLK_KP7 = 263, + SDLK_KP8 = 264, + SDLK_KP9 = 265, + SDLK_KP_PERIOD = 266, + SDLK_KP_DIVIDE = 267, + SDLK_KP_MULTIPLY = 268, + SDLK_KP_MINUS = 269, + SDLK_KP_PLUS = 270, + SDLK_KP_ENTER = 271, + SDLK_KP_EQUALS = 272, - /* Arrows + Home/End pad */ - SDLK_UP = 273, - SDLK_DOWN = 274, - SDLK_RIGHT = 275, - SDLK_LEFT = 276, - SDLK_INSERT = 277, - SDLK_HOME = 278, - SDLK_END = 279, - SDLK_PAGEUP = 280, - SDLK_PAGEDOWN = 281, + /* Arrows + Home/End pad */ + SDLK_UP = 273, + SDLK_DOWN = 274, + SDLK_RIGHT = 275, + SDLK_LEFT = 276, + SDLK_INSERT = 277, + SDLK_HOME = 278, + SDLK_END = 279, + SDLK_PAGEUP = 280, + SDLK_PAGEDOWN = 281, - /* Function keys */ - SDLK_F1 = 282, - SDLK_F2 = 283, - SDLK_F3 = 284, - SDLK_F4 = 285, - SDLK_F5 = 286, - SDLK_F6 = 287, - SDLK_F7 = 288, - SDLK_F8 = 289, - SDLK_F9 = 290, - SDLK_F10 = 291, - SDLK_F11 = 292, - SDLK_F12 = 293, - SDLK_F13 = 294, - SDLK_F14 = 295, - SDLK_F15 = 296, + /* Function keys */ + SDLK_F1 = 282, + SDLK_F2 = 283, + SDLK_F3 = 284, + SDLK_F4 = 285, + SDLK_F5 = 286, + SDLK_F6 = 287, + SDLK_F7 = 288, + SDLK_F8 = 289, + SDLK_F9 = 290, + SDLK_F10 = 291, + SDLK_F11 = 292, + SDLK_F12 = 293, + SDLK_F13 = 294, + SDLK_F14 = 295, + SDLK_F15 = 296, - /* Key state modifier keys */ - SDLK_NUMLOCK = 300, - SDLK_CAPSLOCK = 301, - SDLK_SCROLLOCK = 302, - SDLK_RSHIFT = 303, - SDLK_LSHIFT = 304, - SDLK_RCTRL = 305, - SDLK_LCTRL = 306, - SDLK_RALT = 307, - SDLK_LALT = 308, - SDLK_RMETA = 309, - SDLK_LMETA = 310, - SDLK_LSUPER = 311, /* Left "Windows" key */ - SDLK_RSUPER = 312, /* Right "Windows" key */ - SDLK_MODE = 313, /* "Alt Gr" key */ - SDLK_COMPOSE = 314, /* Multi-key compose key */ + /* Key state modifier keys */ + SDLK_NUMLOCK = 300, + SDLK_CAPSLOCK = 301, + SDLK_SCROLLOCK = 302, + SDLK_RSHIFT = 303, + SDLK_LSHIFT = 304, + SDLK_RCTRL = 305, + SDLK_LCTRL = 306, + SDLK_RALT = 307, + SDLK_LALT = 308, + SDLK_RMETA = 309, + SDLK_LMETA = 310, + SDLK_LSUPER = 311, /* Left "Windows" key */ + SDLK_RSUPER = 312, /* Right "Windows" key */ + SDLK_MODE = 313, /* "Alt Gr" key */ + SDLK_COMPOSE = 314, /* Multi-key compose key */ - /* Miscellaneous function keys */ - SDLK_HELP = 315, - SDLK_PRINT = 316, - SDLK_SYSREQ = 317, - SDLK_BREAK = 318, - SDLK_MENU = 319, - SDLK_POWER = 320, /* Power Macintosh power key */ - SDLK_EURO = 321, /* Some european keyboards */ - SDLK_UNDO = 322, /* Atari keyboard has Undo */ + /* Miscellaneous function keys */ + SDLK_HELP = 315, + SDLK_PRINT = 316, + SDLK_SYSREQ = 317, + SDLK_BREAK = 318, + SDLK_MENU = 319, + SDLK_POWER = 320, /* Power Macintosh power key */ + SDLK_EURO = 321, /* Some european keyboards */ + SDLK_UNDO = 322, /* Atari keyboard has Undo */ - /* Add any other keys here */ + /* Add any other keys here */ - SDLK_LAST + SDLK_LAST } SDLKey; /* Enumeration of valid key mods (possibly OR'd together) */ -typedef enum { - KMOD_NONE = 0x0000, - KMOD_LSHIFT= 0x0001, - KMOD_RSHIFT= 0x0002, - KMOD_LCTRL = 0x0040, - KMOD_RCTRL = 0x0080, - KMOD_LALT = 0x0100, - KMOD_RALT = 0x0200, - KMOD_LMETA = 0x0400, - KMOD_RMETA = 0x0800, - KMOD_NUM = 0x1000, - KMOD_CAPS = 0x2000, - KMOD_MODE = 0x4000, - KMOD_RESERVED = 0x8000 +typedef enum +{ + KMOD_NONE = 0x0000, + KMOD_LSHIFT = 0x0001, + KMOD_RSHIFT = 0x0002, + KMOD_LCTRL = 0x0040, + KMOD_RCTRL = 0x0080, + KMOD_LALT = 0x0100, + KMOD_RALT = 0x0200, + KMOD_LMETA = 0x0400, + KMOD_RMETA = 0x0800, + KMOD_NUM = 0x1000, + KMOD_CAPS = 0x2000, + KMOD_MODE = 0x4000, + KMOD_RESERVED = 0x8000 } SDLMod; #define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL) diff --git a/include/SDL_loadso.h b/include/SDL_loadso.h index ce9644949..25f6c66c0 100644 --- a/include/SDL_loadso.h +++ b/include/SDL_loadso.h @@ -20,23 +20,24 @@ slouken@libsdl.org */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* System dependent library loading routines */ - -/* Some things to keep in mind: - - These functions only work on C function names. Other languages may - have name mangling and intrinsic language support that varies from - compiler to compiler. - - Make sure you declare your function pointers with the same calling - convention as the actual library function. Your code will crash - mysteriously if you do not do this. - - Avoid namespace collisions. If you load a symbol from the library, - it is not defined whether or not it goes into the global symbol - namespace for the application. If it does and it conflicts with - symbols in your code or other shared libraries, you will not get - the results you expect. :) -*/ - +/** + * \file SDL_loadso.h + * + * System dependent library loading routines + * + * Some things to keep in mind: + * - These functions only work on C function names. Other languages may + * have name mangling and intrinsic language support that varies from + * compiler to compiler. + * - Make sure you declare your function pointers with the same calling + * convention as the actual library function. Your code will crash + * mysteriously if you do not do this. + * - Avoid namespace collisions. If you load a symbol from the library, + * it is not defined whether or not it goes into the global symbol + * namespace for the application. If it does and it conflicts with + * symbols in your code or other shared libraries, you will not get + * the results you expect. :) + */ #ifndef _SDL_loadso_h #define _SDL_loadso_h @@ -47,28 +48,35 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* This function dynamically loads a shared object and returns a pointer * to the object handle (or NULL if there was an error). * The 'sofile' parameter is a system dependent name of the object file. */ -extern DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile); +extern DECLSPEC void *SDLCALL SDL_LoadObject (const char *sofile); /* Given an object handle, this function looks up the address of the * named function in the shared object and returns it. This address * is no longer valid after calling SDL_UnloadObject(). */ -extern DECLSPEC void * SDLCALL SDL_LoadFunction(void *handle, const char *name); +extern DECLSPEC void *SDLCALL SDL_LoadFunction (void *handle, + const char *name); /* Unload a shared object from memory */ -extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle); +extern DECLSPEC void SDLCALL SDL_UnloadObject (void *handle); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_loadso_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_main.h b/include/SDL_main.h index cf8b728dc..7b803ed84 100644 --- a/include/SDL_main.h +++ b/include/SDL_main.h @@ -50,7 +50,7 @@ extern "C" #define main SDL_main /* The prototype for the application's main() function */ -extern C_LINKAGE int SDL_main(int argc, char *argv[]); +extern C_LINKAGE int SDL_main (int argc, char *argv[]); /* From the SDL library code -- needed for registering the app on Win32 */ @@ -58,17 +58,22 @@ extern C_LINKAGE int SDL_main(int argc, char *argv[]); #include "begin_code.h" #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* This should be called from your WinMain() function, if any */ -extern DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst); +extern DECLSPEC void SDLCALL SDL_SetModuleHandle (void *hInst); /* This can also be called, but is no longer necessary */ -extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style, void *hInst); +extern DECLSPEC int SDLCALL SDL_RegisterApp (char *name, Uint32 style, + void *hInst); /* This can also be called, but is no longer necessary (SDL_Quit calls it) */ -extern DECLSPEC void SDLCALL SDL_UnregisterApp(void); +extern DECLSPEC void SDLCALL SDL_UnregisterApp (void); #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif @@ -78,17 +83,21 @@ extern DECLSPEC void SDLCALL SDL_UnregisterApp(void); #include "begin_code.h" #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* Forward declaration so we don't need to include QuickDraw.h */ struct QDGlobals; /* This should be called from your main() function, if any */ -extern DECLSPEC void SDLCALL SDL_InitQuickDraw(struct QDGlobals *the_qd); +extern DECLSPEC void SDLCALL SDL_InitQuickDraw (struct QDGlobals *the_qd); #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif @@ -96,3 +105,5 @@ extern DECLSPEC void SDLCALL SDL_InitQuickDraw(struct QDGlobals *the_qd); #endif /* Need to redefine main()? */ #endif /* _SDL_main_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_mouse.h b/include/SDL_mouse.h index c2364d859..fd554a145 100644 --- a/include/SDL_mouse.h +++ b/include/SDL_mouse.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* Include file for SDL mouse event handling */ +/** + * \file SDL_mouse.h + * + * Include file for SDL mouse event handling + */ #ifndef _SDL_mouse_h #define _SDL_mouse_h @@ -32,17 +36,20 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif -typedef struct WMcursor WMcursor; /* Implementation dependent */ -typedef struct SDL_Cursor { - SDL_Rect area; /* The area of the mouse cursor */ - Sint16 hot_x, hot_y; /* The "tip" of the cursor */ - Uint8 *data; /* B/W cursor data */ - Uint8 *mask; /* B/W cursor mask */ - Uint8 *save[2]; /* Place to save cursor area */ - WMcursor *wm_cursor; /* Window-manager cursor */ +typedef struct WMcursor WMcursor; /* Implementation dependent */ +typedef struct SDL_Cursor +{ + SDL_Rect area; /* The area of the mouse cursor */ + Sint16 hot_x, hot_y; /* The "tip" of the cursor */ + Uint8 *data; /* B/W cursor data */ + Uint8 *mask; /* B/W cursor mask */ + Uint8 *save[2]; /* Place to save cursor area */ + WMcursor *wm_cursor; /* Window-manager cursor */ } SDL_Cursor; /* Function prototypes */ @@ -52,7 +59,7 @@ typedef struct SDL_Cursor { * be tested using the SDL_BUTTON(X) macros, and x and y are set to the * current mouse cursor position. You can pass NULL for either x or y. */ -extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y); +extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState (int *x, int *y); /* * Retrieve the current state of the mouse. @@ -60,12 +67,12 @@ extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y); * be tested using the SDL_BUTTON(X) macros, and x and y are set to the * mouse deltas since the last call to SDL_GetRelativeMouseState(). */ -extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y); +extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState (int *x, int *y); /* * Set the position of the mouse cursor (generates a mouse motion event) */ -extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y); +extern DECLSPEC void SDLCALL SDL_WarpMouse (Uint16 x, Uint16 y); /* * Create a cursor using the specified data and mask (in MSB format). @@ -80,25 +87,25 @@ extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y); * * Cursors created with this function must be freed with SDL_FreeCursor(). */ -extern DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor - (Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); +extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor + (Uint8 * data, Uint8 * mask, int w, int h, int hot_x, int hot_y); /* * Set the currently active cursor to the specified one. * If the cursor is currently visible, the change will be immediately * represented on the display. */ -extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor *cursor); +extern DECLSPEC void SDLCALL SDL_SetCursor (SDL_Cursor * cursor); /* * Returns the currently active cursor. */ -extern DECLSPEC SDL_Cursor * SDLCALL SDL_GetCursor(void); +extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor (void); /* * Deallocates a cursor created with SDL_CreateCursor(). */ -extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor *cursor); +extern DECLSPEC void SDLCALL SDL_FreeCursor (SDL_Cursor * cursor); /* * Toggle whether or not the cursor is shown on the screen. @@ -107,7 +114,7 @@ extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor *cursor); * before the call, or 0 if it was not. You can query the current * state by passing a 'toggle' value of -1. */ -extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle); +extern DECLSPEC int SDLCALL SDL_ShowCursor (int toggle); /* Used as a mask when testing buttons in buttonstate Button 1: Left mouse button @@ -129,8 +136,12 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_mouse_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_mutex.h b/include/SDL_mutex.h index 00165281d..d22d6220a 100644 --- a/include/SDL_mutex.h +++ b/include/SDL_mutex.h @@ -23,10 +23,11 @@ #ifndef _SDL_mutex_h #define _SDL_mutex_h -/* Functions to provide thread synchronization primitives - - These are independent of the other SDL routines. -*/ +/** + * \file SDL_mutex.h + * + * Functions to provide thread synchronization primitives + */ #include "SDL_stdinc.h" #include "SDL_error.h" @@ -34,7 +35,9 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* Synchronization functions which can time out return this value @@ -55,21 +58,21 @@ struct SDL_mutex; typedef struct SDL_mutex SDL_mutex; /* Create a mutex, initialized unlocked */ -extern DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void); +extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex (void); /* Lock the mutex (Returns 0, or -1 on error) */ #define SDL_LockMutex(m) SDL_mutexP(m) -extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex); +extern DECLSPEC int SDLCALL SDL_mutexP (SDL_mutex * mutex); /* Unlock the mutex (Returns 0, or -1 on error) It is an error to unlock a mutex that has not been locked by the current thread, and doing so results in undefined behavior. */ #define SDL_UnlockMutex(m) SDL_mutexV(m) -extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex); +extern DECLSPEC int SDLCALL SDL_mutexV (SDL_mutex * mutex); /* Destroy a mutex */ -extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex); +extern DECLSPEC void SDLCALL SDL_DestroyMutex (SDL_mutex * mutex); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -81,21 +84,21 @@ struct SDL_semaphore; typedef struct SDL_semaphore SDL_sem; /* Create a semaphore, initialized with value, returns NULL on failure. */ -extern DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value); +extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore (Uint32 initial_value); /* Destroy a semaphore */ -extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem); +extern DECLSPEC void SDLCALL SDL_DestroySemaphore (SDL_sem * sem); /* This function suspends the calling thread until the semaphore pointed * to by sem has a positive count. It then atomically decreases the semaphore * count. */ -extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem); +extern DECLSPEC int SDLCALL SDL_SemWait (SDL_sem * sem); /* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error. */ -extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem); +extern DECLSPEC int SDLCALL SDL_SemTryWait (SDL_sem * sem); /* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in @@ -103,15 +106,15 @@ extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem); On some platforms this function is implemented by looping with a delay of 1 ms, and so should be avoided if possible. */ -extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms); +extern DECLSPEC int SDLCALL SDL_SemWaitTimeout (SDL_sem * sem, Uint32 ms); /* Atomically increases the semaphore's count (not blocking), returns 0, or -1 on error. */ -extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem); +extern DECLSPEC int SDLCALL SDL_SemPost (SDL_sem * sem); /* Returns the current count of the semaphore */ -extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem); +extern DECLSPEC Uint32 SDLCALL SDL_SemValue (SDL_sem * sem); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -123,27 +126,27 @@ struct SDL_cond; typedef struct SDL_cond SDL_cond; /* Create a condition variable */ -extern DECLSPEC SDL_cond * SDLCALL SDL_CreateCond(void); +extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond (void); /* Destroy a condition variable */ -extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond); +extern DECLSPEC void SDLCALL SDL_DestroyCond (SDL_cond * cond); /* Restart one of the threads that are waiting on the condition variable, returns 0 or -1 on error. */ -extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond); +extern DECLSPEC int SDLCALL SDL_CondSignal (SDL_cond * cond); /* Restart all threads that are waiting on the condition variable, returns 0 or -1 on error. */ -extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond); +extern DECLSPEC int SDLCALL SDL_CondBroadcast (SDL_cond * cond); /* Wait on the condition variable, unlocking the provided mutex. The mutex must be locked before entering this function! The mutex is re-locked once the condition variable is signaled. Returns 0 when it is signaled, or -1 on error. */ -extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut); +extern DECLSPEC int SDLCALL SDL_CondWait (SDL_cond * cond, SDL_mutex * mut); /* Waits for at most 'ms' milliseconds, and returns 0 if the condition variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not @@ -151,12 +154,18 @@ extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut); On some platforms this function is implemented by looping with a delay of 1 ms, and so should be avoided if possible. */ -extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms); +extern DECLSPEC int SDLCALL SDL_CondWaitTimeout (SDL_cond * cond, + SDL_mutex * mutex, + Uint32 ms); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_mutex_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_opengl.h b/include/SDL_opengl.h index 36c0a3099..14f24a3b2 100644 --- a/include/SDL_opengl.h +++ b/include/SDL_opengl.h @@ -20,29 +20,33 @@ slouken@libsdl.org */ -/* This is a simple file to encapsulate the OpenGL API headers */ +/** + * \file SDL_opengl.h + * + * This is a simple file to encapsulate the OpenGL API headers + */ #include "SDL_config.h" #ifdef __WIN32__ #define WIN32_LEAN_AND_MEAN #ifndef NOMINMAX -#define NOMINMAX /* Don't defined min() and max() */ +#define NOMINMAX /* Don't defined min() and max() */ #endif #include #endif #ifndef NO_SDL_GLEXT -#define __glext_h_ /* Don't let gl.h include glext.h */ +#define __glext_h_ /* Don't let gl.h include glext.h */ #endif #if defined(__MACOSX__) -#include /* Header File For The OpenGL Library */ -#include /* Header File For The GLU Library */ +#include /* Header File For The OpenGL Library */ +#include /* Header File For The GLU Library */ #elif defined(__MACOS__) -#include /* Header File For The OpenGL Library */ -#include /* Header File For The GLU Library */ +#include /* Header File For The OpenGL Library */ +#include /* Header File For The GLU Library */ #else -#include /* Header File For The OpenGL Library */ -#include /* Header File For The GLU Library */ +#include /* Header File For The OpenGL Library */ +#include /* Header File For The GLU Library */ #endif #ifndef NO_SDL_GLEXT #undef __glext_h_ @@ -57,7 +61,8 @@ #define __glext_h_ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif /* @@ -3099,642 +3104,1247 @@ extern "C" { #include #ifndef GL_VERSION_2_0 /* GL type for program/shader text */ -typedef char GLchar; /* native character */ + typedef char GLchar; /* native character */ #endif #ifndef GL_VERSION_1_5 /* GL types for handling large vertex buffer objects */ -typedef ptrdiff_t GLintptr; -typedef ptrdiff_t GLsizeiptr; + typedef ptrdiff_t GLintptr; + typedef ptrdiff_t GLsizeiptr; #endif #ifndef GL_ARB_vertex_buffer_object /* GL types for handling large vertex buffer objects */ -typedef ptrdiff_t GLintptrARB; -typedef ptrdiff_t GLsizeiptrARB; + typedef ptrdiff_t GLintptrARB; + typedef ptrdiff_t GLsizeiptrARB; #endif #ifndef GL_ARB_shader_objects /* GL types for handling shader object handles and program/shader text */ -typedef char GLcharARB; /* native character */ -typedef unsigned int GLhandleARB; /* shader object handle */ + typedef char GLcharARB; /* native character */ + typedef unsigned int GLhandleARB; /* shader object handle */ #endif /* GL types for "half" precision (s10e5) float data in host memory */ #ifndef GL_ARB_half_float_pixel -typedef unsigned short GLhalfARB; + typedef unsigned short GLhalfARB; #endif #ifndef GL_NV_half_float -typedef unsigned short GLhalfNV; + typedef unsigned short GLhalfNV; #endif #ifndef GL_VERSION_1_2 #define GL_VERSION_1_2 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendColor (GLclampf, GLclampf, GLclampf, GLclampf); -GLAPI void APIENTRY glBlendEquation (GLenum); -GLAPI void APIENTRY glDrawRangeElements (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); -GLAPI void APIENTRY glColorTable (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glColorTableParameterfv (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glColorTableParameteriv (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glCopyColorTable (GLenum, GLenum, GLint, GLint, GLsizei); -GLAPI void APIENTRY glGetColorTable (GLenum, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetColorTableParameterfv (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetColorTableParameteriv (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glColorSubTable (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glCopyColorSubTable (GLenum, GLsizei, GLint, GLint, GLsizei); -GLAPI void APIENTRY glConvolutionFilter1D (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glConvolutionFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glConvolutionParameterf (GLenum, GLenum, GLfloat); -GLAPI void APIENTRY glConvolutionParameterfv (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glConvolutionParameteri (GLenum, GLenum, GLint); -GLAPI void APIENTRY glConvolutionParameteriv (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum, GLenum, GLint, GLint, GLsizei); -GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); -GLAPI void APIENTRY glGetConvolutionFilter (GLenum, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetSeparableFilter (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); -GLAPI void APIENTRY glSeparableFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); -GLAPI void APIENTRY glGetHistogram (GLenum, GLboolean, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetHistogramParameterfv (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetHistogramParameteriv (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetMinmax (GLenum, GLboolean, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glHistogram (GLenum, GLsizei, GLenum, GLboolean); -GLAPI void APIENTRY glMinmax (GLenum, GLenum, GLboolean); -GLAPI void APIENTRY glResetHistogram (GLenum); -GLAPI void APIENTRY glResetMinmax (GLenum); -GLAPI void APIENTRY glTexImage3D (GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glCopyTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); -typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); -typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); -typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); -typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); -typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + GLAPI void APIENTRY glBlendColor (GLclampf, GLclampf, GLclampf, GLclampf); + GLAPI void APIENTRY glBlendEquation (GLenum); + GLAPI void APIENTRY glDrawRangeElements (GLenum, GLuint, GLuint, GLsizei, + GLenum, const GLvoid *); + GLAPI void APIENTRY glColorTable (GLenum, GLenum, GLsizei, GLenum, GLenum, + const GLvoid *); + GLAPI void APIENTRY glColorTableParameterfv (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glColorTableParameteriv (GLenum, GLenum, + const GLint *); + GLAPI void APIENTRY glCopyColorTable (GLenum, GLenum, GLint, GLint, + GLsizei); + GLAPI void APIENTRY glGetColorTable (GLenum, GLenum, GLenum, GLvoid *); + GLAPI void APIENTRY glGetColorTableParameterfv (GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetColorTableParameteriv (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glColorSubTable (GLenum, GLsizei, GLsizei, GLenum, + GLenum, const GLvoid *); + GLAPI void APIENTRY glCopyColorSubTable (GLenum, GLsizei, GLint, GLint, + GLsizei); + GLAPI void APIENTRY glConvolutionFilter1D (GLenum, GLenum, GLsizei, + GLenum, GLenum, + const GLvoid *); + GLAPI void APIENTRY glConvolutionFilter2D (GLenum, GLenum, GLsizei, + GLsizei, GLenum, GLenum, + const GLvoid *); + GLAPI void APIENTRY glConvolutionParameterf (GLenum, GLenum, GLfloat); + GLAPI void APIENTRY glConvolutionParameterfv (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glConvolutionParameteri (GLenum, GLenum, GLint); + GLAPI void APIENTRY glConvolutionParameteriv (GLenum, GLenum, + const GLint *); + GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum, GLenum, GLint, + GLint, GLsizei); + GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum, GLenum, GLint, + GLint, GLsizei, GLsizei); + GLAPI void APIENTRY glGetConvolutionFilter (GLenum, GLenum, GLenum, + GLvoid *); + GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetSeparableFilter (GLenum, GLenum, GLenum, + GLvoid *, GLvoid *, GLvoid *); + GLAPI void APIENTRY glSeparableFilter2D (GLenum, GLenum, GLsizei, GLsizei, + GLenum, GLenum, const GLvoid *, + const GLvoid *); + GLAPI void APIENTRY glGetHistogram (GLenum, GLboolean, GLenum, GLenum, + GLvoid *); + GLAPI void APIENTRY glGetHistogramParameterfv (GLenum, GLenum, GLfloat *); + GLAPI void APIENTRY glGetHistogramParameteriv (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetMinmax (GLenum, GLboolean, GLenum, GLenum, + GLvoid *); + GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum, GLenum, GLfloat *); + GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glHistogram (GLenum, GLsizei, GLenum, GLboolean); + GLAPI void APIENTRY glMinmax (GLenum, GLenum, GLboolean); + GLAPI void APIENTRY glResetHistogram (GLenum); + GLAPI void APIENTRY glResetMinmax (GLenum); + GLAPI void APIENTRY glTexImage3D (GLenum, GLint, GLint, GLsizei, GLsizei, + GLsizei, GLint, GLenum, GLenum, + const GLvoid *); + GLAPI void APIENTRY glTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, + GLsizei, GLsizei, GLsizei, GLenum, + GLenum, const GLvoid *); + GLAPI void APIENTRY glCopyTexSubImage3D (GLenum, GLint, GLint, GLint, + GLint, GLint, GLint, GLsizei, + GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, + GLclampf green, + GLclampf blue, + GLclampf alpha); + typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); + typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, + GLuint start, + GLuint end, + GLsizei count, + GLenum type, + const GLvoid * + indices); + typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, + GLenum internalformat, + GLsizei width, + GLenum format, GLenum type, + const GLvoid * table); + typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, + GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, + GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, + GLenum internalformat, + GLint x, GLint y, + GLsizei width); + typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, + GLenum format, + GLenum type, + GLvoid * table); + typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, + GLsizei start, + GLsizei count, + GLenum format, + GLenum type, + const GLvoid * data); + typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, + GLsizei start, + GLint x, GLint y, + GLsizei width); + typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, + GLenum + internalformat, + GLsizei width, + GLenum format, + GLenum type, + const GLvoid * + image); + typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + const GLvoid * + image); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, + GLenum pname, + GLfloat params); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, + GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, + GLenum pname, + GLint params); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, + GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, + GLenum + internalformat, + GLint x, + GLint y, + GLsizei width); + typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, + GLenum + internalformat, + GLint x, + GLint y, + GLsizei width, + GLsizei + height); + typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, + GLenum format, + GLenum type, + GLvoid * image); + typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum + target, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum + target, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, + GLenum format, + GLenum type, + GLvoid * row, + GLvoid * column, + GLvoid * span); + typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + const GLvoid * row, + const GLvoid * + column); + typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, + GLboolean reset, + GLenum format, + GLenum type, + GLvoid * values); + typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, + GLboolean reset, + GLenum format, GLenum type, + GLvoid * values); + typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, + GLenum pname, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, + GLenum internalformat, + GLboolean sink); + typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, + GLenum internalformat, + GLboolean sink); + typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); + typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); + typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid * pixels); + typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLsizei width, + GLsizei height, + GLsizei depth, + GLenum format, + GLenum type, + const GLvoid * pixels); + typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLint x, GLint y, + GLsizei width, + GLsizei height); #endif #ifndef GL_VERSION_1_3 #define GL_VERSION_1_3 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glActiveTexture (GLenum); -GLAPI void APIENTRY glClientActiveTexture (GLenum); -GLAPI void APIENTRY glMultiTexCoord1d (GLenum, GLdouble); -GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord1f (GLenum, GLfloat); -GLAPI void APIENTRY glMultiTexCoord1fv (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord1i (GLenum, GLint); -GLAPI void APIENTRY glMultiTexCoord1iv (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord1s (GLenum, GLshort); -GLAPI void APIENTRY glMultiTexCoord1sv (GLenum, const GLshort *); -GLAPI void APIENTRY glMultiTexCoord2d (GLenum, GLdouble, GLdouble); -GLAPI void APIENTRY glMultiTexCoord2dv (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord2f (GLenum, GLfloat, GLfloat); -GLAPI void APIENTRY glMultiTexCoord2fv (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord2i (GLenum, GLint, GLint); -GLAPI void APIENTRY glMultiTexCoord2iv (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord2s (GLenum, GLshort, GLshort); -GLAPI void APIENTRY glMultiTexCoord2sv (GLenum, const GLshort *); -GLAPI void APIENTRY glMultiTexCoord3d (GLenum, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glMultiTexCoord3dv (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord3f (GLenum, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glMultiTexCoord3fv (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord3i (GLenum, GLint, GLint, GLint); -GLAPI void APIENTRY glMultiTexCoord3iv (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord3s (GLenum, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glMultiTexCoord3sv (GLenum, const GLshort *); -GLAPI void APIENTRY glMultiTexCoord4d (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glMultiTexCoord4dv (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord4f (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glMultiTexCoord4fv (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord4i (GLenum, GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glMultiTexCoord4iv (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord4s (GLenum, GLshort, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glMultiTexCoord4sv (GLenum, const GLshort *); -GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *); -GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *); -GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *); -GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *); -GLAPI void APIENTRY glSampleCoverage (GLclampf, GLboolean); -GLAPI void APIENTRY glCompressedTexImage3D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexImage2D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexImage1D (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glGetCompressedTexImage (GLenum, GLint, GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); -typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); + GLAPI void APIENTRY glActiveTexture (GLenum); + GLAPI void APIENTRY glClientActiveTexture (GLenum); + GLAPI void APIENTRY glMultiTexCoord1d (GLenum, GLdouble); + GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord1f (GLenum, GLfloat); + GLAPI void APIENTRY glMultiTexCoord1fv (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord1i (GLenum, GLint); + GLAPI void APIENTRY glMultiTexCoord1iv (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord1s (GLenum, GLshort); + GLAPI void APIENTRY glMultiTexCoord1sv (GLenum, const GLshort *); + GLAPI void APIENTRY glMultiTexCoord2d (GLenum, GLdouble, GLdouble); + GLAPI void APIENTRY glMultiTexCoord2dv (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord2f (GLenum, GLfloat, GLfloat); + GLAPI void APIENTRY glMultiTexCoord2fv (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord2i (GLenum, GLint, GLint); + GLAPI void APIENTRY glMultiTexCoord2iv (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord2s (GLenum, GLshort, GLshort); + GLAPI void APIENTRY glMultiTexCoord2sv (GLenum, const GLshort *); + GLAPI void APIENTRY glMultiTexCoord3d (GLenum, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glMultiTexCoord3dv (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord3f (GLenum, GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glMultiTexCoord3fv (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord3i (GLenum, GLint, GLint, GLint); + GLAPI void APIENTRY glMultiTexCoord3iv (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord3s (GLenum, GLshort, GLshort, GLshort); + GLAPI void APIENTRY glMultiTexCoord3sv (GLenum, const GLshort *); + GLAPI void APIENTRY glMultiTexCoord4d (GLenum, GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glMultiTexCoord4dv (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord4f (GLenum, GLfloat, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glMultiTexCoord4fv (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord4i (GLenum, GLint, GLint, GLint, + GLint); + GLAPI void APIENTRY glMultiTexCoord4iv (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord4s (GLenum, GLshort, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glMultiTexCoord4sv (GLenum, const GLshort *); + GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *); + GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *); + GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *); + GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *); + GLAPI void APIENTRY glSampleCoverage (GLclampf, GLboolean); + GLAPI void APIENTRY glCompressedTexImage3D (GLenum, GLint, GLenum, + GLsizei, GLsizei, GLsizei, + GLint, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glCompressedTexImage2D (GLenum, GLint, GLenum, + GLsizei, GLsizei, GLint, + GLsizei, const GLvoid *); + GLAPI void APIENTRY glCompressedTexImage1D (GLenum, GLint, GLenum, + GLsizei, GLint, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum, GLint, GLint, + GLint, GLint, GLsizei, + GLsizei, GLsizei, GLenum, + GLsizei, const GLvoid *); + GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum, GLint, GLint, + GLint, GLsizei, GLsizei, + GLenum, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum, GLint, GLint, + GLsizei, GLenum, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glGetCompressedTexImage (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); + typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, + GLdouble s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, + const GLdouble * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, + GLfloat s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, + GLint s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, + GLshort s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, + const GLshort * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, + GLdouble s, + GLdouble t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, + const GLdouble * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, + GLfloat s, GLfloat t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, + GLint t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, + GLshort s, GLshort t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, + const GLshort * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, + GLdouble s, GLdouble t, + GLdouble r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, + const GLdouble * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, + GLfloat s, GLfloat t, + GLfloat r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, + GLint t, GLint r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, + GLshort s, GLshort t, + GLshort r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, + const GLshort * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, + GLdouble s, GLdouble t, + GLdouble r, + GLdouble q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, + const GLdouble * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, + GLfloat s, GLfloat t, + GLfloat r, GLfloat q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, + GLint t, GLint r, + GLint q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, + GLshort s, GLshort t, + GLshort r, GLshort q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, + const GLshort * v); + typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat * + m); + typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble * + m); + typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat * + m); + typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble * + m); + typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, + GLboolean invert); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLint border, + GLsizei imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLsizei imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLsizei width, + GLint border, + GLsizei imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLsizei width, + GLsizei height, + GLsizei depth, + GLenum format, + GLsizei + imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLsizei width, + GLsizei height, + GLenum format, + GLsizei + imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, + GLint level, + GLint xoffset, + GLsizei width, + GLenum format, + GLsizei + imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, + GLint level, + GLvoid * img); #endif #ifndef GL_VERSION_1_4 #define GL_VERSION_1_4 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendFuncSeparate (GLenum, GLenum, GLenum, GLenum); -GLAPI void APIENTRY glFogCoordf (GLfloat); -GLAPI void APIENTRY glFogCoordfv (const GLfloat *); -GLAPI void APIENTRY glFogCoordd (GLdouble); -GLAPI void APIENTRY glFogCoorddv (const GLdouble *); -GLAPI void APIENTRY glFogCoordPointer (GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glMultiDrawArrays (GLenum, GLint *, GLsizei *, GLsizei); -GLAPI void APIENTRY glMultiDrawElements (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); -GLAPI void APIENTRY glPointParameterf (GLenum, GLfloat); -GLAPI void APIENTRY glPointParameterfv (GLenum, const GLfloat *); -GLAPI void APIENTRY glPointParameteri (GLenum, GLint); -GLAPI void APIENTRY glPointParameteriv (GLenum, const GLint *); -GLAPI void APIENTRY glSecondaryColor3b (GLbyte, GLbyte, GLbyte); -GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *); -GLAPI void APIENTRY glSecondaryColor3d (GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *); -GLAPI void APIENTRY glSecondaryColor3f (GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *); -GLAPI void APIENTRY glSecondaryColor3i (GLint, GLint, GLint); -GLAPI void APIENTRY glSecondaryColor3iv (const GLint *); -GLAPI void APIENTRY glSecondaryColor3s (GLshort, GLshort, GLshort); -GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *); -GLAPI void APIENTRY glSecondaryColor3ub (GLubyte, GLubyte, GLubyte); -GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *); -GLAPI void APIENTRY glSecondaryColor3ui (GLuint, GLuint, GLuint); -GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *); -GLAPI void APIENTRY glSecondaryColor3us (GLushort, GLushort, GLushort); -GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *); -GLAPI void APIENTRY glSecondaryColorPointer (GLint, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glWindowPos2d (GLdouble, GLdouble); -GLAPI void APIENTRY glWindowPos2dv (const GLdouble *); -GLAPI void APIENTRY glWindowPos2f (GLfloat, GLfloat); -GLAPI void APIENTRY glWindowPos2fv (const GLfloat *); -GLAPI void APIENTRY glWindowPos2i (GLint, GLint); -GLAPI void APIENTRY glWindowPos2iv (const GLint *); -GLAPI void APIENTRY glWindowPos2s (GLshort, GLshort); -GLAPI void APIENTRY glWindowPos2sv (const GLshort *); -GLAPI void APIENTRY glWindowPos3d (GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glWindowPos3dv (const GLdouble *); -GLAPI void APIENTRY glWindowPos3f (GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glWindowPos3fv (const GLfloat *); -GLAPI void APIENTRY glWindowPos3i (GLint, GLint, GLint); -GLAPI void APIENTRY glWindowPos3iv (const GLint *); -GLAPI void APIENTRY glWindowPos3s (GLshort, GLshort, GLshort); -GLAPI void APIENTRY glWindowPos3sv (const GLshort *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); -typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); -typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); -typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); -typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); -typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); + GLAPI void APIENTRY glBlendFuncSeparate (GLenum, GLenum, GLenum, GLenum); + GLAPI void APIENTRY glFogCoordf (GLfloat); + GLAPI void APIENTRY glFogCoordfv (const GLfloat *); + GLAPI void APIENTRY glFogCoordd (GLdouble); + GLAPI void APIENTRY glFogCoorddv (const GLdouble *); + GLAPI void APIENTRY glFogCoordPointer (GLenum, GLsizei, const GLvoid *); + GLAPI void APIENTRY glMultiDrawArrays (GLenum, GLint *, GLsizei *, + GLsizei); + GLAPI void APIENTRY glMultiDrawElements (GLenum, const GLsizei *, GLenum, + const GLvoid * *, GLsizei); + GLAPI void APIENTRY glPointParameterf (GLenum, GLfloat); + GLAPI void APIENTRY glPointParameterfv (GLenum, const GLfloat *); + GLAPI void APIENTRY glPointParameteri (GLenum, GLint); + GLAPI void APIENTRY glPointParameteriv (GLenum, const GLint *); + GLAPI void APIENTRY glSecondaryColor3b (GLbyte, GLbyte, GLbyte); + GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *); + GLAPI void APIENTRY glSecondaryColor3d (GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *); + GLAPI void APIENTRY glSecondaryColor3f (GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *); + GLAPI void APIENTRY glSecondaryColor3i (GLint, GLint, GLint); + GLAPI void APIENTRY glSecondaryColor3iv (const GLint *); + GLAPI void APIENTRY glSecondaryColor3s (GLshort, GLshort, GLshort); + GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *); + GLAPI void APIENTRY glSecondaryColor3ub (GLubyte, GLubyte, GLubyte); + GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *); + GLAPI void APIENTRY glSecondaryColor3ui (GLuint, GLuint, GLuint); + GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *); + GLAPI void APIENTRY glSecondaryColor3us (GLushort, GLushort, GLushort); + GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *); + GLAPI void APIENTRY glSecondaryColorPointer (GLint, GLenum, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glWindowPos2d (GLdouble, GLdouble); + GLAPI void APIENTRY glWindowPos2dv (const GLdouble *); + GLAPI void APIENTRY glWindowPos2f (GLfloat, GLfloat); + GLAPI void APIENTRY glWindowPos2fv (const GLfloat *); + GLAPI void APIENTRY glWindowPos2i (GLint, GLint); + GLAPI void APIENTRY glWindowPos2iv (const GLint *); + GLAPI void APIENTRY glWindowPos2s (GLshort, GLshort); + GLAPI void APIENTRY glWindowPos2sv (const GLshort *); + GLAPI void APIENTRY glWindowPos3d (GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glWindowPos3dv (const GLdouble *); + GLAPI void APIENTRY glWindowPos3f (GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glWindowPos3fv (const GLfloat *); + GLAPI void APIENTRY glWindowPos3i (GLint, GLint, GLint); + GLAPI void APIENTRY glWindowPos3iv (const GLint *); + GLAPI void APIENTRY glWindowPos3s (GLshort, GLshort, GLshort); + GLAPI void APIENTRY glWindowPos3sv (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, + GLenum dfactorRGB, + GLenum sfactorAlpha, + GLenum dfactorAlpha); + typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); + typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat * coord); + typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); + typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble * coord); + typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, + GLsizei stride, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, + GLint * first, + GLsizei * count, + GLsizei primcount); + typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, + const GLsizei * + count, GLenum type, + const GLvoid * + *indices, + GLsizei primcount); + typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, + const GLint * params); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, + GLbyte green, + GLbyte blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, + GLdouble green, + GLdouble blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, + GLfloat green, + GLfloat blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, + GLint green, + GLint blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, + GLshort green, + GLshort blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, + GLubyte green, + GLubyte blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, + GLuint green, + GLuint blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, + GLushort green, + GLushort blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, + GLenum type, + GLsizei stride, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); + typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); + typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); + typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); + typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, + GLdouble z); + typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); + typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, + GLshort z); + typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort * v); #endif #ifndef GL_VERSION_1_5 #define GL_VERSION_1_5 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenQueries (GLsizei, GLuint *); -GLAPI void APIENTRY glDeleteQueries (GLsizei, const GLuint *); -GLAPI GLboolean APIENTRY glIsQuery (GLuint); -GLAPI void APIENTRY glBeginQuery (GLenum, GLuint); -GLAPI void APIENTRY glEndQuery (GLenum); -GLAPI void APIENTRY glGetQueryiv (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetQueryObjectiv (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetQueryObjectuiv (GLuint, GLenum, GLuint *); -GLAPI void APIENTRY glBindBuffer (GLenum, GLuint); -GLAPI void APIENTRY glDeleteBuffers (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenBuffers (GLsizei, GLuint *); -GLAPI GLboolean APIENTRY glIsBuffer (GLuint); -GLAPI void APIENTRY glBufferData (GLenum, GLsizeiptr, const GLvoid *, GLenum); -GLAPI void APIENTRY glBufferSubData (GLenum, GLintptr, GLsizeiptr, const GLvoid *); -GLAPI void APIENTRY glGetBufferSubData (GLenum, GLintptr, GLsizeiptr, GLvoid *); -GLAPI GLvoid* APIENTRY glMapBuffer (GLenum, GLenum); -GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum); -GLAPI void APIENTRY glGetBufferParameteriv (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetBufferPointerv (GLenum, GLenum, GLvoid* *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); -typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); -typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); -typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); -typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); -typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); -typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); -typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); + GLAPI void APIENTRY glGenQueries (GLsizei, GLuint *); + GLAPI void APIENTRY glDeleteQueries (GLsizei, const GLuint *); + GLAPI GLboolean APIENTRY glIsQuery (GLuint); + GLAPI void APIENTRY glBeginQuery (GLenum, GLuint); + GLAPI void APIENTRY glEndQuery (GLenum); + GLAPI void APIENTRY glGetQueryiv (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetQueryObjectiv (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetQueryObjectuiv (GLuint, GLenum, GLuint *); + GLAPI void APIENTRY glBindBuffer (GLenum, GLuint); + GLAPI void APIENTRY glDeleteBuffers (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenBuffers (GLsizei, GLuint *); + GLAPI GLboolean APIENTRY glIsBuffer (GLuint); + GLAPI void APIENTRY glBufferData (GLenum, GLsizeiptr, const GLvoid *, + GLenum); + GLAPI void APIENTRY glBufferSubData (GLenum, GLintptr, GLsizeiptr, + const GLvoid *); + GLAPI void APIENTRY glGetBufferSubData (GLenum, GLintptr, GLsizeiptr, + GLvoid *); + GLAPI GLvoid *APIENTRY glMapBuffer (GLenum, GLenum); + GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum); + GLAPI void APIENTRY glGetBufferParameteriv (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetBufferPointerv (GLenum, GLenum, GLvoid * *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint * ids); + typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, + const GLuint * ids); + typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); + typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); + typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); + typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, + GLenum pname, + GLuint * params); + typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, + GLuint buffer); + typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, + const GLuint * buffers); + typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, + GLuint * buffers); + typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); + typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, + GLsizeiptr size, + const GLvoid * data, + GLenum usage); + typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, + GLintptr offset, + GLsizeiptr size, + const GLvoid * data); + typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, + GLintptr offset, + GLsizeiptr size, + GLvoid * data); + typedef GLvoid *(APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, + GLenum access); + typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); + typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, + GLenum pname, + GLvoid * *params); #endif #ifndef GL_VERSION_2_0 #define GL_VERSION_2_0 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendEquationSeparate (GLenum, GLenum); -GLAPI void APIENTRY glDrawBuffers (GLsizei, const GLenum *); -GLAPI void APIENTRY glStencilOpSeparate (GLenum, GLenum, GLenum, GLenum); -GLAPI void APIENTRY glStencilFuncSeparate (GLenum, GLenum, GLint, GLuint); -GLAPI void APIENTRY glStencilMaskSeparate (GLenum, GLuint); -GLAPI void APIENTRY glAttachShader (GLuint, GLuint); -GLAPI void APIENTRY glBindAttribLocation (GLuint, GLuint, const GLchar *); -GLAPI void APIENTRY glCompileShader (GLuint); -GLAPI GLuint APIENTRY glCreateProgram (void); -GLAPI GLuint APIENTRY glCreateShader (GLenum); -GLAPI void APIENTRY glDeleteProgram (GLuint); -GLAPI void APIENTRY glDeleteShader (GLuint); -GLAPI void APIENTRY glDetachShader (GLuint, GLuint); -GLAPI void APIENTRY glDisableVertexAttribArray (GLuint); -GLAPI void APIENTRY glEnableVertexAttribArray (GLuint); -GLAPI void APIENTRY glGetActiveAttrib (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); -GLAPI void APIENTRY glGetActiveUniform (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); -GLAPI void APIENTRY glGetAttachedShaders (GLuint, GLsizei, GLsizei *, GLuint *); -GLAPI GLint APIENTRY glGetAttribLocation (GLuint, const GLchar *); -GLAPI void APIENTRY glGetProgramiv (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetProgramInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); -GLAPI void APIENTRY glGetShaderiv (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetShaderInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); -GLAPI void APIENTRY glGetShaderSource (GLuint, GLsizei, GLsizei *, GLchar *); -GLAPI GLint APIENTRY glGetUniformLocation (GLuint, const GLchar *); -GLAPI void APIENTRY glGetUniformfv (GLuint, GLint, GLfloat *); -GLAPI void APIENTRY glGetUniformiv (GLuint, GLint, GLint *); -GLAPI void APIENTRY glGetVertexAttribdv (GLuint, GLenum, GLdouble *); -GLAPI void APIENTRY glGetVertexAttribfv (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetVertexAttribiv (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint, GLenum, GLvoid* *); -GLAPI GLboolean APIENTRY glIsProgram (GLuint); -GLAPI GLboolean APIENTRY glIsShader (GLuint); -GLAPI void APIENTRY glLinkProgram (GLuint); -GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *); -GLAPI void APIENTRY glUseProgram (GLuint); -GLAPI void APIENTRY glUniform1f (GLint, GLfloat); -GLAPI void APIENTRY glUniform2f (GLint, GLfloat, GLfloat); -GLAPI void APIENTRY glUniform3f (GLint, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glUniform4f (GLint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glUniform1i (GLint, GLint); -GLAPI void APIENTRY glUniform2i (GLint, GLint, GLint); -GLAPI void APIENTRY glUniform3i (GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glUniform4i (GLint, GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glUniform1fv (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform2fv (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform3fv (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform4fv (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform1iv (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniform2iv (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniform3iv (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniform4iv (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniformMatrix2fv (GLint, GLsizei, GLboolean, const GLfloat *); -GLAPI void APIENTRY glUniformMatrix3fv (GLint, GLsizei, GLboolean, const GLfloat *); -GLAPI void APIENTRY glUniformMatrix4fv (GLint, GLsizei, GLboolean, const GLfloat *); -GLAPI void APIENTRY glValidateProgram (GLuint); -GLAPI void APIENTRY glVertexAttrib1d (GLuint, GLdouble); -GLAPI void APIENTRY glVertexAttrib1dv (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib1f (GLuint, GLfloat); -GLAPI void APIENTRY glVertexAttrib1fv (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib1s (GLuint, GLshort); -GLAPI void APIENTRY glVertexAttrib1sv (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib2d (GLuint, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib2dv (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib2f (GLuint, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib2fv (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib2s (GLuint, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib2sv (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib3d (GLuint, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib3dv (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib3f (GLuint, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib3fv (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib3s (GLuint, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib3sv (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint, const GLbyte *); -GLAPI void APIENTRY glVertexAttrib4Niv (GLuint, const GLint *); -GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4Nub (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); -GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint, const GLubyte *); -GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint, const GLuint *); -GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint, const GLushort *); -GLAPI void APIENTRY glVertexAttrib4bv (GLuint, const GLbyte *); -GLAPI void APIENTRY glVertexAttrib4d (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib4dv (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib4f (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib4fv (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib4iv (GLuint, const GLint *); -GLAPI void APIENTRY glVertexAttrib4s (GLuint, GLshort, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib4sv (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4ubv (GLuint, const GLubyte *); -GLAPI void APIENTRY glVertexAttrib4uiv (GLuint, const GLuint *); -GLAPI void APIENTRY glVertexAttrib4usv (GLuint, const GLushort *); -GLAPI void APIENTRY glVertexAttribPointer (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); -typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); -typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); -typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); -typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); -typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); -typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); -typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); -typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); -typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); -typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); -typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); -typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); -typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); -typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); -typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); -typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); -typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); + GLAPI void APIENTRY glBlendEquationSeparate (GLenum, GLenum); + GLAPI void APIENTRY glDrawBuffers (GLsizei, const GLenum *); + GLAPI void APIENTRY glStencilOpSeparate (GLenum, GLenum, GLenum, GLenum); + GLAPI void APIENTRY glStencilFuncSeparate (GLenum, GLenum, GLint, GLuint); + GLAPI void APIENTRY glStencilMaskSeparate (GLenum, GLuint); + GLAPI void APIENTRY glAttachShader (GLuint, GLuint); + GLAPI void APIENTRY glBindAttribLocation (GLuint, GLuint, const GLchar *); + GLAPI void APIENTRY glCompileShader (GLuint); + GLAPI GLuint APIENTRY glCreateProgram (void); + GLAPI GLuint APIENTRY glCreateShader (GLenum); + GLAPI void APIENTRY glDeleteProgram (GLuint); + GLAPI void APIENTRY glDeleteShader (GLuint); + GLAPI void APIENTRY glDetachShader (GLuint, GLuint); + GLAPI void APIENTRY glDisableVertexAttribArray (GLuint); + GLAPI void APIENTRY glEnableVertexAttribArray (GLuint); + GLAPI void APIENTRY glGetActiveAttrib (GLuint, GLuint, GLsizei, GLsizei *, + GLint *, GLenum *, GLchar *); + GLAPI void APIENTRY glGetActiveUniform (GLuint, GLuint, GLsizei, + GLsizei *, GLint *, GLenum *, + GLchar *); + GLAPI void APIENTRY glGetAttachedShaders (GLuint, GLsizei, GLsizei *, + GLuint *); + GLAPI GLint APIENTRY glGetAttribLocation (GLuint, const GLchar *); + GLAPI void APIENTRY glGetProgramiv (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetProgramInfoLog (GLuint, GLsizei, GLsizei *, + GLchar *); + GLAPI void APIENTRY glGetShaderiv (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetShaderInfoLog (GLuint, GLsizei, GLsizei *, + GLchar *); + GLAPI void APIENTRY glGetShaderSource (GLuint, GLsizei, GLsizei *, + GLchar *); + GLAPI GLint APIENTRY glGetUniformLocation (GLuint, const GLchar *); + GLAPI void APIENTRY glGetUniformfv (GLuint, GLint, GLfloat *); + GLAPI void APIENTRY glGetUniformiv (GLuint, GLint, GLint *); + GLAPI void APIENTRY glGetVertexAttribdv (GLuint, GLenum, GLdouble *); + GLAPI void APIENTRY glGetVertexAttribfv (GLuint, GLenum, GLfloat *); + GLAPI void APIENTRY glGetVertexAttribiv (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint, GLenum, + GLvoid * *); + GLAPI GLboolean APIENTRY glIsProgram (GLuint); + GLAPI GLboolean APIENTRY glIsShader (GLuint); + GLAPI void APIENTRY glLinkProgram (GLuint); + GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar * *, + const GLint *); + GLAPI void APIENTRY glUseProgram (GLuint); + GLAPI void APIENTRY glUniform1f (GLint, GLfloat); + GLAPI void APIENTRY glUniform2f (GLint, GLfloat, GLfloat); + GLAPI void APIENTRY glUniform3f (GLint, GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glUniform4f (GLint, GLfloat, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glUniform1i (GLint, GLint); + GLAPI void APIENTRY glUniform2i (GLint, GLint, GLint); + GLAPI void APIENTRY glUniform3i (GLint, GLint, GLint, GLint); + GLAPI void APIENTRY glUniform4i (GLint, GLint, GLint, GLint, GLint); + GLAPI void APIENTRY glUniform1fv (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform2fv (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform3fv (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform4fv (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform1iv (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniform2iv (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniform3iv (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniform4iv (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniformMatrix2fv (GLint, GLsizei, GLboolean, + const GLfloat *); + GLAPI void APIENTRY glUniformMatrix3fv (GLint, GLsizei, GLboolean, + const GLfloat *); + GLAPI void APIENTRY glUniformMatrix4fv (GLint, GLsizei, GLboolean, + const GLfloat *); + GLAPI void APIENTRY glValidateProgram (GLuint); + GLAPI void APIENTRY glVertexAttrib1d (GLuint, GLdouble); + GLAPI void APIENTRY glVertexAttrib1dv (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib1f (GLuint, GLfloat); + GLAPI void APIENTRY glVertexAttrib1fv (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib1s (GLuint, GLshort); + GLAPI void APIENTRY glVertexAttrib1sv (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib2d (GLuint, GLdouble, GLdouble); + GLAPI void APIENTRY glVertexAttrib2dv (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib2f (GLuint, GLfloat, GLfloat); + GLAPI void APIENTRY glVertexAttrib2fv (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib2s (GLuint, GLshort, GLshort); + GLAPI void APIENTRY glVertexAttrib2sv (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib3d (GLuint, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glVertexAttrib3dv (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib3f (GLuint, GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glVertexAttrib3fv (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib3s (GLuint, GLshort, GLshort, GLshort); + GLAPI void APIENTRY glVertexAttrib3sv (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint, const GLbyte *); + GLAPI void APIENTRY glVertexAttrib4Niv (GLuint, const GLint *); + GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4Nub (GLuint, GLubyte, GLubyte, GLubyte, + GLubyte); + GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint, const GLubyte *); + GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint, const GLuint *); + GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint, const GLushort *); + GLAPI void APIENTRY glVertexAttrib4bv (GLuint, const GLbyte *); + GLAPI void APIENTRY glVertexAttrib4d (GLuint, GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glVertexAttrib4dv (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib4f (GLuint, GLfloat, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glVertexAttrib4fv (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib4iv (GLuint, const GLint *); + GLAPI void APIENTRY glVertexAttrib4s (GLuint, GLshort, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glVertexAttrib4sv (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4ubv (GLuint, const GLubyte *); + GLAPI void APIENTRY glVertexAttrib4uiv (GLuint, const GLuint *); + GLAPI void APIENTRY glVertexAttrib4usv (GLuint, const GLushort *); + GLAPI void APIENTRY glVertexAttribPointer (GLuint, GLint, GLenum, + GLboolean, GLsizei, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, + GLenum + modeAlpha); + typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, + const GLenum * bufs); + typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, + GLenum sfail, + GLenum dpfail, + GLenum dppass); + typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, + GLenum backfunc, + GLint ref, + GLuint mask); + typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, + GLuint mask); + typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, + GLuint shader); + typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, + GLuint index, + const GLchar * + name); + typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); + typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); + typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); + typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); + typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); + typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, + GLuint shader); + typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); + typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); + typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, + GLuint index, + GLsizei bufSize, + GLsizei * length, + GLint * size, + GLenum * type, + GLchar * name); + typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, + GLuint index, + GLsizei bufSize, + GLsizei * length, + GLint * size, + GLenum * type, + GLchar * name); + typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, + GLsizei maxCount, + GLsizei * count, + GLuint * obj); + typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, + const GLchar * + name); + typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, + GLsizei bufSize, + GLsizei * length, + GLchar * infoLog); + typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, + GLsizei bufSize, + GLsizei * length, + GLchar * infoLog); + typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, + GLsizei bufSize, + GLsizei * length, + GLchar * source); + typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, + const GLchar * + name); + typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, + GLint location, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, + GLint location, + GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, + GLenum pname, + GLdouble * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, + GLenum pname, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, + GLenum pname, + GLvoid * + *pointer); + typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); + typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); + typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); + typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, + GLsizei count, + const GLchar * *string, + const GLint * length); + typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); + typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); + typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, + GLfloat v1); + typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, + GLfloat v1, GLfloat v2); + typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, + GLfloat v1, GLfloat v2, + GLfloat v3); + typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); + typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, + GLint v1); + typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, + GLint v1, GLint v2); + typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, + GLint v1, GLint v2, + GLint v3); + typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, + GLsizei count, + GLboolean transpose, + const GLfloat * + value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, + GLsizei count, + GLboolean transpose, + const GLfloat * + value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, + GLsizei count, + GLboolean transpose, + const GLfloat * + value); + typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, + GLdouble x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, + GLfloat x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, + GLshort x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, + GLdouble x, GLdouble y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, + GLfloat y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, + GLshort y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, + GLdouble x, GLdouble y, + GLdouble z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, + GLfloat y, GLfloat z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, + GLshort y, GLshort z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, + const GLbyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, + const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, + GLubyte x, GLubyte y, + GLubyte z, GLubyte w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, + const GLubyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, + const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, + const GLushort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, + const GLbyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, + GLdouble x, GLdouble y, + GLdouble z, GLdouble w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, + GLfloat y, GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, + const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, + GLshort y, GLshort z, + GLshort w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, + const GLubyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, + const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, + const GLushort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, + GLint size, + GLenum type, + GLboolean + normalized, + GLsizei stride, + const GLvoid * + pointer); #endif #ifndef GL_ARB_multitexture #define GL_ARB_multitexture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glActiveTextureARB (GLenum); -GLAPI void APIENTRY glClientActiveTextureARB (GLenum); -GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum, GLdouble); -GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum, GLfloat); -GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum, GLint); -GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum, GLshort); -GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum, const GLshort *); -GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum, GLdouble, GLdouble); -GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum, GLfloat, GLfloat); -GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum, GLint, GLint); -GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum, GLshort, GLshort); -GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum, const GLshort *); -GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum, GLint, GLint, GLint); -GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum, const GLshort *); -GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum, const GLdouble *); -GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum, const GLfloat *); -GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum, GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum, const GLint *); -GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum, GLshort, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum, const GLshort *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); + GLAPI void APIENTRY glActiveTextureARB (GLenum); + GLAPI void APIENTRY glClientActiveTextureARB (GLenum); + GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum, GLdouble); + GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum, GLfloat); + GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum, GLint); + GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum, GLshort); + GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum, const GLshort *); + GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum, GLdouble, GLdouble); + GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum, GLfloat, GLfloat); + GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum, GLint, GLint); + GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum, GLshort, GLshort); + GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum, const GLshort *); + GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum, GLint, GLint, GLint); + GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum, const GLshort *); + GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum, GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum, const GLdouble *); + GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum, GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum, const GLfloat *); + GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum, GLint, GLint, GLint, + GLint); + GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum, const GLint *); + GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum, GLshort, GLshort, + GLshort, GLshort); + GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum, const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); + typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, + GLdouble s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, + const GLdouble * + v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, + GLfloat s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, + GLint s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, + GLshort s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, + const GLshort * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, + GLdouble s, + GLdouble t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, + const GLdouble * + v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, + GLfloat s, + GLfloat t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, + GLint s, GLint t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, + GLshort s, + GLshort t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, + const GLshort * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, + GLdouble s, + GLdouble t, + GLdouble r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, + const GLdouble * + v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, + GLfloat s, + GLfloat t, + GLfloat r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, + GLint s, GLint t, + GLint r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, + GLshort s, + GLshort t, + GLshort r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, + const GLshort * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, + GLdouble s, + GLdouble t, + GLdouble r, + GLdouble q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, + const GLdouble * + v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, + GLfloat s, + GLfloat t, + GLfloat r, + GLfloat q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, + const GLfloat * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, + GLint s, GLint t, + GLint r, GLint q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, + const GLint * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, + GLshort s, + GLshort t, + GLshort r, + GLshort q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, + const GLshort * v); #endif #ifndef GL_ARB_transpose_matrix #define GL_ARB_transpose_matrix 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *); -GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *); -GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *); -GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); + GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *); + GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *); + GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *); + GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat * + m); + typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble + * m); + typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat * + m); + typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble + * m); #endif #ifndef GL_ARB_multisample #define GL_ARB_multisample 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSampleCoverageARB (GLclampf, GLboolean); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, GLboolean invert); + GLAPI void APIENTRY glSampleCoverageARB (GLclampf, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, + GLboolean invert); #endif #ifndef GL_ARB_texture_env_add @@ -3748,21 +4358,118 @@ typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, GLboolean i #ifndef GL_ARB_texture_compression #define GL_ARB_texture_compression 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum, GLint, GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, GLvoid *img); + GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum, GLint, GLenum, + GLsizei, GLsizei, GLsizei, + GLint, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum, GLint, GLenum, + GLsizei, GLsizei, GLint, + GLsizei, const GLvoid *); + GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum, GLint, GLenum, + GLsizei, GLint, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum, GLint, GLint, + GLint, GLint, GLsizei, + GLsizei, GLsizei, + GLenum, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum, GLint, GLint, + GLint, GLsizei, GLsizei, + GLenum, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum, GLint, GLint, + GLsizei, GLenum, + GLsizei, + const GLvoid *); + GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLint border, + GLsizei + imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLsizei + imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLsizei width, + GLint border, + GLsizei + imageSize, + const GLvoid * + data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum + target, + GLint level, + GLint + xoffset, + GLint + yoffset, + GLint + zoffset, + GLsizei + width, + GLsizei + height, + GLsizei + depth, + GLenum + format, + GLsizei + imageSize, + const GLvoid + * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum + target, + GLint level, + GLint + xoffset, + GLint + yoffset, + GLsizei + width, + GLsizei + height, + GLenum + format, + GLsizei + imageSize, + const GLvoid + * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum + target, + GLint level, + GLint + xoffset, + GLsizei + width, + GLenum + format, + GLsizei + imageSize, + const GLvoid + * data); + typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, + GLint level, + GLvoid * img); #endif #ifndef GL_ARB_texture_border_clamp @@ -3772,53 +4479,80 @@ typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint #ifndef GL_ARB_point_parameters #define GL_ARB_point_parameters 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameterfARB (GLenum, GLfloat); -GLAPI void APIENTRY glPointParameterfvARB (GLenum, const GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); + GLAPI void APIENTRY glPointParameterfARB (GLenum, GLfloat); + GLAPI void APIENTRY glPointParameterfvARB (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, + const GLfloat * + params); #endif #ifndef GL_ARB_vertex_blend #define GL_ARB_vertex_blend 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glWeightbvARB (GLint, const GLbyte *); -GLAPI void APIENTRY glWeightsvARB (GLint, const GLshort *); -GLAPI void APIENTRY glWeightivARB (GLint, const GLint *); -GLAPI void APIENTRY glWeightfvARB (GLint, const GLfloat *); -GLAPI void APIENTRY glWeightdvARB (GLint, const GLdouble *); -GLAPI void APIENTRY glWeightubvARB (GLint, const GLubyte *); -GLAPI void APIENTRY glWeightusvARB (GLint, const GLushort *); -GLAPI void APIENTRY glWeightuivARB (GLint, const GLuint *); -GLAPI void APIENTRY glWeightPointerARB (GLint, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glVertexBlendARB (GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); -typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); -typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); -typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); -typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); -typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); -typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); -typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); -typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); + GLAPI void APIENTRY glWeightbvARB (GLint, const GLbyte *); + GLAPI void APIENTRY glWeightsvARB (GLint, const GLshort *); + GLAPI void APIENTRY glWeightivARB (GLint, const GLint *); + GLAPI void APIENTRY glWeightfvARB (GLint, const GLfloat *); + GLAPI void APIENTRY glWeightdvARB (GLint, const GLdouble *); + GLAPI void APIENTRY glWeightubvARB (GLint, const GLubyte *); + GLAPI void APIENTRY glWeightusvARB (GLint, const GLushort *); + GLAPI void APIENTRY glWeightuivARB (GLint, const GLuint *); + GLAPI void APIENTRY glWeightPointerARB (GLint, GLenum, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glVertexBlendARB (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, + const GLbyte * weights); + typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, + const GLshort * weights); + typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, + const GLint * weights); + typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, + const GLfloat * weights); + typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, + const GLdouble * weights); + typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, + const GLubyte * weights); + typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, + const GLushort * weights); + typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, + const GLuint * weights); + typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, + GLenum type, + GLsizei stride, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); #endif #ifndef GL_ARB_matrix_palette #define GL_ARB_matrix_palette 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint); -GLAPI void APIENTRY glMatrixIndexubvARB (GLint, const GLubyte *); -GLAPI void APIENTRY glMatrixIndexusvARB (GLint, const GLushort *); -GLAPI void APIENTRY glMatrixIndexuivARB (GLint, const GLuint *); -GLAPI void APIENTRY glMatrixIndexPointerARB (GLint, GLenum, GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); -typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); -typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); -typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); -typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint); + GLAPI void APIENTRY glMatrixIndexubvARB (GLint, const GLubyte *); + GLAPI void APIENTRY glMatrixIndexusvARB (GLint, const GLushort *); + GLAPI void APIENTRY glMatrixIndexuivARB (GLint, const GLuint *); + GLAPI void APIENTRY glMatrixIndexPointerARB (GLint, GLenum, GLsizei, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); + typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, + const GLubyte * + indices); + typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, + const GLushort * + indices); + typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, + const GLuint * + indices); + typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, + GLenum type, + GLsizei stride, + const GLvoid * + pointer); #endif #ifndef GL_ARB_texture_env_combine @@ -3852,169 +4586,355 @@ typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type #ifndef GL_ARB_window_pos #define GL_ARB_window_pos 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glWindowPos2dARB (GLdouble, GLdouble); -GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *); -GLAPI void APIENTRY glWindowPos2fARB (GLfloat, GLfloat); -GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *); -GLAPI void APIENTRY glWindowPos2iARB (GLint, GLint); -GLAPI void APIENTRY glWindowPos2ivARB (const GLint *); -GLAPI void APIENTRY glWindowPos2sARB (GLshort, GLshort); -GLAPI void APIENTRY glWindowPos2svARB (const GLshort *); -GLAPI void APIENTRY glWindowPos3dARB (GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *); -GLAPI void APIENTRY glWindowPos3fARB (GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *); -GLAPI void APIENTRY glWindowPos3iARB (GLint, GLint, GLint); -GLAPI void APIENTRY glWindowPos3ivARB (const GLint *); -GLAPI void APIENTRY glWindowPos3sARB (GLshort, GLshort, GLshort); -GLAPI void APIENTRY glWindowPos3svARB (const GLshort *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); -typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); + GLAPI void APIENTRY glWindowPos2dARB (GLdouble, GLdouble); + GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *); + GLAPI void APIENTRY glWindowPos2fARB (GLfloat, GLfloat); + GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *); + GLAPI void APIENTRY glWindowPos2iARB (GLint, GLint); + GLAPI void APIENTRY glWindowPos2ivARB (const GLint *); + GLAPI void APIENTRY glWindowPos2sARB (GLshort, GLshort); + GLAPI void APIENTRY glWindowPos2svARB (const GLshort *); + GLAPI void APIENTRY glWindowPos3dARB (GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *); + GLAPI void APIENTRY glWindowPos3fARB (GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *); + GLAPI void APIENTRY glWindowPos3iARB (GLint, GLint, GLint); + GLAPI void APIENTRY glWindowPos3ivARB (const GLint *); + GLAPI void APIENTRY glWindowPos3sARB (GLshort, GLshort, GLshort); + GLAPI void APIENTRY glWindowPos3svARB (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); + typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); + typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); + typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); + typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, + GLdouble z); + typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, + GLint z); + typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, + GLshort z); + typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort * v); #endif #ifndef GL_ARB_vertex_program #define GL_ARB_vertex_program 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttrib1dARB (GLuint, GLdouble); -GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib1fARB (GLuint, GLfloat); -GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib1sARB (GLuint, GLshort); -GLAPI void APIENTRY glVertexAttrib1svARB (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib2dARB (GLuint, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib2fARB (GLuint, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib2sARB (GLuint, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib2svARB (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib3dARB (GLuint, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib3fARB (GLuint, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib3sARB (GLuint, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib3svARB (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint, const GLbyte *); -GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint, const GLint *); -GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); -GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint, const GLubyte *); -GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint, const GLuint *); -GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint, const GLushort *); -GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint, const GLbyte *); -GLAPI void APIENTRY glVertexAttrib4dARB (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib4fARB (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint, const GLint *); -GLAPI void APIENTRY glVertexAttrib4sARB (GLuint, GLshort, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib4svARB (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint, const GLubyte *); -GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint, const GLuint *); -GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint, const GLushort *); -GLAPI void APIENTRY glVertexAttribPointerARB (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); -GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint); -GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint); -GLAPI void APIENTRY glProgramStringARB (GLenum, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glBindProgramARB (GLenum, GLuint); -GLAPI void APIENTRY glDeleteProgramsARB (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenProgramsARB (GLsizei, GLuint *); -GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum, GLuint, const GLdouble *); -GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum, GLuint, const GLfloat *); -GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum, GLuint, const GLdouble *); -GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum, GLuint, const GLfloat *); -GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum, GLuint, GLdouble *); -GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum, GLuint, GLfloat *); -GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum, GLuint, GLdouble *); -GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum, GLuint, GLfloat *); -GLAPI void APIENTRY glGetProgramivARB (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetProgramStringARB (GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint, GLenum, GLdouble *); -GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetVertexAttribivARB (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint, GLenum, GLvoid* *); -GLAPI GLboolean APIENTRY glIsProgramARB (GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); -typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); -typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); -typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); -typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); -typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); -typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, GLvoid *string); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); + GLAPI void APIENTRY glVertexAttrib1dARB (GLuint, GLdouble); + GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib1fARB (GLuint, GLfloat); + GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib1sARB (GLuint, GLshort); + GLAPI void APIENTRY glVertexAttrib1svARB (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib2dARB (GLuint, GLdouble, GLdouble); + GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib2fARB (GLuint, GLfloat, GLfloat); + GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib2sARB (GLuint, GLshort, GLshort); + GLAPI void APIENTRY glVertexAttrib2svARB (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib3dARB (GLuint, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib3fARB (GLuint, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib3sARB (GLuint, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glVertexAttrib3svARB (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint, const GLbyte *); + GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint, const GLint *); + GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint, GLubyte, GLubyte, + GLubyte, GLubyte); + GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint, const GLubyte *); + GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint, const GLuint *); + GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint, const GLushort *); + GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint, const GLbyte *); + GLAPI void APIENTRY glVertexAttrib4dARB (GLuint, GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib4fARB (GLuint, GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint, const GLint *); + GLAPI void APIENTRY glVertexAttrib4sARB (GLuint, GLshort, GLshort, + GLshort, GLshort); + GLAPI void APIENTRY glVertexAttrib4svARB (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint, const GLubyte *); + GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint, const GLuint *); + GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint, const GLushort *); + GLAPI void APIENTRY glVertexAttribPointerARB (GLuint, GLint, GLenum, + GLboolean, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint); + GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint); + GLAPI void APIENTRY glProgramStringARB (GLenum, GLenum, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glBindProgramARB (GLenum, GLuint); + GLAPI void APIENTRY glDeleteProgramsARB (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenProgramsARB (GLsizei, GLuint *); + GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum, GLuint, GLdouble, + GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum, GLuint, + const GLdouble *); + GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum, GLuint, GLfloat, + GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum, GLuint, + const GLfloat *); + GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum, GLuint, + GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum, GLuint, + const GLdouble *); + GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum, GLuint, GLfloat, + GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum, GLuint, + const GLfloat *); + GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum, GLuint, + GLdouble *); + GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum, GLuint, + GLfloat *); + GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum, GLuint, + GLdouble *); + GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum, GLuint, + GLfloat *); + GLAPI void APIENTRY glGetProgramivARB (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetProgramStringARB (GLenum, GLenum, GLvoid *); + GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint, GLenum, GLdouble *); + GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint, GLenum, GLfloat *); + GLAPI void APIENTRY glGetVertexAttribivARB (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint, GLenum, + GLvoid * *); + GLAPI GLboolean APIENTRY glIsProgramARB (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, + GLdouble x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, + GLfloat x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, + GLshort x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, + GLdouble x, + GLdouble y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, + GLfloat x, + GLfloat y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, + GLshort x, + GLshort y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, + GLdouble x, + GLdouble y, + GLdouble z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, + GLfloat x, GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, + GLshort x, GLshort y, + GLshort z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, + const GLbyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, + const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, + GLubyte x, + GLubyte y, + GLubyte z, + GLubyte w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, + const GLubyte * + v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, + const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, + const GLushort * + v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, + const GLbyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, + GLdouble x, + GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, + GLfloat x, GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, + const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, + GLshort x, GLshort y, + GLshort z, + GLshort w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, + const GLubyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, + const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, + const GLushort * + v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, + GLint size, + GLenum type, + GLboolean + normalized, + GLsizei stride, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint + index); + typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint + index); + typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, + GLenum format, + GLsizei len, + const GLvoid * + string); + typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, + GLuint program); + typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, + const GLuint * + programs); + typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, + GLuint * programs); + typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, + GLuint index, + GLdouble x, + GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum + target, + GLuint index, + const + GLdouble * + params); + typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, + GLuint index, + GLfloat x, + GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum + target, + GLuint index, + const GLfloat + * params); + typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum + target, + GLuint + index, + GLdouble x, + GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum + target, + GLuint + index, + const + GLdouble * + params); + typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum + target, + GLuint + index, + GLfloat x, + GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum + target, + GLuint + index, + const + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum + target, + GLuint + index, + GLdouble * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum + target, + GLuint + index, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum + target, + GLuint + index, + GLdouble + * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum + target, + GLuint + index, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, + GLenum pname, + GLvoid * string); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, + GLenum pname, + GLdouble * + params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, + GLenum pname, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint + index, + GLenum + pname, + GLvoid * + *pointer); + typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); #endif #ifndef GL_ARB_fragment_program @@ -4025,147 +4945,296 @@ typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); #ifndef GL_ARB_vertex_buffer_object #define GL_ARB_vertex_buffer_object 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindBufferARB (GLenum, GLuint); -GLAPI void APIENTRY glDeleteBuffersARB (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenBuffersARB (GLsizei, GLuint *); -GLAPI GLboolean APIENTRY glIsBufferARB (GLuint); -GLAPI void APIENTRY glBufferDataARB (GLenum, GLsizeiptrARB, const GLvoid *, GLenum); -GLAPI void APIENTRY glBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *); -GLAPI void APIENTRY glGetBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *); -GLAPI GLvoid* APIENTRY glMapBufferARB (GLenum, GLenum); -GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum); -GLAPI void APIENTRY glGetBufferParameterivARB (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetBufferPointervARB (GLenum, GLenum, GLvoid* *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); -typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); -typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); -typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); -typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); -typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); -typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, GLvoid* *params); + GLAPI void APIENTRY glBindBufferARB (GLenum, GLuint); + GLAPI void APIENTRY glDeleteBuffersARB (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenBuffersARB (GLsizei, GLuint *); + GLAPI GLboolean APIENTRY glIsBufferARB (GLuint); + GLAPI void APIENTRY glBufferDataARB (GLenum, GLsizeiptrARB, + const GLvoid *, GLenum); + GLAPI void APIENTRY glBufferSubDataARB (GLenum, GLintptrARB, + GLsizeiptrARB, const GLvoid *); + GLAPI void APIENTRY glGetBufferSubDataARB (GLenum, GLintptrARB, + GLsizeiptrARB, GLvoid *); + GLAPI GLvoid *APIENTRY glMapBufferARB (GLenum, GLenum); + GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum); + GLAPI void APIENTRY glGetBufferParameterivARB (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetBufferPointervARB (GLenum, GLenum, GLvoid * *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, + GLuint buffer); + typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, + const GLuint * + buffers); + typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, + GLuint * buffers); + typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); + typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, + GLsizeiptrARB size, + const GLvoid * data, + GLenum usage); + typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, + GLintptrARB offset, + GLsizeiptrARB size, + const GLvoid * data); + typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, + GLintptrARB offset, + GLsizeiptrARB size, + GLvoid * data); + typedef GLvoid *(APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, + GLenum access); + typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); + typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, + GLenum pname, + GLvoid * *params); #endif #ifndef GL_ARB_occlusion_query #define GL_ARB_occlusion_query 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenQueriesARB (GLsizei, GLuint *); -GLAPI void APIENTRY glDeleteQueriesARB (GLsizei, const GLuint *); -GLAPI GLboolean APIENTRY glIsQueryARB (GLuint); -GLAPI void APIENTRY glBeginQueryARB (GLenum, GLuint); -GLAPI void APIENTRY glEndQueryARB (GLenum); -GLAPI void APIENTRY glGetQueryivARB (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetQueryObjectivARB (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint, GLenum, GLuint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); -typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); + GLAPI void APIENTRY glGenQueriesARB (GLsizei, GLuint *); + GLAPI void APIENTRY glDeleteQueriesARB (GLsizei, const GLuint *); + GLAPI GLboolean APIENTRY glIsQueryARB (GLuint); + GLAPI void APIENTRY glBeginQueryARB (GLenum, GLuint); + GLAPI void APIENTRY glEndQueryARB (GLenum); + GLAPI void APIENTRY glGetQueryivARB (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetQueryObjectivARB (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint * ids); + typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, + const GLuint * ids); + typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); + typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, + GLuint id); + typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); + typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, + GLenum pname, + GLuint * params); #endif #ifndef GL_ARB_shader_objects #define GL_ARB_shader_objects 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB); -GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum); -GLAPI void APIENTRY glDetachObjectARB (GLhandleARB, GLhandleARB); -GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum); -GLAPI void APIENTRY glShaderSourceARB (GLhandleARB, GLsizei, const GLcharARB* *, const GLint *); -GLAPI void APIENTRY glCompileShaderARB (GLhandleARB); -GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); -GLAPI void APIENTRY glAttachObjectARB (GLhandleARB, GLhandleARB); -GLAPI void APIENTRY glLinkProgramARB (GLhandleARB); -GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB); -GLAPI void APIENTRY glValidateProgramARB (GLhandleARB); -GLAPI void APIENTRY glUniform1fARB (GLint, GLfloat); -GLAPI void APIENTRY glUniform2fARB (GLint, GLfloat, GLfloat); -GLAPI void APIENTRY glUniform3fARB (GLint, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glUniform4fARB (GLint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glUniform1iARB (GLint, GLint); -GLAPI void APIENTRY glUniform2iARB (GLint, GLint, GLint); -GLAPI void APIENTRY glUniform3iARB (GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glUniform4iARB (GLint, GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glUniform1fvARB (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform2fvARB (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform3fvARB (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform4fvARB (GLint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glUniform1ivARB (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniform2ivARB (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniform3ivARB (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniform4ivARB (GLint, GLsizei, const GLint *); -GLAPI void APIENTRY glUniformMatrix2fvARB (GLint, GLsizei, GLboolean, const GLfloat *); -GLAPI void APIENTRY glUniformMatrix3fvARB (GLint, GLsizei, GLboolean, const GLfloat *); -GLAPI void APIENTRY glUniformMatrix4fvARB (GLint, GLsizei, GLboolean, const GLfloat *); -GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB, GLenum, GLfloat *); -GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB, GLenum, GLint *); -GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); -GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB, GLsizei, GLsizei *, GLhandleARB *); -GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB, const GLcharARB *); -GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); -GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB, GLint, GLfloat *); -GLAPI void APIENTRY glGetUniformivARB (GLhandleARB, GLint, GLint *); -GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); -typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); -typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); -typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); -typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); -typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); -typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); -typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); -typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); -typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); -typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); -typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); -typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); -typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); -typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); -typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); + GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB); + GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum); + GLAPI void APIENTRY glDetachObjectARB (GLhandleARB, GLhandleARB); + GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum); + GLAPI void APIENTRY glShaderSourceARB (GLhandleARB, GLsizei, + const GLcharARB * *, + const GLint *); + GLAPI void APIENTRY glCompileShaderARB (GLhandleARB); + GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); + GLAPI void APIENTRY glAttachObjectARB (GLhandleARB, GLhandleARB); + GLAPI void APIENTRY glLinkProgramARB (GLhandleARB); + GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB); + GLAPI void APIENTRY glValidateProgramARB (GLhandleARB); + GLAPI void APIENTRY glUniform1fARB (GLint, GLfloat); + GLAPI void APIENTRY glUniform2fARB (GLint, GLfloat, GLfloat); + GLAPI void APIENTRY glUniform3fARB (GLint, GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glUniform4fARB (GLint, GLfloat, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glUniform1iARB (GLint, GLint); + GLAPI void APIENTRY glUniform2iARB (GLint, GLint, GLint); + GLAPI void APIENTRY glUniform3iARB (GLint, GLint, GLint, GLint); + GLAPI void APIENTRY glUniform4iARB (GLint, GLint, GLint, GLint, GLint); + GLAPI void APIENTRY glUniform1fvARB (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform2fvARB (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform3fvARB (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform4fvARB (GLint, GLsizei, const GLfloat *); + GLAPI void APIENTRY glUniform1ivARB (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniform2ivARB (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniform3ivARB (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniform4ivARB (GLint, GLsizei, const GLint *); + GLAPI void APIENTRY glUniformMatrix2fvARB (GLint, GLsizei, GLboolean, + const GLfloat *); + GLAPI void APIENTRY glUniformMatrix3fvARB (GLint, GLsizei, GLboolean, + const GLfloat *); + GLAPI void APIENTRY glUniformMatrix4fvARB (GLint, GLsizei, GLboolean, + const GLfloat *); + GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB, GLenum, + GLint *); + GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB, GLsizei, GLsizei *, + GLcharARB *); + GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB, GLsizei, + GLsizei *, GLhandleARB *); + GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB, + const GLcharARB *); + GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB, GLuint, GLsizei, + GLsizei *, GLint *, GLenum *, + GLcharARB *); + GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB, GLint, GLfloat *); + GLAPI void APIENTRY glGetUniformivARB (GLhandleARB, GLint, GLint *); + GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB, GLsizei, GLsizei *, + GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); + typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); + typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB + containerObj, + GLhandleARB + attachedObj); + typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum + shaderType); + typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, + GLsizei count, + const GLcharARB * + *string, + const GLint * length); + typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB + shaderObj); + typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); + typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB + containerObj, + GLhandleARB obj); + typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); + typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB + programObj); + typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB + programObj); + typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, + GLfloat v0); + typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, + GLfloat v0, GLfloat v1); + typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, + GLfloat v0, GLfloat v1, + GLfloat v2); + typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, + GLfloat v0, GLfloat v1, + GLfloat v2, GLfloat v3); + typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); + typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, + GLint v1); + typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, + GLint v1, GLint v2); + typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, + GLint v1, GLint v2, + GLint v3); + typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, + GLsizei count, + const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, + GLsizei count, + const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, + GLsizei count, + GLboolean + transpose, + const GLfloat * + value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, + GLsizei count, + GLboolean + transpose, + const GLfloat * + value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, + GLsizei count, + GLboolean + transpose, + const GLfloat * + value); + typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB + obj, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB + obj, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, + GLsizei maxLength, + GLsizei * length, + GLcharARB * infoLog); + typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB + containerObj, + GLsizei maxCount, + GLsizei * count, + GLhandleARB * + obj); + typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB + programObj, + const GLcharARB + * name); + typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB + programObj, + GLuint index, + GLsizei maxLength, + GLsizei * length, + GLint * size, + GLenum * type, + GLcharARB * name); + typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, + GLint location, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, + GLint location, + GLint * params); + typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, + GLsizei maxLength, + GLsizei * length, + GLcharARB * source); #endif #ifndef GL_ARB_vertex_shader #define GL_ARB_vertex_shader 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB, GLuint, const GLcharARB *); -GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); -GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB, const GLcharARB *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); -typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); + GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB, GLuint, + const GLcharARB *); + GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB, GLuint, GLsizei, + GLsizei *, GLint *, GLenum *, + GLcharARB *); + GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB, + const GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB + programObj, + GLuint index, + const GLcharARB * + name); + typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB + programObj, + GLuint index, + GLsizei maxLength, + GLsizei * length, + GLint * size, + GLenum * type, + GLcharARB * name); + typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB + programObj, + const GLcharARB * + name); #endif #ifndef GL_ARB_fragment_shader @@ -4191,9 +5260,10 @@ typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, #ifndef GL_ARB_draw_buffers #define GL_ARB_draw_buffers 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawBuffersARB (GLsizei, const GLenum *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); + GLAPI void APIENTRY glDrawBuffersARB (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, + const GLenum * bufs); #endif #ifndef GL_ARB_texture_rectangle @@ -4203,9 +5273,10 @@ typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs) #ifndef GL_ARB_color_buffer_float #define GL_ARB_color_buffer_float 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glClampColorARB (GLenum, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); + GLAPI void APIENTRY glClampColorARB (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, + GLenum clamp); #endif #ifndef GL_ARB_half_float_pixel @@ -4227,17 +5298,22 @@ typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); #ifndef GL_EXT_blend_color #define GL_EXT_blend_color 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendColorEXT (GLclampf, GLclampf, GLclampf, GLclampf); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + GLAPI void APIENTRY glBlendColorEXT (GLclampf, GLclampf, GLclampf, + GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLclampf red, + GLclampf green, + GLclampf blue, + GLclampf alpha); #endif #ifndef GL_EXT_polygon_offset #define GL_EXT_polygon_offset 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat, GLfloat); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); + GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, + GLfloat bias); #endif #ifndef GL_EXT_texture @@ -4247,105 +5323,316 @@ typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias #ifndef GL_EXT_texture3D #define GL_EXT_texture3D 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexImage3DEXT (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); + GLAPI void APIENTRY glTexImage3DEXT (GLenum, GLint, GLenum, GLsizei, + GLsizei, GLsizei, GLint, GLenum, + GLenum, const GLvoid *); + GLAPI void APIENTRY glTexSubImage3DEXT (GLenum, GLint, GLint, GLint, + GLint, GLsizei, GLsizei, GLsizei, + GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, + GLint level, + GLenum internalformat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLint border, + GLenum format, + GLenum type, + const GLvoid * pixels); + typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLsizei width, + GLsizei height, + GLsizei depth, + GLenum format, + GLenum type, + const GLvoid * + pixels); #endif #ifndef GL_SGIS_texture_filter4 #define GL_SGIS_texture_filter4 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum, GLenum, GLsizei, const GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); -typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); + GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum, GLenum, GLfloat *); + GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum, GLenum, GLsizei, + const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, + GLenum filter, + GLfloat * + weights); + typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, + GLenum filter, + GLsizei n, + const GLfloat * + weights); #endif #ifndef GL_EXT_subtexture #define GL_EXT_subtexture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexSubImage1DEXT (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); + GLAPI void APIENTRY glTexSubImage1DEXT (GLenum, GLint, GLint, GLsizei, + GLenum, GLenum, const GLvoid *); + GLAPI void APIENTRY glTexSubImage2DEXT (GLenum, GLint, GLint, GLint, + GLsizei, GLsizei, GLenum, GLenum, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, + GLint level, + GLint xoffset, + GLsizei width, + GLenum format, + GLenum type, + const GLvoid * + pixels); + typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + const GLvoid * + pixels); #endif #ifndef GL_EXT_copy_texture #define GL_EXT_copy_texture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint); -GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); -GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei); -GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); -GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum, GLint, GLenum, GLint, + GLint, GLsizei, GLint); + GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum, GLint, GLenum, GLint, + GLint, GLsizei, GLsizei, GLint); + GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum, GLint, GLint, GLint, + GLint, GLsizei); + GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum, GLint, GLint, GLint, + GLint, GLint, GLsizei, + GLsizei); + GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum, GLint, GLint, GLint, + GLint, GLint, GLint, GLsizei, + GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLint x, GLint y, + GLsizei width, + GLint border); + typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, + GLint level, + GLenum + internalformat, + GLint x, GLint y, + GLsizei width, + GLsizei height, + GLint border); + typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint x, GLint y, + GLsizei width); + typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint x, GLint y, + GLsizei width, + GLsizei height); + typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLint x, GLint y, + GLsizei width, + GLsizei height); #endif #ifndef GL_EXT_histogram #define GL_EXT_histogram 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetHistogramEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetMinmaxEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glHistogramEXT (GLenum, GLsizei, GLenum, GLboolean); -GLAPI void APIENTRY glMinmaxEXT (GLenum, GLenum, GLboolean); -GLAPI void APIENTRY glResetHistogramEXT (GLenum); -GLAPI void APIENTRY glResetMinmaxEXT (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); -typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); + GLAPI void APIENTRY glGetHistogramEXT (GLenum, GLboolean, GLenum, GLenum, + GLvoid *); + GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum, GLenum, + GLint *); + GLAPI void APIENTRY glGetMinmaxEXT (GLenum, GLboolean, GLenum, GLenum, + GLvoid *); + GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum, GLenum, GLfloat *); + GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glHistogramEXT (GLenum, GLsizei, GLenum, GLboolean); + GLAPI void APIENTRY glMinmaxEXT (GLenum, GLenum, GLboolean); + GLAPI void APIENTRY glResetHistogramEXT (GLenum); + GLAPI void APIENTRY glResetMinmaxEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, + GLboolean reset, + GLenum format, + GLenum type, + GLvoid * values); + typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum + target, + GLenum + pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum + target, + GLenum + pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, + GLboolean reset, + GLenum format, + GLenum type, + GLvoid * values); + typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, + GLsizei width, + GLenum internalformat, + GLboolean sink); + typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, + GLenum internalformat, + GLboolean sink); + typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); + typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); #endif #ifndef GL_EXT_convolution #define GL_EXT_convolution 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum, GLenum, GLfloat); -GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum, GLenum, GLint); -GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum, GLenum, GLint, GLint, GLsizei); -GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); -GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); -GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); -typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); + GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum, GLenum, GLsizei, + GLenum, GLenum, + const GLvoid *); + GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum, GLenum, GLsizei, + GLsizei, GLenum, GLenum, + const GLvoid *); + GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum, GLenum, GLfloat); + GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum, GLenum, GLint); + GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum, GLenum, + const GLint *); + GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum, GLenum, GLint, + GLint, GLsizei); + GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum, GLenum, GLint, + GLint, GLsizei, + GLsizei); + GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum, GLenum, GLenum, + GLvoid *); + GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum, GLenum, + GLint *); + GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum, GLenum, GLenum, + GLvoid *, GLvoid *, + GLvoid *); + GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum, GLenum, GLsizei, + GLsizei, GLenum, GLenum, + const GLvoid *, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, + GLenum + internalformat, + GLsizei width, + GLenum format, + GLenum type, + const GLvoid * + image); + typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + const GLvoid * + image); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, + GLenum pname, + GLfloat + params); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum + target, + GLenum pname, + const GLfloat + * params); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, + GLenum pname, + GLint params); + typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum + target, + GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum + target, + GLenum + internalformat, + GLint x, + GLint y, + GLsizei + width); + typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum + target, + GLenum + internalformat, + GLint x, + GLint y, + GLsizei + width, + GLsizei + height); + typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, + GLenum format, + GLenum type, + GLvoid * + image); + typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum + target, + GLenum + pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum + target, + GLenum + pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, + GLenum format, + GLenum type, + GLvoid * row, + GLvoid * column, + GLvoid * span); + typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, + GLenum + internalformat, + GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + const GLvoid * + row, + const GLvoid * + column); #endif #ifndef GL_EXT_color_matrix @@ -4355,57 +5642,136 @@ typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum in #ifndef GL_SGI_color_table #define GL_SGI_color_table 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorTableSGI (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glColorTableParameterivSGI (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glCopyColorTableSGI (GLenum, GLenum, GLint, GLint, GLsizei); -GLAPI void APIENTRY glGetColorTableSGI (GLenum, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum, GLenum, GLint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); + GLAPI void APIENTRY glColorTableSGI (GLenum, GLenum, GLsizei, GLenum, + GLenum, const GLvoid *); + GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glColorTableParameterivSGI (GLenum, GLenum, + const GLint *); + GLAPI void APIENTRY glCopyColorTableSGI (GLenum, GLenum, GLint, GLint, + GLsizei); + GLAPI void APIENTRY glGetColorTableSGI (GLenum, GLenum, GLenum, GLvoid *); + GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum, GLenum, + GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, + GLenum internalformat, + GLsizei width, + GLenum format, + GLenum type, + const GLvoid * table); + typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, + GLenum pname, + const GLfloat + * params); + typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, + GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, + GLenum + internalformat, + GLint x, GLint y, + GLsizei width); + typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, + GLenum format, + GLenum type, + GLvoid * table); + typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum + target, + GLenum + pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum + target, + GLenum + pname, + GLint * + params); #endif #ifndef GL_SGIX_pixel_texture #define GL_SGIX_pixel_texture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelTexGenSGIX (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); + GLAPI void APIENTRY glPixelTexGenSGIX (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); #endif #ifndef GL_SGIS_pixel_texture #define GL_SGIS_pixel_texture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum, GLint); -GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum, const GLint *); -GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum, GLfloat); -GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum, const GLfloat *); -GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum, GLint *); -GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); + GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum, GLint); + GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum, const GLint *); + GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum, GLfloat); + GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum, + const GLfloat *); + GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum, GLint *); + GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum + pname, + const GLint + * params); + typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, + GLfloat + param); + typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum + pname, + const + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum + pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum + pname, + GLfloat * + params); #endif #ifndef GL_SGIS_texture4D #define GL_SGIS_texture4D 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexImage4DSGIS (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); + GLAPI void APIENTRY glTexImage4DSGIS (GLenum, GLint, GLenum, GLsizei, + GLsizei, GLsizei, GLsizei, GLint, + GLenum, GLenum, const GLvoid *); + GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum, GLint, GLint, GLint, + GLint, GLint, GLsizei, GLsizei, + GLsizei, GLsizei, GLenum, GLenum, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, + GLint level, + GLenum internalformat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLsizei size4d, + GLint border, + GLenum format, + GLenum type, + const GLvoid * pixels); + typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLint woffset, + GLsizei width, + GLsizei height, + GLsizei depth, + GLsizei size4d, + GLenum format, + GLenum type, + const GLvoid * + pixels); #endif #ifndef GL_SGI_texture_color_table @@ -4419,39 +5785,66 @@ typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, #ifndef GL_EXT_texture_object #define GL_EXT_texture_object 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei, const GLuint *, GLboolean *); -GLAPI void APIENTRY glBindTextureEXT (GLenum, GLuint); -GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenTexturesEXT (GLsizei, GLuint *); -GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint); -GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei, const GLuint *, const GLclampf *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); -typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); -typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); -typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); -typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); -typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); + GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei, + const GLuint *, + GLboolean *); + GLAPI void APIENTRY glBindTextureEXT (GLenum, GLuint); + GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenTexturesEXT (GLsizei, GLuint *); + GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint); + GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei, const GLuint *, + const GLclampf *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, + const + GLuint * + textures, + GLboolean * + residences); + typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, + GLuint texture); + typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, + const GLuint * + textures); + typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, + GLuint * textures); + typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); + typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, + const GLuint * + textures, + const GLclampf * + priorities); #endif #ifndef GL_SGIS_detail_texture #define GL_SGIS_detail_texture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum, GLsizei, const GLfloat *); -GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); -typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); + GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum, GLsizei, + const GLfloat *); + GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, + GLsizei n, + const GLfloat * + points); + typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, + GLfloat * points); #endif #ifndef GL_SGIS_sharpen_texture #define GL_SGIS_sharpen_texture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum, GLsizei, const GLfloat *); -GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); -typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); + GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum, GLsizei, + const GLfloat *); + GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, + GLsizei n, + const GLfloat * + points); + typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, + GLfloat * + points); #endif #ifndef GL_EXT_packed_pixels @@ -4465,11 +5858,12 @@ typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat #ifndef GL_SGIS_multisample #define GL_SGIS_multisample 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSampleMaskSGIS (GLclampf, GLboolean); -GLAPI void APIENTRY glSamplePatternSGIS (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); -typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); + GLAPI void APIENTRY glSampleMaskSGIS (GLclampf, GLboolean); + GLAPI void APIENTRY glSamplePatternSGIS (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, + GLboolean invert); + typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); #endif #ifndef GL_EXT_rescale_normal @@ -4479,25 +5873,59 @@ typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); #ifndef GL_EXT_vertex_array #define GL_EXT_vertex_array 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glArrayElementEXT (GLint); -GLAPI void APIENTRY glColorPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); -GLAPI void APIENTRY glDrawArraysEXT (GLenum, GLint, GLsizei); -GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei, GLsizei, const GLboolean *); -GLAPI void APIENTRY glGetPointervEXT (GLenum, GLvoid* *); -GLAPI void APIENTRY glIndexPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); -GLAPI void APIENTRY glNormalPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); -GLAPI void APIENTRY glTexCoordPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); -GLAPI void APIENTRY glVertexPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); -typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); -typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params); -typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); + GLAPI void APIENTRY glArrayElementEXT (GLint); + GLAPI void APIENTRY glColorPointerEXT (GLint, GLenum, GLsizei, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glDrawArraysEXT (GLenum, GLint, GLsizei); + GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei, GLsizei, + const GLboolean *); + GLAPI void APIENTRY glGetPointervEXT (GLenum, GLvoid * *); + GLAPI void APIENTRY glIndexPointerEXT (GLenum, GLsizei, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glNormalPointerEXT (GLenum, GLsizei, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glTexCoordPointerEXT (GLint, GLenum, GLsizei, GLsizei, + const GLvoid *); + GLAPI void APIENTRY glVertexPointerEXT (GLint, GLenum, GLsizei, GLsizei, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); + typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, + GLenum type, + GLsizei stride, + GLsizei count, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, + GLsizei count); + typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, + GLsizei count, + const GLboolean * + pointer); + typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, + GLvoid * *params); + typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, + GLsizei stride, + GLsizei count, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, + GLsizei stride, + GLsizei count, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, + GLenum type, + GLsizei stride, + GLsizei count, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, + GLenum type, + GLsizei stride, + GLsizei count, + const GLvoid * + pointer); #endif #ifndef GL_EXT_misc_attribute @@ -4527,9 +5955,9 @@ typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLs #ifndef GL_EXT_blend_minmax #define GL_EXT_blend_minmax 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendEquationEXT (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); + GLAPI void APIENTRY glBlendEquationEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); #endif #ifndef GL_EXT_blend_subtract @@ -4555,15 +5983,21 @@ typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); #ifndef GL_SGIX_sprite #define GL_SGIX_sprite 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum, GLfloat); -GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum, const GLfloat *); -GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum, GLint); -GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum, const GLint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); + GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum, GLfloat); + GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum, const GLfloat *); + GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum, GLint); + GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, + const GLint * + params); #endif #ifndef GL_SGIX_texture_multi_buffer @@ -4573,39 +6007,46 @@ typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLi #ifndef GL_EXT_point_parameters #define GL_EXT_point_parameters 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameterfEXT (GLenum, GLfloat); -GLAPI void APIENTRY glPointParameterfvEXT (GLenum, const GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); + GLAPI void APIENTRY glPointParameterfEXT (GLenum, GLfloat); + GLAPI void APIENTRY glPointParameterfvEXT (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, + const GLfloat * + params); #endif #ifndef GL_SGIS_point_parameters #define GL_SGIS_point_parameters 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameterfSGIS (GLenum, GLfloat); -GLAPI void APIENTRY glPointParameterfvSGIS (GLenum, const GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); + GLAPI void APIENTRY glPointParameterfSGIS (GLenum, GLfloat); + GLAPI void APIENTRY glPointParameterfvSGIS (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, + const GLfloat * + params); #endif #ifndef GL_SGIX_instruments #define GL_SGIX_instruments 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); -GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei, GLint *); -GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *); -GLAPI void APIENTRY glReadInstrumentsSGIX (GLint); -GLAPI void APIENTRY glStartInstrumentsSGIX (void); -GLAPI void APIENTRY glStopInstrumentsSGIX (GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); -typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); -typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); -typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); -typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); -typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); + GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); + GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei, GLint *); + GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *); + GLAPI void APIENTRY glReadInstrumentsSGIX (GLint); + GLAPI void APIENTRY glStartInstrumentsSGIX (void); + GLAPI void APIENTRY glStopInstrumentsSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); + typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, + GLint * buffer); + typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint * marker_p); + typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); + typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); + typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); #endif #ifndef GL_SGIX_texture_scale_bias @@ -4615,47 +6056,85 @@ typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); #ifndef GL_SGIX_framezoom #define GL_SGIX_framezoom 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFrameZoomSGIX (GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); + GLAPI void APIENTRY glFrameZoomSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); #endif #ifndef GL_SGIX_tag_sample_buffer #define GL_SGIX_tag_sample_buffer 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTagSampleBufferSGIX (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); + GLAPI void APIENTRY glTagSampleBufferSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); #endif #ifndef GL_SGIX_polynomial_ffd #define GL_SGIX_polynomial_ffd 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, const GLdouble *); -GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, const GLfloat *); -GLAPI void APIENTRY glDeformSGIX (GLbitfield); -GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); -typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); -typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); -typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); + GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum, GLdouble, GLdouble, + GLint, GLint, GLdouble, + GLdouble, GLint, GLint, + GLdouble, GLdouble, GLint, + GLint, const GLdouble *); + GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum, GLfloat, GLfloat, + GLint, GLint, GLfloat, + GLfloat, GLint, GLint, + GLfloat, GLfloat, GLint, + GLint, const GLfloat *); + GLAPI void APIENTRY glDeformSGIX (GLbitfield); + GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, + GLdouble u1, + GLdouble u2, + GLint ustride, + GLint uorder, + GLdouble v1, + GLdouble v2, + GLint vstride, + GLint vorder, + GLdouble w1, + GLdouble w2, + GLint wstride, + GLint worder, + const GLdouble * + points); + typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, + GLfloat u1, + GLfloat u2, + GLint ustride, + GLint uorder, + GLfloat v1, + GLfloat v2, + GLint vstride, + GLint vorder, + GLfloat w1, + GLfloat w2, + GLint wstride, + GLint worder, + const GLfloat * + points); + typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); + typedef void (APIENTRYP + PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); #endif #ifndef GL_SGIX_reference_plane #define GL_SGIX_reference_plane 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); + GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble * + equation); #endif #ifndef GL_SGIX_flush_raster #define GL_SGIX_flush_raster 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFlushRasterSGIX (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); + GLAPI void APIENTRY glFlushRasterSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); #endif #ifndef GL_SGIX_depth_texture @@ -4665,11 +6144,12 @@ typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); #ifndef GL_SGIS_fog_function #define GL_SGIS_fog_function 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFogFuncSGIS (GLsizei, const GLfloat *); -GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); -typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); + GLAPI void APIENTRY glFogFuncSGIS (GLsizei, const GLfloat *); + GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, + const GLfloat * points); + typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat * points); #endif #ifndef GL_SGIX_fog_offset @@ -4679,19 +6159,56 @@ typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); #ifndef GL_HP_image_transform #define GL_HP_image_transform 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glImageTransformParameteriHP (GLenum, GLenum, GLint); -GLAPI void APIENTRY glImageTransformParameterfHP (GLenum, GLenum, GLfloat); -GLAPI void APIENTRY glImageTransformParameterivHP (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum, GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); + GLAPI void APIENTRY glImageTransformParameteriHP (GLenum, GLenum, GLint); + GLAPI void APIENTRY glImageTransformParameterfHP (GLenum, GLenum, + GLfloat); + GLAPI void APIENTRY glImageTransformParameterivHP (GLenum, GLenum, + const GLint *); + GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum, GLenum, + GLint *); + GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum, GLenum, + GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum + target, + GLenum + pname, + GLint + param); + typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum + target, + GLenum + pname, + GLfloat + param); + typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum + target, + GLenum + pname, + const GLint + * params); + typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum + target, + GLenum + pname, + const + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum + target, + GLenum + pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum + target, + GLenum + pname, + GLfloat + * + params); #endif #ifndef GL_HP_convolution_border_modes @@ -4705,11 +6222,21 @@ typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, #ifndef GL_EXT_color_subtable #define GL_EXT_color_subtable 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorSubTableEXT (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum, GLsizei, GLint, GLint, GLsizei); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); + GLAPI void APIENTRY glColorSubTableEXT (GLenum, GLsizei, GLsizei, GLenum, + GLenum, const GLvoid *); + GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum, GLsizei, GLint, GLint, + GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, + GLsizei start, + GLsizei count, + GLenum format, + GLenum type, + const GLvoid * data); + typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, + GLsizei start, + GLint x, GLint y, + GLsizei width); #endif #ifndef GL_PGI_vertex_hints @@ -4719,23 +6246,44 @@ typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei s #ifndef GL_PGI_misc_hints #define GL_PGI_misc_hints 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glHintPGI (GLenum, GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); + GLAPI void APIENTRY glHintPGI (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); #endif #ifndef GL_EXT_paletted_texture #define GL_EXT_paletted_texture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorTableEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); -GLAPI void APIENTRY glGetColorTableEXT (GLenum, GLenum, GLenum, GLvoid *); -GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum, GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *data); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); + GLAPI void APIENTRY glColorTableEXT (GLenum, GLenum, GLsizei, GLenum, + GLenum, const GLvoid *); + GLAPI void APIENTRY glGetColorTableEXT (GLenum, GLenum, GLenum, GLvoid *); + GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum, GLenum, + GLint *); + GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum, GLenum, + GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, + GLenum internalFormat, + GLsizei width, + GLenum format, + GLenum type, + const GLvoid * table); + typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, + GLenum format, + GLenum type, + GLvoid * data); + typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum + target, + GLenum + pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum + target, + GLenum + pname, + GLfloat * + params); #endif #ifndef GL_EXT_clip_volume_hint @@ -4745,19 +6293,35 @@ typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GL #ifndef GL_SGIX_list_priority #define GL_SGIX_list_priority 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetListParameterivSGIX (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glListParameterfSGIX (GLuint, GLenum, GLfloat); -GLAPI void APIENTRY glListParameterfvSGIX (GLuint, GLenum, const GLfloat *); -GLAPI void APIENTRY glListParameteriSGIX (GLuint, GLenum, GLint); -GLAPI void APIENTRY glListParameterivSGIX (GLuint, GLenum, const GLint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); + GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint, GLenum, GLfloat *); + GLAPI void APIENTRY glGetListParameterivSGIX (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glListParameterfSGIX (GLuint, GLenum, GLfloat); + GLAPI void APIENTRY glListParameterfvSGIX (GLuint, GLenum, + const GLfloat *); + GLAPI void APIENTRY glListParameteriSGIX (GLuint, GLenum, GLint); + GLAPI void APIENTRY glListParameterivSGIX (GLuint, GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, + GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, + GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, + GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, + GLenum pname, + const GLint * + params); #endif #ifndef GL_SGIX_ir_instrument1 @@ -4783,17 +6347,19 @@ typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname #ifndef GL_EXT_index_material #define GL_EXT_index_material 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glIndexMaterialEXT (GLenum, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); + GLAPI void APIENTRY glIndexMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, + GLenum mode); #endif #ifndef GL_EXT_index_func #define GL_EXT_index_func 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glIndexFuncEXT (GLenum, GLclampf); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); + GLAPI void APIENTRY glIndexFuncEXT (GLenum, GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, + GLclampf ref); #endif #ifndef GL_EXT_index_array_formats @@ -4803,21 +6369,24 @@ typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); #ifndef GL_EXT_compiled_vertex_array #define GL_EXT_compiled_vertex_array 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glLockArraysEXT (GLint, GLsizei); -GLAPI void APIENTRY glUnlockArraysEXT (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); + GLAPI void APIENTRY glLockArraysEXT (GLint, GLsizei); + GLAPI void APIENTRY glUnlockArraysEXT (void); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, + GLsizei count); + typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); #endif #ifndef GL_EXT_cull_vertex #define GL_EXT_cull_vertex 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCullParameterdvEXT (GLenum, GLdouble *); -GLAPI void APIENTRY glCullParameterfvEXT (GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); + GLAPI void APIENTRY glCullParameterdvEXT (GLenum, GLdouble *); + GLAPI void APIENTRY glCullParameterfvEXT (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, + GLdouble * params); + typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, + GLfloat * params); #endif #ifndef GL_SGIX_ycrcb @@ -4827,43 +6396,86 @@ typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *par #ifndef GL_SGIX_fragment_lighting #define GL_SGIX_fragment_lighting 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum, GLenum); -GLAPI void APIENTRY glFragmentLightfSGIX (GLenum, GLenum, GLfloat); -GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glFragmentLightiSGIX (GLenum, GLenum, GLint); -GLAPI void APIENTRY glFragmentLightivSGIX (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum, GLfloat); -GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum, const GLfloat *); -GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum, GLint); -GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum, const GLint *); -GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum, GLenum, GLfloat); -GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum, GLenum, GLint); -GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glLightEnviSGIX (GLenum, GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); + GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum, GLenum); + GLAPI void APIENTRY glFragmentLightfSGIX (GLenum, GLenum, GLfloat); + GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glFragmentLightiSGIX (GLenum, GLenum, GLint); + GLAPI void APIENTRY glFragmentLightivSGIX (GLenum, GLenum, const GLint *); + GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum, GLfloat); + GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum, const GLfloat *); + GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum, GLint); + GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum, const GLint *); + GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum, GLenum, GLfloat); + GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum, GLenum, GLint); + GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum, GLenum, + const GLint *); + GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum, GLenum, GLfloat *); + GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glLightEnviSGIX (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, + GLenum mode); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, + GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, + GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, + GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, + GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, + const GLfloat + * params); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, + GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, + GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, + GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, + GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, + GLint param); #endif #ifndef GL_IBM_rasterpos_clip @@ -4877,9 +6489,17 @@ typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); #ifndef GL_EXT_draw_range_elements #define GL_EXT_draw_range_elements 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); + GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum, GLuint, GLuint, + GLsizei, GLenum, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, + GLuint start, + GLuint end, + GLsizei count, + GLenum type, + const GLvoid * + indices); #endif #ifndef GL_WIN_phong_shading @@ -4893,13 +6513,14 @@ typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint star #ifndef GL_EXT_light_texture #define GL_EXT_light_texture 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glApplyTextureEXT (GLenum); -GLAPI void APIENTRY glTextureLightEXT (GLenum); -GLAPI void APIENTRY glTextureMaterialEXT (GLenum, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); -typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); + GLAPI void APIENTRY glApplyTextureEXT (GLenum); + GLAPI void APIENTRY glTextureLightEXT (GLenum); + GLAPI void APIENTRY glTextureMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); + typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); + typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, + GLenum mode); #endif #ifndef GL_SGIX_blend_alpha_minmax @@ -4913,19 +6534,20 @@ typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); #ifndef GL_SGIX_async #define GL_SGIX_async 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint); -GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *); -GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *); -GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei); -GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint, GLsizei); -GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); -typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); -typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); -typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); -typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); -typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); + GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint); + GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *); + GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *); + GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei); + GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint, GLsizei); + GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); + typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint * markerp); + typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint * markerp); + typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); + typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, + GLsizei range); + typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); #endif #ifndef GL_SGIX_async_pixel @@ -4939,15 +6561,29 @@ typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); #ifndef GL_INTEL_parallel_arrays #define GL_INTEL_parallel_arrays 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexPointervINTEL (GLint, GLenum, const GLvoid* *); -GLAPI void APIENTRY glNormalPointervINTEL (GLenum, const GLvoid* *); -GLAPI void APIENTRY glColorPointervINTEL (GLint, GLenum, const GLvoid* *); -GLAPI void APIENTRY glTexCoordPointervINTEL (GLint, GLenum, const GLvoid* *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); -typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const GLvoid* *pointer); -typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); -typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); + GLAPI void APIENTRY glVertexPointervINTEL (GLint, GLenum, + const GLvoid * *); + GLAPI void APIENTRY glNormalPointervINTEL (GLenum, const GLvoid * *); + GLAPI void APIENTRY glColorPointervINTEL (GLint, GLenum, + const GLvoid * *); + GLAPI void APIENTRY glTexCoordPointervINTEL (GLint, GLenum, + const GLvoid * *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, + GLenum type, + const GLvoid * + *pointer); + typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, + const GLvoid * + *pointer); + typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, + GLenum type, + const GLvoid * + *pointer); + typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, + GLenum type, + const GLvoid * + *pointer); #endif #ifndef GL_HP_occlusion_test @@ -4957,15 +6593,40 @@ typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type #ifndef GL_EXT_pixel_transform #define GL_EXT_pixel_transform 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum, GLenum, GLint); -GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum, GLenum, GLfloat); -GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum, GLenum, const GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); + GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum, GLenum, GLint); + GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum, GLenum, + GLfloat); + GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum, GLenum, + const GLint *); + GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum, GLenum, + const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum + target, + GLenum + pname, + GLint + param); + typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum + target, + GLenum + pname, + GLfloat + param); + typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum + target, + GLenum + pname, + const + GLint * + params); + typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum + target, + GLenum + pname, + const + GLfloat * + params); #endif #ifndef GL_EXT_pixel_transform_color_table @@ -4983,75 +6644,120 @@ typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, G #ifndef GL_EXT_secondary_color #define GL_EXT_secondary_color 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte, GLbyte, GLbyte); -GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *); -GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *); -GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *); -GLAPI void APIENTRY glSecondaryColor3iEXT (GLint, GLint, GLint); -GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *); -GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort, GLshort, GLshort); -GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *); -GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte, GLubyte, GLubyte); -GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *); -GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint, GLuint, GLuint); -GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *); -GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort, GLushort, GLushort); -GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *); -GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint, GLenum, GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte, GLbyte, GLbyte); + GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *); + GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *); + GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *); + GLAPI void APIENTRY glSecondaryColor3iEXT (GLint, GLint, GLint); + GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *); + GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort, GLshort, GLshort); + GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *); + GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte, GLubyte, GLubyte); + GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *); + GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint, GLuint, GLuint); + GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *); + GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort, GLushort, GLushort); + GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *); + GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint, GLenum, GLsizei, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, + GLbyte green, + GLbyte blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, + GLdouble green, + GLdouble blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble * + v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, + GLfloat green, + GLfloat blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat * + v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, + GLint green, + GLint blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, + GLshort green, + GLshort blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort * + v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, + GLubyte green, + GLubyte blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte * + v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, + GLuint green, + GLuint blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint * + v); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, + GLushort green, + GLushort blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort * + v); + typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, + GLenum type, + GLsizei + stride, + const GLvoid * + pointer); #endif #ifndef GL_EXT_texture_perturb_normal #define GL_EXT_texture_perturb_normal 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTextureNormalEXT (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); + GLAPI void APIENTRY glTextureNormalEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); #endif #ifndef GL_EXT_multi_draw_arrays #define GL_EXT_multi_draw_arrays 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); -GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); + GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, + GLsizei); + GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, + GLenum, const GLvoid * *, + GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, + GLint * first, + GLsizei * count, + GLsizei primcount); + typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, + const GLsizei * + count, + GLenum type, + const GLvoid * + *indices, + GLsizei + primcount); #endif #ifndef GL_EXT_fog_coord #define GL_EXT_fog_coord 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFogCoordfEXT (GLfloat); -GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *); -GLAPI void APIENTRY glFogCoorddEXT (GLdouble); -GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *); -GLAPI void APIENTRY glFogCoordPointerEXT (GLenum, GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); -typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); -typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); -typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); -typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); + GLAPI void APIENTRY glFogCoordfEXT (GLfloat); + GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *); + GLAPI void APIENTRY glFogCoorddEXT (GLdouble); + GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *); + GLAPI void APIENTRY glFogCoordPointerEXT (GLenum, GLsizei, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); + typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat * coord); + typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); + typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble * coord); + typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, + GLsizei stride, + const GLvoid * + pointer); #endif #ifndef GL_REND_screen_coordinates @@ -5061,51 +6767,68 @@ typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei strid #ifndef GL_EXT_coordinate_frame #define GL_EXT_coordinate_frame 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTangent3bEXT (GLbyte, GLbyte, GLbyte); -GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *); -GLAPI void APIENTRY glTangent3dEXT (GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *); -GLAPI void APIENTRY glTangent3fEXT (GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *); -GLAPI void APIENTRY glTangent3iEXT (GLint, GLint, GLint); -GLAPI void APIENTRY glTangent3ivEXT (const GLint *); -GLAPI void APIENTRY glTangent3sEXT (GLshort, GLshort, GLshort); -GLAPI void APIENTRY glTangent3svEXT (const GLshort *); -GLAPI void APIENTRY glBinormal3bEXT (GLbyte, GLbyte, GLbyte); -GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *); -GLAPI void APIENTRY glBinormal3dEXT (GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *); -GLAPI void APIENTRY glBinormal3fEXT (GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *); -GLAPI void APIENTRY glBinormal3iEXT (GLint, GLint, GLint); -GLAPI void APIENTRY glBinormal3ivEXT (const GLint *); -GLAPI void APIENTRY glBinormal3sEXT (GLshort, GLshort, GLshort); -GLAPI void APIENTRY glBinormal3svEXT (const GLshort *); -GLAPI void APIENTRY glTangentPointerEXT (GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glBinormalPointerEXT (GLenum, GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); -typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); -typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); -typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); -typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); -typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); -typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); -typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); -typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); -typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); -typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); + GLAPI void APIENTRY glTangent3bEXT (GLbyte, GLbyte, GLbyte); + GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *); + GLAPI void APIENTRY glTangent3dEXT (GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *); + GLAPI void APIENTRY glTangent3fEXT (GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *); + GLAPI void APIENTRY glTangent3iEXT (GLint, GLint, GLint); + GLAPI void APIENTRY glTangent3ivEXT (const GLint *); + GLAPI void APIENTRY glTangent3sEXT (GLshort, GLshort, GLshort); + GLAPI void APIENTRY glTangent3svEXT (const GLshort *); + GLAPI void APIENTRY glBinormal3bEXT (GLbyte, GLbyte, GLbyte); + GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *); + GLAPI void APIENTRY glBinormal3dEXT (GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *); + GLAPI void APIENTRY glBinormal3fEXT (GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *); + GLAPI void APIENTRY glBinormal3iEXT (GLint, GLint, GLint); + GLAPI void APIENTRY glBinormal3ivEXT (const GLint *); + GLAPI void APIENTRY glBinormal3sEXT (GLshort, GLshort, GLshort); + GLAPI void APIENTRY glBinormal3svEXT (const GLshort *); + GLAPI void APIENTRY glTangentPointerEXT (GLenum, GLsizei, const GLvoid *); + GLAPI void APIENTRY glBinormalPointerEXT (GLenum, GLsizei, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, + GLbyte tz); + typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte * v); + typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, + GLdouble tz); + typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, + GLfloat tz); + typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, + GLint tz); + typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, + GLshort tz); + typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort * v); + typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, + GLbyte bz); + typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte * v); + typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, + GLdouble bz); + typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, + GLfloat bz); + typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, + GLint bz); + typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, + GLshort bz); + typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort * v); + typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, + GLsizei stride, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, + GLsizei stride, + const GLvoid * + pointer); #endif #ifndef GL_EXT_texture_env_combine @@ -5127,153 +6850,660 @@ typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei strid #ifndef GL_SUNX_constant_data #define GL_SUNX_constant_data 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFinishTextureSUNX (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); + GLAPI void APIENTRY glFinishTextureSUNX (void); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); #endif #ifndef GL_SUN_global_alpha #define GL_SUN_global_alpha 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte); -GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort); -GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint); -GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat); -GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble); -GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte); -GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort); -GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); + GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte); + GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort); + GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint); + GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat); + GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble); + GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte); + GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort); + GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort + factor); + typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); #endif #ifndef GL_SUN_triangle_list #define GL_SUN_triangle_list 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint); -GLAPI void APIENTRY glReplacementCodeusSUN (GLushort); -GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte); -GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *); -GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *); -GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *); -GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum, GLsizei, const GLvoid* *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const GLvoid* *pointer); + GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint); + GLAPI void APIENTRY glReplacementCodeusSUN (GLushort); + GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte); + GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *); + GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *); + GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *); + GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum, GLsizei, + const GLvoid * *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint * + code); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort * + code); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte * + code); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, + GLsizei + stride, + const GLvoid + * *pointer); #endif #ifndef GL_SUN_vertex #define GL_SUN_vertex 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat); -GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *, const GLfloat *); -GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *, const GLfloat *); -GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat, GLfloat, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *, const GLubyte *, const GLfloat *); -GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *, const GLubyte *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); + GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte, GLubyte, GLubyte, + GLubyte, GLfloat, GLfloat); + GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *, + const GLfloat *); + GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte, GLubyte, GLubyte, + GLubyte, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *, + const GLfloat *); + GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, + GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, + GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *, + const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat, GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat, GLfloat, GLfloat, + GLfloat, GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat, GLfloat, + GLubyte, GLubyte, + GLubyte, GLubyte, + GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *, + const GLubyte *, + const GLfloat *); + GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *, + const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *, + const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat + *, + const GLfloat + *, + const GLfloat + *, + const GLfloat + *); + GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat + *, + const GLfloat + *, + const GLfloat + *, + const GLfloat + *); + GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *, + const GLfloat *); + GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint, + GLubyte, + GLubyte, + GLubyte, + GLubyte, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint + *, + const GLubyte + *, + const GLfloat + *); + GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint + *, + const GLfloat + *, + const GLfloat + *); + GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint + *, + const GLfloat + *, + const GLfloat + *); + GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const + GLuint + *, + const + GLfloat + *, + const + GLfloat + *, + const + GLfloat + *); + GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const + GLuint *, + const + GLfloat *, + const + GLfloat *); + GLAPI void APIENTRY + glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY + glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *, + const GLfloat *, + const GLfloat *, + const GLfloat *); + GLAPI void APIENTRY + glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat, + GLfloat); + GLAPI void APIENTRY + glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint + *, + const + GLfloat *, + const + GLfloat *, + const + GLfloat *, + const + GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, + GLubyte g, + GLubyte b, + GLubyte a, + GLfloat x, + GLfloat y); + typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte * c, + const GLfloat * + v); + typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, + GLubyte g, + GLubyte b, + GLubyte a, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte * c, + const GLfloat * + v); + typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, + GLfloat g, + GLfloat b, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat * c, + const GLfloat * v); + typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, + GLfloat ny, + GLfloat nz, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat * n, + const GLfloat * + v); + typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, + GLfloat g, + GLfloat b, + GLfloat a, + GLfloat nx, + GLfloat ny, + GLfloat nz, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const + GLfloat * + c, + const + GLfloat * + n, + const + GLfloat * + v); + typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, + GLfloat t, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat * + tc, + const GLfloat * + v); + typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, + GLfloat t, + GLfloat p, + GLfloat q, + GLfloat x, + GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat * + tc, + const GLfloat * + v); + typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat + s, + GLfloat + t, + GLubyte + r, + GLubyte + g, + GLubyte + b, + GLubyte + a, + GLfloat + x, + GLfloat + y, + GLfloat + z); + typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const + GLfloat + * tc, + const + GLubyte + * c, + const + GLfloat + * v); + typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, + GLfloat t, + GLfloat r, + GLfloat g, + GLfloat b, + GLfloat x, + GLfloat y, + GLfloat + z); + typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const + GLfloat * + tc, + const + GLfloat * + c, + const + GLfloat * + v); + typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat + s, + GLfloat + t, + GLfloat + nx, + GLfloat + ny, + GLfloat + nz, + GLfloat + x, + GLfloat + y, + GLfloat + z); + typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const + GLfloat + * tc, + const + GLfloat + * n, + const + GLfloat + * v); + typedef void (APIENTRYP + PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, + GLfloat t, + GLfloat r, + GLfloat g, + GLfloat b, + GLfloat a, + GLfloat nx, + GLfloat ny, + GLfloat nz, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP + PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const + GLfloat * + tc, + const + GLfloat * + c, + const + GLfloat * + n, + const + GLfloat * + v); + typedef void (APIENTRYP + PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, + GLfloat t, + GLfloat p, + GLfloat q, + GLfloat r, + GLfloat g, + GLfloat b, + GLfloat a, + GLfloat nx, + GLfloat ny, + GLfloat nz, + GLfloat x, + GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP + PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const + GLfloat * + tc, + const + GLfloat * + c, + const + GLfloat * + n, + const + GLfloat * + v); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, + GLfloat x, + GLfloat y, + GLfloat + z); + typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const + GLuint * + rc, + const + GLfloat * + v); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, + GLubyte r, + GLubyte g, + GLubyte b, + GLubyte a, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const + GLuint * + rc, + const + GLubyte * + c, + const + GLfloat * + v); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, + GLfloat r, + GLfloat g, + GLfloat b, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint + * rc, + const + GLfloat * c, + const + GLfloat * + v); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, + GLfloat nx, + GLfloat ny, + GLfloat nz, + GLfloat x, + GLfloat y, + GLfloat z); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const + GLuint * + rc, + const + GLfloat * + n, + const + GLfloat * + v); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) + + + + + + + + (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, + GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) + + + + + + + + (const GLuint * rc, const GLfloat * c, const GLfloat * n, + const GLfloat * v); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, + GLfloat s, + GLfloat t, + GLfloat x, + GLfloat y, + GLfloat + z); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const + GLuint * + rc, + const + GLfloat * + tc, + const + GLfloat * + v); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) + + + + + + + + (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, + GLfloat x, GLfloat y, GLfloat z); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) + + + + + + + + (const GLuint * rc, const GLfloat * tc, const GLfloat * n, + const GLfloat * v); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) + + + + + + + + (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, + GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, + GLfloat z); + typedef void (APIENTRYP + PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) + + + + + + + + (const GLuint * rc, const GLfloat * tc, const GLfloat * c, + const GLfloat * n, const GLfloat * v); #endif #ifndef GL_EXT_blend_func_separate #define GL_EXT_blend_func_separate 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum, GLenum, GLenum, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); + GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum, GLenum, GLenum, + GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, + GLenum dfactorRGB, + GLenum + sfactorAlpha, + GLenum + dfactorAlpha); #endif #ifndef GL_INGR_blend_func_separate #define GL_INGR_blend_func_separate 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum, GLenum, GLenum, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); + GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum, GLenum, GLenum, + GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum + sfactorRGB, + GLenum + dfactorRGB, + GLenum + sfactorAlpha, + GLenum + dfactorAlpha); #endif #ifndef GL_INGR_color_clamp @@ -5315,13 +7545,19 @@ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLen #ifndef GL_EXT_vertex_weighting #define GL_EXT_vertex_weighting 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexWeightfEXT (GLfloat); -GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *); -GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei, GLenum, GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); + GLAPI void APIENTRY glVertexWeightfEXT (GLfloat); + GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *); + GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei, GLenum, GLsizei, + const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); + typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat * + weight); + typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, + GLenum type, + GLsizei stride, + const GLvoid * + pointer); #endif #ifndef GL_NV_light_max_exponent @@ -5331,43 +7567,126 @@ typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum t #ifndef GL_NV_vertex_array_range #define GL_NV_vertex_array_range 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); -GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); -typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const GLvoid *pointer); + GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); + GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); + typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, + const GLvoid * + pointer); #endif #ifndef GL_NV_register_combiners #define GL_NV_register_combiners 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCombinerParameterfvNV (GLenum, const GLfloat *); -GLAPI void APIENTRY glCombinerParameterfNV (GLenum, GLfloat); -GLAPI void APIENTRY glCombinerParameterivNV (GLenum, const GLint *); -GLAPI void APIENTRY glCombinerParameteriNV (GLenum, GLint); -GLAPI void APIENTRY glCombinerInputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum); -GLAPI void APIENTRY glCombinerOutputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLboolean, GLboolean, GLboolean); -GLAPI void APIENTRY glFinalCombinerInputNV (GLenum, GLenum, GLenum, GLenum); -GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum, GLenum, GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum, GLenum, GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum, GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum, GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum, GLenum, GLint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); -typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); -typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); -typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); + GLAPI void APIENTRY glCombinerParameterfvNV (GLenum, const GLfloat *); + GLAPI void APIENTRY glCombinerParameterfNV (GLenum, GLfloat); + GLAPI void APIENTRY glCombinerParameterivNV (GLenum, const GLint *); + GLAPI void APIENTRY glCombinerParameteriNV (GLenum, GLint); + GLAPI void APIENTRY glCombinerInputNV (GLenum, GLenum, GLenum, GLenum, + GLenum, GLenum); + GLAPI void APIENTRY glCombinerOutputNV (GLenum, GLenum, GLenum, GLenum, + GLenum, GLenum, GLenum, GLboolean, + GLboolean, GLboolean); + GLAPI void APIENTRY glFinalCombinerInputNV (GLenum, GLenum, GLenum, + GLenum); + GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum, GLenum, + GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum, GLenum, + GLenum, GLenum, + GLint *); + GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum, GLenum, + GLenum, GLfloat *); + GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum, GLenum, + GLenum, GLint *); + GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum, GLenum, + GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, + GLfloat param); + typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, + const GLint * + params); + typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, + GLenum portion, + GLenum variable, + GLenum input, + GLenum mapping, + GLenum componentUsage); + typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, + GLenum portion, + GLenum abOutput, + GLenum cdOutput, + GLenum sumOutput, + GLenum scale, + GLenum bias, + GLboolean + abDotProduct, + GLboolean + cdDotProduct, + GLboolean muxSum); + typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, + GLenum input, + GLenum mapping, + GLenum + componentUsage); + typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum + stage, + GLenum + portion, + GLenum + variable, + GLenum + pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum + stage, + GLenum + portion, + GLenum + variable, + GLenum + pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum + stage, + GLenum + portion, + GLenum + pname, + GLfloat + * + params); + typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum + stage, + GLenum + portion, + GLenum + pname, + GLint * + params); + typedef void (APIENTRYP + PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum + variable, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP + PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum + variable, + GLenum pname, + GLint * + params); #endif #ifndef GL_NV_fog_distance @@ -5389,63 +7708,76 @@ typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum var #ifndef GL_MESA_resize_buffers #define GL_MESA_resize_buffers 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glResizeBuffersMESA (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); + GLAPI void APIENTRY glResizeBuffersMESA (void); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); #endif #ifndef GL_MESA_window_pos #define GL_MESA_window_pos 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glWindowPos2dMESA (GLdouble, GLdouble); -GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *); -GLAPI void APIENTRY glWindowPos2fMESA (GLfloat, GLfloat); -GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *); -GLAPI void APIENTRY glWindowPos2iMESA (GLint, GLint); -GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *); -GLAPI void APIENTRY glWindowPos2sMESA (GLshort, GLshort); -GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *); -GLAPI void APIENTRY glWindowPos3dMESA (GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *); -GLAPI void APIENTRY glWindowPos3fMESA (GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *); -GLAPI void APIENTRY glWindowPos3iMESA (GLint, GLint, GLint); -GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *); -GLAPI void APIENTRY glWindowPos3sMESA (GLshort, GLshort, GLshort); -GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *); -GLAPI void APIENTRY glWindowPos4dMESA (GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *); -GLAPI void APIENTRY glWindowPos4fMESA (GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *); -GLAPI void APIENTRY glWindowPos4iMESA (GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *); -GLAPI void APIENTRY glWindowPos4sMESA (GLshort, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); -typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); + GLAPI void APIENTRY glWindowPos2dMESA (GLdouble, GLdouble); + GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *); + GLAPI void APIENTRY glWindowPos2fMESA (GLfloat, GLfloat); + GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *); + GLAPI void APIENTRY glWindowPos2iMESA (GLint, GLint); + GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *); + GLAPI void APIENTRY glWindowPos2sMESA (GLshort, GLshort); + GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *); + GLAPI void APIENTRY glWindowPos3dMESA (GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *); + GLAPI void APIENTRY glWindowPos3fMESA (GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *); + GLAPI void APIENTRY glWindowPos3iMESA (GLint, GLint, GLint); + GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *); + GLAPI void APIENTRY glWindowPos3sMESA (GLshort, GLshort, GLshort); + GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *); + GLAPI void APIENTRY glWindowPos4dMESA (GLdouble, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *); + GLAPI void APIENTRY glWindowPos4fMESA (GLfloat, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *); + GLAPI void APIENTRY glWindowPos4iMESA (GLint, GLint, GLint, GLint); + GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *); + GLAPI void APIENTRY glWindowPos4sMESA (GLshort, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, + GLdouble y); + typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); + typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); + typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); + typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, + GLdouble z); + typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, + GLint z); + typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, + GLshort z); + typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort * v); + typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble * v); + typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, + GLfloat z, GLfloat w); + typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat * v); + typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, + GLint z, GLint w); + typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint * v); + typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, + GLshort z, GLshort w); + typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort * v); #endif #ifndef GL_IBM_cull_vertex @@ -5455,33 +7787,111 @@ typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); #ifndef GL_IBM_multimode_draw_arrays #define GL_IBM_multimode_draw_arrays 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *, const GLint *, const GLsizei *, GLsizei, GLint); -GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *, const GLsizei *, GLenum, const GLvoid* const *, GLsizei, GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); -typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); + GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *, + const GLint *, + const GLsizei *, GLsizei, + GLint); + GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *, + const GLsizei *, GLenum, + const GLvoid * const *, + GLsizei, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum * + mode, + const GLint * + first, + const GLsizei * + count, + GLsizei + primcount, + GLint + modestride); + typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum * + mode, + const GLsizei + * count, + GLenum type, + const GLvoid * + const + *indices, + GLsizei + primcount, + GLint + modestride); #endif #ifndef GL_IBM_vertex_array_lists #define GL_IBM_vertex_array_lists 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); -GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); -GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint, const GLboolean* *, GLint); -GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); -GLAPI void APIENTRY glIndexPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); -GLAPI void APIENTRY glNormalPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); -GLAPI void APIENTRY glTexCoordPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); -GLAPI void APIENTRY glVertexPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); + GLAPI void APIENTRY glColorPointerListIBM (GLint, GLenum, GLint, + const GLvoid * *, GLint); + GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint, GLenum, GLint, + const GLvoid * *, + GLint); + GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint, const GLboolean * *, + GLint); + GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum, GLint, + const GLvoid * *, GLint); + GLAPI void APIENTRY glIndexPointerListIBM (GLenum, GLint, + const GLvoid * *, GLint); + GLAPI void APIENTRY glNormalPointerListIBM (GLenum, GLint, + const GLvoid * *, GLint); + GLAPI void APIENTRY glTexCoordPointerListIBM (GLint, GLenum, GLint, + const GLvoid * *, GLint); + GLAPI void APIENTRY glVertexPointerListIBM (GLint, GLenum, GLint, + const GLvoid * *, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, + GLenum type, + GLint stride, + const GLvoid * + *pointer, + GLint ptrstride); + typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint + size, + GLenum + type, + GLint + stride, + const + GLvoid * + *pointer, + GLint + ptrstride); + typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, + const GLboolean + * *pointer, + GLint + ptrstride); + typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, + GLint stride, + const GLvoid * + *pointer, + GLint + ptrstride); + typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, + GLint stride, + const GLvoid * + *pointer, + GLint ptrstride); + typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, + GLint stride, + const GLvoid * + *pointer, + GLint ptrstride); + typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, + GLenum type, + GLint stride, + const GLvoid * + *pointer, + GLint + ptrstride); + typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, + GLenum type, + GLint stride, + const GLvoid * + *pointer, + GLint ptrstride); #endif #ifndef GL_SGIX_subsample @@ -5511,19 +7921,20 @@ typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, #ifndef GL_3DFX_tbuffer #define GL_3DFX_tbuffer 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTbufferMask3DFX (GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); + GLAPI void APIENTRY glTbufferMask3DFX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); #endif #ifndef GL_EXT_multisample #define GL_EXT_multisample 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSampleMaskEXT (GLclampf, GLboolean); -GLAPI void APIENTRY glSamplePatternEXT (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); -typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); + GLAPI void APIENTRY glSampleMaskEXT (GLclampf, GLboolean); + GLAPI void APIENTRY glSamplePatternEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, + GLboolean invert); + typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); #endif #ifndef GL_SGIX_vertex_preclip @@ -5545,17 +7956,23 @@ typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); #ifndef GL_SGIS_texture_color_mask #define GL_SGIS_texture_color_mask 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean, GLboolean, GLboolean, GLboolean); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean, GLboolean, + GLboolean, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, + GLboolean green, + GLboolean blue, + GLboolean alpha); #endif #ifndef GL_SGIX_igloo_interface #define GL_SGIX_igloo_interface 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid *params); + GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, + const GLvoid * + params); #endif #ifndef GL_EXT_texture_env_dot3 @@ -5569,45 +7986,90 @@ typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid #ifndef GL_NV_fence #define GL_NV_fence 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenFencesNV (GLsizei, GLuint *); -GLAPI GLboolean APIENTRY glIsFenceNV (GLuint); -GLAPI GLboolean APIENTRY glTestFenceNV (GLuint); -GLAPI void APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glFinishFenceNV (GLuint); -GLAPI void APIENTRY glSetFenceNV (GLuint, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); -typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); -typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); -typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); -typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); + GLAPI void APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenFencesNV (GLsizei, GLuint *); + GLAPI GLboolean APIENTRY glIsFenceNV (GLuint); + GLAPI GLboolean APIENTRY glTestFenceNV (GLuint); + GLAPI void APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glFinishFenceNV (GLuint); + GLAPI void APIENTRY glSetFenceNV (GLuint, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, + const GLuint * fences); + typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, + GLuint * fences); + typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); + typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); + typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); + typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, + GLenum condition); #endif #ifndef GL_NV_evaluators #define GL_NV_evaluators 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLint, GLint, GLboolean, const GLvoid *); -GLAPI void APIENTRY glMapParameterivNV (GLenum, GLenum, const GLint *); -GLAPI void APIENTRY glMapParameterfvNV (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glGetMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLboolean, GLvoid *); -GLAPI void APIENTRY glGetMapParameterivNV (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGetMapParameterfvNV (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum, GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glEvalMapsNV (GLenum, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); -typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); -typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); + GLAPI void APIENTRY glMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, + GLsizei, GLint, GLint, + GLboolean, const GLvoid *); + GLAPI void APIENTRY glMapParameterivNV (GLenum, GLenum, const GLint *); + GLAPI void APIENTRY glMapParameterfvNV (GLenum, GLenum, const GLfloat *); + GLAPI void APIENTRY glGetMapControlPointsNV (GLenum, GLuint, GLenum, + GLsizei, GLsizei, GLboolean, + GLvoid *); + GLAPI void APIENTRY glGetMapParameterivNV (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glGetMapParameterfvNV (GLenum, GLenum, GLfloat *); + GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum, GLuint, GLenum, + GLint *); + GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum, GLuint, GLenum, + GLfloat *); + GLAPI void APIENTRY glEvalMapsNV (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, + GLuint index, + GLenum type, + GLsizei ustride, + GLsizei vstride, + GLint uorder, + GLint vorder, + GLboolean packed, + const GLvoid * + points); + typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, + GLenum pname, + const GLint * params); + typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, + GLenum pname, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, + GLuint index, + GLenum type, + GLsizei ustride, + GLsizei vstride, + GLboolean packed, + GLvoid * points); + typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, + GLenum pname, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum + target, + GLuint index, + GLenum pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum + target, + GLuint index, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); #endif #ifndef GL_NV_packed_depth_stencil @@ -5617,11 +8079,24 @@ typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); #ifndef GL_NV_register_combiners2 #define GL_NV_register_combiners2 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum, GLenum, const GLfloat *); -GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum, GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); + GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum, GLenum, + const GLfloat *); + GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum, GLenum, + GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum + stage, + GLenum + pname, + const + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum + stage, + GLenum + pname, + GLfloat * + params); #endif #ifndef GL_NV_texture_compression_vtc @@ -5647,135 +8122,302 @@ typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, G #ifndef GL_NV_vertex_program #define GL_NV_vertex_program 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei, const GLuint *, GLboolean *); -GLAPI void APIENTRY glBindProgramNV (GLenum, GLuint); -GLAPI void APIENTRY glDeleteProgramsNV (GLsizei, const GLuint *); -GLAPI void APIENTRY glExecuteProgramNV (GLenum, GLuint, const GLfloat *); -GLAPI void APIENTRY glGenProgramsNV (GLsizei, GLuint *); -GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum, GLuint, GLenum, GLdouble *); -GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetProgramivNV (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetProgramStringNV (GLuint, GLenum, GLubyte *); -GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum, GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint, GLenum, GLdouble *); -GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetVertexAttribivNV (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint, GLenum, GLvoid* *); -GLAPI GLboolean APIENTRY glIsProgramNV (GLuint); -GLAPI void APIENTRY glLoadProgramNV (GLenum, GLuint, GLsizei, const GLubyte *); -GLAPI void APIENTRY glProgramParameter4dNV (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glProgramParameter4dvNV (GLenum, GLuint, const GLdouble *); -GLAPI void APIENTRY glProgramParameter4fNV (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glProgramParameter4fvNV (GLenum, GLuint, const GLfloat *); -GLAPI void APIENTRY glProgramParameters4dvNV (GLenum, GLuint, GLuint, const GLdouble *); -GLAPI void APIENTRY glProgramParameters4fvNV (GLenum, GLuint, GLuint, const GLfloat *); -GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei, const GLuint *); -GLAPI void APIENTRY glTrackMatrixNV (GLenum, GLuint, GLenum, GLenum); -GLAPI void APIENTRY glVertexAttribPointerNV (GLuint, GLint, GLenum, GLsizei, const GLvoid *); -GLAPI void APIENTRY glVertexAttrib1dNV (GLuint, GLdouble); -GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib1fNV (GLuint, GLfloat); -GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib1sNV (GLuint, GLshort); -GLAPI void APIENTRY glVertexAttrib1svNV (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib2dNV (GLuint, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib2fNV (GLuint, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib2sNV (GLuint, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib2svNV (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib3dNV (GLuint, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib3fNV (GLuint, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib3sNV (GLuint, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib3svNV (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4dNV (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint, const GLdouble *); -GLAPI void APIENTRY glVertexAttrib4fNV (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint, const GLfloat *); -GLAPI void APIENTRY glVertexAttrib4sNV (GLuint, GLshort, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexAttrib4svNV (GLuint, const GLshort *); -GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); -GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint, const GLubyte *); -GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint, GLsizei, const GLdouble *); -GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glVertexAttribs1svNV (GLuint, GLsizei, const GLshort *); -GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint, GLsizei, const GLdouble *); -GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glVertexAttribs2svNV (GLuint, GLsizei, const GLshort *); -GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint, GLsizei, const GLdouble *); -GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glVertexAttribs3svNV (GLuint, GLsizei, const GLshort *); -GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint, GLsizei, const GLdouble *); -GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint, GLsizei, const GLfloat *); -GLAPI void APIENTRY glVertexAttribs4svNV (GLuint, GLsizei, const GLshort *); -GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint, GLsizei, const GLubyte *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); -typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); -typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); -typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); -typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); -typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); -typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLuint count, const GLdouble *v); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLuint count, const GLfloat *v); -typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); -typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); + GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei, const GLuint *, + GLboolean *); + GLAPI void APIENTRY glBindProgramNV (GLenum, GLuint); + GLAPI void APIENTRY glDeleteProgramsNV (GLsizei, const GLuint *); + GLAPI void APIENTRY glExecuteProgramNV (GLenum, GLuint, const GLfloat *); + GLAPI void APIENTRY glGenProgramsNV (GLsizei, GLuint *); + GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum, GLuint, GLenum, + GLdouble *); + GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum, GLuint, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetProgramivNV (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetProgramStringNV (GLuint, GLenum, GLubyte *); + GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum, GLuint, GLenum, + GLint *); + GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint, GLenum, GLdouble *); + GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint, GLenum, GLfloat *); + GLAPI void APIENTRY glGetVertexAttribivNV (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint, GLenum, + GLvoid * *); + GLAPI GLboolean APIENTRY glIsProgramNV (GLuint); + GLAPI void APIENTRY glLoadProgramNV (GLenum, GLuint, GLsizei, + const GLubyte *); + GLAPI void APIENTRY glProgramParameter4dNV (GLenum, GLuint, GLdouble, + GLdouble, GLdouble, GLdouble); + GLAPI void APIENTRY glProgramParameter4dvNV (GLenum, GLuint, + const GLdouble *); + GLAPI void APIENTRY glProgramParameter4fNV (GLenum, GLuint, GLfloat, + GLfloat, GLfloat, GLfloat); + GLAPI void APIENTRY glProgramParameter4fvNV (GLenum, GLuint, + const GLfloat *); + GLAPI void APIENTRY glProgramParameters4dvNV (GLenum, GLuint, GLuint, + const GLdouble *); + GLAPI void APIENTRY glProgramParameters4fvNV (GLenum, GLuint, GLuint, + const GLfloat *); + GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei, const GLuint *); + GLAPI void APIENTRY glTrackMatrixNV (GLenum, GLuint, GLenum, GLenum); + GLAPI void APIENTRY glVertexAttribPointerNV (GLuint, GLint, GLenum, + GLsizei, const GLvoid *); + GLAPI void APIENTRY glVertexAttrib1dNV (GLuint, GLdouble); + GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib1fNV (GLuint, GLfloat); + GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib1sNV (GLuint, GLshort); + GLAPI void APIENTRY glVertexAttrib1svNV (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib2dNV (GLuint, GLdouble, GLdouble); + GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib2fNV (GLuint, GLfloat, GLfloat); + GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib2sNV (GLuint, GLshort, GLshort); + GLAPI void APIENTRY glVertexAttrib2svNV (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib3dNV (GLuint, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib3fNV (GLuint, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib3sNV (GLuint, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glVertexAttrib3svNV (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4dNV (GLuint, GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint, const GLdouble *); + GLAPI void APIENTRY glVertexAttrib4fNV (GLuint, GLfloat, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint, const GLfloat *); + GLAPI void APIENTRY glVertexAttrib4sNV (GLuint, GLshort, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glVertexAttrib4svNV (GLuint, const GLshort *); + GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint, GLubyte, GLubyte, + GLubyte, GLubyte); + GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint, const GLubyte *); + GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint, GLsizei, + const GLdouble *); + GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint, GLsizei, + const GLfloat *); + GLAPI void APIENTRY glVertexAttribs1svNV (GLuint, GLsizei, + const GLshort *); + GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint, GLsizei, + const GLdouble *); + GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint, GLsizei, + const GLfloat *); + GLAPI void APIENTRY glVertexAttribs2svNV (GLuint, GLsizei, + const GLshort *); + GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint, GLsizei, + const GLdouble *); + GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint, GLsizei, + const GLfloat *); + GLAPI void APIENTRY glVertexAttribs3svNV (GLuint, GLsizei, + const GLshort *); + GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint, GLsizei, + const GLdouble *); + GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint, GLsizei, + const GLfloat *); + GLAPI void APIENTRY glVertexAttribs4svNV (GLuint, GLsizei, + const GLshort *); + GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint, GLsizei, + const GLubyte *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, + const GLuint + * programs, + GLboolean * + residences); + typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, + GLuint id); + typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, + const GLuint * + programs); + typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, + GLuint id, + const GLfloat * + params); + typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, + GLuint * programs); + typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, + GLuint index, + GLenum pname, + GLdouble * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, + GLuint index, + GLenum pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, + GLenum pname, + GLubyte * program); + typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, + GLuint address, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, + GLenum pname, + GLdouble * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, + GLenum pname, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, + GLenum pname, + GLvoid * + *pointer); + typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); + typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, + GLsizei len, + const GLubyte * program); + typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, + GLuint index, + GLdouble x, + GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, + GLuint index, + const GLdouble * + v); + typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, + GLuint index, + GLfloat x, + GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, + GLuint index, + const GLfloat * + v); + typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, + GLuint index, + GLuint count, + const GLdouble * + v); + typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, + GLuint index, + GLuint count, + const GLfloat * + v); + typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, + const GLuint + * programs); + typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, + GLuint address, + GLenum matrix, + GLenum transform); + typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, + GLint fsize, + GLenum type, + GLsizei stride, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, + GLdouble x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, + GLfloat x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, + GLshort x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, + GLdouble x, + GLdouble y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, + GLfloat x, GLfloat y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, + GLshort x, GLshort y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, + GLdouble x, + GLdouble y, + GLdouble z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, + GLfloat x, GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, + GLshort x, GLshort y, + GLshort z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, + GLdouble x, + GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, + GLfloat x, GLfloat y, + GLfloat z, GLfloat w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, + GLshort x, GLshort y, + GLshort z, GLshort w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, + GLubyte x, GLubyte y, + GLubyte z, + GLubyte w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, + const GLubyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, + GLsizei count, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, + GLsizei count, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, + GLsizei count, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, + GLsizei count, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, + GLsizei count, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, + GLsizei count, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, + GLsizei count, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, + GLsizei count, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, + GLsizei count, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, + GLsizei count, + const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, + GLsizei count, + const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, + GLsizei count, + const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, + GLsizei count, + const GLubyte * v); #endif #ifndef GL_SGIX_texture_coordinate_clamp @@ -5805,295 +8447,601 @@ typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei cou #ifndef GL_ATI_envmap_bumpmap #define GL_ATI_envmap_bumpmap 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexBumpParameterivATI (GLenum, const GLint *); -GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum, const GLfloat *); -GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum, GLint *); -GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); -typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); -typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); -typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); + GLAPI void APIENTRY glTexBumpParameterivATI (GLenum, const GLint *); + GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum, const GLfloat *); + GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum, GLint *); + GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, + const GLint * + param); + typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, + const GLfloat * + param); + typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, + GLint * + param); + typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, + GLfloat * + param); #endif #ifndef GL_ATI_fragment_shader #define GL_ATI_fragment_shader 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint); -GLAPI void APIENTRY glBindFragmentShaderATI (GLuint); -GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint); -GLAPI void APIENTRY glBeginFragmentShaderATI (void); -GLAPI void APIENTRY glEndFragmentShaderATI (void); -GLAPI void APIENTRY glPassTexCoordATI (GLuint, GLuint, GLenum); -GLAPI void APIENTRY glSampleMapATI (GLuint, GLuint, GLenum); -GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint, const GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); -typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); -typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); -typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); -typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); -typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); -typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); -typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); -typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); -typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); -typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); -typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); -typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); + GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint); + GLAPI void APIENTRY glBindFragmentShaderATI (GLuint); + GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint); + GLAPI void APIENTRY glBeginFragmentShaderATI (void); + GLAPI void APIENTRY glEndFragmentShaderATI (void); + GLAPI void APIENTRY glPassTexCoordATI (GLuint, GLuint, GLenum); + GLAPI void APIENTRY glSampleMapATI (GLuint, GLuint, GLenum); + GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, + GLuint, GLuint, GLuint); + GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, + GLuint, GLuint, GLuint, GLuint, + GLuint, GLuint); + GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, + GLuint, GLuint, GLuint, GLuint, + GLuint, GLuint, GLuint, GLuint, + GLuint); + GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, + GLuint, GLuint); + GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, + GLuint, GLuint, GLuint, GLuint, + GLuint); + GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, + GLuint, GLuint, GLuint, GLuint, + GLuint, GLuint, GLuint, + GLuint); + GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint, + const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); + typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); + typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); + typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); + typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); + typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, + GLuint coord, + GLenum swizzle); + typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, + GLenum swizzle); + typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, + GLuint dst, + GLuint dstMask, + GLuint dstMod, + GLuint arg1, + GLuint arg1Rep, + GLuint arg1Mod); + typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, + GLuint dst, + GLuint dstMask, + GLuint dstMod, + GLuint arg1, + GLuint arg1Rep, + GLuint arg1Mod, + GLuint arg2, + GLuint arg2Rep, + GLuint arg2Mod); + typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, + GLuint dst, + GLuint dstMask, + GLuint dstMod, + GLuint arg1, + GLuint arg1Rep, + GLuint arg1Mod, + GLuint arg2, + GLuint arg2Rep, + GLuint arg2Mod, + GLuint arg3, + GLuint arg3Rep, + GLuint arg3Mod); + typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, + GLuint dst, + GLuint dstMod, + GLuint arg1, + GLuint arg1Rep, + GLuint arg1Mod); + typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, + GLuint dst, + GLuint dstMod, + GLuint arg1, + GLuint arg1Rep, + GLuint arg1Mod, + GLuint arg2, + GLuint arg2Rep, + GLuint arg2Mod); + typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, + GLuint dst, + GLuint dstMod, + GLuint arg1, + GLuint arg1Rep, + GLuint arg1Mod, + GLuint arg2, + GLuint arg2Rep, + GLuint arg2Mod, + GLuint arg3, + GLuint arg3Rep, + GLuint arg3Mod); + typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint + dst, + const + GLfloat * + value); #endif #ifndef GL_ATI_pn_triangles #define GL_ATI_pn_triangles 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPNTrianglesiATI (GLenum, GLint); -GLAPI void APIENTRY glPNTrianglesfATI (GLenum, GLfloat); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); + GLAPI void APIENTRY glPNTrianglesiATI (GLenum, GLint); + GLAPI void APIENTRY glPNTrianglesfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, + GLfloat param); #endif #ifndef GL_ATI_vertex_array_object #define GL_ATI_vertex_array_object 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei, const GLvoid *, GLenum); -GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint); -GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint, GLuint, GLsizei, const GLvoid *, GLenum); -GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetObjectBufferivATI (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glFreeObjectBufferATI (GLuint); -GLAPI void APIENTRY glArrayObjectATI (GLenum, GLint, GLenum, GLsizei, GLuint, GLuint); -GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum, GLenum, GLfloat *); -GLAPI void APIENTRY glGetArrayObjectivATI (GLenum, GLenum, GLint *); -GLAPI void APIENTRY glVariantArrayObjectATI (GLuint, GLenum, GLsizei, GLuint, GLuint); -GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint, GLenum, GLint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const GLvoid *pointer, GLenum usage); -typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); -typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); -typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); -typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); + GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei, const GLvoid *, + GLenum); + GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint); + GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint, GLuint, GLsizei, + const GLvoid *, GLenum); + GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint, GLenum, GLfloat *); + GLAPI void APIENTRY glGetObjectBufferivATI (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glFreeObjectBufferATI (GLuint); + GLAPI void APIENTRY glArrayObjectATI (GLenum, GLint, GLenum, GLsizei, + GLuint, GLuint); + GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum, GLenum, GLfloat *); + GLAPI void APIENTRY glGetArrayObjectivATI (GLenum, GLenum, GLint *); + GLAPI void APIENTRY glVariantArrayObjectATI (GLuint, GLenum, GLsizei, + GLuint, GLuint); + GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint, GLenum, + GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, + const GLvoid * + pointer, + GLenum usage); + typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); + typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, + GLuint offset, + GLsizei size, + const GLvoid * + pointer, + GLenum preserve); + typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, + GLenum pname, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); + typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, + GLint size, GLenum type, + GLsizei stride, + GLuint buffer, + GLuint offset); + typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, + GLenum pname, + GLfloat * params); + typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, + GLenum type, + GLsizei stride, + GLuint buffer, + GLuint offset); + typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, + GLenum + pname, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, + GLenum + pname, + GLint * + params); #endif #ifndef GL_EXT_vertex_shader #define GL_EXT_vertex_shader 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBeginVertexShaderEXT (void); -GLAPI void APIENTRY glEndVertexShaderEXT (void); -GLAPI void APIENTRY glBindVertexShaderEXT (GLuint); -GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint); -GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint); -GLAPI void APIENTRY glShaderOp1EXT (GLenum, GLuint, GLuint); -GLAPI void APIENTRY glShaderOp2EXT (GLenum, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glShaderOp3EXT (GLenum, GLuint, GLuint, GLuint, GLuint); -GLAPI void APIENTRY glSwizzleEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); -GLAPI void APIENTRY glWriteMaskEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); -GLAPI void APIENTRY glInsertComponentEXT (GLuint, GLuint, GLuint); -GLAPI void APIENTRY glExtractComponentEXT (GLuint, GLuint, GLuint); -GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum, GLenum, GLenum, GLuint); -GLAPI void APIENTRY glSetInvariantEXT (GLuint, GLenum, const GLvoid *); -GLAPI void APIENTRY glSetLocalConstantEXT (GLuint, GLenum, const GLvoid *); -GLAPI void APIENTRY glVariantbvEXT (GLuint, const GLbyte *); -GLAPI void APIENTRY glVariantsvEXT (GLuint, const GLshort *); -GLAPI void APIENTRY glVariantivEXT (GLuint, const GLint *); -GLAPI void APIENTRY glVariantfvEXT (GLuint, const GLfloat *); -GLAPI void APIENTRY glVariantdvEXT (GLuint, const GLdouble *); -GLAPI void APIENTRY glVariantubvEXT (GLuint, const GLubyte *); -GLAPI void APIENTRY glVariantusvEXT (GLuint, const GLushort *); -GLAPI void APIENTRY glVariantuivEXT (GLuint, const GLuint *); -GLAPI void APIENTRY glVariantPointerEXT (GLuint, GLenum, GLuint, const GLvoid *); -GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint); -GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint); -GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum, GLenum); -GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum, GLenum); -GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum, GLenum, GLenum); -GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum, GLenum); -GLAPI GLuint APIENTRY glBindParameterEXT (GLenum); -GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint, GLenum); -GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint, GLenum, GLboolean *); -GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetVariantPointervEXT (GLuint, GLenum, GLvoid* *); -GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint, GLenum, GLboolean *); -GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint, GLenum, GLboolean *); -GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint, GLenum, GLfloat *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); -typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); -typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); -typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); -typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); -typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); -typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); -typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); -typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); -typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); -typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); -typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); -typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); -typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); -typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); -typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); -typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); -typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); -typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); -typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); -typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); -typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); -typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); -typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); -typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); -typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); -typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); -typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); -typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); -typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); -typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, GLvoid* *data); -typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); -typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); -typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); -typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); + GLAPI void APIENTRY glBeginVertexShaderEXT (void); + GLAPI void APIENTRY glEndVertexShaderEXT (void); + GLAPI void APIENTRY glBindVertexShaderEXT (GLuint); + GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint); + GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint); + GLAPI void APIENTRY glShaderOp1EXT (GLenum, GLuint, GLuint); + GLAPI void APIENTRY glShaderOp2EXT (GLenum, GLuint, GLuint, GLuint); + GLAPI void APIENTRY glShaderOp3EXT (GLenum, GLuint, GLuint, GLuint, + GLuint); + GLAPI void APIENTRY glSwizzleEXT (GLuint, GLuint, GLenum, GLenum, GLenum, + GLenum); + GLAPI void APIENTRY glWriteMaskEXT (GLuint, GLuint, GLenum, GLenum, + GLenum, GLenum); + GLAPI void APIENTRY glInsertComponentEXT (GLuint, GLuint, GLuint); + GLAPI void APIENTRY glExtractComponentEXT (GLuint, GLuint, GLuint); + GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum, GLenum, GLenum, GLuint); + GLAPI void APIENTRY glSetInvariantEXT (GLuint, GLenum, const GLvoid *); + GLAPI void APIENTRY glSetLocalConstantEXT (GLuint, GLenum, + const GLvoid *); + GLAPI void APIENTRY glVariantbvEXT (GLuint, const GLbyte *); + GLAPI void APIENTRY glVariantsvEXT (GLuint, const GLshort *); + GLAPI void APIENTRY glVariantivEXT (GLuint, const GLint *); + GLAPI void APIENTRY glVariantfvEXT (GLuint, const GLfloat *); + GLAPI void APIENTRY glVariantdvEXT (GLuint, const GLdouble *); + GLAPI void APIENTRY glVariantubvEXT (GLuint, const GLubyte *); + GLAPI void APIENTRY glVariantusvEXT (GLuint, const GLushort *); + GLAPI void APIENTRY glVariantuivEXT (GLuint, const GLuint *); + GLAPI void APIENTRY glVariantPointerEXT (GLuint, GLenum, GLuint, + const GLvoid *); + GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint); + GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint); + GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum, GLenum); + GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum, GLenum); + GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum, GLenum, GLenum); + GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum, GLenum); + GLAPI GLuint APIENTRY glBindParameterEXT (GLenum); + GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint, GLenum); + GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint, GLenum, GLboolean *); + GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint, GLenum, GLfloat *); + GLAPI void APIENTRY glGetVariantPointervEXT (GLuint, GLenum, GLvoid * *); + GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint, GLenum, + GLboolean *); + GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint, GLenum, GLfloat *); + GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint, GLenum, + GLboolean *); + GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint, GLenum, + GLint *); + GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint, GLenum, + GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); + typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); + typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); + typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); + typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); + typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, + GLuint arg1); + typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, + GLuint arg1, GLuint arg2); + typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, + GLuint arg1, GLuint arg2, + GLuint arg3); + typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, + GLenum outX, GLenum outY, + GLenum outZ, GLenum outW); + typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, + GLenum outX, GLenum outY, + GLenum outZ, GLenum outW); + typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, + GLuint src, + GLuint num); + typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, + GLuint src, + GLuint num); + typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, + GLenum storagetype, + GLenum range, + GLuint components); + typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, + const GLvoid * addr); + typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, + GLenum type, + const GLvoid * + addr); + typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, + const GLbyte * addr); + typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, + const GLshort * addr); + typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, + const GLint * addr); + typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, + const GLfloat * addr); + typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, + const GLdouble * addr); + typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, + const GLubyte * addr); + typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, + const GLushort * addr); + typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, + const GLuint * addr); + typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, + GLenum type, + GLuint stride, + const GLvoid * addr); + typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); + typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint + id); + typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, + GLenum value); + typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, + GLenum + value); + typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, + GLenum coord, + GLenum value); + typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum + unit, + GLenum + value); + typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); + typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, + GLenum cap); + typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, + GLenum value, + GLboolean * + data); + typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, + GLenum value, + GLint * data); + typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, + GLenum value, + GLfloat * data); + typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, + GLenum value, + GLvoid * *data); + typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, + GLenum value, + GLboolean * + data); + typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, + GLenum value, + GLint * data); + typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, + GLenum value, + GLfloat * data); + typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, + GLenum + value, + GLboolean * + data); + typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, + GLenum + value, + GLint * + data); + typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, + GLenum value, + GLfloat * + data); #endif #ifndef GL_ATI_vertex_streams #define GL_ATI_vertex_streams 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexStream1sATI (GLenum, GLshort); -GLAPI void APIENTRY glVertexStream1svATI (GLenum, const GLshort *); -GLAPI void APIENTRY glVertexStream1iATI (GLenum, GLint); -GLAPI void APIENTRY glVertexStream1ivATI (GLenum, const GLint *); -GLAPI void APIENTRY glVertexStream1fATI (GLenum, GLfloat); -GLAPI void APIENTRY glVertexStream1fvATI (GLenum, const GLfloat *); -GLAPI void APIENTRY glVertexStream1dATI (GLenum, GLdouble); -GLAPI void APIENTRY glVertexStream1dvATI (GLenum, const GLdouble *); -GLAPI void APIENTRY glVertexStream2sATI (GLenum, GLshort, GLshort); -GLAPI void APIENTRY glVertexStream2svATI (GLenum, const GLshort *); -GLAPI void APIENTRY glVertexStream2iATI (GLenum, GLint, GLint); -GLAPI void APIENTRY glVertexStream2ivATI (GLenum, const GLint *); -GLAPI void APIENTRY glVertexStream2fATI (GLenum, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexStream2fvATI (GLenum, const GLfloat *); -GLAPI void APIENTRY glVertexStream2dATI (GLenum, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexStream2dvATI (GLenum, const GLdouble *); -GLAPI void APIENTRY glVertexStream3sATI (GLenum, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexStream3svATI (GLenum, const GLshort *); -GLAPI void APIENTRY glVertexStream3iATI (GLenum, GLint, GLint, GLint); -GLAPI void APIENTRY glVertexStream3ivATI (GLenum, const GLint *); -GLAPI void APIENTRY glVertexStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexStream3fvATI (GLenum, const GLfloat *); -GLAPI void APIENTRY glVertexStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexStream3dvATI (GLenum, const GLdouble *); -GLAPI void APIENTRY glVertexStream4sATI (GLenum, GLshort, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glVertexStream4svATI (GLenum, const GLshort *); -GLAPI void APIENTRY glVertexStream4iATI (GLenum, GLint, GLint, GLint, GLint); -GLAPI void APIENTRY glVertexStream4ivATI (GLenum, const GLint *); -GLAPI void APIENTRY glVertexStream4fATI (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glVertexStream4fvATI (GLenum, const GLfloat *); -GLAPI void APIENTRY glVertexStream4dATI (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glVertexStream4dvATI (GLenum, const GLdouble *); -GLAPI void APIENTRY glNormalStream3bATI (GLenum, GLbyte, GLbyte, GLbyte); -GLAPI void APIENTRY glNormalStream3bvATI (GLenum, const GLbyte *); -GLAPI void APIENTRY glNormalStream3sATI (GLenum, GLshort, GLshort, GLshort); -GLAPI void APIENTRY glNormalStream3svATI (GLenum, const GLshort *); -GLAPI void APIENTRY glNormalStream3iATI (GLenum, GLint, GLint, GLint); -GLAPI void APIENTRY glNormalStream3ivATI (GLenum, const GLint *); -GLAPI void APIENTRY glNormalStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glNormalStream3fvATI (GLenum, const GLfloat *); -GLAPI void APIENTRY glNormalStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glNormalStream3dvATI (GLenum, const GLdouble *); -GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum); -GLAPI void APIENTRY glVertexBlendEnviATI (GLenum, GLint); -GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum, GLfloat); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); -typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); + GLAPI void APIENTRY glVertexStream1sATI (GLenum, GLshort); + GLAPI void APIENTRY glVertexStream1svATI (GLenum, const GLshort *); + GLAPI void APIENTRY glVertexStream1iATI (GLenum, GLint); + GLAPI void APIENTRY glVertexStream1ivATI (GLenum, const GLint *); + GLAPI void APIENTRY glVertexStream1fATI (GLenum, GLfloat); + GLAPI void APIENTRY glVertexStream1fvATI (GLenum, const GLfloat *); + GLAPI void APIENTRY glVertexStream1dATI (GLenum, GLdouble); + GLAPI void APIENTRY glVertexStream1dvATI (GLenum, const GLdouble *); + GLAPI void APIENTRY glVertexStream2sATI (GLenum, GLshort, GLshort); + GLAPI void APIENTRY glVertexStream2svATI (GLenum, const GLshort *); + GLAPI void APIENTRY glVertexStream2iATI (GLenum, GLint, GLint); + GLAPI void APIENTRY glVertexStream2ivATI (GLenum, const GLint *); + GLAPI void APIENTRY glVertexStream2fATI (GLenum, GLfloat, GLfloat); + GLAPI void APIENTRY glVertexStream2fvATI (GLenum, const GLfloat *); + GLAPI void APIENTRY glVertexStream2dATI (GLenum, GLdouble, GLdouble); + GLAPI void APIENTRY glVertexStream2dvATI (GLenum, const GLdouble *); + GLAPI void APIENTRY glVertexStream3sATI (GLenum, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glVertexStream3svATI (GLenum, const GLshort *); + GLAPI void APIENTRY glVertexStream3iATI (GLenum, GLint, GLint, GLint); + GLAPI void APIENTRY glVertexStream3ivATI (GLenum, const GLint *); + GLAPI void APIENTRY glVertexStream3fATI (GLenum, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glVertexStream3fvATI (GLenum, const GLfloat *); + GLAPI void APIENTRY glVertexStream3dATI (GLenum, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glVertexStream3dvATI (GLenum, const GLdouble *); + GLAPI void APIENTRY glVertexStream4sATI (GLenum, GLshort, GLshort, + GLshort, GLshort); + GLAPI void APIENTRY glVertexStream4svATI (GLenum, const GLshort *); + GLAPI void APIENTRY glVertexStream4iATI (GLenum, GLint, GLint, GLint, + GLint); + GLAPI void APIENTRY glVertexStream4ivATI (GLenum, const GLint *); + GLAPI void APIENTRY glVertexStream4fATI (GLenum, GLfloat, GLfloat, + GLfloat, GLfloat); + GLAPI void APIENTRY glVertexStream4fvATI (GLenum, const GLfloat *); + GLAPI void APIENTRY glVertexStream4dATI (GLenum, GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glVertexStream4dvATI (GLenum, const GLdouble *); + GLAPI void APIENTRY glNormalStream3bATI (GLenum, GLbyte, GLbyte, GLbyte); + GLAPI void APIENTRY glNormalStream3bvATI (GLenum, const GLbyte *); + GLAPI void APIENTRY glNormalStream3sATI (GLenum, GLshort, GLshort, + GLshort); + GLAPI void APIENTRY glNormalStream3svATI (GLenum, const GLshort *); + GLAPI void APIENTRY glNormalStream3iATI (GLenum, GLint, GLint, GLint); + GLAPI void APIENTRY glNormalStream3ivATI (GLenum, const GLint *); + GLAPI void APIENTRY glNormalStream3fATI (GLenum, GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glNormalStream3fvATI (GLenum, const GLfloat *); + GLAPI void APIENTRY glNormalStream3dATI (GLenum, GLdouble, GLdouble, + GLdouble); + GLAPI void APIENTRY glNormalStream3dvATI (GLenum, const GLdouble *); + GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum); + GLAPI void APIENTRY glVertexBlendEnviATI (GLenum, GLint); + GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, + GLshort x); + typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, + const GLshort * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, + GLint x); + typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, + const GLint * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, + GLfloat x); + typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, + const GLfloat * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, + GLdouble x); + typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, + const GLdouble * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, + GLshort x, + GLshort y); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, + const GLshort * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, + GLint x, GLint y); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, + const GLint * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, + GLfloat x, + GLfloat y); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, + const GLfloat * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, + GLdouble x, + GLdouble y); + typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, + const GLdouble * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, + GLshort x, GLshort y, + GLshort z); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, + const GLshort * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, + GLint x, GLint y, + GLint z); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, + const GLint * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, + GLfloat x, GLfloat y, + GLfloat z); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, + const GLfloat * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, + GLdouble x, + GLdouble y, + GLdouble z); + typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, + const GLdouble * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, + GLshort x, GLshort y, + GLshort z, + GLshort w); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, + const GLshort * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, + GLint x, GLint y, + GLint z, GLint w); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, + const GLint * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, + GLfloat x, GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, + const GLfloat * + coords); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, + GLdouble x, + GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, + const GLdouble * + coords); + typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, + GLbyte nx, GLbyte ny, + GLbyte nz); + typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, + const GLbyte * + coords); + typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, + GLshort nx, + GLshort ny, + GLshort nz); + typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, + const GLshort * + coords); + typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, + GLint nx, GLint ny, + GLint nz); + typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, + const GLint * + coords); + typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, + GLfloat nx, + GLfloat ny, + GLfloat nz); + typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, + const GLfloat * + coords); + typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, + GLdouble nx, + GLdouble ny, + GLdouble nz); + typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, + const GLdouble * + coords); + typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum + stream); + typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, + GLfloat param); #endif #ifndef GL_ATI_element_array #define GL_ATI_element_array 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glElementPointerATI (GLenum, const GLvoid *); -GLAPI void APIENTRY glDrawElementArrayATI (GLenum, GLsizei); -GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum, GLuint, GLuint, GLsizei); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); + GLAPI void APIENTRY glElementPointerATI (GLenum, const GLvoid *); + GLAPI void APIENTRY glDrawElementArrayATI (GLenum, GLsizei); + GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum, GLuint, GLuint, + GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, + GLsizei count); + typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, + GLuint start, + GLuint end, + GLsizei + count); #endif #ifndef GL_SUN_mesh_array #define GL_SUN_mesh_array 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum, GLint, GLsizei, GLsizei); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); + GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, + GLint first, + GLsizei count, + GLsizei width); #endif #ifndef GL_SUN_slice_accum @@ -6111,31 +9059,42 @@ typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, G #ifndef GL_NV_occlusion_query #define GL_NV_occlusion_query 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei, GLuint *); -GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei, const GLuint *); -GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint); -GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint); -GLAPI void APIENTRY glEndOcclusionQueryNV (void); -GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint, GLenum, GLint *); -GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint, GLenum, GLuint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); -typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); -typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); -typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); + GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei, GLuint *); + GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei, const GLuint *); + GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint); + GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint); + GLAPI void APIENTRY glEndOcclusionQueryNV (void); + GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint, GLenum, GLint *); + GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, + GLuint * ids); + typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, + const GLuint * + ids); + typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); + typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); + typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); + typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, + GLenum pname, + GLint * params); + typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, + GLenum pname, + GLuint * + params); #endif #ifndef GL_NV_point_sprite #define GL_NV_point_sprite 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameteriNV (GLenum, GLint); -GLAPI void APIENTRY glPointParameterivNV (GLenum, const GLint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); + GLAPI void APIENTRY glPointParameteriNV (GLenum, GLint); + GLAPI void APIENTRY glPointParameterivNV (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, + GLint param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, + const GLint * + params); #endif #ifndef GL_NV_texture_shader3 @@ -6153,9 +9112,9 @@ typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint #ifndef GL_EXT_stencil_two_side #define GL_EXT_stencil_two_side 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); + GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); #endif #ifndef GL_ATI_text_fragment_shader @@ -6169,65 +9128,120 @@ typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); #ifndef GL_APPLE_element_array #define GL_APPLE_element_array 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glElementPointerAPPLE (GLenum, const GLvoid *); -GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum, GLint, GLsizei); -GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, GLint, GLsizei); -GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum, const GLint *, const GLsizei *, GLsizei); -GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, const GLint *, const GLsizei *, GLsizei); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); + GLAPI void APIENTRY glElementPointerAPPLE (GLenum, const GLvoid *); + GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum, GLint, GLsizei); + GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, + GLint, GLsizei); + GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum, const GLint *, + const GLsizei *, + GLsizei); + GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum, GLuint, + GLuint, + const GLint *, + const GLsizei *, + GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, + const GLvoid * + pointer); + typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, + GLint first, + GLsizei count); + typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, + GLuint + start, + GLuint end, + GLint first, + GLsizei + count); + typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, + const GLint + * first, + const + GLsizei * + count, + GLsizei + primcount); + typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum + mode, + GLuint + start, + GLuint + end, + const + GLint * + first, + const + GLsizei + * + count, + GLsizei + primcount); #endif #ifndef GL_APPLE_fence #define GL_APPLE_fence 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenFencesAPPLE (GLsizei, GLuint *); -GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei, const GLuint *); -GLAPI void APIENTRY glSetFenceAPPLE (GLuint); -GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint); -GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint); -GLAPI void APIENTRY glFinishFenceAPPLE (GLuint); -GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum, GLuint); -GLAPI void APIENTRY glFinishObjectAPPLE (GLenum, GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); -typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); -typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); -typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); -typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); + GLAPI void APIENTRY glGenFencesAPPLE (GLsizei, GLuint *); + GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei, const GLuint *); + GLAPI void APIENTRY glSetFenceAPPLE (GLuint); + GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint); + GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint); + GLAPI void APIENTRY glFinishFenceAPPLE (GLuint); + GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum, GLuint); + GLAPI void APIENTRY glFinishObjectAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, + GLuint * fences); + typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, + const GLuint * + fences); + typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); + typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); + typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); + typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); + typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, + GLuint name); + typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, + GLint name); #endif #ifndef GL_APPLE_vertex_array_object #define GL_APPLE_vertex_array_object 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint); -GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei, const GLuint *); -GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); -typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); -typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); -typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); + GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint); + GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei, const GLuint *); + GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); + typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, + const GLuint * + arrays); + typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, + const GLuint * + arrays); + typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); #endif #ifndef GL_APPLE_vertex_array_range #define GL_APPLE_vertex_array_range 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei, GLvoid *); -GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei, GLvoid *); -GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum, GLint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); -typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); + GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei, GLvoid *); + GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei, GLvoid *); + GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, + GLvoid * + pointer); + typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei + length, + GLvoid * + pointer); + typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum + pname, + GLint + param); #endif #ifndef GL_APPLE_ycbcr_422 @@ -6241,9 +9255,10 @@ typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLin #ifndef GL_ATI_draw_buffers #define GL_ATI_draw_buffers 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawBuffersATI (GLsizei, const GLenum *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); + GLAPI void APIENTRY glDrawBuffersATI (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, + const GLenum * bufs); #endif #ifndef GL_ATI_pixel_format_float @@ -6269,137 +9284,252 @@ typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs) #define GL_NV_fragment_program 1 /* Some NV_fragment_program entry points are shared with ARB_vertex_program. */ #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint, GLsizei, const GLubyte *, GLfloat, GLfloat, GLfloat, GLfloat); -GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint, GLsizei, const GLubyte *, GLdouble, GLdouble, GLdouble, GLdouble); -GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint, GLsizei, const GLubyte *, const GLfloat *); -GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint, GLsizei, const GLubyte *, const GLdouble *); -GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint, GLsizei, const GLubyte *, GLfloat *); -GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint, GLsizei, const GLubyte *, GLdouble *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); -typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); + GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint, GLsizei, + const GLubyte *, GLfloat, + GLfloat, GLfloat, + GLfloat); + GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint, GLsizei, + const GLubyte *, + GLdouble, GLdouble, + GLdouble, GLdouble); + GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint, GLsizei, + const GLubyte *, + const GLfloat *); + GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint, GLsizei, + const GLubyte *, + const GLdouble *); + GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint, GLsizei, + const GLubyte *, + GLfloat *); + GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint, GLsizei, + const GLubyte *, + GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, + GLsizei len, + const GLubyte + * name, + GLfloat x, + GLfloat y, + GLfloat z, + GLfloat w); + typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, + GLsizei len, + const GLubyte + * name, + GLdouble x, + GLdouble y, + GLdouble z, + GLdouble w); + typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, + GLsizei len, + const + GLubyte * + name, + const + GLfloat * + v); + typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, + GLsizei len, + const + GLubyte * + name, + const + GLdouble * + v); + typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, + GLsizei + len, + const + GLubyte * + name, + GLfloat * + params); + typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, + GLsizei + len, + const + GLubyte * + name, + GLdouble * + params); #endif #ifndef GL_NV_half_float #define GL_NV_half_float 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertex2hNV (GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *); -GLAPI void APIENTRY glVertex3hNV (GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *); -GLAPI void APIENTRY glVertex4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *); -GLAPI void APIENTRY glNormal3hNV (GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *); -GLAPI void APIENTRY glColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *); -GLAPI void APIENTRY glColor4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *); -GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV); -GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *); -GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *); -GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *); -GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *); -GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum, GLhalfNV); -GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum, const GLhalfNV *); -GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum, const GLhalfNV *); -GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum, const GLhalfNV *); -GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum, const GLhalfNV *); -GLAPI void APIENTRY glFogCoordhNV (GLhalfNV); -GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *); -GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *); -GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV); -GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *); -GLAPI void APIENTRY glVertexAttrib1hNV (GLuint, GLhalfNV); -GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint, const GLhalfNV *); -GLAPI void APIENTRY glVertexAttrib2hNV (GLuint, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint, const GLhalfNV *); -GLAPI void APIENTRY glVertexAttrib3hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint, const GLhalfNV *); -GLAPI void APIENTRY glVertexAttrib4hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); -GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint, const GLhalfNV *); -GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint, GLsizei, const GLhalfNV *); -GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint, GLsizei, const GLhalfNV *); -GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint, GLsizei, const GLhalfNV *); -GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint, GLsizei, const GLhalfNV *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); -typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); -typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); -typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); -typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); -typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); -typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); -typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); -typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); -typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); -typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); -typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); + GLAPI void APIENTRY glVertex2hNV (GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *); + GLAPI void APIENTRY glVertex3hNV (GLhalfNV, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *); + GLAPI void APIENTRY glVertex4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *); + GLAPI void APIENTRY glNormal3hNV (GLhalfNV, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *); + GLAPI void APIENTRY glColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *); + GLAPI void APIENTRY glColor4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *); + GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV); + GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *); + GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *); + GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *); + GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV, GLhalfNV, GLhalfNV, + GLhalfNV); + GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *); + GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum, GLhalfNV); + GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum, const GLhalfNV *); + GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum, const GLhalfNV *); + GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum, GLhalfNV, GLhalfNV, + GLhalfNV); + GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum, const GLhalfNV *); + GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum, GLhalfNV, GLhalfNV, + GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum, const GLhalfNV *); + GLAPI void APIENTRY glFogCoordhNV (GLhalfNV); + GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *); + GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *); + GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV); + GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *); + GLAPI void APIENTRY glVertexAttrib1hNV (GLuint, GLhalfNV); + GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint, const GLhalfNV *); + GLAPI void APIENTRY glVertexAttrib2hNV (GLuint, GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint, const GLhalfNV *); + GLAPI void APIENTRY glVertexAttrib3hNV (GLuint, GLhalfNV, GLhalfNV, + GLhalfNV); + GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint, const GLhalfNV *); + GLAPI void APIENTRY glVertexAttrib4hNV (GLuint, GLhalfNV, GLhalfNV, + GLhalfNV, GLhalfNV); + GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint, const GLhalfNV *); + GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint, GLsizei, + const GLhalfNV *); + GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint, GLsizei, + const GLhalfNV *); + GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint, GLsizei, + const GLhalfNV *); + GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint, GLsizei, + const GLhalfNV *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); + typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, + GLhalfNV z); + typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, + GLhalfNV z, GLhalfNV w); + typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, + GLhalfNV nz); + typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, + GLhalfNV blue); + typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, + GLhalfNV blue, + GLhalfNV alpha); + typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); + typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); + typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, + GLhalfNV r); + typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, + GLhalfNV r, GLhalfNV q); + typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, + GLhalfNV s); + typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, + GLhalfNV s, + GLhalfNV t); + typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, + GLhalfNV s, + GLhalfNV t, + GLhalfNV r); + typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, + GLhalfNV s, + GLhalfNV t, + GLhalfNV r, + GLhalfNV q); + typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); + typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV * fog); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, + GLhalfNV green, + GLhalfNV blue); + typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV * + v); + typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); + typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV * + weight); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, + GLhalfNV x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, + GLhalfNV x, + GLhalfNV y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, + GLhalfNV x, + GLhalfNV y, + GLhalfNV z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, + GLhalfNV x, + GLhalfNV y, + GLhalfNV z, + GLhalfNV w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, + GLsizei n, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, + GLsizei n, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, + GLsizei n, + const GLhalfNV * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, + GLsizei n, + const GLhalfNV * v); #endif #ifndef GL_NV_pixel_data_range #define GL_NV_pixel_data_range 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelDataRangeNV (GLenum, GLsizei, GLvoid *); -GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, GLvoid *pointer); -typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); + GLAPI void APIENTRY glPixelDataRangeNV (GLenum, GLsizei, GLvoid *); + GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, + GLsizei length, + GLvoid * pointer); + typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); #endif #ifndef GL_NV_primitive_restart #define GL_NV_primitive_restart 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPrimitiveRestartNV (void); -GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); -typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); + GLAPI void APIENTRY glPrimitiveRestartNV (void); + GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); + typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); #endif #ifndef GL_NV_texture_expand_normal @@ -6413,33 +9543,68 @@ typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); #ifndef GL_ATI_map_object_buffer #define GL_ATI_map_object_buffer 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI GLvoid* APIENTRY glMapObjectBufferATI (GLuint); -GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLvoid* (APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); + GLAPI GLvoid *APIENTRY glMapObjectBufferATI (GLuint); + GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef GLvoid *(APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); + typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); #endif #ifndef GL_ATI_separate_stencil #define GL_ATI_separate_stencil 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glStencilOpSeparateATI (GLenum, GLenum, GLenum, GLenum); -GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum, GLenum, GLint, GLuint); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); + GLAPI void APIENTRY glStencilOpSeparateATI (GLenum, GLenum, GLenum, + GLenum); + GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum, GLenum, GLint, + GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, + GLenum sfail, + GLenum dpfail, + GLenum dppass); + typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum + frontfunc, + GLenum backfunc, + GLint ref, + GLuint mask); #endif #ifndef GL_ATI_vertex_attrib_array_object #define GL_ATI_vertex_attrib_array_object 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint, GLint, GLenum, GLboolean, GLsizei, GLuint, GLuint); -GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint, GLenum, GLfloat *); -GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint, GLenum, GLint *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); + GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint, GLint, GLenum, + GLboolean, GLsizei, + GLuint, GLuint); + GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint, GLenum, + GLfloat *); + GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint, GLenum, + GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint + index, + GLint size, + GLenum type, + GLboolean + normalized, + GLsizei + stride, + GLuint + buffer, + GLuint + offset); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint + index, + GLenum + pname, + GLfloat + * + params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint + index, + GLenum + pname, + GLint * + params); #endif #ifndef GL_OES_read_format @@ -6449,9 +9614,10 @@ typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, #ifndef GL_EXT_depth_bounds_test #define GL_EXT_depth_bounds_test 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDepthBoundsEXT (GLclampd, GLclampd); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); + GLAPI void APIENTRY glDepthBoundsEXT (GLclampd, GLclampd); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, + GLclampd zmax); #endif #ifndef GL_EXT_texture_mirror_clamp @@ -6461,9 +9627,12 @@ typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); #ifndef GL_EXT_blend_equation_separate #define GL_EXT_blend_equation_separate 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum, GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); + GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum + modeRGB, + GLenum + modeAlpha); #endif #ifndef GL_MESA_pack_invert @@ -6497,49 +9666,117 @@ typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLen #ifndef GL_EXT_framebuffer_object #define GL_EXT_framebuffer_object 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint); -GLAPI void APIENTRY glBindRenderbufferEXT (GLenum, GLuint); -GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei, GLuint *); -GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum, GLenum, GLsizei, GLsizei); -GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum, GLenum, GLint *); -GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint); -GLAPI void APIENTRY glBindFramebufferEXT (GLenum, GLuint); -GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei, const GLuint *); -GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei, GLuint *); -GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum); -GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum, GLenum, GLenum, GLuint, GLint); -GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum, GLenum, GLenum, GLuint, GLint); -GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum, GLenum, GLenum, GLuint, GLint, GLint); -GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum, GLenum, GLenum, GLuint); -GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum, GLenum, GLenum, GLint *); -GLAPI void APIENTRY glGenerateMipmapEXT (GLenum); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); -typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); -typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); -typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); -typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); -typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); + GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint); + GLAPI void APIENTRY glBindRenderbufferEXT (GLenum, GLuint); + GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei, GLuint *); + GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum, GLenum, GLsizei, + GLsizei); + GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum, GLenum, + GLint *); + GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint); + GLAPI void APIENTRY glBindFramebufferEXT (GLenum, GLuint); + GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei, const GLuint *); + GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei, GLuint *); + GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum); + GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum, GLenum, GLenum, + GLuint, GLint); + GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum, GLenum, GLenum, + GLuint, GLint); + GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum, GLenum, GLenum, + GLuint, GLint, GLint); + GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum, GLenum, GLenum, + GLuint); + GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum, + GLenum, + GLenum, + GLint *); + GLAPI void APIENTRY glGenerateMipmapEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint + renderbuffer); + typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, + GLuint + renderbuffer); + typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, + const GLuint * + renderbuffers); + typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, + GLuint * + renderbuffers); + typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, + GLenum + internalformat, + GLsizei width, + GLsizei height); + typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum + target, + GLenum + pname, + GLint * + params); + typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint + framebuffer); + typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, + GLuint framebuffer); + typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, + const GLuint * + framebuffers); + typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, + GLuint * + framebuffers); + typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum + target); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, + GLenum + attachment, + GLenum + textarget, + GLuint texture, + GLint level); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, + GLenum + attachment, + GLenum + textarget, + GLuint texture, + GLint level); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, + GLenum + attachment, + GLenum + textarget, + GLuint texture, + GLint level, + GLint zoffset); + typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum + target, + GLenum + attachment, + GLenum + renderbuffertarget, + GLuint + renderbuffer); + typedef void (APIENTRYP + PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum + target, + GLenum + attachment, + GLenum + pname, + GLint * + params); + typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); #endif #ifndef GL_GREMEDY_string_marker #define GL_GREMEDY_string_marker 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei, const GLvoid *); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid *string); + GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ + typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, + const GLvoid * + string); #endif @@ -6548,4 +9785,4 @@ typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid #endif #endif -#endif /* NO_SDL_GLEXT */ +#endif /* NO_SDL_GLEXT */ diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h new file mode 100644 index 000000000..dc9fe16c8 --- /dev/null +++ b/include/SDL_pixels.h @@ -0,0 +1,240 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/** + * \file SDL_pixels.h + * + * Header for the enumerated pixel format definitions + */ + +#ifndef _SDL_pixels_h +#define _SDL_pixels_h + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +enum +{ /* Pixel type */ + SDL_PixelType_Unknown, + SDL_PixelType_Index1, + SDL_PixelType_Index4, + SDL_PixelType_Index8, + SDL_PixelType_Packed8, + SDL_PixelType_Packed16, + SDL_PixelType_Packed32, + SDL_PixelType_ArrayU8, + SDL_PixelType_ArrayU16, + SDL_PixelType_ArrayU32, + SDL_PixelType_ArrayF16, + SDL_PixelType_ArrayF32, +}; + +enum +{ /* bitmap pixel order, high bit -> low bit */ + SDL_BitmapOrder_None, + SDL_BitmapOrder_4321, + SDL_BitmapOrder_1234, +}; +enum +{ /* packed component order, high bit -> low bit */ + SDL_PackedOrder_None, + SDL_PackedOrder_XRGB, + SDL_PackedOrder_RGBX, + SDL_PackedOrder_ARGB, + SDL_PackedOrder_RGBA, + SDL_PackedOrder_XBGR, + SDL_PackedOrder_BGRX, + SDL_PackedOrder_ABGR, + SDL_PackedOrder_BGRA, +}; +enum +{ /* array component order, low byte -> high byte */ + SDL_ArrayOrder_None, + SDL_ArrayOrder_RGB, + SDL_ArrayOrder_RGBA, + SDL_ArrayOrder_ARGB, + SDL_ArrayOrder_BGR, + SDL_ArrayOrder_BGRA, + SDL_ArrayOrder_ABGR, +}; + +enum +{ /* Packed component layout */ + SDL_PackedLayout_None, + SDL_PackedLayout_332, + SDL_PackedLayout_4444, + SDL_PackedLayout_1555, + SDL_PackedLayout_5551, + SDL_PackedLayout_565, + SDL_PackedLayout_8888, + SDL_PackedLayout_2101010, + SDL_PackedLayout_1010102, +}; + +#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \ + ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \ + ((bits) << 8) | ((bytes) << 0)) + +#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F) +#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F) +#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F) +#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF) +#define SDL_BYTESPERPIXEL(X) (((X) >> 0) & 0xFF) + +enum +{ + SDL_PixelFormat_Unknown, + SDL_PixelFormat_Index1LSB = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index1, SDL_BitmapOrder_1234, 0, + 1, 0), + SDL_PixelFormat_Index1MSB = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index1, SDL_BitmapOrder_4321, 0, + 1, 0), + SDL_PixelFormat_Index4LSB = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index4, SDL_BitmapOrder_1234, 0, + 2, 0), + SDL_PixelFormat_Index4MSB = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index4, SDL_BitmapOrder_4321, 0, + 2, 0), + SDL_PixelFormat_Index8 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index8, 0, 0, 8, 1), + SDL_PixelFormat_RGB332 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed8, SDL_PackedOrder_XRGB, + SDL_PackedLayout_332, 8, 1), + SDL_PixelFormat_RGB444 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_XRGB, + SDL_PackedLayout_4444, 12, 2), + SDL_PixelFormat_RGB555 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_XRGB, + SDL_PackedLayout_1555, 15, 2), + SDL_PixelFormat_ARGB4444 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_ARGB, + SDL_PackedLayout_4444, 16, 2), + SDL_PixelFormat_ARGB1555 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_ARGB, + SDL_PackedLayout_1555, 16, 2), + SDL_PixelFormat_RGB565 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_XRGB, + SDL_PackedLayout_565, 16, 2), + SDL_PixelFormat_RGB24 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_ArrayU8, SDL_ArrayOrder_RGB, 0, + 24, 3), + SDL_PixelFormat_BGR24 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_ArrayU8, SDL_ArrayOrder_BGR, 0, + 24, 3), + SDL_PixelFormat_RGB888 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_XRGB, + SDL_PackedLayout_8888, 24, 4), + SDL_PixelFormat_BGR888 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_XBGR, + SDL_PackedLayout_8888, 24, 4), + SDL_PixelFormat_ARGB8888 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_ARGB, + SDL_PackedLayout_8888, 32, 4), + SDL_PixelFormat_RGBA8888 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_RGBA, + SDL_PackedLayout_8888, 32, 4), + SDL_PixelFormat_ABGR8888 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_ABGR, + SDL_PackedLayout_8888, 32, 4), + SDL_PixelFormat_BGRA8888 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_BGRA, + SDL_PackedLayout_8888, 32, 4), + SDL_PixelFormat_ARGB2101010 = + SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_ARGB, + SDL_PackedLayout_2101010, 32, 4), +}; + +typedef struct SDL_Color +{ + Uint8 r; + Uint8 g; + Uint8 b; + Uint8 unused; +} SDL_Color; +#define SDL_Colour SDL_Color + +typedef struct SDL_Palette +{ + int ncolors; + SDL_Color *colors; +} SDL_Palette; + +/* Everything in the pixel format structure is read-only */ +typedef struct SDL_PixelFormat +{ + SDL_Palette *palette; + Uint8 BitsPerPixel; + Uint8 BytesPerPixel; + Uint8 Rloss; + Uint8 Gloss; + Uint8 Bloss; + Uint8 Aloss; + Uint8 Rshift; + Uint8 Gshift; + Uint8 Bshift; + Uint8 Ashift; + Uint32 Rmask; + Uint32 Gmask; + Uint32 Bmask; + Uint32 Amask; + + /* RGB color key information */ + Uint32 colorkey; + /* Alpha value information (per-surface alpha) */ + Uint8 alpha; +} SDL_PixelFormat; + +/* + * Convert one of the enumerated formats above to a bpp and RGBA masks. + * Returns SDL_TRUE, or SDL_FALSE if the conversion wasn't possible. + */ +extern DECLSPEC SDL_bool SDL_PixelFormatEnumToMasks (Uint32 format, int *bpp, + Uint32 * Rmask, + Uint32 * Gmask, + Uint32 * Bmask, + Uint32 * Amask); + +/* + * Convert a bpp and RGBA masks to one of the enumerated formats above. + * Returns SDL_PixelFormat_Unknown if the conversion wasn't possible. + */ +extern DECLSPEC Uint32 SDL_MasksToPixelFormatEnum (int bpp, Uint32 Rmask, + Uint32 Gmask, Uint32 Bmask, + Uint32 Amask); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + +#endif /* _SDL_pixels_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_quit.h b/include/SDL_quit.h index fcf40fbdd..5eedb4c34 100644 --- a/include/SDL_quit.h +++ b/include/SDL_quit.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* Include file for SDL quit event handling */ +/** + * \file SDL_quit.h + * + * Include file for SDL quit event handling + */ #ifndef _SDL_quit_h #define _SDL_quit_h diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h index d7e01d8fd..c972a1810 100644 --- a/include/SDL_rwops.h +++ b/include/SDL_rwops.h @@ -20,9 +20,12 @@ slouken@libsdl.org */ -/* This file provides a general interface for SDL to read and write - data sources. It can easily be extended to files, memory, etc. -*/ +/** + * \file SDL_rwops.h + * + * This file provides a general interface for SDL to read and write + * data sources. It can easily be extended to files, memory, etc. + */ #ifndef _SDL_rwops_h #define _SDL_rwops_h @@ -33,77 +36,89 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* This is the read/write operation structure -- very basic */ -typedef struct SDL_RWops { - /* Seek to 'offset' relative to whence, one of stdio's whence values: - SEEK_SET, SEEK_CUR, SEEK_END - Returns the final offset in the data source. - */ - int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence); - - /* Read up to 'num' objects each of size 'objsize' from the data - source to the area pointed at by 'ptr'. - Returns the number of objects read, or -1 if the read failed. - */ - int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum); - - /* Write exactly 'num' objects each of size 'objsize' from the area - pointed at by 'ptr' to data source. - Returns 'num', or -1 if the write failed. - */ - int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num); - - /* Close and free an allocated SDL_FSops structure */ - int (SDLCALL *close)(struct SDL_RWops *context); - - Uint32 type; - union { +typedef struct SDL_RWops +{ + /* Seek to 'offset' relative to whence, one of stdio's whence values: + SEEK_SET, SEEK_CUR, SEEK_END + Returns the final offset in the data source. + */ + int (SDLCALL * seek) (struct SDL_RWops * context, int offset, int whence); + + /* Read up to 'num' objects each of size 'objsize' from the data + source to the area pointed at by 'ptr'. + Returns the number of objects read, or -1 if the read failed. + */ + int (SDLCALL * read) (struct SDL_RWops * context, void *ptr, int size, + int maxnum); + + /* Write exactly 'num' objects each of size 'objsize' from the area + pointed at by 'ptr' to data source. + Returns 'num', or -1 if the write failed. + */ + int (SDLCALL * write) (struct SDL_RWops * context, const void *ptr, + int size, int num); + + /* Close and free an allocated SDL_FSops structure */ + int (SDLCALL * close) (struct SDL_RWops * context); + + Uint32 type; + union + { #ifdef __WIN32__ - struct { - int append; - void* h; - } win32io; + struct + { + int append; + void *h; + } win32io; #endif -#ifdef HAVE_STDIO_H - struct { - int autoclose; - FILE *fp; - } stdio; +#ifdef HAVE_STDIO_H + struct + { + int autoclose; + FILE *fp; + } stdio; #endif - struct { - Uint8 *base; - Uint8 *here; - Uint8 *stop; - } mem; - struct { - void *data1; - } unknown; - } hidden; + struct + { + Uint8 *base; + Uint8 *here; + Uint8 *stop; + } mem; + struct + { + void *data1; + } unknown; + } hidden; } SDL_RWops; /* Functions to create SDL_RWops structures from various data sources */ -extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode); +extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile (const char *file, + const char *mode); #ifdef HAVE_STDIO_H -extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose); +extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP (FILE * fp, int autoclose); #endif -extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size); -extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size); +extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem (void *mem, int size); +extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem (const void *mem, + int size); -extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void); -extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area); +extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW (void); +extern DECLSPEC void SDLCALL SDL_FreeRW (SDL_RWops * area); -#define RW_SEEK_SET 0 /* Seek from the beginning of data */ -#define RW_SEEK_CUR 1 /* Seek relative to current read point */ -#define RW_SEEK_END 2 /* Seek relative to the end of data */ +#define RW_SEEK_SET 0 /* Seek from the beginning of data */ +#define RW_SEEK_CUR 1 /* Seek relative to current read point */ +#define RW_SEEK_END 2 /* Seek relative to the end of data */ /* Macros to easily read and write from an SDL_RWops structure */ #define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence) @@ -114,26 +129,30 @@ extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area); /* Read an item of the specified endianness and return in native format */ -extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src); -extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops *src); -extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src); -extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src); -extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops *src); -extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops *src); +extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16 (SDL_RWops * src); +extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16 (SDL_RWops * src); +extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32 (SDL_RWops * src); +extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32 (SDL_RWops * src); +extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64 (SDL_RWops * src); +extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64 (SDL_RWops * src); /* Write an item of native format to the specified endianness */ -extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops *dst, Uint16 value); -extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops *dst, Uint16 value); -extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops *dst, Uint32 value); -extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops *dst, Uint32 value); -extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops *dst, Uint64 value); -extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops *dst, Uint64 value); +extern DECLSPEC int SDLCALL SDL_WriteLE16 (SDL_RWops * dst, Uint16 value); +extern DECLSPEC int SDLCALL SDL_WriteBE16 (SDL_RWops * dst, Uint16 value); +extern DECLSPEC int SDLCALL SDL_WriteLE32 (SDL_RWops * dst, Uint32 value); +extern DECLSPEC int SDLCALL SDL_WriteBE32 (SDL_RWops * dst, Uint32 value); +extern DECLSPEC int SDLCALL SDL_WriteLE64 (SDL_RWops * dst, Uint64 value); +extern DECLSPEC int SDLCALL SDL_WriteBE64 (SDL_RWops * dst, Uint64 value); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_rwops_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index f790cd564..4adc85618 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* This is a general header that includes C language support */ +/** + * \file SDL_stdinc.h + * + * This is a general header that includes C language support + */ #ifndef _SDL_stdinc_h #define _SDL_stdinc_h @@ -77,41 +81,75 @@ #define SDL_TABLESIZE(table) SDL_arraysize(table) /* Basic data types */ -typedef enum SDL_bool { - SDL_FALSE = 0, - SDL_TRUE = 1 +typedef enum SDL_bool +{ + SDL_FALSE = 0, + SDL_TRUE = 1 } SDL_bool; -typedef int8_t Sint8; -typedef uint8_t Uint8; -typedef int16_t Sint16; -typedef uint16_t Uint16; -typedef int32_t Sint32; -typedef uint32_t Uint32; +/** + * \typedef Sint8 + * \brief A signed 8-bit integer type. + */ +typedef int8_t Sint8; +/** + * \typedef Uint8 + * \brief An unsigned 8-bit integer type. + */ +typedef uint8_t Uint8; +/** + * \typedef Sint16 + * \brief A signed 16-bit integer type. + */ +typedef int16_t Sint16; +/** + * \typedef Uint16 + * \brief An unsigned 16-bit integer type. + */ +typedef uint16_t Uint16; +/** + * \typedef Sint32 + * \brief A signed 32-bit integer type. + */ +typedef int32_t Sint32; +/** + * \typedef Uint32 + * \brief An unsigned 32-bit integer type. + */ +typedef uint32_t Uint32; #ifdef SDL_HAS_64BIT_TYPE -typedef int64_t Sint64; -typedef uint64_t Uint64; +/** + * \typedef Sint64 + * \brief A signed 64-bit integer type. + * \warning On platforms without any sort of 64-bit datatype, this is equivalent to Sint32! + */ +typedef int64_t Sint64; +/** + * \typedef Uint64 + * \brief An unsigned 64-bit integer type. + * \warning On platforms without any sort of 64-bit datatype, this is equivalent to Uint32! + */ +typedef uint64_t Uint64; #else /* This is really just a hack to prevent the compiler from complaining */ -typedef struct { - Uint32 hi; - Uint32 lo; -} Uint64, Sint64; +typdef Sint32 Sint64; +typdef Uint32 Uint32; #endif /* Make sure the types really have the right sizes */ #define SDL_COMPILE_TIME_ASSERT(name, x) \ typedef int SDL_dummy_ ## name[(x) * 2 - 1] - -SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1); -SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1); -SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2); -SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2); -SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4); -SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4); -SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8); -SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); +#ifndef DOXYGEN_SHOULD_IGNORE_THIS +SDL_COMPILE_TIME_ASSERT (uint8, sizeof (Uint8) == 1); +SDL_COMPILE_TIME_ASSERT (sint8, sizeof (Sint8) == 1); +SDL_COMPILE_TIME_ASSERT (uint16, sizeof (Uint16) == 2); +SDL_COMPILE_TIME_ASSERT (sint16, sizeof (Sint16) == 2); +SDL_COMPILE_TIME_ASSERT (uint32, sizeof (Uint32) == 4); +SDL_COMPILE_TIME_ASSERT (sint32, sizeof (Sint32) == 4); +SDL_COMPILE_TIME_ASSERT (uint64, sizeof (Uint64) == 8); +SDL_COMPILE_TIME_ASSERT (sint64, sizeof (Sint64) == 8); +#endif /* DOXYGEN_SHOULD_IGNORE_THIS */ /* Check to make sure enums are the size of ints, for structure packing. For both Watcom C/C++ and Borland C/C++ the compiler option that makes @@ -123,41 +161,45 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); #pragma enumsalwaysint on #endif -typedef enum { - DUMMY_ENUM_VALUE +#ifndef DOXYGEN_SHOULD_IGNORE_THIS +typedef enum +{ + DUMMY_ENUM_VALUE } SDL_DUMMY_ENUM; -SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); - +SDL_COMPILE_TIME_ASSERT (enum, sizeof (SDL_DUMMY_ENUM) == sizeof (int)); +#endif /* DOXYGEN_SHOULD_IGNORE_THIS */ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif #ifdef HAVE_MALLOC #define SDL_malloc malloc #else -extern DECLSPEC void * SDLCALL SDL_malloc(size_t size); +extern DECLSPEC void *SDLCALL SDL_malloc (size_t size); #endif #ifdef HAVE_CALLOC #define SDL_calloc calloc #else -extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size); +extern DECLSPEC void *SDLCALL SDL_calloc (size_t nmemb, size_t size); #endif #ifdef HAVE_REALLOC #define SDL_realloc realloc #else -extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size); +extern DECLSPEC void *SDLCALL SDL_realloc (void *mem, size_t size); #endif #ifdef HAVE_FREE #define SDL_free free #else -extern DECLSPEC void SDLCALL SDL_free(void *mem); +extern DECLSPEC void SDLCALL SDL_free (void *mem); #endif #if defined(HAVE_ALLOCA) && !defined(alloca) @@ -171,11 +213,11 @@ extern DECLSPEC void SDLCALL SDL_free(void *mem); # elif defined(__WATCOMC__) # include # elif defined(__AIX__) - #pragma alloca +#pragma alloca # elif defined(__MRC__) - void *alloca (unsigned); +void *alloca (unsigned); # else - char *alloca (); +char *alloca (); # endif #endif #ifdef HAVE_ALLOCA @@ -189,20 +231,21 @@ extern DECLSPEC void SDLCALL SDL_free(void *mem); #ifdef HAVE_GETENV #define SDL_getenv getenv #else -extern DECLSPEC char * SDLCALL SDL_getenv(const char *name); +extern DECLSPEC char *SDLCALL SDL_getenv (const char *name); #endif #ifdef HAVE_PUTENV #define SDL_putenv putenv #else -extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); +extern DECLSPEC int SDLCALL SDL_putenv (const char *variable); #endif #ifdef HAVE_QSORT #define SDL_qsort qsort #else -extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, - int (*compare)(const void *, const void *)); +extern DECLSPEC void SDLCALL SDL_qsort (void *base, size_t nmemb, size_t size, + int (*compare) (const void *, + const void *)); #endif #ifdef HAVE_ABS @@ -229,8 +272,10 @@ extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, #ifdef HAVE_MEMSET #define SDL_memset memset #else -extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len); +extern DECLSPEC void *SDLCALL SDL_memset (void *dst, int c, size_t len); #endif +#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) +#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) #if defined(__GNUC__) && defined(i386) #define SDL_memset4(dst, val, len) \ @@ -286,7 +331,8 @@ do { \ #elif defined(HAVE_BCOPY) #define SDL_memcpy(d, s, n) bcopy((s), (d), (n)) #else -extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len); +extern DECLSPEC void *SDLCALL SDL_memcpy (void *dst, const void *src, + size_t len); #endif #endif @@ -333,7 +379,8 @@ do { \ } while(0) #endif #ifndef SDL_revcpy -extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len); +extern DECLSPEC void *SDLCALL SDL_revcpy (void *dst, const void *src, + size_t len); #endif #ifdef HAVE_MEMMOVE @@ -354,49 +401,52 @@ do { \ #ifdef HAVE_MEMCMP #define SDL_memcmp memcmp #else -extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); +extern DECLSPEC int SDLCALL SDL_memcmp (const void *s1, const void *s2, + size_t len); #endif #ifdef HAVE_STRLEN #define SDL_strlen strlen #else -extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); +extern DECLSPEC size_t SDLCALL SDL_strlen (const char *string); #endif #ifdef HAVE_STRLCPY #define SDL_strlcpy strlcpy #else -extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); +extern DECLSPEC size_t SDLCALL SDL_strlcpy (char *dst, const char *src, + size_t maxlen); #endif #ifdef HAVE_STRLCAT #define SDL_strlcat strlcat #else -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen); +extern DECLSPEC size_t SDLCALL SDL_strlcat (char *dst, const char *src, + size_t maxlen); #endif #ifdef HAVE_STRDUP #define SDL_strdup strdup #else -extern DECLSPEC char * SDLCALL SDL_strdup(const char *string); +extern DECLSPEC char *SDLCALL SDL_strdup (const char *string); #endif #ifdef HAVE__STRREV #define SDL_strrev _strrev #else -extern DECLSPEC char * SDLCALL SDL_strrev(char *string); +extern DECLSPEC char *SDLCALL SDL_strrev (char *string); #endif #ifdef HAVE__STRUPR #define SDL_strupr _strupr #else -extern DECLSPEC char * SDLCALL SDL_strupr(char *string); +extern DECLSPEC char *SDLCALL SDL_strupr (char *string); #endif #ifdef HAVE__STRLWR #define SDL_strlwr _strlwr #else -extern DECLSPEC char * SDLCALL SDL_strlwr(char *string); +extern DECLSPEC char *SDLCALL SDL_strlwr (char *string); #endif #ifdef HAVE_STRCHR @@ -404,7 +454,7 @@ extern DECLSPEC char * SDLCALL SDL_strlwr(char *string); #elif defined(HAVE_INDEX) #define SDL_strchr index #else -extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c); +extern DECLSPEC char *SDLCALL SDL_strchr (const char *string, int c); #endif #ifdef HAVE_STRRCHR @@ -412,13 +462,14 @@ extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c); #elif defined(HAVE_RINDEX) #define SDL_strrchr rindex #else -extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c); +extern DECLSPEC char *SDLCALL SDL_strrchr (const char *string, int c); #endif #ifdef HAVE_STRSTR #define SDL_strstr strstr #else -extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle); +extern DECLSPEC char *SDLCALL SDL_strstr (const char *haystack, + const char *needle); #endif #ifdef HAVE_ITOA @@ -430,7 +481,7 @@ extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *need #ifdef HAVE__LTOA #define SDL_ltoa _ltoa #else -extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix); +extern DECLSPEC char *SDLCALL SDL_ltoa (long value, char *string, int radix); #endif #ifdef HAVE__UITOA @@ -442,19 +493,22 @@ extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix); #ifdef HAVE__ULTOA #define SDL_ultoa _ultoa #else -extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix); +extern DECLSPEC char *SDLCALL SDL_ultoa (unsigned long value, char *string, + int radix); #endif #ifdef HAVE_STRTOL #define SDL_strtol strtol #else -extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base); +extern DECLSPEC long SDLCALL SDL_strtol (const char *string, char **endp, + int base); #endif #ifdef HAVE_STRTOUL #define SDL_strtoul strtoul #else -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **endp, int base); +extern DECLSPEC unsigned long SDLCALL SDL_strtoul (const char *string, + char **endp, int base); #endif #ifdef SDL_HAS_64BIT_TYPE @@ -462,25 +516,29 @@ extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **end #ifdef HAVE__I64TOA #define SDL_lltoa _i64toa #else -extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix); +extern DECLSPEC char *SDLCALL SDL_lltoa (Sint64 value, char *string, + int radix); #endif #ifdef HAVE__UI64TOA #define SDL_ulltoa _ui64toa #else -extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix); +extern DECLSPEC char *SDLCALL SDL_ulltoa (Uint64 value, char *string, + int radix); #endif #ifdef HAVE_STRTOLL #define SDL_strtoll strtoll #else -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base); +extern DECLSPEC Sint64 SDLCALL SDL_strtoll (const char *string, char **endp, + int base); #endif #ifdef HAVE_STRTOULL #define SDL_strtoull strtoull #else -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int base); +extern DECLSPEC Uint64 SDLCALL SDL_strtoull (const char *string, char **endp, + int base); #endif #endif /* SDL_HAS_64BIT_TYPE */ @@ -488,7 +546,7 @@ extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int #ifdef HAVE_STRTOD #define SDL_strtod strtod #else -extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); +extern DECLSPEC double SDLCALL SDL_strtod (const char *string, char **endp); #endif #ifdef HAVE_ATOI @@ -506,13 +564,14 @@ extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); #ifdef HAVE_STRCMP #define SDL_strcmp strcmp #else -extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); +extern DECLSPEC int SDLCALL SDL_strcmp (const char *str1, const char *str2); #endif #ifdef HAVE_STRNCMP #define SDL_strncmp strncmp #else -extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen); +extern DECLSPEC int SDLCALL SDL_strncmp (const char *str1, const char *str2, + size_t maxlen); #endif #ifdef HAVE_STRCASECMP @@ -520,7 +579,8 @@ extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size #elif defined(HAVE__STRICMP) #define SDL_strcasecmp _stricmp #else -extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); +extern DECLSPEC int SDLCALL SDL_strcasecmp (const char *str1, + const char *str2); #endif #ifdef HAVE_STRNCASECMP @@ -528,25 +588,29 @@ extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); #elif defined(HAVE__STRNICMP) #define SDL_strncasecmp _strnicmp #else -extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen); +extern DECLSPEC int SDLCALL SDL_strncasecmp (const char *str1, + const char *str2, size_t maxlen); #endif #ifdef HAVE_SSCANF #define SDL_sscanf sscanf #else -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); +extern DECLSPEC int SDLCALL SDL_sscanf (const char *text, const char *fmt, + ...); #endif #ifdef HAVE_SNPRINTF #define SDL_snprintf snprintf #else -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); +extern DECLSPEC int SDLCALL SDL_snprintf (char *text, size_t maxlen, + const char *fmt, ...); #endif #ifdef HAVE_VSNPRINTF #define SDL_vsnprintf vsnprintf #else -extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); +extern DECLSPEC int SDLCALL SDL_vsnprintf (char *text, size_t maxlen, + const char *fmt, va_list ap); #endif /* The SDL implementation of iconv() returns these error codes */ @@ -559,17 +623,25 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char #define SDL_iconv_t iconv_t #define SDL_iconv_open iconv_open #define SDL_iconv_close iconv_close -extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +extern DECLSPEC size_t SDLCALL SDL_iconv (SDL_iconv_t cd, char **inbuf, + size_t * inbytesleft, char **outbuf, + size_t * outbytesleft); #else typedef struct _SDL_iconv_t *SDL_iconv_t; -extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode); -extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd); -extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open (const char *tocode, + const char *fromcode); +extern DECLSPEC int SDLCALL SDL_iconv_close (SDL_iconv_t cd); +extern DECLSPEC size_t SDLCALL SDL_iconv (SDL_iconv_t cd, char **inbuf, + size_t * inbytesleft, char **outbuf, + size_t * outbytesleft); #endif /* This function converts a string between encodings in one pass, returning a string that must be freed with SDL_free() or NULL on error. */ -extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf, size_t inbytesleft); +extern DECLSPEC char *SDLCALL SDL_iconv_string (const char *tocode, + const char *fromcode, + char *inbuf, + size_t inbytesleft); #define SDL_iconv_utf8_ascii(S) SDL_iconv_string("ASCII", "UTF-8", S, SDL_strlen(S)+1) #define SDL_iconv_utf8_latin1(S) SDL_iconv_string("LATIN1", "UTF-8", S, SDL_strlen(S)+1) #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1) @@ -577,8 +649,12 @@ extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char * /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_stdinc_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h index e7f35139a..226ab7815 100644 --- a/include/SDL_syswm.h +++ b/include/SDL_syswm.h @@ -20,19 +20,26 @@ slouken@libsdl.org */ -/* Include file for SDL custom system window manager hooks */ +/** + * \file SDL_syswm.h + * + * Include file for SDL custom system window manager hooks + */ #ifndef _SDL_syswm_h #define _SDL_syswm_h #include "SDL_stdinc.h" #include "SDL_error.h" +#include "SDL_video.h" #include "SDL_version.h" #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* Your application has access to a special type of event 'SDL_SYSWMEVENT', @@ -42,7 +49,6 @@ extern "C" { */ #ifdef SDL_PROTOTYPES_ONLY struct SDL_SysWMinfo; -typedef struct SDL_SysWMinfo SDL_SysWMinfo; #else /* This is the structure for custom window manager events */ @@ -61,150 +67,179 @@ typedef struct SDL_SysWMinfo SDL_SysWMinfo; #endif /* These are the various supported subsystems under UNIX */ -typedef enum { - SDL_SYSWM_X11 +typedef enum +{ + SDL_SYSWM_X11 } SDL_SYSWM_TYPE; /* The UNIX custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - SDL_SYSWM_TYPE subsystem; - union { - XEvent xevent; - } event; +struct SDL_SysWMmsg +{ + SDL_version version; + SDL_SYSWM_TYPE subsystem; + union + { + XEvent xevent; + } event; }; /* The UNIX custom window manager information structure. When this structure is returned, it holds information about which low level system it is using, and will be one of SDL_SYSWM_TYPE. */ -typedef struct SDL_SysWMinfo { - SDL_version version; - SDL_SYSWM_TYPE subsystem; - union { - struct { - Display *display; /* The X11 display */ - Window window; /* The X11 display window */ - /* These locking functions should be called around - any X11 functions using the display variable. - They lock the event thread, so should not be - called around event functions or from event filters. - */ - void (*lock_func)(void); - void (*unlock_func)(void); - - /* Introduced in SDL 1.0.2 */ - Window fswindow; /* The X11 fullscreen window */ - Window wmwindow; /* The X11 managed input window */ - } x11; - } info; -} SDL_SysWMinfo; +struct SDL_SysWMinfo +{ + SDL_version version; + SDL_SYSWM_TYPE subsystem; + union + { + struct + { + Display *display; /* The X11 display */ + Window window; /* The X11 display window */ + /* These locking functions should be called around + any X11 functions using the display variable. + They lock the event thread, so should not be + called around event functions or from event filters. + */ + void (*lock_func) (void); + void (*unlock_func) (void); + + /* Introduced in SDL 1.0.2 */ + Window fswindow; /* The X11 fullscreen window */ + Window wmwindow; /* The X11 managed input window */ + } x11; + } info; +}; #elif defined(SDL_VIDEO_DRIVER_NANOX) #include /* The generic custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - int data; +struct SDL_SysWMmsg +{ + SDL_version version; + int data; }; /* The windows custom window manager information structure */ -typedef struct SDL_SysWMinfo { - SDL_version version ; - GR_WINDOW_ID window ; /* The display window */ -} SDL_SysWMinfo; +struct SDL_SysWMinfo +{ + SDL_version version; + GR_WINDOW_ID window; /* The display window */ +}; #elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI) #define WIN32_LEAN_AND_MEAN #include /* The windows custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - HWND hwnd; /* The window for the message */ - UINT msg; /* The type of message */ - WPARAM wParam; /* WORD message parameter */ - LPARAM lParam; /* LONG message parameter */ +struct SDL_SysWMmsg +{ + SDL_version version; + HWND hwnd; /* The window for the message */ + UINT msg; /* The type of message */ + WPARAM wParam; /* WORD message parameter */ + LPARAM lParam; /* LONG message parameter */ }; /* The windows custom window manager information structure */ -typedef struct SDL_SysWMinfo { - SDL_version version; - HWND window; /* The Win32 display window */ - HGLRC hglrc; /* The OpenGL context, if any */ -} SDL_SysWMinfo; +struct SDL_SysWMinfo +{ + SDL_version version; + HWND window; /* The Win32 display window */ + HGLRC hglrc; /* The OpenGL context, if any */ +}; #elif defined(SDL_VIDEO_DRIVER_RISCOS) /* RISC OS custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - int eventCode; /* The window for the message */ - int pollBlock[64]; +struct SDL_SysWMmsg +{ + SDL_version version; + int eventCode; /* The window for the message */ + int pollBlock[64]; }; /* The RISC OS custom window manager information structure */ -typedef struct SDL_SysWMinfo { - SDL_version version; - int wimpVersion; /* Wimp version running under */ - int taskHandle; /* The RISC OS task handle */ - int window; /* The RISC OS display window */ -} SDL_SysWMinfo; +struct SDL_SysWMinfo +{ + SDL_version version; + int wimpVersion; /* Wimp version running under */ + int taskHandle; /* The RISC OS task handle */ + int window; /* The RISC OS display window */ +}; #elif defined(SDL_VIDEO_DRIVER_PHOTON) #include #include /* The QNX custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - int data; +struct SDL_SysWMmsg +{ + SDL_version version; + int data; }; /* The QNX custom window manager information structure */ -typedef struct SDL_SysWMinfo { - SDL_version version; - int data; -} SDL_SysWMinfo; +struct SDL_SysWMinfo +{ + SDL_version version; + int data; +}; #else /* The generic custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - int data; +struct SDL_SysWMmsg +{ + SDL_version version; + int data; }; /* The generic custom window manager information structure */ -typedef struct SDL_SysWMinfo { - SDL_version version; - int data; -} SDL_SysWMinfo; +struct SDL_SysWMinfo +{ + SDL_version version; + int data; +}; #endif /* video driver type */ #endif /* SDL_PROTOTYPES_ONLY */ +typedef struct SDL_SysWMinfo SDL_SysWMinfo; + /* Function prototypes */ -/* - * This function gives you custom hooks into the window manager information. - * It fills the structure pointed to by 'info' with custom information and - * returns 1 if the function is implemented. If it's not implemented, or - * the version member of the 'info' structure is invalid, it returns 0. +/** + * \fn SDL_bool SDL_GetWindowWMInfo (SDL_WindowID windowID, SDL_SysWMinfo * info) + * + * \brief This function allows access to driver-dependent window information. + * + * \param windowID The window about which information is being requested + * \param info This structure must be initialized with the SDL version, and is then filled in with information about the given window. + * + * \return SDL_TRUE if the function is implemented and the version member of the 'info' struct is valid, SDL_FALSE otherwise. * * You typically use this function like this: + * \code * SDL_SysWMInfo info; * SDL_VERSION(&info.version); - * if ( SDL_GetWMInfo(&info) ) { ... } + * if ( SDL_GetWindowWMInfo(&info) ) { ... } + * \endcode */ -extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo *info); +extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo (SDL_WindowID windowID, + SDL_SysWMinfo * info); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_syswm_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_thread.h b/include/SDL_thread.h index 80746fe38..50835ce98 100644 --- a/include/SDL_thread.h +++ b/include/SDL_thread.h @@ -23,10 +23,11 @@ #ifndef _SDL_thread_h #define _SDL_thread_h -/* Header for the SDL thread management routines - - These are independent of the other SDL routines. -*/ +/** + * \file SDL_thread.h + * + * Header for the SDL thread management routines + */ #include "SDL_stdinc.h" #include "SDL_error.h" @@ -37,7 +38,9 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* The SDL thread structure, defined in SDL_thread.c */ @@ -61,25 +64,39 @@ typedef struct SDL_Thread SDL_Thread; */ #define SDL_PASSED_BEGINTHREAD_ENDTHREAD #ifndef _WIN32_WCE -#include /* This has _beginthread() and _endthread() defined! */ +#include /* This has _beginthread() and _endthread() defined! */ #endif #ifdef __OS2__ -typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg); -typedef void (*pfnSDL_CurrentEndThread)(void); +typedef int (*pfnSDL_CurrentBeginThread) (void (*func) (void *), void *, + unsigned, void *arg); +typedef void (*pfnSDL_CurrentEndThread) (void); #elif __GNUC__ -typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned + (__stdcall * + func) (void *), + void *arg, + unsigned, + unsigned + *threadID); +typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); #else -typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned (__stdcall * + func) (void + *), + void *arg, unsigned, + unsigned *threadID); +typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); #endif -extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); +extern DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread (int (*fn) (void *), + void *data, + pfnSDL_CurrentBeginThread + pfnBeginThread, + pfnSDL_CurrentEndThread + pfnEndThread); #ifdef __OS2__ #define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread) @@ -89,31 +106,37 @@ extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *d #define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex) #endif #else -extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data); +extern DECLSPEC SDL_Thread *SDLCALL +SDL_CreateThread (int (SDLCALL * fn) (void *), void *data); #endif /* Get the 32-bit thread identifier for the current thread */ -extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void); +extern DECLSPEC Uint32 SDLCALL SDL_ThreadID (void); /* Get the 32-bit thread identifier for the specified thread, equivalent to SDL_ThreadID() if the specified thread is NULL. */ -extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread *thread); +extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID (SDL_Thread * thread); /* Wait for a thread to finish. The return code for the thread function is placed in the area pointed to by 'status', if 'status' is not NULL. */ -extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status); +extern DECLSPEC void SDLCALL SDL_WaitThread (SDL_Thread * thread, + int *status); /* Forcefully kill a thread without worrying about its state */ -extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread *thread); +extern DECLSPEC void SDLCALL SDL_KillThread (SDL_Thread * thread); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_thread_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_timer.h b/include/SDL_timer.h index d21159fed..937e618a2 100644 --- a/include/SDL_timer.h +++ b/include/SDL_timer.h @@ -23,7 +23,11 @@ #ifndef _SDL_timer_h #define _SDL_timer_h -/* Header for the SDL time management routines */ +/** + * \file SDL_timer.h + * + * Header for the SDL time management routines + */ #include "SDL_stdinc.h" #include "SDL_error.h" @@ -31,25 +35,27 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* This is the OS scheduler timeslice, in milliseconds */ #define SDL_TIMESLICE 10 /* This is the maximum resolution of the SDL timer on all platforms */ -#define TIMER_RESOLUTION 10 /* Experimentally determined */ +#define TIMER_RESOLUTION 10 /* Experimentally determined */ /* Get the number of milliseconds since the SDL library initialization. * Note that this value wraps if the program runs for more than ~49 days. - */ -extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); + */ +extern DECLSPEC Uint32 SDLCALL SDL_GetTicks (void); /* Wait a specified number of milliseconds before returning */ -extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); +extern DECLSPEC void SDLCALL SDL_Delay (Uint32 ms); /* Function prototype for the timer callback function */ -typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval); +typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval); /* Set a callback to run after the specified number of milliseconds has * elapsed. The callback function is passed the current timer interval @@ -79,7 +85,8 @@ typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval); * * This function returns 0 if successful, or -1 if there was an error. */ -extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback); +extern DECLSPEC int SDLCALL SDL_SetTimer (Uint32 interval, + SDL_TimerCallback callback); /* New timer API, supports multiple timers * Written by Stephane Peter @@ -91,7 +98,8 @@ extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_TimerCallback call * passed in, the periodic alarm continues, otherwise a new alarm is * scheduled. If the callback returns 0, the periodic alarm is cancelled. */ -typedef Uint32 (SDLCALL *SDL_NewTimerCallback)(Uint32 interval, void *param); +typedef Uint32 (SDLCALL * SDL_NewTimerCallback) (Uint32 interval, + void *param); /* Definition of the timer ID type */ typedef struct _SDL_TimerID *SDL_TimerID; @@ -99,17 +107,23 @@ typedef struct _SDL_TimerID *SDL_TimerID; /* Add a new timer to the pool of timers already running. Returns a timer ID, or NULL when an error occurs. */ -extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param); +extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer (Uint32 interval, + SDL_NewTimerCallback + callback, void *param); /* Remove one of the multiple timers knowing its ID. * Returns a boolean value indicating success. */ -extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t); +extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer (SDL_TimerID t); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_timer_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_version.h b/include/SDL_version.h index d1b7b56eb..c75044f01 100644 --- a/include/SDL_version.h +++ b/include/SDL_version.h @@ -20,7 +20,11 @@ slouken@libsdl.org */ -/* This header defines the current SDL version */ +/** + * \file SDL_version.h + * + * This header defines the current SDL version + */ #ifndef _SDL_version_h #define _SDL_version_h @@ -30,29 +34,58 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif +/** + * \struct SDL_version + * \brief Information the version of SDL in use. + * + * Represents the library's version as three levels: major revision + * (increments with massive changes, additions, and enhancements), + * minor revision (increments with backwards-compatible changes to the + * major revision), and patchlevel (increments with fixes to the minor + * revision). + * + * \sa SDL_VERSION + * \sa SDL_GetVersion + */ +typedef struct SDL_version +{ + Uint8 major; /**< major version */ + Uint8 minor; /**< minor version */ + Uint8 patch; /**< update version */ +} SDL_version; + /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL */ #define SDL_MAJOR_VERSION 1 #define SDL_MINOR_VERSION 3 #define SDL_PATCHLEVEL 0 -typedef struct SDL_version { - Uint8 major; - Uint8 minor; - Uint8 patch; -} SDL_version; - -/* This macro can be used to fill a version structure with the compile-time - * version of the SDL library. +/** + * \def SDL_VERSION(x) + * \brief Macro to determine SDL version program was compiled against. + * + * This macro fills in a SDL_version structure with the version of the + * library you compiled against. This is determined by what header the + * compiler uses. Note that if you dynamically linked the library, you might + * have a slightly newer or older version at runtime. That version can be + * determined with SDL_GetVersion(), which, unlike SDL_VERSION, + * is not a macro. + * + * \param x A pointer to a SDL_version struct to initialize. + * + * \sa SDL_version + * \sa SDL_GetVersion */ -#define SDL_VERSION(X) \ +#define SDL_VERSION(x) \ { \ - (X)->major = SDL_MAJOR_VERSION; \ - (X)->minor = SDL_MINOR_VERSION; \ - (X)->patch = SDL_PATCHLEVEL; \ + (x)->major = SDL_MAJOR_VERSION; \ + (x)->minor = SDL_MINOR_VERSION; \ + (x)->patch = SDL_PATCHLEVEL; \ } /* This macro turns the version numbers into a numeric value: @@ -70,16 +103,42 @@ typedef struct SDL_version { #define SDL_VERSION_ATLEAST(X, Y, Z) \ (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z)) -/* This function gets the version of the dynamically linked SDL library. - it should NOT be used to fill a version structure, instead you should - use the SDL_Version() macro. +/** + * \fn void SDL_GetVersion(SDL_version *ver) + * \brief Get the version of SDL that is linked against your program. + * + * If you are using a shared library (DLL) version of SDL, then it is + * possible that it will be different than the version you compiled against. + * + * This is a real function; the macro SDL_VERSION tells you what version + * of SDL you compiled against: + * + * \code + * SDL_version compiled; + * SDL_version linked; + * + * SDL_VERSION(&compiled); + * SDL_GetVersion(&linked); + * printf("We compiled against SDL version %d.%d.%d ...\n", + * compiled.major, compiled.minor, compiled.patch); + * printf("But we linked against SDL version %d.%d.%d.\n", + * linked.major, linked.minor, linked.patch); + * \endcode + * + * This function may be called safely at any time, even before SDL_Init(). + * + * \sa SDL_VERSION */ -extern DECLSPEC const SDL_version * SDLCALL SDL_Linked_Version(void); +extern DECLSPEC void SDLCALL SDL_GetVersion (SDL_version * ver); /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_version_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_video.h b/include/SDL_video.h index 6390867da..f1860cc16 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -20,19 +20,26 @@ slouken@libsdl.org */ -/* Header file for access to the SDL raw framebuffer window */ +/** + * \file SDL_video.h + * + * Header file for access to the SDL raw framebuffer window + */ #ifndef _SDL_video_h #define _SDL_video_h #include "SDL_stdinc.h" #include "SDL_error.h" +#include "SDL_pixels.h" #include "SDL_rwops.h" #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ extern "C" { +/* *INDENT-ON* */ #endif /* Transparency definitions: These define alpha as the opacity of a surface */ @@ -40,165 +47,199 @@ extern "C" { #define SDL_ALPHA_TRANSPARENT 0 /* Useful data types */ -typedef struct SDL_Rect { - Sint16 x, y; - Uint16 w, h; +typedef struct SDL_Rect +{ + Sint16 x, y; + Uint16 w, h; } SDL_Rect; -typedef struct SDL_Color { - Uint8 r; - Uint8 g; - Uint8 b; - Uint8 unused; -} SDL_Color; -#define SDL_Colour SDL_Color - -typedef struct SDL_Palette { - int ncolors; - SDL_Color *colors; -} SDL_Palette; - -/* Everything in the pixel format structure is read-only */ -typedef struct SDL_PixelFormat { - SDL_Palette *palette; - Uint8 BitsPerPixel; - Uint8 BytesPerPixel; - Uint8 Rloss; - Uint8 Gloss; - Uint8 Bloss; - Uint8 Aloss; - Uint8 Rshift; - Uint8 Gshift; - Uint8 Bshift; - Uint8 Ashift; - Uint32 Rmask; - Uint32 Gmask; - Uint32 Bmask; - Uint32 Amask; - - /* RGB color key information */ - Uint32 colorkey; - /* Alpha value information (per-surface alpha) */ - Uint8 alpha; -} SDL_PixelFormat; - /* This structure should be treated as read-only, except for 'pixels', which, if not NULL, contains the raw pixel data for the surface. */ -typedef struct SDL_Surface { - Uint32 flags; /* Read-only */ - SDL_PixelFormat *format; /* Read-only */ - int w, h; /* Read-only */ - Uint16 pitch; /* Read-only */ - void *pixels; /* Read-write */ - int offset; /* Private */ +typedef struct SDL_Surface +{ + Uint32 flags; /* Read-only */ + SDL_PixelFormat *format; /* Read-only */ + int w, h; /* Read-only */ + Uint16 pitch; /* Read-only */ + void *pixels; /* Read-write */ + int offset; /* Private */ - /* Hardware-specific surface info */ - struct private_hwdata *hwdata; + /* Hardware-specific surface info */ + struct private_hwdata *hwdata; - /* clipping information */ - SDL_Rect clip_rect; /* Read-only */ - Uint32 unused1; /* for binary compatibility */ + /* clipping information */ + SDL_Rect clip_rect; /* Read-only */ + Uint32 unused1; /* for binary compatibility */ - /* Allow recursive locks */ - Uint32 locked; /* Private */ + /* Allow recursive locks */ + Uint32 locked; /* Private */ - /* info for fast blit mapping to other surfaces */ - struct SDL_BlitMap *map; /* Private */ + /* info for fast blit mapping to other surfaces */ + struct SDL_BlitMap *map; /* Private */ - /* format version, bumped at every change to invalidate blit maps */ - unsigned int format_version; /* Private */ + /* format version, bumped at every change to invalidate blit maps */ + unsigned int format_version; /* Private */ - /* Reference count -- used when freeing surface */ - int refcount; /* Read-mostly */ + /* Reference count -- used when freeing surface */ + int refcount; /* Read-mostly */ } SDL_Surface; -/* These are the currently supported flags for the SDL_surface */ -/* Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */ -#define SDL_SWSURFACE 0x00000000 /* Surface is in system memory */ -#define SDL_HWSURFACE 0x00000001 /* Surface is in video memory */ -#define SDL_ASYNCBLIT 0x00000004 /* Use asynchronous blits if possible */ -/* Available for SDL_SetVideoMode() */ -#define SDL_ANYFORMAT 0x10000000 /* Allow any video depth/pixel-format */ -#define SDL_HWPALETTE 0x20000000 /* Surface has exclusive palette */ -#define SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered video mode */ -#define SDL_FULLSCREEN 0x80000000 /* Surface is a full screen display */ -#define SDL_OPENGL 0x00000002 /* Create an OpenGL rendering context */ -#define SDL_INTERNALOPENGL 0x00000008 /* SDL uses OpenGL internally for this window */ -#define SDL_RESIZABLE 0x00000010 /* This video mode may be resized */ -#define SDL_NOFRAME 0x00000020 /* No window caption or edge frame */ -/* Used internally (read-only) */ -#define SDL_HWACCEL 0x00000100 /* Blit uses hardware acceleration */ -#define SDL_SRCCOLORKEY 0x00001000 /* Blit uses a source color key */ -#define SDL_RLEACCELOK 0x00002000 /* Private flag */ -#define SDL_RLEACCEL 0x00004000 /* Surface is RLE encoded */ -#define SDL_SRCALPHA 0x00010000 /* Blit uses source alpha blending */ -#define SDL_PREALLOC 0x01000000 /* Surface uses preallocated memory */ +/* The most common video overlay formats. + For an explanation of these pixel formats, see: + http://www.webartz.com/fourcc/indexyuv.htm + + For information on the relationship between color spaces, see: + http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html + */ +#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */ +#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */ +#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ +#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ +#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ + +/* The YUV hardware video overlay */ +typedef struct SDL_Overlay +{ + Uint32 format; /* Read-only */ + int w, h; /* Read-only */ + int planes; /* Read-only */ + Uint16 *pitches; /* Read-only */ + Uint8 **pixels; /* Read-write */ + + /* Hardware-specific surface info */ + struct private_yuvhwfuncs *hwfuncs; + struct private_yuvhwdata *hwdata; + + /* Special flags */ + Uint32 hw_overlay:1; /* Flag: This overlay hardware accelerated? */ + Uint32 UnusedBits:31; +} SDL_Overlay; /* Evaluates to true if the surface needs to be locked before access */ #define SDL_MUSTLOCK(surface) \ (surface->offset || \ - ((surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL)) != 0)) + ((surface->flags & (SDL_HWSURFACE|SDL_RLEACCEL)) != 0)) /* typedef for private surface blitting functions */ -typedef int (*SDL_blit)(struct SDL_Surface *src, SDL_Rect *srcrect, - struct SDL_Surface *dst, SDL_Rect *dstrect); +typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect, + struct SDL_Surface * dst, SDL_Rect * dstrect); /* Useful for determining the video hardware capabilities */ -typedef struct SDL_VideoInfo { - Uint32 hw_available :1; /* Flag: Can you create hardware surfaces? */ - Uint32 wm_available :1; /* Flag: Can you talk to a window manager? */ - Uint32 UnusedBits1 :6; - Uint32 UnusedBits2 :1; - Uint32 blit_hw :1; /* Flag: Accelerated blits HW --> HW */ - Uint32 blit_hw_CC :1; /* Flag: Accelerated blits with Colorkey */ - Uint32 blit_hw_A :1; /* Flag: Accelerated blits with Alpha */ - Uint32 blit_sw :1; /* Flag: Accelerated blits SW --> HW */ - Uint32 blit_sw_CC :1; /* Flag: Accelerated blits with Colorkey */ - Uint32 blit_sw_A :1; /* Flag: Accelerated blits with Alpha */ - Uint32 blit_fill :1; /* Flag: Accelerated color fill */ - Uint32 UnusedBits3 :16; - Uint32 video_mem; /* The total amount of video memory (in K) */ - SDL_PixelFormat *vfmt; /* Value: The format of the video surface */ - int current_w; /* Value: The current video mode width */ - int current_h; /* Value: The current video mode height */ +typedef struct SDL_VideoInfo +{ + Uint32 hw_available:1; /* Flag: Can you create hardware surfaces? */ + Uint32 wm_available:1; /* Flag: Can you talk to a window manager? */ + Uint32 UnusedBits1:6; + Uint32 UnusedBits2:1; + Uint32 blit_hw:1; /* Flag: Accelerated blits HW --> HW */ + Uint32 blit_hw_CC:1; /* Flag: Accelerated blits with Colorkey */ + Uint32 blit_hw_A:1; /* Flag: Accelerated blits with Alpha */ + Uint32 blit_sw:1; /* Flag: Accelerated blits SW --> HW */ + Uint32 blit_sw_CC:1; /* Flag: Accelerated blits with Colorkey */ + Uint32 blit_sw_A:1; /* Flag: Accelerated blits with Alpha */ + Uint32 blit_fill:1; /* Flag: Accelerated color fill */ + Uint32 UnusedBits3:16; + Uint32 video_mem; /* The total amount of video memory (in K) */ } SDL_VideoInfo; - -/* The most common video overlay formats. - For an explanation of these pixel formats, see: - http://www.webartz.com/fourcc/indexyuv.htm - - For information on the relationship between color spaces, see: - http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html +/** + * \struct SDL_DisplayMode + * + * \brief The structure that defines a display mode + * + * \sa SDL_GetNumDisplayModes() + * \sa SDL_GetDisplayMode() + * \sa SDL_GetDesktopDisplayMode() + * \sa SDL_GetCurrentDisplayMode() + * \sa SDL_GetClosestDisplayMode() + * \sa SDL_SetDisplayMode() */ -#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */ -#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */ -#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ -#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ -#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ - -/* The YUV hardware video overlay */ -typedef struct SDL_Overlay { - Uint32 format; /* Read-only */ - int w, h; /* Read-only */ - int planes; /* Read-only */ - Uint16 *pitches; /* Read-only */ - Uint8 **pixels; /* Read-write */ - - /* Hardware-specific surface info */ - struct private_yuvhwfuncs *hwfuncs; - struct private_yuvhwdata *hwdata; - - /* Special flags */ - Uint32 hw_overlay :1; /* Flag: This overlay hardware accelerated? */ - Uint32 UnusedBits :31; -} SDL_Overlay; - +typedef struct +{ + Uint32 format; /**< pixel format */ + int w; /**< width */ + int h; /**< height */ + int refresh_rate; /**< refresh rate (or zero for unspecified) */ +} SDL_DisplayMode; + +/** + * \typedef SDL_WindowID + * + * \brief The type used to identify a window + * + * \sa SDL_CreateWindow() + * \sa SDL_CreateWindowFrom() + * \sa SDL_DestroyWindow() + * \sa SDL_GetWindowData() + * \sa SDL_GetWindowFlags() + * \sa SDL_GetWindowGrab() + * \sa SDL_GetWindowPosition() + * \sa SDL_GetWindowSize() + * \sa SDL_GetWindowTitle() + * \sa SDL_HideWindow() + * \sa SDL_MaximizeWindow() + * \sa SDL_MinimizeWindow() + * \sa SDL_RaiseWindow() + * \sa SDL_RestoreWindow() + * \sa SDL_SetWindowData() + * \sa SDL_SetWindowGrab() + * \sa SDL_SetWindowIcon() + * \sa SDL_SetWindowPosition() + * \sa SDL_SetWindowSize() + * \sa SDL_SetWindowTitle() + * \sa SDL_ShowWindow() + */ +typedef Uint32 SDL_WindowID; -/* Public enumeration for setting the OpenGL window attributes. */ -typedef enum { +/** + * \enum SDL_WindowFlags + * + * \brief The flags on a window + */ +typedef enum +{ + SDL_WINDOW_FULLSCREEN = 0x00000001, /**< fullscreen window, implies borderless */ + SDL_WINDOW_BORDERLESS = 0x00000002, /**< no window decoration */ + SDL_WINDOW_SHOWN = 0x00000004, /**< window is visible */ + SDL_WINDOW_OPENGL = 0x00000008, /**< window usable with OpenGL context */ + SDL_WINDOW_RESIZABLE = 0x00000010, /**< window can be resized */ + SDL_WINDOW_MAXIMIZED = 0x00000020, /**< maximized */ + SDL_WINDOW_MINIMIZED = 0x00000040, /**< minimized */ + SDL_WINDOW_INPUT_GRABBED = 0x00000080, /**< window has grabbed input focus */ + SDL_WINDOW_KEYBOARD_FOCUS = 0x00000100, /**< window has keyboard focus */ + SDL_WINDOW_MOUSE_FOCUS = 0x00000200, /**< window has mouse focus */ +} SDL_WindowFlags; + +/** + * \enum SDL_WindowEventID + * + * \brief Event subtype for window events + */ +typedef enum +{ + SDL_WINDOWEVENT_NONE, /**< Never used */ + SDL_WINDOWEVENT_SHOWN, /**< Window has been shown */ + SDL_WINDOWEVENT_HIDDEN, /**< Window has been hidden */ + SDL_WINDOWEVENT_MOVED, /**< Window has been moved to data1,data2 */ + SDL_WINDOWEVENT_RESIZED, /**< Window size changed to data1xdata2 */ + SDL_WINDOWEVENT_MINIMIZED, /**< Window has been minimized */ + SDL_WINDOWEVENT_MAXIMIZED, /**< Window has been maximized */ + SDL_WINDOWEVENT_RESTORED, /**< Window has been restored to normal size and position */ + SDL_WINDOWEVENT_ENTER, /**< The window has gained mouse focus */ + SDL_WINDOWEVENT_LEAVE, /**< The window has lost mouse focus */ + SDL_WINDOWEVENT_FOCUS_GAINED, /**< The window has gained keyboard focus */ + SDL_WINDOWEVENT_FOCUS_LOST, /**< The window has lost keyboard focus */ +} SDL_WindowEventID; + +/** + * \enum SDL_GLattr + * + * \brief OpenGL configuration attributes + */ +typedef enum +{ SDL_GL_RED_SIZE, SDL_GL_GREEN_SIZE, SDL_GL_BLUE_SIZE, @@ -218,139 +259,423 @@ typedef enum { SDL_GL_SWAP_CONTROL } SDL_GLattr; -/* flags for SDL_SetPalette() */ -#define SDL_LOGPAL 0x01 -#define SDL_PHYSPAL 0x02 +/* These are the currently supported flags for the SDL_surface */ +#define SDL_SWSURFACE 0x00000000 /* Surface is in system memory */ +#define SDL_HWSURFACE 0x00000001 /* Surface is in video memory */ +/* Available for SDL_CreateWindowSurface() */ +#define SDL_ANYFORMAT 0x10000000 /* Allow any video depth/pixel-format */ +#define SDL_HWPALETTE 0x20000000 /* Surface has exclusive palette */ +#define SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered surface */ +/* Used internally (read-only) */ +#define SDL_HWACCEL 0x00000100 /* Blit uses hardware acceleration */ +#define SDL_SRCCOLORKEY 0x00001000 /* Blit uses a source color key */ +#define SDL_RLEACCELOK 0x00002000 /* Private flag */ +#define SDL_RLEACCEL 0x00004000 /* Surface is RLE encoded */ +#define SDL_SRCALPHA 0x00010000 /* Blit uses source alpha blending */ +#define SDL_PREALLOC 0x00100000 /* Surface uses preallocated memory */ +#define SDL_SCREEN_SURFACE 0x01000000 /* Surface is a window screen surface */ +#define SDL_SHADOW_SURFACE 0x02000000 /* Surface is a window shadow surface */ /* Function prototypes */ -/* These functions return the list of built in video drivers, in the - * order that they are normally initialized by default. +/** + * \fn int SDL_GetNumVideoDrivers(void) + * + * \brief Get the number of video drivers compiled into SDL + * + * \sa SDL_GetVideoDriver() */ -extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void); -extern DECLSPEC const char * SDLCALL SDL_GetVideoDriver(int index); +extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers (void); -/* These functions are used internally, and should not be used unless you - * have a specific need to specify the video driver you want to use. - * You should normally use SDL_Init() or SDL_InitSubSystem(). +/** + * \fn const char *SDL_GetVideoDriver(int index) * - * SDL_VideoInit() initializes the video subsystem -- sets up a connection - * to the window manager, etc, and determines the current video mode and - * pixel format, but does not initialize a window or graphics mode. - * Note that event handling is activated by this routine. + * \brief Get the name of a built in video driver. * - * If you use both sound and video in your application, you need to call - * SDL_Init() before opening the sound device, otherwise under Win32 DirectX, - * you won't be able to set full-screen display modes. + * \note The video drivers are presented in the order in which they are + * normally checked during initialization. + * + * \sa SDL_GetNumVideoDrivers() */ -extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, Uint32 flags); -extern DECLSPEC void SDLCALL SDL_VideoQuit(void); +extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver (int index); -/* This function returns the name of the current video driver, or NULL - * if no driver has been initialized. +/** + * \fn int SDL_VideoInit(const char *driver_name, Uint32 flags) + * + * \brief Initialize the video subsystem, optionally specifying a video driver. + * + * \param driver_name Initialize a specific driver by name, or NULL for the default video driver. + * \param flags FIXME: Still needed? + * + * \return 0 on success, -1 on error + * + * This function initializes the video subsystem; setting up a connection + * to the window manager, etc, and determines the available display modes + * and pixel formats, but does not initialize a window or graphics mode. + * + * \sa SDL_VideoQuit() */ -extern DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void); +extern DECLSPEC int SDLCALL SDL_VideoInit (const char *driver_name, + Uint32 flags); -/* - * This function returns a pointer to the current display surface. - * If SDL is doing format conversion on the display surface, this - * function returns the publicly visible surface, not the real video - * surface. +/** + * \fn void SDL_VideoQuit(void) + * + * \brief Shuts down the video subsystem. + * + * This function closes all windows, and restores the original video mode. + * + * \sa SDL_VideoInit() */ -extern DECLSPEC SDL_Surface * SDLCALL SDL_GetVideoSurface(void); +extern DECLSPEC void SDLCALL SDL_VideoQuit (void); -/* - * This function returns a read-only pointer to information about the - * video hardware. If this is called before SDL_SetVideoMode(), the 'vfmt' - * member of the returned structure will contain the pixel format of the - * "best" video mode. +/** + * \fn const char *SDL_GetCurrentVideoDriver(void) + * + * \brief Returns the name of the currently initialized video driver. + * + * \return The name of the current video driver or NULL if no driver + * has been initialized + * + * \sa SDL_GetNumVideoDrivers() + * \sa SDL_GetVideoDriver() */ -extern DECLSPEC const SDL_VideoInfo * SDLCALL SDL_GetVideoInfo(void); +extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver (void); -/* - * Check to see if a particular video mode is supported. - * It returns 0 if the requested mode is not supported under any bit depth, - * or returns the bits-per-pixel of the closest available mode with the - * given width and height. If this bits-per-pixel is different from the - * one used when setting the video mode, SDL_SetVideoMode() will succeed, - * but will emulate the requested bits-per-pixel with a shadow surface. +/** + * \fn const SDL_VideoInfo *SDL_GetVideoInfo(void) + * + * \brief Returns information about the currently initialized video driver. * - * The arguments to SDL_VideoModeOK() are the same ones you would pass to - * SDL_SetVideoMode() + * \return A read-only pointer to information about the video hardware, + * or NULL if no video driver has been initialized. */ -extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags); +extern DECLSPEC const SDL_VideoInfo *SDLCALL SDL_GetVideoInfo (void); -/* - * Return a pointer to an array of available screen dimensions for the - * given format and video flags, sorted largest to smallest. Returns - * NULL if there are no dimensions available for a particular format, - * or (SDL_Rect **)-1 if any dimension is okay for the given format. +/** + * \fn int SDL_GetNumVideoDisplays(void) + * + * \brief Returns the number of available video displays. * - * If 'format' is NULL, the mode list will be for the format given - * by SDL_GetVideoInfo()->vfmt + * \sa SDL_SelectVideoDisplay() */ -extern DECLSPEC SDL_Rect ** SDLCALL SDL_ListModes(SDL_PixelFormat *format, Uint32 flags); +extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays (void); -/* - * Set up a video mode with the specified width, height and bits-per-pixel. - * - * If 'bpp' is 0, it is treated as the current display bits per pixel. - * - * If SDL_ANYFORMAT is set in 'flags', the SDL library will try to set the - * requested bits-per-pixel, but will return whatever video pixel format is - * available. The default is to emulate the requested pixel format if it - * is not natively available. - * - * If SDL_HWSURFACE is set in 'flags', the video surface will be placed in - * video memory, if possible, and you may have to call SDL_LockSurface() - * in order to access the raw framebuffer. Otherwise, the video surface - * will be created in system memory. - * - * If SDL_ASYNCBLIT is set in 'flags', SDL will try to perform rectangle - * updates asynchronously, but you must always lock before accessing pixels. - * SDL will wait for updates to complete before returning from the lock. - * - * If SDL_HWPALETTE is set in 'flags', the SDL library will guarantee - * that the colors set by SDL_SetColors() will be the colors you get. - * Otherwise, in 8-bit mode, SDL_SetColors() may not be able to set all - * of the colors exactly the way they are requested, and you should look - * at the video surface structure to determine the actual palette. - * If SDL cannot guarantee that the colors you request can be set, - * i.e. if the colormap is shared, then the video surface may be created - * under emulation in system memory, overriding the SDL_HWSURFACE flag. - * - * If SDL_FULLSCREEN is set in 'flags', the SDL library will try to set - * a fullscreen video mode. The default is to create a windowed mode - * if the current graphics system has a window manager. - * If the SDL library is able to set a fullscreen video mode, this flag - * will be set in the surface that is returned. - * - * If SDL_DOUBLEBUF is set in 'flags', the SDL library will try to set up - * two surfaces in video memory and swap between them when you call - * SDL_Flip(). This is usually slower than the normal single-buffering - * scheme, but prevents "tearing" artifacts caused by modifying video - * memory while the monitor is refreshing. It should only be used by - * applications that redraw the entire screen on every update. - * - * If SDL_RESIZABLE is set in 'flags', the SDL library will allow the - * window manager, if any, to resize the window at runtime. When this - * occurs, SDL will send a SDL_VIDEORESIZE event to you application, - * and you must respond to the event by re-calling SDL_SetVideoMode() - * with the requested size (or another size that suits the application). - * - * If SDL_NOFRAME is set in 'flags', the SDL library will create a window - * without any title bar or frame decoration. Fullscreen video modes have - * this flag set automatically. - * - * This function returns the video framebuffer surface, or NULL if it fails. - * - * If you rely on functionality provided by certain video flags, check the - * flags of the returned surface to make sure that functionality is available. - * SDL will fall back to reduced functionality if the exact flags you wanted - * are not available. - */ -extern DECLSPEC SDL_Surface * SDLCALL SDL_SetVideoMode - (int width, int height, int bpp, Uint32 flags); +/** + * \fn int SDL_SelectVideoDisplay(int index) + * + * \brief Set the index of the currently selected display. + * + * \note You can query the currently selected display by passing an index of -1. + * + * \sa SDL_GetNumVideoDisplays() + */ +extern DECLSPEC int SDLCALL SDL_SelectVideoDisplay (int index); + +/** + * \fn int SDL_GetNumDisplayModes(void) + * + * \brief Returns the number of available display modes for the current display. + * + * \sa SDL_GetDisplayMode() + */ +extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes (void); + +/** + * \fn const SDL_DisplayMode *SDL_GetDisplayMode(int index) + * + * \brief Retrieve information about a specific display mode. + * + * \note The display modes are sorted in this priority: + * \li bits per pixel -> more colors to fewer colors + * \li width -> largest to smallest + * \li height -> largest to smallest + * \li refresh rate -> highest to lowest + * + * \sa SDL_GetNumDisplayModes() + */ +extern DECLSPEC const SDL_DisplayMode *SDLCALL SDL_GetDisplayMode (int index); + +/** + * \fn const SDL_DisplayMode *SDL_GetDesktopDisplayMode(void) + * + * \brief Retrieve information about the desktop display mode for the current display. + */ +extern DECLSPEC const SDL_DisplayMode *SDLCALL +SDL_GetDesktopDisplayMode (void); + +/** + * \fn const SDL_DisplayMode *SDL_GetCurrentDisplayMode(void) + * + * \brief Retrieve information about the current display mode. + */ +extern DECLSPEC const SDL_DisplayMode *SDLCALL +SDL_GetCurrentDisplayMode (void); + +/** + * \fn SDL_DisplayMode *SDL_GetClosestDisplayMode(const SDL_DisplayMode *mode, SDL_DisplayMode *closest) + * + * \brief Get the closest match to the requested display mode. + * + * \param mode The desired display mode + * \param closest A pointer to a display mode to be filled in with the closest match of the available display modes. + * + * \return The passed in value 'closest', or NULL if no matching video mode was available. + * + * The available display modes are scanned, and 'closest' is filled in with the closest mode matching the requested mode and returned. The mode format and refresh_rate default to the desktop mode if they are 0. The modes are scanned with size being first priority, format being second priority, and finally checking the refresh_rate. If all the available modes are too small, then NULL is returned. + * + * \sa SDL_GetNumDisplayModes() + * \sa SDL_GetDisplayMode() + */ +extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode (const + SDL_DisplayMode + * mode, + SDL_DisplayMode + * + closest); + +/** + * \fn int SDL_SetDisplayMode(const SDL_DisplayMode *mode) + * + * \brief Set up the closest available mode on the current display. + * + * \param mode The desired display mode + * + * \return 0 on success, or -1 if setting the display mode failed. + */ +extern DECLSPEC int SDLCALL SDL_SetDisplayMode (const SDL_DisplayMode * mode); + +/** + * \fn SDL_WindowID SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) + * + * \brief Create a window with the specified position, dimensions, and flags. + * + * \param title The title of the window + * \param x The x position of the window + * \param y The y position of the window + * \param w The width of the window + * \param h The height of the window + * \param flags The flags for the window + * + * \return The id of the window created, or zero if window creation failed. + * + * \note Setting the position to -1, -1, indicates any position is fine. + * + * \sa SDL_DestroyWindow() + */ +extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindow (const char *title, + int x, int y, int w, + int h, Uint32 flags); + +/** + * \fn SDL_WindowID SDL_CreateWindowFrom(void *data) + * + * \brief Create an SDL window struct from an existing native window. + * + * \param data A pointer to driver-dependent window creation data + * + * \return The id of the window created, or zero if window creation failed. + * + * \warning This function is NOT SUPPORTED, use at your own risk! + * + * \sa SDL_DestroyWindow() + */ +extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindowFrom (void *data); + +/** + * \fn Uint32 SDL_GetWindowFlags(SDL_WindowID windowID) + * + * \brief Get the window flags. + */ +extern DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags (SDL_WindowID windowID); + +/** + * \fn void SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) + * + * \brief Set the title of the window, in UTF-8 format. + * + * \sa SDL_GetWindowTitle() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowTitle (SDL_WindowID windowID, + const char *title); + +/** + * \fn const char *SDL_GetWindowTitle(SDL_WindowID windowID) + * + * \brief Get the title of the window, in UTF-8 format. + * + * \sa SDL_SetWindowTitle() + */ +extern DECLSPEC const char *SDLCALL SDL_GetWindowTitle (SDL_WindowID + windowID); + +/** + * \fn void SDL_SetWindowIcon(SDL_Surface *icon) + * + * \brief Set the icon of the window. + * + * \param icon The icon for the window + * + * FIXME: The icon needs to be set before the window is first shown. Should some icon representation be part of the window creation data? + */ +extern DECLSPEC void SDLCALL SDL_SetWindowIcon (SDL_Surface * icon); + +/** + * \fn void SDL_SetWindowData(SDL_WindowID windowID, void *userdata) + * + * \brief Associate an arbitrary pointer with the window. + * + * \sa SDL_GetWindowData() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowData (SDL_WindowID windowID, + void *userdata); + +/** + * \fn void *SDL_GetWindowData(SDL_WindowID windowID) + * + * \brief Retrieve the data pointer associated with the window. + * + * \sa SDL_SetWindowData() + */ +extern DECLSPEC void *SDLCALL SDL_GetWindowData (SDL_WindowID windowID); + +/** + * \fn void SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) + * + * \brief Set the position of the window. + * + * \sa SDL_GetWindowPosition() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowPosition (SDL_WindowID windowID, + int x, int y); + +/** + * \fn void SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y) + * + * \brief Get the position of the window. + * + * \sa SDL_SetWindowPosition() + */ +extern DECLSPEC void SDLCALL SDL_GetWindowPosition (SDL_WindowID windowID, + int *x, int *y); + +/** + * \fn void SDL_SetWindowSize(SDL_WindowID windowID, int w, int w) + * + * \brief Set the size of the window's client area. + * + * \note You can't change the size of a fullscreen window, it automatically + * matches the size of the display mode. + * + * \sa SDL_GetWindowSize() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowSize (SDL_WindowID windowID, int w, + int h); + +/** + * \fn void SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *w) + * + * \brief Get the size of the window's client area. + * + * \sa SDL_SetWindowSize() + */ +extern DECLSPEC void SDLCALL SDL_GetWindowSize (SDL_WindowID windowID, int *w, + int *h); + +/** + * \fn void SDL_ShowWindow(SDL_WindowID windowID) + * + * \brief Show the window + * + * \sa SDL_HideWindow() + */ +extern DECLSPEC void SDLCALL SDL_ShowWindow (SDL_WindowID windowID); + +/** + * \fn void SDL_HideWindow(SDL_WindowID windowID) + * + * \brief Hide the window + * + * \sa SDL_ShowWindow() + */ +extern DECLSPEC void SDLCALL SDL_HideWindow (SDL_WindowID windowID); + +/** + * \fn void SDL_RaiseWindow(SDL_WindowID windowID) + * + * \brief Raise the window so it's above other windows. + */ +extern DECLSPEC void SDLCALL SDL_RaiseWindow (SDL_WindowID windowID); + +/** + * \fn void SDL_MaximizeWindow(SDL_WindowID windowID) + * + * \brief Make the window as large as possible. + * + * \sa SDL_RestoreWindow() + */ +extern DECLSPEC void SDLCALL SDL_MaximizeWindow (SDL_WindowID windowID); + +/** + * \fn void SDL_MinimizeWindow(SDL_WindowID windowID) + * + * \brief Minimize the window to an iconic representation. + * + * \sa SDL_RestoreWindow() + */ +extern DECLSPEC void SDLCALL SDL_MinimizeWindow (SDL_WindowID windowID); + +/** + * \fn void SDL_RestoreWindow(SDL_WindowID windowID) + * + * \brief Restore the size and position of a minimized or maximized window. + * + * \sa SDL_MaximizeWindow() + * \sa SDL_MinimizeWindow() + */ +extern DECLSPEC void SDLCALL SDL_RestoreWindow (SDL_WindowID windowID); + +/** + * \fn void SDL_SetWindowGrab(SDL_WindowID windowID, int mode) + * + * \brief Set the window's input grab mode. + * + * \param mode This is 1 to grab input, and 0 to release input. + * + * \sa SDL_GrabMode + * \sa SDL_GetWindowGrab() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowGrab (SDL_WindowID windowID, + int mode); + +/** + * \fn int SDL_GetWindowGrab(SDL_WindowID windowID) + * + * \brief Get the window's input grab mode. + * + * \return This returns 1 if input is grabbed, and 0 otherwise. + * + * \sa SDL_GrabMode + * \sa SDL_SetWindowGrab() + */ +extern DECLSPEC int SDLCALL SDL_GetWindowGrab (SDL_WindowID windowID); + +/** + * \fn void SDL_DestroyWindow(SDL_WindowID windowID) + * + * \brief Destroy a window. + */ +extern DECLSPEC void SDLCALL SDL_DestroyWindow (SDL_WindowID windowID); + +/** + * \fn SDL_Surface *SDL_CreateWindowSurface (SDL_WindowID windowID, Uint32 format, Uint32 flags) + * + * \brief Create an SDL_Surface representing the drawing area of the window. + */ +extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateWindowSurface (SDL_WindowID + windowID, + Uint32 format, + Uint32 flags); /* * Makes sure the given list of rectangles is updated on the given screen. @@ -359,9 +684,9 @@ extern DECLSPEC SDL_Surface * SDLCALL SDL_SetVideoMode * These functions should not be called while 'screen' is locked. */ extern DECLSPEC void SDLCALL SDL_UpdateRects - (SDL_Surface *screen, int numrects, SDL_Rect *rects); + (SDL_Surface * screen, int numrects, SDL_Rect * rects); extern DECLSPEC void SDLCALL SDL_UpdateRect - (SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h); + (SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h); /* * On hardware that supports double-buffering, this function sets up a flip @@ -373,7 +698,7 @@ extern DECLSPEC void SDLCALL SDL_UpdateRect * setting the video mode for this function to perform hardware flipping. * This function returns 0 if successful, or -1 if there was an error. */ -extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface *screen); +extern DECLSPEC int SDLCALL SDL_Flip (SDL_Surface * screen); /* * Set the gamma correction for each of the color channels. @@ -383,7 +708,7 @@ extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface *screen); * be emulated using gamma ramps, if available. If successful, this * function returns 0, otherwise it returns -1. */ -extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue); +extern DECLSPEC int SDLCALL SDL_SetGamma (float red, float green, float blue); /* * Set the gamma translation table for the red, green, and blue channels @@ -397,7 +722,9 @@ extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue); * hardware does not support gamma translation, or otherwise fails, * this function will return -1. */ -extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue); +extern DECLSPEC int SDLCALL SDL_SetGammaRamp (const Uint16 * red, + const Uint16 * green, + const Uint16 * blue); /* * Retrieve the current values of the gamma translation tables. @@ -408,7 +735,8 @@ extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 *red, const Uint16 *gr * hardware does not support gamma translation, or otherwise fails, * this function will return -1. */ -extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue); +extern DECLSPEC int SDLCALL SDL_GetGammaRamp (Uint16 * red, Uint16 * green, + Uint16 * blue); /* * Sets a portion of the colormap for the given 8-bit surface. If 'surface' @@ -425,52 +753,35 @@ extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 * you desire, even if the window colormap has to be warped or run under * emulation. */ -extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface *surface, - SDL_Color *colors, int firstcolor, int ncolors); - -/* - * Sets a portion of the colormap for a given 8-bit surface. - * 'flags' is one or both of: - * SDL_LOGPAL -- set logical palette, which controls how blits are mapped - * to/from the surface, - * SDL_PHYSPAL -- set physical palette, which controls how pixels look on - * the screen - * Only screens have physical palettes. Separate change of physical/logical - * palettes is only possible if the screen has SDL_HWPALETTE set. - * - * The return value is 1 if all colours could be set as requested, and 0 - * otherwise. - * - * SDL_SetColors() is equivalent to calling this function with - * flags = (SDL_LOGPAL|SDL_PHYSPAL). - */ -extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface *surface, int flags, - SDL_Color *colors, int firstcolor, - int ncolors); +extern DECLSPEC int SDLCALL SDL_SetColors (SDL_Surface * surface, + SDL_Color * colors, int firstcolor, + int ncolors); /* * Maps an RGB triple to an opaque pixel value for a given pixel format */ extern DECLSPEC Uint32 SDLCALL SDL_MapRGB - (SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b); + (SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b); /* * Maps an RGBA quadruple to a pixel value for a given pixel format */ -extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(SDL_PixelFormat *format, - Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA (SDL_PixelFormat * format, + Uint8 r, Uint8 g, Uint8 b, + Uint8 a); /* * Maps a pixel value into the RGB components for a given pixel format */ -extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, - Uint8 *r, Uint8 *g, Uint8 *b); +extern DECLSPEC void SDLCALL SDL_GetRGB (Uint32 pixel, SDL_PixelFormat * fmt, + Uint8 * r, Uint8 * g, Uint8 * b); /* * Maps a pixel value into the RGBA components for a given pixel format */ -extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, - Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); +extern DECLSPEC void SDLCALL SDL_GetRGBA (Uint32 pixel, SDL_PixelFormat * fmt, + Uint8 * r, Uint8 * g, Uint8 * b, + Uint8 * a); /* * Allocate and free an RGB surface (must be called after SDL_SetVideoMode) @@ -507,13 +818,19 @@ extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, * the SDL_HWSURFACE flag set, and will be created in system memory instead. */ #define SDL_AllocSurface SDL_CreateRGBSurface -extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurface - (Uint32 flags, int width, int height, int depth, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); -extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels, - int width, int height, int depth, int pitch, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); -extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface); +extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface + (Uint32 flags, int width, int height, int depth, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); +extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom (void *pixels, + int width, + int height, + int depth, + int pitch, + Uint32 Rmask, + Uint32 Gmask, + Uint32 Bmask, + Uint32 Amask); +extern DECLSPEC void SDLCALL SDL_FreeSurface (SDL_Surface * surface); /* * SDL_LockSurface() sets up a surface for directly accessing the pixels. @@ -533,8 +850,8 @@ extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface); * * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked. */ -extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface); -extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface); +extern DECLSPEC int SDLCALL SDL_LockSurface (SDL_Surface * surface); +extern DECLSPEC void SDLCALL SDL_UnlockSurface (SDL_Surface * surface); /* * Load a surface from a seekable SDL data source (memory or file.) @@ -542,7 +859,8 @@ extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface); * Returns the new surface, or NULL if there was an error. * The new surface should be freed with SDL_FreeSurface(). */ -extern DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, int freesrc); +extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW (SDL_RWops * src, + int freesrc); /* Convenience macro -- load a surface from a file */ #define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1) @@ -553,7 +871,7 @@ extern DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, int freesrc * Returns 0 if successful or -1 if there was an error. */ extern DECLSPEC int SDLCALL SDL_SaveBMP_RW - (SDL_Surface *surface, SDL_RWops *dst, int freedst); + (SDL_Surface * surface, SDL_RWops * dst, int freedst); /* Convenience macro -- save a surface to a file */ #define SDL_SaveBMP(surface, file) \ @@ -569,7 +887,7 @@ extern DECLSPEC int SDLCALL SDL_SaveBMP_RW * This function returns 0, or -1 if there was an error. */ extern DECLSPEC int SDLCALL SDL_SetColorKey - (SDL_Surface *surface, Uint32 flag, Uint32 key); + (SDL_Surface * surface, Uint32 flag, Uint32 key); /* * This function sets the alpha value for the entire surface, as opposed to @@ -586,7 +904,8 @@ extern DECLSPEC int SDLCALL SDL_SetColorKey * * The 'alpha' parameter is ignored for surfaces that have an alpha channel. */ -extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha); +extern DECLSPEC int SDLCALL SDL_SetAlpha (SDL_Surface * surface, Uint32 flag, + Uint8 alpha); /* * Sets the clipping rectangle for the destination surface in a blit. @@ -600,14 +919,16 @@ extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint * Note that blits are automatically clipped to the edges of the source * and destination surfaces. */ -extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect); +extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect (SDL_Surface * surface, + const SDL_Rect * rect); /* * Gets the clipping rectangle for the destination surface in a blit. * 'rect' must be a pointer to a valid rectangle which will be filled * with the correct values. */ -extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect); +extern DECLSPEC void SDLCALL SDL_GetClipRect (SDL_Surface * surface, + SDL_Rect * rect); /* * Creates a new surface of the specified format, and then copies and maps @@ -621,8 +942,8 @@ extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rec * * This function is used internally by SDL_DisplayFormat(). */ -extern DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface - (SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags); +extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface + (SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags); /* * This performs a fast blit from the source surface to the destination @@ -699,14 +1020,14 @@ extern DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface rectangle validation and clipping before passing it to SDL_LowerBlit() */ extern DECLSPEC int SDLCALL SDL_UpperBlit - (SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); + (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect); /* This is a semi-private blit function and it performs low-level surface blitting only. */ extern DECLSPEC int SDLCALL SDL_LowerBlit - (SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); + (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect); /* * This function performs a fast fill of the given rectangle with 'color' @@ -718,7 +1039,7 @@ extern DECLSPEC int SDLCALL SDL_LowerBlit * This function returns 0 on success, or -1 on error. */ extern DECLSPEC int SDLCALL SDL_FillRect - (SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color); + (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color); /* * This function takes a surface and copies it to a new surface of the @@ -731,7 +1052,8 @@ extern DECLSPEC int SDLCALL SDL_FillRect * * If the conversion fails or runs out of memory, it returns NULL */ -extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormat(SDL_Surface *surface); +extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat (SDL_Surface * + surface); /* * This function takes a surface and copies it to a new surface of the @@ -745,7 +1067,8 @@ extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormat(SDL_Surface *surface); * * If the conversion fails or runs out of memory, it returns NULL */ -extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *surface); +extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha (SDL_Surface * + surface); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -757,12 +1080,15 @@ extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *surfac the contents of the display surface underneath the area where the overlay is shown is undefined - it may be overwritten with the converted YUV data. */ -extern DECLSPEC SDL_Overlay * SDLCALL SDL_CreateYUVOverlay(int width, int height, - Uint32 format, SDL_Surface *display); +extern DECLSPEC SDL_Overlay *SDLCALL SDL_CreateYUVOverlay (int width, + int height, + Uint32 format, + SDL_Surface * + display); /* Lock an overlay for direct access, and unlock it when you are done */ -extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay *overlay); -extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay *overlay); +extern DECLSPEC int SDLCALL SDL_LockYUVOverlay (SDL_Overlay * overlay); +extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay (SDL_Overlay * overlay); /* Blit a video overlay to the display surface. The contents of the video surface underneath the blit destination are @@ -770,10 +1096,11 @@ extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay *overlay); The width and height of the destination rectangle may be different from that of the overlay, but currently only 2x scaling is supported. */ -extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect); +extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay (SDL_Overlay * overlay, + SDL_Rect * dstrect); /* Free a video overlay */ -extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay *overlay); +extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay (SDL_Overlay * overlay); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -786,17 +1113,17 @@ extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay *overlay); * If you do this, you need to retrieve all of the GL functions used in * your program from the dynamic library using SDL_GL_GetProcAddress(). */ -extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path); +extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary (const char *path); /* * Get the address of a GL function */ -extern DECLSPEC void * SDLCALL SDL_GL_GetProcAddress(const char* proc); +extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress (const char *proc); /* - * Set an attribute of the OpenGL subsystem before intialization. + * Set an attribute of the OpenGL subsystem before window creation. */ -extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); +extern DECLSPEC int SDLCALL SDL_GL_SetAttribute (SDL_GLattr attr, int value); /* * Get an attribute of the OpenGL subsystem from the windowing @@ -807,80 +1134,27 @@ extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); * Developers should track the values they pass into SDL_GL_SetAttribute * themselves if they want to retrieve these values. */ -extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int* value); +extern DECLSPEC int SDLCALL SDL_GL_GetAttribute (SDL_GLattr attr, int *value); /* * Swap the OpenGL buffers, if double-buffering is supported. */ -extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void); - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* These functions allow interaction with the window manager, if any. */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* - * Sets/Gets the title and icon text of the display window (UTF-8 encoded) - */ -extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title, const char *icon); -extern DECLSPEC void SDLCALL SDL_WM_GetCaption(char **title, char **icon); - -/* - * Sets the icon for the display window. - * This function must be called before the first call to SDL_SetVideoMode(). - * It takes an icon surface, and a mask in MSB format. - * If 'mask' is NULL, the entire icon surface will be used as the icon. - */ -extern DECLSPEC void SDLCALL SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); - -/* - * This function iconifies the window, and returns 1 if it succeeded. - * If the function succeeds, it generates an SDL_APPACTIVE loss event. - * This function is a noop and returns 0 in non-windowed environments. - */ -extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void); - -/* - * Toggle fullscreen mode without changing the contents of the screen. - * If the display surface does not require locking before accessing - * the pixel information, then the memory pointers will not change. - * - * If this function was able to toggle fullscreen mode (change from - * running in a window to fullscreen, or vice-versa), it will return 1. - * If it is not implemented, or fails, it returns 0. - * - * The next call to SDL_SetVideoMode() will set the mode fullscreen - * attribute based on the flags parameter - if SDL_FULLSCREEN is not - * set, then the display will be windowed by default where supported. - * - * This is currently only implemented in the X11 video driver. - */ -extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface *surface); - -/* - * This function allows you to set and query the input grab state of - * the application. It returns the new input grab state. - */ -typedef enum { - SDL_GRAB_QUERY = -1, - SDL_GRAB_OFF = 0, - SDL_GRAB_ON = 1, - SDL_GRAB_FULLSCREEN /* Used internally */ -} SDL_GrabMode; -/* - * Grabbing means that the mouse is confined to the application window, - * and nearly all keyboard input is passed directly to the application, - * and not interpreted by a window manager, if any. - */ -extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode); +extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers (void); /* Not in public API at the moment - do not use! */ -extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); - +extern DECLSPEC int SDLCALL SDL_SoftStretch (SDL_Surface * src, + SDL_Rect * srcrect, + SDL_Surface * dst, + SDL_Rect * dstrect); + /* Ends C function definitions when using C++ */ #ifdef __cplusplus +/* *INDENT-OFF* */ } +/* *INDENT-ON* */ #endif #include "close_code.h" #endif /* _SDL_video_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/begin_code.h b/include/begin_code.h index 40279337f..01f4088de 100644 --- a/include/begin_code.h +++ b/include/begin_code.h @@ -42,7 +42,7 @@ # elif defined(__WIN32__) # ifdef __BORLANDC__ # ifdef BUILD_SDL -# define DECLSPEC +# define DECLSPEC # else # define DECLSPEC __declspec(dllimport) # endif @@ -84,7 +84,7 @@ #endif /* SDLCALL */ /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */ -#ifdef __SYMBIAN32__ +#ifdef __SYMBIAN32__ #undef DECLSPEC #define DECLSPEC #endif /* __SYMBIAN32__ */ diff --git a/include/close_code.h b/include/close_code.h index afbb65047..bf609d88a 100644 --- a/include/close_code.h +++ b/include/close_code.h @@ -38,4 +38,3 @@ #pragma pack(pop) #endif #endif /* Compiler needs structure packing set */ - diff --git a/include/doxyfile b/include/doxyfile new file mode 100644 index 000000000..e53097f4b --- /dev/null +++ b/include/doxyfile @@ -0,0 +1,1229 @@ +# Doxyfile 1.4.4 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = SDL + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 1.3.0 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = docs + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is YES. + +SHOW_DIRECTORIES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the progam writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = YES + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = YES + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = YES + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = DOXYGEN_SHOULD_IGNORE_THIS=1 \ + DECLSPEC= SDLCALL= + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = NO + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/src/SDL.c b/src/SDL.c index 64a3e93dc..0c91c0d3c 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -35,23 +35,19 @@ /* Initialization/Cleanup routines */ #if !SDL_JOYSTICK_DISABLED -extern int SDL_JoystickInit(void); -extern void SDL_JoystickQuit(void); +extern int SDL_JoystickInit (void); +extern void SDL_JoystickQuit (void); #endif #if !SDL_CDROM_DISABLED -extern int SDL_CDROMInit(void); -extern void SDL_CDROMQuit(void); +extern int SDL_CDROMInit (void); +extern void SDL_CDROMQuit (void); #endif #if !SDL_TIMERS_DISABLED -extern void SDL_StartTicks(void); -extern int SDL_TimerInit(void); -extern void SDL_TimerQuit(void); +extern void SDL_StartTicks (void); +extern int SDL_TimerInit (void); +extern void SDL_TimerQuit (void); #endif -/* The current SDL version */ -static SDL_version version = - { SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL }; - /* The initialized subsystems */ static Uint32 SDL_initialized = 0; static Uint32 ticks_started = 0; @@ -60,196 +56,205 @@ static Uint32 ticks_started = 0; int surfaces_allocated = 0; #endif -int SDL_InitSubSystem(Uint32 flags) +int +SDL_InitSubSystem (Uint32 flags) { #if !SDL_VIDEO_DISABLED - /* Initialize the video/event subsystem */ - if ( (flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO) ) { - if ( SDL_VideoInit(SDL_getenv("SDL_VIDEODRIVER"), - (flags&SDL_INIT_EVENTTHREAD)) < 0 ) { - return(-1); - } - SDL_initialized |= SDL_INIT_VIDEO; - } + /* Initialize the video/event subsystem */ + if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) { + if (SDL_VideoInit (SDL_getenv ("SDL_VIDEODRIVER"), + (flags & SDL_INIT_EVENTTHREAD)) < 0) { + return (-1); + } + SDL_initialized |= SDL_INIT_VIDEO; + } #else - if ( flags & SDL_INIT_VIDEO ) { - SDL_SetError("SDL not built with video support"); - return(-1); - } + if (flags & SDL_INIT_VIDEO) { + SDL_SetError ("SDL not built with video support"); + return (-1); + } #endif #if !SDL_AUDIO_DISABLED - /* Initialize the audio subsystem */ - if ( (flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO) ) { - if ( SDL_AudioInit(SDL_getenv("SDL_AUDIODRIVER")) < 0 ) { - return(-1); - } - SDL_initialized |= SDL_INIT_AUDIO; - } + /* Initialize the audio subsystem */ + if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) { + if (SDL_AudioInit (SDL_getenv ("SDL_AUDIODRIVER")) < 0) { + return (-1); + } + SDL_initialized |= SDL_INIT_AUDIO; + } #else - if ( flags & SDL_INIT_AUDIO ) { - SDL_SetError("SDL not built with audio support"); - return(-1); - } + if (flags & SDL_INIT_AUDIO) { + SDL_SetError ("SDL not built with audio support"); + return (-1); + } #endif #if !SDL_TIMERS_DISABLED - /* Initialize the timer subsystem */ - if ( ! ticks_started ) { - SDL_StartTicks(); - ticks_started = 1; - } - if ( (flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER) ) { - if ( SDL_TimerInit() < 0 ) { - return(-1); - } - SDL_initialized |= SDL_INIT_TIMER; - } + /* Initialize the timer subsystem */ + if (!ticks_started) { + SDL_StartTicks (); + ticks_started = 1; + } + if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) { + if (SDL_TimerInit () < 0) { + return (-1); + } + SDL_initialized |= SDL_INIT_TIMER; + } #else - if ( flags & SDL_INIT_TIMER ) { - SDL_SetError("SDL not built with timer support"); - return(-1); - } + if (flags & SDL_INIT_TIMER) { + SDL_SetError ("SDL not built with timer support"); + return (-1); + } #endif #if !SDL_JOYSTICK_DISABLED - /* Initialize the joystick subsystem */ - if ( (flags & SDL_INIT_JOYSTICK) && - !(SDL_initialized & SDL_INIT_JOYSTICK) ) { - if ( SDL_JoystickInit() < 0 ) { - return(-1); - } - SDL_initialized |= SDL_INIT_JOYSTICK; - } + /* Initialize the joystick subsystem */ + if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) { + if (SDL_JoystickInit () < 0) { + return (-1); + } + SDL_initialized |= SDL_INIT_JOYSTICK; + } #else - if ( flags & SDL_INIT_JOYSTICK ) { - SDL_SetError("SDL not built with joystick support"); - return(-1); - } + if (flags & SDL_INIT_JOYSTICK) { + SDL_SetError ("SDL not built with joystick support"); + return (-1); + } #endif #if !SDL_CDROM_DISABLED - /* Initialize the CD-ROM subsystem */ - if ( (flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM) ) { - if ( SDL_CDROMInit() < 0 ) { - return(-1); - } - SDL_initialized |= SDL_INIT_CDROM; - } + /* Initialize the CD-ROM subsystem */ + if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) { + if (SDL_CDROMInit () < 0) { + return (-1); + } + SDL_initialized |= SDL_INIT_CDROM; + } #else - if ( flags & SDL_INIT_CDROM ) { - SDL_SetError("SDL not built with cdrom support"); - return(-1); - } + if (flags & SDL_INIT_CDROM) { + SDL_SetError ("SDL not built with cdrom support"); + return (-1); + } #endif - return(0); + return (0); } -int SDL_Init(Uint32 flags) +int +SDL_Init (Uint32 flags) { #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH - if (!pth_init()) { - return -1; - } + if (!pth_init ()) { + return -1; + } #endif - /* Clear the error message */ - SDL_ClearError(); + /* Clear the error message */ + SDL_ClearError (); - /* Initialize the desired subsystems */ - if ( SDL_InitSubSystem(flags) < 0 ) { - return(-1); - } + /* Initialize the desired subsystems */ + if (SDL_InitSubSystem (flags) < 0) { + return (-1); + } - /* Everything is initialized */ - if ( !(flags & SDL_INIT_NOPARACHUTE) ) { - SDL_InstallParachute(); - } - return(0); + /* Everything is initialized */ + if (!(flags & SDL_INIT_NOPARACHUTE)) { + SDL_InstallParachute (); + } + return (0); } -void SDL_QuitSubSystem(Uint32 flags) +void +SDL_QuitSubSystem (Uint32 flags) { - /* Shut down requested initialized subsystems */ + /* Shut down requested initialized subsystems */ #if !SDL_CDROM_DISABLED - if ( (flags & SDL_initialized & SDL_INIT_CDROM) ) { - SDL_CDROMQuit(); - SDL_initialized &= ~SDL_INIT_CDROM; - } + if ((flags & SDL_initialized & SDL_INIT_CDROM)) { + SDL_CDROMQuit (); + SDL_initialized &= ~SDL_INIT_CDROM; + } #endif #if !SDL_JOYSTICK_DISABLED - if ( (flags & SDL_initialized & SDL_INIT_JOYSTICK) ) { - SDL_JoystickQuit(); - SDL_initialized &= ~SDL_INIT_JOYSTICK; - } + if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) { + SDL_JoystickQuit (); + SDL_initialized &= ~SDL_INIT_JOYSTICK; + } #endif #if !SDL_TIMERS_DISABLED - if ( (flags & SDL_initialized & SDL_INIT_TIMER) ) { - SDL_TimerQuit(); - SDL_initialized &= ~SDL_INIT_TIMER; - } + if ((flags & SDL_initialized & SDL_INIT_TIMER)) { + SDL_TimerQuit (); + SDL_initialized &= ~SDL_INIT_TIMER; + } #endif #if !SDL_AUDIO_DISABLED - if ( (flags & SDL_initialized & SDL_INIT_AUDIO) ) { - SDL_AudioQuit(); - SDL_initialized &= ~SDL_INIT_AUDIO; - } + if ((flags & SDL_initialized & SDL_INIT_AUDIO)) { + SDL_AudioQuit (); + SDL_initialized &= ~SDL_INIT_AUDIO; + } #endif #if !SDL_VIDEO_DISABLED - if ( (flags & SDL_initialized & SDL_INIT_VIDEO) ) { - SDL_VideoQuit(); - SDL_initialized &= ~SDL_INIT_VIDEO; - } + if ((flags & SDL_initialized & SDL_INIT_VIDEO)) { + SDL_VideoQuit (); + SDL_initialized &= ~SDL_INIT_VIDEO; + } #endif } -Uint32 SDL_WasInit(Uint32 flags) +Uint32 +SDL_WasInit (Uint32 flags) { - if ( ! flags ) { - flags = SDL_INIT_EVERYTHING; - } - return (SDL_initialized&flags); + if (!flags) { + flags = SDL_INIT_EVERYTHING; + } + return (SDL_initialized & flags); } -void SDL_Quit(void) +void +SDL_Quit (void) { - /* Quit all subsystems */ + /* Quit all subsystems */ #ifdef DEBUG_BUILD - printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); fflush(stdout); + printf ("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); + fflush (stdout); #endif - SDL_QuitSubSystem(SDL_INIT_EVERYTHING); + SDL_QuitSubSystem (SDL_INIT_EVERYTHING); #ifdef CHECK_LEAKS #ifdef DEBUG_BUILD - printf("[SDL_Quit] : CHECK_LEAKS\n"); fflush(stdout); + printf ("[SDL_Quit] : CHECK_LEAKS\n"); + fflush (stdout); #endif - /* Print the number of surfaces not freed */ - if ( surfaces_allocated != 0 ) { - fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n", - surfaces_allocated); - } + /* Print the number of surfaces not freed */ + if (surfaces_allocated != 0) { + fprintf (stderr, "SDL Warning: %d SDL surfaces extant\n", + surfaces_allocated); + } #endif #ifdef DEBUG_BUILD - printf("[SDL_Quit] : SDL_UninstallParachute()\n"); fflush(stdout); + printf ("[SDL_Quit] : SDL_UninstallParachute()\n"); + fflush (stdout); #endif - /* Uninstall any parachute signal handlers */ - SDL_UninstallParachute(); + /* Uninstall any parachute signal handlers */ + SDL_UninstallParachute (); #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH - pth_kill(); + pth_kill (); #endif #ifdef DEBUG_BUILD - printf("[SDL_Quit] : Returning!\n"); fflush(stdout); + printf ("[SDL_Quit] : Returning!\n"); + fflush (stdout); #endif } -/* Return the library version number */ -const SDL_version * SDL_Linked_Version(void) +/* Get the library version number */ +void +SDL_GetVersion (SDL_version * ver) { - return(&version); + SDL_VERSION (ver); } #if defined(__OS2__) @@ -261,65 +266,63 @@ const SDL_version * SDL_Linked_Version(void) #include /* Exception handler to prevent the Audio thread hanging, making a zombie process! */ -ULONG _System SDL_Main_ExceptionHandler(PEXCEPTIONREPORTRECORD pERepRec, - PEXCEPTIONREGISTRATIONRECORD pERegRec, - PCONTEXTRECORD pCtxRec, - PVOID p) +ULONG _System +SDL_Main_ExceptionHandler (PEXCEPTIONREPORTRECORD pERepRec, + PEXCEPTIONREGISTRATIONRECORD pERegRec, + PCONTEXTRECORD pCtxRec, PVOID p) { - if (pERepRec->fHandlerFlags & EH_EXIT_UNWIND) - return XCPT_CONTINUE_SEARCH; - if (pERepRec->fHandlerFlags & EH_UNWINDING) - return XCPT_CONTINUE_SEARCH; - if (pERepRec->fHandlerFlags & EH_NESTED_CALL) - return XCPT_CONTINUE_SEARCH; - - /* Do cleanup at every fatal exception! */ - if (((pERepRec->ExceptionNum & XCPT_SEVERITY_CODE) == XCPT_FATAL_EXCEPTION) && - (pERepRec->ExceptionNum != XCPT_BREAKPOINT) && - (pERepRec->ExceptionNum != XCPT_SINGLE_STEP) - ) - { - if (SDL_initialized & SDL_INIT_AUDIO) - { - /* This removes the zombie audio thread in case of emergency. */ + if (pERepRec->fHandlerFlags & EH_EXIT_UNWIND) + return XCPT_CONTINUE_SEARCH; + if (pERepRec->fHandlerFlags & EH_UNWINDING) + return XCPT_CONTINUE_SEARCH; + if (pERepRec->fHandlerFlags & EH_NESTED_CALL) + return XCPT_CONTINUE_SEARCH; + + /* Do cleanup at every fatal exception! */ + if (((pERepRec->ExceptionNum & XCPT_SEVERITY_CODE) == + XCPT_FATAL_EXCEPTION) && (pERepRec->ExceptionNum != XCPT_BREAKPOINT) + && (pERepRec->ExceptionNum != XCPT_SINGLE_STEP)) { + if (SDL_initialized & SDL_INIT_AUDIO) { + /* This removes the zombie audio thread in case of emergency. */ #ifdef DEBUG_BUILD - printf("[SDL_Main_ExceptionHandler] : Calling SDL_CloseAudio()!\n"); + printf + ("[SDL_Main_ExceptionHandler] : Calling SDL_CloseAudio()!\n"); #endif - SDL_CloseAudio(); + SDL_CloseAudio (); + } } - } - return (XCPT_CONTINUE_SEARCH); + return (XCPT_CONTINUE_SEARCH); } -EXCEPTIONREGISTRATIONRECORD SDL_Main_xcpthand = {0, SDL_Main_ExceptionHandler}; +EXCEPTIONREGISTRATIONRECORD SDL_Main_xcpthand = + { 0, SDL_Main_ExceptionHandler }; /* The main DLL entry for DLL Initialization and Uninitialization: */ -unsigned _System LibMain(unsigned hmod, unsigned termination) +unsigned _System +LibMain (unsigned hmod, unsigned termination) { - if (termination) - { + if (termination) { #ifdef DEBUG_BUILD /* printf("[SDL DLL Unintialization] : Removing exception handler\n"); */ #endif - DosUnsetExceptionHandler(&SDL_Main_xcpthand); - return 1; - } else - { + DosUnsetExceptionHandler (&SDL_Main_xcpthand); + return 1; + } else { #ifdef DEBUG_BUILD - /* Make stdout and stderr unbuffered! */ - setbuf(stdout, NULL); - setbuf(stderr, NULL); + /* Make stdout and stderr unbuffered! */ + setbuf (stdout, NULL); + setbuf (stderr, NULL); #endif - /* Fire up exception handler */ + /* Fire up exception handler */ #ifdef DEBUG_BUILD /* printf("[SDL DLL Initialization] : Setting exception handler\n"); */ #endif - /* Set exception handler */ - DosSetExceptionHandler(&SDL_Main_xcpthand); + /* Set exception handler */ + DosSetExceptionHandler (&SDL_Main_xcpthand); - return 1; - } + return 1; + } } #endif /* __WATCOMC__ */ @@ -330,19 +333,20 @@ unsigned _System LibMain(unsigned hmod, unsigned termination) #define WIN32_LEAN_AND_MEAN #include -BOOL APIENTRY _DllMainCRTStartup( HANDLE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved ) +BOOL APIENTRY +_DllMainCRTStartup (HANDLE hModule, + DWORD ul_reason_for_call, LPVOID lpReserved) { - switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; } #endif /* building DLL with Watcom C */ #endif /* OS/2 elif __WIN32__ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL_error.c b/src/SDL_error.c index 11632f281..dea6931df 100644 --- a/src/SDL_error.c +++ b/src/SDL_error.c @@ -32,207 +32,224 @@ static SDL_error SDL_global_error; #define SDL_GetErrBuf() (&SDL_global_error) #else -extern SDL_error *SDL_GetErrBuf(void); +extern SDL_error *SDL_GetErrBuf (void); #endif /* SDL_THREADS_DISABLED */ #define SDL_ERRBUFIZE 1024 /* Private functions */ -static const char *SDL_LookupString(const char *key) +static const char * +SDL_LookupString (const char *key) { - /* FIXME: Add code to lookup key in language string hash-table */ - return key; + /* FIXME: Add code to lookup key in language string hash-table */ + return key; } /* Public functions */ -void SDL_SetError (const char *fmt, ...) +void +SDL_SetError (const char *fmt, ...) { - va_list ap; - SDL_error *error; - - /* Copy in the key, mark error as valid */ - error = SDL_GetErrBuf(); - error->error = 1; - SDL_strlcpy((char *)error->key, fmt, sizeof(error->key)); - - va_start(ap, fmt); - error->argc = 0; - while ( *fmt ) { - if ( *fmt++ == '%' ) { - while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) { - ++fmt; - } - switch (*fmt++) { - case 0: /* Malformed format string.. */ - --fmt; - break; - case 'c': - case 'i': - case 'd': - case 'u': - case 'o': - case 'x': - case 'X': - error->args[error->argc++].value_i = - va_arg(ap, int); - break; - case 'f': - error->args[error->argc++].value_f = - va_arg(ap, double); - break; - case 'p': - error->args[error->argc++].value_ptr = - va_arg(ap, void *); - break; - case 's': - { - int i = error->argc; - const char *str = va_arg(ap, const char *); - if (str == NULL) - str = "(null)"; - SDL_strlcpy((char *)error->args[i].buf, str, ERR_MAX_STRLEN); - error->argc++; - } - break; - default: - break; - } - if ( error->argc >= ERR_MAX_ARGS ) { - break; - } - } - } - va_end(ap); - - /* If we are in debug mode, print out an error message */ + va_list ap; + SDL_error *error; + + /* Copy in the key, mark error as valid */ + error = SDL_GetErrBuf (); + error->error = 1; + SDL_strlcpy ((char *) error->key, fmt, sizeof (error->key)); + + va_start (ap, fmt); + error->argc = 0; + while (*fmt) { + if (*fmt++ == '%') { + while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) { + ++fmt; + } + switch (*fmt++) { + case 0: /* Malformed format string.. */ + --fmt; + break; + case 'c': + case 'i': + case 'd': + case 'u': + case 'o': + case 'x': + case 'X': + error->args[error->argc++].value_i = va_arg (ap, int); + break; + case 'f': + error->args[error->argc++].value_f = va_arg (ap, double); + break; + case 'p': + error->args[error->argc++].value_ptr = va_arg (ap, void *); + break; + case 's': + { + int i = error->argc; + const char *str = va_arg (ap, const char *); + if (str == NULL) + str = "(null)"; + SDL_strlcpy ((char *) error->args[i].buf, str, + ERR_MAX_STRLEN); + error->argc++; + } + break; + default: + break; + } + if (error->argc >= ERR_MAX_ARGS) { + break; + } + } + } + va_end (ap); + + /* If we are in debug mode, print out an error message */ #ifdef DEBUG_ERROR - fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError()); + fprintf (stderr, "SDL_SetError: %s\n", SDL_GetError ()); #endif } /* This function has a bit more overhead than most error functions so that it supports internationalization and thread-safe errors. */ -char *SDL_GetErrorMsg(char *errstr, unsigned int maxlen) +char * +SDL_GetErrorMsg (char *errstr, unsigned int maxlen) { - SDL_error *error; - - /* Clear the error string */ - *errstr = '\0'; --maxlen; - - /* Get the thread-safe error, and print it out */ - error = SDL_GetErrBuf(); - if ( error->error ) { - const char *fmt; - char *msg = errstr; - int len; - int argi; - - fmt = SDL_LookupString(error->key); - argi = 0; - while ( *fmt && (maxlen > 0) ) { - if ( *fmt == '%' ) { - char tmp[32], *spot = tmp; - *spot++ = *fmt++; - while ( (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) && spot < (tmp+SDL_arraysize(tmp)-2) ) { - *spot++ = *fmt++; - } - *spot++ = *fmt++; - *spot++ = '\0'; - switch (spot[-2]) { - case '%': - *msg++ = '%'; - maxlen -= 1; - break; - case 'c': - case 'i': - case 'd': - case 'u': - case 'o': - case 'x': - case 'X': - len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_i); - msg += len; - maxlen -= len; - break; - case 'f': - len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_f); - msg += len; - maxlen -= len; - break; - case 'p': - len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_ptr); - msg += len; - maxlen -= len; - break; - case 's': - len = SDL_snprintf(msg, maxlen, tmp, SDL_LookupString(error->args[argi++].buf)); - msg += len; - maxlen -= len; - break; - } - } else { - *msg++ = *fmt++; - maxlen -= 1; - } - } - *msg = 0; /* NULL terminate the string */ - } - return(errstr); + SDL_error *error; + + /* Clear the error string */ + *errstr = '\0'; + --maxlen; + + /* Get the thread-safe error, and print it out */ + error = SDL_GetErrBuf (); + if (error->error) { + const char *fmt; + char *msg = errstr; + int len; + int argi; + + fmt = SDL_LookupString (error->key); + argi = 0; + while (*fmt && (maxlen > 0)) { + if (*fmt == '%') { + char tmp[32], *spot = tmp; + *spot++ = *fmt++; + while ((*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) + && spot < (tmp + SDL_arraysize (tmp) - 2)) { + *spot++ = *fmt++; + } + *spot++ = *fmt++; + *spot++ = '\0'; + switch (spot[-2]) { + case '%': + *msg++ = '%'; + maxlen -= 1; + break; + case 'c': + case 'i': + case 'd': + case 'u': + case 'o': + case 'x': + case 'X': + len = + SDL_snprintf (msg, maxlen, tmp, + error->args[argi++].value_i); + msg += len; + maxlen -= len; + break; + case 'f': + len = + SDL_snprintf (msg, maxlen, tmp, + error->args[argi++].value_f); + msg += len; + maxlen -= len; + break; + case 'p': + len = + SDL_snprintf (msg, maxlen, tmp, + error->args[argi++].value_ptr); + msg += len; + maxlen -= len; + break; + case 's': + len = + SDL_snprintf (msg, maxlen, tmp, + SDL_LookupString (error-> + args[argi++].buf)); + msg += len; + maxlen -= len; + break; + } + } else { + *msg++ = *fmt++; + maxlen -= 1; + } + } + *msg = 0; /* NULL terminate the string */ + } + return (errstr); } /* Available for backwards compatibility */ -char *SDL_GetError (void) +char * +SDL_GetError (void) { - static char errmsg[SDL_ERRBUFIZE]; + static char errmsg[SDL_ERRBUFIZE]; - return((char *)SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE)); + return ((char *) SDL_GetErrorMsg (errmsg, SDL_ERRBUFIZE)); } -void SDL_ClearError(void) +void +SDL_ClearError (void) { - SDL_error *error; + SDL_error *error; - error = SDL_GetErrBuf(); - error->error = 0; + error = SDL_GetErrBuf (); + error->error = 0; } /* Very common errors go here */ -void SDL_Error(SDL_errorcode code) +void +SDL_Error (SDL_errorcode code) { - switch (code) { - case SDL_ENOMEM: - SDL_SetError("Out of memory"); - break; - case SDL_EFREAD: - SDL_SetError("Error reading from datastream"); - break; - case SDL_EFWRITE: - SDL_SetError("Error writing to datastream"); - break; - case SDL_EFSEEK: - SDL_SetError("Error seeking in datastream"); - break; - default: - SDL_SetError("Unknown SDL error"); - break; - } + switch (code) { + case SDL_ENOMEM: + SDL_SetError ("Out of memory"); + break; + case SDL_EFREAD: + SDL_SetError ("Error reading from datastream"); + break; + case SDL_EFWRITE: + SDL_SetError ("Error writing to datastream"); + break; + case SDL_EFSEEK: + SDL_SetError ("Error seeking in datastream"); + break; + default: + SDL_SetError ("Unknown SDL error"); + break; + } } #ifdef TEST_ERROR -int main(int argc, char *argv[]) +int +main (int argc, char *argv[]) { - char buffer[BUFSIZ+1]; - - SDL_SetError("Hi there!"); - printf("Error 1: %s\n", SDL_GetError()); - SDL_ClearError(); - SDL_memset(buffer, '1', BUFSIZ); - buffer[BUFSIZ] = 0; - SDL_SetError("This is the error: %s (%f)", buffer, 1.0); - printf("Error 2: %s\n", SDL_GetError()); - exit(0); + char buffer[BUFSIZ + 1]; + + SDL_SetError ("Hi there!"); + printf ("Error 1: %s\n", SDL_GetError ()); + SDL_ClearError (); + SDL_memset (buffer, '1', BUFSIZ); + buffer[BUFSIZ] = 0; + SDL_SetError ("This is the error: %s (%f)", buffer, 1.0); + printf ("Error 2: %s\n", SDL_GetError ()); + exit (0); } #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL_error_c.h b/src/SDL_error_c.h index 990acb56b..f0afff10a 100644 --- a/src/SDL_error_c.h +++ b/src/SDL_error_c.h @@ -31,28 +31,31 @@ #define ERR_MAX_STRLEN 128 #define ERR_MAX_ARGS 5 -typedef struct SDL_error { - /* This is a numeric value corresponding to the current error */ - int error; - - /* This is a key used to index into a language hashtable containing - internationalized versions of the SDL error messages. If the key - is not in the hashtable, or no hashtable is available, the key is - used directly as an error message format string. - */ - char key[ERR_MAX_STRLEN]; - - /* These are the arguments for the error functions */ - int argc; - union { - void *value_ptr; -#if 0 /* What is a character anyway? (UNICODE issues) */ - unsigned char value_c; +typedef struct SDL_error +{ + /* This is a numeric value corresponding to the current error */ + int error; + + /* This is a key used to index into a language hashtable containing + internationalized versions of the SDL error messages. If the key + is not in the hashtable, or no hashtable is available, the key is + used directly as an error message format string. + */ + char key[ERR_MAX_STRLEN]; + + /* These are the arguments for the error functions */ + int argc; + union + { + void *value_ptr; +#if 0 /* What is a character anyway? (UNICODE issues) */ + unsigned char value_c; #endif - int value_i; - double value_f; - char buf[ERR_MAX_STRLEN]; - } args[ERR_MAX_ARGS]; + int value_i; + double value_f; + char buf[ERR_MAX_STRLEN]; + } args[ERR_MAX_ARGS]; } SDL_error; #endif /* _SDL_error_c_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL_fatal.c b/src/SDL_fatal.c index 784836b9f..c450fdb3e 100644 --- a/src/SDL_fatal.c +++ b/src/SDL_fatal.c @@ -35,85 +35,88 @@ the program crashes. */ -static void SDL_Parachute(int sig) +static void +SDL_Parachute (int sig) { - signal(sig, SIG_DFL); - SDL_Quit(); - raise(sig); + signal (sig, SIG_DFL); + SDL_Quit (); + raise (sig); } static int SDL_fatal_signals[] = { - SIGSEGV, + SIGSEGV, #ifdef SIGBUS - SIGBUS, + SIGBUS, #endif #ifdef SIGFPE - SIGFPE, + SIGFPE, #endif #ifdef SIGQUIT - SIGQUIT, + SIGQUIT, #endif - 0 + 0 }; -void SDL_InstallParachute(void) +void +SDL_InstallParachute (void) { - /* Set a handler for any fatal signal not already handled */ - int i; + /* Set a handler for any fatal signal not already handled */ + int i; #ifdef HAVE_SIGACTION - struct sigaction action; - - for ( i=0; SDL_fatal_signals[i]; ++i ) { - sigaction(SDL_fatal_signals[i], NULL, &action); - if ( action.sa_handler == SIG_DFL ) { - action.sa_handler = SDL_Parachute; - sigaction(SDL_fatal_signals[i], &action, NULL); - } - } + struct sigaction action; + + for (i = 0; SDL_fatal_signals[i]; ++i) { + sigaction (SDL_fatal_signals[i], NULL, &action); + if (action.sa_handler == SIG_DFL) { + action.sa_handler = SDL_Parachute; + sigaction (SDL_fatal_signals[i], &action, NULL); + } + } #ifdef SIGALRM - /* Set SIGALRM to be ignored -- necessary on Solaris */ - sigaction(SIGALRM, NULL, &action); - if ( action.sa_handler == SIG_DFL ) { - action.sa_handler = SIG_IGN; - sigaction(SIGALRM, &action, NULL); - } + /* Set SIGALRM to be ignored -- necessary on Solaris */ + sigaction (SIGALRM, NULL, &action); + if (action.sa_handler == SIG_DFL) { + action.sa_handler = SIG_IGN; + sigaction (SIGALRM, &action, NULL); + } #endif #else - void (*ohandler)(int); - - for ( i=0; SDL_fatal_signals[i]; ++i ) { - ohandler = signal(SDL_fatal_signals[i], SDL_Parachute); - if ( ohandler != SIG_DFL ) { - signal(SDL_fatal_signals[i], ohandler); - } - } + void (*ohandler) (int); + + for (i = 0; SDL_fatal_signals[i]; ++i) { + ohandler = signal (SDL_fatal_signals[i], SDL_Parachute); + if (ohandler != SIG_DFL) { + signal (SDL_fatal_signals[i], ohandler); + } + } #endif /* HAVE_SIGACTION */ - return; + return; } -void SDL_UninstallParachute(void) +void +SDL_UninstallParachute (void) { - /* Remove a handler for any fatal signal handled */ - int i; + /* Remove a handler for any fatal signal handled */ + int i; #ifdef HAVE_SIGACTION - struct sigaction action; - - for ( i=0; SDL_fatal_signals[i]; ++i ) { - sigaction(SDL_fatal_signals[i], NULL, &action); - if ( action.sa_handler == SDL_Parachute ) { - action.sa_handler = SIG_DFL; - sigaction(SDL_fatal_signals[i], &action, NULL); - } - } + struct sigaction action; + + for (i = 0; SDL_fatal_signals[i]; ++i) { + sigaction (SDL_fatal_signals[i], NULL, &action); + if (action.sa_handler == SDL_Parachute) { + action.sa_handler = SIG_DFL; + sigaction (SDL_fatal_signals[i], &action, NULL); + } + } #else - void (*ohandler)(int); - - for ( i=0; SDL_fatal_signals[i]; ++i ) { - ohandler = signal(SDL_fatal_signals[i], SIG_DFL); - if ( ohandler != SDL_Parachute ) { - signal(SDL_fatal_signals[i], ohandler); - } - } + void (*ohandler) (int); + + for (i = 0; SDL_fatal_signals[i]; ++i) { + ohandler = signal (SDL_fatal_signals[i], SIG_DFL); + if (ohandler != SDL_Parachute) { + signal (SDL_fatal_signals[i], ohandler); + } + } #endif /* HAVE_SIGACTION */ } @@ -121,14 +124,17 @@ void SDL_UninstallParachute(void) /* No signals on this platform, nothing to do.. */ -void SDL_InstallParachute(void) +void +SDL_InstallParachute (void) { - return; + return; } -void SDL_UninstallParachute(void) +void +SDL_UninstallParachute (void) { - return; + return; } #endif /* HAVE_SIGNAL_H */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL_fatal.h b/src/SDL_fatal.h index 34b60690c..3159d97dc 100644 --- a/src/SDL_fatal.h +++ b/src/SDL_fatal.h @@ -23,6 +23,6 @@ /* General fatal signal handling code for SDL */ -extern void SDL_InstallParachute(void); -extern void SDL_UninstallParachute(void); - +extern void SDL_InstallParachute (void); +extern void SDL_UninstallParachute (void); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 111433582..9dfa03700 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -37,737 +37,767 @@ /* Available audio drivers */ static AudioBootStrap *bootstrap[] = { #if SDL_AUDIO_DRIVER_BSD - &BSD_AUDIO_bootstrap, + &BSD_AUDIO_bootstrap, #endif #if SDL_AUDIO_DRIVER_OSS - &DSP_bootstrap, - &DMA_bootstrap, + &DSP_bootstrap, + &DMA_bootstrap, #endif #if SDL_AUDIO_DRIVER_ALSA - &ALSA_bootstrap, + &ALSA_bootstrap, #endif #if SDL_AUDIO_DRIVER_QNXNTO - &QNXNTOAUDIO_bootstrap, + &QNXNTOAUDIO_bootstrap, #endif #if SDL_AUDIO_DRIVER_SUNAUDIO - &SUNAUDIO_bootstrap, + &SUNAUDIO_bootstrap, #endif #if SDL_AUDIO_DRIVER_DMEDIA - &DMEDIA_bootstrap, + &DMEDIA_bootstrap, #endif #if SDL_AUDIO_DRIVER_ARTS - &ARTS_bootstrap, + &ARTS_bootstrap, #endif #if SDL_AUDIO_DRIVER_ESD - &ESD_bootstrap, + &ESD_bootstrap, #endif #if SDL_AUDIO_DRIVER_NAS - &NAS_bootstrap, + &NAS_bootstrap, #endif #if SDL_AUDIO_DRIVER_DSOUND - &DSOUND_bootstrap, + &DSOUND_bootstrap, #endif #if SDL_AUDIO_DRIVER_WAVEOUT - &WAVEOUT_bootstrap, + &WAVEOUT_bootstrap, #endif #if SDL_AUDIO_DRIVER_PAUD - &Paud_bootstrap, + &Paud_bootstrap, #endif #if SDL_AUDIO_DRIVER_BAUDIO - &BAUDIO_bootstrap, + &BAUDIO_bootstrap, #endif #if SDL_AUDIO_DRIVER_COREAUDIO - &COREAUDIO_bootstrap, + &COREAUDIO_bootstrap, #endif #if SDL_AUDIO_DRIVER_SNDMGR - &SNDMGR_bootstrap, + &SNDMGR_bootstrap, #endif #if SDL_AUDIO_DRIVER_AHI - &AHI_bootstrap, + &AHI_bootstrap, #endif #if SDL_AUDIO_DRIVER_MINT - &MINTAUDIO_GSXB_bootstrap, - &MINTAUDIO_MCSN_bootstrap, - &MINTAUDIO_STFA_bootstrap, - &MINTAUDIO_XBIOS_bootstrap, - &MINTAUDIO_DMA8_bootstrap, + &MINTAUDIO_GSXB_bootstrap, + &MINTAUDIO_MCSN_bootstrap, + &MINTAUDIO_STFA_bootstrap, + &MINTAUDIO_XBIOS_bootstrap, + &MINTAUDIO_DMA8_bootstrap, #endif #if SDL_AUDIO_DRIVER_DISK - &DISKAUD_bootstrap, + &DISKAUD_bootstrap, #endif #if SDL_AUDIO_DRIVER_DUMMY - &DUMMYAUD_bootstrap, + &DUMMYAUD_bootstrap, #endif #if SDL_AUDIO_DRIVER_DC - &DCAUD_bootstrap, + &DCAUD_bootstrap, #endif #if SDL_AUDIO_DRIVER_MMEAUDIO - &MMEAUDIO_bootstrap, + &MMEAUDIO_bootstrap, #endif #if SDL_AUDIO_DRIVER_DART - &DART_bootstrap, + &DART_bootstrap, #endif - NULL + NULL }; SDL_AudioDevice *current_audio = NULL; /* Various local functions */ -int SDL_AudioInit(const char *driver_name); -void SDL_AudioQuit(void); +int SDL_AudioInit (const char *driver_name); +void SDL_AudioQuit (void); #if SDL_AUDIO_DRIVER_AHI static int audio_configured = 0; #endif /* The general mixing thread function */ -int SDLCALL SDL_RunAudio(void *audiop) +int SDLCALL +SDL_RunAudio (void *audiop) { - SDL_AudioDevice *audio = (SDL_AudioDevice *)audiop; - Uint8 *stream; - int stream_len; - void *udata; - void (SDLCALL *fill)(void *userdata,Uint8 *stream, int len); - int silence; + SDL_AudioDevice *audio = (SDL_AudioDevice *) audiop; + Uint8 *stream; + int stream_len; + void *udata; + void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len); + int silence; #if SDL_AUDIO_DRIVER_AHI - int started = 0; + int started = 0; /* AmigaOS NEEDS that the audio driver is opened in the thread that uses it! */ - D(bug("Task audio started audio struct:<%lx>...\n",audiop)); + D (bug ("Task audio started audio struct:<%lx>...\n", audiop)); - D(bug("Before Openaudio...")); - if(audio->OpenAudio(audio, &audio->spec)==-1) - { - D(bug("Open audio failed...\n")); - return(-1); - } - D(bug("OpenAudio...OK\n")); + D (bug ("Before Openaudio...")); + if (audio->OpenAudio (audio, &audio->spec) == -1) { + D (bug ("Open audio failed...\n")); + return (-1); + } + D (bug ("OpenAudio...OK\n")); #endif - /* Perform any thread setup */ - if ( audio->ThreadInit ) { - audio->ThreadInit(audio); - } - audio->threadid = SDL_ThreadID(); + /* Perform any thread setup */ + if (audio->ThreadInit) { + audio->ThreadInit (audio); + } + audio->threadid = SDL_ThreadID (); - /* Set up the mixing function */ - fill = audio->spec.callback; - udata = audio->spec.userdata; + /* Set up the mixing function */ + fill = audio->spec.callback; + udata = audio->spec.userdata; #if SDL_AUDIO_DRIVER_AHI - audio_configured = 1; + audio_configured = 1; - D(bug("Audio configured... Checking for conversion\n")); - SDL_mutexP(audio->mixer_lock); - D(bug("Semaphore obtained...\n")); + D (bug ("Audio configured... Checking for conversion\n")); + SDL_mutexP (audio->mixer_lock); + D (bug ("Semaphore obtained...\n")); #endif - if ( audio->convert.needed ) { - if ( audio->convert.src_format == AUDIO_U8 ) { - silence = 0x80; - } else { - silence = 0; - } - stream_len = audio->convert.len; - } else { - silence = audio->spec.silence; - stream_len = audio->spec.size; - } + if (audio->convert.needed) { + if (audio->convert.src_format == AUDIO_U8) { + silence = 0x80; + } else { + silence = 0; + } + stream_len = audio->convert.len; + } else { + silence = audio->spec.silence; + stream_len = audio->spec.size; + } #if SDL_AUDIO_DRIVER_AHI - SDL_mutexV(audio->mixer_lock); - D(bug("Entering audio loop...\n")); + SDL_mutexV (audio->mixer_lock); + D (bug ("Entering audio loop...\n")); #endif #ifdef __OS2__ - /* Increase the priority of this thread to make sure that - the audio will be continuous all the time! */ + /* Increase the priority of this thread to make sure that + the audio will be continuous all the time! */ #ifdef USE_DOSSETPRIORITY - if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) - { + if (SDL_getenv ("SDL_USE_TIMECRITICAL_AUDIO")) { #ifdef DEBUG_BUILD - printf("[SDL_RunAudio] : Setting priority to TimeCritical+0! (TID%d)\n", SDL_ThreadID()); + printf + ("[SDL_RunAudio] : Setting priority to TimeCritical+0! (TID%d)\n", + SDL_ThreadID ()); #endif - DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); - } - else - { + DosSetPriority (PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); + } else { #ifdef DEBUG_BUILD - printf("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n", SDL_ThreadID()); -#endif - DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0); + printf + ("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n", + SDL_ThreadID ()); +#endif + DosSetPriority (PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0); + } +#endif +#endif + + /* Loop, filling the audio buffers */ + while (audio->enabled) { + + /* Fill the current buffer with sound */ + if (audio->convert.needed) { + if (audio->convert.buf) { + stream = audio->convert.buf; + } else { + continue; + } + } else { + stream = audio->GetAudioBuf (audio); + if (stream == NULL) { + stream = audio->fake_stream; + } + } + SDL_memset (stream, silence, stream_len); + + if (!audio->paused) { + SDL_mutexP (audio->mixer_lock); + (*fill) (udata, stream, stream_len); + SDL_mutexV (audio->mixer_lock); + } + + /* Convert the audio if necessary */ + if (audio->convert.needed) { + SDL_ConvertAudio (&audio->convert); + stream = audio->GetAudioBuf (audio); + if (stream == NULL) { + stream = audio->fake_stream; + } + SDL_memcpy (stream, audio->convert.buf, audio->convert.len_cvt); } -#endif -#endif - /* Loop, filling the audio buffers */ - while ( audio->enabled ) { - - /* Fill the current buffer with sound */ - if ( audio->convert.needed ) { - if ( audio->convert.buf ) { - stream = audio->convert.buf; - } else { - continue; - } - } else { - stream = audio->GetAudioBuf(audio); - if ( stream == NULL ) { - stream = audio->fake_stream; - } - } - SDL_memset(stream, silence, stream_len); - - if ( ! audio->paused ) { - SDL_mutexP(audio->mixer_lock); - (*fill)(udata, stream, stream_len); - SDL_mutexV(audio->mixer_lock); - } - - /* Convert the audio if necessary */ - if ( audio->convert.needed ) { - SDL_ConvertAudio(&audio->convert); - stream = audio->GetAudioBuf(audio); - if ( stream == NULL ) { - stream = audio->fake_stream; - } - SDL_memcpy(stream, audio->convert.buf, - audio->convert.len_cvt); - } - - /* Ready current buffer for play and change current buffer */ - if ( stream != audio->fake_stream ) { - audio->PlayAudio(audio); - } - - /* Wait for an audio buffer to become available */ - if ( stream == audio->fake_stream ) { - SDL_Delay((audio->spec.samples*1000)/audio->spec.freq); - } else { - audio->WaitAudio(audio); - } - } - - /* Wait for the audio to drain.. */ - if ( audio->WaitDone ) { - audio->WaitDone(audio); - } + /* Ready current buffer for play and change current buffer */ + if (stream != audio->fake_stream) { + audio->PlayAudio (audio); + } + + /* Wait for an audio buffer to become available */ + if (stream == audio->fake_stream) { + SDL_Delay ((audio->spec.samples * 1000) / audio->spec.freq); + } else { + audio->WaitAudio (audio); + } + } + /* Wait for the audio to drain.. */ + if (audio->WaitDone) { + audio->WaitDone (audio); + } #if SDL_AUDIO_DRIVER_AHI - D(bug("WaitAudio...Done\n")); + D (bug ("WaitAudio...Done\n")); - audio->CloseAudio(audio); + audio->CloseAudio (audio); - D(bug("CloseAudio..Done, subtask exiting...\n")); - audio_configured = 0; + D (bug ("CloseAudio..Done, subtask exiting...\n")); + audio_configured = 0; #endif #ifdef __OS2__ #ifdef DEBUG_BUILD - printf("[SDL_RunAudio] : Task exiting. (TID%d)\n", SDL_ThreadID()); + printf ("[SDL_RunAudio] : Task exiting. (TID%d)\n", SDL_ThreadID ()); #endif #endif - return(0); + return (0); } -static void SDL_LockAudio_Default(SDL_AudioDevice *audio) +static void +SDL_LockAudio_Default (SDL_AudioDevice * audio) { - if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) { - return; - } - SDL_mutexP(audio->mixer_lock); + if (audio->thread && (SDL_ThreadID () == audio->threadid)) { + return; + } + SDL_mutexP (audio->mixer_lock); } -static void SDL_UnlockAudio_Default(SDL_AudioDevice *audio) +static void +SDL_UnlockAudio_Default (SDL_AudioDevice * audio) { - if ( audio->thread && (SDL_ThreadID() == audio->threadid) ) { - return; - } - SDL_mutexV(audio->mixer_lock); + if (audio->thread && (SDL_ThreadID () == audio->threadid)) { + return; + } + SDL_mutexV (audio->mixer_lock); } -static Uint16 SDL_ParseAudioFormat(const char *string) +static Uint16 +SDL_ParseAudioFormat (const char *string) { - Uint16 format = 0; - - switch (*string) { - case 'U': - ++string; - format |= 0x0000; - break; - case 'S': - ++string; - format |= 0x8000; - break; - default: - return 0; - } - switch (SDL_atoi(string)) { - case 8: - string += 1; - format |= 8; - break; - case 16: - string += 2; - format |= 16; - if ( SDL_strcmp(string, "LSB") == 0 + Uint16 format = 0; + + switch (*string) { + case 'U': + ++string; + format |= 0x0000; + break; + case 'S': + ++string; + format |= 0x8000; + break; + default: + return 0; + } + switch (SDL_atoi (string)) { + case 8: + string += 1; + format |= 8; + break; + case 16: + string += 2; + format |= 16; + if (SDL_strcmp (string, "LSB") == 0 #if SDL_BYTEORDER == SDL_LIL_ENDIAN - || SDL_strcmp(string, "SYS") == 0 + || SDL_strcmp (string, "SYS") == 0 #endif - ) { - format |= 0x0000; - } - if ( SDL_strcmp(string, "MSB") == 0 + ) { + format |= 0x0000; + } + if (SDL_strcmp (string, "MSB") == 0 #if SDL_BYTEORDER == SDL_BIG_ENDIAN - || SDL_strcmp(string, "SYS") == 0 -#endif - ) { - format |= 0x1000; - } - break; - default: - return 0; - } - return format; + || SDL_strcmp (string, "SYS") == 0 +#endif + ) { + format |= 0x1000; + } + break; + default: + return 0; + } + return format; } -int SDL_GetNumAudioDrivers(void) +int +SDL_GetNumAudioDrivers (void) { - return(SDL_arraysize(bootstrap)-1); + return (SDL_arraysize (bootstrap) - 1); } -const char *SDL_GetAudioDriver(int index) +const char * +SDL_GetAudioDriver (int index) { - if ( index >= 0 && index < SDL_GetNumAudioDrivers() ) { - return(bootstrap[index]->name); - } - return(NULL); + if (index >= 0 && index < SDL_GetNumAudioDrivers ()) { + return (bootstrap[index]->name); + } + return (NULL); } -int SDL_AudioInit(const char *driver_name) +int +SDL_AudioInit (const char *driver_name) { - SDL_AudioDevice *audio; - int i = 0, idx; + SDL_AudioDevice *audio; + int i = 0, idx; - /* Check to make sure we don't overwrite 'current_audio' */ - if ( current_audio != NULL ) { - SDL_AudioQuit(); - } + /* Check to make sure we don't overwrite 'current_audio' */ + if (current_audio != NULL) { + SDL_AudioQuit (); + } - /* Select the proper audio driver */ - audio = NULL; - idx = 0; + /* Select the proper audio driver */ + audio = NULL; + idx = 0; #if SDL_AUDIO_DRIVER_ESD - if ( (driver_name == NULL) && (SDL_getenv("ESPEAKER") != NULL) ) { - /* Ahem, we know that if ESPEAKER is set, user probably wants - to use ESD, but don't start it if it's not already running. - This probably isn't the place to do this, but... Shh! :) - */ - for ( i=0; bootstrap[i]; ++i ) { - if ( SDL_strcmp(bootstrap[i]->name, "esd") == 0 ) { + if ((driver_name == NULL) && (SDL_getenv ("ESPEAKER") != NULL)) { + /* Ahem, we know that if ESPEAKER is set, user probably wants + to use ESD, but don't start it if it's not already running. + This probably isn't the place to do this, but... Shh! :) + */ + for (i = 0; bootstrap[i]; ++i) { + if (SDL_strcmp (bootstrap[i]->name, "esd") == 0) { #ifdef HAVE_PUTENV - const char *esd_no_spawn; - - /* Don't start ESD if it's not running */ - esd_no_spawn = getenv("ESD_NO_SPAWN"); - if ( esd_no_spawn == NULL ) { - putenv("ESD_NO_SPAWN=1"); - } -#endif - if ( bootstrap[i]->available() ) { - audio = bootstrap[i]->create(0); - break; - } + const char *esd_no_spawn; + + /* Don't start ESD if it's not running */ + esd_no_spawn = getenv ("ESD_NO_SPAWN"); + if (esd_no_spawn == NULL) { + putenv ("ESD_NO_SPAWN=1"); + } +#endif + if (bootstrap[i]->available ()) { + audio = bootstrap[i]->create (0); + break; + } #ifdef HAVE_UNSETENV - if ( esd_no_spawn == NULL ) { - unsetenv("ESD_NO_SPAWN"); - } + if (esd_no_spawn == NULL) { + unsetenv ("ESD_NO_SPAWN"); + } #endif - } - } - } + } + } + } #endif /* SDL_AUDIO_DRIVER_ESD */ - if ( audio == NULL ) { - if ( driver_name != NULL ) { -#if 0 /* This will be replaced with a better driver selection API */ - if ( SDL_strrchr(driver_name, ':') != NULL ) { - idx = atoi(SDL_strrchr(driver_name, ':')+1); - } -#endif - for ( i=0; bootstrap[i]; ++i ) { - if (SDL_strncmp(bootstrap[i]->name, driver_name, - SDL_strlen(bootstrap[i]->name)) == 0) { - if ( bootstrap[i]->available() ) { - audio=bootstrap[i]->create(idx); - break; - } - } - } - } else { - for ( i=0; bootstrap[i]; ++i ) { - if ( bootstrap[i]->available() ) { - audio = bootstrap[i]->create(idx); - if ( audio != NULL ) { - break; - } - } - } - } - if ( audio == NULL ) { - SDL_SetError("No available audio device"); -#if 0 /* Don't fail SDL_Init() if audio isn't available. - SDL_OpenAudio() will handle it at that point. *sigh* - */ - return(-1); -#endif - } - } - current_audio = audio; - if ( current_audio ) { - current_audio->name = bootstrap[i]->name; - if ( !current_audio->LockAudio && !current_audio->UnlockAudio ) { - current_audio->LockAudio = SDL_LockAudio_Default; - current_audio->UnlockAudio = SDL_UnlockAudio_Default; - } - } - return(0); + if (audio == NULL) { + if (driver_name != NULL) { +#if 0 /* This will be replaced with a better driver selection API */ + if (SDL_strrchr (driver_name, ':') != NULL) { + idx = atoi (SDL_strrchr (driver_name, ':') + 1); + } +#endif + for (i = 0; bootstrap[i]; ++i) { + if (SDL_strncmp (bootstrap[i]->name, driver_name, + SDL_strlen (bootstrap[i]->name)) == 0) { + if (bootstrap[i]->available ()) { + audio = bootstrap[i]->create (idx); + } + break; + } + } + } else { + for (i = 0; bootstrap[i]; ++i) { + if (bootstrap[i]->available ()) { + audio = bootstrap[i]->create (idx); + if (audio != NULL) { + break; + } + } + } + } + if (audio == NULL) { + if (driver_name) { + SDL_SetError ("%s not available", driver_name); + } else { + SDL_SetError ("No available audio device"); + } +#if 0 /* Don't fail SDL_Init() if audio isn't available. + SDL_OpenAudio() will handle it at that point. *sigh* + */ + return (-1); +#endif + } + } + current_audio = audio; + if (current_audio) { + current_audio->name = bootstrap[i]->name; + if (!current_audio->LockAudio && !current_audio->UnlockAudio) { + current_audio->LockAudio = SDL_LockAudio_Default; + current_audio->UnlockAudio = SDL_UnlockAudio_Default; + } + } + return (0); } -const char *SDL_GetCurrentAudioDriver() +/* + * Get the current audio driver name + */ +const char * +SDL_GetCurrentAudioDriver () { - if ( current_audio ) { - return current_audio->name; - } - return(NULL); + if (current_audio) { + return current_audio->name; + } + return (NULL); } -int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) +int +SDL_OpenAudio (SDL_AudioSpec * desired, SDL_AudioSpec * obtained) { - SDL_AudioDevice *audio; - const char *env; - - /* Start up the audio driver, if necessary */ - if ( ! current_audio ) { - if ( (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) || - (current_audio == NULL) ) { - return(-1); - } - } - audio = current_audio; - - if (audio->opened) { - SDL_SetError("Audio device is already opened"); - return(-1); - } - - /* Verify some parameters */ - if ( desired->freq == 0 ) { - env = SDL_getenv("SDL_AUDIO_FREQUENCY"); - if ( env ) { - desired->freq = SDL_atoi(env); - } - } - if ( desired->freq == 0 ) { - /* Pick some default audio frequency */ - desired->freq = 22050; - } - if ( desired->format == 0 ) { - env = SDL_getenv("SDL_AUDIO_FORMAT"); - if ( env ) { - desired->format = SDL_ParseAudioFormat(env); - } - } - if ( desired->format == 0 ) { - /* Pick some default audio format */ - desired->format = AUDIO_S16; - } - if ( desired->channels == 0 ) { - env = SDL_getenv("SDL_AUDIO_CHANNELS"); - if ( env ) { - desired->channels = SDL_atoi(env); - } - } - if ( desired->channels == 0 ) { - /* Pick a default number of channels */ - desired->channels = 2; - } - switch ( desired->channels ) { - case 1: /* Mono */ - case 2: /* Stereo */ - case 4: /* surround */ - case 6: /* surround with center and lfe */ - break; - default: - SDL_SetError("1 (mono) and 2 (stereo) channels supported"); - return(-1); - } - if ( desired->samples == 0 ) { - env = SDL_getenv("SDL_AUDIO_SAMPLES"); - if ( env ) { - desired->samples = SDL_atoi(env); - } - } - if ( desired->samples == 0 ) { - /* Pick a default of ~46 ms at desired frequency */ - int samples = (desired->freq / 1000) * 46; - int power2 = 1; - while ( power2 < samples ) { - power2 *= 2; - } - desired->samples = power2; - } - if ( desired->callback == NULL ) { - SDL_SetError("SDL_OpenAudio() passed a NULL callback"); - return(-1); - } - + SDL_AudioDevice *audio; + const char *env; + + /* Start up the audio driver, if necessary */ + if (!current_audio) { + if ((SDL_InitSubSystem (SDL_INIT_AUDIO) < 0) || + (current_audio == NULL)) { + return (-1); + } + } + audio = current_audio; + + if (audio->opened) { + SDL_SetError ("Audio device is already opened"); + return (-1); + } + + /* Verify some parameters */ + if (desired->freq == 0) { + env = SDL_getenv ("SDL_AUDIO_FREQUENCY"); + if (env) { + desired->freq = SDL_atoi (env); + } + } + if (desired->freq == 0) { + /* Pick some default audio frequency */ + desired->freq = 22050; + } + if (desired->format == 0) { + env = SDL_getenv ("SDL_AUDIO_FORMAT"); + if (env) { + desired->format = SDL_ParseAudioFormat (env); + } + } + if (desired->format == 0) { + /* Pick some default audio format */ + desired->format = AUDIO_S16; + } + if (desired->channels == 0) { + env = SDL_getenv ("SDL_AUDIO_CHANNELS"); + if (env) { + desired->channels = SDL_atoi (env); + } + } + if (desired->channels == 0) { + /* Pick a default number of channels */ + desired->channels = 2; + } + switch (desired->channels) { + case 1: /* Mono */ + case 2: /* Stereo */ + case 4: /* surround */ + case 6: /* surround with center and lfe */ + break; + default: + SDL_SetError ("1 (mono) and 2 (stereo) channels supported"); + return (-1); + } + if (desired->samples == 0) { + env = SDL_getenv ("SDL_AUDIO_SAMPLES"); + if (env) { + desired->samples = SDL_atoi (env); + } + } + if (desired->samples == 0) { + /* Pick a default of ~46 ms at desired frequency */ + int samples = (desired->freq / 1000) * 46; + int power2 = 1; + while (power2 < samples) { + power2 *= 2; + } + desired->samples = power2; + } + if (desired->callback == NULL) { + SDL_SetError ("SDL_OpenAudio() passed a NULL callback"); + return (-1); + } #if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED) - /* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */ + /* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */ #else #if defined(__MINT__) && SDL_THREADS_DISABLED - /* Uses interrupt driven audio, without thread */ + /* Uses interrupt driven audio, without thread */ #else - /* Create a semaphore for locking the sound buffers */ - audio->mixer_lock = SDL_CreateMutex(); - if ( audio->mixer_lock == NULL ) { - SDL_SetError("Couldn't create mixer lock"); - SDL_CloseAudio(); - return(-1); - } + /* Create a semaphore for locking the sound buffers */ + audio->mixer_lock = SDL_CreateMutex (); + if (audio->mixer_lock == NULL) { + SDL_SetError ("Couldn't create mixer lock"); + SDL_CloseAudio (); + return (-1); + } #endif /* __MINT__ */ #endif /* __MACOS__ */ - /* Calculate the silence and size of the audio specification */ - SDL_CalculateAudioSpec(desired); + /* Calculate the silence and size of the audio specification */ + SDL_CalculateAudioSpec (desired); - /* Open the audio subsystem */ - SDL_memcpy(&audio->spec, desired, sizeof(audio->spec)); - audio->convert.needed = 0; - audio->enabled = 1; - audio->paused = 1; + /* Open the audio subsystem */ + SDL_memcpy (&audio->spec, desired, sizeof (audio->spec)); + audio->convert.needed = 0; + audio->enabled = 1; + audio->paused = 1; #if !SDL_AUDIO_DRIVER_AHI /* AmigaOS opens audio inside the main loop */ - audio->opened = audio->OpenAudio(audio, &audio->spec)+1; + audio->opened = audio->OpenAudio (audio, &audio->spec) + 1; - if ( ! audio->opened ) { - SDL_CloseAudio(); - return(-1); - } + if (!audio->opened) { + SDL_CloseAudio (); + return (-1); + } #else - D(bug("Locking semaphore...")); - SDL_mutexP(audio->mixer_lock); - - - audio->thread = SDL_CreateThread(SDL_RunAudio, audio); - D(bug("Created thread...\n")); - - if ( audio->thread == NULL ) { - SDL_mutexV(audio->mixer_lock); - SDL_CloseAudio(); - SDL_SetError("Couldn't create audio thread"); - return(-1); - } - - while(!audio_configured) - SDL_Delay(100); -#endif - - /* If the audio driver changes the buffer size, accept it */ - if ( audio->spec.samples != desired->samples ) { - desired->samples = audio->spec.samples; - SDL_CalculateAudioSpec(desired); - } - - /* Allocate a fake audio memory buffer */ - audio->fake_stream = SDL_AllocAudioMem(audio->spec.size); - if ( audio->fake_stream == NULL ) { - SDL_CloseAudio(); - SDL_OutOfMemory(); - return(-1); - } - - /* See if we need to do any conversion */ - if ( obtained != NULL ) { - SDL_memcpy(obtained, &audio->spec, sizeof(audio->spec)); - } else if ( desired->freq != audio->spec.freq || - desired->format != audio->spec.format || - desired->channels != audio->spec.channels ) { - /* Build an audio conversion block */ - if ( SDL_BuildAudioCVT(&audio->convert, - desired->format, desired->channels, - desired->freq, - audio->spec.format, audio->spec.channels, - audio->spec.freq) < 0 ) { - SDL_CloseAudio(); - return(-1); - } - if ( audio->convert.needed ) { - audio->convert.len = desired->size; - audio->convert.buf =(Uint8 *)SDL_AllocAudioMem( - audio->convert.len*audio->convert.len_mult); - if ( audio->convert.buf == NULL ) { - SDL_CloseAudio(); - SDL_OutOfMemory(); - return(-1); - } - } - } - + D (bug ("Locking semaphore...")); + SDL_mutexP (audio->mixer_lock); + + + audio->thread = SDL_CreateThread (SDL_RunAudio, audio); + D (bug ("Created thread...\n")); + + if (audio->thread == NULL) { + SDL_mutexV (audio->mixer_lock); + SDL_CloseAudio (); + SDL_SetError ("Couldn't create audio thread"); + return (-1); + } + + while (!audio_configured) + SDL_Delay (100); +#endif + + /* If the audio driver changes the buffer size, accept it */ + if (audio->spec.samples != desired->samples) { + desired->samples = audio->spec.samples; + SDL_CalculateAudioSpec (desired); + } + + /* Allocate a fake audio memory buffer */ + audio->fake_stream = SDL_AllocAudioMem (audio->spec.size); + if (audio->fake_stream == NULL) { + SDL_CloseAudio (); + SDL_OutOfMemory (); + return (-1); + } + + /* See if we need to do any conversion */ + if (obtained != NULL) { + SDL_memcpy (obtained, &audio->spec, sizeof (audio->spec)); + } else if (desired->freq != audio->spec.freq || + desired->format != audio->spec.format || + desired->channels != audio->spec.channels) { + /* Build an audio conversion block */ + if (SDL_BuildAudioCVT (&audio->convert, + desired->format, desired->channels, + desired->freq, + audio->spec.format, audio->spec.channels, + audio->spec.freq) < 0) { + SDL_CloseAudio (); + return (-1); + } + if (audio->convert.needed) { + audio->convert.len = desired->size; + audio->convert.buf = + (Uint8 *) SDL_AllocAudioMem (audio->convert.len * + audio->convert.len_mult); + if (audio->convert.buf == NULL) { + SDL_CloseAudio (); + SDL_OutOfMemory (); + return (-1); + } + } + } #if !SDL_AUDIO_DRIVER_AHI - /* Start the audio thread if necessary */ - switch (audio->opened) { - case 1: - /* Start the audio thread */ + /* Start the audio thread if necessary */ + switch (audio->opened) { + case 1: + /* Start the audio thread */ #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) #undef SDL_CreateThread - audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL); + audio->thread = SDL_CreateThread (SDL_RunAudio, audio, NULL, NULL); #else - audio->thread = SDL_CreateThread(SDL_RunAudio, audio); -#endif - if ( audio->thread == NULL ) { - SDL_CloseAudio(); - SDL_SetError("Couldn't create audio thread"); - return(-1); - } - break; - - default: - /* The audio is now playing */ - break; - } + audio->thread = SDL_CreateThread (SDL_RunAudio, audio); +#endif + if (audio->thread == NULL) { + SDL_CloseAudio (); + SDL_SetError ("Couldn't create audio thread"); + return (-1); + } + break; + + default: + /* The audio is now playing */ + break; + } #else - SDL_mutexV(audio->mixer_lock); - D(bug("SDL_OpenAudio USCITA...\n")); + SDL_mutexV (audio->mixer_lock); + D (bug ("SDL_OpenAudio USCITA...\n")); #endif - return(0); + return (0); } -SDL_audiostatus SDL_GetAudioStatus(void) +SDL_audiostatus +SDL_GetAudioStatus (void) { - SDL_AudioDevice *audio = current_audio; - SDL_audiostatus status; - - status = SDL_AUDIO_STOPPED; - if ( audio && audio->enabled ) { - if ( audio->paused ) { - status = SDL_AUDIO_PAUSED; - } else { - status = SDL_AUDIO_PLAYING; - } - } - return(status); + SDL_AudioDevice *audio = current_audio; + SDL_audiostatus status; + + status = SDL_AUDIO_STOPPED; + if (audio && audio->enabled) { + if (audio->paused) { + status = SDL_AUDIO_PAUSED; + } else { + status = SDL_AUDIO_PLAYING; + } + } + return (status); } -void SDL_PauseAudio (int pause_on) +void +SDL_PauseAudio (int pause_on) { - SDL_AudioDevice *audio = current_audio; + SDL_AudioDevice *audio = current_audio; - if ( audio ) { - audio->paused = pause_on; - } + if (audio) { + audio->paused = pause_on; + } } -void SDL_LockAudio (void) +void +SDL_LockAudio (void) { - SDL_AudioDevice *audio = current_audio; + SDL_AudioDevice *audio = current_audio; - /* Obtain a lock on the mixing buffers */ - if ( audio && audio->LockAudio ) { - audio->LockAudio(audio); - } + /* Obtain a lock on the mixing buffers */ + if (audio && audio->LockAudio) { + audio->LockAudio (audio); + } } -void SDL_UnlockAudio (void) +void +SDL_UnlockAudio (void) { - SDL_AudioDevice *audio = current_audio; + SDL_AudioDevice *audio = current_audio; - /* Release lock on the mixing buffers */ - if ( audio && audio->UnlockAudio ) { - audio->UnlockAudio(audio); - } + /* Release lock on the mixing buffers */ + if (audio && audio->UnlockAudio) { + audio->UnlockAudio (audio); + } } -void SDL_CloseAudio (void) +void +SDL_CloseAudio (void) { - SDL_QuitSubSystem(SDL_INIT_AUDIO); + SDL_QuitSubSystem (SDL_INIT_AUDIO); } -void SDL_AudioQuit(void) +void +SDL_AudioQuit (void) { - SDL_AudioDevice *audio = current_audio; - - if ( audio ) { - audio->enabled = 0; - if ( audio->thread != NULL ) { - SDL_WaitThread(audio->thread, NULL); - } - if ( audio->mixer_lock != NULL ) { - SDL_DestroyMutex(audio->mixer_lock); - } - if ( audio->fake_stream != NULL ) { - SDL_FreeAudioMem(audio->fake_stream); - } - if ( audio->convert.needed ) { - SDL_FreeAudioMem(audio->convert.buf); - - } + SDL_AudioDevice *audio = current_audio; + + if (audio) { + audio->enabled = 0; + if (audio->thread != NULL) { + SDL_WaitThread (audio->thread, NULL); + } + if (audio->mixer_lock != NULL) { + SDL_DestroyMutex (audio->mixer_lock); + } + if (audio->fake_stream != NULL) { + SDL_FreeAudioMem (audio->fake_stream); + } + if (audio->convert.needed) { + SDL_FreeAudioMem (audio->convert.buf); + + } #if !SDL_AUDIO_DRIVER_AHI - if ( audio->opened ) { - audio->CloseAudio(audio); - audio->opened = 0; - } -#endif - /* Free the driver data */ - audio->free(audio); - current_audio = NULL; - } + if (audio->opened) { + audio->CloseAudio (audio); + audio->opened = 0; + } +#endif + /* Free the driver data */ + audio->free (audio); + current_audio = NULL; + } } #define NUM_FORMATS 6 static int format_idx; static int format_idx_sub; static Uint16 format_list[NUM_FORMATS][NUM_FORMATS] = { - { AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB }, - { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB }, - { AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8 }, - { AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8 }, - { AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U8, AUDIO_S8 }, - { AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U8, AUDIO_S8 }, + {AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, + AUDIO_U16MSB}, + {AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, + AUDIO_U16MSB}, + {AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, + AUDIO_S8}, + {AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, + AUDIO_S8}, + {AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U8, + AUDIO_S8}, + {AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U8, + AUDIO_S8}, }; -Uint16 SDL_FirstAudioFormat(Uint16 format) +Uint16 +SDL_FirstAudioFormat (Uint16 format) { - for ( format_idx=0; format_idx < NUM_FORMATS; ++format_idx ) { - if ( format_list[format_idx][0] == format ) { - break; - } - } - format_idx_sub = 0; - return(SDL_NextAudioFormat()); + for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) { + if (format_list[format_idx][0] == format) { + break; + } + } + format_idx_sub = 0; + return (SDL_NextAudioFormat ()); } -Uint16 SDL_NextAudioFormat(void) +Uint16 +SDL_NextAudioFormat (void) { - if ( (format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS) ) { - return(0); - } - return(format_list[format_idx][format_idx_sub++]); + if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) { + return (0); + } + return (format_list[format_idx][format_idx_sub++]); } -void SDL_CalculateAudioSpec(SDL_AudioSpec *spec) +void +SDL_CalculateAudioSpec (SDL_AudioSpec * spec) { - switch (spec->format) { - case AUDIO_U8: - spec->silence = 0x80; - break; - default: - spec->silence = 0x00; - break; - } - spec->size = (spec->format&0xFF)/8; - spec->size *= spec->channels; - spec->size *= spec->samples; + switch (spec->format) { + case AUDIO_U8: + spec->silence = 0x80; + break; + default: + spec->silence = 0x00; + break; + } + spec->size = (spec->format & 0xFF) / 8; + spec->size *= spec->channels; + spec->size *= spec->samples; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_audio_c.h b/src/audio/SDL_audio_c.h index f5848959e..f07dfd6a8 100644 --- a/src/audio/SDL_audio_c.h +++ b/src/audio/SDL_audio_c.h @@ -24,11 +24,12 @@ /* Functions and variables exported from SDL_audio.c for SDL_sysaudio.c */ /* Functions to get a list of "close" audio formats */ -extern Uint16 SDL_FirstAudioFormat(Uint16 format); -extern Uint16 SDL_NextAudioFormat(void); +extern Uint16 SDL_FirstAudioFormat (Uint16 format); +extern Uint16 SDL_NextAudioFormat (void); /* Function to calculate the size and silence for a SDL_AudioSpec */ -extern void SDL_CalculateAudioSpec(SDL_AudioSpec *spec); +extern void SDL_CalculateAudioSpec (SDL_AudioSpec * spec); /* The actual mixing thread function */ -extern int SDLCALL SDL_RunAudio(void *audiop); +extern int SDLCALL SDL_RunAudio (void *audiop); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index 3c361155e..d421ad7bc 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -27,1519 +27,1569 @@ /* Effectively mix right and left channels into a single channel */ -void SDLCALL SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertMono (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Sint32 sample; + int i; + Sint32 sample; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting to mono\n"); + fprintf (stderr, "Converting to mono\n"); #endif - switch (format&0x8018) { - - case AUDIO_U8: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - for ( i=cvt->len_cvt/2; i; --i ) { - sample = src[0] + src[1]; - if ( sample > 255 ) { - *dst = 255; - } else { - *dst = (Uint8)sample; - } - src += 2; - dst += 1; - } - } - break; - - case AUDIO_S8: { - Sint8 *src, *dst; - - src = (Sint8 *)cvt->buf; - dst = (Sint8 *)cvt->buf; - for ( i=cvt->len_cvt/2; i; --i ) { - sample = src[0] + src[1]; - if ( sample > 127 ) { - *dst = 127; - } else - if ( sample < -128 ) { - *dst = -128; - } else { - *dst = (Sint8)sample; - } - src += 2; - dst += 1; - } - } - break; - - case AUDIO_U16: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/4; i; --i ) { - sample = (Uint16)((src[0]<<8)|src[1])+ - (Uint16)((src[2]<<8)|src[3]); - if ( sample > 65535 ) { - dst[0] = 0xFF; - dst[1] = 0xFF; - } else { - dst[1] = (sample&0xFF); - sample >>= 8; - dst[0] = (sample&0xFF); - } - src += 4; - dst += 2; - } - } else { - for ( i=cvt->len_cvt/4; i; --i ) { - sample = (Uint16)((src[1]<<8)|src[0])+ - (Uint16)((src[3]<<8)|src[2]); - if ( sample > 65535 ) { - dst[0] = 0xFF; - dst[1] = 0xFF; - } else { - dst[0] = (sample&0xFF); - sample >>= 8; - dst[1] = (sample&0xFF); - } - src += 4; - dst += 2; - } - } - } - break; - - case AUDIO_S16: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/4; i; --i ) { - sample = (Sint16)((src[0]<<8)|src[1])+ - (Sint16)((src[2]<<8)|src[3]); - if ( sample > 32767 ) { - dst[0] = 0x7F; - dst[1] = 0xFF; - } else - if ( sample < -32768 ) { - dst[0] = 0x80; - dst[1] = 0x00; - } else { - dst[1] = (sample&0xFF); - sample >>= 8; - dst[0] = (sample&0xFF); - } - src += 4; - dst += 2; - } - } else { - for ( i=cvt->len_cvt/4; i; --i ) { - sample = (Sint16)((src[1]<<8)|src[0])+ - (Sint16)((src[3]<<8)|src[2]); - if ( sample > 32767 ) { - dst[1] = 0x7F; - dst[0] = 0xFF; - } else - if ( sample < -32768 ) { - dst[1] = 0x80; - dst[0] = 0x00; - } else { - dst[0] = (sample&0xFF); - sample >>= 8; - dst[1] = (sample&0xFF); - } - src += 4; - dst += 2; - } - } - } - break; - } - cvt->len_cvt /= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + switch (format & 0x8018) { + + case AUDIO_U8: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + for (i = cvt->len_cvt / 2; i; --i) { + sample = src[0] + src[1]; + if (sample > 255) { + *dst = 255; + } else { + *dst = (Uint8) sample; + } + src += 2; + dst += 1; + } + } + break; + + case AUDIO_S8: + { + Sint8 *src, *dst; + + src = (Sint8 *) cvt->buf; + dst = (Sint8 *) cvt->buf; + for (i = cvt->len_cvt / 2; i; --i) { + sample = src[0] + src[1]; + if (sample > 127) { + *dst = 127; + } else if (sample < -128) { + *dst = -128; + } else { + *dst = (Sint8) sample; + } + src += 2; + dst += 1; + } + } + break; + + case AUDIO_U16: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 4; i; --i) { + sample = (Uint16) ((src[0] << 8) | src[1]) + + (Uint16) ((src[2] << 8) | src[3]); + if (sample > 65535) { + dst[0] = 0xFF; + dst[1] = 0xFF; + } else { + dst[1] = (sample & 0xFF); + sample >>= 8; + dst[0] = (sample & 0xFF); + } + src += 4; + dst += 2; + } + } else { + for (i = cvt->len_cvt / 4; i; --i) { + sample = (Uint16) ((src[1] << 8) | src[0]) + + (Uint16) ((src[3] << 8) | src[2]); + if (sample > 65535) { + dst[0] = 0xFF; + dst[1] = 0xFF; + } else { + dst[0] = (sample & 0xFF); + sample >>= 8; + dst[1] = (sample & 0xFF); + } + src += 4; + dst += 2; + } + } + } + break; + + case AUDIO_S16: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 4; i; --i) { + sample = (Sint16) ((src[0] << 8) | src[1]) + + (Sint16) ((src[2] << 8) | src[3]); + if (sample > 32767) { + dst[0] = 0x7F; + dst[1] = 0xFF; + } else if (sample < -32768) { + dst[0] = 0x80; + dst[1] = 0x00; + } else { + dst[1] = (sample & 0xFF); + sample >>= 8; + dst[0] = (sample & 0xFF); + } + src += 4; + dst += 2; + } + } else { + for (i = cvt->len_cvt / 4; i; --i) { + sample = (Sint16) ((src[1] << 8) | src[0]) + + (Sint16) ((src[3] << 8) | src[2]); + if (sample > 32767) { + dst[1] = 0x7F; + dst[0] = 0xFF; + } else if (sample < -32768) { + dst[1] = 0x80; + dst[0] = 0x00; + } else { + dst[0] = (sample & 0xFF); + sample >>= 8; + dst[1] = (sample & 0xFF); + } + src += 4; + dst += 2; + } + } + } + break; + } + cvt->len_cvt /= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Discard top 4 channels */ -void SDLCALL SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertStrip (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Sint32 lsample, rsample; + int i; + Sint32 lsample, rsample; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting down to stereo\n"); + fprintf (stderr, "Converting down to stereo\n"); #endif - switch (format&0x8018) { - - case AUDIO_U8: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - for ( i=cvt->len_cvt/6; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - src += 6; - dst += 2; - } - } - break; - - case AUDIO_S8: { - Sint8 *src, *dst; - - src = (Sint8 *)cvt->buf; - dst = (Sint8 *)cvt->buf; - for ( i=cvt->len_cvt/6; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - src += 6; - dst += 2; - } - } - break; - - case AUDIO_U16: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/12; i; --i ) { - lsample = (Uint16)((src[0]<<8)|src[1]); - rsample = (Uint16)((src[2]<<8)|src[3]); - dst[1] = (lsample&0xFF); - lsample >>= 8; - dst[0] = (lsample&0xFF); - dst[3] = (rsample&0xFF); - rsample >>= 8; - dst[2] = (rsample&0xFF); - src += 12; - dst += 4; - } - } else { - for ( i=cvt->len_cvt/12; i; --i ) { - lsample = (Uint16)((src[1]<<8)|src[0]); - rsample = (Uint16)((src[3]<<8)|src[2]); - dst[0] = (lsample&0xFF); - lsample >>= 8; - dst[1] = (lsample&0xFF); - dst[2] = (rsample&0xFF); - rsample >>= 8; - dst[3] = (rsample&0xFF); - src += 12; - dst += 4; - } - } - } - break; - - case AUDIO_S16: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/12; i; --i ) { - lsample = (Sint16)((src[0]<<8)|src[1]); - rsample = (Sint16)((src[2]<<8)|src[3]); - dst[1] = (lsample&0xFF); - lsample >>= 8; - dst[0] = (lsample&0xFF); - dst[3] = (rsample&0xFF); - rsample >>= 8; - dst[2] = (rsample&0xFF); - src += 12; - dst += 4; - } - } else { - for ( i=cvt->len_cvt/12; i; --i ) { - lsample = (Sint16)((src[1]<<8)|src[0]); - rsample = (Sint16)((src[3]<<8)|src[2]); - dst[0] = (lsample&0xFF); - lsample >>= 8; - dst[1] = (lsample&0xFF); - dst[2] = (rsample&0xFF); - rsample >>= 8; - dst[3] = (rsample&0xFF); - src += 12; - dst += 4; - } - } - } - break; - } - cvt->len_cvt /= 3; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + switch (format & 0x8018) { + + case AUDIO_U8: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + for (i = cvt->len_cvt / 6; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 6; + dst += 2; + } + } + break; + + case AUDIO_S8: + { + Sint8 *src, *dst; + + src = (Sint8 *) cvt->buf; + dst = (Sint8 *) cvt->buf; + for (i = cvt->len_cvt / 6; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 6; + dst += 2; + } + } + break; + + case AUDIO_U16: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 12; i; --i) { + lsample = (Uint16) ((src[0] << 8) | src[1]); + rsample = (Uint16) ((src[2] << 8) | src[3]); + dst[1] = (lsample & 0xFF); + lsample >>= 8; + dst[0] = (lsample & 0xFF); + dst[3] = (rsample & 0xFF); + rsample >>= 8; + dst[2] = (rsample & 0xFF); + src += 12; + dst += 4; + } + } else { + for (i = cvt->len_cvt / 12; i; --i) { + lsample = (Uint16) ((src[1] << 8) | src[0]); + rsample = (Uint16) ((src[3] << 8) | src[2]); + dst[0] = (lsample & 0xFF); + lsample >>= 8; + dst[1] = (lsample & 0xFF); + dst[2] = (rsample & 0xFF); + rsample >>= 8; + dst[3] = (rsample & 0xFF); + src += 12; + dst += 4; + } + } + } + break; + + case AUDIO_S16: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 12; i; --i) { + lsample = (Sint16) ((src[0] << 8) | src[1]); + rsample = (Sint16) ((src[2] << 8) | src[3]); + dst[1] = (lsample & 0xFF); + lsample >>= 8; + dst[0] = (lsample & 0xFF); + dst[3] = (rsample & 0xFF); + rsample >>= 8; + dst[2] = (rsample & 0xFF); + src += 12; + dst += 4; + } + } else { + for (i = cvt->len_cvt / 12; i; --i) { + lsample = (Sint16) ((src[1] << 8) | src[0]); + rsample = (Sint16) ((src[3] << 8) | src[2]); + dst[0] = (lsample & 0xFF); + lsample >>= 8; + dst[1] = (lsample & 0xFF); + dst[2] = (rsample & 0xFF); + rsample >>= 8; + dst[3] = (rsample & 0xFF); + src += 12; + dst += 4; + } + } + } + break; + } + cvt->len_cvt /= 3; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Discard top 2 channels of 6 */ -void SDLCALL SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertStrip_2 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Sint32 lsample, rsample; + int i; + Sint32 lsample, rsample; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting 6 down to quad\n"); + fprintf (stderr, "Converting 6 down to quad\n"); #endif - switch (format&0x8018) { - - case AUDIO_U8: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - for ( i=cvt->len_cvt/4; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - src += 4; - dst += 2; - } - } - break; - - case AUDIO_S8: { - Sint8 *src, *dst; - - src = (Sint8 *)cvt->buf; - dst = (Sint8 *)cvt->buf; - for ( i=cvt->len_cvt/4; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - src += 4; - dst += 2; - } - } - break; - - case AUDIO_U16: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/8; i; --i ) { - lsample = (Uint16)((src[0]<<8)|src[1]); - rsample = (Uint16)((src[2]<<8)|src[3]); - dst[1] = (lsample&0xFF); - lsample >>= 8; - dst[0] = (lsample&0xFF); - dst[3] = (rsample&0xFF); - rsample >>= 8; - dst[2] = (rsample&0xFF); - src += 8; - dst += 4; - } - } else { - for ( i=cvt->len_cvt/8; i; --i ) { - lsample = (Uint16)((src[1]<<8)|src[0]); - rsample = (Uint16)((src[3]<<8)|src[2]); - dst[0] = (lsample&0xFF); - lsample >>= 8; - dst[1] = (lsample&0xFF); - dst[2] = (rsample&0xFF); - rsample >>= 8; - dst[3] = (rsample&0xFF); - src += 8; - dst += 4; - } - } - } - break; - - case AUDIO_S16: { - Uint8 *src, *dst; - - src = cvt->buf; - dst = cvt->buf; - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/8; i; --i ) { - lsample = (Sint16)((src[0]<<8)|src[1]); - rsample = (Sint16)((src[2]<<8)|src[3]); - dst[1] = (lsample&0xFF); - lsample >>= 8; - dst[0] = (lsample&0xFF); - dst[3] = (rsample&0xFF); - rsample >>= 8; - dst[2] = (rsample&0xFF); - src += 8; - dst += 4; - } - } else { - for ( i=cvt->len_cvt/8; i; --i ) { - lsample = (Sint16)((src[1]<<8)|src[0]); - rsample = (Sint16)((src[3]<<8)|src[2]); - dst[0] = (lsample&0xFF); - lsample >>= 8; - dst[1] = (lsample&0xFF); - dst[2] = (rsample&0xFF); - rsample >>= 8; - dst[3] = (rsample&0xFF); - src += 8; - dst += 4; - } - } - } - break; - } - cvt->len_cvt /= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + switch (format & 0x8018) { + + case AUDIO_U8: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + for (i = cvt->len_cvt / 4; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 4; + dst += 2; + } + } + break; + + case AUDIO_S8: + { + Sint8 *src, *dst; + + src = (Sint8 *) cvt->buf; + dst = (Sint8 *) cvt->buf; + for (i = cvt->len_cvt / 4; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 4; + dst += 2; + } + } + break; + + case AUDIO_U16: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 8; i; --i) { + lsample = (Uint16) ((src[0] << 8) | src[1]); + rsample = (Uint16) ((src[2] << 8) | src[3]); + dst[1] = (lsample & 0xFF); + lsample >>= 8; + dst[0] = (lsample & 0xFF); + dst[3] = (rsample & 0xFF); + rsample >>= 8; + dst[2] = (rsample & 0xFF); + src += 8; + dst += 4; + } + } else { + for (i = cvt->len_cvt / 8; i; --i) { + lsample = (Uint16) ((src[1] << 8) | src[0]); + rsample = (Uint16) ((src[3] << 8) | src[2]); + dst[0] = (lsample & 0xFF); + lsample >>= 8; + dst[1] = (lsample & 0xFF); + dst[2] = (rsample & 0xFF); + rsample >>= 8; + dst[3] = (rsample & 0xFF); + src += 8; + dst += 4; + } + } + } + break; + + case AUDIO_S16: + { + Uint8 *src, *dst; + + src = cvt->buf; + dst = cvt->buf; + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 8; i; --i) { + lsample = (Sint16) ((src[0] << 8) | src[1]); + rsample = (Sint16) ((src[2] << 8) | src[3]); + dst[1] = (lsample & 0xFF); + lsample >>= 8; + dst[0] = (lsample & 0xFF); + dst[3] = (rsample & 0xFF); + rsample >>= 8; + dst[2] = (rsample & 0xFF); + src += 8; + dst += 4; + } + } else { + for (i = cvt->len_cvt / 8; i; --i) { + lsample = (Sint16) ((src[1] << 8) | src[0]); + rsample = (Sint16) ((src[3] << 8) | src[2]); + dst[0] = (lsample & 0xFF); + lsample >>= 8; + dst[1] = (lsample & 0xFF); + dst[2] = (rsample & 0xFF); + rsample >>= 8; + dst[3] = (rsample & 0xFF); + src += 8; + dst += 4; + } + } + } + break; + } + cvt->len_cvt /= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Duplicate a mono channel to both stereo channels */ -void SDLCALL SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertStereo (SDL_AudioCVT * cvt, Uint16 format) { - int i; + int i; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting to stereo\n"); + fprintf (stderr, "Converting to stereo\n"); #endif - if ( (format & 0xFF) == 16 ) { - Uint16 *src, *dst; - - src = (Uint16 *)(cvt->buf+cvt->len_cvt); - dst = (Uint16 *)(cvt->buf+cvt->len_cvt*2); - for ( i=cvt->len_cvt/2; i; --i ) { - dst -= 2; - src -= 1; - dst[0] = src[0]; - dst[1] = src[0]; - } - } else { - Uint8 *src, *dst; - - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - for ( i=cvt->len_cvt; i; --i ) { - dst -= 2; - src -= 1; - dst[0] = src[0]; - dst[1] = src[0]; - } - } - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + if ((format & 0xFF) == 16) { + Uint16 *src, *dst; + + src = (Uint16 *) (cvt->buf + cvt->len_cvt); + dst = (Uint16 *) (cvt->buf + cvt->len_cvt * 2); + for (i = cvt->len_cvt / 2; i; --i) { + dst -= 2; + src -= 1; + dst[0] = src[0]; + dst[1] = src[0]; + } + } else { + Uint8 *src, *dst; + + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + for (i = cvt->len_cvt; i; --i) { + dst -= 2; + src -= 1; + dst[0] = src[0]; + dst[1] = src[0]; + } + } + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Duplicate a stereo channel to a pseudo-5.1 stream */ -void SDLCALL SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertSurround (SDL_AudioCVT * cvt, Uint16 format) { - int i; + int i; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting stereo to surround\n"); + fprintf (stderr, "Converting stereo to surround\n"); #endif - switch (format&0x8018) { - - case AUDIO_U8: { - Uint8 *src, *dst, lf, rf, ce; - - src = (Uint8 *)(cvt->buf+cvt->len_cvt); - dst = (Uint8 *)(cvt->buf+cvt->len_cvt*3); - for ( i=cvt->len_cvt; i; --i ) { - dst -= 6; - src -= 2; - lf = src[0]; - rf = src[1]; - ce = (lf/2) + (rf/2); - dst[0] = lf; - dst[1] = rf; - dst[2] = lf - ce; - dst[3] = rf - ce; - dst[4] = ce; - dst[5] = ce; - } - } - break; - - case AUDIO_S8: { - Sint8 *src, *dst, lf, rf, ce; - - src = (Sint8 *)cvt->buf+cvt->len_cvt; - dst = (Sint8 *)cvt->buf+cvt->len_cvt*3; - for ( i=cvt->len_cvt; i; --i ) { - dst -= 6; - src -= 2; - lf = src[0]; - rf = src[1]; - ce = (lf/2) + (rf/2); - dst[0] = lf; - dst[1] = rf; - dst[2] = lf - ce; - dst[3] = rf - ce; - dst[4] = ce; - dst[5] = ce; - } - } - break; - - case AUDIO_U16: { - Uint8 *src, *dst; - Uint16 lf, rf, ce, lr, rr; - - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*3; - - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 12; - src -= 4; - lf = (Uint16)((src[0]<<8)|src[1]); - rf = (Uint16)((src[2]<<8)|src[3]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[1] = (lf&0xFF); - dst[0] = ((lf>>8)&0xFF); - dst[3] = (rf&0xFF); - dst[2] = ((rf>>8)&0xFF); - - dst[1+4] = (lr&0xFF); - dst[0+4] = ((lr>>8)&0xFF); - dst[3+4] = (rr&0xFF); - dst[2+4] = ((rr>>8)&0xFF); - - dst[1+8] = (ce&0xFF); - dst[0+8] = ((ce>>8)&0xFF); - dst[3+8] = (ce&0xFF); - dst[2+8] = ((ce>>8)&0xFF); - } - } else { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 12; - src -= 4; - lf = (Uint16)((src[1]<<8)|src[0]); - rf = (Uint16)((src[3]<<8)|src[2]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[0] = (lf&0xFF); - dst[1] = ((lf>>8)&0xFF); - dst[2] = (rf&0xFF); - dst[3] = ((rf>>8)&0xFF); - - dst[0+4] = (lr&0xFF); - dst[1+4] = ((lr>>8)&0xFF); - dst[2+4] = (rr&0xFF); - dst[3+4] = ((rr>>8)&0xFF); - - dst[0+8] = (ce&0xFF); - dst[1+8] = ((ce>>8)&0xFF); - dst[2+8] = (ce&0xFF); - dst[3+8] = ((ce>>8)&0xFF); - } - } - } - break; - - case AUDIO_S16: { - Uint8 *src, *dst; - Sint16 lf, rf, ce, lr, rr; - - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*3; - - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 12; - src -= 4; - lf = (Sint16)((src[0]<<8)|src[1]); - rf = (Sint16)((src[2]<<8)|src[3]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[1] = (lf&0xFF); - dst[0] = ((lf>>8)&0xFF); - dst[3] = (rf&0xFF); - dst[2] = ((rf>>8)&0xFF); - - dst[1+4] = (lr&0xFF); - dst[0+4] = ((lr>>8)&0xFF); - dst[3+4] = (rr&0xFF); - dst[2+4] = ((rr>>8)&0xFF); - - dst[1+8] = (ce&0xFF); - dst[0+8] = ((ce>>8)&0xFF); - dst[3+8] = (ce&0xFF); - dst[2+8] = ((ce>>8)&0xFF); - } - } else { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 12; - src -= 4; - lf = (Sint16)((src[1]<<8)|src[0]); - rf = (Sint16)((src[3]<<8)|src[2]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[0] = (lf&0xFF); - dst[1] = ((lf>>8)&0xFF); - dst[2] = (rf&0xFF); - dst[3] = ((rf>>8)&0xFF); - - dst[0+4] = (lr&0xFF); - dst[1+4] = ((lr>>8)&0xFF); - dst[2+4] = (rr&0xFF); - dst[3+4] = ((rr>>8)&0xFF); - - dst[0+8] = (ce&0xFF); - dst[1+8] = ((ce>>8)&0xFF); - dst[2+8] = (ce&0xFF); - dst[3+8] = ((ce>>8)&0xFF); - } - } - } - break; - } - cvt->len_cvt *= 3; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + switch (format & 0x8018) { + + case AUDIO_U8: + { + Uint8 *src, *dst, lf, rf, ce; + + src = (Uint8 *) (cvt->buf + cvt->len_cvt); + dst = (Uint8 *) (cvt->buf + cvt->len_cvt * 3); + for (i = cvt->len_cvt; i; --i) { + dst -= 6; + src -= 2; + lf = src[0]; + rf = src[1]; + ce = (lf / 2) + (rf / 2); + dst[0] = lf; + dst[1] = rf; + dst[2] = lf - ce; + dst[3] = rf - ce; + dst[4] = ce; + dst[5] = ce; + } + } + break; + + case AUDIO_S8: + { + Sint8 *src, *dst, lf, rf, ce; + + src = (Sint8 *) cvt->buf + cvt->len_cvt; + dst = (Sint8 *) cvt->buf + cvt->len_cvt * 3; + for (i = cvt->len_cvt; i; --i) { + dst -= 6; + src -= 2; + lf = src[0]; + rf = src[1]; + ce = (lf / 2) + (rf / 2); + dst[0] = lf; + dst[1] = rf; + dst[2] = lf - ce; + dst[3] = rf - ce; + dst[4] = ce; + dst[5] = ce; + } + } + break; + + case AUDIO_U16: + { + Uint8 *src, *dst; + Uint16 lf, rf, ce, lr, rr; + + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 3; + + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 12; + src -= 4; + lf = (Uint16) ((src[0] << 8) | src[1]); + rf = (Uint16) ((src[2] << 8) | src[3]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[1] = (lf & 0xFF); + dst[0] = ((lf >> 8) & 0xFF); + dst[3] = (rf & 0xFF); + dst[2] = ((rf >> 8) & 0xFF); + + dst[1 + 4] = (lr & 0xFF); + dst[0 + 4] = ((lr >> 8) & 0xFF); + dst[3 + 4] = (rr & 0xFF); + dst[2 + 4] = ((rr >> 8) & 0xFF); + + dst[1 + 8] = (ce & 0xFF); + dst[0 + 8] = ((ce >> 8) & 0xFF); + dst[3 + 8] = (ce & 0xFF); + dst[2 + 8] = ((ce >> 8) & 0xFF); + } + } else { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 12; + src -= 4; + lf = (Uint16) ((src[1] << 8) | src[0]); + rf = (Uint16) ((src[3] << 8) | src[2]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[0] = (lf & 0xFF); + dst[1] = ((lf >> 8) & 0xFF); + dst[2] = (rf & 0xFF); + dst[3] = ((rf >> 8) & 0xFF); + + dst[0 + 4] = (lr & 0xFF); + dst[1 + 4] = ((lr >> 8) & 0xFF); + dst[2 + 4] = (rr & 0xFF); + dst[3 + 4] = ((rr >> 8) & 0xFF); + + dst[0 + 8] = (ce & 0xFF); + dst[1 + 8] = ((ce >> 8) & 0xFF); + dst[2 + 8] = (ce & 0xFF); + dst[3 + 8] = ((ce >> 8) & 0xFF); + } + } + } + break; + + case AUDIO_S16: + { + Uint8 *src, *dst; + Sint16 lf, rf, ce, lr, rr; + + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 3; + + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 12; + src -= 4; + lf = (Sint16) ((src[0] << 8) | src[1]); + rf = (Sint16) ((src[2] << 8) | src[3]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[1] = (lf & 0xFF); + dst[0] = ((lf >> 8) & 0xFF); + dst[3] = (rf & 0xFF); + dst[2] = ((rf >> 8) & 0xFF); + + dst[1 + 4] = (lr & 0xFF); + dst[0 + 4] = ((lr >> 8) & 0xFF); + dst[3 + 4] = (rr & 0xFF); + dst[2 + 4] = ((rr >> 8) & 0xFF); + + dst[1 + 8] = (ce & 0xFF); + dst[0 + 8] = ((ce >> 8) & 0xFF); + dst[3 + 8] = (ce & 0xFF); + dst[2 + 8] = ((ce >> 8) & 0xFF); + } + } else { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 12; + src -= 4; + lf = (Sint16) ((src[1] << 8) | src[0]); + rf = (Sint16) ((src[3] << 8) | src[2]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[0] = (lf & 0xFF); + dst[1] = ((lf >> 8) & 0xFF); + dst[2] = (rf & 0xFF); + dst[3] = ((rf >> 8) & 0xFF); + + dst[0 + 4] = (lr & 0xFF); + dst[1 + 4] = ((lr >> 8) & 0xFF); + dst[2 + 4] = (rr & 0xFF); + dst[3 + 4] = ((rr >> 8) & 0xFF); + + dst[0 + 8] = (ce & 0xFF); + dst[1 + 8] = ((ce >> 8) & 0xFF); + dst[2 + 8] = (ce & 0xFF); + dst[3 + 8] = ((ce >> 8) & 0xFF); + } + } + } + break; + } + cvt->len_cvt *= 3; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Duplicate a stereo channel to a pseudo-4.0 stream */ -void SDLCALL SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertSurround_4 (SDL_AudioCVT * cvt, Uint16 format) { - int i; + int i; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting stereo to quad\n"); + fprintf (stderr, "Converting stereo to quad\n"); #endif - switch (format&0x8018) { - - case AUDIO_U8: { - Uint8 *src, *dst, lf, rf, ce; - - src = (Uint8 *)(cvt->buf+cvt->len_cvt); - dst = (Uint8 *)(cvt->buf+cvt->len_cvt*2); - for ( i=cvt->len_cvt; i; --i ) { - dst -= 4; - src -= 2; - lf = src[0]; - rf = src[1]; - ce = (lf/2) + (rf/2); - dst[0] = lf; - dst[1] = rf; - dst[2] = lf - ce; - dst[3] = rf - ce; - } - } - break; - - case AUDIO_S8: { - Sint8 *src, *dst, lf, rf, ce; - - src = (Sint8 *)cvt->buf+cvt->len_cvt; - dst = (Sint8 *)cvt->buf+cvt->len_cvt*2; - for ( i=cvt->len_cvt; i; --i ) { - dst -= 4; - src -= 2; - lf = src[0]; - rf = src[1]; - ce = (lf/2) + (rf/2); - dst[0] = lf; - dst[1] = rf; - dst[2] = lf - ce; - dst[3] = rf - ce; - } - } - break; - - case AUDIO_U16: { - Uint8 *src, *dst; - Uint16 lf, rf, ce, lr, rr; - - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 8; - src -= 4; - lf = (Uint16)((src[0]<<8)|src[1]); - rf = (Uint16)((src[2]<<8)|src[3]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[1] = (lf&0xFF); - dst[0] = ((lf>>8)&0xFF); - dst[3] = (rf&0xFF); - dst[2] = ((rf>>8)&0xFF); - - dst[1+4] = (lr&0xFF); - dst[0+4] = ((lr>>8)&0xFF); - dst[3+4] = (rr&0xFF); - dst[2+4] = ((rr>>8)&0xFF); - } - } else { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 8; - src -= 4; - lf = (Uint16)((src[1]<<8)|src[0]); - rf = (Uint16)((src[3]<<8)|src[2]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[0] = (lf&0xFF); - dst[1] = ((lf>>8)&0xFF); - dst[2] = (rf&0xFF); - dst[3] = ((rf>>8)&0xFF); - - dst[0+4] = (lr&0xFF); - dst[1+4] = ((lr>>8)&0xFF); - dst[2+4] = (rr&0xFF); - dst[3+4] = ((rr>>8)&0xFF); - } - } - } - break; - - case AUDIO_S16: { - Uint8 *src, *dst; - Sint16 lf, rf, ce, lr, rr; - - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - - if ( (format & 0x1000) == 0x1000 ) { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 8; - src -= 4; - lf = (Sint16)((src[0]<<8)|src[1]); - rf = (Sint16)((src[2]<<8)|src[3]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[1] = (lf&0xFF); - dst[0] = ((lf>>8)&0xFF); - dst[3] = (rf&0xFF); - dst[2] = ((rf>>8)&0xFF); - - dst[1+4] = (lr&0xFF); - dst[0+4] = ((lr>>8)&0xFF); - dst[3+4] = (rr&0xFF); - dst[2+4] = ((rr>>8)&0xFF); - } - } else { - for ( i=cvt->len_cvt/4; i; --i ) { - dst -= 8; - src -= 4; - lf = (Sint16)((src[1]<<8)|src[0]); - rf = (Sint16)((src[3]<<8)|src[2]); - ce = (lf/2) + (rf/2); - rr = lf - ce; - lr = rf - ce; - dst[0] = (lf&0xFF); - dst[1] = ((lf>>8)&0xFF); - dst[2] = (rf&0xFF); - dst[3] = ((rf>>8)&0xFF); - - dst[0+4] = (lr&0xFF); - dst[1+4] = ((lr>>8)&0xFF); - dst[2+4] = (rr&0xFF); - dst[3+4] = ((rr>>8)&0xFF); - } - } - } - break; - } - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + switch (format & 0x8018) { + + case AUDIO_U8: + { + Uint8 *src, *dst, lf, rf, ce; + + src = (Uint8 *) (cvt->buf + cvt->len_cvt); + dst = (Uint8 *) (cvt->buf + cvt->len_cvt * 2); + for (i = cvt->len_cvt; i; --i) { + dst -= 4; + src -= 2; + lf = src[0]; + rf = src[1]; + ce = (lf / 2) + (rf / 2); + dst[0] = lf; + dst[1] = rf; + dst[2] = lf - ce; + dst[3] = rf - ce; + } + } + break; + + case AUDIO_S8: + { + Sint8 *src, *dst, lf, rf, ce; + + src = (Sint8 *) cvt->buf + cvt->len_cvt; + dst = (Sint8 *) cvt->buf + cvt->len_cvt * 2; + for (i = cvt->len_cvt; i; --i) { + dst -= 4; + src -= 2; + lf = src[0]; + rf = src[1]; + ce = (lf / 2) + (rf / 2); + dst[0] = lf; + dst[1] = rf; + dst[2] = lf - ce; + dst[3] = rf - ce; + } + } + break; + + case AUDIO_U16: + { + Uint8 *src, *dst; + Uint16 lf, rf, ce, lr, rr; + + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 8; + src -= 4; + lf = (Uint16) ((src[0] << 8) | src[1]); + rf = (Uint16) ((src[2] << 8) | src[3]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[1] = (lf & 0xFF); + dst[0] = ((lf >> 8) & 0xFF); + dst[3] = (rf & 0xFF); + dst[2] = ((rf >> 8) & 0xFF); + + dst[1 + 4] = (lr & 0xFF); + dst[0 + 4] = ((lr >> 8) & 0xFF); + dst[3 + 4] = (rr & 0xFF); + dst[2 + 4] = ((rr >> 8) & 0xFF); + } + } else { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 8; + src -= 4; + lf = (Uint16) ((src[1] << 8) | src[0]); + rf = (Uint16) ((src[3] << 8) | src[2]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[0] = (lf & 0xFF); + dst[1] = ((lf >> 8) & 0xFF); + dst[2] = (rf & 0xFF); + dst[3] = ((rf >> 8) & 0xFF); + + dst[0 + 4] = (lr & 0xFF); + dst[1 + 4] = ((lr >> 8) & 0xFF); + dst[2 + 4] = (rr & 0xFF); + dst[3 + 4] = ((rr >> 8) & 0xFF); + } + } + } + break; + + case AUDIO_S16: + { + Uint8 *src, *dst; + Sint16 lf, rf, ce, lr, rr; + + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + + if ((format & 0x1000) == 0x1000) { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 8; + src -= 4; + lf = (Sint16) ((src[0] << 8) | src[1]); + rf = (Sint16) ((src[2] << 8) | src[3]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[1] = (lf & 0xFF); + dst[0] = ((lf >> 8) & 0xFF); + dst[3] = (rf & 0xFF); + dst[2] = ((rf >> 8) & 0xFF); + + dst[1 + 4] = (lr & 0xFF); + dst[0 + 4] = ((lr >> 8) & 0xFF); + dst[3 + 4] = (rr & 0xFF); + dst[2 + 4] = ((rr >> 8) & 0xFF); + } + } else { + for (i = cvt->len_cvt / 4; i; --i) { + dst -= 8; + src -= 4; + lf = (Sint16) ((src[1] << 8) | src[0]); + rf = (Sint16) ((src[3] << 8) | src[2]); + ce = (lf / 2) + (rf / 2); + rr = lf - ce; + lr = rf - ce; + dst[0] = (lf & 0xFF); + dst[1] = ((lf >> 8) & 0xFF); + dst[2] = (rf & 0xFF); + dst[3] = ((rf >> 8) & 0xFF); + + dst[0 + 4] = (lr & 0xFF); + dst[1 + 4] = ((lr >> 8) & 0xFF); + dst[2 + 4] = (rr & 0xFF); + dst[3 + 4] = ((rr >> 8) & 0xFF); + } + } + } + break; + } + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert 8-bit to 16-bit - LSB */ -void SDLCALL SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_Convert16LSB (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting to 16-bit LSB\n"); + fprintf (stderr, "Converting to 16-bit LSB\n"); #endif - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - for ( i=cvt->len_cvt; i; --i ) { - src -= 1; - dst -= 2; - dst[1] = *src; - dst[0] = 0; - } - format = ((format & ~0x0008) | AUDIO_U16LSB); - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + for (i = cvt->len_cvt; i; --i) { + src -= 1; + dst -= 2; + dst[1] = *src; + dst[0] = 0; + } + format = ((format & ~0x0008) | AUDIO_U16LSB); + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } + /* Convert 8-bit to 16-bit - MSB */ -void SDLCALL SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_Convert16MSB (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting to 16-bit MSB\n"); + fprintf (stderr, "Converting to 16-bit MSB\n"); #endif - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - for ( i=cvt->len_cvt; i; --i ) { - src -= 1; - dst -= 2; - dst[0] = *src; - dst[1] = 0; - } - format = ((format & ~0x0008) | AUDIO_U16MSB); - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + for (i = cvt->len_cvt; i; --i) { + src -= 1; + dst -= 2; + dst[0] = *src; + dst[1] = 0; + } + format = ((format & ~0x0008) | AUDIO_U16MSB); + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert 16-bit to 8-bit */ -void SDLCALL SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_Convert8 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting to 8-bit\n"); + fprintf (stderr, "Converting to 8-bit\n"); #endif - src = cvt->buf; - dst = cvt->buf; - if ( (format & 0x1000) != 0x1000 ) { /* Little endian */ - ++src; - } - for ( i=cvt->len_cvt/2; i; --i ) { - *dst = *src; - src += 2; - dst += 1; - } - format = ((format & ~0x9010) | AUDIO_U8); - cvt->len_cvt /= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf; + dst = cvt->buf; + if ((format & 0x1000) != 0x1000) { /* Little endian */ + ++src; + } + for (i = cvt->len_cvt / 2; i; --i) { + *dst = *src; + src += 2; + dst += 1; + } + format = ((format & ~0x9010) | AUDIO_U8); + cvt->len_cvt /= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Toggle signed/unsigned */ -void SDLCALL SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertSign (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *data; + int i; + Uint8 *data; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio signedness\n"); + fprintf (stderr, "Converting audio signedness\n"); #endif - data = cvt->buf; - if ( (format & 0xFF) == 16 ) { - if ( (format & 0x1000) != 0x1000 ) { /* Little endian */ - ++data; - } - for ( i=cvt->len_cvt/2; i; --i ) { - *data ^= 0x80; - data += 2; - } - } else { - for ( i=cvt->len_cvt; i; --i ) { - *data++ ^= 0x80; - } - } - format = (format ^ 0x8000); - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + data = cvt->buf; + if ((format & 0xFF) == 16) { + if ((format & 0x1000) != 0x1000) { /* Little endian */ + ++data; + } + for (i = cvt->len_cvt / 2; i; --i) { + *data ^= 0x80; + data += 2; + } + } else { + for (i = cvt->len_cvt; i; --i) { + *data++ ^= 0x80; + } + } + format = (format ^ 0x8000); + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Toggle endianness */ -void SDLCALL SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_ConvertEndian (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *data, tmp; + int i; + Uint8 *data, tmp; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio endianness\n"); + fprintf (stderr, "Converting audio endianness\n"); #endif - data = cvt->buf; - for ( i=cvt->len_cvt/2; i; --i ) { - tmp = data[0]; - data[0] = data[1]; - data[1] = tmp; - data += 2; - } - format = (format ^ 0x1000); - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + data = cvt->buf; + for (i = cvt->len_cvt / 2; i; --i) { + tmp = data[0]; + data[0] = data[1]; + data[1] = tmp; + data += 2; + } + format = (format ^ 0x1000); + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate up by multiple of 2 */ -void SDLCALL SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateMUL2 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate * 2\n"); + fprintf (stderr, "Converting audio rate * 2\n"); #endif - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt; i; --i ) { - src -= 1; - dst -= 2; - dst[0] = src[0]; - dst[1] = src[0]; - } - break; - case 16: - for ( i=cvt->len_cvt/2; i; --i ) { - src -= 2; - dst -= 4; - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[0]; - dst[3] = src[1]; - } - break; - } - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt; i; --i) { + src -= 1; + dst -= 2; + dst[0] = src[0]; + dst[1] = src[0]; + } + break; + case 16: + for (i = cvt->len_cvt / 2; i; --i) { + src -= 2; + dst -= 4; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[0]; + dst[3] = src[1]; + } + break; + } + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate up by multiple of 2, for stereo */ -void SDLCALL SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateMUL2_c2 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate * 2\n"); + fprintf (stderr, "Converting audio rate * 2\n"); #endif - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt/2; i; --i ) { - src -= 2; - dst -= 4; - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[0]; - dst[3] = src[1]; - } - break; - case 16: - for ( i=cvt->len_cvt/4; i; --i ) { - src -= 4; - dst -= 8; - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[0]; - dst[5] = src[1]; - dst[6] = src[2]; - dst[7] = src[3]; - } - break; - } - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt / 2; i; --i) { + src -= 2; + dst -= 4; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[0]; + dst[3] = src[1]; + } + break; + case 16: + for (i = cvt->len_cvt / 4; i; --i) { + src -= 4; + dst -= 8; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[0]; + dst[5] = src[1]; + dst[6] = src[2]; + dst[7] = src[3]; + } + break; + } + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate up by multiple of 2, for quad */ -void SDLCALL SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateMUL2_c4 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate * 2\n"); + fprintf (stderr, "Converting audio rate * 2\n"); #endif - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt/4; i; --i ) { - src -= 4; - dst -= 8; - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[0]; - dst[5] = src[1]; - dst[6] = src[2]; - dst[7] = src[3]; - } - break; - case 16: - for ( i=cvt->len_cvt/8; i; --i ) { - src -= 8; - dst -= 16; - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - dst[6] = src[6]; - dst[7] = src[7]; - dst[8] = src[0]; - dst[9] = src[1]; - dst[10] = src[2]; - dst[11] = src[3]; - dst[12] = src[4]; - dst[13] = src[5]; - dst[14] = src[6]; - dst[15] = src[7]; - } - break; - } - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt / 4; i; --i) { + src -= 4; + dst -= 8; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[0]; + dst[5] = src[1]; + dst[6] = src[2]; + dst[7] = src[3]; + } + break; + case 16: + for (i = cvt->len_cvt / 8; i; --i) { + src -= 8; + dst -= 16; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[4]; + dst[5] = src[5]; + dst[6] = src[6]; + dst[7] = src[7]; + dst[8] = src[0]; + dst[9] = src[1]; + dst[10] = src[2]; + dst[11] = src[3]; + dst[12] = src[4]; + dst[13] = src[5]; + dst[14] = src[6]; + dst[15] = src[7]; + } + break; + } + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate up by multiple of 2, for 5.1 */ -void SDLCALL SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateMUL2_c6 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate * 2\n"); + fprintf (stderr, "Converting audio rate * 2\n"); #endif - src = cvt->buf+cvt->len_cvt; - dst = cvt->buf+cvt->len_cvt*2; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt/6; i; --i ) { - src -= 6; - dst -= 12; - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - dst[6] = src[0]; - dst[7] = src[1]; - dst[8] = src[2]; - dst[9] = src[3]; - dst[10] = src[4]; - dst[11] = src[5]; - } - break; - case 16: - for ( i=cvt->len_cvt/12; i; --i ) { - src -= 12; - dst -= 24; - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - dst[6] = src[6]; - dst[7] = src[7]; - dst[8] = src[8]; - dst[9] = src[9]; - dst[10] = src[10]; - dst[11] = src[11]; - dst[12] = src[0]; - dst[13] = src[1]; - dst[14] = src[2]; - dst[15] = src[3]; - dst[16] = src[4]; - dst[17] = src[5]; - dst[18] = src[6]; - dst[19] = src[7]; - dst[20] = src[8]; - dst[21] = src[9]; - dst[22] = src[10]; - dst[23] = src[11]; - } - break; - } - cvt->len_cvt *= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf + cvt->len_cvt; + dst = cvt->buf + cvt->len_cvt * 2; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt / 6; i; --i) { + src -= 6; + dst -= 12; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[4]; + dst[5] = src[5]; + dst[6] = src[0]; + dst[7] = src[1]; + dst[8] = src[2]; + dst[9] = src[3]; + dst[10] = src[4]; + dst[11] = src[5]; + } + break; + case 16: + for (i = cvt->len_cvt / 12; i; --i) { + src -= 12; + dst -= 24; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[4]; + dst[5] = src[5]; + dst[6] = src[6]; + dst[7] = src[7]; + dst[8] = src[8]; + dst[9] = src[9]; + dst[10] = src[10]; + dst[11] = src[11]; + dst[12] = src[0]; + dst[13] = src[1]; + dst[14] = src[2]; + dst[15] = src[3]; + dst[16] = src[4]; + dst[17] = src[5]; + dst[18] = src[6]; + dst[19] = src[7]; + dst[20] = src[8]; + dst[21] = src[9]; + dst[22] = src[10]; + dst[23] = src[11]; + } + break; + } + cvt->len_cvt *= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate down by multiple of 2 */ -void SDLCALL SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateDIV2 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate / 2\n"); + fprintf (stderr, "Converting audio rate / 2\n"); #endif - src = cvt->buf; - dst = cvt->buf; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt/2; i; --i ) { - dst[0] = src[0]; - src += 2; - dst += 1; - } - break; - case 16: - for ( i=cvt->len_cvt/4; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - src += 4; - dst += 2; - } - break; - } - cvt->len_cvt /= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf; + dst = cvt->buf; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt / 2; i; --i) { + dst[0] = src[0]; + src += 2; + dst += 1; + } + break; + case 16: + for (i = cvt->len_cvt / 4; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 4; + dst += 2; + } + break; + } + cvt->len_cvt /= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate down by multiple of 2, for stereo */ -void SDLCALL SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateDIV2_c2 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate / 2\n"); + fprintf (stderr, "Converting audio rate / 2\n"); #endif - src = cvt->buf; - dst = cvt->buf; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt/4; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - src += 4; - dst += 2; - } - break; - case 16: - for ( i=cvt->len_cvt/8; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - src += 8; - dst += 4; - } - break; - } - cvt->len_cvt /= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf; + dst = cvt->buf; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt / 4; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + src += 4; + dst += 2; + } + break; + case 16: + for (i = cvt->len_cvt / 8; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + src += 8; + dst += 4; + } + break; + } + cvt->len_cvt /= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate down by multiple of 2, for quad */ -void SDLCALL SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateDIV2_c4 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate / 2\n"); + fprintf (stderr, "Converting audio rate / 2\n"); #endif - src = cvt->buf; - dst = cvt->buf; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt/8; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - src += 8; - dst += 4; - } - break; - case 16: - for ( i=cvt->len_cvt/16; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - dst[6] = src[6]; - dst[7] = src[7]; - src += 16; - dst += 8; - } - break; - } - cvt->len_cvt /= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf; + dst = cvt->buf; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt / 8; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + src += 8; + dst += 4; + } + break; + case 16: + for (i = cvt->len_cvt / 16; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[4]; + dst[5] = src[5]; + dst[6] = src[6]; + dst[7] = src[7]; + src += 16; + dst += 8; + } + break; + } + cvt->len_cvt /= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Convert rate down by multiple of 2, for 5.1 */ -void SDLCALL SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateDIV2_c6 (SDL_AudioCVT * cvt, Uint16 format) { - int i; - Uint8 *src, *dst; + int i; + Uint8 *src, *dst; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate / 2\n"); + fprintf (stderr, "Converting audio rate / 2\n"); #endif - src = cvt->buf; - dst = cvt->buf; - switch (format & 0xFF) { - case 8: - for ( i=cvt->len_cvt/12; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - src += 12; - dst += 6; - } - break; - case 16: - for ( i=cvt->len_cvt/24; i; --i ) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - dst[6] = src[6]; - dst[7] = src[7]; - dst[8] = src[8]; - dst[9] = src[9]; - dst[10] = src[10]; - dst[11] = src[11]; - src += 24; - dst += 12; - } - break; - } - cvt->len_cvt /= 2; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + src = cvt->buf; + dst = cvt->buf; + switch (format & 0xFF) { + case 8: + for (i = cvt->len_cvt / 12; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[4]; + dst[5] = src[5]; + src += 12; + dst += 6; + } + break; + case 16: + for (i = cvt->len_cvt / 24; i; --i) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[4]; + dst[5] = src[5]; + dst[6] = src[6]; + dst[7] = src[7]; + dst[8] = src[8]; + dst[9] = src[9]; + dst[10] = src[10]; + dst[11] = src[11]; + src += 24; + dst += 12; + } + break; + } + cvt->len_cvt /= 2; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } /* Very slow rate conversion routine */ -void SDLCALL SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format) +void SDLCALL +SDL_RateSLOW (SDL_AudioCVT * cvt, Uint16 format) { - double ipos; - int i, clen; + double ipos; + int i, clen; #ifdef DEBUG_CONVERT - fprintf(stderr, "Converting audio rate * %4.4f\n", 1.0/cvt->rate_incr); + fprintf (stderr, "Converting audio rate * %4.4f\n", 1.0 / cvt->rate_incr); #endif - clen = (int)((double)cvt->len_cvt / cvt->rate_incr); - if ( cvt->rate_incr > 1.0 ) { - switch (format & 0xFF) { - case 8: { - Uint8 *output; - - output = cvt->buf; - ipos = 0.0; - for ( i=clen; i; --i ) { - *output = cvt->buf[(int)ipos]; - ipos += cvt->rate_incr; - output += 1; - } - } - break; - - case 16: { - Uint16 *output; - - clen &= ~1; - output = (Uint16 *)cvt->buf; - ipos = 0.0; - for ( i=clen/2; i; --i ) { - *output=((Uint16 *)cvt->buf)[(int)ipos]; - ipos += cvt->rate_incr; - output += 1; - } - } - break; - } - } else { - switch (format & 0xFF) { - case 8: { - Uint8 *output; - - output = cvt->buf+clen; - ipos = (double)cvt->len_cvt; - for ( i=clen; i; --i ) { - ipos -= cvt->rate_incr; - output -= 1; - *output = cvt->buf[(int)ipos]; - } - } - break; - - case 16: { - Uint16 *output; - - clen &= ~1; - output = (Uint16 *)(cvt->buf+clen); - ipos = (double)cvt->len_cvt/2; - for ( i=clen/2; i; --i ) { - ipos -= cvt->rate_incr; - output -= 1; - *output=((Uint16 *)cvt->buf)[(int)ipos]; - } - } - break; - } - } - cvt->len_cvt = clen; - if ( cvt->filters[++cvt->filter_index] ) { - cvt->filters[cvt->filter_index](cvt, format); - } + clen = (int) ((double) cvt->len_cvt / cvt->rate_incr); + if (cvt->rate_incr > 1.0) { + switch (format & 0xFF) { + case 8: + { + Uint8 *output; + + output = cvt->buf; + ipos = 0.0; + for (i = clen; i; --i) { + *output = cvt->buf[(int) ipos]; + ipos += cvt->rate_incr; + output += 1; + } + } + break; + + case 16: + { + Uint16 *output; + + clen &= ~1; + output = (Uint16 *) cvt->buf; + ipos = 0.0; + for (i = clen / 2; i; --i) { + *output = ((Uint16 *) cvt->buf)[(int) ipos]; + ipos += cvt->rate_incr; + output += 1; + } + } + break; + } + } else { + switch (format & 0xFF) { + case 8: + { + Uint8 *output; + + output = cvt->buf + clen; + ipos = (double) cvt->len_cvt; + for (i = clen; i; --i) { + ipos -= cvt->rate_incr; + output -= 1; + *output = cvt->buf[(int) ipos]; + } + } + break; + + case 16: + { + Uint16 *output; + + clen &= ~1; + output = (Uint16 *) (cvt->buf + clen); + ipos = (double) cvt->len_cvt / 2; + for (i = clen / 2; i; --i) { + ipos -= cvt->rate_incr; + output -= 1; + *output = ((Uint16 *) cvt->buf)[(int) ipos]; + } + } + break; + } + } + cvt->len_cvt = clen; + if (cvt->filters[++cvt->filter_index]) { + cvt->filters[cvt->filter_index] (cvt, format); + } } -int SDL_ConvertAudio(SDL_AudioCVT *cvt) +int +SDL_ConvertAudio (SDL_AudioCVT * cvt) { - /* Make sure there's data to convert */ - if ( cvt->buf == NULL ) { - SDL_SetError("No buffer allocated for conversion"); - return(-1); - } - /* Return okay if no conversion is necessary */ - cvt->len_cvt = cvt->len; - if ( cvt->filters[0] == NULL ) { - return(0); - } - - /* Set up the conversion and go! */ - cvt->filter_index = 0; - cvt->filters[0](cvt, cvt->src_format); - return(0); + /* Make sure there's data to convert */ + if (cvt->buf == NULL) { + SDL_SetError ("No buffer allocated for conversion"); + return (-1); + } + /* Return okay if no conversion is necessary */ + cvt->len_cvt = cvt->len; + if (cvt->filters[0] == NULL) { + return (0); + } + + /* Set up the conversion and go! */ + cvt->filter_index = 0; + cvt->filters[0] (cvt, cvt->src_format); + return (0); } /* Creates a set of audio filters to convert from one format to another. Returns -1 if the format conversion is not supported, or 1 if the audio filter is set up. */ - -int SDL_BuildAudioCVT(SDL_AudioCVT *cvt, - Uint16 src_format, Uint8 src_channels, int src_rate, - Uint16 dst_format, Uint8 dst_channels, int dst_rate) + +int +SDL_BuildAudioCVT (SDL_AudioCVT * cvt, + Uint16 src_format, Uint8 src_channels, int src_rate, + Uint16 dst_format, Uint8 dst_channels, int dst_rate) { /*printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n", src_format, dst_format, src_channels, dst_channels, src_rate, dst_rate);*/ - /* Start off with no conversion necessary */ - cvt->needed = 0; - cvt->filter_index = 0; - cvt->filters[0] = NULL; - cvt->len_mult = 1; - cvt->len_ratio = 1.0; - - /* First filter: Endian conversion from src to dst */ - if ( (src_format & 0x1000) != (dst_format & 0x1000) - && ((src_format & 0xff) != 8) ) { - cvt->filters[cvt->filter_index++] = SDL_ConvertEndian; - } - - /* Second filter: Sign conversion -- signed/unsigned */ - if ( (src_format & 0x8000) != (dst_format & 0x8000) ) { - cvt->filters[cvt->filter_index++] = SDL_ConvertSign; - } - - /* Next filter: Convert 16 bit <--> 8 bit PCM */ - if ( (src_format & 0xFF) != (dst_format & 0xFF) ) { - switch (dst_format&0x10FF) { - case AUDIO_U8: - cvt->filters[cvt->filter_index++] = - SDL_Convert8; - cvt->len_ratio /= 2; - break; - case AUDIO_U16LSB: - cvt->filters[cvt->filter_index++] = - SDL_Convert16LSB; - cvt->len_mult *= 2; - cvt->len_ratio *= 2; - break; - case AUDIO_U16MSB: - cvt->filters[cvt->filter_index++] = - SDL_Convert16MSB; - cvt->len_mult *= 2; - cvt->len_ratio *= 2; - break; - } - } - - /* Last filter: Mono/Stereo conversion */ - if ( src_channels != dst_channels ) { - if ( (src_channels == 1) && (dst_channels > 1) ) { - cvt->filters[cvt->filter_index++] = - SDL_ConvertStereo; - cvt->len_mult *= 2; - src_channels = 2; - cvt->len_ratio *= 2; - } - if ( (src_channels == 2) && - (dst_channels == 6) ) { - cvt->filters[cvt->filter_index++] = - SDL_ConvertSurround; - src_channels = 6; - cvt->len_mult *= 3; - cvt->len_ratio *= 3; - } - if ( (src_channels == 2) && - (dst_channels == 4) ) { - cvt->filters[cvt->filter_index++] = - SDL_ConvertSurround_4; - src_channels = 4; - cvt->len_mult *= 2; - cvt->len_ratio *= 2; - } - while ( (src_channels*2) <= dst_channels ) { - cvt->filters[cvt->filter_index++] = - SDL_ConvertStereo; - cvt->len_mult *= 2; - src_channels *= 2; - cvt->len_ratio *= 2; - } - if ( (src_channels == 6) && - (dst_channels <= 2) ) { - cvt->filters[cvt->filter_index++] = - SDL_ConvertStrip; - src_channels = 2; - cvt->len_ratio /= 3; - } - if ( (src_channels == 6) && - (dst_channels == 4) ) { - cvt->filters[cvt->filter_index++] = - SDL_ConvertStrip_2; - src_channels = 4; - cvt->len_ratio /= 2; - } - /* This assumes that 4 channel audio is in the format: - Left {front/back} + Right {front/back} - so converting to L/R stereo works properly. - */ - while ( ((src_channels%2) == 0) && - ((src_channels/2) >= dst_channels) ) { - cvt->filters[cvt->filter_index++] = - SDL_ConvertMono; - src_channels /= 2; - cvt->len_ratio /= 2; - } - if ( src_channels != dst_channels ) { - /* Uh oh.. */; - } - } - - /* Do rate conversion */ - cvt->rate_incr = 0.0; - if ( (src_rate/100) != (dst_rate/100) ) { - Uint32 hi_rate, lo_rate; - int len_mult; - double len_ratio; - void (SDLCALL *rate_cvt)(SDL_AudioCVT *cvt, Uint16 format); - - if ( src_rate > dst_rate ) { - hi_rate = src_rate; - lo_rate = dst_rate; - switch (src_channels) { - case 1: rate_cvt = SDL_RateDIV2; break; - case 2: rate_cvt = SDL_RateDIV2_c2; break; - case 4: rate_cvt = SDL_RateDIV2_c4; break; - case 6: rate_cvt = SDL_RateDIV2_c6; break; - default: return -1; - } - len_mult = 1; - len_ratio = 0.5; - } else { - hi_rate = dst_rate; - lo_rate = src_rate; - switch (src_channels) { - case 1: rate_cvt = SDL_RateMUL2; break; - case 2: rate_cvt = SDL_RateMUL2_c2; break; - case 4: rate_cvt = SDL_RateMUL2_c4; break; - case 6: rate_cvt = SDL_RateMUL2_c6; break; - default: return -1; - } - len_mult = 2; - len_ratio = 2.0; - } - /* If hi_rate = lo_rate*2^x then conversion is easy */ - while ( ((lo_rate*2)/100) <= (hi_rate/100) ) { - cvt->filters[cvt->filter_index++] = rate_cvt; - cvt->len_mult *= len_mult; - lo_rate *= 2; - cvt->len_ratio *= len_ratio; - } - /* We may need a slow conversion here to finish up */ - if ( (lo_rate/100) != (hi_rate/100) ) { + /* Start off with no conversion necessary */ + cvt->needed = 0; + cvt->filter_index = 0; + cvt->filters[0] = NULL; + cvt->len_mult = 1; + cvt->len_ratio = 1.0; + + /* First filter: Endian conversion from src to dst */ + if ((src_format & 0x1000) != (dst_format & 0x1000) + && ((src_format & 0xff) != 8)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertEndian; + } + + /* Second filter: Sign conversion -- signed/unsigned */ + if ((src_format & 0x8000) != (dst_format & 0x8000)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertSign; + } + + /* Next filter: Convert 16 bit <--> 8 bit PCM */ + if ((src_format & 0xFF) != (dst_format & 0xFF)) { + switch (dst_format & 0x10FF) { + case AUDIO_U8: + cvt->filters[cvt->filter_index++] = SDL_Convert8; + cvt->len_ratio /= 2; + break; + case AUDIO_U16LSB: + cvt->filters[cvt->filter_index++] = SDL_Convert16LSB; + cvt->len_mult *= 2; + cvt->len_ratio *= 2; + break; + case AUDIO_U16MSB: + cvt->filters[cvt->filter_index++] = SDL_Convert16MSB; + cvt->len_mult *= 2; + cvt->len_ratio *= 2; + break; + } + } + + /* Last filter: Mono/Stereo conversion */ + if (src_channels != dst_channels) { + if ((src_channels == 1) && (dst_channels > 1)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertStereo; + cvt->len_mult *= 2; + src_channels = 2; + cvt->len_ratio *= 2; + } + if ((src_channels == 2) && (dst_channels == 6)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertSurround; + src_channels = 6; + cvt->len_mult *= 3; + cvt->len_ratio *= 3; + } + if ((src_channels == 2) && (dst_channels == 4)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertSurround_4; + src_channels = 4; + cvt->len_mult *= 2; + cvt->len_ratio *= 2; + } + while ((src_channels * 2) <= dst_channels) { + cvt->filters[cvt->filter_index++] = SDL_ConvertStereo; + cvt->len_mult *= 2; + src_channels *= 2; + cvt->len_ratio *= 2; + } + if ((src_channels == 6) && (dst_channels <= 2)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertStrip; + src_channels = 2; + cvt->len_ratio /= 3; + } + if ((src_channels == 6) && (dst_channels == 4)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertStrip_2; + src_channels = 4; + cvt->len_ratio /= 2; + } + /* This assumes that 4 channel audio is in the format: + Left {front/back} + Right {front/back} + so converting to L/R stereo works properly. + */ + while (((src_channels % 2) == 0) && + ((src_channels / 2) >= dst_channels)) { + cvt->filters[cvt->filter_index++] = SDL_ConvertMono; + src_channels /= 2; + cvt->len_ratio /= 2; + } + if (src_channels != dst_channels) { + /* Uh oh.. */ ; + } + } + + /* Do rate conversion */ + cvt->rate_incr = 0.0; + if ((src_rate / 100) != (dst_rate / 100)) { + Uint32 hi_rate, lo_rate; + int len_mult; + double len_ratio; + void (SDLCALL * rate_cvt) (SDL_AudioCVT * cvt, Uint16 format); + + if (src_rate > dst_rate) { + hi_rate = src_rate; + lo_rate = dst_rate; + switch (src_channels) { + case 1: + rate_cvt = SDL_RateDIV2; + break; + case 2: + rate_cvt = SDL_RateDIV2_c2; + break; + case 4: + rate_cvt = SDL_RateDIV2_c4; + break; + case 6: + rate_cvt = SDL_RateDIV2_c6; + break; + default: + return -1; + } + len_mult = 1; + len_ratio = 0.5; + } else { + hi_rate = dst_rate; + lo_rate = src_rate; + switch (src_channels) { + case 1: + rate_cvt = SDL_RateMUL2; + break; + case 2: + rate_cvt = SDL_RateMUL2_c2; + break; + case 4: + rate_cvt = SDL_RateMUL2_c4; + break; + case 6: + rate_cvt = SDL_RateMUL2_c6; + break; + default: + return -1; + } + len_mult = 2; + len_ratio = 2.0; + } + /* If hi_rate = lo_rate*2^x then conversion is easy */ + while (((lo_rate * 2) / 100) <= (hi_rate / 100)) { + cvt->filters[cvt->filter_index++] = rate_cvt; + cvt->len_mult *= len_mult; + lo_rate *= 2; + cvt->len_ratio *= len_ratio; + } + /* We may need a slow conversion here to finish up */ + if ((lo_rate / 100) != (hi_rate / 100)) { #if 1 - /* The problem with this is that if the input buffer is - say 1K, and the conversion rate is say 1.1, then the - output buffer is 1.1K, which may not be an acceptable - buffer size for the audio driver (not a power of 2) - */ - /* For now, punt and hope the rate distortion isn't great. - */ + /* The problem with this is that if the input buffer is + say 1K, and the conversion rate is say 1.1, then the + output buffer is 1.1K, which may not be an acceptable + buffer size for the audio driver (not a power of 2) + */ + /* For now, punt and hope the rate distortion isn't great. + */ #else - if ( src_rate < dst_rate ) { - cvt->rate_incr = (double)lo_rate/hi_rate; - cvt->len_mult *= 2; - cvt->len_ratio /= cvt->rate_incr; - } else { - cvt->rate_incr = (double)hi_rate/lo_rate; - cvt->len_ratio *= cvt->rate_incr; - } - cvt->filters[cvt->filter_index++] = SDL_RateSLOW; + if (src_rate < dst_rate) { + cvt->rate_incr = (double) lo_rate / hi_rate; + cvt->len_mult *= 2; + cvt->len_ratio /= cvt->rate_incr; + } else { + cvt->rate_incr = (double) hi_rate / lo_rate; + cvt->len_ratio *= cvt->rate_incr; + } + cvt->filters[cvt->filter_index++] = SDL_RateSLOW; #endif - } - } - - /* Set up the filter information */ - if ( cvt->filter_index != 0 ) { - cvt->needed = 1; - cvt->src_format = src_format; - cvt->dst_format = dst_format; - cvt->len = 0; - cvt->buf = NULL; - cvt->filters[cvt->filter_index] = NULL; - } - return(cvt->needed); + } + } + + /* Set up the filter information */ + if (cvt->filter_index != 0) { + cvt->needed = 1; + cvt->src_format = src_format; + cvt->dst_format = dst_format; + cvt->len = 0; + cvt->buf = NULL; + cvt->filters[cvt->filter_index] = NULL; + } + return (cvt->needed); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_audiodev.c b/src/audio/SDL_audiodev.c index 90671f971..1cd68637b 100644 --- a/src/audio/SDL_audiodev.c +++ b/src/audio/SDL_audiodev.c @@ -47,53 +47,56 @@ #endif -int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) +int +SDL_OpenAudioPath (char *path, int maxlen, int flags, int classic) { - const char *audiodev; - int audio_fd; - char audiopath[1024]; - - /* Figure out what our audio device is */ - if ( ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) && - ((audiodev=SDL_getenv("AUDIODEV")) == NULL) ) { - if ( classic ) { - audiodev = _PATH_DEV_AUDIO; - } else { - struct stat sb; - - /* Added support for /dev/sound/\* in Linux 2.4 */ - if ( ((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) && - ((stat(_PATH_DEV_DSP24, &sb) == 0) && S_ISCHR(sb.st_mode)) ) { - audiodev = _PATH_DEV_DSP24; - } else { - audiodev = _PATH_DEV_DSP; - } - } - } - audio_fd = open(audiodev, flags, 0); - - /* If the first open fails, look for other devices */ - if ( (audio_fd < 0) && (SDL_strlen(audiodev) < (sizeof(audiopath)-3)) ) { - int exists, instance; - struct stat sb; - - instance = 1; - do { /* Don't use errno ENOENT - it may not be thread-safe */ - SDL_snprintf(audiopath, SDL_arraysize(audiopath), - "%s%d", audiodev, instance++); - exists = 0; - if ( stat(audiopath, &sb) == 0 ) { - exists = 1; - audio_fd = open(audiopath, flags, 0); - } - } while ( exists && (audio_fd < 0) ); - audiodev = audiopath; - } - if ( path != NULL ) { - SDL_strlcpy(path, audiodev, maxlen); - path[maxlen-1] = '\0'; - } - return(audio_fd); + const char *audiodev; + int audio_fd; + char audiopath[1024]; + + /* Figure out what our audio device is */ + if (((audiodev = SDL_getenv ("SDL_PATH_DSP")) == NULL) && + ((audiodev = SDL_getenv ("AUDIODEV")) == NULL)) { + if (classic) { + audiodev = _PATH_DEV_AUDIO; + } else { + struct stat sb; + + /* Added support for /dev/sound/\* in Linux 2.4 */ + if (((stat ("/dev/sound", &sb) == 0) && S_ISDIR (sb.st_mode)) + && ((stat (_PATH_DEV_DSP24, &sb) == 0) + && S_ISCHR (sb.st_mode))) { + audiodev = _PATH_DEV_DSP24; + } else { + audiodev = _PATH_DEV_DSP; + } + } + } + audio_fd = open (audiodev, flags, 0); + + /* If the first open fails, look for other devices */ + if ((audio_fd < 0) && (SDL_strlen (audiodev) < (sizeof (audiopath) - 3))) { + int exists, instance; + struct stat sb; + + instance = 1; + do { /* Don't use errno ENOENT - it may not be thread-safe */ + SDL_snprintf (audiopath, SDL_arraysize (audiopath), + "%s%d", audiodev, instance++); + exists = 0; + if (stat (audiopath, &sb) == 0) { + exists = 1; + audio_fd = open (audiopath, flags, 0); + } + } + while (exists && (audio_fd < 0)); + audiodev = audiopath; + } + if (path != NULL) { + SDL_strlcpy (path, audiodev, maxlen); + path[maxlen - 1] = '\0'; + } + return (audio_fd); } #elif SDL_AUDIO_DRIVER_PAUD @@ -110,70 +113,71 @@ int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) #define _PATH_DEV_DSP "/dev/%caud%c/%c" #endif -char devsettings[][3] = -{ - { 'p', '0', '1' }, { 'p', '0', '2' }, { 'p', '0', '3' }, { 'p', '0', '4' }, - { 'p', '1', '1' }, { 'p', '1', '2' }, { 'p', '1', '3' }, { 'p', '1', '4' }, - { 'p', '2', '1' }, { 'p', '2', '2' }, { 'p', '2', '3' }, { 'p', '2', '4' }, - { 'p', '3', '1' }, { 'p', '3', '2' }, { 'p', '3', '3' }, { 'p', '3', '4' }, - { 'b', '0', '1' }, { 'b', '0', '2' }, { 'b', '0', '3' }, { 'b', '0', '4' }, - { 'b', '1', '1' }, { 'b', '1', '2' }, { 'b', '1', '3' }, { 'b', '1', '4' }, - { 'b', '2', '1' }, { 'b', '2', '2' }, { 'b', '2', '3' }, { 'b', '2', '4' }, - { 'b', '3', '1' }, { 'b', '3', '2' }, { 'b', '3', '3' }, { 'b', '3', '4' }, - { '\0', '\0', '\0' } +char devsettings[][3] = { + {'p', '0', '1'}, {'p', '0', '2'}, {'p', '0', '3'}, {'p', '0', '4'}, + {'p', '1', '1'}, {'p', '1', '2'}, {'p', '1', '3'}, {'p', '1', '4'}, + {'p', '2', '1'}, {'p', '2', '2'}, {'p', '2', '3'}, {'p', '2', '4'}, + {'p', '3', '1'}, {'p', '3', '2'}, {'p', '3', '3'}, {'p', '3', '4'}, + {'b', '0', '1'}, {'b', '0', '2'}, {'b', '0', '3'}, {'b', '0', '4'}, + {'b', '1', '1'}, {'b', '1', '2'}, {'b', '1', '3'}, {'b', '1', '4'}, + {'b', '2', '1'}, {'b', '2', '2'}, {'b', '2', '3'}, {'b', '2', '4'}, + {'b', '3', '1'}, {'b', '3', '2'}, {'b', '3', '3'}, {'b', '3', '4'}, + {'\0', '\0', '\0'} }; -static int OpenUserDefinedDevice(char *path, int maxlen, int flags) +static int +OpenUserDefinedDevice (char *path, int maxlen, int flags) { - const char *audiodev; - int audio_fd; - - /* Figure out what our audio device is */ - if ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) { - audiodev=SDL_getenv("AUDIODEV"); - } - if ( audiodev == NULL ) { - return -1; - } - audio_fd = open(audiodev, flags, 0); - if ( path != NULL ) { - SDL_strlcpy(path, audiodev, maxlen); - path[maxlen-1] = '\0'; - } - return audio_fd; + const char *audiodev; + int audio_fd; + + /* Figure out what our audio device is */ + if ((audiodev = SDL_getenv ("SDL_PATH_DSP")) == NULL) { + audiodev = SDL_getenv ("AUDIODEV"); + } + if (audiodev == NULL) { + return -1; + } + audio_fd = open (audiodev, flags, 0); + if (path != NULL) { + SDL_strlcpy (path, audiodev, maxlen); + path[maxlen - 1] = '\0'; + } + return audio_fd; } -int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) +int +SDL_OpenAudioPath (char *path, int maxlen, int flags, int classic) { struct stat sb; - int audio_fd; - char audiopath[1024]; - int cycle; + int audio_fd; + char audiopath[1024]; + int cycle; - audio_fd = OpenUserDefinedDevice(path,maxlen,flags); - if ( audio_fd != -1 ) { + audio_fd = OpenUserDefinedDevice (path, maxlen, flags); + if (audio_fd != -1) { return audio_fd; } - cycle = 0; - while( devsettings[cycle][0] != '\0' ) { - SDL_snprintf( audiopath, SDL_arraysize(audiopath), - _PATH_DEV_DSP, - devsettings[cycle][0], - devsettings[cycle][1], - devsettings[cycle][2]); - - if ( stat(audiopath, &sb) == 0 ) { - audio_fd = open(audiopath, flags, 0); - if ( audio_fd > 0 ) { - if ( path != NULL ) { - SDL_strlcpy( path, audiopath, maxlen ); - } - return audio_fd; - } - } + cycle = 0; + while (devsettings[cycle][0] != '\0') { + SDL_snprintf (audiopath, SDL_arraysize (audiopath), + _PATH_DEV_DSP, + devsettings[cycle][0], + devsettings[cycle][1], devsettings[cycle][2]); + + if (stat (audiopath, &sb) == 0) { + audio_fd = open (audiopath, flags, 0); + if (audio_fd > 0) { + if (path != NULL) { + SDL_strlcpy (path, audiopath, maxlen); + } + return audio_fd; + } + } } return -1; } #endif /* Audio driver selection */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_audiodev_c.h b/src/audio/SDL_audiodev_c.h index 055fd6541..bdc9b8844 100644 --- a/src/audio/SDL_audiodev_c.h +++ b/src/audio/SDL_audiodev_c.h @@ -22,5 +22,5 @@ #include "SDL_config.h" /* Open the audio device, storing the pathname in 'path' */ -extern int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic); - +extern int SDL_OpenAudioPath (char *path, int maxlen, int flags, int classic); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_audiomem.h b/src/audio/SDL_audiomem.h index 3d759eb3f..b611de884 100644 --- a/src/audio/SDL_audiomem.h +++ b/src/audio/SDL_audiomem.h @@ -23,3 +23,4 @@ #define SDL_AllocAudioMem SDL_malloc #define SDL_FreeAudioMem SDL_free +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_mixer.c b/src/audio/SDL_mixer.c index 5e07a0720..7d2cca60e 100644 --- a/src/audio/SDL_mixer.c +++ b/src/audio/SDL_mixer.c @@ -35,224 +35,227 @@ * the value to avoid overflow. (used with permission from ARDI) * Changed to use 0xFE instead of 0xFF for better sound quality. */ -static const Uint8 mix8[] = -{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, - 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, - 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, - 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, - 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, - 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, - 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, - 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, - 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, - 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, - 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, - 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, - 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, - 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, - 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE +static const Uint8 mix8[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, + 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, + 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, + 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, + 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, + 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, + 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, + 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, + 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, + 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, + 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, + 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, + 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, + 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE }; /* The volume ranges from 0 - 128 */ #define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME) #define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128) -void SDL_MixAudio (Uint8 *dst, const Uint8 *src, Uint32 len, int volume) +void +SDL_MixAudio (Uint8 * dst, const Uint8 * src, Uint32 len, int volume) { - Uint16 format; + Uint16 format; - if ( volume == 0 ) { - return; - } - /* Mix the user-level audio format */ - if ( current_audio ) { - if ( current_audio->convert.needed ) { - format = current_audio->convert.src_format; - } else { - format = current_audio->spec.format; - } - } else { - /* HACK HACK HACK */ - format = AUDIO_S16; - } - switch (format) { + if (volume == 0) { + return; + } + /* Mix the user-level audio format */ + if (current_audio) { + if (current_audio->convert.needed) { + format = current_audio->convert.src_format; + } else { + format = current_audio->spec.format; + } + } else { + /* HACK HACK HACK */ + format = AUDIO_S16; + } + switch (format) { - case AUDIO_U8: { + case AUDIO_U8: + { #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) - SDL_MixAudio_m68k_U8((char*)dst,(char*)src,(unsigned long)len,(long)volume,(char *)mix8); + SDL_MixAudio_m68k_U8 ((char *) dst, (char *) src, + (unsigned long) len, (long) volume, + (char *) mix8); #else - Uint8 src_sample; + Uint8 src_sample; - while ( len-- ) { - src_sample = *src; - ADJUST_VOLUME_U8(src_sample, volume); - *dst = mix8[*dst+src_sample]; - ++dst; - ++src; - } + while (len--) { + src_sample = *src; + ADJUST_VOLUME_U8 (src_sample, volume); + *dst = mix8[*dst + src_sample]; + ++dst; + ++src; + } #endif - } - break; + } + break; - case AUDIO_S8: { + case AUDIO_S8: + { #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) - if (SDL_HasMMX()) - { - SDL_MixAudio_MMX_S8((char*)dst,(char*)src,(unsigned int)len,(int)volume); - } - else + if (SDL_HasMMX ()) { + SDL_MixAudio_MMX_S8 ((char *) dst, (char *) src, + (unsigned int) len, (int) volume); + } else #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) - if (SDL_HasMMX()) - { - SDL_MixAudio_MMX_S8_VC((char*)dst,(char*)src,(unsigned int)len,(int)volume); - } - else + if (SDL_HasMMX ()) { + SDL_MixAudio_MMX_S8_VC ((char *) dst, (char *) src, + (unsigned int) len, (int) volume); + } else #endif #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) - SDL_MixAudio_m68k_S8((char*)dst,(char*)src,(unsigned long)len,(long)volume); + SDL_MixAudio_m68k_S8 ((char *) dst, (char *) src, + (unsigned long) len, (long) volume); #else - { - Sint8 *dst8, *src8; - Sint8 src_sample; - int dst_sample; - const int max_audioval = ((1<<(8-1))-1); - const int min_audioval = -(1<<(8-1)); + { + Sint8 *dst8, *src8; + Sint8 src_sample; + int dst_sample; + const int max_audioval = ((1 << (8 - 1)) - 1); + const int min_audioval = -(1 << (8 - 1)); - src8 = (Sint8 *)src; - dst8 = (Sint8 *)dst; - while ( len-- ) { - src_sample = *src8; - ADJUST_VOLUME(src_sample, volume); - dst_sample = *dst8 + src_sample; - if ( dst_sample > max_audioval ) { - *dst8 = max_audioval; - } else - if ( dst_sample < min_audioval ) { - *dst8 = min_audioval; - } else { - *dst8 = dst_sample; - } - ++dst8; - ++src8; - } - } + src8 = (Sint8 *) src; + dst8 = (Sint8 *) dst; + while (len--) { + src_sample = *src8; + ADJUST_VOLUME (src_sample, volume); + dst_sample = *dst8 + src_sample; + if (dst_sample > max_audioval) { + *dst8 = max_audioval; + } else if (dst_sample < min_audioval) { + *dst8 = min_audioval; + } else { + *dst8 = dst_sample; + } + ++dst8; + ++src8; + } + } #endif - } - break; + } + break; - case AUDIO_S16LSB: { + case AUDIO_S16LSB: + { #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) - if (SDL_HasMMX()) - { - SDL_MixAudio_MMX_S16((char*)dst,(char*)src,(unsigned int)len,(int)volume); - } - else + if (SDL_HasMMX ()) { + SDL_MixAudio_MMX_S16 ((char *) dst, (char *) src, + (unsigned int) len, (int) volume); + } else #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) - if (SDL_HasMMX()) - { - SDL_MixAudio_MMX_S16_VC((char*)dst,(char*)src,(unsigned int)len,(int)volume); - } - else + if (SDL_HasMMX ()) { + SDL_MixAudio_MMX_S16_VC ((char *) dst, (char *) src, + (unsigned int) len, (int) volume); + } else #endif #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) - SDL_MixAudio_m68k_S16LSB((short*)dst,(short*)src,(unsigned long)len,(long)volume); + SDL_MixAudio_m68k_S16LSB ((short *) dst, (short *) src, + (unsigned long) len, (long) volume); #else - { - Sint16 src1, src2; - int dst_sample; - const int max_audioval = ((1<<(16-1))-1); - const int min_audioval = -(1<<(16-1)); + { + Sint16 src1, src2; + int dst_sample; + const int max_audioval = ((1 << (16 - 1)) - 1); + const int min_audioval = -(1 << (16 - 1)); - len /= 2; - while ( len-- ) { - src1 = ((src[1])<<8|src[0]); - ADJUST_VOLUME(src1, volume); - src2 = ((dst[1])<<8|dst[0]); - src += 2; - dst_sample = src1+src2; - if ( dst_sample > max_audioval ) { - dst_sample = max_audioval; - } else - if ( dst_sample < min_audioval ) { - dst_sample = min_audioval; - } - dst[0] = dst_sample&0xFF; - dst_sample >>= 8; - dst[1] = dst_sample&0xFF; - dst += 2; - } - } + len /= 2; + while (len--) { + src1 = ((src[1]) << 8 | src[0]); + ADJUST_VOLUME (src1, volume); + src2 = ((dst[1]) << 8 | dst[0]); + src += 2; + dst_sample = src1 + src2; + if (dst_sample > max_audioval) { + dst_sample = max_audioval; + } else if (dst_sample < min_audioval) { + dst_sample = min_audioval; + } + dst[0] = dst_sample & 0xFF; + dst_sample >>= 8; + dst[1] = dst_sample & 0xFF; + dst += 2; + } + } #endif - } - break; + } + break; - case AUDIO_S16MSB: { + case AUDIO_S16MSB: + { #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) - SDL_MixAudio_m68k_S16MSB((short*)dst,(short*)src,(unsigned long)len,(long)volume); + SDL_MixAudio_m68k_S16MSB ((short *) dst, (short *) src, + (unsigned long) len, (long) volume); #else - Sint16 src1, src2; - int dst_sample; - const int max_audioval = ((1<<(16-1))-1); - const int min_audioval = -(1<<(16-1)); + Sint16 src1, src2; + int dst_sample; + const int max_audioval = ((1 << (16 - 1)) - 1); + const int min_audioval = -(1 << (16 - 1)); - len /= 2; - while ( len-- ) { - src1 = ((src[0])<<8|src[1]); - ADJUST_VOLUME(src1, volume); - src2 = ((dst[0])<<8|dst[1]); - src += 2; - dst_sample = src1+src2; - if ( dst_sample > max_audioval ) { - dst_sample = max_audioval; - } else - if ( dst_sample < min_audioval ) { - dst_sample = min_audioval; - } - dst[1] = dst_sample&0xFF; - dst_sample >>= 8; - dst[0] = dst_sample&0xFF; - dst += 2; - } + len /= 2; + while (len--) { + src1 = ((src[0]) << 8 | src[1]); + ADJUST_VOLUME (src1, volume); + src2 = ((dst[0]) << 8 | dst[1]); + src += 2; + dst_sample = src1 + src2; + if (dst_sample > max_audioval) { + dst_sample = max_audioval; + } else if (dst_sample < min_audioval) { + dst_sample = min_audioval; + } + dst[1] = dst_sample & 0xFF; + dst_sample >>= 8; + dst[0] = dst_sample & 0xFF; + dst += 2; + } #endif - } - break; + } + break; - default: /* If this happens... FIXME! */ - SDL_SetError("SDL_MixAudio(): unknown audio format"); - return; - } + default: /* If this happens... FIXME! */ + SDL_SetError ("SDL_MixAudio(): unknown audio format"); + return; + } } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_mixer_MMX.c b/src/audio/SDL_mixer_MMX.c index 9d24ba054..cb18994c1 100644 --- a/src/audio/SDL_mixer_MMX.c +++ b/src/audio/SDL_mixer_MMX.c @@ -36,100 +36,50 @@ ***********************************************/ #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) -void SDL_MixAudio_MMX_S16(char* dst,char* src,unsigned int size,int volume) +void +SDL_MixAudio_MMX_S16 (char *dst, char *src, unsigned int size, int volume) { - __asm__ __volatile__ ( - -" movl %3,%%eax\n" /* eax = volume */ - -" movl %2,%%edx\n" /* edx = size */ - -" shrl $4,%%edx\n" /* process 16 bytes per iteration = 8 samples */ - -" jz .endS16\n" - -" pxor %%mm0,%%mm0\n" - -" movd %%eax,%%mm0\n" -" movq %%mm0,%%mm1\n" -" psllq $16,%%mm0\n" -" por %%mm1,%%mm0\n" -" psllq $16,%%mm0\n" -" por %%mm1,%%mm0\n" -" psllq $16,%%mm0\n" -" por %%mm1,%%mm0\n" /* mm0 = vol|vol|vol|vol */ - -".align 8\n" -" .mixloopS16:\n" - -" movq (%1),%%mm1\n" /* mm1 = a|b|c|d */ - -" movq %%mm1,%%mm2\n" /* mm2 = a|b|c|d */ - -" movq 8(%1),%%mm4\n" /* mm4 = e|f|g|h */ - - /* pré charger le buffer dst dans mm7 */ -" movq (%0),%%mm7\n" /* mm7 = dst[0] */ - - /* multiplier par le volume */ -" pmullw %%mm0,%%mm1\n" /* mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */ - -" pmulhw %%mm0,%%mm2\n" /* mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) */ -" movq %%mm4,%%mm5\n" /* mm5 = e|f|g|h */ - -" pmullw %%mm0,%%mm4\n" /* mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */ - -" pmulhw %%mm0,%%mm5\n" /* mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) */ -" movq %%mm1,%%mm3\n" /* mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */ - -" punpckhwd %%mm2,%%mm1\n" /* mm1 = a*v|b*v */ - -" movq %%mm4,%%mm6\n" /* mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */ -" punpcklwd %%mm2,%%mm3\n" /* mm3 = c*v|d*v */ - -" punpckhwd %%mm5,%%mm4\n" /* mm4 = e*f|f*v */ - -" punpcklwd %%mm5,%%mm6\n" /* mm6 = g*v|h*v */ - - /* pré charger le buffer dst dans mm5 */ -" movq 8(%0),%%mm5\n" /* mm5 = dst[1] */ - - /* diviser par 128 */ -" psrad $7,%%mm1\n" /* mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME */ -" add $16,%1\n" - -" psrad $7,%%mm3\n" /* mm3 = c*v/128|d*v/128 */ - -" psrad $7,%%mm4\n" /* mm4 = e*v/128|f*v/128 */ - - /* mm1 = le sample avec le volume modifié */ -" packssdw %%mm1,%%mm3\n" /* mm3 = s(a*v|b*v|c*v|d*v) */ - -" psrad $7,%%mm6\n" /* mm6= g*v/128|h*v/128 */ -" paddsw %%mm7,%%mm3\n" /* mm3 = adjust_volume(src)+dst */ - - /* mm4 = le sample avec le volume modifié */ -" packssdw %%mm4,%%mm6\n" /* mm6 = s(e*v|f*v|g*v|h*v) */ -" movq %%mm3,(%0)\n" - -" paddsw %%mm5,%%mm6\n" /* mm6 = adjust_volume(src)+dst */ - -" movq %%mm6,8(%0)\n" - -" add $16,%0\n" - -" dec %%edx\n" - -" jnz .mixloopS16\n" - -" emms\n" - -".endS16:\n" - : - : "r" (dst), "r"(src),"m"(size), - "m"(volume) - : "eax","edx","memory" - ); + __asm__ __volatile__ (" movl %3,%%eax\n" /* eax = volume */ + " movl %2,%%edx\n" /* edx = size */ + " shrl $4,%%edx\n" /* process 16 bytes per iteration = 8 samples */ + " jz .endS16\n" " pxor %%mm0,%%mm0\n" " movd %%eax,%%mm0\n" " movq %%mm0,%%mm1\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" /* mm0 = vol|vol|vol|vol */ + ".align 8\n" " .mixloopS16:\n" " movq (%1),%%mm1\n" /* mm1 = a|b|c|d */ + " movq %%mm1,%%mm2\n" /* mm2 = a|b|c|d */ + " movq 8(%1),%%mm4\n" /* mm4 = e|f|g|h */ + /* pré charger le buffer dst dans mm7 */ + " movq (%0),%%mm7\n" /* mm7 = dst[0] */ + /* multiplier par le volume */ + " pmullw %%mm0,%%mm1\n" /* mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */ + " pmulhw %%mm0,%%mm2\n" /* mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) */ + " movq %%mm4,%%mm5\n" /* mm5 = e|f|g|h */ + " pmullw %%mm0,%%mm4\n" /* mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */ + " pmulhw %%mm0,%%mm5\n" /* mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) */ + " movq %%mm1,%%mm3\n" /* mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */ + " punpckhwd %%mm2,%%mm1\n" /* mm1 = a*v|b*v */ + " movq %%mm4,%%mm6\n" /* mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */ + " punpcklwd %%mm2,%%mm3\n" /* mm3 = c*v|d*v */ + " punpckhwd %%mm5,%%mm4\n" /* mm4 = e*f|f*v */ + " punpcklwd %%mm5,%%mm6\n" /* mm6 = g*v|h*v */ + /* pré charger le buffer dst dans mm5 */ + " movq 8(%0),%%mm5\n" /* mm5 = dst[1] */ + /* diviser par 128 */ + " psrad $7,%%mm1\n" /* mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME */ + " add $16,%1\n" " psrad $7,%%mm3\n" /* mm3 = c*v/128|d*v/128 */ + " psrad $7,%%mm4\n" /* mm4 = e*v/128|f*v/128 */ + /* mm1 = le sample avec le volume modifié */ + " packssdw %%mm1,%%mm3\n" /* mm3 = s(a*v|b*v|c*v|d*v) */ + " psrad $7,%%mm6\n" /* mm6= g*v/128|h*v/128 */ + " paddsw %%mm7,%%mm3\n" /* mm3 = adjust_volume(src)+dst */ + /* mm4 = le sample avec le volume modifié */ + " packssdw %%mm4,%%mm6\n" /* mm6 = s(e*v|f*v|g*v|h*v) */ + " movq %%mm3,(%0)\n" " paddsw %%mm5,%%mm6\n" /* mm6 = adjust_volume(src)+dst */ + " movq %%mm6,8(%0)\n" + " add $16,%0\n" + " dec %%edx\n" + " jnz .mixloopS16\n" + " emms\n" + ".endS16:\n"::"r" (dst), "r" (src), + "m" (size), "m" (volume):"eax", "edx", "memory"); } @@ -138,69 +88,33 @@ void SDL_MixAudio_MMX_S16(char* dst,char* src,unsigned int size,int volume) /* Mixing for 8 bit signed buffers */ /*////////////////////////////////////////////// */ -void SDL_MixAudio_MMX_S8(char* dst,char* src,unsigned int size,int volume) +void +SDL_MixAudio_MMX_S8 (char *dst, char *src, unsigned int size, int volume) { - __asm__ __volatile__ ( - -" movl %3,%%eax\n" /* eax = volume */ - -" movd %%eax,%%mm0\n" -" movq %%mm0,%%mm1\n" -" psllq $16,%%mm0\n" -" por %%mm1,%%mm0\n" -" psllq $16,%%mm0\n" -" por %%mm1,%%mm0\n" -" psllq $16,%%mm0\n" -" por %%mm1,%%mm0\n" - -" movl %2,%%edx\n" /* edx = size */ -" shr $3,%%edx\n" /* process 8 bytes per iteration = 8 samples */ - -" cmp $0,%%edx\n" -" je .endS8\n" - -".align 8\n" -" .mixloopS8:\n" - -" pxor %%mm2,%%mm2\n" /* mm2 = 0 */ -" movq (%1),%%mm1\n" /* mm1 = a|b|c|d|e|f|g|h */ - -" movq %%mm1,%%mm3\n" /* mm3 = a|b|c|d|e|f|g|h */ - - /* on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 */ -" pcmpgtb %%mm1,%%mm2\n" /* mm2 = 11111111|00000000|00000000.... */ - -" punpckhbw %%mm2,%%mm1\n" /* mm1 = 0|a|0|b|0|c|0|d */ - -" punpcklbw %%mm2,%%mm3\n" /* mm3 = 0|e|0|f|0|g|0|h */ -" movq (%0),%%mm2\n" /* mm2 = destination */ - -" pmullw %%mm0,%%mm1\n" /* mm1 = v*a|v*b|v*c|v*d */ -" add $8,%1\n" - -" pmullw %%mm0,%%mm3\n" /* mm3 = v*e|v*f|v*g|v*h */ -" psraw $7,%%mm1\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128 */ - -" psraw $7,%%mm3\n" /* mm3 = v*e/128|v*f/128|v*g/128|v*h/128 */ - -" packsswb %%mm1,%%mm3\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128 */ - -" paddsb %%mm2,%%mm3\n" /* add to destination buffer */ - -" movq %%mm3,(%0)\n" /* store back to ram */ -" add $8,%0\n" - -" dec %%edx\n" - -" jnz .mixloopS8\n" - -".endS8:\n" -" emms\n" - : - : "r" (dst), "r"(src),"m"(size), - "m"(volume) - : "eax","edx","memory" - ); + __asm__ __volatile__ (" movl %3,%%eax\n" /* eax = volume */ + " movd %%eax,%%mm0\n" " movq %%mm0,%%mm1\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " movl %2,%%edx\n" /* edx = size */ + " shr $3,%%edx\n" /* process 8 bytes per iteration = 8 samples */ + " cmp $0,%%edx\n" " je .endS8\n" ".align 8\n" " .mixloopS8:\n" " pxor %%mm2,%%mm2\n" /* mm2 = 0 */ + " movq (%1),%%mm1\n" /* mm1 = a|b|c|d|e|f|g|h */ + " movq %%mm1,%%mm3\n" /* mm3 = a|b|c|d|e|f|g|h */ + /* on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 */ + " pcmpgtb %%mm1,%%mm2\n" /* mm2 = 11111111|00000000|00000000.... */ + " punpckhbw %%mm2,%%mm1\n" /* mm1 = 0|a|0|b|0|c|0|d */ + " punpcklbw %%mm2,%%mm3\n" /* mm3 = 0|e|0|f|0|g|0|h */ + " movq (%0),%%mm2\n" /* mm2 = destination */ + " pmullw %%mm0,%%mm1\n" /* mm1 = v*a|v*b|v*c|v*d */ + " add $8,%1\n" " pmullw %%mm0,%%mm3\n" /* mm3 = v*e|v*f|v*g|v*h */ + " psraw $7,%%mm1\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128 */ + " psraw $7,%%mm3\n" /* mm3 = v*e/128|v*f/128|v*g/128|v*h/128 */ + " packsswb %%mm1,%%mm3\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128 */ + " paddsb %%mm2,%%mm3\n" /* add to destination buffer */ + " movq %%mm3,(%0)\n" /* store back to ram */ + " add $8,%0\n" + " dec %%edx\n" + " jnz .mixloopS8\n" + ".endS8:\n" + " emms\n"::"r" (dst), "r" (src), "m" (size), + "m" (volume):"eax", "edx", "memory"); } #endif - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_mixer_MMX.h b/src/audio/SDL_mixer_MMX.h index 5a62683b2..28d0ab4e4 100644 --- a/src/audio/SDL_mixer_MMX.h +++ b/src/audio/SDL_mixer_MMX.h @@ -9,7 +9,7 @@ #include "SDL_config.h" #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) -void SDL_MixAudio_MMX_S16(char* ,char* ,unsigned int ,int ); -void SDL_MixAudio_MMX_S8(char* ,char* ,unsigned int ,int ); +void SDL_MixAudio_MMX_S16 (char *, char *, unsigned int, int); +void SDL_MixAudio_MMX_S8 (char *, char *, unsigned int, int); #endif - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_mixer_MMX_VC.c b/src/audio/SDL_mixer_MMX_VC.c index 89b646a05..6f23fffbf 100644 --- a/src/audio/SDL_mixer_MMX_VC.c +++ b/src/audio/SDL_mixer_MMX_VC.c @@ -37,80 +37,63 @@ // Mixing for 16 bit signed buffers //////////////////////////////////////////////// -void SDL_MixAudio_MMX_S16_VC(char* dst,char* src,unsigned int nSize,int volume) +void +SDL_MixAudio_MMX_S16_VC (char *dst, char *src, unsigned int nSize, int volume) { - __asm - { - - push edi - push esi - push ebx - - mov edi, dst // edi = dst - mov esi, src // esi = src - mov eax, volume // eax = volume - mov ebx, nSize // ebx = size - shr ebx, 4 // process 16 bytes per iteration = 8 samples - jz endS16 - - pxor mm0, mm0 - movd mm0, eax //%%eax,%%mm0 - movq mm1, mm0 //%%mm0,%%mm1 - psllq mm0, 16 //$16,%%mm0 - por mm0, mm1 //%%mm1,%%mm0 - psllq mm0, 16 //$16,%%mm0 - por mm0, mm1 //%%mm1,%%mm0 - psllq mm0, 16 //$16,%%mm0 - por mm0, mm1 //%%mm1,%%mm0 // mm0 = vol|vol|vol|vol - - #ifndef __WATCOMC__ - align 16 - #endif -mixloopS16: - movq mm1, [esi] //(%%esi),%%mm1\n" // mm1 = a|b|c|d - movq mm2, mm1 //%%mm1,%%mm2\n" // mm2 = a|b|c|d - movq mm4, [esi + 8] //8(%%esi),%%mm4\n" // mm4 = e|f|g|h - // pre charger le buffer dst dans mm7 - movq mm7, [edi] //(%%edi),%%mm7\n" // mm7 = dst[0]" - // multiplier par le volume - pmullw mm1, mm0 //%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) - pmulhw mm2, mm0 //%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) - movq mm5, mm4 //%%mm4,%%mm5\n" // mm5 = e|f|g|h - pmullw mm4, mm0 //%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) - pmulhw mm5, mm0 //%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) - movq mm3, mm1 //%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) - punpckhwd mm1, mm2 //%%mm2,%%mm1\n" // mm1 = a*v|b*v - movq mm6, mm4 //%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) - punpcklwd mm3, mm2 //%%mm2,%%mm3\n" // mm3 = c*v|d*v - punpckhwd mm4, mm5 //%%mm5,%%mm4\n" // mm4 = e*f|f*v - punpcklwd mm6, mm5 //%%mm5,%%mm6\n" // mm6 = g*v|h*v - // pre charger le buffer dst dans mm5 - movq mm5, [edi + 8] //8(%%edi),%%mm5\n" // mm5 = dst[1] - // diviser par 128 - psrad mm1, 7 //$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME - add esi, 16 //$16,%%esi\n" - psrad mm3, 7 //$7,%%mm3\n" // mm3 = c*v/128|d*v/128 - psrad mm4, 7 //$7,%%mm4\n" // mm4 = e*v/128|f*v/128 - // mm1 = le sample avec le volume modifie - packssdw mm3, mm1 //%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v) - psrad mm6, 7 //$7,%%mm6\n" // mm6= g*v/128|h*v/128 - paddsw mm3, mm7 //%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst - // mm4 = le sample avec le volume modifie - packssdw mm6, mm4 //%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v) - movq [edi], mm3 //%%mm3,(%%edi)\n" - paddsw mm6, mm5 //%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst - movq [edi + 8], mm6 //%%mm6,8(%%edi)\n" - add edi, 16 //$16,%%edi\n" - dec ebx //%%ebx\n" - jnz mixloopS16 - -ends16: - emms - - pop ebx - pop esi - pop edi - } + __asm { + + push edi push esi push ebx mov edi, dst // edi = dst + mov esi, src // esi = src + mov eax, volume // eax = volume + mov ebx, nSize // ebx = size + shr ebx, 4 // process 16 bytes per iteration = 8 samples + jz endS16 pxor mm0, mm0 movd mm0, eax //%%eax,%%mm0 + movq mm1, mm0 //%%mm0,%%mm1 + psllq mm0, 16 //$16,%%mm0 + por mm0, mm1 //%%mm1,%%mm0 + psllq mm0, 16 //$16,%%mm0 + por mm0, mm1 //%%mm1,%%mm0 + psllq mm0, 16 //$16,%%mm0 + por mm0, mm1 //%%mm1,%%mm0 // mm0 = vol|vol|vol|vol +#ifndef __WATCOMC__ + align 16 +#endif + mixloopS16:movq mm1,[esi] //(%%esi),%%mm1\n" // mm1 = a|b|c|d + movq mm2, mm1 //%%mm1,%%mm2\n" // mm2 = a|b|c|d + movq mm4,[esi + 8] //8(%%esi),%%mm4\n" // mm4 = e|f|g|h + // pre charger le buffer dst dans mm7 + movq mm7,[edi] //(%%edi),%%mm7\n" // mm7 = dst[0]" + // multiplier par le volume + pmullw mm1, mm0 //%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) + pmulhw mm2, mm0 //%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) + movq mm5, mm4 //%%mm4,%%mm5\n" // mm5 = e|f|g|h + pmullw mm4, mm0 //%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) + pmulhw mm5, mm0 //%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) + movq mm3, mm1 //%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) + punpckhwd mm1, mm2 //%%mm2,%%mm1\n" // mm1 = a*v|b*v + movq mm6, mm4 //%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) + punpcklwd mm3, mm2 //%%mm2,%%mm3\n" // mm3 = c*v|d*v + punpckhwd mm4, mm5 //%%mm5,%%mm4\n" // mm4 = e*f|f*v + punpcklwd mm6, mm5 //%%mm5,%%mm6\n" // mm6 = g*v|h*v + // pre charger le buffer dst dans mm5 + movq mm5,[edi + 8] //8(%%edi),%%mm5\n" // mm5 = dst[1] + // diviser par 128 + psrad mm1, 7 //$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME + add esi, 16 //$16,%%esi\n" + psrad mm3, 7 //$7,%%mm3\n" // mm3 = c*v/128|d*v/128 + psrad mm4, 7 //$7,%%mm4\n" // mm4 = e*v/128|f*v/128 + // mm1 = le sample avec le volume modifie + packssdw mm3, mm1 //%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v) + psrad mm6, 7 //$7,%%mm6\n" // mm6= g*v/128|h*v/128 + paddsw mm3, mm7 //%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst + // mm4 = le sample avec le volume modifie + packssdw mm6, mm4 //%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v) + movq[edi], mm3 //%%mm3,(%%edi)\n" + paddsw mm6, mm5 //%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst + movq[edi + 8], mm6 //%%mm6,8(%%edi)\n" + add edi, 16 //$16,%%edi\n" + dec ebx //%%ebx\n" + jnz mixloopS16 ends16:emms pop ebx pop esi pop edi} } @@ -118,64 +101,49 @@ void SDL_MixAudio_MMX_S16_VC(char* dst,char* src,unsigned int nSize,int volume) // Mixing for 8 bit signed buffers //////////////////////////////////////////////// -void SDL_MixAudio_MMX_S8_VC(char* dst,char* src,unsigned int nSize,int volume) +void +SDL_MixAudio_MMX_S8_VC (char *dst, char *src, unsigned int nSize, int volume) { - _asm - { - - push edi - push esi - push ebx - - mov edi, dst //movl %0,%%edi // edi = dst - mov esi, src //%1,%%esi // esi = src - mov eax, volume //%3,%%eax // eax = volume - - movd mm0, eax //%%eax,%%mm0 - movq mm1, mm0 //%%mm0,%%mm1 - psllq mm0, 16 //$16,%%mm0 - por mm0, mm1 //%%mm1,%%mm0 - psllq mm0, 16 //$16,%%mm0 - por mm0, mm1 //%%mm1,%%mm0 - psllq mm0, 16 //$16,%%mm0 - por mm0, mm1 //%%mm1,%%mm0 - - mov ebx, nSize //%2,%%ebx // ebx = size - shr ebx, 3 //$3,%%ebx // process 8 bytes per iteration = 8 samples - cmp ebx, 0 //$0,%%ebx - je endS8 - - #ifndef __WATCOMC__ - align 16 - #endif -mixloopS8: - pxor mm2, mm2 //%%mm2,%%mm2 // mm2 = 0 - movq mm1, [esi] //(%%esi),%%mm1 // mm1 = a|b|c|d|e|f|g|h - movq mm3, mm1 //%%mm1,%%mm3 // mm3 = a|b|c|d|e|f|g|h - // on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 - pcmpgtb mm2, mm1 //%%mm1,%%mm2 // mm2 = 11111111|00000000|00000000.... - punpckhbw mm1, mm2 //%%mm2,%%mm1 // mm1 = 0|a|0|b|0|c|0|d - punpcklbw mm3, mm2 //%%mm2,%%mm3 // mm3 = 0|e|0|f|0|g|0|h - movq mm2, [edi] //(%%edi),%%mm2 // mm2 = destination - pmullw mm1, mm0 //%%mm0,%%mm1 // mm1 = v*a|v*b|v*c|v*d - add esi, 8 //$8,%%esi - pmullw mm3, mm0 //%%mm0,%%mm3 // mm3 = v*e|v*f|v*g|v*h - psraw mm1, 7 //$7,%%mm1 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128 - psraw mm3, 7 //$7,%%mm3 // mm3 = v*e/128|v*f/128|v*g/128|v*h/128 - packsswb mm3, mm1 //%%mm1,%%mm3 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128 - paddsb mm3, mm2 //%%mm2,%%mm3 // add to destination buffer - movq [edi], mm3 //%%mm3,(%%edi) // store back to ram - add edi, 8 //$8,%%edi - dec ebx //%%ebx - jnz mixloopS8 - -endS8: - emms - - pop ebx - pop esi - pop edi - } + _asm { + + push edi push esi push ebx mov edi, dst //movl %0,%%edi // edi = dst + mov esi, src //%1,%%esi // esi = src + mov eax, volume //%3,%%eax // eax = volume + movd mm0, eax //%%eax,%%mm0 + movq mm1, mm0 //%%mm0,%%mm1 + psllq mm0, 16 //$16,%%mm0 + por mm0, mm1 //%%mm1,%%mm0 + psllq mm0, 16 //$16,%%mm0 + por mm0, mm1 //%%mm1,%%mm0 + psllq mm0, 16 //$16,%%mm0 + por mm0, mm1 //%%mm1,%%mm0 + mov ebx, nSize //%2,%%ebx // ebx = size + shr ebx, 3 //$3,%%ebx // process 8 bytes per iteration = 8 samples + cmp ebx, 0 //$0,%%ebx + je endS8 +#ifndef __WATCOMC__ + align 16 +#endif + mixloopS8:pxor mm2, mm2 //%%mm2,%%mm2 // mm2 = 0 + movq mm1,[esi] //(%%esi),%%mm1 // mm1 = a|b|c|d|e|f|g|h + movq mm3, mm1 //%%mm1,%%mm3 // mm3 = a|b|c|d|e|f|g|h + // on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 + pcmpgtb mm2, mm1 //%%mm1,%%mm2 // mm2 = 11111111|00000000|00000000.... + punpckhbw mm1, mm2 //%%mm2,%%mm1 // mm1 = 0|a|0|b|0|c|0|d + punpcklbw mm3, mm2 //%%mm2,%%mm3 // mm3 = 0|e|0|f|0|g|0|h + movq mm2,[edi] //(%%edi),%%mm2 // mm2 = destination + pmullw mm1, mm0 //%%mm0,%%mm1 // mm1 = v*a|v*b|v*c|v*d + add esi, 8 //$8,%%esi + pmullw mm3, mm0 //%%mm0,%%mm3 // mm3 = v*e|v*f|v*g|v*h + psraw mm1, 7 //$7,%%mm1 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128 + psraw mm3, 7 //$7,%%mm3 // mm3 = v*e/128|v*f/128|v*g/128|v*h/128 + packsswb mm3, mm1 //%%mm1,%%mm3 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128 + paddsb mm3, mm2 //%%mm2,%%mm3 // add to destination buffer + movq[edi], mm3 //%%mm3,(%%edi) // store back to ram + add edi, 8 //$8,%%edi + dec ebx //%%ebx + jnz mixloopS8 endS8:emms pop ebx pop esi pop edi} } -#endif /* SDL_ASSEMBLY_ROUTINES */ +#endif /* SDL_ASSEMBLY_ROUTINES */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_mixer_MMX_VC.h b/src/audio/SDL_mixer_MMX_VC.h index bfe02a988..77459faab 100644 --- a/src/audio/SDL_mixer_MMX_VC.h +++ b/src/audio/SDL_mixer_MMX_VC.h @@ -31,6 +31,7 @@ Assumes buffer size in bytes is a multiple of 16 Assumes SDL_MIX_MAXVOLUME = 128 */ -void SDL_MixAudio_MMX_S16_VC(char* ,char* ,unsigned int ,int ); -void SDL_MixAudio_MMX_S8_VC(char* ,char* ,unsigned int ,int ); +void SDL_MixAudio_MMX_S16_VC (char *, char *, unsigned int, int); +void SDL_MixAudio_MMX_S8_VC (char *, char *, unsigned int, int); #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_mixer_m68k.c b/src/audio/SDL_mixer_m68k.c index f8786da24..1de0681b7 100644 --- a/src/audio/SDL_mixer_m68k.c +++ b/src/audio/SDL_mixer_m68k.c @@ -28,184 +28,113 @@ */ #if defined(__M68000__) && defined(__GNUC__) -void SDL_MixAudio_m68k_U8(char* dst, char* src, long len, long volume, char* mix8) +void +SDL_MixAudio_m68k_U8 (char *dst, char *src, long len, long volume, char *mix8) { - __asm__ __volatile__ ( - - "tstl %2\n" -" beqs stoploop_u8\n" -"mixloop_u8:\n" - - /* Mix a sample */ - -" moveq #0,%%d0\n" -" moveq #0,%%d1\n" - -" moveb %1@+,%%d0\n" /* d0 = *src++ */ -" sub #128,%%d0\n" /* d0 -= 128 */ -" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ -" moveb %0@,%%d1\n" /* d1 = *dst */ -" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ -" add #128,%%d0\n" /* d0 += 128 */ - -" add %%d1,%%d0\n" - -" moveb %4@(%%d0:w),%0@+\n" - - /* Loop till done */ - -" subql #1,%2\n" -" bhis mixloop_u8\n" -"stoploop_u8:\n" - - : /* no return value */ - : /* input */ - "a"(dst), "a"(src), "d"(len), "d"(volume), "a"(mix8) - : /* clobbered registers */ - "d0", "d1", "cc", "memory" - ); + __asm__ __volatile__ ("tstl %2\n" " beqs stoploop_u8\n" "mixloop_u8:\n" + /* Mix a sample */ + " moveq #0,%%d0\n" " moveq #0,%%d1\n" " moveb %1@+,%%d0\n" /* d0 = *src++ */ + " sub #128,%%d0\n" /* d0 -= 128 */ + " muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ + " moveb %0@,%%d1\n" /* d1 = *dst */ + " asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ + " add #128,%%d0\n" /* d0 += 128 */ + " add %%d1,%%d0\n" + " moveb %4@(%%d0:w),%0@+\n" + /* Loop till done */ + " subql #1,%2\n" " bhis mixloop_u8\n" "stoploop_u8:\n": /* no return value */ + : /* input */ + "a" (dst), "a" (src), "d" (len), "d" (volume), "a" (mix8): /* clobbered registers */ + "d0", "d1", "cc", "memory"); } -void SDL_MixAudio_m68k_S8(char* dst, char* src, long len, long volume) +void +SDL_MixAudio_m68k_S8 (char *dst, char *src, long len, long volume) { - __asm__ __volatile__ ( - - "tstl %2\n" -" beqs stoploop_s8\n" -" moveq #-128,%%d2\n" -" moveq #127,%%d3\n" -"mixloop_s8:\n" - - /* Mix a sample */ - -" moveq #0,%%d0\n" -" moveq #0,%%d1\n" - -" moveb %1@+,%%d0\n" /* d0 = *src++ */ -" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ -" moveb %0@,%%d1\n" /* d1 = *dst */ -" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ - -" add %%d1,%%d0\n" - -" cmp %%d2,%%d0\n" -" bges lower_limit_s8\n" -" move %%d2,%%d0\n" -"lower_limit_s8:\n" - -" cmp %%d3,%%d0\n" -" bles upper_limit_s8\n" -" move %%d3,%%d0\n" -"upper_limit_s8:\n" -" moveb %%d0,%0@+\n" - - /* Loop till done */ - -" subql #1,%2\n" -" bhis mixloop_s8\n" -"stoploop_s8:\n" - - : /* no return value */ - : /* input */ - "a"(dst), "a"(src), "d"(len), "d"(volume) - : /* clobbered registers */ - "d0", "d1", "d2", "d3", "cc", "memory" - ); + __asm__ __volatile__ ("tstl %2\n" + " beqs stoploop_s8\n" + " moveq #-128,%%d2\n" + " moveq #127,%%d3\n" "mixloop_s8:\n" + /* Mix a sample */ + " moveq #0,%%d0\n" " moveq #0,%%d1\n" " moveb %1@+,%%d0\n" /* d0 = *src++ */ + " muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ + " moveb %0@,%%d1\n" /* d1 = *dst */ + " asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ + " add %%d1,%%d0\n" + " cmp %%d2,%%d0\n" + " bges lower_limit_s8\n" + " move %%d2,%%d0\n" + "lower_limit_s8:\n" + " cmp %%d3,%%d0\n" + " bles upper_limit_s8\n" + " move %%d3,%%d0\n" + "upper_limit_s8:\n" " moveb %%d0,%0@+\n" + /* Loop till done */ + " subql #1,%2\n" " bhis mixloop_s8\n" "stoploop_s8:\n": /* no return value */ + : /* input */ + "a" (dst), "a" (src), "d" (len), "d" (volume): /* clobbered registers */ + "d0", "d1", "d2", "d3", "cc", "memory"); } -void SDL_MixAudio_m68k_S16MSB(short* dst, short* src, long len, long volume) +void +SDL_MixAudio_m68k_S16MSB (short *dst, short *src, long len, long volume) { - __asm__ __volatile__ ( - - "tstl %2\n" -" beqs stoploop_s16msb\n" -" movel #-32768,%%d2\n" -" movel #32767,%%d3\n" -" lsrl #1,%2\n" -"mixloop_s16msb:\n" - - /* Mix a sample */ - -" move %1@+,%%d0\n" /* d0 = *src++ */ -" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ -" move %0@,%%d1\n" /* d1 = *dst */ -" extl %%d1\n" /* extend d1 to 32 bits */ -" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ - -" addl %%d1,%%d0\n" - -" cmpl %%d2,%%d0\n" -" bges lower_limit_s16msb\n" -" move %%d2,%%d0\n" -"lower_limit_s16msb:\n" - -" cmpl %%d3,%%d0\n" -" bles upper_limit_s16msb\n" -" move %%d3,%%d0\n" -"upper_limit_s16msb:\n" -" move %%d0,%0@+\n" - - /* Loop till done */ - -" subql #1,%2\n" -" bhis mixloop_s16msb\n" -"stoploop_s16msb:\n" - - : /* no return value */ - : /* input */ - "a"(dst), "a"(src), "d"(len), "d"(volume) - : /* clobbered registers */ - "d0", "d1", "d2", "d3", "cc", "memory" - ); + __asm__ __volatile__ ("tstl %2\n" + " beqs stoploop_s16msb\n" + " movel #-32768,%%d2\n" + " movel #32767,%%d3\n" + " lsrl #1,%2\n" "mixloop_s16msb:\n" + /* Mix a sample */ + " move %1@+,%%d0\n" /* d0 = *src++ */ + " muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ + " move %0@,%%d1\n" /* d1 = *dst */ + " extl %%d1\n" /* extend d1 to 32 bits */ + " asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ + " addl %%d1,%%d0\n" + " cmpl %%d2,%%d0\n" + " bges lower_limit_s16msb\n" + " move %%d2,%%d0\n" + "lower_limit_s16msb:\n" + " cmpl %%d3,%%d0\n" + " bles upper_limit_s16msb\n" + " move %%d3,%%d0\n" + "upper_limit_s16msb:\n" " move %%d0,%0@+\n" + /* Loop till done */ + " subql #1,%2\n" " bhis mixloop_s16msb\n" "stoploop_s16msb:\n": /* no return value */ + : /* input */ + "a" (dst), "a" (src), "d" (len), "d" (volume): /* clobbered registers */ + "d0", "d1", "d2", "d3", "cc", "memory"); } -void SDL_MixAudio_m68k_S16LSB(short* dst, short* src, long len, long volume) +void +SDL_MixAudio_m68k_S16LSB (short *dst, short *src, long len, long volume) { - __asm__ __volatile__ ( - - "tstl %2\n" -" beqs stoploop_s16lsb\n" -" movel #-32768,%%d2\n" -" movel #32767,%%d3\n" -" lsrl #1,%2\n" -"mixloop_s16lsb:\n" - - /* Mix a sample */ - -" move %1@+,%%d0\n" /* d0 = *src++ */ -" rorw #8,%%d0\n" -" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ -" move %0@,%%d1\n" /* d1 = *dst */ -" rorw #8,%%d1\n" -" extl %%d1\n" /* extend d1 to 32 bits */ -" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ - -" addl %%d1,%%d0\n" - -" cmpl %%d2,%%d0\n" -" bges lower_limit_s16lsb\n" -" move %%d2,%%d0\n" -"lower_limit_s16lsb:\n" - -" cmpl %%d3,%%d0\n" -" bles upper_limit_s16lsb\n" -" move %%d3,%%d0\n" -"upper_limit_s16lsb:\n" -" rorw #8,%%d0\n" -" move %%d0,%0@+\n" - - /* Loop till done */ - -" subql #1,%2\n" -" bhis mixloop_s16lsb\n" -"stoploop_s16lsb:\n" - - : /* no return value */ - : /* input */ - "a"(dst), "a"(src), "d"(len), "d"(volume) - : /* clobbered registers */ - "d0", "d1", "d2", "d3", "cc", "memory" - ); + __asm__ __volatile__ ("tstl %2\n" + " beqs stoploop_s16lsb\n" + " movel #-32768,%%d2\n" + " movel #32767,%%d3\n" + " lsrl #1,%2\n" "mixloop_s16lsb:\n" + /* Mix a sample */ + " move %1@+,%%d0\n" /* d0 = *src++ */ + " rorw #8,%%d0\n" " muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */ + " move %0@,%%d1\n" /* d1 = *dst */ + " rorw #8,%%d1\n" " extl %%d1\n" /* extend d1 to 32 bits */ + " asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */ + " addl %%d1,%%d0\n" + " cmpl %%d2,%%d0\n" + " bges lower_limit_s16lsb\n" + " move %%d2,%%d0\n" + "lower_limit_s16lsb:\n" + " cmpl %%d3,%%d0\n" + " bles upper_limit_s16lsb\n" + " move %%d3,%%d0\n" + "upper_limit_s16lsb:\n" + " rorw #8,%%d0\n" " move %%d0,%0@+\n" + /* Loop till done */ + " subql #1,%2\n" " bhis mixloop_s16lsb\n" "stoploop_s16lsb:\n": /* no return value */ + : /* input */ + "a" (dst), "a" (src), "d" (len), "d" (volume): /* clobbered registers */ + "d0", "d1", "d2", "d3", "cc", "memory"); } #endif - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_mixer_m68k.h b/src/audio/SDL_mixer_m68k.h index d451dc43b..6f9d2338b 100644 --- a/src/audio/SDL_mixer_m68k.h +++ b/src/audio/SDL_mixer_m68k.h @@ -28,9 +28,11 @@ */ #if defined(__M68000__) && defined(__GNUC__) -void SDL_MixAudio_m68k_U8(char* dst,char* src, long len, long volume, char* mix8); -void SDL_MixAudio_m68k_S8(char* dst,char* src, long len, long volume); +void SDL_MixAudio_m68k_U8 (char *dst, char *src, long len, long volume, + char *mix8); +void SDL_MixAudio_m68k_S8 (char *dst, char *src, long len, long volume); -void SDL_MixAudio_m68k_S16MSB(short* dst,short* src, long len, long volume); -void SDL_MixAudio_m68k_S16LSB(short* dst,short* src, long len, long volume); +void SDL_MixAudio_m68k_S16MSB (short *dst, short *src, long len, long volume); +void SDL_MixAudio_m68k_S16LSB (short *dst, short *src, long len, long volume); #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 13e2dd516..00d814b4a 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -35,69 +35,71 @@ typedef struct SDL_AudioDevice SDL_AudioDevice; #ifndef _STATUS #define _STATUS SDL_status *status #endif -struct SDL_AudioDevice { - /* * * */ - /* The name of this audio driver */ - const char *name; - - /* * * */ - /* The description of this audio driver */ - const char *desc; - - /* * * */ - /* Public driver functions */ - int (*OpenAudio)(_THIS, SDL_AudioSpec *spec); - void (*ThreadInit)(_THIS); /* Called by audio thread at start */ - void (*WaitAudio)(_THIS); - void (*PlayAudio)(_THIS); - Uint8 *(*GetAudioBuf)(_THIS); - void (*WaitDone)(_THIS); - void (*CloseAudio)(_THIS); - - /* * * */ - /* Lock / Unlock functions added for the Mac port */ - void (*LockAudio)(_THIS); - void (*UnlockAudio)(_THIS); - - /* * * */ - /* Data common to all devices */ - - /* The current audio specification (shared with audio thread) */ - SDL_AudioSpec spec; - - /* An audio conversion block for audio format emulation */ - SDL_AudioCVT convert; - - /* Current state flags */ - int enabled; - int paused; - int opened; - - /* Fake audio buffer for when the audio hardware is busy */ - Uint8 *fake_stream; - - /* A semaphore for locking the mixing buffers */ - SDL_mutex *mixer_lock; - - /* A thread to feed the audio device */ - SDL_Thread *thread; - Uint32 threadid; - - /* * * */ - /* Data private to this driver */ - struct SDL_PrivateAudioData *hidden; - - /* * * */ - /* The function used to dispose of this structure */ - void (*free)(_THIS); +struct SDL_AudioDevice +{ + /* * * */ + /* The name of this audio driver */ + const char *name; + + /* * * */ + /* The description of this audio driver */ + const char *desc; + + /* * * */ + /* Public driver functions */ + int (*OpenAudio) (_THIS, SDL_AudioSpec * spec); + void (*ThreadInit) (_THIS); /* Called by audio thread at start */ + void (*WaitAudio) (_THIS); + void (*PlayAudio) (_THIS); + Uint8 *(*GetAudioBuf) (_THIS); + void (*WaitDone) (_THIS); + void (*CloseAudio) (_THIS); + + /* * * */ + /* Lock / Unlock functions added for the Mac port */ + void (*LockAudio) (_THIS); + void (*UnlockAudio) (_THIS); + + /* * * */ + /* Data common to all devices */ + + /* The current audio specification (shared with audio thread) */ + SDL_AudioSpec spec; + + /* An audio conversion block for audio format emulation */ + SDL_AudioCVT convert; + + /* Current state flags */ + int enabled; + int paused; + int opened; + + /* Fake audio buffer for when the audio hardware is busy */ + Uint8 *fake_stream; + + /* A semaphore for locking the mixing buffers */ + SDL_mutex *mixer_lock; + + /* A thread to feed the audio device */ + SDL_Thread *thread; + Uint32 threadid; + + /* * * */ + /* Data private to this driver */ + struct SDL_PrivateAudioData *hidden; + + /* * * */ + /* The function used to dispose of this structure */ + void (*free) (_THIS); }; #undef _THIS -typedef struct AudioBootStrap { - const char *name; - const char *desc; - int (*available)(void); - SDL_AudioDevice *(*create)(int devindex); +typedef struct AudioBootStrap +{ + const char *name; + const char *desc; + int (*available) (void); + SDL_AudioDevice *(*create) (int devindex); } AudioBootStrap; #if SDL_AUDIO_DRIVER_BSD @@ -176,3 +178,4 @@ extern AudioBootStrap DART_bootstrap; extern SDL_AudioDevice *current_audio; #endif /* _SDL_sysaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c index 465195eb8..56710e347 100644 --- a/src/audio/SDL_wave.c +++ b/src/audio/SDL_wave.c @@ -27,571 +27,593 @@ #include "SDL_wave.h" -static int ReadChunk(SDL_RWops *src, Chunk *chunk); +static int ReadChunk (SDL_RWops * src, Chunk * chunk); -struct MS_ADPCM_decodestate { - Uint8 hPredictor; - Uint16 iDelta; - Sint16 iSamp1; - Sint16 iSamp2; +struct MS_ADPCM_decodestate +{ + Uint8 hPredictor; + Uint16 iDelta; + Sint16 iSamp1; + Sint16 iSamp2; }; -static struct MS_ADPCM_decoder { - WaveFMT wavefmt; - Uint16 wSamplesPerBlock; - Uint16 wNumCoef; - Sint16 aCoeff[7][2]; - /* * * */ - struct MS_ADPCM_decodestate state[2]; +static struct MS_ADPCM_decoder +{ + WaveFMT wavefmt; + Uint16 wSamplesPerBlock; + Uint16 wNumCoef; + Sint16 aCoeff[7][2]; + /* * * */ + struct MS_ADPCM_decodestate state[2]; } MS_ADPCM_state; -static int InitMS_ADPCM(WaveFMT *format) +static int +InitMS_ADPCM (WaveFMT * format) { - Uint8 *rogue_feel; - Uint16 extra_info; - int i; - - /* Set the rogue pointer to the MS_ADPCM specific data */ - MS_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding); - MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels); - MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency); - MS_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate); - MS_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign); - MS_ADPCM_state.wavefmt.bitspersample = - SDL_SwapLE16(format->bitspersample); - rogue_feel = (Uint8 *)format+sizeof(*format); - if ( sizeof(*format) == 16 ) { - extra_info = ((rogue_feel[1]<<8)|rogue_feel[0]); - rogue_feel += sizeof(Uint16); - } - MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]); - rogue_feel += sizeof(Uint16); - MS_ADPCM_state.wNumCoef = ((rogue_feel[1]<<8)|rogue_feel[0]); - rogue_feel += sizeof(Uint16); - if ( MS_ADPCM_state.wNumCoef != 7 ) { - SDL_SetError("Unknown set of MS_ADPCM coefficients"); - return(-1); - } - for ( i=0; iencoding); + MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16 (format->channels); + MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32 (format->frequency); + MS_ADPCM_state.wavefmt.byterate = SDL_SwapLE32 (format->byterate); + MS_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16 (format->blockalign); + MS_ADPCM_state.wavefmt.bitspersample = + SDL_SwapLE16 (format->bitspersample); + rogue_feel = (Uint8 *) format + sizeof (*format); + if (sizeof (*format) == 16) { + extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]); + rogue_feel += sizeof (Uint16); + } + MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]); + rogue_feel += sizeof (Uint16); + MS_ADPCM_state.wNumCoef = ((rogue_feel[1] << 8) | rogue_feel[0]); + rogue_feel += sizeof (Uint16); + if (MS_ADPCM_state.wNumCoef != 7) { + SDL_SetError ("Unknown set of MS_ADPCM coefficients"); + return (-1); + } + for (i = 0; i < MS_ADPCM_state.wNumCoef; ++i) { + MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1] << 8) | rogue_feel[0]); + rogue_feel += sizeof (Uint16); + MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1] << 8) | rogue_feel[0]); + rogue_feel += sizeof (Uint16); + } + return (0); } -static Sint32 MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state, - Uint8 nybble, Sint16 *coeff) +static Sint32 +MS_ADPCM_nibble (struct MS_ADPCM_decodestate *state, + Uint8 nybble, Sint16 * coeff) { - const Sint32 max_audioval = ((1<<(16-1))-1); - const Sint32 min_audioval = -(1<<(16-1)); - const Sint32 adaptive[] = { - 230, 230, 230, 230, 307, 409, 512, 614, - 768, 614, 512, 409, 307, 230, 230, 230 - }; - Sint32 new_sample, delta; - - new_sample = ((state->iSamp1 * coeff[0]) + - (state->iSamp2 * coeff[1]))/256; - if ( nybble & 0x08 ) { - new_sample += state->iDelta * (nybble-0x10); - } else { - new_sample += state->iDelta * nybble; - } - if ( new_sample < min_audioval ) { - new_sample = min_audioval; - } else - if ( new_sample > max_audioval ) { - new_sample = max_audioval; - } - delta = ((Sint32)state->iDelta * adaptive[nybble])/256; - if ( delta < 16 ) { - delta = 16; - } - state->iDelta = (Uint16)delta; - state->iSamp2 = state->iSamp1; - state->iSamp1 = (Sint16)new_sample; - return(new_sample); + const Sint32 max_audioval = ((1 << (16 - 1)) - 1); + const Sint32 min_audioval = -(1 << (16 - 1)); + const Sint32 adaptive[] = { + 230, 230, 230, 230, 307, 409, 512, 614, + 768, 614, 512, 409, 307, 230, 230, 230 + }; + Sint32 new_sample, delta; + + new_sample = ((state->iSamp1 * coeff[0]) + + (state->iSamp2 * coeff[1])) / 256; + if (nybble & 0x08) { + new_sample += state->iDelta * (nybble - 0x10); + } else { + new_sample += state->iDelta * nybble; + } + if (new_sample < min_audioval) { + new_sample = min_audioval; + } else if (new_sample > max_audioval) { + new_sample = max_audioval; + } + delta = ((Sint32) state->iDelta * adaptive[nybble]) / 256; + if (delta < 16) { + delta = 16; + } + state->iDelta = (Uint16) delta; + state->iSamp2 = state->iSamp1; + state->iSamp1 = (Sint16) new_sample; + return (new_sample); } -static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len) +static int +MS_ADPCM_decode (Uint8 ** audio_buf, Uint32 * audio_len) { - struct MS_ADPCM_decodestate *state[2]; - Uint8 *freeable, *encoded, *decoded; - Sint32 encoded_len, samplesleft; - Sint8 nybble, stereo; - Sint16 *coeff[2]; - Sint32 new_sample; - - /* Allocate the proper sized output buffer */ - encoded_len = *audio_len; - encoded = *audio_buf; - freeable = *audio_buf; - *audio_len = (encoded_len/MS_ADPCM_state.wavefmt.blockalign) * - MS_ADPCM_state.wSamplesPerBlock* - MS_ADPCM_state.wavefmt.channels*sizeof(Sint16); - *audio_buf = (Uint8 *)SDL_malloc(*audio_len); - if ( *audio_buf == NULL ) { - SDL_Error(SDL_ENOMEM); - return(-1); - } - decoded = *audio_buf; - - /* Get ready... Go! */ - stereo = (MS_ADPCM_state.wavefmt.channels == 2); - state[0] = &MS_ADPCM_state.state[0]; - state[1] = &MS_ADPCM_state.state[stereo]; - while ( encoded_len >= MS_ADPCM_state.wavefmt.blockalign ) { - /* Grab the initial information for this block */ - state[0]->hPredictor = *encoded++; - if ( stereo ) { - state[1]->hPredictor = *encoded++; - } - state[0]->iDelta = ((encoded[1]<<8)|encoded[0]); - encoded += sizeof(Sint16); - if ( stereo ) { - state[1]->iDelta = ((encoded[1]<<8)|encoded[0]); - encoded += sizeof(Sint16); - } - state[0]->iSamp1 = ((encoded[1]<<8)|encoded[0]); - encoded += sizeof(Sint16); - if ( stereo ) { - state[1]->iSamp1 = ((encoded[1]<<8)|encoded[0]); - encoded += sizeof(Sint16); - } - state[0]->iSamp2 = ((encoded[1]<<8)|encoded[0]); - encoded += sizeof(Sint16); - if ( stereo ) { - state[1]->iSamp2 = ((encoded[1]<<8)|encoded[0]); - encoded += sizeof(Sint16); - } - coeff[0] = MS_ADPCM_state.aCoeff[state[0]->hPredictor]; - coeff[1] = MS_ADPCM_state.aCoeff[state[1]->hPredictor]; - - /* Store the two initial samples we start with */ - decoded[0] = state[0]->iSamp2&0xFF; - decoded[1] = state[0]->iSamp2>>8; - decoded += 2; - if ( stereo ) { - decoded[0] = state[1]->iSamp2&0xFF; - decoded[1] = state[1]->iSamp2>>8; - decoded += 2; - } - decoded[0] = state[0]->iSamp1&0xFF; - decoded[1] = state[0]->iSamp1>>8; - decoded += 2; - if ( stereo ) { - decoded[0] = state[1]->iSamp1&0xFF; - decoded[1] = state[1]->iSamp1>>8; - decoded += 2; - } - - /* Decode and store the other samples in this block */ - samplesleft = (MS_ADPCM_state.wSamplesPerBlock-2)* - MS_ADPCM_state.wavefmt.channels; - while ( samplesleft > 0 ) { - nybble = (*encoded)>>4; - new_sample = MS_ADPCM_nibble(state[0],nybble,coeff[0]); - decoded[0] = new_sample&0xFF; - new_sample >>= 8; - decoded[1] = new_sample&0xFF; - decoded += 2; - - nybble = (*encoded)&0x0F; - new_sample = MS_ADPCM_nibble(state[1],nybble,coeff[1]); - decoded[0] = new_sample&0xFF; - new_sample >>= 8; - decoded[1] = new_sample&0xFF; - decoded += 2; - - ++encoded; - samplesleft -= 2; - } - encoded_len -= MS_ADPCM_state.wavefmt.blockalign; - } - SDL_free(freeable); - return(0); + struct MS_ADPCM_decodestate *state[2]; + Uint8 *freeable, *encoded, *decoded; + Sint32 encoded_len, samplesleft; + Sint8 nybble, stereo; + Sint16 *coeff[2]; + Sint32 new_sample; + + /* Allocate the proper sized output buffer */ + encoded_len = *audio_len; + encoded = *audio_buf; + freeable = *audio_buf; + *audio_len = (encoded_len / MS_ADPCM_state.wavefmt.blockalign) * + MS_ADPCM_state.wSamplesPerBlock * + MS_ADPCM_state.wavefmt.channels * sizeof (Sint16); + *audio_buf = (Uint8 *) SDL_malloc (*audio_len); + if (*audio_buf == NULL) { + SDL_Error (SDL_ENOMEM); + return (-1); + } + decoded = *audio_buf; + + /* Get ready... Go! */ + stereo = (MS_ADPCM_state.wavefmt.channels == 2); + state[0] = &MS_ADPCM_state.state[0]; + state[1] = &MS_ADPCM_state.state[stereo]; + while (encoded_len >= MS_ADPCM_state.wavefmt.blockalign) { + /* Grab the initial information for this block */ + state[0]->hPredictor = *encoded++; + if (stereo) { + state[1]->hPredictor = *encoded++; + } + state[0]->iDelta = ((encoded[1] << 8) | encoded[0]); + encoded += sizeof (Sint16); + if (stereo) { + state[1]->iDelta = ((encoded[1] << 8) | encoded[0]); + encoded += sizeof (Sint16); + } + state[0]->iSamp1 = ((encoded[1] << 8) | encoded[0]); + encoded += sizeof (Sint16); + if (stereo) { + state[1]->iSamp1 = ((encoded[1] << 8) | encoded[0]); + encoded += sizeof (Sint16); + } + state[0]->iSamp2 = ((encoded[1] << 8) | encoded[0]); + encoded += sizeof (Sint16); + if (stereo) { + state[1]->iSamp2 = ((encoded[1] << 8) | encoded[0]); + encoded += sizeof (Sint16); + } + coeff[0] = MS_ADPCM_state.aCoeff[state[0]->hPredictor]; + coeff[1] = MS_ADPCM_state.aCoeff[state[1]->hPredictor]; + + /* Store the two initial samples we start with */ + decoded[0] = state[0]->iSamp2 & 0xFF; + decoded[1] = state[0]->iSamp2 >> 8; + decoded += 2; + if (stereo) { + decoded[0] = state[1]->iSamp2 & 0xFF; + decoded[1] = state[1]->iSamp2 >> 8; + decoded += 2; + } + decoded[0] = state[0]->iSamp1 & 0xFF; + decoded[1] = state[0]->iSamp1 >> 8; + decoded += 2; + if (stereo) { + decoded[0] = state[1]->iSamp1 & 0xFF; + decoded[1] = state[1]->iSamp1 >> 8; + decoded += 2; + } + + /* Decode and store the other samples in this block */ + samplesleft = (MS_ADPCM_state.wSamplesPerBlock - 2) * + MS_ADPCM_state.wavefmt.channels; + while (samplesleft > 0) { + nybble = (*encoded) >> 4; + new_sample = MS_ADPCM_nibble (state[0], nybble, coeff[0]); + decoded[0] = new_sample & 0xFF; + new_sample >>= 8; + decoded[1] = new_sample & 0xFF; + decoded += 2; + + nybble = (*encoded) & 0x0F; + new_sample = MS_ADPCM_nibble (state[1], nybble, coeff[1]); + decoded[0] = new_sample & 0xFF; + new_sample >>= 8; + decoded[1] = new_sample & 0xFF; + decoded += 2; + + ++encoded; + samplesleft -= 2; + } + encoded_len -= MS_ADPCM_state.wavefmt.blockalign; + } + SDL_free (freeable); + return (0); } -struct IMA_ADPCM_decodestate { - Sint32 sample; - Sint8 index; +struct IMA_ADPCM_decodestate +{ + Sint32 sample; + Sint8 index; }; -static struct IMA_ADPCM_decoder { - WaveFMT wavefmt; - Uint16 wSamplesPerBlock; - /* * * */ - struct IMA_ADPCM_decodestate state[2]; +static struct IMA_ADPCM_decoder +{ + WaveFMT wavefmt; + Uint16 wSamplesPerBlock; + /* * * */ + struct IMA_ADPCM_decodestate state[2]; } IMA_ADPCM_state; -static int InitIMA_ADPCM(WaveFMT *format) +static int +InitIMA_ADPCM (WaveFMT * format) { - Uint8 *rogue_feel; - Uint16 extra_info; - - /* Set the rogue pointer to the IMA_ADPCM specific data */ - IMA_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding); - IMA_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels); - IMA_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency); - IMA_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate); - IMA_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign); - IMA_ADPCM_state.wavefmt.bitspersample = - SDL_SwapLE16(format->bitspersample); - rogue_feel = (Uint8 *)format+sizeof(*format); - if ( sizeof(*format) == 16 ) { - extra_info = ((rogue_feel[1]<<8)|rogue_feel[0]); - rogue_feel += sizeof(Uint16); - } - IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]); - return(0); + Uint8 *rogue_feel; + Uint16 extra_info; + + /* Set the rogue pointer to the IMA_ADPCM specific data */ + IMA_ADPCM_state.wavefmt.encoding = SDL_SwapLE16 (format->encoding); + IMA_ADPCM_state.wavefmt.channels = SDL_SwapLE16 (format->channels); + IMA_ADPCM_state.wavefmt.frequency = SDL_SwapLE32 (format->frequency); + IMA_ADPCM_state.wavefmt.byterate = SDL_SwapLE32 (format->byterate); + IMA_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16 (format->blockalign); + IMA_ADPCM_state.wavefmt.bitspersample = + SDL_SwapLE16 (format->bitspersample); + rogue_feel = (Uint8 *) format + sizeof (*format); + if (sizeof (*format) == 16) { + extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]); + rogue_feel += sizeof (Uint16); + } + IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]); + return (0); } -static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state,Uint8 nybble) +static Sint32 +IMA_ADPCM_nibble (struct IMA_ADPCM_decodestate *state, Uint8 nybble) { - const Sint32 max_audioval = ((1<<(16-1))-1); - const Sint32 min_audioval = -(1<<(16-1)); - const int index_table[16] = { - -1, -1, -1, -1, - 2, 4, 6, 8, - -1, -1, -1, -1, - 2, 4, 6, 8 - }; - const Sint32 step_table[89] = { - 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, - 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, - 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, - 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, - 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, - 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, - 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, - 22385, 24623, 27086, 29794, 32767 - }; - Sint32 delta, step; - - /* Compute difference and new sample value */ - step = step_table[state->index]; - delta = step >> 3; - if ( nybble & 0x04 ) delta += step; - if ( nybble & 0x02 ) delta += (step >> 1); - if ( nybble & 0x01 ) delta += (step >> 2); - if ( nybble & 0x08 ) delta = -delta; - state->sample += delta; - - /* Update index value */ - state->index += index_table[nybble]; - if ( state->index > 88 ) { - state->index = 88; - } else - if ( state->index < 0 ) { - state->index = 0; - } - - /* Clamp output sample */ - if ( state->sample > max_audioval ) { - state->sample = max_audioval; - } else - if ( state->sample < min_audioval ) { - state->sample = min_audioval; - } - return(state->sample); + const Sint32 max_audioval = ((1 << (16 - 1)) - 1); + const Sint32 min_audioval = -(1 << (16 - 1)); + const int index_table[16] = { + -1, -1, -1, -1, + 2, 4, 6, 8, + -1, -1, -1, -1, + 2, 4, 6, 8 + }; + const Sint32 step_table[89] = { + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, + 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, + 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, + 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, + 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, + 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, + 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, + 22385, 24623, 27086, 29794, 32767 + }; + Sint32 delta, step; + + /* Compute difference and new sample value */ + step = step_table[state->index]; + delta = step >> 3; + if (nybble & 0x04) + delta += step; + if (nybble & 0x02) + delta += (step >> 1); + if (nybble & 0x01) + delta += (step >> 2); + if (nybble & 0x08) + delta = -delta; + state->sample += delta; + + /* Update index value */ + state->index += index_table[nybble]; + if (state->index > 88) { + state->index = 88; + } else if (state->index < 0) { + state->index = 0; + } + + /* Clamp output sample */ + if (state->sample > max_audioval) { + state->sample = max_audioval; + } else if (state->sample < min_audioval) { + state->sample = min_audioval; + } + return (state->sample); } /* Fill the decode buffer with a channel block of data (8 samples) */ -static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded, - int channel, int numchannels, struct IMA_ADPCM_decodestate *state) +static void +Fill_IMA_ADPCM_block (Uint8 * decoded, Uint8 * encoded, + int channel, int numchannels, + struct IMA_ADPCM_decodestate *state) { - int i; - Sint8 nybble; - Sint32 new_sample; - - decoded += (channel * 2); - for ( i=0; i<4; ++i ) { - nybble = (*encoded)&0x0F; - new_sample = IMA_ADPCM_nibble(state, nybble); - decoded[0] = new_sample&0xFF; - new_sample >>= 8; - decoded[1] = new_sample&0xFF; - decoded += 2 * numchannels; - - nybble = (*encoded)>>4; - new_sample = IMA_ADPCM_nibble(state, nybble); - decoded[0] = new_sample&0xFF; - new_sample >>= 8; - decoded[1] = new_sample&0xFF; - decoded += 2 * numchannels; - - ++encoded; - } + int i; + Sint8 nybble; + Sint32 new_sample; + + decoded += (channel * 2); + for (i = 0; i < 4; ++i) { + nybble = (*encoded) & 0x0F; + new_sample = IMA_ADPCM_nibble (state, nybble); + decoded[0] = new_sample & 0xFF; + new_sample >>= 8; + decoded[1] = new_sample & 0xFF; + decoded += 2 * numchannels; + + nybble = (*encoded) >> 4; + new_sample = IMA_ADPCM_nibble (state, nybble); + decoded[0] = new_sample & 0xFF; + new_sample >>= 8; + decoded[1] = new_sample & 0xFF; + decoded += 2 * numchannels; + + ++encoded; + } } -static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len) +static int +IMA_ADPCM_decode (Uint8 ** audio_buf, Uint32 * audio_len) { - struct IMA_ADPCM_decodestate *state; - Uint8 *freeable, *encoded, *decoded; - Sint32 encoded_len, samplesleft; - unsigned int c, channels; - - /* Check to make sure we have enough variables in the state array */ - channels = IMA_ADPCM_state.wavefmt.channels; - if ( channels > SDL_arraysize(IMA_ADPCM_state.state) ) { - SDL_SetError("IMA ADPCM decoder can only handle %d channels", - SDL_arraysize(IMA_ADPCM_state.state)); - return(-1); - } - state = IMA_ADPCM_state.state; - - /* Allocate the proper sized output buffer */ - encoded_len = *audio_len; - encoded = *audio_buf; - freeable = *audio_buf; - *audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) * - IMA_ADPCM_state.wSamplesPerBlock* - IMA_ADPCM_state.wavefmt.channels*sizeof(Sint16); - *audio_buf = (Uint8 *)SDL_malloc(*audio_len); - if ( *audio_buf == NULL ) { - SDL_Error(SDL_ENOMEM); - return(-1); - } - decoded = *audio_buf; - - /* Get ready... Go! */ - while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) { - /* Grab the initial information for this block */ - for ( c=0; c>8); - decoded += 2; - } - - /* Decode and store the other samples in this block */ - samplesleft = (IMA_ADPCM_state.wSamplesPerBlock-1)*channels; - while ( samplesleft > 0 ) { - for ( c=0; c SDL_arraysize (IMA_ADPCM_state.state)) { + SDL_SetError ("IMA ADPCM decoder can only handle %d channels", + SDL_arraysize (IMA_ADPCM_state.state)); + return (-1); + } + state = IMA_ADPCM_state.state; + + /* Allocate the proper sized output buffer */ + encoded_len = *audio_len; + encoded = *audio_buf; + freeable = *audio_buf; + *audio_len = (encoded_len / IMA_ADPCM_state.wavefmt.blockalign) * + IMA_ADPCM_state.wSamplesPerBlock * + IMA_ADPCM_state.wavefmt.channels * sizeof (Sint16); + *audio_buf = (Uint8 *) SDL_malloc (*audio_len); + if (*audio_buf == NULL) { + SDL_Error (SDL_ENOMEM); + return (-1); + } + decoded = *audio_buf; + + /* Get ready... Go! */ + while (encoded_len >= IMA_ADPCM_state.wavefmt.blockalign) { + /* Grab the initial information for this block */ + for (c = 0; c < channels; ++c) { + /* Fill the state information for this block */ + state[c].sample = ((encoded[1] << 8) | encoded[0]); + encoded += 2; + if (state[c].sample & 0x8000) { + state[c].sample -= 0x10000; + } + state[c].index = *encoded++; + /* Reserved byte in buffer header, should be 0 */ + if (*encoded++ != 0) { + /* Uh oh, corrupt data? Buggy code? */ ; + } + + /* Store the initial sample we start with */ + decoded[0] = (Uint8) (state[c].sample & 0xFF); + decoded[1] = (Uint8) (state[c].sample >> 8); + decoded += 2; + } + + /* Decode and store the other samples in this block */ + samplesleft = (IMA_ADPCM_state.wSamplesPerBlock - 1) * channels; + while (samplesleft > 0) { + for (c = 0; c < channels; ++c) { + Fill_IMA_ADPCM_block (decoded, encoded, + c, channels, &state[c]); + encoded += 4; + samplesleft -= 8; + } + decoded += (channels * 8 * 2); + } + encoded_len -= IMA_ADPCM_state.wavefmt.blockalign; + } + SDL_free (freeable); + return (0); } -SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc, - SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) +SDL_AudioSpec * +SDL_LoadWAV_RW (SDL_RWops * src, int freesrc, + SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len) { - int was_error; - Chunk chunk; - int lenread; - int MS_ADPCM_encoded, IMA_ADPCM_encoded; - int samplesize; - - /* WAV magic header */ - Uint32 RIFFchunk; - Uint32 wavelen = 0; - Uint32 WAVEmagic; - Uint32 headerDiff = 0; - - /* FMT chunk */ - WaveFMT *format = NULL; - - /* Make sure we are passed a valid data source */ - was_error = 0; - if ( src == NULL ) { - was_error = 1; - goto done; - } - - /* Check the magic header */ - RIFFchunk = SDL_ReadLE32(src); - wavelen = SDL_ReadLE32(src); - if ( wavelen == WAVE ) { /* The RIFFchunk has already been read */ - WAVEmagic = wavelen; - wavelen = RIFFchunk; - RIFFchunk = RIFF; - } else { - WAVEmagic = SDL_ReadLE32(src); - } - if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) { - SDL_SetError("Unrecognized file type (not WAVE)"); - was_error = 1; - goto done; - } - headerDiff += sizeof(Uint32); /* for WAVE */ - - /* Read the audio data format chunk */ - chunk.data = NULL; - do { - if ( chunk.data != NULL ) { - SDL_free(chunk.data); - } - lenread = ReadChunk(src, &chunk); - if ( lenread < 0 ) { - was_error = 1; - goto done; - } - /* 2 Uint32's for chunk header+len, plus the lenread */ - headerDiff += lenread + 2 * sizeof(Uint32); - } while ( (chunk.magic == FACT) || (chunk.magic == LIST) ); - - /* Decode the audio data format */ - format = (WaveFMT *)chunk.data; - if ( chunk.magic != FMT ) { - SDL_SetError("Complex WAVE files not supported"); - was_error = 1; - goto done; - } - MS_ADPCM_encoded = IMA_ADPCM_encoded = 0; - switch (SDL_SwapLE16(format->encoding)) { - case PCM_CODE: - /* We can understand this */ - break; - case MS_ADPCM_CODE: - /* Try to understand this */ - if ( InitMS_ADPCM(format) < 0 ) { - was_error = 1; - goto done; - } - MS_ADPCM_encoded = 1; - break; - case IMA_ADPCM_CODE: - /* Try to understand this */ - if ( InitIMA_ADPCM(format) < 0 ) { - was_error = 1; - goto done; - } - IMA_ADPCM_encoded = 1; - break; - case MP3_CODE: - SDL_SetError("MPEG Layer 3 data not supported", - SDL_SwapLE16(format->encoding)); - was_error = 1; - goto done; - default: - SDL_SetError("Unknown WAVE data format: 0x%.4x", - SDL_SwapLE16(format->encoding)); - was_error = 1; - goto done; - } - SDL_memset(spec, 0, (sizeof *spec)); - spec->freq = SDL_SwapLE32(format->frequency); - switch (SDL_SwapLE16(format->bitspersample)) { - case 4: - if ( MS_ADPCM_encoded || IMA_ADPCM_encoded ) { - spec->format = AUDIO_S16; - } else { - was_error = 1; - } - break; - case 8: - spec->format = AUDIO_U8; - break; - case 16: - spec->format = AUDIO_S16; - break; - default: - was_error = 1; - break; - } - if ( was_error ) { - SDL_SetError("Unknown %d-bit PCM data format", - SDL_SwapLE16(format->bitspersample)); - goto done; - } - spec->channels = (Uint8)SDL_SwapLE16(format->channels); - spec->samples = 4096; /* Good default buffer size */ - - /* Read the audio data chunk */ - *audio_buf = NULL; - do { - if ( *audio_buf != NULL ) { - SDL_free(*audio_buf); - } - lenread = ReadChunk(src, &chunk); - if ( lenread < 0 ) { - was_error = 1; - goto done; - } - *audio_len = lenread; - *audio_buf = chunk.data; - if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32); - } while ( chunk.magic != DATA ); - headerDiff += 2 * sizeof(Uint32); /* for the data chunk and len */ - - if ( MS_ADPCM_encoded ) { - if ( MS_ADPCM_decode(audio_buf, audio_len) < 0 ) { - was_error = 1; - goto done; - } - } - if ( IMA_ADPCM_encoded ) { - if ( IMA_ADPCM_decode(audio_buf, audio_len) < 0 ) { - was_error = 1; - goto done; - } - } - - /* Don't return a buffer that isn't a multiple of samplesize */ - samplesize = ((spec->format & 0xFF)/8)*spec->channels; - *audio_len &= ~(samplesize-1); - -done: - if ( format != NULL ) { - SDL_free(format); - } - if ( src ) { - if ( freesrc ) { - SDL_RWclose(src); - } else { - /* seek to the end of the file (given by the RIFF chunk) */ - SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR); - } - } - if ( was_error ) { - spec = NULL; - } - return(spec); + int was_error; + Chunk chunk; + int lenread; + int MS_ADPCM_encoded, IMA_ADPCM_encoded; + int samplesize; + + /* WAV magic header */ + Uint32 RIFFchunk; + Uint32 wavelen = 0; + Uint32 WAVEmagic; + Uint32 headerDiff = 0; + + /* FMT chunk */ + WaveFMT *format = NULL; + + /* Make sure we are passed a valid data source */ + was_error = 0; + if (src == NULL) { + was_error = 1; + goto done; + } + + /* Check the magic header */ + RIFFchunk = SDL_ReadLE32 (src); + wavelen = SDL_ReadLE32 (src); + if (wavelen == WAVE) { /* The RIFFchunk has already been read */ + WAVEmagic = wavelen; + wavelen = RIFFchunk; + RIFFchunk = RIFF; + } else { + WAVEmagic = SDL_ReadLE32 (src); + } + if ((RIFFchunk != RIFF) || (WAVEmagic != WAVE)) { + SDL_SetError ("Unrecognized file type (not WAVE)"); + was_error = 1; + goto done; + } + headerDiff += sizeof (Uint32); /* for WAVE */ + + /* Read the audio data format chunk */ + chunk.data = NULL; + do { + if (chunk.data != NULL) { + SDL_free (chunk.data); + } + lenread = ReadChunk (src, &chunk); + if (lenread < 0) { + was_error = 1; + goto done; + } + /* 2 Uint32's for chunk header+len, plus the lenread */ + headerDiff += lenread + 2 * sizeof (Uint32); + } + while ((chunk.magic == FACT) || (chunk.magic == LIST)); + + /* Decode the audio data format */ + format = (WaveFMT *) chunk.data; + if (chunk.magic != FMT) { + SDL_SetError ("Complex WAVE files not supported"); + was_error = 1; + goto done; + } + MS_ADPCM_encoded = IMA_ADPCM_encoded = 0; + switch (SDL_SwapLE16 (format->encoding)) { + case PCM_CODE: + /* We can understand this */ + break; + case MS_ADPCM_CODE: + /* Try to understand this */ + if (InitMS_ADPCM (format) < 0) { + was_error = 1; + goto done; + } + MS_ADPCM_encoded = 1; + break; + case IMA_ADPCM_CODE: + /* Try to understand this */ + if (InitIMA_ADPCM (format) < 0) { + was_error = 1; + goto done; + } + IMA_ADPCM_encoded = 1; + break; + case MP3_CODE: + SDL_SetError ("MPEG Layer 3 data not supported", + SDL_SwapLE16 (format->encoding)); + was_error = 1; + goto done; + default: + SDL_SetError ("Unknown WAVE data format: 0x%.4x", + SDL_SwapLE16 (format->encoding)); + was_error = 1; + goto done; + } + SDL_memset (spec, 0, (sizeof *spec)); + spec->freq = SDL_SwapLE32 (format->frequency); + switch (SDL_SwapLE16 (format->bitspersample)) { + case 4: + if (MS_ADPCM_encoded || IMA_ADPCM_encoded) { + spec->format = AUDIO_S16; + } else { + was_error = 1; + } + break; + case 8: + spec->format = AUDIO_U8; + break; + case 16: + spec->format = AUDIO_S16; + break; + default: + was_error = 1; + break; + } + if (was_error) { + SDL_SetError ("Unknown %d-bit PCM data format", + SDL_SwapLE16 (format->bitspersample)); + goto done; + } + spec->channels = (Uint8) SDL_SwapLE16 (format->channels); + spec->samples = 4096; /* Good default buffer size */ + + /* Read the audio data chunk */ + *audio_buf = NULL; + do { + if (*audio_buf != NULL) { + SDL_free (*audio_buf); + } + lenread = ReadChunk (src, &chunk); + if (lenread < 0) { + was_error = 1; + goto done; + } + *audio_len = lenread; + *audio_buf = chunk.data; + if (chunk.magic != DATA) + headerDiff += lenread + 2 * sizeof (Uint32); + } + while (chunk.magic != DATA); + headerDiff += 2 * sizeof (Uint32); /* for the data chunk and len */ + + if (MS_ADPCM_encoded) { + if (MS_ADPCM_decode (audio_buf, audio_len) < 0) { + was_error = 1; + goto done; + } + } + if (IMA_ADPCM_encoded) { + if (IMA_ADPCM_decode (audio_buf, audio_len) < 0) { + was_error = 1; + goto done; + } + } + + /* Don't return a buffer that isn't a multiple of samplesize */ + samplesize = ((spec->format & 0xFF) / 8) * spec->channels; + *audio_len &= ~(samplesize - 1); + + done: + if (format != NULL) { + SDL_free (format); + } + if (src) { + if (freesrc) { + SDL_RWclose (src); + } else { + /* seek to the end of the file (given by the RIFF chunk) */ + SDL_RWseek (src, wavelen - chunk.length - headerDiff, + RW_SEEK_CUR); + } + } + if (was_error) { + spec = NULL; + } + return (spec); } /* Since the WAV memory is allocated in the shared library, it must also be freed here. (Necessary under Win32, VC++) */ -void SDL_FreeWAV(Uint8 *audio_buf) +void +SDL_FreeWAV (Uint8 * audio_buf) { - if ( audio_buf != NULL ) { - SDL_free(audio_buf); - } + if (audio_buf != NULL) { + SDL_free (audio_buf); + } } -static int ReadChunk(SDL_RWops *src, Chunk *chunk) +static int +ReadChunk (SDL_RWops * src, Chunk * chunk) { - chunk->magic = SDL_ReadLE32(src); - chunk->length = SDL_ReadLE32(src); - chunk->data = (Uint8 *)SDL_malloc(chunk->length); - if ( chunk->data == NULL ) { - SDL_Error(SDL_ENOMEM); - return(-1); - } - if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) { - SDL_Error(SDL_EFREAD); - SDL_free(chunk->data); - return(-1); - } - return(chunk->length); + chunk->magic = SDL_ReadLE32 (src); + chunk->length = SDL_ReadLE32 (src); + chunk->data = (Uint8 *) SDL_malloc (chunk->length); + if (chunk->data == NULL) { + SDL_Error (SDL_ENOMEM); + return (-1); + } + if (SDL_RWread (src, chunk->data, chunk->length, 1) != 1) { + SDL_Error (SDL_EFREAD); + SDL_free (chunk->data); + return (-1); + } + return (chunk->length); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/SDL_wave.h b/src/audio/SDL_wave.h index a0af6ebd8..036a0c839 100644 --- a/src/audio/SDL_wave.h +++ b/src/audio/SDL_wave.h @@ -26,12 +26,12 @@ /*******************************************/ /* Define values for Microsoft WAVE format */ /*******************************************/ -#define RIFF 0x46464952 /* "RIFF" */ -#define WAVE 0x45564157 /* "WAVE" */ -#define FACT 0x74636166 /* "fact" */ -#define LIST 0x5453494c /* "LIST" */ -#define FMT 0x20746D66 /* "fmt " */ -#define DATA 0x61746164 /* "data" */ +#define RIFF 0x46464952 /* "RIFF" */ +#define WAVE 0x45564157 /* "WAVE" */ +#define FACT 0x74636166 /* "fact" */ +#define LIST 0x5453494c /* "LIST" */ +#define FMT 0x20746D66 /* "fmt " */ +#define DATA 0x61746164 /* "data" */ #define PCM_CODE 0x0001 #define MS_ADPCM_CODE 0x0002 #define IMA_ADPCM_CODE 0x0011 @@ -40,23 +40,25 @@ #define WAVE_STEREO 2 /* Normally, these three chunks come consecutively in a WAVE file */ -typedef struct WaveFMT { +typedef struct WaveFMT +{ /* Not saved in the chunk we read: Uint32 FMTchunk; Uint32 fmtlen; */ - Uint16 encoding; - Uint16 channels; /* 1 = mono, 2 = stereo */ - Uint32 frequency; /* One of 11025, 22050, or 44100 Hz */ - Uint32 byterate; /* Average bytes per second */ - Uint16 blockalign; /* Bytes per sample block */ - Uint16 bitspersample; /* One of 8, 12, 16, or 4 for ADPCM */ + Uint16 encoding; + Uint16 channels; /* 1 = mono, 2 = stereo */ + Uint32 frequency; /* One of 11025, 22050, or 44100 Hz */ + Uint32 byterate; /* Average bytes per second */ + Uint16 blockalign; /* Bytes per sample block */ + Uint16 bitspersample; /* One of 8, 12, 16, or 4 for ADPCM */ } WaveFMT; /* The general chunk found in the WAVE file */ -typedef struct Chunk { - Uint32 magic; - Uint32 length; - Uint8 *data; +typedef struct Chunk +{ + Uint32 magic; + Uint32 length; + Uint8 *data; } Chunk; - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index d2e674168..0f693c486 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -24,7 +24,7 @@ /* Allow access to a raw mixing buffer */ #include -#include /* For kill() */ +#include /* For kill() */ #include "SDL_timer.h" #include "SDL_audio.h" @@ -48,11 +48,11 @@ #define DEFAULT_DEVICE "default" /* Audio driver functions */ -static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void ALSA_WaitAudio(_THIS); -static void ALSA_PlayAudio(_THIS); -static Uint8 *ALSA_GetAudioBuf(_THIS); -static void ALSA_CloseAudio(_THIS); +static int ALSA_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void ALSA_WaitAudio (_THIS); +static void ALSA_PlayAudio (_THIS); +static Uint8 *ALSA_GetAudioBuf (_THIS); +static void ALSA_CloseAudio (_THIS); #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC @@ -60,374 +60,493 @@ static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC; static void *alsa_handle = NULL; static int alsa_loaded = 0; -static int (*SDL_snd_pcm_open)(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode); -static int (*SDL_NAME(snd_pcm_open))(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode); -static int (*SDL_NAME(snd_pcm_close))(snd_pcm_t *pcm); -static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_writei))(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size); -static int (*SDL_NAME(snd_pcm_resume))(snd_pcm_t *pcm); -static int (*SDL_NAME(snd_pcm_prepare))(snd_pcm_t *pcm); -static int (*SDL_NAME(snd_pcm_drain))(snd_pcm_t *pcm); -static const char *(*SDL_NAME(snd_strerror))(int errnum); -static size_t (*SDL_NAME(snd_pcm_hw_params_sizeof))(void); -static size_t (*SDL_NAME(snd_pcm_sw_params_sizeof))(void); -static int (*SDL_NAME(snd_pcm_hw_params_any))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); -static int (*SDL_NAME(snd_pcm_hw_params_set_access))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access); -static int (*SDL_NAME(snd_pcm_hw_params_set_format))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val); -static int (*SDL_NAME(snd_pcm_hw_params_set_channels))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val); -static int (*SDL_NAME(snd_pcm_hw_params_get_channels))(const snd_pcm_hw_params_t *params); -static unsigned int (*SDL_NAME(snd_pcm_hw_params_set_rate_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir); -static snd_pcm_uframes_t (*SDL_NAME(snd_pcm_hw_params_set_period_size_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int *dir); -static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_hw_params_get_period_size))(const snd_pcm_hw_params_t *params); -static unsigned int (*SDL_NAME(snd_pcm_hw_params_set_periods_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir); -static int (*SDL_NAME(snd_pcm_hw_params_get_periods))(snd_pcm_hw_params_t *params); -static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); +static int (*SDL_snd_pcm_open) (snd_pcm_t ** pcm, const char *name, + snd_pcm_stream_t stream, int mode); +static int (*SDL_NAME (snd_pcm_open)) (snd_pcm_t ** pcm, const char *name, + snd_pcm_stream_t stream, int mode); +static int (*SDL_NAME (snd_pcm_close)) (snd_pcm_t * pcm); +static snd_pcm_sframes_t (*SDL_NAME (snd_pcm_writei)) (snd_pcm_t * pcm, + const void *buffer, + snd_pcm_uframes_t + size); +static int (*SDL_NAME (snd_pcm_resume)) (snd_pcm_t * pcm); +static int (*SDL_NAME (snd_pcm_prepare)) (snd_pcm_t * pcm); +static int (*SDL_NAME (snd_pcm_drain)) (snd_pcm_t * pcm); +static const char *(*SDL_NAME (snd_strerror)) (int errnum); +static size_t (*SDL_NAME (snd_pcm_hw_params_sizeof)) (void); +static size_t (*SDL_NAME (snd_pcm_sw_params_sizeof)) (void); +static int (*SDL_NAME (snd_pcm_hw_params_any)) (snd_pcm_t * pcm, + snd_pcm_hw_params_t * params); +static int (*SDL_NAME (snd_pcm_hw_params_set_access)) (snd_pcm_t * pcm, + snd_pcm_hw_params_t * + params, + snd_pcm_access_t + access); +static int (*SDL_NAME (snd_pcm_hw_params_set_format)) (snd_pcm_t * pcm, + snd_pcm_hw_params_t * + params, + snd_pcm_format_t val); +static int (*SDL_NAME (snd_pcm_hw_params_set_channels)) (snd_pcm_t * pcm, + snd_pcm_hw_params_t * + params, + unsigned int val); +static int (*SDL_NAME (snd_pcm_hw_params_get_channels)) (const + snd_pcm_hw_params_t * + params); +static unsigned int (*SDL_NAME (snd_pcm_hw_params_set_rate_near)) (snd_pcm_t * + pcm, + snd_pcm_hw_params_t + * params, + unsigned + int val, + int *dir); +static snd_pcm_uframes_t (*SDL_NAME (snd_pcm_hw_params_set_period_size_near)) + + + + + + + + (snd_pcm_t * pcm, snd_pcm_hw_params_t * params, snd_pcm_uframes_t val, + int *dir); +static +snd_pcm_sframes_t (*SDL_NAME (snd_pcm_hw_params_get_period_size)) (const + snd_pcm_hw_params_t + * params); +static unsigned + int (*SDL_NAME (snd_pcm_hw_params_set_periods_near)) (snd_pcm_t * pcm, + snd_pcm_hw_params_t + * params, + unsigned int val, + int *dir); +static int (*SDL_NAME (snd_pcm_hw_params_get_periods)) (snd_pcm_hw_params_t * + params); +static int (*SDL_NAME (snd_pcm_hw_params)) (snd_pcm_t * pcm, + snd_pcm_hw_params_t * params); /* */ -static int (*SDL_NAME(snd_pcm_sw_params_current))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams); -static int (*SDL_NAME(snd_pcm_sw_params_set_start_threshold))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val); -static int (*SDL_NAME(snd_pcm_sw_params_set_avail_min))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val); -static int (*SDL_NAME(snd_pcm_sw_params))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params); -static int (*SDL_NAME(snd_pcm_nonblock))(snd_pcm_t *pcm, int nonblock); +static int (*SDL_NAME (snd_pcm_sw_params_current)) (snd_pcm_t * pcm, + snd_pcm_sw_params_t * + swparams); +static int (*SDL_NAME (snd_pcm_sw_params_set_start_threshold)) (snd_pcm_t * + pcm, + snd_pcm_sw_params_t + * params, + snd_pcm_uframes_t + val); +static int (*SDL_NAME (snd_pcm_sw_params_set_avail_min)) (snd_pcm_t * pcm, + snd_pcm_sw_params_t + * params, + snd_pcm_uframes_t + val); +static int (*SDL_NAME (snd_pcm_sw_params)) (snd_pcm_t * pcm, + snd_pcm_sw_params_t * params); +static int (*SDL_NAME (snd_pcm_nonblock)) (snd_pcm_t * pcm, int nonblock); #define snd_pcm_hw_params_sizeof SDL_NAME(snd_pcm_hw_params_sizeof) #define snd_pcm_sw_params_sizeof SDL_NAME(snd_pcm_sw_params_sizeof) /* cast funcs to char* first, to please GCC's strict aliasing rules. */ -static struct { - const char *name; - void **func; +static struct +{ + const char *name; + void **func; } alsa_functions[] = { - { "snd_pcm_open", (void**)(char*)&SDL_NAME(snd_pcm_open) }, - { "snd_pcm_close", (void**)(char*)&SDL_NAME(snd_pcm_close) }, - { "snd_pcm_writei", (void**)(char*)&SDL_NAME(snd_pcm_writei) }, - { "snd_pcm_resume", (void**)(char*)&SDL_NAME(snd_pcm_resume) }, - { "snd_pcm_prepare", (void**)(char*)&SDL_NAME(snd_pcm_prepare) }, - { "snd_pcm_drain", (void**)(char*)&SDL_NAME(snd_pcm_drain) }, - { "snd_strerror", (void**)(char*)&SDL_NAME(snd_strerror) }, - { "snd_pcm_hw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_sizeof) }, - { "snd_pcm_sw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_sizeof) }, - { "snd_pcm_hw_params_any", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_any) }, - { "snd_pcm_hw_params_set_access", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_access) }, - { "snd_pcm_hw_params_set_format", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_format) }, - { "snd_pcm_hw_params_set_channels", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_channels) }, - { "snd_pcm_hw_params_get_channels", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_channels) }, - { "snd_pcm_hw_params_set_rate_near", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_rate_near) }, - { "snd_pcm_hw_params_set_period_size_near", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_period_size_near) }, - { "snd_pcm_hw_params_get_period_size", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_period_size) }, - { "snd_pcm_hw_params_set_periods_near", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_periods_near) }, - { "snd_pcm_hw_params_get_periods", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_periods) }, - { "snd_pcm_hw_params", (void**)(char*)&SDL_NAME(snd_pcm_hw_params) }, - { "snd_pcm_sw_params_current", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_current) }, - { "snd_pcm_sw_params_set_start_threshold", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_start_threshold) }, - { "snd_pcm_sw_params_set_avail_min", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_avail_min) }, - { "snd_pcm_sw_params", (void**)(char*)&SDL_NAME(snd_pcm_sw_params) }, - { "snd_pcm_nonblock", (void**)(char*)&SDL_NAME(snd_pcm_nonblock) }, -}; - -static void UnloadALSALibrary(void) { - if (alsa_loaded) { + { + "snd_pcm_open", (void **) (char *) &SDL_NAME (snd_pcm_open)}, { + "snd_pcm_close", (void **) (char *) &SDL_NAME (snd_pcm_close)}, { + "snd_pcm_writei", (void **) (char *) &SDL_NAME (snd_pcm_writei)}, { + "snd_pcm_resume", (void **) (char *) &SDL_NAME (snd_pcm_resume)}, { + "snd_pcm_prepare", (void **) (char *) &SDL_NAME (snd_pcm_prepare)}, { + "snd_pcm_drain", (void **) (char *) &SDL_NAME (snd_pcm_drain)}, { + "snd_strerror", (void **) (char *) &SDL_NAME (snd_strerror)}, { + "snd_pcm_hw_params_sizeof", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_sizeof)}, { + "snd_pcm_sw_params_sizeof", + (void **) (char *) &SDL_NAME (snd_pcm_sw_params_sizeof)}, { + "snd_pcm_hw_params_any", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_any)}, { + "snd_pcm_hw_params_set_access", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_set_access)}, { + "snd_pcm_hw_params_set_format", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_set_format)}, { + "snd_pcm_hw_params_set_channels", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_set_channels)}, { + "snd_pcm_hw_params_get_channels", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_get_channels)}, { + "snd_pcm_hw_params_set_rate_near", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_set_rate_near)}, { + "snd_pcm_hw_params_set_period_size_near", (void **) (char *) + &SDL_NAME (snd_pcm_hw_params_set_period_size_near)}, { + "snd_pcm_hw_params_get_period_size", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_get_period_size)}, + { + "snd_pcm_hw_params_set_periods_near", (void **) (char *) + &SDL_NAME (snd_pcm_hw_params_set_periods_near)}, { + "snd_pcm_hw_params_get_periods", + (void **) (char *) &SDL_NAME (snd_pcm_hw_params_get_periods)}, { + "snd_pcm_hw_params", (void **) (char *) &SDL_NAME (snd_pcm_hw_params)}, { + "snd_pcm_sw_params_current", + (void **) (char *) &SDL_NAME (snd_pcm_sw_params_current)}, { + "snd_pcm_sw_params_set_start_threshold", (void **) (char *) + &SDL_NAME (snd_pcm_sw_params_set_start_threshold)}, { + "snd_pcm_sw_params_set_avail_min", + (void **) (char *) &SDL_NAME (snd_pcm_sw_params_set_avail_min)}, { + "snd_pcm_sw_params", (void **) (char *) &SDL_NAME (snd_pcm_sw_params)}, { +"snd_pcm_nonblock", (void **) (char *) &SDL_NAME (snd_pcm_nonblock)},}; + +static void +UnloadALSALibrary (void) +{ + if (alsa_loaded) { /* SDL_UnloadObject(alsa_handle);*/ - dlclose(alsa_handle); - alsa_handle = NULL; - alsa_loaded = 0; - } + dlclose (alsa_handle); + alsa_handle = NULL; + alsa_loaded = 0; + } } -static int LoadALSALibrary(void) { - int i, retval = -1; +static int +LoadALSALibrary (void) +{ + int i, retval = -1; /* alsa_handle = SDL_LoadObject(alsa_library);*/ - alsa_handle = dlopen(alsa_library,RTLD_NOW); - if (alsa_handle) { - alsa_loaded = 1; - retval = 0; - for (i = 0; i < SDL_arraysize(alsa_functions); i++) { + alsa_handle = dlopen (alsa_library, RTLD_NOW); + if (alsa_handle) { + alsa_loaded = 1; + retval = 0; + for (i = 0; i < SDL_arraysize (alsa_functions); i++) { /* *alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);*/ #if HAVE_DLVSYM - *alsa_functions[i].func = dlvsym(alsa_handle,alsa_functions[i].name,"ALSA_0.9"); - if (!*alsa_functions[i].func) + *alsa_functions[i].func = + dlvsym (alsa_handle, alsa_functions[i].name, "ALSA_0.9"); + if (!*alsa_functions[i].func) #endif - *alsa_functions[i].func = dlsym(alsa_handle,alsa_functions[i].name); - if (!*alsa_functions[i].func) { - retval = -1; - UnloadALSALibrary(); - break; - } - } - } - return retval; + *alsa_functions[i].func = + dlsym (alsa_handle, alsa_functions[i].name); + if (!*alsa_functions[i].func) { + retval = -1; + UnloadALSALibrary (); + break; + } + } + } + return retval; } #else -static void UnloadALSALibrary(void) { - return; +static void +UnloadALSALibrary (void) +{ + return; } -static int LoadALSALibrary(void) { - return 0; +static int +LoadALSALibrary (void) +{ + return 0; } #endif /* SDL_AUDIO_DRIVER_ALSA_DYNAMIC */ -static const char *get_audio_device(int channels) +static const char * +get_audio_device (int channels) { - const char *device; - - device = SDL_getenv("AUDIODEV"); /* Is there a standard variable name? */ - if ( device == NULL ) { - if (channels == 6) device = "surround51"; - else if (channels == 4) device = "surround40"; - else device = DEFAULT_DEVICE; - } - return device; + const char *device; + + device = SDL_getenv ("AUDIODEV"); /* Is there a standard variable name? */ + if (device == NULL) { + if (channels == 6) + device = "surround51"; + else if (channels == 4) + device = "surround40"; + else + device = DEFAULT_DEVICE; + } + return device; } /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - int available; - int status; - snd_pcm_t *handle; - - available = 0; - if (LoadALSALibrary() < 0) { - return available; - } - status = SDL_NAME(snd_pcm_open)(&handle, get_audio_device(2), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); - if ( status >= 0 ) { - available = 1; - SDL_NAME(snd_pcm_close)(handle); - } - UnloadALSALibrary(); - return(available); + int available; + int status; + snd_pcm_t *handle; + + available = 0; + if (LoadALSALibrary () < 0) { + return available; + } + status = + SDL_NAME (snd_pcm_open) (&handle, get_audio_device (2), + SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); + if (status >= 0) { + available = 1; + SDL_NAME (snd_pcm_close) (handle); + } + UnloadALSALibrary (); + return (available); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); - UnloadALSALibrary(); + SDL_free (device->hidden); + SDL_free (device); + UnloadALSALibrary (); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - LoadALSALibrary(); - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = ALSA_OpenAudio; - this->WaitAudio = ALSA_WaitAudio; - this->PlayAudio = ALSA_PlayAudio; - this->GetAudioBuf = ALSA_GetAudioBuf; - this->CloseAudio = ALSA_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + LoadALSALibrary (); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = ALSA_OpenAudio; + this->WaitAudio = ALSA_WaitAudio; + this->PlayAudio = ALSA_PlayAudio; + this->GetAudioBuf = ALSA_GetAudioBuf; + this->CloseAudio = ALSA_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap ALSA_bootstrap = { - DRIVER_NAME, "ALSA 0.9 PCM audio", - Audio_Available, Audio_CreateDevice + DRIVER_NAME, "ALSA 0.9 PCM audio", + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void ALSA_WaitAudio(_THIS) +static void +ALSA_WaitAudio (_THIS) { - /* Check to see if the thread-parent process is still alive */ - { static int cnt = 0; - /* Note that this only works with thread implementations - that use a different process id for each thread. - */ - if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ - if ( kill(parent, 0) < 0 ) { - this->enabled = 0; - } - } - } + /* Check to see if the thread-parent process is still alive */ + { + static int cnt = 0; + /* Note that this only works with thread implementations + that use a different process id for each thread. + */ + if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */ + if (kill (parent, 0) < 0) { + this->enabled = 0; + } + } + } } -static void ALSA_PlayAudio(_THIS) +static void +ALSA_PlayAudio (_THIS) { - int status; - int sample_len; - signed short *sample_buf; - - sample_len = this->spec.samples; - sample_buf = (signed short *)mixbuf; - while ( sample_len > 0 ) { - status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, sample_len); - if ( status < 0 ) { - if ( status == -EAGAIN ) { - SDL_Delay(1); - continue; - } - if ( status == -ESTRPIPE ) { - do { - SDL_Delay(1); - status = SDL_NAME(snd_pcm_resume)(pcm_handle); - } while ( status == -EAGAIN ); - } - if ( status < 0 ) { - status = SDL_NAME(snd_pcm_prepare)(pcm_handle); - } - if ( status < 0 ) { - /* Hmm, not much we can do - abort */ - this->enabled = 0; - return; - } - continue; - } - sample_buf += status * this->spec.channels; - sample_len -= status; - } + int status; + int sample_len; + signed short *sample_buf; + + sample_len = this->spec.samples; + sample_buf = (signed short *) mixbuf; + while (sample_len > 0) { + status = + SDL_NAME (snd_pcm_writei) (pcm_handle, sample_buf, sample_len); + if (status < 0) { + if (status == -EAGAIN) { + SDL_Delay (1); + continue; + } + if (status == -ESTRPIPE) { + do { + SDL_Delay (1); + status = SDL_NAME (snd_pcm_resume) (pcm_handle); + } + while (status == -EAGAIN); + } + if (status < 0) { + status = SDL_NAME (snd_pcm_prepare) (pcm_handle); + } + if (status < 0) { + /* Hmm, not much we can do - abort */ + this->enabled = 0; + return; + } + continue; + } + sample_buf += status * this->spec.channels; + sample_len -= status; + } } -static Uint8 *ALSA_GetAudioBuf(_THIS) +static Uint8 * +ALSA_GetAudioBuf (_THIS) { - return(mixbuf); + return (mixbuf); } -static void ALSA_CloseAudio(_THIS) +static void +ALSA_CloseAudio (_THIS) { - if ( mixbuf != NULL ) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if ( pcm_handle ) { - SDL_NAME(snd_pcm_drain)(pcm_handle); - SDL_NAME(snd_pcm_close)(pcm_handle); - pcm_handle = NULL; - } + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; + } + if (pcm_handle) { + SDL_NAME (snd_pcm_drain) (pcm_handle); + SDL_NAME (snd_pcm_close) (pcm_handle); + pcm_handle = NULL; + } } -static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +ALSA_OpenAudio (_THIS, SDL_AudioSpec * spec) { - int status; - snd_pcm_hw_params_t *hwparams; - snd_pcm_sw_params_t *swparams; - snd_pcm_format_t format; - snd_pcm_uframes_t frames; - Uint16 test_format; - - /* Open the audio device */ - /* Name of device should depend on # channels in spec */ - status = SDL_NAME(snd_pcm_open)(&pcm_handle, get_audio_device(spec->channels), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); - - if ( status < 0 ) { - SDL_SetError("Couldn't open audio device: %s", SDL_NAME(snd_strerror)(status)); - return(-1); - } - - /* Figure out what the hardware is capable of */ - snd_pcm_hw_params_alloca(&hwparams); - status = SDL_NAME(snd_pcm_hw_params_any)(pcm_handle, hwparams); - if ( status < 0 ) { - SDL_SetError("Couldn't get hardware config: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } - - /* SDL only uses interleaved sample output */ - status = SDL_NAME(snd_pcm_hw_params_set_access)(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); - if ( status < 0 ) { - SDL_SetError("Couldn't set interleaved access: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } - - /* Try for a closest match on audio format */ - status = -1; - for ( test_format = SDL_FirstAudioFormat(spec->format); - test_format && (status < 0); ) { - switch ( test_format ) { - case AUDIO_U8: - format = SND_PCM_FORMAT_U8; - break; - case AUDIO_S8: - format = SND_PCM_FORMAT_S8; - break; - case AUDIO_S16LSB: - format = SND_PCM_FORMAT_S16_LE; - break; - case AUDIO_S16MSB: - format = SND_PCM_FORMAT_S16_BE; - break; - case AUDIO_U16LSB: - format = SND_PCM_FORMAT_U16_LE; - break; - case AUDIO_U16MSB: - format = SND_PCM_FORMAT_U16_BE; - break; - default: - format = 0; - break; - } - if ( format != 0 ) { - status = SDL_NAME(snd_pcm_hw_params_set_format)(pcm_handle, hwparams, format); - } - if ( status < 0 ) { - test_format = SDL_NextAudioFormat(); - } - } - if ( status < 0 ) { - SDL_SetError("Couldn't find any hardware audio formats"); - ALSA_CloseAudio(this); - return(-1); - } - spec->format = test_format; - - /* Set the number of channels */ - status = SDL_NAME(snd_pcm_hw_params_set_channels)(pcm_handle, hwparams, spec->channels); - if ( status < 0 ) { - status = SDL_NAME(snd_pcm_hw_params_get_channels)(hwparams); - if ( (status <= 0) || (status > 2) ) { - SDL_SetError("Couldn't set audio channels"); - ALSA_CloseAudio(this); - return(-1); - } - spec->channels = status; - } - - /* Set the audio rate */ - status = SDL_NAME(snd_pcm_hw_params_set_rate_near)(pcm_handle, hwparams, spec->freq, NULL); - if ( status < 0 ) { - SDL_SetError("Couldn't set audio frequency: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } - spec->freq = status; - - /* Set the buffer size, in samples */ - frames = spec->samples; - frames = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, frames, NULL); - spec->samples = frames; - SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, 2, NULL); - - /* "set" the hardware with the desired parameters */ - status = SDL_NAME(snd_pcm_hw_params)(pcm_handle, hwparams); - if ( status < 0 ) { - SDL_SetError("Couldn't set hardware audio parameters: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } + int status; + snd_pcm_hw_params_t *hwparams; + snd_pcm_sw_params_t *swparams; + snd_pcm_format_t format; + snd_pcm_uframes_t frames; + Uint16 test_format; + + /* Open the audio device */ + /* Name of device should depend on # channels in spec */ + status = + SDL_NAME (snd_pcm_open) (&pcm_handle, + get_audio_device (spec->channels), + SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); + + if (status < 0) { + SDL_SetError ("Couldn't open audio device: %s", + SDL_NAME (snd_strerror) (status)); + return (-1); + } + + /* Figure out what the hardware is capable of */ + snd_pcm_hw_params_alloca (&hwparams); + status = SDL_NAME (snd_pcm_hw_params_any) (pcm_handle, hwparams); + if (status < 0) { + SDL_SetError ("Couldn't get hardware config: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } + + /* SDL only uses interleaved sample output */ + status = + SDL_NAME (snd_pcm_hw_params_set_access) (pcm_handle, hwparams, + SND_PCM_ACCESS_RW_INTERLEAVED); + if (status < 0) { + SDL_SetError ("Couldn't set interleaved access: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } + + /* Try for a closest match on audio format */ + status = -1; + for (test_format = SDL_FirstAudioFormat (spec->format); + test_format && (status < 0);) { + switch (test_format) { + case AUDIO_U8: + format = SND_PCM_FORMAT_U8; + break; + case AUDIO_S8: + format = SND_PCM_FORMAT_S8; + break; + case AUDIO_S16LSB: + format = SND_PCM_FORMAT_S16_LE; + break; + case AUDIO_S16MSB: + format = SND_PCM_FORMAT_S16_BE; + break; + case AUDIO_U16LSB: + format = SND_PCM_FORMAT_U16_LE; + break; + case AUDIO_U16MSB: + format = SND_PCM_FORMAT_U16_BE; + break; + default: + format = 0; + break; + } + if (format != 0) { + status = + SDL_NAME (snd_pcm_hw_params_set_format) (pcm_handle, + hwparams, format); + } + if (status < 0) { + test_format = SDL_NextAudioFormat (); + } + } + if (status < 0) { + SDL_SetError ("Couldn't find any hardware audio formats"); + ALSA_CloseAudio (this); + return (-1); + } + spec->format = test_format; + + /* Set the number of channels */ + status = + SDL_NAME (snd_pcm_hw_params_set_channels) (pcm_handle, hwparams, + spec->channels); + if (status < 0) { + status = SDL_NAME (snd_pcm_hw_params_get_channels) (hwparams); + if ((status <= 0) || (status > 2)) { + SDL_SetError ("Couldn't set audio channels"); + ALSA_CloseAudio (this); + return (-1); + } + spec->channels = status; + } + + /* Set the audio rate */ + status = + SDL_NAME (snd_pcm_hw_params_set_rate_near) (pcm_handle, hwparams, + spec->freq, NULL); + if (status < 0) { + SDL_SetError ("Couldn't set audio frequency: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } + spec->freq = status; + + /* Set the buffer size, in samples */ + frames = spec->samples; + frames = + SDL_NAME (snd_pcm_hw_params_set_period_size_near) (pcm_handle, + hwparams, frames, + NULL); + spec->samples = frames; + SDL_NAME (snd_pcm_hw_params_set_periods_near) (pcm_handle, hwparams, 2, + NULL); + + /* "set" the hardware with the desired parameters */ + status = SDL_NAME (snd_pcm_hw_params) (pcm_handle, hwparams); + if (status < 0) { + SDL_SetError ("Couldn't set hardware audio parameters: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } /* This is useful for debugging... */ /* @@ -439,51 +558,61 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec) } */ - /* Set the software parameters */ - snd_pcm_sw_params_alloca(&swparams); - status = SDL_NAME(snd_pcm_sw_params_current)(pcm_handle, swparams); - if ( status < 0 ) { - SDL_SetError("Couldn't get software config: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } - status = SDL_NAME(snd_pcm_sw_params_set_start_threshold)(pcm_handle, swparams, 0); - if ( status < 0 ) { - SDL_SetError("Couldn't set start threshold: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } - status = SDL_NAME(snd_pcm_sw_params_set_avail_min)(pcm_handle, swparams, frames); - if ( status < 0 ) { - SDL_SetError("Couldn't set avail min: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } - status = SDL_NAME(snd_pcm_sw_params)(pcm_handle, swparams); - if ( status < 0 ) { - SDL_SetError("Couldn't set software audio parameters: %s", SDL_NAME(snd_strerror)(status)); - ALSA_CloseAudio(this); - return(-1); - } - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - - /* Allocate mixing buffer */ - mixlen = spec->size; - mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); - if ( mixbuf == NULL ) { - ALSA_CloseAudio(this); - return(-1); - } - SDL_memset(mixbuf, spec->silence, spec->size); - - /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); - - /* Switch to blocking mode for playback */ - SDL_NAME(snd_pcm_nonblock)(pcm_handle, 0); - - /* We're ready to rock and roll. :-) */ - return(0); + /* Set the software parameters */ + snd_pcm_sw_params_alloca (&swparams); + status = SDL_NAME (snd_pcm_sw_params_current) (pcm_handle, swparams); + if (status < 0) { + SDL_SetError ("Couldn't get software config: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } + status = + SDL_NAME (snd_pcm_sw_params_set_start_threshold) (pcm_handle, + swparams, 0); + if (status < 0) { + SDL_SetError ("Couldn't set start threshold: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } + status = + SDL_NAME (snd_pcm_sw_params_set_avail_min) (pcm_handle, swparams, + frames); + if (status < 0) { + SDL_SetError ("Couldn't set avail min: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } + status = SDL_NAME (snd_pcm_sw_params) (pcm_handle, swparams); + if (status < 0) { + SDL_SetError ("Couldn't set software audio parameters: %s", + SDL_NAME (snd_strerror) (status)); + ALSA_CloseAudio (this); + return (-1); + } + + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + + /* Allocate mixing buffer */ + mixlen = spec->size; + mixbuf = (Uint8 *) SDL_AllocAudioMem (mixlen); + if (mixbuf == NULL) { + ALSA_CloseAudio (this); + return (-1); + } + SDL_memset (mixbuf, spec->silence, spec->size); + + /* Get the parent process id (we're the parent of the audio thread) */ + parent = getpid (); + + /* Switch to blocking mode for playback */ + SDL_NAME (snd_pcm_nonblock) (pcm_handle, 0); + + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/alsa/SDL_alsa_audio.h b/src/audio/alsa/SDL_alsa_audio.h index fd9ac0381..aa2eb786a 100644 --- a/src/audio/alsa/SDL_alsa_audio.h +++ b/src/audio/alsa/SDL_alsa_audio.h @@ -33,16 +33,17 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The audio device handle */ - snd_pcm_t *pcm_handle; +struct SDL_PrivateAudioData +{ + /* The audio device handle */ + snd_pcm_t *pcm_handle; - /* The parent process id, to detect when application quits */ - pid_t parent; + /* The parent process id, to detect when application quits */ + pid_t parent; - /* Raw mixing buffer */ - Uint8 *mixbuf; - int mixlen; + /* Raw mixing buffer */ + Uint8 *mixbuf; + int mixlen; }; /* Old variable names */ @@ -52,3 +53,4 @@ struct SDL_PrivateAudioData { #define mixlen (this->hidden->mixlen) #endif /* _ALSA_PCM_audio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/amigaos/SDL_ahiaudio.c b/src/audio/amigaos/SDL_ahiaudio.c index c9a4c1a4f..bec3eb90f 100644 --- a/src/audio/amigaos/SDL_ahiaudio.c +++ b/src/audio/amigaos/SDL_ahiaudio.c @@ -28,310 +28,322 @@ #include "SDL_ahiaudio.h" /* Audio driver functions */ -static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void AHI_WaitAudio(_THIS); -static void AHI_PlayAudio(_THIS); -static Uint8 *AHI_GetAudioBuf(_THIS); -static void AHI_CloseAudio(_THIS); +static int AHI_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void AHI_WaitAudio (_THIS); +static void AHI_PlayAudio (_THIS); +static Uint8 *AHI_GetAudioBuf (_THIS); +static void AHI_CloseAudio (_THIS); #ifndef __SASC - #define mymalloc(x) AllocVec(x,MEMF_PUBLIC) - #define myfree FreeVec +#define mymalloc(x) AllocVec(x,MEMF_PUBLIC) +#define myfree FreeVec #else - #define mymalloc malloc - #define myfree free +#define mymalloc malloc +#define myfree free #endif /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - int ok=0; - struct MsgPort *p; - struct AHIRequest *req; - - if(p=CreateMsgPort()) - { - if(req=(struct AHIRequest *)CreateIORequest(p,sizeof(struct AHIRequest))) - { - req->ahir_Version=4; - - if(!OpenDevice(AHINAME,0,(struct IORequest *)req,NULL)) - { - D(bug("AHI available.\n")); - ok=1; - CloseDevice((struct IORequest *)req); - } - DeleteIORequest((struct IORequest *)req); - } - DeleteMsgPort(p); - } - - D(if(!ok) bug("AHI not available\n")); - return ok; + int ok = 0; + struct MsgPort *p; + struct AHIRequest *req; + + if (p = CreateMsgPort ()) { + if (req = + (struct AHIRequest *) CreateIORequest (p, + sizeof (struct + AHIRequest))) { + req->ahir_Version = 4; + + if (!OpenDevice (AHINAME, 0, (struct IORequest *) req, NULL)) { + D (bug ("AHI available.\n")); + ok = 1; + CloseDevice ((struct IORequest *) req); + } + DeleteIORequest ((struct IORequest *) req); + } + DeleteMsgPort (p); + } + + D (if (!ok) bug ("AHI not available\n")); + return ok; } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; + SDL_AudioDevice *this; #ifndef NO_AMIGADEBUG - D(bug("AHI created...\n")); + D (bug ("AHI created...\n")); #endif - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = AHI_OpenAudio; - this->WaitAudio = AHI_WaitAudio; - this->PlayAudio = AHI_PlayAudio; - this->GetAudioBuf = AHI_GetAudioBuf; - this->CloseAudio = AHI_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = AHI_OpenAudio; + this->WaitAudio = AHI_WaitAudio; + this->PlayAudio = AHI_PlayAudio; + this->GetAudioBuf = AHI_GetAudioBuf; + this->CloseAudio = AHI_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap AHI_bootstrap = { - "AHI", Audio_Available, Audio_CreateDevice + "AHI", Audio_Available, Audio_CreateDevice }; -void static AHI_WaitAudio(_THIS) +void static +AHI_WaitAudio (_THIS) { - if(!CheckIO((struct IORequest *)audio_req[current_buffer])) - { - WaitIO((struct IORequest *)audio_req[current_buffer]); -// AbortIO((struct IORequest *)audio_req[current_buffer]); - } + if (!CheckIO ((struct IORequest *) audio_req[current_buffer])) { + WaitIO ((struct IORequest *) audio_req[current_buffer]); +// AbortIO((struct IORequest *)audio_req[current_buffer]); + } } -static void AHI_PlayAudio(_THIS) +static void +AHI_PlayAudio (_THIS) { - if(playing>1) - WaitIO((struct IORequest *)audio_req[current_buffer]); - - /* Write the audio data out */ - audio_req[current_buffer] -> ahir_Std. io_Message.mn_Node.ln_Pri = 60; - audio_req[current_buffer] -> ahir_Std. io_Data = mixbuf[current_buffer]; - audio_req[current_buffer] -> ahir_Std. io_Length = this->hidden->size; - audio_req[current_buffer] -> ahir_Std. io_Offset = 0; - audio_req[current_buffer] -> ahir_Std . io_Command = CMD_WRITE; - audio_req[current_buffer] -> ahir_Frequency = this->hidden->freq; - audio_req[current_buffer] -> ahir_Volume = 0x10000; - audio_req[current_buffer] -> ahir_Type = this->hidden->type; - audio_req[current_buffer] -> ahir_Position = 0x8000; - audio_req[current_buffer] -> ahir_Link = (playing>0 ? audio_req[current_buffer^1] : NULL); - - SendIO((struct IORequest *)audio_req[current_buffer]); - current_buffer^=1; - - playing++; + if (playing > 1) + WaitIO ((struct IORequest *) audio_req[current_buffer]); + + /* Write the audio data out */ + audio_req[current_buffer]->ahir_Std.io_Message.mn_Node.ln_Pri = 60; + audio_req[current_buffer]->ahir_Std.io_Data = mixbuf[current_buffer]; + audio_req[current_buffer]->ahir_Std.io_Length = this->hidden->size; + audio_req[current_buffer]->ahir_Std.io_Offset = 0; + audio_req[current_buffer]->ahir_Std.io_Command = CMD_WRITE; + audio_req[current_buffer]->ahir_Frequency = this->hidden->freq; + audio_req[current_buffer]->ahir_Volume = 0x10000; + audio_req[current_buffer]->ahir_Type = this->hidden->type; + audio_req[current_buffer]->ahir_Position = 0x8000; + audio_req[current_buffer]->ahir_Link = + (playing > 0 ? audio_req[current_buffer ^ 1] : NULL); + + SendIO ((struct IORequest *) audio_req[current_buffer]); + current_buffer ^= 1; + + playing++; } -static Uint8 *AHI_GetAudioBuf(_THIS) +static Uint8 * +AHI_GetAudioBuf (_THIS) { - return(mixbuf[current_buffer]); + return (mixbuf[current_buffer]); } -static void AHI_CloseAudio(_THIS) +static void +AHI_CloseAudio (_THIS) { - D(bug("Closing audio...\n")); + D (bug ("Closing audio...\n")); - playing=0; + playing = 0; - if(audio_req[0]) - { - if(audio_req[1]) - { - D(bug("Break req[1]...\n")); + if (audio_req[0]) { + if (audio_req[1]) { + D (bug ("Break req[1]...\n")); - AbortIO((struct IORequest *)audio_req[1]); - WaitIO((struct IORequest *)audio_req[1]); - } + AbortIO ((struct IORequest *) audio_req[1]); + WaitIO ((struct IORequest *) audio_req[1]); + } - D(bug("Break req[0]...\n")); + D (bug ("Break req[0]...\n")); - AbortIO((struct IORequest *)audio_req[0]); - WaitIO((struct IORequest *)audio_req[0]); + AbortIO ((struct IORequest *) audio_req[0]); + WaitIO ((struct IORequest *) audio_req[0]); - if(audio_req[1]) - { - D(bug("Break AGAIN req[1]...\n")); - AbortIO((struct IORequest *)audio_req[1]); - WaitIO((struct IORequest *)audio_req[1]); - } + if (audio_req[1]) { + D (bug ("Break AGAIN req[1]...\n")); + AbortIO ((struct IORequest *) audio_req[1]); + WaitIO ((struct IORequest *) audio_req[1]); + } // Double abort to be sure to break the dbuffering process. - SDL_Delay(200); - - D(bug("Reqs breaked, closing device...\n")); - CloseDevice((struct IORequest *)audio_req[0]); - D(bug("Device closed, freeing memory...\n")); - myfree(audio_req[1]); - D(bug("Memory freed, deleting IOReq...\n")); - DeleteIORequest((struct IORequest *)audio_req[0]); - audio_req[0]=audio_req[1]=NULL; - } - - D(bug("Freeing mixbuf[0]...\n")); - if ( mixbuf[0] != NULL ) { - myfree(mixbuf[0]); -// SDL_FreeAudioMem(mixbuf[0]); - mixbuf[0] = NULL; - } - - D(bug("Freeing mixbuf[1]...\n")); - if ( mixbuf[1] != NULL ) { - myfree(mixbuf[1]); -// SDL_FreeAudioMem(mixbuf[1]); - mixbuf[1] = NULL; - } - - D(bug("Freeing audio_port...\n")); - - if ( audio_port != NULL ) { - DeleteMsgPort(audio_port); - audio_port = NULL; - } - D(bug("...done!\n")); + SDL_Delay (200); + + D (bug ("Reqs breaked, closing device...\n")); + CloseDevice ((struct IORequest *) audio_req[0]); + D (bug ("Device closed, freeing memory...\n")); + myfree (audio_req[1]); + D (bug ("Memory freed, deleting IOReq...\n")); + DeleteIORequest ((struct IORequest *) audio_req[0]); + audio_req[0] = audio_req[1] = NULL; + } + + D (bug ("Freeing mixbuf[0]...\n")); + if (mixbuf[0] != NULL) { + myfree (mixbuf[0]); +// SDL_FreeAudioMem(mixbuf[0]); + mixbuf[0] = NULL; + } + + D (bug ("Freeing mixbuf[1]...\n")); + if (mixbuf[1] != NULL) { + myfree (mixbuf[1]); +// SDL_FreeAudioMem(mixbuf[1]); + mixbuf[1] = NULL; + } + + D (bug ("Freeing audio_port...\n")); + + if (audio_port != NULL) { + DeleteMsgPort (audio_port); + audio_port = NULL; + } + D (bug ("...done!\n")); } -static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec) -{ -// int width; - - D(bug("AHI opening...\n")); - - /* Determine the audio parameters from the AudioSpec */ - switch ( spec->format & 0xFF ) { - - case 8: { /* Signed 8 bit audio data */ - D(bug("Samples a 8 bit...\n")); - spec->format = AUDIO_S8; - this->hidden->bytespersample=1; - if(spec->channels<2) - this->hidden->type = AHIST_M8S; - else - this->hidden->type = AHIST_S8S; - } - break; - - case 16: { /* Signed 16 bit audio data */ - D(bug("Samples a 16 bit...\n")); - spec->format = AUDIO_S16MSB; - this->hidden->bytespersample=2; - if(spec->channels<2) - this->hidden->type = AHIST_M16S; - else - this->hidden->type = AHIST_S16S; - } - break; - - default: { - SDL_SetError("Unsupported audio format"); - return(-1); - } - } - - if(spec->channels!=1 && spec->channels!=2) - { - D(bug("Wrong channel number!\n")); - SDL_SetError("Channel number non supported"); - return -1; - } - - D(bug("Before CalculateAudioSpec\n")); - /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); - - D(bug("Before CreateMsgPort\n")); - - if(!(audio_port=CreateMsgPort())) - { - SDL_SetError("Unable to create a MsgPort"); - return -1; - } - - D(bug("Before CreateIORequest\n")); - - if(!(audio_req[0]=(struct AHIRequest *)CreateIORequest(audio_port,sizeof(struct AHIRequest)))) - { - SDL_SetError("Unable to create an AHIRequest"); - DeleteMsgPort(audio_port); - return -1; - } - - audio_req[0]->ahir_Version = 4; - - if(OpenDevice(AHINAME,0,(struct IORequest *)audio_req[0],NULL)) - { - SDL_SetError("Unable to open AHI device!\n"); - DeleteIORequest((struct IORequest *)audio_req[0]); - DeleteMsgPort(audio_port); - return -1; - } - - D(bug("AFTER opendevice\n")); - - /* Set output frequency and size */ - this->hidden->freq = spec->freq; - this->hidden->size = spec->size; - - D(bug("Before buffer allocation\n")); - - /* Allocate mixing buffer */ - mixbuf[0] = (Uint8 *)mymalloc(spec->size); - mixbuf[1] = (Uint8 *)mymalloc(spec->size); - - D(bug("Before audio_req allocation\n")); - - if(!(audio_req[1]=mymalloc(sizeof(struct AHIRequest)))) - { - SDL_OutOfMemory(); - return(-1); - } - - D(bug("Before audio_req memcpy\n")); - - SDL_memcpy(audio_req[1],audio_req[0],sizeof(struct AHIRequest)); - - if ( mixbuf[0] == NULL || mixbuf[1] == NULL ) { - SDL_OutOfMemory(); - return(-1); - } - - D(bug("Before mixbuf memset\n")); - - SDL_memset(mixbuf[0], spec->silence, spec->size); - SDL_memset(mixbuf[1], spec->silence, spec->size); - - current_buffer=0; - playing=0; - - D(bug("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n",spec->freq,mixbuf[0],mixbuf[1],spec->size,this->hidden->bytespersample*8,spec->channels)); - - /* We're ready to rock and roll. :-) */ - return(0); +static int +AHI_OpenAudio (_THIS, SDL_AudioSpec * spec) +{ +// int width; + + D (bug ("AHI opening...\n")); + + /* Determine the audio parameters from the AudioSpec */ + switch (spec->format & 0xFF) { + + case 8: + { /* Signed 8 bit audio data */ + D (bug ("Samples a 8 bit...\n")); + spec->format = AUDIO_S8; + this->hidden->bytespersample = 1; + if (spec->channels < 2) + this->hidden->type = AHIST_M8S; + else + this->hidden->type = AHIST_S8S; + } + break; + + case 16: + { /* Signed 16 bit audio data */ + D (bug ("Samples a 16 bit...\n")); + spec->format = AUDIO_S16MSB; + this->hidden->bytespersample = 2; + if (spec->channels < 2) + this->hidden->type = AHIST_M16S; + else + this->hidden->type = AHIST_S16S; + } + break; + + default: + { + SDL_SetError ("Unsupported audio format"); + return (-1); + } + } + + if (spec->channels != 1 && spec->channels != 2) { + D (bug ("Wrong channel number!\n")); + SDL_SetError ("Channel number non supported"); + return -1; + } + + D (bug ("Before CalculateAudioSpec\n")); + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec (spec); + + D (bug ("Before CreateMsgPort\n")); + + if (!(audio_port = CreateMsgPort ())) { + SDL_SetError ("Unable to create a MsgPort"); + return -1; + } + + D (bug ("Before CreateIORequest\n")); + + if (! + (audio_req[0] = + (struct AHIRequest *) CreateIORequest (audio_port, + sizeof (struct AHIRequest)))) + { + SDL_SetError ("Unable to create an AHIRequest"); + DeleteMsgPort (audio_port); + return -1; + } + + audio_req[0]->ahir_Version = 4; + + if (OpenDevice (AHINAME, 0, (struct IORequest *) audio_req[0], NULL)) { + SDL_SetError ("Unable to open AHI device!\n"); + DeleteIORequest ((struct IORequest *) audio_req[0]); + DeleteMsgPort (audio_port); + return -1; + } + + D (bug ("AFTER opendevice\n")); + + /* Set output frequency and size */ + this->hidden->freq = spec->freq; + this->hidden->size = spec->size; + + D (bug ("Before buffer allocation\n")); + + /* Allocate mixing buffer */ + mixbuf[0] = (Uint8 *) mymalloc (spec->size); + mixbuf[1] = (Uint8 *) mymalloc (spec->size); + + D (bug ("Before audio_req allocation\n")); + + if (!(audio_req[1] = mymalloc (sizeof (struct AHIRequest)))) { + SDL_OutOfMemory (); + return (-1); + } + + D (bug ("Before audio_req memcpy\n")); + + SDL_memcpy (audio_req[1], audio_req[0], sizeof (struct AHIRequest)); + + if (mixbuf[0] == NULL || mixbuf[1] == NULL) { + SDL_OutOfMemory (); + return (-1); + } + + D (bug ("Before mixbuf memset\n")); + + SDL_memset (mixbuf[0], spec->silence, spec->size); + SDL_memset (mixbuf[1], spec->silence, spec->size); + + current_buffer = 0; + playing = 0; + + D (bug + ("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n", + spec->freq, mixbuf[0], mixbuf[1], spec->size, + this->hidden->bytespersample * 8, spec->channels)); + + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/amigaos/SDL_ahiaudio.h b/src/audio/amigaos/SDL_ahiaudio.h index b9ef339c6..7e311daa6 100644 --- a/src/audio/amigaos/SDL_ahiaudio.h +++ b/src/audio/amigaos/SDL_ahiaudio.h @@ -40,14 +40,15 @@ /* Hidden "this" pointer for the audio functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The handle for the audio device */ - struct AHIRequest *audio_req[2]; - struct MsgPort *audio_port; - Sint32 freq,type,bytespersample,size; - Uint8 *mixbuf[2]; /* The app mixing buffer */ - int current_buffer; - Uint32 playing; +struct SDL_PrivateAudioData +{ + /* The handle for the audio device */ + struct AHIRequest *audio_req[2]; + struct MsgPort *audio_port; + Sint32 freq, type, bytespersample, size; + Uint8 *mixbuf[2]; /* The app mixing buffer */ + int current_buffer; + Uint32 playing; }; /* Old variable names */ @@ -58,3 +59,4 @@ struct SDL_PrivateAudioData { #define playing (this->hidden->playing) #endif /* _SDL_ahiaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/arts/SDL_artsaudio.c b/src/audio/arts/SDL_artsaudio.c index 59949a52f..d2112bdf1 100644 --- a/src/audio/arts/SDL_artsaudio.c +++ b/src/audio/arts/SDL_artsaudio.c @@ -41,11 +41,11 @@ #define ARTS_DRIVER_NAME "arts" /* Audio driver functions */ -static int ARTS_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void ARTS_WaitAudio(_THIS); -static void ARTS_PlayAudio(_THIS); -static Uint8 *ARTS_GetAudioBuf(_THIS); -static void ARTS_CloseAudio(_THIS); +static int ARTS_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void ARTS_WaitAudio (_THIS); +static void ARTS_PlayAudio (_THIS); +static Uint8 *ARTS_GetAudioBuf (_THIS); +static void ARTS_CloseAudio (_THIS); #ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC @@ -53,281 +53,305 @@ static const char *arts_library = SDL_AUDIO_DRIVER_ARTS_DYNAMIC; static void *arts_handle = NULL; static int arts_loaded = 0; -static int (*SDL_NAME(arts_init))(void); -static void (*SDL_NAME(arts_free))(void); -static arts_stream_t (*SDL_NAME(arts_play_stream))(int rate, int bits, int channels, const char *name); -static int (*SDL_NAME(arts_stream_set))(arts_stream_t s, arts_parameter_t param, int value); -static int (*SDL_NAME(arts_stream_get))(arts_stream_t s, arts_parameter_t param); -static int (*SDL_NAME(arts_write))(arts_stream_t s, const void *buffer, int count); -static void (*SDL_NAME(arts_close_stream))(arts_stream_t s); - -static struct { - const char *name; - void **func; +static int (*SDL_NAME (arts_init)) (void); +static void (*SDL_NAME (arts_free)) (void); +static arts_stream_t (*SDL_NAME (arts_play_stream)) (int rate, int bits, + int channels, + const char *name); +static int (*SDL_NAME (arts_stream_set)) (arts_stream_t s, + arts_parameter_t param, int value); +static int (*SDL_NAME (arts_stream_get)) (arts_stream_t s, + arts_parameter_t param); +static int (*SDL_NAME (arts_write)) (arts_stream_t s, const void *buffer, + int count); +static void (*SDL_NAME (arts_close_stream)) (arts_stream_t s); + +static struct +{ + const char *name; + void **func; } arts_functions[] = { - { "arts_init", (void **)&SDL_NAME(arts_init) }, - { "arts_free", (void **)&SDL_NAME(arts_free) }, - { "arts_play_stream", (void **)&SDL_NAME(arts_play_stream) }, - { "arts_stream_set", (void **)&SDL_NAME(arts_stream_set) }, - { "arts_stream_get", (void **)&SDL_NAME(arts_stream_get) }, - { "arts_write", (void **)&SDL_NAME(arts_write) }, - { "arts_close_stream", (void **)&SDL_NAME(arts_close_stream) }, -}; - -static void UnloadARTSLibrary() + { + "arts_init", (void **) &SDL_NAME (arts_init)}, { + "arts_free", (void **) &SDL_NAME (arts_free)}, { + "arts_play_stream", (void **) &SDL_NAME (arts_play_stream)}, { + "arts_stream_set", (void **) &SDL_NAME (arts_stream_set)}, { + "arts_stream_get", (void **) &SDL_NAME (arts_stream_get)}, { + "arts_write", (void **) &SDL_NAME (arts_write)}, { +"arts_close_stream", (void **) &SDL_NAME (arts_close_stream)},}; + +static void +UnloadARTSLibrary () { - if ( arts_loaded ) { - SDL_UnloadObject(arts_handle); - arts_handle = NULL; - arts_loaded = 0; - } + if (arts_loaded) { + SDL_UnloadObject (arts_handle); + arts_handle = NULL; + arts_loaded = 0; + } } -static int LoadARTSLibrary(void) +static int +LoadARTSLibrary (void) { - int i, retval = -1; - - arts_handle = SDL_LoadObject(arts_library); - if ( arts_handle ) { - arts_loaded = 1; - retval = 0; - for ( i=0; ihidden); - SDL_free(device); - UnloadARTSLibrary(); + SDL_free (device->hidden); + SDL_free (device); + UnloadARTSLibrary (); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - LoadARTSLibrary(); - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - stream = 0; - - /* Set the function pointers */ - this->OpenAudio = ARTS_OpenAudio; - this->WaitAudio = ARTS_WaitAudio; - this->PlayAudio = ARTS_PlayAudio; - this->GetAudioBuf = ARTS_GetAudioBuf; - this->CloseAudio = ARTS_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + LoadARTSLibrary (); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + stream = 0; + + /* Set the function pointers */ + this->OpenAudio = ARTS_OpenAudio; + this->WaitAudio = ARTS_WaitAudio; + this->PlayAudio = ARTS_PlayAudio; + this->GetAudioBuf = ARTS_GetAudioBuf; + this->CloseAudio = ARTS_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap ARTS_bootstrap = { - ARTS_DRIVER_NAME, "Analog Realtime Synthesizer", - Audio_Available, Audio_CreateDevice + ARTS_DRIVER_NAME, "Analog Realtime Synthesizer", + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void ARTS_WaitAudio(_THIS) +static void +ARTS_WaitAudio (_THIS) { - Sint32 ticks; - - /* Check to see if the thread-parent process is still alive */ - { static int cnt = 0; - /* Note that this only works with thread implementations - that use a different process id for each thread. - */ - if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ - if ( kill(parent, 0) < 0 ) { - this->enabled = 0; - } - } - } - - /* Use timer for general audio synchronization */ - ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; - if ( ticks > 0 ) { - SDL_Delay(ticks); - } + Sint32 ticks; + + /* Check to see if the thread-parent process is still alive */ + { + static int cnt = 0; + /* Note that this only works with thread implementations + that use a different process id for each thread. + */ + if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */ + if (kill (parent, 0) < 0) { + this->enabled = 0; + } + } + } + + /* Use timer for general audio synchronization */ + ticks = ((Sint32) (next_frame - SDL_GetTicks ())) - FUDGE_TICKS; + if (ticks > 0) { + SDL_Delay (ticks); + } } -static void ARTS_PlayAudio(_THIS) +static void +ARTS_PlayAudio (_THIS) { - int written; - - /* Write the audio data */ - written = SDL_NAME(arts_write)(stream, mixbuf, mixlen); - - /* If timer synchronization is enabled, set the next write frame */ - if ( frame_ticks ) { - next_frame += frame_ticks; - } - - /* If we couldn't write, assume fatal error for now */ - if ( written < 0 ) { - this->enabled = 0; - } + int written; + + /* Write the audio data */ + written = SDL_NAME (arts_write) (stream, mixbuf, mixlen); + + /* If timer synchronization is enabled, set the next write frame */ + if (frame_ticks) { + next_frame += frame_ticks; + } + + /* If we couldn't write, assume fatal error for now */ + if (written < 0) { + this->enabled = 0; + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Wrote %d bytes of audio data\n", written); + fprintf (stderr, "Wrote %d bytes of audio data\n", written); #endif } -static Uint8 *ARTS_GetAudioBuf(_THIS) +static Uint8 * +ARTS_GetAudioBuf (_THIS) { - return(mixbuf); + return (mixbuf); } -static void ARTS_CloseAudio(_THIS) +static void +ARTS_CloseAudio (_THIS) { - if ( mixbuf != NULL ) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if ( stream ) { - SDL_NAME(arts_close_stream)(stream); - stream = 0; - } - SDL_NAME(arts_free)(); + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; + } + if (stream) { + SDL_NAME (arts_close_stream) (stream); + stream = 0; + } + SDL_NAME (arts_free) (); } -static int ARTS_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +ARTS_OpenAudio (_THIS, SDL_AudioSpec * spec) { - int bits, frag_spec; - Uint16 test_format, format; + int bits, frag_spec; + Uint16 test_format, format; - /* Reset the timer synchronization flag */ - frame_ticks = 0.0; + /* Reset the timer synchronization flag */ + frame_ticks = 0.0; - mixbuf = NULL; + mixbuf = NULL; - /* Try for a closest match on audio format */ - format = 0; - bits = 0; - for ( test_format = SDL_FirstAudioFormat(spec->format); - ! format && test_format; ) { + /* Try for a closest match on audio format */ + format = 0; + bits = 0; + for (test_format = SDL_FirstAudioFormat (spec->format); + !format && test_format;) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Trying format 0x%4.4x\n", test_format); + fprintf (stderr, "Trying format 0x%4.4x\n", test_format); #endif - switch ( test_format ) { - case AUDIO_U8: - bits = 8; - format = 1; - break; - case AUDIO_S16LSB: - bits = 16; - format = 1; - break; - default: - format = 0; - break; - } - if ( ! format ) { - test_format = SDL_NextAudioFormat(); - } - } - if ( format == 0 ) { - SDL_SetError("Couldn't find any hardware audio formats"); - return(-1); - } - spec->format = test_format; - - if ( SDL_NAME(arts_init)() != 0 ) { - SDL_SetError("Unable to initialize ARTS"); - return(-1); - } - stream = SDL_NAME(arts_play_stream)(spec->freq, bits, spec->channels, "SDL"); - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - - /* Determine the power of two of the fragment size */ - for ( frag_spec = 0; (0x01<size; ++frag_spec ); - if ( (0x01<size ) { - SDL_SetError("Fragment size must be a power of two"); - return(-1); - } - frag_spec |= 0x00020000; /* two fragments, for low latency */ + switch (test_format) { + case AUDIO_U8: + bits = 8; + format = 1; + break; + case AUDIO_S16LSB: + bits = 16; + format = 1; + break; + default: + format = 0; + break; + } + if (!format) { + test_format = SDL_NextAudioFormat (); + } + } + if (format == 0) { + SDL_SetError ("Couldn't find any hardware audio formats"); + return (-1); + } + spec->format = test_format; + + if (SDL_NAME (arts_init) () != 0) { + SDL_SetError ("Unable to initialize ARTS"); + return (-1); + } + stream = + SDL_NAME (arts_play_stream) (spec->freq, bits, spec->channels, "SDL"); + + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + + /* Determine the power of two of the fragment size */ + for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec); + if ((0x01 << frag_spec) != spec->size) { + SDL_SetError ("Fragment size must be a power of two"); + return (-1); + } + frag_spec |= 0x00020000; /* two fragments, for low latency */ #ifdef ARTS_P_PACKET_SETTINGS - SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SETTINGS, frag_spec); + SDL_NAME (arts_stream_set) (stream, ARTS_P_PACKET_SETTINGS, frag_spec); #else - SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SIZE, frag_spec&0xffff); - SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_COUNT, frag_spec>>16); + SDL_NAME (arts_stream_set) (stream, ARTS_P_PACKET_SIZE, + frag_spec & 0xffff); + SDL_NAME (arts_stream_set) (stream, ARTS_P_PACKET_COUNT, frag_spec >> 16); #endif - spec->size = SDL_NAME(arts_stream_get)(stream, ARTS_P_PACKET_SIZE); + spec->size = SDL_NAME (arts_stream_get) (stream, ARTS_P_PACKET_SIZE); - /* Allocate mixing buffer */ - mixlen = spec->size; - mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); - if ( mixbuf == NULL ) { - return(-1); - } - SDL_memset(mixbuf, spec->silence, spec->size); + /* Allocate mixing buffer */ + mixlen = spec->size; + mixbuf = (Uint8 *) SDL_AllocAudioMem (mixlen); + if (mixbuf == NULL) { + return (-1); + } + SDL_memset (mixbuf, spec->silence, spec->size); - /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); + /* Get the parent process id (we're the parent of the audio thread) */ + parent = getpid (); - /* We're ready to rock and roll. :-) */ - return(0); + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/arts/SDL_artsaudio.h b/src/audio/arts/SDL_artsaudio.h index 5569a3d49..3f0c68c63 100644 --- a/src/audio/arts/SDL_artsaudio.h +++ b/src/audio/arts/SDL_artsaudio.h @@ -31,22 +31,23 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The stream descriptor for the audio device */ - arts_stream_t stream; +struct SDL_PrivateAudioData +{ + /* The stream descriptor for the audio device */ + arts_stream_t stream; - /* The parent process id, to detect when application quits */ - pid_t parent; + /* The parent process id, to detect when application quits */ + pid_t parent; - /* Raw mixing buffer */ - Uint8 *mixbuf; - int mixlen; + /* Raw mixing buffer */ + Uint8 *mixbuf; + int mixlen; - /* Support for audio timing using a timer, in addition to select() */ - float frame_ticks; - float next_frame; + /* Support for audio timing using a timer, in addition to select() */ + float frame_ticks; + float next_frame; }; -#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ +#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ /* Old variable names */ #define stream (this->hidden->stream) @@ -57,4 +58,4 @@ struct SDL_PrivateAudioData { #define next_frame (this->hidden->next_frame) #endif /* _SDL_artscaudio_h */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/baudio/SDL_beaudio.cc b/src/audio/baudio/SDL_beaudio.cc index b074f9c2b..a73cb2aba 100644 --- a/src/audio/baudio/SDL_beaudio.cc +++ b/src/audio/baudio/SDL_beaudio.cc @@ -27,7 +27,8 @@ #include "../../main/beos/SDL_BeApp.h" -extern "C" { +extern "C" +{ #include "SDL_audio.h" #include "../SDL_audio_c.h" @@ -37,172 +38,177 @@ extern "C" { /* Audio driver functions */ -static int BE_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void BE_WaitAudio(_THIS); -static void BE_PlayAudio(_THIS); -static Uint8 *BE_GetAudioBuf(_THIS); -static void BE_CloseAudio(_THIS); + static int BE_OpenAudio (_THIS, SDL_AudioSpec * spec); + static void BE_WaitAudio (_THIS); + static void BE_PlayAudio (_THIS); + static Uint8 *BE_GetAudioBuf (_THIS); + static void BE_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) -{ - return(1); -} - -static void Audio_DeleteDevice(SDL_AudioDevice *device) -{ - SDL_free(device->hidden); - SDL_free(device); -} - -static SDL_AudioDevice *Audio_CreateDevice(int devindex) -{ - SDL_AudioDevice *device; - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( device ) { - SDL_memset(device, 0, (sizeof *device)); - device->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *device->hidden)); - } - if ( (device == NULL) || (device->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( device ) { - SDL_free(device); - } - return(0); - } - SDL_memset(device->hidden, 0, (sizeof *device->hidden)); - - /* Set the function pointers */ - device->OpenAudio = BE_OpenAudio; - device->WaitAudio = BE_WaitAudio; - device->PlayAudio = BE_PlayAudio; - device->GetAudioBuf = BE_GetAudioBuf; - device->CloseAudio = BE_CloseAudio; - - device->free = Audio_DeleteDevice; - - return device; -} - -AudioBootStrap BAUDIO_bootstrap = { - "baudio", "BeOS BSoundPlayer", - Audio_Available, Audio_CreateDevice -}; + static int Audio_Available (void) + { + return (1); + } + + static void Audio_DeleteDevice (SDL_AudioDevice * device) + { + SDL_free (device->hidden); + SDL_free (device); + } + + static SDL_AudioDevice *Audio_CreateDevice (int devindex) + { + SDL_AudioDevice *device; + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (device) { + SDL_memset (device, 0, (sizeof *device)); + device->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *device->hidden)); + } + if ((device == NULL) || (device->hidden == NULL)) { + SDL_OutOfMemory (); + if (device) { + SDL_free (device); + } + return (0); + } + SDL_memset (device->hidden, 0, (sizeof *device->hidden)); + + /* Set the function pointers */ + device->OpenAudio = BE_OpenAudio; + device->WaitAudio = BE_WaitAudio; + device->PlayAudio = BE_PlayAudio; + device->GetAudioBuf = BE_GetAudioBuf; + device->CloseAudio = BE_CloseAudio; + + device->free = Audio_DeleteDevice; + + return device; + } + + AudioBootStrap BAUDIO_bootstrap = { + "baudio", "BeOS BSoundPlayer", + Audio_Available, Audio_CreateDevice + }; /* The BeOS callback for handling the audio buffer */ -static void FillSound(void *device, void *stream, size_t len, - const media_raw_audio_format &format) -{ - SDL_AudioDevice *audio = (SDL_AudioDevice *)device; - - /* Silence the buffer, since it's ours */ - SDL_memset(stream, audio->spec.silence, len); - - /* Only do soemthing if audio is enabled */ - if ( ! audio->enabled ) - return; - - if ( ! audio->paused ) { - if ( audio->convert.needed ) { - SDL_mutexP(audio->mixer_lock); - (*audio->spec.callback)(audio->spec.userdata, - (Uint8 *)audio->convert.buf,audio->convert.len); - SDL_mutexV(audio->mixer_lock); - SDL_ConvertAudio(&audio->convert); - SDL_memcpy(stream,audio->convert.buf,audio->convert.len_cvt); - } else { - SDL_mutexP(audio->mixer_lock); - (*audio->spec.callback)(audio->spec.userdata, - (Uint8 *)stream, len); - SDL_mutexV(audio->mixer_lock); - } - } - return; -} + static void FillSound (void *device, void *stream, size_t len, + const media_raw_audio_format & format) + { + SDL_AudioDevice *audio = (SDL_AudioDevice *) device; + + /* Silence the buffer, since it's ours */ + SDL_memset (stream, audio->spec.silence, len); + + /* Only do soemthing if audio is enabled */ + if (!audio->enabled) + return; + + if (!audio->paused) { + if (audio->convert.needed) { + SDL_mutexP (audio->mixer_lock); + (*audio->spec.callback) (audio->spec.userdata, + (Uint8 *) audio->convert.buf, + audio->convert.len); + SDL_mutexV (audio->mixer_lock); + SDL_ConvertAudio (&audio->convert); + SDL_memcpy (stream, audio->convert.buf, + audio->convert.len_cvt); + } else { + SDL_mutexP (audio->mixer_lock); + (*audio->spec.callback) (audio->spec.userdata, + (Uint8 *) stream, len); + SDL_mutexV (audio->mixer_lock); + } + } + return; + } /* Dummy functions -- we don't use thread-based audio */ -void BE_WaitAudio(_THIS) -{ - return; -} -void BE_PlayAudio(_THIS) -{ - return; -} -Uint8 *BE_GetAudioBuf(_THIS) -{ - return(NULL); -} - -void BE_CloseAudio(_THIS) -{ - if ( audio_obj ) { - audio_obj->Stop(); - delete audio_obj; - audio_obj = NULL; - } - - /* Quit the Be Application, if there's nothing left to do */ - SDL_QuitBeApp(); -} - -int BE_OpenAudio(_THIS, SDL_AudioSpec *spec) -{ - media_raw_audio_format format; - - /* Initialize the Be Application, if it's not already started */ - if ( SDL_InitBeApp() < 0 ) { - return(-1); - } - - /* Parse the audio format and fill the Be raw audio format */ - format.frame_rate = (float)spec->freq; - format.channel_count = spec->channels; - switch (spec->format&~0x1000) { - case AUDIO_S8: - /* Signed 8-bit audio unsupported, convert to U8 */ - spec->format = AUDIO_U8; - case AUDIO_U8: - format.format = media_raw_audio_format::B_AUDIO_UCHAR; - format.byte_order = 0; - break; - case AUDIO_U16: - /* Unsigned 16-bit audio unsupported, convert to S16 */ - spec->format ^= 0x8000; - case AUDIO_S16: - format.format = media_raw_audio_format::B_AUDIO_SHORT; - if ( spec->format & 0x1000 ) { - format.byte_order = 1; /* Big endian */ - } else { - format.byte_order = 2; /* Little endian */ - } - break; - } - format.buffer_size = spec->samples; - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - - /* Subscribe to the audio stream (creates a new thread) */ - { sigset_t omask; - SDL_MaskSignals(&omask); - audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound, - NULL, _this); - SDL_UnmaskSignals(&omask); - } - if ( audio_obj->Start() == B_NO_ERROR ) { - audio_obj->SetHasData(true); - } else { - SDL_SetError("Unable to start Be audio"); - return(-1); - } - - /* We're running! */ - return(1); -} - -}; /* Extern C */ + void BE_WaitAudio (_THIS) + { + return; + } + void BE_PlayAudio (_THIS) + { + return; + } + Uint8 *BE_GetAudioBuf (_THIS) + { + return (NULL); + } + + void BE_CloseAudio (_THIS) + { + if (audio_obj) { + audio_obj->Stop (); + delete audio_obj; + audio_obj = NULL; + } + + /* Quit the Be Application, if there's nothing left to do */ + SDL_QuitBeApp (); + } + + int BE_OpenAudio (_THIS, SDL_AudioSpec * spec) + { + media_raw_audio_format format; + + /* Initialize the Be Application, if it's not already started */ + if (SDL_InitBeApp () < 0) { + return (-1); + } + + /* Parse the audio format and fill the Be raw audio format */ + format.frame_rate = (float) spec->freq; + format.channel_count = spec->channels; + switch (spec->format & ~0x1000) { + case AUDIO_S8: + /* Signed 8-bit audio unsupported, convert to U8 */ + spec->format = AUDIO_U8; + case AUDIO_U8: + format.format = media_raw_audio_format::B_AUDIO_UCHAR; + format.byte_order = 0; + break; + case AUDIO_U16: + /* Unsigned 16-bit audio unsupported, convert to S16 */ + spec->format ^= 0x8000; + case AUDIO_S16: + format.format = media_raw_audio_format::B_AUDIO_SHORT; + if (spec->format & 0x1000) { + format.byte_order = 1; /* Big endian */ + } else { + format.byte_order = 2; /* Little endian */ + } + break; + } + format.buffer_size = spec->samples; + + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + + /* Subscribe to the audio stream (creates a new thread) */ + { + sigset_t omask; + SDL_MaskSignals (&omask); + audio_obj = new BSoundPlayer (&format, "SDL Audio", FillSound, + NULL, _this); + SDL_UnmaskSignals (&omask); + } + if (audio_obj->Start () == B_NO_ERROR) { + audio_obj->SetHasData (true); + } else { + SDL_SetError ("Unable to start Be audio"); + return (-1); + } + + /* We're running! */ + return (1); + } + +}; /* Extern C */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/baudio/SDL_beaudio.h b/src/audio/baudio/SDL_beaudio.h index 942c60ea3..fc8d52bb4 100644 --- a/src/audio/baudio/SDL_beaudio.h +++ b/src/audio/baudio/SDL_beaudio.h @@ -29,11 +29,13 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *_this -struct SDL_PrivateAudioData { - BSoundPlayer *audio_obj; +struct SDL_PrivateAudioData +{ + BSoundPlayer *audio_obj; }; /* Old variable names */ #define audio_obj (_this->hidden->audio_obj) #endif /* _SDL_lowaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/bsd/SDL_bsdaudio.c b/src/audio/bsd/SDL_bsdaudio.c index f1946c055..c6898f1e4 100644 --- a/src/audio/bsd/SDL_bsdaudio.c +++ b/src/audio/bsd/SDL_bsdaudio.c @@ -67,58 +67,59 @@ #endif /* Audio driver functions */ -static void OBSD_WaitAudio(_THIS); -static int OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void OBSD_PlayAudio(_THIS); -static Uint8 *OBSD_GetAudioBuf(_THIS); -static void OBSD_CloseAudio(_THIS); +static void OBSD_WaitAudio (_THIS); +static int OBSD_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void OBSD_PlayAudio (_THIS); +static Uint8 *OBSD_GetAudioBuf (_THIS); +static void OBSD_CloseAudio (_THIS); #ifdef DEBUG_AUDIO -static void OBSD_Status(_THIS); +static void OBSD_Status (_THIS); #endif /* Audio driver bootstrap functions */ static int -Audio_Available(void) +Audio_Available (void) { int fd; int available; available = 0; - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0); - if(fd >= 0) { - available = 1; - close(fd); + fd = SDL_OpenAudioPath (NULL, 0, OPEN_FLAGS, 0); + if (fd >= 0) { + available = 1; + close (fd); } - return(available); + return (available); } static void -Audio_DeleteDevice(SDL_AudioDevice *device) +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice -*Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { SDL_AudioDevice *this; /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice*)SDL_malloc(sizeof(SDL_AudioDevice)); - if(this) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = - (struct SDL_PrivateAudioData*)SDL_malloc((sizeof *this->hidden)); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); } - if((this == NULL) || (this->hidden == NULL)) { - SDL_OutOfMemory(); - if(this) SDL_free(this); - return(0); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) + SDL_free (this); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); audio_fd = -1; /* Set the function pointers */ @@ -129,276 +130,305 @@ static SDL_AudioDevice this->CloseAudio = OBSD_CloseAudio; this->free = Audio_DeleteDevice; - + return this; } AudioBootStrap BSD_AUDIO_bootstrap = { - BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC, - Audio_Available, Audio_CreateDevice + BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC, + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ static void -OBSD_WaitAudio(_THIS) +OBSD_WaitAudio (_THIS) { -#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */ - /* See if we need to use timed audio synchronization */ - if ( frame_ticks ) { - /* Use timer for general audio synchronization */ - Sint32 ticks; - - ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; - if ( ticks > 0 ) { - SDL_Delay(ticks); - } - } else { - /* Use select() for audio synchronization */ - fd_set fdset; - struct timeval timeout; - - FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); - timeout.tv_sec = 10; - timeout.tv_usec = 0; +#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */ + /* See if we need to use timed audio synchronization */ + if (frame_ticks) { + /* Use timer for general audio synchronization */ + Sint32 ticks; + + ticks = ((Sint32) (next_frame - SDL_GetTicks ())) - FUDGE_TICKS; + if (ticks > 0) { + SDL_Delay (ticks); + } + } else { + /* Use select() for audio synchronization */ + fd_set fdset; + struct timeval timeout; + + FD_ZERO (&fdset); + FD_SET (audio_fd, &fdset); + timeout.tv_sec = 10; + timeout.tv_usec = 0; #ifdef DEBUG_AUDIO - fprintf(stderr, "Waiting for audio to get ready\n"); + fprintf (stderr, "Waiting for audio to get ready\n"); #endif - if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) { - const char *message = - "Audio timeout - buggy audio driver? (disabled)"; - /* In general we should never print to the screen, - but in this case we have no other way of letting - the user know what happened. - */ - fprintf(stderr, "SDL: %s\n", message); - this->enabled = 0; - /* Don't try to close - may hang */ - audio_fd = -1; + if (select (audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) { + const char *message = + "Audio timeout - buggy audio driver? (disabled)"; + /* In general we should never print to the screen, + but in this case we have no other way of letting + the user know what happened. + */ + fprintf (stderr, "SDL: %s\n", message); + this->enabled = 0; + /* Don't try to close - may hang */ + audio_fd = -1; #ifdef DEBUG_AUDIO - fprintf(stderr, "Done disabling audio\n"); + fprintf (stderr, "Done disabling audio\n"); #endif - } + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Ready!\n"); + fprintf (stderr, "Ready!\n"); #endif - } + } #endif /* !USE_BLOCKING_WRITES */ } static void -OBSD_PlayAudio(_THIS) +OBSD_PlayAudio (_THIS) { - int written, p=0; - - /* Write the audio data, checking for EAGAIN on broken audio drivers */ - do { - written = write(audio_fd, &mixbuf[p], mixlen-p); - if (written>0) - p += written; - if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) - { - /* Non recoverable error has occurred. It should be reported!!! */ - perror("audio"); - break; - } - - if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) { - SDL_Delay(1); /* Let a little CPU time go by */ - } - } while ( p < written ); - - /* If timer synchronization is enabled, set the next write frame */ - if ( frame_ticks ) { - next_frame += frame_ticks; - } - - /* If we couldn't write, assume fatal error for now */ - if ( written < 0 ) { - this->enabled = 0; - } + int written, p = 0; + + /* Write the audio data, checking for EAGAIN on broken audio drivers */ + do { + written = write (audio_fd, &mixbuf[p], mixlen - p); + if (written > 0) + p += written; + if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) { + /* Non recoverable error has occurred. It should be reported!!! */ + perror ("audio"); + break; + } + + if (p < written + || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) { + SDL_Delay (1); /* Let a little CPU time go by */ + } + } + while (p < written); + + /* If timer synchronization is enabled, set the next write frame */ + if (frame_ticks) { + next_frame += frame_ticks; + } + + /* If we couldn't write, assume fatal error for now */ + if (written < 0) { + this->enabled = 0; + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Wrote %d bytes of audio data\n", written); + fprintf (stderr, "Wrote %d bytes of audio data\n", written); #endif } -static Uint8 -*OBSD_GetAudioBuf(_THIS) +static Uint8 * +OBSD_GetAudioBuf (_THIS) { - return(mixbuf); + return (mixbuf); } static void -OBSD_CloseAudio(_THIS) +OBSD_CloseAudio (_THIS) { - if(mixbuf != NULL) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; } - if(audio_fd >= 0) { - close(audio_fd); - audio_fd = -1; + if (audio_fd >= 0) { + close (audio_fd); + audio_fd = -1; } } #ifdef DEBUG_AUDIO void -OBSD_Status(_THIS) +OBSD_Status (_THIS) { audio_info_t info; - if(ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { - fprintf(stderr,"AUDIO_GETINFO failed.\n"); - return; + if (ioctl (audio_fd, AUDIO_GETINFO, &info) < 0) { + fprintf (stderr, "AUDIO_GETINFO failed.\n"); + return; } - fprintf(stderr,"\n" -"[play/record info]\n" -"buffer size : %d bytes\n" -"sample rate : %i Hz\n" -"channels : %i\n" -"precision : %i-bit\n" -"encoding : 0x%x\n" -"seek : %i\n" -"sample count : %i\n" -"EOF count : %i\n" -"paused : %s\n" -"error occured : %s\n" -"waiting : %s\n" -"active : %s\n" -"", - info.play.buffer_size, - info.play.sample_rate, - info.play.channels, - info.play.precision, - info.play.encoding, - info.play.seek, - info.play.samples, - info.play.eof, - info.play.pause ? "yes" : "no", - info.play.error ? "yes" : "no", - info.play.waiting ? "yes" : "no", - info.play.active ? "yes": "no"); - - fprintf(stderr,"\n" -"[audio info]\n" -"monitor_gain : %i\n" -"hw block size : %d bytes\n" -"hi watermark : %i\n" -"lo watermark : %i\n" -"audio mode : %s\n" -"", - info.monitor_gain, - info.blocksize, - info.hiwat, info.lowat, - (info.mode == AUMODE_PLAY) ? "PLAY" - : (info.mode = AUMODE_RECORD) ? "RECORD" - : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" - : "?")); + fprintf (stderr, "\n" + "[play/record info]\n" + "buffer size : %d bytes\n" + "sample rate : %i Hz\n" + "channels : %i\n" + "precision : %i-bit\n" + "encoding : 0x%x\n" + "seek : %i\n" + "sample count : %i\n" + "EOF count : %i\n" + "paused : %s\n" + "error occured : %s\n" + "waiting : %s\n" + "active : %s\n" + "", + info. + play. + buffer_size, + info. + play. + sample_rate, + info. + play. + channels, + info. + play. + precision, + info. + play. + encoding, + info. + play. + seek, + info. + play. + samples, + info. + play. + eof, + info. + play. + pause + ? + "yes" + : + "no", + info. + play. + error + ? + "yes" + : + "no", + info. + play.waiting ? "yes" : "no", info.play.active ? "yes" : "no"); + + fprintf (stderr, "\n" + "[audio info]\n" + "monitor_gain : %i\n" + "hw block size : %d bytes\n" + "hi watermark : %i\n" + "lo watermark : %i\n" + "audio mode : %s\n" + "", + info.monitor_gain, + info.blocksize, + info.hiwat, info.lowat, + (info.mode == AUMODE_PLAY) ? "PLAY" + : (info.mode = AUMODE_RECORD) ? "RECORD" + : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?")); } #endif /* DEBUG_AUDIO */ static int -OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec) +OBSD_OpenAudio (_THIS, SDL_AudioSpec * spec) { char audiodev[64]; Uint16 format; audio_info_t info; - AUDIO_INITINFO(&info); - + AUDIO_INITINFO (&info); + /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); #ifdef USE_TIMER_SYNC frame_ticks = 0.0; #endif /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0); - if(audio_fd < 0) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return(-1); + audio_fd = SDL_OpenAudioPath (audiodev, sizeof (audiodev), OPEN_FLAGS, 0); + if (audio_fd < 0) { + SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); + return (-1); } - + /* Set to play mode */ info.mode = AUMODE_PLAY; - if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) { - SDL_SetError("Couldn't put device into play mode"); - return(-1); + if (ioctl (audio_fd, AUDIO_SETINFO, &info) < 0) { + SDL_SetError ("Couldn't put device into play mode"); + return (-1); } - + mixbuf = NULL; - AUDIO_INITINFO(&info); - for (format = SDL_FirstAudioFormat(spec->format); - format; format = SDL_NextAudioFormat()) - { - switch(format) { - case AUDIO_U8: - info.play.encoding = AUDIO_ENCODING_ULINEAR; - info.play.precision = 8; - break; - case AUDIO_S8: - info.play.encoding = AUDIO_ENCODING_SLINEAR; - info.play.precision = 8; - break; - case AUDIO_S16LSB: - info.play.encoding = AUDIO_ENCODING_SLINEAR_LE; - info.play.precision = 16; - break; - case AUDIO_S16MSB: - info.play.encoding = AUDIO_ENCODING_SLINEAR_BE; - info.play.precision = 16; - break; - case AUDIO_U16LSB: - info.play.encoding = AUDIO_ENCODING_ULINEAR_LE; - info.play.precision = 16; - break; - case AUDIO_U16MSB: - info.play.encoding = AUDIO_ENCODING_ULINEAR_BE; - info.play.precision = 16; - break; - default: - continue; - } - if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0) - break; + AUDIO_INITINFO (&info); + for (format = SDL_FirstAudioFormat (spec->format); + format; format = SDL_NextAudioFormat ()) { + switch (format) { + case AUDIO_U8: + info.play.encoding = AUDIO_ENCODING_ULINEAR; + info.play.precision = 8; + break; + case AUDIO_S8: + info.play.encoding = AUDIO_ENCODING_SLINEAR; + info.play.precision = 8; + break; + case AUDIO_S16LSB: + info.play.encoding = AUDIO_ENCODING_SLINEAR_LE; + info.play.precision = 16; + break; + case AUDIO_S16MSB: + info.play.encoding = AUDIO_ENCODING_SLINEAR_BE; + info.play.precision = 16; + break; + case AUDIO_U16LSB: + info.play.encoding = AUDIO_ENCODING_ULINEAR_LE; + info.play.precision = 16; + break; + case AUDIO_U16MSB: + info.play.encoding = AUDIO_ENCODING_ULINEAR_BE; + info.play.precision = 16; + break; + default: + continue; + } + if (ioctl (audio_fd, AUDIO_SETINFO, &info) == 0) + break; } - if(!format) { - SDL_SetError("No supported encoding for 0x%x", spec->format); - return(-1); + if (!format) { + SDL_SetError ("No supported encoding for 0x%x", spec->format); + return (-1); } spec->format = format; - AUDIO_INITINFO(&info); + AUDIO_INITINFO (&info); info.play.channels = spec->channels; - if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1) - spec->channels = 1; - AUDIO_INITINFO(&info); + if (ioctl (audio_fd, AUDIO_SETINFO, &info) == -1) + spec->channels = 1; + AUDIO_INITINFO (&info); info.play.sample_rate = spec->freq; info.blocksize = spec->size; info.hiwat = 5; info.lowat = 3; - (void)ioctl(audio_fd, AUDIO_SETINFO, &info); - (void)ioctl(audio_fd, AUDIO_GETINFO, &info); - spec->freq = info.play.sample_rate; + (void) ioctl (audio_fd, AUDIO_SETINFO, &info); + (void) ioctl (audio_fd, AUDIO_GETINFO, &info); + spec->freq = info.play.sample_rate; /* Allocate mixing buffer */ mixlen = spec->size; - mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen); - if(mixbuf == NULL) { - return(-1); + mixbuf = (Uint8 *) SDL_AllocAudioMem (mixlen); + if (mixbuf == NULL) { + return (-1); } - SDL_memset(mixbuf, spec->silence, spec->size); - + SDL_memset (mixbuf, spec->silence, spec->size); + /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); + parent = getpid (); #ifdef DEBUG_AUDIO - OBSD_Status(this); + OBSD_Status (this); #endif /* We're ready to rock and roll. :-) */ - return(0); + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/bsd/SDL_bsdaudio.h b/src/audio/bsd/SDL_bsdaudio.h index 8e8db89e9..618401d90 100644 --- a/src/audio/bsd/SDL_bsdaudio.h +++ b/src/audio/bsd/SDL_bsdaudio.h @@ -38,14 +38,14 @@ struct SDL_PrivateAudioData /* Raw mixing buffer */ Uint8 *mixbuf; - int mixlen; + int mixlen; /* Support for audio timing using a timer, in addition to select() */ float frame_ticks; float next_frame; }; -#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ +#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ /* Old variable names */ #define audio_fd (this->hidden->audio_fd) @@ -56,3 +56,4 @@ struct SDL_PrivateAudioData #define next_frame (this->hidden->next_frame) #endif /* _SDL_openbsdaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dart/SDL_dart.c b/src/audio/dart/SDL_dart.c index 6381de161..b7ce2092b 100644 --- a/src/audio/dart/SDL_dart.c +++ b/src/audio/dart/SDL_dart.c @@ -32,9 +32,10 @@ #define BUFFER_EMPTY 0 #define BUFFER_USED 1 -typedef struct _tMixBufferDesc { - int iBufferUsage; // BUFFER_EMPTY or BUFFER_USED - SDL_AudioDevice *pSDLAudioDevice; +typedef struct _tMixBufferDesc +{ + int iBufferUsage; // BUFFER_EMPTY or BUFFER_USED + SDL_AudioDevice *pSDLAudioDevice; } tMixBufferDesc, *pMixBufferDesc; @@ -44,70 +45,67 @@ typedef struct _tMixBufferDesc { // This function is called by DART, when an event occures, like end of // playback of a buffer, etc... //--------------------------------------------------------------------- -LONG APIENTRY DARTEventFunc(ULONG ulStatus, - PMCI_MIX_BUFFER pBuffer, - ULONG ulFlags) +LONG APIENTRY +DARTEventFunc (ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags) { - if (ulFlags && MIX_WRITE_COMPLETE) - { // Playback of buffer completed! - - // Get pointer to buffer description - pMixBufferDesc pBufDesc; - - if (pBuffer) - { - pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm; - - if (pBufDesc) - { - SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice; - // Set the buffer to be empty - pBufDesc->iBufferUsage = BUFFER_EMPTY; - // And notify DART feeder thread that it will have to work a bit. - if (pSDLAudioDevice) - DosPostEventSem(pSDLAudioDevice->hidden->hevAudioBufferPlayed); - } + if (ulFlags && MIX_WRITE_COMPLETE) { // Playback of buffer completed! + + // Get pointer to buffer description + pMixBufferDesc pBufDesc; + + if (pBuffer) { + pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm; + + if (pBufDesc) { + SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice; + // Set the buffer to be empty + pBufDesc->iBufferUsage = BUFFER_EMPTY; + // And notify DART feeder thread that it will have to work a bit. + if (pSDLAudioDevice) + DosPostEventSem (pSDLAudioDevice->hidden-> + hevAudioBufferPlayed); + } + } } - } - return TRUE; + return TRUE; } -int DART_OpenAudio(_THIS, SDL_AudioSpec *spec) +int +DART_OpenAudio (_THIS, SDL_AudioSpec * spec) { - MCI_AMP_OPEN_PARMS AmpOpenParms; - MCI_GENERIC_PARMS GenericParms; - int iDeviceOrd = 0; // Default device to be used - int bOpenShared = 1; // Try opening it shared - int iBits = 16; // Default is 16 bits signed - int iFreq = 44100; // Default is 44KHz - int iChannels = 2; // Default is 2 channels (Stereo) - int iNumBufs = 2; // Number of audio buffers: 2 - int iBufSize; - int iOpenMode; - int iSilence; - int rc; - - // First thing is to try to open a given DART device! - SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS)); - // pszDeviceType should contain the device type in low word, and device ordinal in high word! - AmpOpenParms.pszDeviceType = (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16)); - - iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID; - if (bOpenShared) iOpenMode |= MCI_OPEN_SHAREABLE; - - rc = mciSendCommand( 0, MCI_OPEN, - iOpenMode, - (PVOID) &AmpOpenParms, 0); - if (rc!=MCIERR_SUCCESS) // No audio available?? - return (-1); - // Save the device ID we got from DART! - // We will use this in the next calls! - iDeviceOrd = AmpOpenParms.usDeviceID; - - // Determine the audio parameters from the AudioSpec - switch ( spec->format & 0xFF ) - { + MCI_AMP_OPEN_PARMS AmpOpenParms; + MCI_GENERIC_PARMS GenericParms; + int iDeviceOrd = 0; // Default device to be used + int bOpenShared = 1; // Try opening it shared + int iBits = 16; // Default is 16 bits signed + int iFreq = 44100; // Default is 44KHz + int iChannels = 2; // Default is 2 channels (Stereo) + int iNumBufs = 2; // Number of audio buffers: 2 + int iBufSize; + int iOpenMode; + int iSilence; + int rc; + + // First thing is to try to open a given DART device! + SDL_memset (&AmpOpenParms, 0, sizeof (MCI_AMP_OPEN_PARMS)); + // pszDeviceType should contain the device type in low word, and device ordinal in high word! + AmpOpenParms.pszDeviceType = + (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16)); + + iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID; + if (bOpenShared) + iOpenMode |= MCI_OPEN_SHAREABLE; + + rc = mciSendCommand (0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0); + if (rc != MCIERR_SUCCESS) // No audio available?? + return (-1); + // Save the device ID we got from DART! + // We will use this in the next calls! + iDeviceOrd = AmpOpenParms.usDeviceID; + + // Determine the audio parameters from the AudioSpec + switch (spec->format & 0xFF) { case 8: /* Unsigned 8 bit audio data */ spec->format = AUDIO_U8; @@ -122,305 +120,336 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec) break; default: // Close DART, and exit with error code! - mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); - SDL_SetError("Unsupported audio format"); - return(-1); - } - iFreq = spec->freq; - iChannels = spec->channels; - /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); - iBufSize = spec->size; - - // Now query this device if it supports the given freq/bits/channels! - SDL_memset(&(_this->hidden->MixSetupParms), 0, sizeof(MCI_MIXSETUP_PARMS)); - _this->hidden->MixSetupParms.ulBitsPerSample = iBits; - _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM; - _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq; - _this->hidden->MixSetupParms.ulChannels = iChannels; - _this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY; - _this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; - _this->hidden->MixSetupParms.pmixEvent = DARTEventFunc; - rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP, - MCI_WAIT | MCI_MIXSETUP_QUERYMODE, - &(_this->hidden->MixSetupParms), 0); - if (rc!=MCIERR_SUCCESS) - { // The device cannot handle this format! - // Close DART, and exit with error code! - mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); - SDL_SetError("Audio device doesn't support requested audio format"); - return(-1); - } - // The device can handle this format, so initialize! - rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP, - MCI_WAIT | MCI_MIXSETUP_INIT, - &(_this->hidden->MixSetupParms), 0); - if (rc!=MCIERR_SUCCESS) - { // The device could not be opened! - // Close DART, and exit with error code! - mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); - SDL_SetError("Audio device could not be set up"); - return(-1); - } - // Ok, the device is initialized. - // Now we should allocate buffers. For this, we need a place where - // the buffer descriptors will be: - _this->hidden->pMixBuffers = (MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER)*iNumBufs); - if (!(_this->hidden->pMixBuffers)) - { // Not enough memory! - // Close DART, and exit with error code! - mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); - SDL_SetError("Not enough memory for audio buffer descriptors"); - return(-1); - } - // Now that we have the place for buffer list, we can ask DART for the - // buffers! - _this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers - _this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size - _this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list - // Allocate buffers! - rc = mciSendCommand(iDeviceOrd, MCI_BUFFER, - MCI_WAIT | MCI_ALLOCATE_MEMORY, - &(_this->hidden->BufferParms), 0); - if ((rc!=MCIERR_SUCCESS) || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) || (_this->hidden->BufferParms.ulBufferSize==0)) - { // Could not allocate memory! - // Close DART, and exit with error code! - SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; - mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); - SDL_SetError("DART could not allocate buffers"); - return(-1); - } - // Ok, we have all the buffers allocated, let's mark them! - { - int i; - for (i=0; ihidden->pMixBuffers[i].pBuffer)) || (!pBufferDesc)) - { // Wrong buffer! + mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); + SDL_SetError ("Unsupported audio format"); + return (-1); + } + iFreq = spec->freq; + iChannels = spec->channels; + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec (spec); + iBufSize = spec->size; + + // Now query this device if it supports the given freq/bits/channels! + SDL_memset (&(_this->hidden->MixSetupParms), 0, + sizeof (MCI_MIXSETUP_PARMS)); + _this->hidden->MixSetupParms.ulBitsPerSample = iBits; + _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM; + _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq; + _this->hidden->MixSetupParms.ulChannels = iChannels; + _this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY; + _this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; + _this->hidden->MixSetupParms.pmixEvent = DARTEventFunc; + rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP, + MCI_WAIT | MCI_MIXSETUP_QUERYMODE, + &(_this->hidden->MixSetupParms), 0); + if (rc != MCIERR_SUCCESS) { // The device cannot handle this format! + // Close DART, and exit with error code! + mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); + SDL_SetError ("Audio device doesn't support requested audio format"); + return (-1); + } + // The device can handle this format, so initialize! + rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP, + MCI_WAIT | MCI_MIXSETUP_INIT, + &(_this->hidden->MixSetupParms), 0); + if (rc != MCIERR_SUCCESS) { // The device could not be opened! // Close DART, and exit with error code! - // Free buffer descriptions - { int j; - for (j=0; jhidden->pMixBuffers[j].ulUserParm)); + mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); + SDL_SetError ("Audio device could not be set up"); + return (-1); + } + // Ok, the device is initialized. + // Now we should allocate buffers. For this, we need a place where + // the buffer descriptors will be: + _this->hidden->pMixBuffers = + (MCI_MIX_BUFFER *) SDL_malloc (sizeof (MCI_MIX_BUFFER) * iNumBufs); + if (!(_this->hidden->pMixBuffers)) { // Not enough memory! + // Close DART, and exit with error code! + mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); + SDL_SetError ("Not enough memory for audio buffer descriptors"); + return (-1); + } + // Now that we have the place for buffer list, we can ask DART for the + // buffers! + _this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers + _this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size + _this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list + // Allocate buffers! + rc = mciSendCommand (iDeviceOrd, MCI_BUFFER, + MCI_WAIT | MCI_ALLOCATE_MEMORY, + &(_this->hidden->BufferParms), 0); + if ((rc != MCIERR_SUCCESS) + || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) + || (_this->hidden->BufferParms.ulBufferSize == 0)) { // Could not allocate memory! + // Close DART, and exit with error code! + SDL_free (_this->hidden->pMixBuffers); + _this->hidden->pMixBuffers = NULL; + mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); + SDL_SetError ("DART could not allocate buffers"); + return (-1); + } + // Ok, we have all the buffers allocated, let's mark them! + { + int i; + for (i = 0; i < iNumBufs; i++) { + pMixBufferDesc pBufferDesc = + (pMixBufferDesc) SDL_malloc (sizeof (tMixBufferDesc));; + // Check if this buffer was really allocated by DART + if ((!(_this->hidden->pMixBuffers[i].pBuffer)) + || (!pBufferDesc)) { // Wrong buffer! + // Close DART, and exit with error code! + // Free buffer descriptions + { + int j; + for (j = 0; j < i; j++) + SDL_free ((void *) (_this->hidden->pMixBuffers[j]. + ulUserParm)); + } + // and cleanup + mciSendCommand (iDeviceOrd, MCI_BUFFER, + MCI_WAIT | MCI_DEALLOCATE_MEMORY, + &(_this->hidden->BufferParms), 0); + SDL_free (_this->hidden->pMixBuffers); + _this->hidden->pMixBuffers = NULL; + mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, + &GenericParms, 0); + SDL_SetError ("Error at internal buffer check"); + return (-1); + } + pBufferDesc->iBufferUsage = BUFFER_EMPTY; + pBufferDesc->pSDLAudioDevice = _this; + + _this->hidden->pMixBuffers[i].ulBufferLength = + _this->hidden->BufferParms.ulBufferSize; + _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer + _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of + // audio data, but as we will continously send + // audio data, there will be no end.:) + SDL_memset (_this->hidden->pMixBuffers[i].pBuffer, iSilence, + iBufSize); } - // and cleanup - mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0); - SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; - mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); - SDL_SetError("Error at internal buffer check"); - return(-1); - } - pBufferDesc->iBufferUsage = BUFFER_EMPTY; - pBufferDesc->pSDLAudioDevice = _this; - - _this->hidden->pMixBuffers[i].ulBufferLength = _this->hidden->BufferParms.ulBufferSize; - _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer - _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of - // audio data, but as we will continously send - // audio data, there will be no end.:) - SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize); } - } - _this->hidden->iNextFreeBuffer = 0; - _this->hidden->iLastPlayedBuf = -1; - // Create event semaphore - if (DosCreateEventSem(NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE)!=NO_ERROR) - { - // Could not create event semaphore! + _this->hidden->iNextFreeBuffer = 0; + _this->hidden->iLastPlayedBuf = -1; + // Create event semaphore + if (DosCreateEventSem + (NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE) != NO_ERROR) { - int i; - for (i=0; ihidden->pMixBuffers[i].ulUserParm)); + // Could not create event semaphore! + { + int i; + for (i = 0; i < iNumBufs; i++) + SDL_free ((void *) (_this->hidden->pMixBuffers[i]. + ulUserParm)); + } + mciSendCommand (iDeviceOrd, MCI_BUFFER, + MCI_WAIT | MCI_DEALLOCATE_MEMORY, + &(_this->hidden->BufferParms), 0); + SDL_free (_this->hidden->pMixBuffers); + _this->hidden->pMixBuffers = NULL; + mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); + SDL_SetError ("Could not create event semaphore"); + return (-1); } - mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0); - SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; - mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); - SDL_SetError("Could not create event semaphore"); - return(-1); - } - - // Store the new settings in global variables - _this->hidden->iCurrDeviceOrd = iDeviceOrd; - _this->hidden->iCurrFreq = iFreq; - _this->hidden->iCurrBits = iBits; - _this->hidden->iCurrChannels = iChannels; - _this->hidden->iCurrNumBufs = iNumBufs; - _this->hidden->iCurrBufSize = iBufSize; - - return (0); + // Store the new settings in global variables + _this->hidden->iCurrDeviceOrd = iDeviceOrd; + _this->hidden->iCurrFreq = iFreq; + _this->hidden->iCurrBits = iBits; + _this->hidden->iCurrChannels = iChannels; + _this->hidden->iCurrNumBufs = iNumBufs; + _this->hidden->iCurrBufSize = iBufSize; + + return (0); } -void DART_ThreadInit(_THIS) +void +DART_ThreadInit (_THIS) { - return; + return; } /* This function waits until it is possible to write a full sound buffer */ -void DART_WaitAudio(_THIS) +void +DART_WaitAudio (_THIS) { - int i; - pMixBufferDesc pBufDesc; - ULONG ulPostCount; - - DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount); - // If there is already an empty buffer, then return now! - for (i=0; i<_this->hidden->iCurrNumBufs; i++) - { - pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm; - if (pBufDesc->iBufferUsage == BUFFER_EMPTY) - return; - } - // If there is no empty buffer, wait for one to be empty! - DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important! - return; + int i; + pMixBufferDesc pBufDesc; + ULONG ulPostCount; + + DosResetEventSem (_this->hidden->hevAudioBufferPlayed, &ulPostCount); + // If there is already an empty buffer, then return now! + for (i = 0; i < _this->hidden->iCurrNumBufs; i++) { + pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm; + if (pBufDesc->iBufferUsage == BUFFER_EMPTY) + return; + } + // If there is no empty buffer, wait for one to be empty! + DosWaitEventSem (_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important! + return; } -void DART_PlayAudio(_THIS) +void +DART_PlayAudio (_THIS) { - int iFreeBuf = _this->hidden->iNextFreeBuffer; - pMixBufferDesc pBufDesc; - - pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm; - pBufDesc->iBufferUsage = BUFFER_USED; - // Send it to DART to be queued - _this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.ulMixHandle, - &(_this->hidden->pMixBuffers[iFreeBuf]), 1); - - _this->hidden->iLastPlayedBuf = iFreeBuf; - iFreeBuf = (iFreeBuf+1) % _this->hidden->iCurrNumBufs; - _this->hidden->iNextFreeBuffer = iFreeBuf; + int iFreeBuf = _this->hidden->iNextFreeBuffer; + pMixBufferDesc pBufDesc; + + pBufDesc = + (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm; + pBufDesc->iBufferUsage = BUFFER_USED; + // Send it to DART to be queued + _this->hidden->MixSetupParms.pmixWrite (_this->hidden->MixSetupParms. + ulMixHandle, + &(_this->hidden-> + pMixBuffers[iFreeBuf]), 1); + + _this->hidden->iLastPlayedBuf = iFreeBuf; + iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs; + _this->hidden->iNextFreeBuffer = iFreeBuf; } -Uint8 *DART_GetAudioBuf(_THIS) +Uint8 * +DART_GetAudioBuf (_THIS) { - int iFreeBuf; - Uint8 *pResult; - pMixBufferDesc pBufDesc; + int iFreeBuf; + Uint8 *pResult; + pMixBufferDesc pBufDesc; - if (_this) - { - if (_this->hidden) - { - iFreeBuf = _this->hidden->iNextFreeBuffer; - pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm; - - if (pBufDesc) - { - if (pBufDesc->iBufferUsage == BUFFER_EMPTY) - { - pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer; - return pResult; - } - } else - printf("[DART_GetAudioBuf] : ERROR! pBufDesc = %p\n", pBufDesc); + if (_this) { + if (_this->hidden) { + iFreeBuf = _this->hidden->iNextFreeBuffer; + pBufDesc = + (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf]. + ulUserParm; + + if (pBufDesc) { + if (pBufDesc->iBufferUsage == BUFFER_EMPTY) { + pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer; + return pResult; + } + } else + printf ("[DART_GetAudioBuf] : ERROR! pBufDesc = %p\n", + pBufDesc); + } else + printf ("[DART_GetAudioBuf] : ERROR! _this->hidden = %p\n", + _this->hidden); } else - printf("[DART_GetAudioBuf] : ERROR! _this->hidden = %p\n", _this->hidden); - } else - printf("[DART_GetAudioBuf] : ERROR! _this = %p\n", _this); - return NULL; + printf ("[DART_GetAudioBuf] : ERROR! _this = %p\n", _this); + return NULL; } -void DART_WaitDone(_THIS) +void +DART_WaitDone (_THIS) { - pMixBufferDesc pBufDesc; - ULONG ulPostCount; - APIRET rc; - - pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[_this->hidden->iLastPlayedBuf].ulUserParm; - rc = NO_ERROR; - while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc==NO_ERROR)) - { - DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount); - rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important! - } + pMixBufferDesc pBufDesc; + ULONG ulPostCount; + APIRET rc; + + pBufDesc = + (pMixBufferDesc) _this->hidden->pMixBuffers[_this->hidden-> + iLastPlayedBuf]. + ulUserParm; + rc = NO_ERROR; + while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) { + DosResetEventSem (_this->hidden->hevAudioBufferPlayed, &ulPostCount); + rc = DosWaitEventSem (_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important! + } } -void DART_CloseAudio(_THIS) +void +DART_CloseAudio (_THIS) { - MCI_GENERIC_PARMS GenericParms; - int rc; + MCI_GENERIC_PARMS GenericParms; + int rc; - // Stop DART playback - rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_STOP, MCI_WAIT, &GenericParms, 0); - if (rc!=MCIERR_SUCCESS) - { + // Stop DART playback + rc = mciSendCommand (_this->hidden->iCurrDeviceOrd, MCI_STOP, MCI_WAIT, + &GenericParms, 0); + if (rc != MCIERR_SUCCESS) { #ifdef SFX_DEBUG_BUILD - printf("Could not stop DART playback!\n"); - fflush(stdout); + printf ("Could not stop DART playback!\n"); + fflush (stdout); #endif - } - - // Close event semaphore - DosCloseEventSem(_this->hidden->hevAudioBufferPlayed); + } + // Close event semaphore + DosCloseEventSem (_this->hidden->hevAudioBufferPlayed); - // Free memory of buffer descriptions - { - int i; - for (i=0; i<_this->hidden->iCurrNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm)); - } + // Free memory of buffer descriptions + { + int i; + for (i = 0; i < _this->hidden->iCurrNumBufs; i++) + SDL_free ((void *) (_this->hidden->pMixBuffers[i].ulUserParm)); + } - // Deallocate buffers - rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0); + // Deallocate buffers + rc = mciSendCommand (_this->hidden->iCurrDeviceOrd, MCI_BUFFER, + MCI_WAIT | MCI_DEALLOCATE_MEMORY, + &(_this->hidden->BufferParms), 0); - // Free bufferlist - SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; + // Free bufferlist + SDL_free (_this->hidden->pMixBuffers); + _this->hidden->pMixBuffers = NULL; - // Close dart - rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT, &(GenericParms), 0); + // Close dart + rc = mciSendCommand (_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT, + &(GenericParms), 0); } /* Audio driver bootstrap functions */ -int Audio_Available(void) +int +Audio_Available (void) { - return(1); + return (1); } -void Audio_DeleteDevice(SDL_AudioDevice *device) +void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -SDL_AudioDevice *Audio_CreateDevice(int devindex) +SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) - { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) - { - SDL_OutOfMemory(); - if ( this ) - SDL_free(this); - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = DART_OpenAudio; - this->ThreadInit = DART_ThreadInit; - this->WaitAudio = DART_WaitAudio; - this->PlayAudio = DART_PlayAudio; - this->GetAudioBuf = DART_GetAudioBuf; - this->WaitDone = DART_WaitDone; - this->CloseAudio = DART_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) + SDL_free (this); + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = DART_OpenAudio; + this->ThreadInit = DART_ThreadInit; + this->WaitAudio = DART_WaitAudio; + this->PlayAudio = DART_PlayAudio; + this->GetAudioBuf = DART_GetAudioBuf; + this->WaitDone = DART_WaitDone; + this->CloseAudio = DART_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap DART_bootstrap = { - "dart", "OS/2 Direct Audio RouTines (DART)", - Audio_Available, Audio_CreateDevice + "dart", "OS/2 Direct Audio RouTines (DART)", + Audio_Available, Audio_CreateDevice }; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dart/SDL_dart.h b/src/audio/dart/SDL_dart.h index 895da0040..a58eda3f0 100644 --- a/src/audio/dart/SDL_dart.h +++ b/src/audio/dart/SDL_dart.h @@ -34,7 +34,7 @@ #define INCL_MMIOOS2 #define INCL_MCIOS2 #include -#include // DART stuff and MMIO stuff +#include // DART stuff and MMIO stuff #include "../SDL_sysaudio.h" @@ -44,20 +44,21 @@ /* The DirectSound objects */ struct SDL_PrivateAudioData { - int iCurrDeviceOrd; - int iCurrFreq; - int iCurrBits; - int iCurrChannels; - int iCurrNumBufs; - int iCurrBufSize; - - int iLastPlayedBuf; - int iNextFreeBuffer; - - MCI_BUFFER_PARMS BufferParms; // Sound buffer parameters - MCI_MIX_BUFFER *pMixBuffers; // Sound buffers - MCI_MIXSETUP_PARMS MixSetupParms; // Mixer setup parameters - HEV hevAudioBufferPlayed; // Event semaphore to indicate that an audio buffer has been played by DART + int iCurrDeviceOrd; + int iCurrFreq; + int iCurrBits; + int iCurrChannels; + int iCurrNumBufs; + int iCurrBufSize; + + int iLastPlayedBuf; + int iNextFreeBuffer; + + MCI_BUFFER_PARMS BufferParms; // Sound buffer parameters + MCI_MIX_BUFFER *pMixBuffers; // Sound buffers + MCI_MIXSETUP_PARMS MixSetupParms; // Mixer setup parameters + HEV hevAudioBufferPlayed; // Event semaphore to indicate that an audio buffer has been played by DART }; #endif /* _SDL_lowaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dc/SDL_dcaudio.c b/src/audio/dc/SDL_dcaudio.c index 8715376fa..77f62d50e 100644 --- a/src/audio/dc/SDL_dcaudio.c +++ b/src/audio/dc/SDL_dcaudio.c @@ -35,195 +35,220 @@ #include /* Audio driver functions */ -static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DCAUD_WaitAudio(_THIS); -static void DCAUD_PlayAudio(_THIS); -static Uint8 *DCAUD_GetAudioBuf(_THIS); -static void DCAUD_CloseAudio(_THIS); +static int DCAUD_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DCAUD_WaitAudio (_THIS); +static void DCAUD_PlayAudio (_THIS); +static Uint8 *DCAUD_GetAudioBuf (_THIS); +static void DCAUD_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int DCAUD_Available(void) +static int +DCAUD_Available (void) { - return 1; + return 1; } -static void DCAUD_DeleteDevice(SDL_AudioDevice *device) +static void +DCAUD_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *DCAUD_CreateDevice(int devindex) +static SDL_AudioDevice * +DCAUD_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = DCAUD_OpenAudio; - this->WaitAudio = DCAUD_WaitAudio; - this->PlayAudio = DCAUD_PlayAudio; - this->GetAudioBuf = DCAUD_GetAudioBuf; - this->CloseAudio = DCAUD_CloseAudio; - - this->free = DCAUD_DeleteDevice; - - spu_init(); - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = DCAUD_OpenAudio; + this->WaitAudio = DCAUD_WaitAudio; + this->PlayAudio = DCAUD_PlayAudio; + this->GetAudioBuf = DCAUD_GetAudioBuf; + this->CloseAudio = DCAUD_CloseAudio; + + this->free = DCAUD_DeleteDevice; + + spu_init (); + + return this; } AudioBootStrap DCAUD_bootstrap = { - "dcaudio", "Dreamcast AICA audio", - DCAUD_Available, DCAUD_CreateDevice + "dcaudio", "Dreamcast AICA audio", + DCAUD_Available, DCAUD_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void DCAUD_WaitAudio(_THIS) +static void +DCAUD_WaitAudio (_THIS) { - if (this->hidden->playing) { - /* wait */ - while(aica_get_pos(0)/this->spec.samples == this->hidden->nextbuf) { - thd_pass(); - } - } + if (this->hidden->playing) { + /* wait */ + while (aica_get_pos (0) / this->spec.samples == this->hidden->nextbuf) { + thd_pass (); + } + } } #define SPU_RAM_BASE 0xa0800000 -static void spu_memload_stereo8(int leftpos,int rightpos,void *src0,size_t size) +static void +spu_memload_stereo8 (int leftpos, int rightpos, void *src0, size_t size) { - uint8 *src = src0; - uint32 *left = (uint32*)(leftpos +SPU_RAM_BASE); - uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE); - size = (size+7)/8; - while(size--) { - unsigned lval,rval; - lval = *src++; - rval = *src++; - lval|= (*src++)<<8; - rval|= (*src++)<<8; - lval|= (*src++)<<16; - rval|= (*src++)<<16; - lval|= (*src++)<<24; - rval|= (*src++)<<24; - g2_write_32(left++,lval); - g2_write_32(right++,rval); - g2_fifo_wait(); - } + uint8 *src = src0; + uint32 *left = (uint32 *) (leftpos + SPU_RAM_BASE); + uint32 *right = (uint32 *) (rightpos + SPU_RAM_BASE); + size = (size + 7) / 8; + while (size--) { + unsigned lval, rval; + lval = *src++; + rval = *src++; + lval |= (*src++) << 8; + rval |= (*src++) << 8; + lval |= (*src++) << 16; + rval |= (*src++) << 16; + lval |= (*src++) << 24; + rval |= (*src++) << 24; + g2_write_32 (left++, lval); + g2_write_32 (right++, rval); + g2_fifo_wait (); + } } -static void spu_memload_stereo16(int leftpos,int rightpos,void *src0,size_t size) +static void +spu_memload_stereo16 (int leftpos, int rightpos, void *src0, size_t size) { - uint16 *src = src0; - uint32 *left = (uint32*)(leftpos +SPU_RAM_BASE); - uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE); - size = (size+7)/8; - while(size--) { - unsigned lval,rval; - lval = *src++; - rval = *src++; - lval|= (*src++)<<16; - rval|= (*src++)<<16; - g2_write_32(left++,lval); - g2_write_32(right++,rval); - g2_fifo_wait(); - } + uint16 *src = src0; + uint32 *left = (uint32 *) (leftpos + SPU_RAM_BASE); + uint32 *right = (uint32 *) (rightpos + SPU_RAM_BASE); + size = (size + 7) / 8; + while (size--) { + unsigned lval, rval; + lval = *src++; + rval = *src++; + lval |= (*src++) << 16; + rval |= (*src++) << 16; + g2_write_32 (left++, lval); + g2_write_32 (right++, rval); + g2_fifo_wait (); + } } -static void DCAUD_PlayAudio(_THIS) +static void +DCAUD_PlayAudio (_THIS) { - SDL_AudioSpec *spec = &this->spec; - unsigned int offset; - - if (this->hidden->playing) { - /* wait */ - while(aica_get_pos(0)/spec->samples == this->hidden->nextbuf) { - thd_pass(); - } - } - - offset = this->hidden->nextbuf*spec->size; - this->hidden->nextbuf^=1; - /* Write the audio data, checking for EAGAIN on broken audio drivers */ - if (spec->channels==1) { - spu_memload(this->hidden->leftpos+offset,this->hidden->mixbuf,this->hidden->mixlen); - } else { - offset/=2; - if ((this->spec.format&255)==8) { - spu_memload_stereo8(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen); - } else { - spu_memload_stereo16(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen); - } - } - - if (!this->hidden->playing) { - int mode; - this->hidden->playing = 1; - mode = (spec->format==AUDIO_S8)?SM_8BIT:SM_16BIT; - if (spec->channels==1) { - aica_play(0,mode,this->hidden->leftpos,0,spec->samples*2,spec->freq,255,128,1); - } else { - aica_play(0,mode,this->hidden->leftpos ,0,spec->samples*2,spec->freq,255,0,1); - aica_play(1,mode,this->hidden->rightpos,0,spec->samples*2,spec->freq,255,255,1); - } - } + SDL_AudioSpec *spec = &this->spec; + unsigned int offset; + + if (this->hidden->playing) { + /* wait */ + while (aica_get_pos (0) / spec->samples == this->hidden->nextbuf) { + thd_pass (); + } + } + + offset = this->hidden->nextbuf * spec->size; + this->hidden->nextbuf ^= 1; + /* Write the audio data, checking for EAGAIN on broken audio drivers */ + if (spec->channels == 1) { + spu_memload (this->hidden->leftpos + offset, this->hidden->mixbuf, + this->hidden->mixlen); + } else { + offset /= 2; + if ((this->spec.format & 255) == 8) { + spu_memload_stereo8 (this->hidden->leftpos + offset, + this->hidden->rightpos + offset, + this->hidden->mixbuf, this->hidden->mixlen); + } else { + spu_memload_stereo16 (this->hidden->leftpos + offset, + this->hidden->rightpos + offset, + this->hidden->mixbuf, this->hidden->mixlen); + } + } + + if (!this->hidden->playing) { + int mode; + this->hidden->playing = 1; + mode = (spec->format == AUDIO_S8) ? SM_8BIT : SM_16BIT; + if (spec->channels == 1) { + aica_play (0, mode, this->hidden->leftpos, 0, + spec->samples * 2, spec->freq, 255, 128, 1); + } else { + aica_play (0, mode, this->hidden->leftpos, 0, + spec->samples * 2, spec->freq, 255, 0, 1); + aica_play (1, mode, this->hidden->rightpos, 0, + spec->samples * 2, spec->freq, 255, 255, 1); + } + } } -static Uint8 *DCAUD_GetAudioBuf(_THIS) +static Uint8 * +DCAUD_GetAudioBuf (_THIS) { - return(this->hidden->mixbuf); + return (this->hidden->mixbuf); } -static void DCAUD_CloseAudio(_THIS) +static void +DCAUD_CloseAudio (_THIS) { - aica_stop(0); - if (this->spec.channels==2) aica_stop(1); - if ( this->hidden->mixbuf != NULL ) { - SDL_FreeAudioMem(this->hidden->mixbuf); - this->hidden->mixbuf = NULL; - } + aica_stop (0); + if (this->spec.channels == 2) + aica_stop (1); + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem (this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } } -static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +DCAUD_OpenAudio (_THIS, SDL_AudioSpec * spec) { - switch(spec->format&0xff) { - case 8: spec->format = AUDIO_S8; break; - case 16: spec->format = AUDIO_S16LSB; break; - default: - SDL_SetError("Unsupported audio format"); - return(-1); - } - - /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); - - /* Allocate mixing buffer */ - this->hidden->mixlen = spec->size; - this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); - if ( this->hidden->mixbuf == NULL ) { - return(-1); - } - SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); - this->hidden->leftpos = 0x11000; - this->hidden->rightpos = 0x11000+spec->size; - this->hidden->playing = 0; - this->hidden->nextbuf = 0; - - /* We're ready to rock and roll. :-) */ - return(0); + switch (spec->format & 0xff) { + case 8: + spec->format = AUDIO_S8; + break; + case 16: + spec->format = AUDIO_S16LSB; + break; + default: + SDL_SetError ("Unsupported audio format"); + return (-1); + } + + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec (spec); + + /* Allocate mixing buffer */ + this->hidden->mixlen = spec->size; + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen); + if (this->hidden->mixbuf == NULL) { + return (-1); + } + SDL_memset (this->hidden->mixbuf, spec->silence, spec->size); + this->hidden->leftpos = 0x11000; + this->hidden->rightpos = 0x11000 + spec->size; + this->hidden->playing = 0; + this->hidden->nextbuf = 0; + + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dc/SDL_dcaudio.h b/src/audio/dc/SDL_dcaudio.h index a5b01d3fc..4020f5119 100644 --- a/src/audio/dc/SDL_dcaudio.h +++ b/src/audio/dc/SDL_dcaudio.h @@ -29,13 +29,15 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - Uint8 *mixbuf; - Uint32 mixlen; - int playing; - int leftpos,rightpos; - int nextbuf; +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + Uint8 *mixbuf; + Uint32 mixlen; + int playing; + int leftpos, rightpos; + int nextbuf; }; #endif /* _SDL_dcaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dc/aica.c b/src/audio/dc/aica.c index b6a1c9364..42e1f8c2b 100644 --- a/src/audio/dc/aica.c +++ b/src/audio/dc/aica.c @@ -9,8 +9,8 @@ #include #include -/* #define dc_snd_base ((volatile unsigned char *)0x00800000) */ /* arm side */ -#define dc_snd_base ((volatile unsigned char *)0xa0700000) /* dc side */ + /* #define dc_snd_base ((volatile unsigned char *)0x00800000) *//* arm side */ +#define dc_snd_base ((volatile unsigned char *)0xa0700000) /* dc side */ /* Some convienence macros */ #define SNDREGADDR(x) (0xa0700000 + (x)) @@ -39,26 +39,29 @@ } while(0) -void aica_init() { - int i, j, old = 0; - - /* Initialize AICA channels */ - G2_LOCK(old); - SNDREG32(0x2800) = 0x0000; - - for (i=0; i<64; i++) { - for (j=0; j<0x80; j+=4) { - if ((j&31)==0) g2_fifo_wait(); - CHNREG32(i, j) = 0; - } - g2_fifo_wait(); - CHNREG32(i,0) = 0x8000; - CHNREG32(i,20) = 0x1f; - } +void +aica_init () +{ + int i, j, old = 0; + + /* Initialize AICA channels */ + G2_LOCK (old); + SNDREG32 (0x2800) = 0x0000; + + for (i = 0; i < 64; i++) { + for (j = 0; j < 0x80; j += 4) { + if ((j & 31) == 0) + g2_fifo_wait (); + CHNREG32 (i, j) = 0; + } + g2_fifo_wait (); + CHNREG32 (i, 0) = 0x8000; + CHNREG32 (i, 20) = 0x1f; + } - SNDREG32(0x2800) = 0x000f; - g2_fifo_wait(); - G2_UNLOCK(old); + SNDREG32 (0x2800) = 0x000f; + g2_fifo_wait (); + G2_UNLOCK (old); } /* Translates a volume from linear form to logarithmic form (required by @@ -86,25 +89,25 @@ void aica_init() { }; */ const static unsigned char logs[] = { - 0, 15, 22, 27, 31, 35, 39, 42, 45, 47, 50, 52, 55, 57, 59, 61, - 63, 65, 67, 69, 71, 73, 74, 76, 78, 79, 81, 82, 84, 85, 87, 88, - 90, 91, 92, 94, 95, 96, 98, 99, 100, 102, 103, 104, 105, 106, - 108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121, - 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, - 135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 145, 146, - 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 156, - 157, 158, 159, 160, 160, 161, 162, 163, 164, 164, 165, 166, 167, - 167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176, - 177, 178, 178, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185, - 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, - 195, 195, 196, 197, 197, 198, 199, 199, 200, 200, 201, 202, 202, - 203, 204, 204, 205, 205, 206, 207, 207, 208, 209, 209, 210, 210, - 211, 212, 212, 213, 213, 214, 215, 215, 216, 216, 217, 217, 218, - 219, 219, 220, 220, 221, 221, 222, 223, 223, 224, 224, 225, 225, - 226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 232, 232, 233, - 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, 239, 240, - 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, - 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 255 + 0, 15, 22, 27, 31, 35, 39, 42, 45, 47, 50, 52, 55, 57, 59, 61, + 63, 65, 67, 69, 71, 73, 74, 76, 78, 79, 81, 82, 84, 85, 87, 88, + 90, 91, 92, 94, 95, 96, 98, 99, 100, 102, 103, 104, 105, 106, + 108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121, + 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 145, 146, + 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 156, + 157, 158, 159, 160, 160, 161, 162, 163, 164, 164, 165, 166, 167, + 167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176, + 177, 178, 178, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185, + 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, + 195, 195, 196, 197, 197, 198, 199, 199, 200, 200, 201, 202, 202, + 203, 204, 204, 205, 205, 206, 207, 207, 208, 209, 209, 210, 210, + 211, 212, 212, 213, 213, 214, 215, 215, 216, 216, 217, 217, 218, + 219, 219, 220, 220, 221, 221, 222, 223, 223, 224, 224, 225, 225, + 226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 232, 232, 233, + 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, 239, 240, + 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, + 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 255 }; /* For the moment this is going to have to suffice, until we really @@ -113,23 +116,25 @@ const static unsigned char logs[] = { #define AICA_VOL(x) (0xff - logs[128 + (((x) & 0xff) / 2)]) //#define AICA_VOL(x) (0xff - logs[x&255]) -static inline unsigned AICA_FREQ(unsigned freq) { - unsigned long freq_lo, freq_base = 5644800; - int freq_hi = 7; +static inline unsigned +AICA_FREQ (unsigned freq) +{ + unsigned long freq_lo, freq_base = 5644800; + int freq_hi = 7; - /* Need to convert frequency to floating point format - (freq_hi is exponent, freq_lo is mantissa) - Formula is ferq = 44100*2^freq_hi*(1+freq_lo/1024) */ - while (freq < freq_base && freq_hi > -8) { - freq_base >>= 1; - --freq_hi; - } - while (freq < freq_base && freq_hi > -8) { - freq_base >>= 1; - freq_hi--; - } - freq_lo = (freq<<10) / freq_base; - return (freq_hi << 11) | (freq_lo & 1023); + /* Need to convert frequency to floating point format + (freq_hi is exponent, freq_lo is mantissa) + Formula is ferq = 44100*2^freq_hi*(1+freq_lo/1024) */ + while (freq < freq_base && freq_hi > -8) { + freq_base >>= 1; + --freq_hi; + } + while (freq < freq_base && freq_hi > -8) { + freq_base >>= 1; + freq_hi--; + } + freq_lo = (freq << 10) / freq_base; + return (freq_hi << 11) | (freq_lo & 1023); } /* Sets up a sound channel completely. This is generally good if you want @@ -148,15 +153,18 @@ static inline unsigned AICA_FREQ(unsigned freq) { This routine (and the similar ones) owe a lot to Marcus' sound example -- I hadn't gotten quite this far into dissecting the individual regs yet. */ -void aica_play(int ch,int mode,unsigned long smpptr,int loopst,int loopend,int freq,int vol,int pan,int loopflag) { +void +aica_play (int ch, int mode, unsigned long smpptr, int loopst, int loopend, + int freq, int vol, int pan, int loopflag) +{ /* int i; */ - int val; - int old = 0; + int val; + int old = 0; - /* Stop the channel (if it's already playing) */ - aica_stop(ch); - /* doesn't seem to be needed, but it's here just in case */ + /* Stop the channel (if it's already playing) */ + aica_stop (ch); + /* doesn't seem to be needed, but it's here just in case */ /* for (i=0; i<256; i++) { asm("nop"); @@ -165,107 +173,127 @@ void aica_play(int ch,int mode,unsigned long smpptr,int loopst,int loopend,int f asm("nop"); } */ - G2_LOCK(old); - /* Envelope setup. The first of these is the loop point, - e.g., where the sample starts over when it loops. The second - is the loop end. This is the full length of the sample when - you are not looping, or the loop end point when you are (though - storing more than that is a waste of memory if you're not doing - volume enveloping). */ - CHNREG32(ch, 8) = loopst & 0xffff; - CHNREG32(ch, 12) = loopend & 0xffff; - - /* Write resulting values */ - CHNREG32(ch, 24) = AICA_FREQ(freq); - - /* Set volume, pan, and some other things that we don't know what - they do =) */ - CHNREG32(ch, 36) = AICA_PAN(pan) | (0xf<<8); - /* Convert the incoming volume and pan into hardware values */ - /* Vol starts at zero so we can ramp */ - vol = AICA_VOL(vol); - CHNREG32(ch, 40) = 0x24 | (vol<<8); - /* Convert the incoming volume and pan into hardware values */ - /* Vol starts at zero so we can ramp */ - - /* If we supported volume envelopes (which we don't yet) then - this value would set that up. The top 4 bits determine the - envelope speed. f is the fastest, 1 is the slowest, and 0 - seems to be an invalid value and does weird things). The - default (below) sets it into normal mode (play and terminate/loop). - CHNREG32(ch, 16) = 0xf010; - */ - CHNREG32(ch, 16) = 0x1f; /* No volume envelope */ - - - /* Set sample format, buffer address, and looping control. If - 0x0200 mask is set on reg 0, the sample loops infinitely. If - it's not set, the sample plays once and terminates. We'll - also set the bits to start playback here. */ - CHNREG32(ch, 4) = smpptr & 0xffff; - val = 0xc000 | 0x0000 | (mode<<7) | (smpptr >> 16); - if (loopflag) val|=0x200; - - CHNREG32(ch, 0) = val; - - G2_UNLOCK(old); - - /* Enable playback */ - /* CHNREG32(ch, 0) |= 0xc000; */ - g2_fifo_wait(); + G2_LOCK (old); + /* Envelope setup. The first of these is the loop point, + e.g., where the sample starts over when it loops. The second + is the loop end. This is the full length of the sample when + you are not looping, or the loop end point when you are (though + storing more than that is a waste of memory if you're not doing + volume enveloping). */ + CHNREG32 (ch, 8) = loopst & 0xffff; + CHNREG32 (ch, 12) = loopend & 0xffff; + + /* Write resulting values */ + CHNREG32 (ch, 24) = AICA_FREQ (freq); + + /* Set volume, pan, and some other things that we don't know what + they do =) */ + CHNREG32 (ch, 36) = AICA_PAN (pan) | (0xf << 8); + /* Convert the incoming volume and pan into hardware values */ + /* Vol starts at zero so we can ramp */ + vol = AICA_VOL (vol); + CHNREG32 (ch, 40) = 0x24 | (vol << 8); + /* Convert the incoming volume and pan into hardware values */ + /* Vol starts at zero so we can ramp */ + + /* If we supported volume envelopes (which we don't yet) then + this value would set that up. The top 4 bits determine the + envelope speed. f is the fastest, 1 is the slowest, and 0 + seems to be an invalid value and does weird things). The + default (below) sets it into normal mode (play and terminate/loop). + CHNREG32(ch, 16) = 0xf010; + */ + CHNREG32 (ch, 16) = 0x1f; /* No volume envelope */ + + + /* Set sample format, buffer address, and looping control. If + 0x0200 mask is set on reg 0, the sample loops infinitely. If + it's not set, the sample plays once and terminates. We'll + also set the bits to start playback here. */ + CHNREG32 (ch, 4) = smpptr & 0xffff; + val = 0xc000 | 0x0000 | (mode << 7) | (smpptr >> 16); + if (loopflag) + val |= 0x200; + + CHNREG32 (ch, 0) = val; + + G2_UNLOCK (old); + + /* Enable playback */ + /* CHNREG32(ch, 0) |= 0xc000; */ + g2_fifo_wait (); #if 0 - for (i=0xff; i>=vol; i--) { - if ((i&7)==0) g2_fifo_wait(); - CHNREG32(ch, 40) = 0x24 | (i<<8);; - } + for (i = 0xff; i >= vol; i--) { + if ((i & 7) == 0) + g2_fifo_wait (); + CHNREG32 (ch, 40) = 0x24 | (i << 8);; + } - g2_fifo_wait(); + g2_fifo_wait (); #endif } /* Stop the sound on a given channel */ -void aica_stop(int ch) { - g2_write_32(CHNREGADDR(ch, 0),(g2_read_32(CHNREGADDR(ch, 0)) & ~0x4000) | 0x8000); - g2_fifo_wait(); +void +aica_stop (int ch) +{ + g2_write_32 (CHNREGADDR (ch, 0), + (g2_read_32 (CHNREGADDR (ch, 0)) & ~0x4000) | 0x8000); + g2_fifo_wait (); } /* The rest of these routines can change the channel in mid-stride so you can do things like vibrato and panning effects. */ - + /* Set channel volume */ -void aica_vol(int ch,int vol) { -// g2_write_8(CHNREGADDR(ch, 41),AICA_VOL(vol)); - g2_write_32(CHNREGADDR(ch, 40),(g2_read_32(CHNREGADDR(ch, 40))&0xffff00ff)|(AICA_VOL(vol)<<8) ); - g2_fifo_wait(); +void +aica_vol (int ch, int vol) +{ +// g2_write_8(CHNREGADDR(ch, 41),AICA_VOL(vol)); + g2_write_32 (CHNREGADDR (ch, 40), + (g2_read_32 (CHNREGADDR (ch, 40)) & 0xffff00ff) | + (AICA_VOL (vol) << 8)); + g2_fifo_wait (); } /* Set channel pan */ -void aica_pan(int ch,int pan) { -// g2_write_8(CHNREGADDR(ch, 36),AICA_PAN(pan)); - g2_write_32(CHNREGADDR(ch, 36),(g2_read_32(CHNREGADDR(ch, 36))&0xffffff00)|(AICA_PAN(pan)) ); - g2_fifo_wait(); +void +aica_pan (int ch, int pan) +{ +// g2_write_8(CHNREGADDR(ch, 36),AICA_PAN(pan)); + g2_write_32 (CHNREGADDR (ch, 36), + (g2_read_32 (CHNREGADDR (ch, 36)) & 0xffffff00) | + (AICA_PAN (pan))); + g2_fifo_wait (); } /* Set channel frequency */ -void aica_freq(int ch,int freq) { - g2_write_32(CHNREGADDR(ch, 24),AICA_FREQ(freq)); - g2_fifo_wait(); +void +aica_freq (int ch, int freq) +{ + g2_write_32 (CHNREGADDR (ch, 24), AICA_FREQ (freq)); + g2_fifo_wait (); } /* Get channel position */ -int aica_get_pos(int ch) { +int +aica_get_pos (int ch) +{ #if 1 - /* Observe channel ch */ - g2_write_32(SNDREGADDR(0x280c),(g2_read_32(SNDREGADDR(0x280c))&0xffff00ff) | (ch<<8)); - g2_fifo_wait(); - /* Update position counters */ - return g2_read_32(SNDREGADDR(0x2814)) & 0xffff; + /* Observe channel ch */ + g2_write_32 (SNDREGADDR (0x280c), + (g2_read_32 (SNDREGADDR (0x280c)) & 0xffff00ff) | (ch << 8)); + g2_fifo_wait (); + /* Update position counters */ + return g2_read_32 (SNDREGADDR (0x2814)) & 0xffff; #else - /* Observe channel ch */ - g2_write_8(SNDREGADDR(0x280d),ch); - /* Update position counters */ - return g2_read_32(SNDREGADDR(0x2814)) & 0xffff; + /* Observe channel ch */ + g2_write_8 (SNDREGADDR (0x280d), ch); + /* Update position counters */ + return g2_read_32 (SNDREGADDR (0x2814)) & 0xffff; #endif } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dc/aica.h b/src/audio/dc/aica.h index 93155d281..6c1688a3e 100644 --- a/src/audio/dc/aica.h +++ b/src/audio/dc/aica.h @@ -30,11 +30,13 @@ #define SM_16BIT 0 #define SM_ADPCM 2 -void aica_play(int ch,int mode,unsigned long smpptr,int looptst,int loopend,int freq,int vol,int pan,int loopflag); -void aica_stop(int ch); -void aica_vol(int ch,int vol); -void aica_pan(int ch,int pan); -void aica_freq(int ch,int freq); -int aica_get_pos(int ch); +void aica_play (int ch, int mode, unsigned long smpptr, int looptst, + int loopend, int freq, int vol, int pan, int loopflag); +void aica_stop (int ch); +void aica_vol (int ch, int vol); +void aica_pan (int ch, int pan); +void aica_freq (int ch, int freq); +int aica_get_pos (int ch); #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/disk/SDL_diskaudio.c b/src/audio/disk/SDL_diskaudio.c index d896d9da3..51e291122 100644 --- a/src/audio/disk/SDL_diskaudio.c +++ b/src/audio/disk/SDL_diskaudio.c @@ -47,140 +47,149 @@ #define DISKDEFAULT_WRITEDELAY 150 /* Audio driver functions */ -static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DISKAUD_WaitAudio(_THIS); -static void DISKAUD_PlayAudio(_THIS); -static Uint8 *DISKAUD_GetAudioBuf(_THIS); -static void DISKAUD_CloseAudio(_THIS); - -static const char *DISKAUD_GetOutputFilename(void) +static int DISKAUD_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DISKAUD_WaitAudio (_THIS); +static void DISKAUD_PlayAudio (_THIS); +static Uint8 *DISKAUD_GetAudioBuf (_THIS); +static void DISKAUD_CloseAudio (_THIS); + +static const char * +DISKAUD_GetOutputFilename (void) { - const char *envr = SDL_getenv(DISKENVR_OUTFILE); - return((envr != NULL) ? envr : DISKDEFAULT_OUTFILE); + const char *envr = SDL_getenv (DISKENVR_OUTFILE); + return ((envr != NULL) ? envr : DISKDEFAULT_OUTFILE); } /* Audio driver bootstrap functions */ -static int DISKAUD_Available(void) +static int +DISKAUD_Available (void) { - const char *envr = SDL_getenv("SDL_AUDIODRIVER"); - if (envr && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) { - return(1); - } - return(0); + const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); + if (envr && (SDL_strcmp (envr, DISKAUD_DRIVER_NAME) == 0)) { + return (1); + } + return (0); } -static void DISKAUD_DeleteDevice(SDL_AudioDevice *device) +static void +DISKAUD_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *DISKAUD_CreateDevice(int devindex) +static SDL_AudioDevice * +DISKAUD_CreateDevice (int devindex) { - SDL_AudioDevice *this; - const char *envr; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - envr = SDL_getenv(DISKENVR_WRITEDELAY); - this->hidden->write_delay = (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY; - - /* Set the function pointers */ - this->OpenAudio = DISKAUD_OpenAudio; - this->WaitAudio = DISKAUD_WaitAudio; - this->PlayAudio = DISKAUD_PlayAudio; - this->GetAudioBuf = DISKAUD_GetAudioBuf; - this->CloseAudio = DISKAUD_CloseAudio; - - this->free = DISKAUD_DeleteDevice; - - return this; + SDL_AudioDevice *this; + const char *envr; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + envr = SDL_getenv (DISKENVR_WRITEDELAY); + this->hidden->write_delay = + (envr) ? SDL_atoi (envr) : DISKDEFAULT_WRITEDELAY; + + /* Set the function pointers */ + this->OpenAudio = DISKAUD_OpenAudio; + this->WaitAudio = DISKAUD_WaitAudio; + this->PlayAudio = DISKAUD_PlayAudio; + this->GetAudioBuf = DISKAUD_GetAudioBuf; + this->CloseAudio = DISKAUD_CloseAudio; + + this->free = DISKAUD_DeleteDevice; + + return this; } AudioBootStrap DISKAUD_bootstrap = { - DISKAUD_DRIVER_NAME, "direct-to-disk audio", - DISKAUD_Available, DISKAUD_CreateDevice + DISKAUD_DRIVER_NAME, "direct-to-disk audio", + DISKAUD_Available, DISKAUD_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void DISKAUD_WaitAudio(_THIS) +static void +DISKAUD_WaitAudio (_THIS) { - SDL_Delay(this->hidden->write_delay); + SDL_Delay (this->hidden->write_delay); } -static void DISKAUD_PlayAudio(_THIS) +static void +DISKAUD_PlayAudio (_THIS) { - int written; + int written; - /* Write the audio data */ - written = SDL_RWwrite(this->hidden->output, - this->hidden->mixbuf, 1, - this->hidden->mixlen); + /* Write the audio data */ + written = SDL_RWwrite (this->hidden->output, + this->hidden->mixbuf, 1, this->hidden->mixlen); - /* If we couldn't write, assume fatal error for now */ - if ( (Uint32)written != this->hidden->mixlen ) { - this->enabled = 0; - } + /* If we couldn't write, assume fatal error for now */ + if ((Uint32) written != this->hidden->mixlen) { + this->enabled = 0; + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Wrote %d bytes of audio data\n", written); + fprintf (stderr, "Wrote %d bytes of audio data\n", written); #endif } -static Uint8 *DISKAUD_GetAudioBuf(_THIS) +static Uint8 * +DISKAUD_GetAudioBuf (_THIS) { - return(this->hidden->mixbuf); + return (this->hidden->mixbuf); } -static void DISKAUD_CloseAudio(_THIS) +static void +DISKAUD_CloseAudio (_THIS) { - if ( this->hidden->mixbuf != NULL ) { - SDL_FreeAudioMem(this->hidden->mixbuf); - this->hidden->mixbuf = NULL; - } - if ( this->hidden->output != NULL ) { - SDL_RWclose(this->hidden->output); - this->hidden->output = NULL; - } + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem (this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } + if (this->hidden->output != NULL) { + SDL_RWclose (this->hidden->output); + this->hidden->output = NULL; + } } -static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +DISKAUD_OpenAudio (_THIS, SDL_AudioSpec * spec) { - const char *fname = DISKAUD_GetOutputFilename(); - - /* Open the audio device */ - this->hidden->output = SDL_RWFromFile(fname, "wb"); - if ( this->hidden->output == NULL ) { - return(-1); - } + const char *fname = DISKAUD_GetOutputFilename (); + /* Open the audio device */ + this->hidden->output = SDL_RWFromFile (fname, "wb"); + if (this->hidden->output == NULL) { + return (-1); + } #if HAVE_STDIO_H - fprintf(stderr, "WARNING: You are using the SDL disk writer" - " audio driver!\n Writing to file [%s].\n", fname); + fprintf (stderr, "WARNING: You are using the SDL disk writer" + " audio driver!\n Writing to file [%s].\n", fname); #endif - /* Allocate mixing buffer */ - this->hidden->mixlen = spec->size; - this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); - if ( this->hidden->mixbuf == NULL ) { - return(-1); - } - SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); + /* Allocate mixing buffer */ + this->hidden->mixlen = spec->size; + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen); + if (this->hidden->mixbuf == NULL) { + return (-1); + } + SDL_memset (this->hidden->mixbuf, spec->silence, spec->size); - /* We're ready to rock and roll. :-) */ - return(0); + /* We're ready to rock and roll. :-) */ + return (0); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/disk/SDL_diskaudio.h b/src/audio/disk/SDL_diskaudio.h index 2ddd68f95..231c55337 100644 --- a/src/audio/disk/SDL_diskaudio.h +++ b/src/audio/disk/SDL_diskaudio.h @@ -30,12 +30,14 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - SDL_RWops *output; - Uint8 *mixbuf; - Uint32 mixlen; - Uint32 write_delay; +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + SDL_RWops *output; + Uint8 *mixbuf; + Uint32 mixlen; + Uint32 write_delay; }; #endif /* _SDL_diskaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dma/SDL_dmaaudio.c b/src/audio/dma/SDL_dmaaudio.c index 84734a3da..3c6783028 100644 --- a/src/audio/dma/SDL_dmaaudio.c +++ b/src/audio/dma/SDL_dmaaudio.c @@ -24,7 +24,7 @@ /* Allow access to a raw mixing buffer */ #include -#include /* For strerror() */ +#include /* For strerror() */ #include #include #include @@ -60,396 +60,410 @@ #define OPEN_FLAGS (O_RDWR|O_NONBLOCK) /* Audio driver functions */ -static int DMA_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DMA_WaitAudio(_THIS); -static void DMA_PlayAudio(_THIS); -static Uint8 *DMA_GetAudioBuf(_THIS); -static void DMA_CloseAudio(_THIS); +static int DMA_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DMA_WaitAudio (_THIS); +static void DMA_PlayAudio (_THIS); +static Uint8 *DMA_GetAudioBuf (_THIS); +static void DMA_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - int available; - int fd; - - available = 0; - - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0); - if ( fd >= 0 ) { - int caps; - struct audio_buf_info info; - - if ( (ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) == 0) && - (caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) && - (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == 0) ) { - available = 1; - } - close(fd); - } - return(available); + int available; + int fd; + + available = 0; + + fd = SDL_OpenAudioPath (NULL, 0, OPEN_FLAGS, 0); + if (fd >= 0) { + int caps; + struct audio_buf_info info; + + if ((ioctl (fd, SNDCTL_DSP_GETCAPS, &caps) == 0) && + (caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) && + (ioctl (fd, SNDCTL_DSP_GETOSPACE, &info) == 0)) { + available = 1; + } + close (fd); + } + return (available); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = DMA_OpenAudio; - this->WaitAudio = DMA_WaitAudio; - this->PlayAudio = DMA_PlayAudio; - this->GetAudioBuf = DMA_GetAudioBuf; - this->CloseAudio = DMA_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + audio_fd = -1; + + /* Set the function pointers */ + this->OpenAudio = DMA_OpenAudio; + this->WaitAudio = DMA_WaitAudio; + this->PlayAudio = DMA_PlayAudio; + this->GetAudioBuf = DMA_GetAudioBuf; + this->CloseAudio = DMA_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap DMA_bootstrap = { - DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio", - Audio_Available, Audio_CreateDevice + DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio", + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void DMA_WaitAudio(_THIS) +static void +DMA_WaitAudio (_THIS) { - fd_set fdset; - - /* Check to see if the thread-parent process is still alive */ - { static int cnt = 0; - /* Note that this only works with thread implementations - that use a different process id for each thread. - */ - if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ - if ( kill(parent, 0) < 0 ) { - this->enabled = 0; - } - } - } - - /* See if we need to use timed audio synchronization */ - if ( frame_ticks ) { - /* Use timer for general audio synchronization */ - Sint32 ticks; - - ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; - if ( ticks > 0 ) { - SDL_Delay(ticks); - } - } else { - /* Use select() for audio synchronization */ - struct timeval timeout; - FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); - timeout.tv_sec = 10; - timeout.tv_usec = 0; + fd_set fdset; + + /* Check to see if the thread-parent process is still alive */ + { + static int cnt = 0; + /* Note that this only works with thread implementations + that use a different process id for each thread. + */ + if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */ + if (kill (parent, 0) < 0) { + this->enabled = 0; + } + } + } + + /* See if we need to use timed audio synchronization */ + if (frame_ticks) { + /* Use timer for general audio synchronization */ + Sint32 ticks; + + ticks = ((Sint32) (next_frame - SDL_GetTicks ())) - FUDGE_TICKS; + if (ticks > 0) { + SDL_Delay (ticks); + } + } else { + /* Use select() for audio synchronization */ + struct timeval timeout; + FD_ZERO (&fdset); + FD_SET (audio_fd, &fdset); + timeout.tv_sec = 10; + timeout.tv_usec = 0; #ifdef DEBUG_AUDIO - fprintf(stderr, "Waiting for audio to get ready\n"); + fprintf (stderr, "Waiting for audio to get ready\n"); #endif - if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) { - const char *message = + if (select (audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) { + const char *message = #ifdef AUDIO_OSPACE_HACK - "Audio timeout - buggy audio driver? (trying ospace)"; + "Audio timeout - buggy audio driver? (trying ospace)"; #else - "Audio timeout - buggy audio driver? (disabled)"; + "Audio timeout - buggy audio driver? (disabled)"; #endif - /* In general we should never print to the screen, - but in this case we have no other way of letting - the user know what happened. - */ - fprintf(stderr, "SDL: %s\n", message); + /* In general we should never print to the screen, + but in this case we have no other way of letting + the user know what happened. + */ + fprintf (stderr, "SDL: %s\n", message); #ifdef AUDIO_OSPACE_HACK - /* We may be able to use GET_OSPACE trick */ - frame_ticks = (float)(this->spec->samples*1000) / - this->spec->freq; - next_frame = SDL_GetTicks()+frame_ticks; + /* We may be able to use GET_OSPACE trick */ + frame_ticks = (float) (this->spec->samples * 1000) / + this->spec->freq; + next_frame = SDL_GetTicks () + frame_ticks; #else - this->enabled = 0; - /* Don't try to close - may hang */ - audio_fd = -1; + this->enabled = 0; + /* Don't try to close - may hang */ + audio_fd = -1; #ifdef DEBUG_AUDIO - fprintf(stderr, "Done disabling audio\n"); + fprintf (stderr, "Done disabling audio\n"); #endif #endif /* AUDIO_OSPACE_HACK */ - } + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Ready!\n"); + fprintf (stderr, "Ready!\n"); #endif - } + } } -static void DMA_PlayAudio(_THIS) +static void +DMA_PlayAudio (_THIS) { - /* If timer synchronization is enabled, set the next write frame */ - if ( frame_ticks ) { - next_frame += frame_ticks; - } - return; + /* If timer synchronization is enabled, set the next write frame */ + if (frame_ticks) { + next_frame += frame_ticks; + } + return; } -static Uint8 *DMA_GetAudioBuf(_THIS) +static Uint8 * +DMA_GetAudioBuf (_THIS) { - count_info info; - int playing; - int filling; - - /* Get number of blocks, looping if we're not using select() */ - do { - if ( ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &info) < 0 ) { - /* Uh oh... */ - this->enabled = 0; - return(NULL); - } - } while ( frame_ticks && (info.blocks < 1) ); + count_info info; + int playing; + int filling; + + /* Get number of blocks, looping if we're not using select() */ + do { + if (ioctl (audio_fd, SNDCTL_DSP_GETOPTR, &info) < 0) { + /* Uh oh... */ + this->enabled = 0; + return (NULL); + } + } + while (frame_ticks && (info.blocks < 1)); #ifdef DEBUG_AUDIO - if ( info.blocks > 1 ) { - printf("Warning: audio underflow (%d frags)\n", info.blocks-1); - } + if (info.blocks > 1) { + printf ("Warning: audio underflow (%d frags)\n", info.blocks - 1); + } #endif - playing = info.ptr / this->spec.size; - filling = (playing + 1)%num_buffers; - return (dma_buf + (filling * this->spec.size)); + playing = info.ptr / this->spec.size; + filling = (playing + 1) % num_buffers; + return (dma_buf + (filling * this->spec.size)); } -static void DMA_CloseAudio(_THIS) +static void +DMA_CloseAudio (_THIS) { - if ( dma_buf != NULL ) { - munmap(dma_buf, dma_len); - dma_buf = NULL; - } - if ( audio_fd >= 0 ) { - close(audio_fd); - audio_fd = -1; - } + if (dma_buf != NULL) { + munmap (dma_buf, dma_len); + dma_buf = NULL; + } + if (audio_fd >= 0) { + close (audio_fd); + audio_fd = -1; + } } -static int DMA_ReopenAudio(_THIS, const char *audiodev, int format, int stereo, - SDL_AudioSpec *spec) +static int +DMA_ReopenAudio (_THIS, const char *audiodev, int format, int stereo, + SDL_AudioSpec * spec) { - int frag_spec; - int value; - - /* Close and then reopen the audio device */ - close(audio_fd); - audio_fd = open(audiodev, O_RDWR, 0); - if ( audio_fd < 0 ) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return(-1); - } - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - - /* Determine the power of two of the fragment size */ - for ( frag_spec = 0; (0x01<size; ++frag_spec ); - if ( (0x01<size ) { - SDL_SetError("Fragment size must be a power of two"); - return(-1); - } - - /* Set the audio buffering parameters */ - if ( ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0 ) { - SDL_SetError("Couldn't set audio fragment spec"); - return(-1); - } - - /* Set the audio format */ - value = format; - if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || - (value != format) ) { - SDL_SetError("Couldn't set audio format"); - return(-1); - } - - /* Set mono or stereo audio */ - value = (spec->channels > 1); - if ( (ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) || - (value != stereo) ) { - SDL_SetError("Couldn't set audio channels"); - return(-1); - } - - /* Set the DSP frequency */ - value = spec->freq; - if ( ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0 ) { - SDL_SetError("Couldn't set audio frequency"); - return(-1); - } - spec->freq = value; - - /* We successfully re-opened the audio */ - return(0); + int frag_spec; + int value; + + /* Close and then reopen the audio device */ + close (audio_fd); + audio_fd = open (audiodev, O_RDWR, 0); + if (audio_fd < 0) { + SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); + return (-1); + } + + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + + /* Determine the power of two of the fragment size */ + for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec); + if ((0x01 << frag_spec) != spec->size) { + SDL_SetError ("Fragment size must be a power of two"); + return (-1); + } + + /* Set the audio buffering parameters */ + if (ioctl (audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) { + SDL_SetError ("Couldn't set audio fragment spec"); + return (-1); + } + + /* Set the audio format */ + value = format; + if ((ioctl (audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || + (value != format)) { + SDL_SetError ("Couldn't set audio format"); + return (-1); + } + + /* Set mono or stereo audio */ + value = (spec->channels > 1); + if ((ioctl (audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) || + (value != stereo)) { + SDL_SetError ("Couldn't set audio channels"); + return (-1); + } + + /* Set the DSP frequency */ + value = spec->freq; + if (ioctl (audio_fd, SNDCTL_DSP_SPEED, &value) < 0) { + SDL_SetError ("Couldn't set audio frequency"); + return (-1); + } + spec->freq = value; + + /* We successfully re-opened the audio */ + return (0); } -static int DMA_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +DMA_OpenAudio (_THIS, SDL_AudioSpec * spec) { - char audiodev[1024]; - int format; - int stereo; - int value; - Uint16 test_format; - struct audio_buf_info info; - - /* Reset the timer synchronization flag */ - frame_ticks = 0.0; - - /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0); - if ( audio_fd < 0 ) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return(-1); - } - dma_buf = NULL; - ioctl(audio_fd, SNDCTL_DSP_RESET, 0); - - /* Get a list of supported hardware formats */ - if ( ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0 ) { - SDL_SetError("Couldn't get audio format list"); - return(-1); - } - - /* Try for a closest match on audio format */ - format = 0; - for ( test_format = SDL_FirstAudioFormat(spec->format); - ! format && test_format; ) { + char audiodev[1024]; + int format; + int stereo; + int value; + Uint16 test_format; + struct audio_buf_info info; + + /* Reset the timer synchronization flag */ + frame_ticks = 0.0; + + /* Open the audio device */ + audio_fd = SDL_OpenAudioPath (audiodev, sizeof (audiodev), OPEN_FLAGS, 0); + if (audio_fd < 0) { + SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); + return (-1); + } + dma_buf = NULL; + ioctl (audio_fd, SNDCTL_DSP_RESET, 0); + + /* Get a list of supported hardware formats */ + if (ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) { + SDL_SetError ("Couldn't get audio format list"); + return (-1); + } + + /* Try for a closest match on audio format */ + format = 0; + for (test_format = SDL_FirstAudioFormat (spec->format); + !format && test_format;) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Trying format 0x%4.4x\n", test_format); + fprintf (stderr, "Trying format 0x%4.4x\n", test_format); #endif - switch ( test_format ) { - case AUDIO_U8: - if ( value & AFMT_U8 ) { - format = AFMT_U8; - } - break; - case AUDIO_S8: - if ( value & AFMT_S8 ) { - format = AFMT_S8; - } - break; - case AUDIO_S16LSB: - if ( value & AFMT_S16_LE ) { - format = AFMT_S16_LE; - } - break; - case AUDIO_S16MSB: - if ( value & AFMT_S16_BE ) { - format = AFMT_S16_BE; - } - break; - case AUDIO_U16LSB: - if ( value & AFMT_U16_LE ) { - format = AFMT_U16_LE; - } - break; - case AUDIO_U16MSB: - if ( value & AFMT_U16_BE ) { - format = AFMT_U16_BE; - } - break; - default: - format = 0; - break; - } - if ( ! format ) { - test_format = SDL_NextAudioFormat(); - } - } - if ( format == 0 ) { - SDL_SetError("Couldn't find any hardware audio formats"); - return(-1); - } - spec->format = test_format; - - /* Set the audio format */ - value = format; - if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || - (value != format) ) { - SDL_SetError("Couldn't set audio format"); - return(-1); - } - - /* Set mono or stereo audio (currently only two channels supported) */ - stereo = (spec->channels > 1); - ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo); - if ( stereo ) { - spec->channels = 2; - } else { - spec->channels = 1; - } - - /* Because some drivers don't allow setting the buffer size - after setting the format, we must re-open the audio device - once we know what format and channels are supported - */ - if ( DMA_ReopenAudio(this, audiodev, format, stereo, spec) < 0 ) { - /* Error is set by DMA_ReopenAudio() */ - return(-1); - } - - /* Memory map the audio buffer */ - if ( ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0 ) { - SDL_SetError("Couldn't get OSPACE parameters"); - return(-1); - } - spec->size = info.fragsize; - spec->samples = spec->size / ((spec->format & 0xFF) / 8); - spec->samples /= spec->channels; - num_buffers = info.fragstotal; - dma_len = num_buffers*spec->size; - dma_buf = (Uint8 *)mmap(NULL, dma_len, PROT_WRITE, MAP_SHARED, - audio_fd, 0); - if ( dma_buf == MAP_FAILED ) { - SDL_SetError("DMA memory map failed"); - dma_buf = NULL; - return(-1); - } - SDL_memset(dma_buf, spec->silence, dma_len); - - /* Check to see if we need to use select() workaround */ - { char *workaround; - workaround = SDL_getenv("SDL_DSP_NOSELECT"); - if ( workaround ) { - frame_ticks = (float)(spec->samples*1000)/spec->freq; - next_frame = SDL_GetTicks()+frame_ticks; - } - } - - /* Trigger audio playback */ - value = 0; - ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value); - value = PCM_ENABLE_OUTPUT; - if ( ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0 ) { - SDL_SetError("Couldn't trigger audio output"); - return(-1); - } - - /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); - - /* We're ready to rock and roll. :-) */ - return(0); + switch (test_format) { + case AUDIO_U8: + if (value & AFMT_U8) { + format = AFMT_U8; + } + break; + case AUDIO_S8: + if (value & AFMT_S8) { + format = AFMT_S8; + } + break; + case AUDIO_S16LSB: + if (value & AFMT_S16_LE) { + format = AFMT_S16_LE; + } + break; + case AUDIO_S16MSB: + if (value & AFMT_S16_BE) { + format = AFMT_S16_BE; + } + break; + case AUDIO_U16LSB: + if (value & AFMT_U16_LE) { + format = AFMT_U16_LE; + } + break; + case AUDIO_U16MSB: + if (value & AFMT_U16_BE) { + format = AFMT_U16_BE; + } + break; + default: + format = 0; + break; + } + if (!format) { + test_format = SDL_NextAudioFormat (); + } + } + if (format == 0) { + SDL_SetError ("Couldn't find any hardware audio formats"); + return (-1); + } + spec->format = test_format; + + /* Set the audio format */ + value = format; + if ((ioctl (audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || + (value != format)) { + SDL_SetError ("Couldn't set audio format"); + return (-1); + } + + /* Set mono or stereo audio (currently only two channels supported) */ + stereo = (spec->channels > 1); + ioctl (audio_fd, SNDCTL_DSP_STEREO, &stereo); + if (stereo) { + spec->channels = 2; + } else { + spec->channels = 1; + } + + /* Because some drivers don't allow setting the buffer size + after setting the format, we must re-open the audio device + once we know what format and channels are supported + */ + if (DMA_ReopenAudio (this, audiodev, format, stereo, spec) < 0) { + /* Error is set by DMA_ReopenAudio() */ + return (-1); + } + + /* Memory map the audio buffer */ + if (ioctl (audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0) { + SDL_SetError ("Couldn't get OSPACE parameters"); + return (-1); + } + spec->size = info.fragsize; + spec->samples = spec->size / ((spec->format & 0xFF) / 8); + spec->samples /= spec->channels; + num_buffers = info.fragstotal; + dma_len = num_buffers * spec->size; + dma_buf = (Uint8 *) mmap (NULL, dma_len, PROT_WRITE, MAP_SHARED, + audio_fd, 0); + if (dma_buf == MAP_FAILED) { + SDL_SetError ("DMA memory map failed"); + dma_buf = NULL; + return (-1); + } + SDL_memset (dma_buf, spec->silence, dma_len); + + /* Check to see if we need to use select() workaround */ + { + char *workaround; + workaround = SDL_getenv ("SDL_DSP_NOSELECT"); + if (workaround) { + frame_ticks = (float) (spec->samples * 1000) / spec->freq; + next_frame = SDL_GetTicks () + frame_ticks; + } + } + + /* Trigger audio playback */ + value = 0; + ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &value); + value = PCM_ENABLE_OUTPUT; + if (ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0) { + SDL_SetError ("Couldn't trigger audio output"); + return (-1); + } + + /* Get the parent process id (we're the parent of the audio thread) */ + parent = getpid (); + + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dma/SDL_dmaaudio.h b/src/audio/dma/SDL_dmaaudio.h index ca8c05ad7..1d851bd9f 100644 --- a/src/audio/dma/SDL_dmaaudio.h +++ b/src/audio/dma/SDL_dmaaudio.h @@ -29,23 +29,24 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - int audio_fd; - - /* The parent process id, to detect when application quits */ - pid_t parent; - - /* Raw mixing buffer */ - Uint8 *dma_buf; - int dma_len; - int num_buffers; - - /* Support for audio timing using a timer, in addition to select() */ - float frame_ticks; - float next_frame; +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + int audio_fd; + + /* The parent process id, to detect when application quits */ + pid_t parent; + + /* Raw mixing buffer */ + Uint8 *dma_buf; + int dma_len; + int num_buffers; + + /* Support for audio timing using a timer, in addition to select() */ + float frame_ticks; + float next_frame; }; -#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ +#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ /* Old variable names */ #define audio_fd (this->hidden->audio_fd) @@ -57,3 +58,4 @@ struct SDL_PrivateAudioData { #define next_frame (this->hidden->next_frame) #endif /* _SDL_dspaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dmedia/SDL_irixaudio.c b/src/audio/dmedia/SDL_irixaudio.c index 96cbaef67..3a83a4995 100644 --- a/src/audio/dmedia/SDL_irixaudio.c +++ b/src/audio/dmedia/SDL_irixaudio.c @@ -31,7 +31,7 @@ #include "SDL_irixaudio.h" -#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */ +#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */ #define OLD_IRIX_AUDIO #define alClosePort(x) ALcloseport(x) #define alFreeConfig(x) ALfreeconfig(x) @@ -45,172 +45,185 @@ #endif /* Audio driver functions */ -static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void AL_WaitAudio(_THIS); -static void AL_PlayAudio(_THIS); -static Uint8 *AL_GetAudioBuf(_THIS); -static void AL_CloseAudio(_THIS); +static int AL_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void AL_WaitAudio (_THIS); +static void AL_PlayAudio (_THIS); +static Uint8 *AL_GetAudioBuf (_THIS); +static void AL_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - return 1; + return 1; } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = AL_OpenAudio; - this->WaitAudio = AL_WaitAudio; - this->PlayAudio = AL_PlayAudio; - this->GetAudioBuf = AL_GetAudioBuf; - this->CloseAudio = AL_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = AL_OpenAudio; + this->WaitAudio = AL_WaitAudio; + this->PlayAudio = AL_PlayAudio; + this->GetAudioBuf = AL_GetAudioBuf; + this->CloseAudio = AL_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap DMEDIA_bootstrap = { - "AL", "IRIX DMedia audio", - Audio_Available, Audio_CreateDevice + "AL", "IRIX DMedia audio", + Audio_Available, Audio_CreateDevice }; -void static AL_WaitAudio(_THIS) +void static +AL_WaitAudio (_THIS) { - Sint32 timeleft; + Sint32 timeleft; - timeleft = this->spec.samples - alGetFillable(audio_port); - if ( timeleft > 0 ) { - timeleft /= (this->spec.freq/1000); - SDL_Delay((Uint32)timeleft); - } + timeleft = this->spec.samples - alGetFillable (audio_port); + if (timeleft > 0) { + timeleft /= (this->spec.freq / 1000); + SDL_Delay ((Uint32) timeleft); + } } -static void AL_PlayAudio(_THIS) +static void +AL_PlayAudio (_THIS) { - /* Write the audio data out */ - if ( alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0 ) { - /* Assume fatal error, for now */ - this->enabled = 0; - } + /* Write the audio data out */ + if (alWriteFrames (audio_port, mixbuf, this->spec.samples) < 0) { + /* Assume fatal error, for now */ + this->enabled = 0; + } } -static Uint8 *AL_GetAudioBuf(_THIS) +static Uint8 * +AL_GetAudioBuf (_THIS) { - return(mixbuf); + return (mixbuf); } -static void AL_CloseAudio(_THIS) +static void +AL_CloseAudio (_THIS) { - if ( mixbuf != NULL ) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if ( audio_port != NULL ) { - alClosePort(audio_port); - audio_port = NULL; - } + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; + } + if (audio_port != NULL) { + alClosePort (audio_port); + audio_port = NULL; + } } -static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +AL_OpenAudio (_THIS, SDL_AudioSpec * spec) { - ALconfig audio_config; + ALconfig audio_config; #ifdef OLD_IRIX_AUDIO - long audio_param[2]; + long audio_param[2]; #else - ALpv audio_param; + ALpv audio_param; #endif - int width; - - /* Determine the audio parameters from the AudioSpec */ - switch ( spec->format & 0xFF ) { - - case 8: { /* Signed 8 bit audio data */ - spec->format = AUDIO_S8; - width = AL_SAMPLE_8; - } - break; - - case 16: { /* Signed 16 bit audio data */ - spec->format = AUDIO_S16MSB; - width = AL_SAMPLE_16; - } - break; - - default: { - SDL_SetError("Unsupported audio format"); - return(-1); - } - } - - /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); - - /* Set output frequency */ + int width; + + /* Determine the audio parameters from the AudioSpec */ + switch (spec->format & 0xFF) { + + case 8: + { /* Signed 8 bit audio data */ + spec->format = AUDIO_S8; + width = AL_SAMPLE_8; + } + break; + + case 16: + { /* Signed 16 bit audio data */ + spec->format = AUDIO_S16MSB; + width = AL_SAMPLE_16; + } + break; + + default: + { + SDL_SetError ("Unsupported audio format"); + return (-1); + } + } + + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec (spec); + + /* Set output frequency */ #ifdef OLD_IRIX_AUDIO - audio_param[0] = AL_OUTPUT_RATE; - audio_param[1] = spec->freq; - if( ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0 ) { + audio_param[0] = AL_OUTPUT_RATE; + audio_param[1] = spec->freq; + if (ALsetparams (AL_DEFAULT_DEVICE, audio_param, 2) < 0) { #else - audio_param.param = AL_RATE; - audio_param.value.i = spec->freq; - if( alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0 ) { + audio_param.param = AL_RATE; + audio_param.value.i = spec->freq; + if (alSetParams (AL_DEFAULT_OUTPUT, &audio_param, 1) < 0) { #endif - SDL_SetError("alSetParams failed"); - return(-1); - } - - /* Open the audio port with the requested frequency */ - audio_port = NULL; - audio_config = alNewConfig(); - if ( audio_config && - (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && - (alSetWidth(audio_config, width) >= 0) && - (alSetQueueSize(audio_config, spec->samples*2) >= 0) && - (alSetChannels(audio_config, spec->channels) >= 0) ) { - audio_port = alOpenPort("SDL audio", "w", audio_config); - } - alFreeConfig(audio_config); - if( audio_port == NULL ) { - SDL_SetError("Unable to open audio port"); - return(-1); - } - - /* Allocate mixing buffer */ - mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size); - if ( mixbuf == NULL ) { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(mixbuf, spec->silence, spec->size); - - /* We're ready to rock and roll. :-) */ - return(0); + SDL_SetError ("alSetParams failed"); + return (-1); + } + + /* Open the audio port with the requested frequency */ + audio_port = NULL; + audio_config = alNewConfig (); + if (audio_config && + (alSetSampFmt (audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && + (alSetWidth (audio_config, width) >= 0) && + (alSetQueueSize (audio_config, spec->samples * 2) >= 0) && + (alSetChannels (audio_config, spec->channels) >= 0)) { + audio_port = alOpenPort ("SDL audio", "w", audio_config); + } + alFreeConfig (audio_config); + if (audio_port == NULL) { + SDL_SetError ("Unable to open audio port"); + return (-1); + } + + /* Allocate mixing buffer */ + mixbuf = (Uint8 *) SDL_AllocAudioMem (spec->size); + if (mixbuf == NULL) { + SDL_OutOfMemory (); + return (-1); + } + SDL_memset (mixbuf, spec->silence, spec->size); + + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dmedia/SDL_irixaudio.h b/src/audio/dmedia/SDL_irixaudio.h index 751de41f0..41d6b31cb 100644 --- a/src/audio/dmedia/SDL_irixaudio.h +++ b/src/audio/dmedia/SDL_irixaudio.h @@ -31,11 +31,12 @@ /* Hidden "this" pointer for the audio functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The handle for the audio device */ - ALport audio_port; +struct SDL_PrivateAudioData +{ + /* The handle for the audio device */ + ALport audio_port; - Uint8 *mixbuf; /* The app mixing buffer */ + Uint8 *mixbuf; /* The app mixing buffer */ }; /* Old variable names */ @@ -43,3 +44,4 @@ struct SDL_PrivateAudioData { #define mixbuf (this->hidden->mixbuf) #endif /* _SDL_lowaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c index 183cdd170..f5431ac7f 100644 --- a/src/audio/dsp/SDL_dspaudio.c +++ b/src/audio/dsp/SDL_dspaudio.c @@ -26,8 +26,8 @@ /* Allow access to a raw mixing buffer */ -#include /* For perror() */ -#include /* For strerror() */ +#include /* For perror() */ +#include /* For strerror() */ #include #include #include @@ -58,274 +58,284 @@ #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) /* Audio driver functions */ -static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DSP_WaitAudio(_THIS); -static void DSP_PlayAudio(_THIS); -static Uint8 *DSP_GetAudioBuf(_THIS); -static void DSP_CloseAudio(_THIS); +static int DSP_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DSP_WaitAudio (_THIS); +static void DSP_PlayAudio (_THIS); +static Uint8 *DSP_GetAudioBuf (_THIS); +static void DSP_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - int fd; - int available; - - available = 0; - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0); - if ( fd >= 0 ) { - available = 1; - close(fd); - } - return(available); + int fd; + int available; + + available = 0; + fd = SDL_OpenAudioPath (NULL, 0, OPEN_FLAGS, 0); + if (fd >= 0) { + available = 1; + close (fd); + } + return (available); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = DSP_OpenAudio; - this->WaitAudio = DSP_WaitAudio; - this->PlayAudio = DSP_PlayAudio; - this->GetAudioBuf = DSP_GetAudioBuf; - this->CloseAudio = DSP_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + audio_fd = -1; + + /* Set the function pointers */ + this->OpenAudio = DSP_OpenAudio; + this->WaitAudio = DSP_WaitAudio; + this->PlayAudio = DSP_PlayAudio; + this->GetAudioBuf = DSP_GetAudioBuf; + this->CloseAudio = DSP_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap DSP_bootstrap = { - DSP_DRIVER_NAME, "OSS /dev/dsp standard audio", - Audio_Available, Audio_CreateDevice + DSP_DRIVER_NAME, "OSS /dev/dsp standard audio", + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void DSP_WaitAudio(_THIS) +static void +DSP_WaitAudio (_THIS) { - /* Not needed at all since OSS handles waiting automagically */ + /* Not needed at all since OSS handles waiting automagically */ } -static void DSP_PlayAudio(_THIS) +static void +DSP_PlayAudio (_THIS) { - if (write(audio_fd, mixbuf, mixlen)==-1) - { - perror("Audio write"); - this->enabled = 0; - } - + if (write (audio_fd, mixbuf, mixlen) == -1) { + perror ("Audio write"); + this->enabled = 0; + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Wrote %d bytes of audio data\n", mixlen); + fprintf (stderr, "Wrote %d bytes of audio data\n", mixlen); #endif } -static Uint8 *DSP_GetAudioBuf(_THIS) +static Uint8 * +DSP_GetAudioBuf (_THIS) { - return(mixbuf); + return (mixbuf); } -static void DSP_CloseAudio(_THIS) +static void +DSP_CloseAudio (_THIS) { - if ( mixbuf != NULL ) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if ( audio_fd >= 0 ) { - close(audio_fd); - audio_fd = -1; - } + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; + } + if (audio_fd >= 0) { + close (audio_fd); + audio_fd = -1; + } } -static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +DSP_OpenAudio (_THIS, SDL_AudioSpec * spec) { - char audiodev[1024]; - int format; - int value; - int frag_spec; - Uint16 test_format; - - /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0); - if ( audio_fd < 0 ) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return(-1); - } - mixbuf = NULL; - - /* Make the file descriptor use blocking writes with fcntl() */ - { long flags; - flags = fcntl(audio_fd, F_GETFL); - flags &= ~O_NONBLOCK; - if ( fcntl(audio_fd, F_SETFL, flags) < 0 ) { - SDL_SetError("Couldn't set audio blocking mode"); - DSP_CloseAudio(this); - return(-1); - } - } - - /* Get a list of supported hardware formats */ - if ( ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0 ) { - perror("SNDCTL_DSP_GETFMTS"); - SDL_SetError("Couldn't get audio format list"); - DSP_CloseAudio(this); - return(-1); - } - - /* Try for a closest match on audio format */ - format = 0; - for ( test_format = SDL_FirstAudioFormat(spec->format); - ! format && test_format; ) { + char audiodev[1024]; + int format; + int value; + int frag_spec; + Uint16 test_format; + + /* Open the audio device */ + audio_fd = SDL_OpenAudioPath (audiodev, sizeof (audiodev), OPEN_FLAGS, 0); + if (audio_fd < 0) { + SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); + return (-1); + } + mixbuf = NULL; + + /* Make the file descriptor use blocking writes with fcntl() */ + { + long flags; + flags = fcntl (audio_fd, F_GETFL); + flags &= ~O_NONBLOCK; + if (fcntl (audio_fd, F_SETFL, flags) < 0) { + SDL_SetError ("Couldn't set audio blocking mode"); + DSP_CloseAudio (this); + return (-1); + } + } + + /* Get a list of supported hardware formats */ + if (ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) { + perror ("SNDCTL_DSP_GETFMTS"); + SDL_SetError ("Couldn't get audio format list"); + DSP_CloseAudio (this); + return (-1); + } + + /* Try for a closest match on audio format */ + format = 0; + for (test_format = SDL_FirstAudioFormat (spec->format); + !format && test_format;) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Trying format 0x%4.4x\n", test_format); + fprintf (stderr, "Trying format 0x%4.4x\n", test_format); #endif - switch ( test_format ) { - case AUDIO_U8: - if ( value & AFMT_U8 ) { - format = AFMT_U8; - } - break; - case AUDIO_S16LSB: - if ( value & AFMT_S16_LE ) { - format = AFMT_S16_LE; - } - break; - case AUDIO_S16MSB: - if ( value & AFMT_S16_BE ) { - format = AFMT_S16_BE; - } - break; + switch (test_format) { + case AUDIO_U8: + if (value & AFMT_U8) { + format = AFMT_U8; + } + break; + case AUDIO_S16LSB: + if (value & AFMT_S16_LE) { + format = AFMT_S16_LE; + } + break; + case AUDIO_S16MSB: + if (value & AFMT_S16_BE) { + format = AFMT_S16_BE; + } + break; #if 0 /* * These formats are not used by any real life systems so they are not * needed here. */ - case AUDIO_S8: - if ( value & AFMT_S8 ) { - format = AFMT_S8; - } - break; - case AUDIO_U16LSB: - if ( value & AFMT_U16_LE ) { - format = AFMT_U16_LE; - } - break; - case AUDIO_U16MSB: - if ( value & AFMT_U16_BE ) { - format = AFMT_U16_BE; - } - break; + case AUDIO_S8: + if (value & AFMT_S8) { + format = AFMT_S8; + } + break; + case AUDIO_U16LSB: + if (value & AFMT_U16_LE) { + format = AFMT_U16_LE; + } + break; + case AUDIO_U16MSB: + if (value & AFMT_U16_BE) { + format = AFMT_U16_BE; + } + break; #endif - default: - format = 0; - break; - } - if ( ! format ) { - test_format = SDL_NextAudioFormat(); - } - } - if ( format == 0 ) { - SDL_SetError("Couldn't find any hardware audio formats"); - DSP_CloseAudio(this); - return(-1); - } - spec->format = test_format; - - /* Set the audio format */ - value = format; - if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || - (value != format) ) { - perror("SNDCTL_DSP_SETFMT"); - SDL_SetError("Couldn't set audio format"); - DSP_CloseAudio(this); - return(-1); - } - - /* Set the number of channels of output */ - value = spec->channels; - if ( ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0 ) { - perror("SNDCTL_DSP_CHANNELS"); - SDL_SetError("Cannot set the number of channels"); - DSP_CloseAudio(this); - return(-1); - } - spec->channels = value; - - /* Set the DSP frequency */ - value = spec->freq; - if ( ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0 ) { - perror("SNDCTL_DSP_SPEED"); - SDL_SetError("Couldn't set audio frequency"); - DSP_CloseAudio(this); - return(-1); - } - spec->freq = value; - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - - /* Determine the power of two of the fragment size */ - for ( frag_spec = 0; (0x01U<size; ++frag_spec ); - if ( (0x01U<size ) { - SDL_SetError("Fragment size must be a power of two"); - DSP_CloseAudio(this); - return(-1); - } - frag_spec |= 0x00020000; /* two fragments, for low latency */ - - /* Set the audio buffering parameters */ + default: + format = 0; + break; + } + if (!format) { + test_format = SDL_NextAudioFormat (); + } + } + if (format == 0) { + SDL_SetError ("Couldn't find any hardware audio formats"); + DSP_CloseAudio (this); + return (-1); + } + spec->format = test_format; + + /* Set the audio format */ + value = format; + if ((ioctl (audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || + (value != format)) { + perror ("SNDCTL_DSP_SETFMT"); + SDL_SetError ("Couldn't set audio format"); + DSP_CloseAudio (this); + return (-1); + } + + /* Set the number of channels of output */ + value = spec->channels; + if (ioctl (audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) { + perror ("SNDCTL_DSP_CHANNELS"); + SDL_SetError ("Cannot set the number of channels"); + DSP_CloseAudio (this); + return (-1); + } + spec->channels = value; + + /* Set the DSP frequency */ + value = spec->freq; + if (ioctl (audio_fd, SNDCTL_DSP_SPEED, &value) < 0) { + perror ("SNDCTL_DSP_SPEED"); + SDL_SetError ("Couldn't set audio frequency"); + DSP_CloseAudio (this); + return (-1); + } + spec->freq = value; + + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + + /* Determine the power of two of the fragment size */ + for (frag_spec = 0; (0x01U << frag_spec) < spec->size; ++frag_spec); + if ((0x01U << frag_spec) != spec->size) { + SDL_SetError ("Fragment size must be a power of two"); + DSP_CloseAudio (this); + return (-1); + } + frag_spec |= 0x00020000; /* two fragments, for low latency */ + + /* Set the audio buffering parameters */ #ifdef DEBUG_AUDIO - fprintf(stderr, "Requesting %d fragments of size %d\n", - (frag_spec >> 16), 1<<(frag_spec&0xFFFF)); + fprintf (stderr, "Requesting %d fragments of size %d\n", + (frag_spec >> 16), 1 << (frag_spec & 0xFFFF)); #endif - if ( ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0 ) { - perror("SNDCTL_DSP_SETFRAGMENT"); - } + if (ioctl (audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) { + perror ("SNDCTL_DSP_SETFRAGMENT"); + } #ifdef DEBUG_AUDIO - { audio_buf_info info; - ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info); - fprintf(stderr, "fragments = %d\n", info.fragments); - fprintf(stderr, "fragstotal = %d\n", info.fragstotal); - fprintf(stderr, "fragsize = %d\n", info.fragsize); - fprintf(stderr, "bytes = %d\n", info.bytes); - } + { + audio_buf_info info; + ioctl (audio_fd, SNDCTL_DSP_GETOSPACE, &info); + fprintf (stderr, "fragments = %d\n", info.fragments); + fprintf (stderr, "fragstotal = %d\n", info.fragstotal); + fprintf (stderr, "fragsize = %d\n", info.fragsize); + fprintf (stderr, "bytes = %d\n", info.bytes); + } #endif - /* Allocate mixing buffer */ - mixlen = spec->size; - mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); - if ( mixbuf == NULL ) { - DSP_CloseAudio(this); - return(-1); - } - SDL_memset(mixbuf, spec->silence, spec->size); + /* Allocate mixing buffer */ + mixlen = spec->size; + mixbuf = (Uint8 *) SDL_AllocAudioMem (mixlen); + if (mixbuf == NULL) { + DSP_CloseAudio (this); + return (-1); + } + SDL_memset (mixbuf, spec->silence, spec->size); - /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); + /* Get the parent process id (we're the parent of the audio thread) */ + parent = getpid (); - /* We're ready to rock and roll. :-) */ - return(0); + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dsp/SDL_dspaudio.h b/src/audio/dsp/SDL_dspaudio.h index 0bf803fc8..3f1af967b 100644 --- a/src/audio/dsp/SDL_dspaudio.h +++ b/src/audio/dsp/SDL_dspaudio.h @@ -29,18 +29,19 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - int audio_fd; +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + int audio_fd; - /* The parent process id, to detect when application quits */ - pid_t parent; + /* The parent process id, to detect when application quits */ + pid_t parent; - /* Raw mixing buffer */ - Uint8 *mixbuf; - int mixlen; + /* Raw mixing buffer */ + Uint8 *mixbuf; + int mixlen; }; -#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ +#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ /* Old variable names */ #define audio_fd (this->hidden->audio_fd) @@ -51,3 +52,4 @@ struct SDL_PrivateAudioData { #define next_frame (this->hidden->next_frame) #endif /* _SDL_dspaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dummy/SDL_dummyaudio.c b/src/audio/dummy/SDL_dummyaudio.c index 6e9a3f06e..84d15490d 100644 --- a/src/audio/dummy/SDL_dummyaudio.c +++ b/src/audio/dummy/SDL_dummyaudio.c @@ -37,120 +37,129 @@ #define DUMMYAUD_DRIVER_NAME "dummy" /* Audio driver functions */ -static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DUMMYAUD_WaitAudio(_THIS); -static void DUMMYAUD_PlayAudio(_THIS); -static Uint8 *DUMMYAUD_GetAudioBuf(_THIS); -static void DUMMYAUD_CloseAudio(_THIS); +static int DUMMYAUD_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DUMMYAUD_WaitAudio (_THIS); +static void DUMMYAUD_PlayAudio (_THIS); +static Uint8 *DUMMYAUD_GetAudioBuf (_THIS); +static void DUMMYAUD_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int DUMMYAUD_Available(void) +static int +DUMMYAUD_Available (void) { - const char *envr = SDL_getenv("SDL_AUDIODRIVER"); - if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) { - return(1); - } - return(0); + const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); + if (envr && (SDL_strcmp (envr, DUMMYAUD_DRIVER_NAME) == 0)) { + return (1); + } + return (0); } -static void DUMMYAUD_DeleteDevice(SDL_AudioDevice *device) +static void +DUMMYAUD_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex) +static SDL_AudioDevice * +DUMMYAUD_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = DUMMYAUD_OpenAudio; - this->WaitAudio = DUMMYAUD_WaitAudio; - this->PlayAudio = DUMMYAUD_PlayAudio; - this->GetAudioBuf = DUMMYAUD_GetAudioBuf; - this->CloseAudio = DUMMYAUD_CloseAudio; - - this->free = DUMMYAUD_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = DUMMYAUD_OpenAudio; + this->WaitAudio = DUMMYAUD_WaitAudio; + this->PlayAudio = DUMMYAUD_PlayAudio; + this->GetAudioBuf = DUMMYAUD_GetAudioBuf; + this->CloseAudio = DUMMYAUD_CloseAudio; + + this->free = DUMMYAUD_DeleteDevice; + + return this; } AudioBootStrap DUMMYAUD_bootstrap = { - DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver", - DUMMYAUD_Available, DUMMYAUD_CreateDevice + DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver", + DUMMYAUD_Available, DUMMYAUD_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void DUMMYAUD_WaitAudio(_THIS) +static void +DUMMYAUD_WaitAudio (_THIS) { - /* Don't block on first calls to simulate initial fragment filling. */ - if (this->hidden->initial_calls) - this->hidden->initial_calls--; - else - SDL_Delay(this->hidden->write_delay); + /* Don't block on first calls to simulate initial fragment filling. */ + if (this->hidden->initial_calls) + this->hidden->initial_calls--; + else + SDL_Delay (this->hidden->write_delay); } -static void DUMMYAUD_PlayAudio(_THIS) +static void +DUMMYAUD_PlayAudio (_THIS) { - /* no-op...this is a null driver. */ + /* no-op...this is a null driver. */ } -static Uint8 *DUMMYAUD_GetAudioBuf(_THIS) +static Uint8 * +DUMMYAUD_GetAudioBuf (_THIS) { - return(this->hidden->mixbuf); + return (this->hidden->mixbuf); } -static void DUMMYAUD_CloseAudio(_THIS) +static void +DUMMYAUD_CloseAudio (_THIS) { - if ( this->hidden->mixbuf != NULL ) { - SDL_FreeAudioMem(this->hidden->mixbuf); - this->hidden->mixbuf = NULL; - } + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem (this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } } -static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +DUMMYAUD_OpenAudio (_THIS, SDL_AudioSpec * spec) { - float bytes_per_sec = 0.0f; - - /* Allocate mixing buffer */ - this->hidden->mixlen = spec->size; - this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); - if ( this->hidden->mixbuf == NULL ) { - return(-1); - } - SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); - - bytes_per_sec = (float) (((spec->format & 0xFF) / 8) * - spec->channels * spec->freq); - - /* - * We try to make this request more audio at the correct rate for - * a given audio spec, so timing stays fairly faithful. - * Also, we have it not block at all for the first two calls, so - * it seems like we're filling two audio fragments right out of the - * gate, like other SDL drivers tend to do. - */ - this->hidden->initial_calls = 2; - this->hidden->write_delay = - (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f); - - /* We're ready to rock and roll. :-) */ - return(0); + float bytes_per_sec = 0.0f; + + /* Allocate mixing buffer */ + this->hidden->mixlen = spec->size; + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen); + if (this->hidden->mixbuf == NULL) { + return (-1); + } + SDL_memset (this->hidden->mixbuf, spec->silence, spec->size); + + bytes_per_sec = (float) (((spec->format & 0xFF) / 8) * + spec->channels * spec->freq); + + /* + * We try to make this request more audio at the correct rate for + * a given audio spec, so timing stays fairly faithful. + * Also, we have it not block at all for the first two calls, so + * it seems like we're filling two audio fragments right out of the + * gate, like other SDL drivers tend to do. + */ + this->hidden->initial_calls = 2; + this->hidden->write_delay = + (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f); + + /* We're ready to rock and roll. :-) */ + return (0); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/dummy/SDL_dummyaudio.h b/src/audio/dummy/SDL_dummyaudio.h index ff16cc7d9..58adcf802 100644 --- a/src/audio/dummy/SDL_dummyaudio.h +++ b/src/audio/dummy/SDL_dummyaudio.h @@ -29,12 +29,14 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - Uint8 *mixbuf; - Uint32 mixlen; - Uint32 write_delay; - Uint32 initial_calls; +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + Uint8 *mixbuf; + Uint32 mixlen; + Uint32 write_delay; + Uint32 initial_calls; }; #endif /* _SDL_dummyaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/esd/SDL_esdaudio.c b/src/audio/esd/SDL_esdaudio.c index d35e89aa4..d69a96c7f 100644 --- a/src/audio/esd/SDL_esdaudio.c +++ b/src/audio/esd/SDL_esdaudio.c @@ -47,11 +47,11 @@ #define ESD_DRIVER_NAME "esd" /* Audio driver functions */ -static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void ESD_WaitAudio(_THIS); -static void ESD_PlayAudio(_THIS); -static Uint8 *ESD_GetAudioBuf(_THIS); -static void ESD_CloseAudio(_THIS); +static int ESD_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void ESD_WaitAudio (_THIS); +static void ESD_PlayAudio (_THIS); +static Uint8 *ESD_GetAudioBuf (_THIS); +static void ESD_CloseAudio (_THIS); #ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC @@ -59,265 +59,286 @@ static const char *esd_library = SDL_AUDIO_DRIVER_ESD_DYNAMIC; static void *esd_handle = NULL; static int esd_loaded = 0; -static int (*SDL_NAME(esd_open_sound))( const char *host ); -static int (*SDL_NAME(esd_close))( int esd ); -static int (*SDL_NAME(esd_play_stream))( esd_format_t format, int rate, - const char *host, const char *name ); -static struct { - const char *name; - void **func; +static int (*SDL_NAME (esd_open_sound)) (const char *host); +static int (*SDL_NAME (esd_close)) (int esd); +static int (*SDL_NAME (esd_play_stream)) (esd_format_t format, int rate, + const char *host, const char *name); +static struct +{ + const char *name; + void **func; } esd_functions[] = { - { "esd_open_sound", (void **)&SDL_NAME(esd_open_sound) }, - { "esd_close", (void **)&SDL_NAME(esd_close) }, - { "esd_play_stream", (void **)&SDL_NAME(esd_play_stream) }, -}; + { + "esd_open_sound", (void **) &SDL_NAME (esd_open_sound)}, { + "esd_close", (void **) &SDL_NAME (esd_close)}, { +"esd_play_stream", (void **) &SDL_NAME (esd_play_stream)},}; -static void UnloadESDLibrary() +static void +UnloadESDLibrary () { - if ( esd_loaded ) { - SDL_UnloadObject(esd_handle); - esd_handle = NULL; - esd_loaded = 0; - } + if (esd_loaded) { + SDL_UnloadObject (esd_handle); + esd_handle = NULL; + esd_loaded = 0; + } } -static int LoadESDLibrary(void) +static int +LoadESDLibrary (void) { - int i, retval = -1; - - esd_handle = SDL_LoadObject(esd_library); - if ( esd_handle ) { - esd_loaded = 1; - retval = 0; - for ( i=0; i= 0 ) { - available = 1; - SDL_NAME(esd_close)(connection); - } - UnloadESDLibrary(); - return(available); + int connection; + int available; + + available = 0; + if (LoadESDLibrary () < 0) { + return available; + } + connection = SDL_NAME (esd_open_sound) (NULL); + if (connection >= 0) { + available = 1; + SDL_NAME (esd_close) (connection); + } + UnloadESDLibrary (); + return (available); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); - UnloadESDLibrary(); + SDL_free (device->hidden); + SDL_free (device); + UnloadESDLibrary (); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - LoadESDLibrary(); - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = ESD_OpenAudio; - this->WaitAudio = ESD_WaitAudio; - this->PlayAudio = ESD_PlayAudio; - this->GetAudioBuf = ESD_GetAudioBuf; - this->CloseAudio = ESD_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + LoadESDLibrary (); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + audio_fd = -1; + + /* Set the function pointers */ + this->OpenAudio = ESD_OpenAudio; + this->WaitAudio = ESD_WaitAudio; + this->PlayAudio = ESD_PlayAudio; + this->GetAudioBuf = ESD_GetAudioBuf; + this->CloseAudio = ESD_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap ESD_bootstrap = { - ESD_DRIVER_NAME, "Enlightened Sound Daemon", - Audio_Available, Audio_CreateDevice + ESD_DRIVER_NAME, "Enlightened Sound Daemon", + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void ESD_WaitAudio(_THIS) +static void +ESD_WaitAudio (_THIS) { - Sint32 ticks; - - /* Check to see if the thread-parent process is still alive */ - { static int cnt = 0; - /* Note that this only works with thread implementations - that use a different process id for each thread. - */ - if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ - if ( kill(parent, 0) < 0 ) { - this->enabled = 0; - } - } - } - - /* Use timer for general audio synchronization */ - ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; - if ( ticks > 0 ) { - SDL_Delay(ticks); - } + Sint32 ticks; + + /* Check to see if the thread-parent process is still alive */ + { + static int cnt = 0; + /* Note that this only works with thread implementations + that use a different process id for each thread. + */ + if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */ + if (kill (parent, 0) < 0) { + this->enabled = 0; + } + } + } + + /* Use timer for general audio synchronization */ + ticks = ((Sint32) (next_frame - SDL_GetTicks ())) - FUDGE_TICKS; + if (ticks > 0) { + SDL_Delay (ticks); + } } -static void ESD_PlayAudio(_THIS) +static void +ESD_PlayAudio (_THIS) { - int written; - - /* Write the audio data, checking for EAGAIN on broken audio drivers */ - do { - written = write(audio_fd, mixbuf, mixlen); - if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) { - SDL_Delay(1); /* Let a little CPU time go by */ - } - } while ( (written < 0) && - ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) ); - - /* Set the next write frame */ - next_frame += frame_ticks; - - /* If we couldn't write, assume fatal error for now */ - if ( written < 0 ) { - this->enabled = 0; - } + int written; + + /* Write the audio data, checking for EAGAIN on broken audio drivers */ + do { + written = write (audio_fd, mixbuf, mixlen); + if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) { + SDL_Delay (1); /* Let a little CPU time go by */ + } + } + while ((written < 0) && + ((errno == 0) || (errno == EAGAIN) || (errno == EINTR))); + + /* Set the next write frame */ + next_frame += frame_ticks; + + /* If we couldn't write, assume fatal error for now */ + if (written < 0) { + this->enabled = 0; + } } -static Uint8 *ESD_GetAudioBuf(_THIS) +static Uint8 * +ESD_GetAudioBuf (_THIS) { - return(mixbuf); + return (mixbuf); } -static void ESD_CloseAudio(_THIS) +static void +ESD_CloseAudio (_THIS) { - if ( mixbuf != NULL ) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if ( audio_fd >= 0 ) { - SDL_NAME(esd_close)(audio_fd); - audio_fd = -1; - } + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; + } + if (audio_fd >= 0) { + SDL_NAME (esd_close) (audio_fd); + audio_fd = -1; + } } /* Try to get the name of the program */ -static char *get_progname(void) +static char * +get_progname (void) { - char *progname = NULL; + char *progname = NULL; #ifdef __LINUX__ - FILE *fp; - static char temp[BUFSIZ]; - - SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid()); - fp = fopen(temp, "r"); - if ( fp != NULL ) { - if ( fgets(temp, sizeof(temp)-1, fp) ) { - progname = SDL_strrchr(temp, '/'); - if ( progname == NULL ) { - progname = temp; - } else { - progname = progname+1; - } - } - fclose(fp); - } + FILE *fp; + static char temp[BUFSIZ]; + + SDL_snprintf (temp, SDL_arraysize (temp), "/proc/%d/cmdline", getpid ()); + fp = fopen (temp, "r"); + if (fp != NULL) { + if (fgets (temp, sizeof (temp) - 1, fp)) { + progname = SDL_strrchr (temp, '/'); + if (progname == NULL) { + progname = temp; + } else { + progname = progname + 1; + } + } + fclose (fp); + } #endif - return(progname); + return (progname); } -static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +ESD_OpenAudio (_THIS, SDL_AudioSpec * spec) { - esd_format_t format; - - /* Convert audio spec to the ESD audio format */ - format = (ESD_STREAM | ESD_PLAY); - switch ( spec->format & 0xFF ) { - case 8: - format |= ESD_BITS8; - break; - case 16: - format |= ESD_BITS16; - break; - default: - SDL_SetError("Unsupported ESD audio format"); - return(-1); - } - if ( spec->channels == 1 ) { - format |= ESD_MONO; - } else { - format |= ESD_STEREO; - } + esd_format_t format; + + /* Convert audio spec to the ESD audio format */ + format = (ESD_STREAM | ESD_PLAY); + switch (spec->format & 0xFF) { + case 8: + format |= ESD_BITS8; + break; + case 16: + format |= ESD_BITS16; + break; + default: + SDL_SetError ("Unsupported ESD audio format"); + return (-1); + } + if (spec->channels == 1) { + format |= ESD_MONO; + } else { + format |= ESD_STEREO; + } #if 0 - spec->samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */ + spec->samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */ #endif - /* Open a connection to the ESD audio server */ - audio_fd = SDL_NAME(esd_play_stream)(format, spec->freq, NULL, get_progname()); - if ( audio_fd < 0 ) { - SDL_SetError("Couldn't open ESD connection"); - return(-1); - } - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - frame_ticks = (float)(spec->samples*1000)/spec->freq; - next_frame = SDL_GetTicks()+frame_ticks; - - /* Allocate mixing buffer */ - mixlen = spec->size; - mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); - if ( mixbuf == NULL ) { - return(-1); - } - SDL_memset(mixbuf, spec->silence, spec->size); - - /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); - - /* We're ready to rock and roll. :-) */ - return(0); + /* Open a connection to the ESD audio server */ + audio_fd = + SDL_NAME (esd_play_stream) (format, spec->freq, NULL, + get_progname ()); + if (audio_fd < 0) { + SDL_SetError ("Couldn't open ESD connection"); + return (-1); + } + + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + frame_ticks = (float) (spec->samples * 1000) / spec->freq; + next_frame = SDL_GetTicks () + frame_ticks; + + /* Allocate mixing buffer */ + mixlen = spec->size; + mixbuf = (Uint8 *) SDL_AllocAudioMem (mixlen); + if (mixbuf == NULL) { + return (-1); + } + SDL_memset (mixbuf, spec->silence, spec->size); + + /* Get the parent process id (we're the parent of the audio thread) */ + parent = getpid (); + + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/esd/SDL_esdaudio.h b/src/audio/esd/SDL_esdaudio.h index cffb2768a..b3abeca7d 100644 --- a/src/audio/esd/SDL_esdaudio.h +++ b/src/audio/esd/SDL_esdaudio.h @@ -29,22 +29,23 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - int audio_fd; +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + int audio_fd; - /* The parent process id, to detect when application quits */ - pid_t parent; + /* The parent process id, to detect when application quits */ + pid_t parent; - /* Raw mixing buffer */ - Uint8 *mixbuf; - int mixlen; + /* Raw mixing buffer */ + Uint8 *mixbuf; + int mixlen; - /* Support for audio timing using a timer */ - float frame_ticks; - float next_frame; + /* Support for audio timing using a timer */ + float frame_ticks; + float next_frame; }; -#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ +#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ /* Old variable names */ #define audio_fd (this->hidden->audio_fd) @@ -55,3 +56,4 @@ struct SDL_PrivateAudioData { #define next_frame (this->hidden->next_frame) #endif /* _SDL_esdaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/macosx/SDL_coreaudio.c b/src/audio/macosx/SDL_coreaudio.c index 2cae95813..fb6704e6e 100644 --- a/src/audio/macosx/SDL_coreaudio.c +++ b/src/audio/macosx/SDL_coreaudio.c @@ -31,44 +31,47 @@ /* Audio driver functions */ -static int Core_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Core_WaitAudio(_THIS); -static void Core_PlayAudio(_THIS); -static Uint8 *Core_GetAudioBuf(_THIS); -static void Core_CloseAudio(_THIS); +static int Core_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Core_WaitAudio (_THIS); +static void Core_PlayAudio (_THIS); +static Uint8 *Core_GetAudioBuf (_THIS); +static void Core_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - return(1); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { SDL_AudioDevice *this; /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ this->OpenAudio = Core_OpenAudio; @@ -88,72 +91,75 @@ AudioBootStrap COREAUDIO_bootstrap = { }; /* The CoreAudio callback */ -static OSStatus audioCallback (void *inRefCon, - AudioUnitRenderActionFlags inActionFlags, - const AudioTimeStamp *inTimeStamp, - UInt32 inBusNumber, - AudioBuffer *ioData) +static OSStatus +audioCallback (void *inRefCon, + AudioUnitRenderActionFlags inActionFlags, + const AudioTimeStamp * inTimeStamp, + UInt32 inBusNumber, AudioBuffer * ioData) { - SDL_AudioDevice *this = (SDL_AudioDevice *)inRefCon; + SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon; UInt32 remaining, len; void *ptr; /* Only do anything if audio is enabled and not paused */ - if ( ! this->enabled || this->paused ) { - SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize); + if (!this->enabled || this->paused) { + SDL_memset (ioData->mData, this->spec.silence, ioData->mDataByteSize); return 0; } - + /* No SDL conversion should be needed here, ever, since we accept any input format in OpenAudio, and leave the conversion to CoreAudio. */ /* - assert(!this->convert.needed); - assert(this->spec.channels == ioData->mNumberChannels); + assert(!this->convert.needed); + assert(this->spec.channels == ioData->mNumberChannels); */ - + remaining = ioData->mDataByteSize; ptr = ioData->mData; while (remaining > 0) { if (bufferOffset >= bufferSize) { /* Generate the data */ - SDL_memset(buffer, this->spec.silence, bufferSize); - SDL_mutexP(this->mixer_lock); - (*this->spec.callback)(this->spec.userdata, - buffer, bufferSize); - SDL_mutexV(this->mixer_lock); + SDL_memset (buffer, this->spec.silence, bufferSize); + SDL_mutexP (this->mixer_lock); + (*this->spec.callback) (this->spec.userdata, buffer, bufferSize); + SDL_mutexV (this->mixer_lock); bufferOffset = 0; } - + len = bufferSize - bufferOffset; if (len > remaining) len = remaining; - SDL_memcpy(ptr, (char *)buffer + bufferOffset, len); - ptr = (char *)ptr + len; + SDL_memcpy (ptr, (char *) buffer + bufferOffset, len); + ptr = (char *) ptr + len; remaining -= len; bufferOffset += len; } - + return 0; } /* Dummy functions -- we don't use thread-based audio */ -void Core_WaitAudio(_THIS) +void +Core_WaitAudio (_THIS) { return; } -void Core_PlayAudio(_THIS) +void +Core_PlayAudio (_THIS) { return; } -Uint8 *Core_GetAudioBuf(_THIS) +Uint8 * +Core_GetAudioBuf (_THIS) { - return(NULL); + return (NULL); } -void Core_CloseAudio(_THIS) +void +Core_CloseAudio (_THIS) { OSStatus result; struct AudioUnitInputCallback callback; @@ -161,31 +167,30 @@ void Core_CloseAudio(_THIS) /* stop processing the audio unit */ result = AudioOutputUnitStop (outputAudioUnit); if (result != noErr) { - SDL_SetError("Core_CloseAudio: AudioOutputUnitStop"); + SDL_SetError ("Core_CloseAudio: AudioOutputUnitStop"); return; } /* Remove the input callback */ callback.inputProc = 0; callback.inputProcRefCon = 0; - result = AudioUnitSetProperty (outputAudioUnit, - kAudioUnitProperty_SetInputCallback, - kAudioUnitScope_Input, - 0, - &callback, - sizeof(callback)); + result = AudioUnitSetProperty (outputAudioUnit, + kAudioUnitProperty_SetInputCallback, + kAudioUnitScope_Input, + 0, &callback, sizeof (callback)); if (result != noErr) { - SDL_SetError("Core_CloseAudio: AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)"); + SDL_SetError + ("Core_CloseAudio: AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)"); return; } - result = CloseComponent(outputAudioUnit); + result = CloseComponent (outputAudioUnit); if (result != noErr) { - SDL_SetError("Core_CloseAudio: CloseComponent"); + SDL_SetError ("Core_CloseAudio: CloseComponent"); return; } - - SDL_free(buffer); + + SDL_free (buffer); } #define CHECK_RESULT(msg) \ @@ -195,7 +200,8 @@ void Core_CloseAudio(_THIS) } -int Core_OpenAudio(_THIS, SDL_AudioSpec *spec) +int +Core_OpenAudio (_THIS, SDL_AudioSpec * spec) { OSStatus result = noErr; Component comp; @@ -208,7 +214,7 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec) requestedDesc.mFormatFlags = kLinearPCMFormatFlagIsPacked; requestedDesc.mChannelsPerFrame = spec->channels; requestedDesc.mSampleRate = spec->freq; - + requestedDesc.mBitsPerChannel = spec->format & 0xFF; if (spec->format & 0x8000) requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger; @@ -216,8 +222,10 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec) requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; requestedDesc.mFramesPerPacket = 1; - requestedDesc.mBytesPerFrame = requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8; - requestedDesc.mBytesPerPacket = requestedDesc.mBytesPerFrame * requestedDesc.mFramesPerPacket; + requestedDesc.mBytesPerFrame = + requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8; + requestedDesc.mBytesPerPacket = + requestedDesc.mBytesPerFrame * requestedDesc.mFramesPerPacket; /* Locate the default output audio unit */ @@ -226,52 +234,48 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec) desc.componentManufacturer = kAudioUnitID_DefaultOutput; desc.componentFlags = 0; desc.componentFlagsMask = 0; - + comp = FindNextComponent (NULL, &desc); if (comp == NULL) { - SDL_SetError ("Failed to start CoreAudio: FindNextComponent returned NULL"); + SDL_SetError + ("Failed to start CoreAudio: FindNextComponent returned NULL"); return -1; } - + /* Open & initialize the default output audio unit */ result = OpenAComponent (comp, &outputAudioUnit); - CHECK_RESULT("OpenAComponent") - - result = AudioUnitInitialize (outputAudioUnit); - CHECK_RESULT("AudioUnitInitialize") - - /* Set the input format of the audio unit. */ - result = AudioUnitSetProperty (outputAudioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &requestedDesc, - sizeof (requestedDesc)); - CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)") - - /* Set the audio callback */ - callback.inputProc = audioCallback; + CHECK_RESULT ("OpenAComponent") + result = AudioUnitInitialize (outputAudioUnit); + CHECK_RESULT ("AudioUnitInitialize") + /* Set the input format of the audio unit. */ + result = AudioUnitSetProperty (outputAudioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &requestedDesc, + sizeof (requestedDesc)); + CHECK_RESULT ("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)") + /* Set the audio callback */ + callback.inputProc = audioCallback; callback.inputProcRefCon = this; - result = AudioUnitSetProperty (outputAudioUnit, - kAudioUnitProperty_SetInputCallback, - kAudioUnitScope_Input, - 0, - &callback, - sizeof(callback)); - CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)") - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - + result = AudioUnitSetProperty (outputAudioUnit, + kAudioUnitProperty_SetInputCallback, + kAudioUnitScope_Input, + 0, &callback, sizeof (callback)); + CHECK_RESULT + ("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)") + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + /* Allocate a sample buffer */ bufferOffset = bufferSize = this->spec.size; - buffer = SDL_malloc(bufferSize); + buffer = SDL_malloc (bufferSize); /* Finally, start processing of the audio unit */ result = AudioOutputUnitStart (outputAudioUnit); - CHECK_RESULT("AudioOutputUnitStart") - - - /* We're running! */ - return(1); + CHECK_RESULT ("AudioOutputUnitStart") + /* We're running! */ + return (1); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/macosx/SDL_coreaudio.h b/src/audio/macosx/SDL_coreaudio.h index 0902deddf..8167ace1e 100644 --- a/src/audio/macosx/SDL_coreaudio.h +++ b/src/audio/macosx/SDL_coreaudio.h @@ -29,11 +29,12 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - AudioUnit outputAudioUnit; - void *buffer; - UInt32 bufferOffset; - UInt32 bufferSize; +struct SDL_PrivateAudioData +{ + AudioUnit outputAudioUnit; + void *buffer; + UInt32 bufferOffset; + UInt32 bufferSize; }; /* Old variable names */ @@ -43,3 +44,4 @@ struct SDL_PrivateAudioData { #define bufferSize (this->hidden->bufferSize) #endif /* _SDL_coreaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/macrom/SDL_romaudio.c b/src/audio/macrom/SDL_romaudio.c index 140c0338c..bb8af0ccc 100644 --- a/src/audio/macrom/SDL_romaudio.c +++ b/src/audio/macrom/SDL_romaudio.c @@ -26,13 +26,13 @@ #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) # include #else -# include /* SoundManager interface */ +# include /* SoundManager interface */ # include # include #endif #if !defined(NewSndCallBackUPP) && (UNIVERSAL_INTERFACES_VERSION < 0x0335) -#if !defined(NewSndCallBackProc) /* avoid circular redefinition... */ +#if !defined(NewSndCallBackProc) /* avoid circular redefinition... */ #define NewSndCallBackUPP NewSndCallBackProc #endif #if !defined(NewSndCallBackUPP) @@ -47,62 +47,65 @@ /* Audio driver functions */ -static void Mac_CloseAudio(_THIS); -static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Mac_LockAudio(_THIS); -static void Mac_UnlockAudio(_THIS); +static void Mac_CloseAudio (_THIS); +static int Mac_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Mac_LockAudio (_THIS); +static void Mac_UnlockAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - return(1); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { SDL_AudioDevice *this; /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ - this->OpenAudio = Mac_OpenAudio; - this->CloseAudio = Mac_CloseAudio; - this->LockAudio = Mac_LockAudio; + this->OpenAudio = Mac_OpenAudio; + this->CloseAudio = Mac_CloseAudio; + this->LockAudio = Mac_LockAudio; this->UnlockAudio = Mac_UnlockAudio; - this->free = Audio_DeleteDevice; + this->free = Audio_DeleteDevice; -#ifdef __MACOSX__ /* Mac OS X uses threaded audio, so normal thread code is okay */ - this->LockAudio = NULL; +#ifdef __MACOSX__ /* Mac OS X uses threaded audio, so normal thread code is okay */ + this->LockAudio = NULL; this->UnlockAudio = NULL; #endif return this; } AudioBootStrap SNDMGR_bootstrap = { - "sndmgr", "MacOS SoundManager 3.0", - Audio_Available, Audio_CreateDevice + "sndmgr", "MacOS SoundManager 3.0", + Audio_Available, Audio_CreateDevice }; #if defined(TARGET_API_MAC_CARBON) || defined(USE_RYANS_SOUNDCODE) @@ -113,51 +116,56 @@ AudioBootStrap SNDMGR_bootstrap = { static volatile SInt32 audio_is_locked = 0; static volatile SInt32 need_to_mix = 0; -static UInt8 *buffer[2]; +static UInt8 *buffer[2]; static volatile UInt32 running = 0; static CmpSoundHeader header; static volatile Uint32 fill_me = 0; -static void mix_buffer(SDL_AudioDevice *audio, UInt8 *buffer) +static void +mix_buffer (SDL_AudioDevice * audio, UInt8 * buffer) { - if ( ! audio->paused ) { + if (!audio->paused) { #ifdef __MACOSX__ - SDL_mutexP(audio->mixer_lock); + SDL_mutexP (audio->mixer_lock); #endif - if ( audio->convert.needed ) { - audio->spec.callback(audio->spec.userdata, - (Uint8 *)audio->convert.buf,audio->convert.len); - SDL_ConvertAudio(&audio->convert); - if ( audio->convert.len_cvt != audio->spec.size ) { - /* Uh oh... probably crashes here */; + if (audio->convert.needed) { + audio->spec.callback (audio->spec.userdata, + (Uint8 *) audio->convert.buf, + audio->convert.len); + SDL_ConvertAudio (&audio->convert); + if (audio->convert.len_cvt != audio->spec.size) { + /* Uh oh... probably crashes here */ ; } - SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt); + SDL_memcpy (buffer, audio->convert.buf, audio->convert.len_cvt); } else { - audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size); + audio->spec.callback (audio->spec.userdata, buffer, + audio->spec.size); } #ifdef __MACOSX__ - SDL_mutexV(audio->mixer_lock); + SDL_mutexV (audio->mixer_lock); #endif } - DecrementAtomic((SInt32 *) &need_to_mix); + DecrementAtomic ((SInt32 *) & need_to_mix); } -static void Mac_LockAudio(_THIS) +static void +Mac_LockAudio (_THIS) { - IncrementAtomic((SInt32 *) &audio_is_locked); + IncrementAtomic ((SInt32 *) & audio_is_locked); } -static void Mac_UnlockAudio(_THIS) +static void +Mac_UnlockAudio (_THIS) { SInt32 oldval; - - oldval = DecrementAtomic((SInt32 *) &audio_is_locked); - if ( oldval != 1 ) /* != 1 means audio is still locked. */ + + oldval = DecrementAtomic ((SInt32 *) & audio_is_locked); + if (oldval != 1) /* != 1 means audio is still locked. */ return; /* Did we miss the chance to mix in an interrupt? Do it now. */ - if ( BitAndAtomic (0xFFFFFFFF, (UInt32 *) &need_to_mix) ) { + if (BitAndAtomic (0xFFFFFFFF, (UInt32 *) & need_to_mix)) { /* * Note that this could be a problem if you missed an interrupt * while the audio was locked, and get preempted by a second @@ -167,147 +175,154 @@ static void Mac_UnlockAudio(_THIS) } } -static void callBackProc (SndChannel *chan, SndCommand *cmd_passed ) { - UInt32 play_me; - SndCommand cmd; - SDL_AudioDevice *audio = (SDL_AudioDevice *)chan->userInfo; - - IncrementAtomic((SInt32 *) &need_to_mix); - - fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */ - play_me = ! fill_me; /* filled buffer to play _now_ */ - - if ( ! audio->enabled ) { - return; - } - - /* queue previously mixed buffer for playback. */ - header.samplePtr = (Ptr)buffer[play_me]; - cmd.cmd = bufferCmd; - cmd.param1 = 0; - cmd.param2 = (long)&header; - SndDoCommand (chan, &cmd, 0); - - memset (buffer[fill_me], 0, audio->spec.size); - - /* - * if audio device isn't locked, mix the next buffer to be queued in - * the memory block that just finished playing. - */ - if ( ! BitAndAtomic(0xFFFFFFFF, (UInt32 *) &audio_is_locked) ) { - mix_buffer (audio, buffer[fill_me]); - } - - /* set this callback to run again when current buffer drains. */ - if ( running ) { - cmd.cmd = callBackCmd; - cmd.param1 = 0; - cmd.param2 = play_me; - - SndDoCommand (chan, &cmd, 0); - } +static void +callBackProc (SndChannel * chan, SndCommand * cmd_passed) +{ + UInt32 play_me; + SndCommand cmd; + SDL_AudioDevice *audio = (SDL_AudioDevice *) chan->userInfo; + + IncrementAtomic ((SInt32 *) & need_to_mix); + + fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */ + play_me = !fill_me; /* filled buffer to play _now_ */ + + if (!audio->enabled) { + return; + } + + /* queue previously mixed buffer for playback. */ + header.samplePtr = (Ptr) buffer[play_me]; + cmd.cmd = bufferCmd; + cmd.param1 = 0; + cmd.param2 = (long) &header; + SndDoCommand (chan, &cmd, 0); + + memset (buffer[fill_me], 0, audio->spec.size); + + /* + * if audio device isn't locked, mix the next buffer to be queued in + * the memory block that just finished playing. + */ + if (!BitAndAtomic (0xFFFFFFFF, (UInt32 *) & audio_is_locked)) { + mix_buffer (audio, buffer[fill_me]); + } + + /* set this callback to run again when current buffer drains. */ + if (running) { + cmd.cmd = callBackCmd; + cmd.param1 = 0; + cmd.param2 = play_me; + + SndDoCommand (chan, &cmd, 0); + } } -static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) { +static int +Mac_OpenAudio (_THIS, SDL_AudioSpec * spec) +{ + + SndCallBackUPP callback; + int sample_bits; + int i; + long initOptions; - SndCallBackUPP callback; - int sample_bits; - int i; - long initOptions; - - /* Very few conversions are required, but... */ + /* Very few conversions are required, but... */ switch (spec->format) { - case AUDIO_S8: + case AUDIO_S8: spec->format = AUDIO_U8; break; - case AUDIO_U16LSB: + case AUDIO_U16LSB: spec->format = AUDIO_S16LSB; break; - case AUDIO_U16MSB: + case AUDIO_U16MSB: spec->format = AUDIO_S16MSB; break; } - SDL_CalculateAudioSpec(spec); - + SDL_CalculateAudioSpec (spec); + /* initialize bufferCmd header */ - memset (&header, 0, sizeof(header)); + memset (&header, 0, sizeof (header)); callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc); sample_bits = spec->size / spec->samples / spec->channels * 8; #ifdef DEBUG_AUDIO - fprintf(stderr, - "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", - spec->format, spec->channels, sample_bits, spec->freq); + fprintf (stderr, + "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", + spec->format, spec->channels, sample_bits, spec->freq); #endif /* DEBUG_AUDIO */ - + header.numChannels = spec->channels; - header.sampleSize = sample_bits; - header.sampleRate = spec->freq << 16; - header.numFrames = spec->samples; - header.encode = cmpSH; - + header.sampleSize = sample_bits; + header.sampleRate = spec->freq << 16; + header.numFrames = spec->samples; + header.encode = cmpSH; + /* Note that we install the 16bitLittleEndian Converter if needed. */ - if ( spec->format == 0x8010 ) { + if (spec->format == 0x8010) { header.compressionID = fixedCompression; header.format = k16BitLittleEndianFormat; } - + /* allocate 2 buffers */ - for (i=0; i<2; i++) { - buffer[i] = (UInt8*)malloc (sizeof(UInt8) * spec->size); - if (buffer[i] == NULL) { - SDL_OutOfMemory(); - return (-1); - } - memset (buffer[i], 0, spec->size); - } - - /* Create the sound manager channel */ - channel = (SndChannelPtr)SDL_malloc(sizeof(*channel)); - if ( channel == NULL ) { - SDL_OutOfMemory(); - return(-1); + for (i = 0; i < 2; i++) { + buffer[i] = (UInt8 *) malloc (sizeof (UInt8) * spec->size); + if (buffer[i] == NULL) { + SDL_OutOfMemory (); + return (-1); + } + memset (buffer[i], 0, spec->size); + } + + /* Create the sound manager channel */ + channel = (SndChannelPtr) SDL_malloc (sizeof (*channel)); + if (channel == NULL) { + SDL_OutOfMemory (); + return (-1); } - if ( spec->channels >= 2 ) { + if (spec->channels >= 2) { initOptions = initStereo; } else { initOptions = initMono; } - channel->userInfo = (long)this; + channel->userInfo = (long) this; channel->qLength = 128; - if ( SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr ) { - SDL_SetError("Unable to create audio channel"); - SDL_free(channel); + if (SndNewChannel (&channel, sampledSynth, initOptions, callback) != + noErr) { + SDL_SetError ("Unable to create audio channel"); + SDL_free (channel); channel = NULL; - return(-1); + return (-1); } - - /* start playback */ - { - SndCommand cmd; - cmd.cmd = callBackCmd; - cmd.param2 = 0; - running = 1; - SndDoCommand (channel, &cmd, 0); - } - - return 1; + + /* start playback */ + { + SndCommand cmd; + cmd.cmd = callBackCmd; + cmd.param2 = 0; + running = 1; + SndDoCommand (channel, &cmd, 0); + } + + return 1; } -static void Mac_CloseAudio(_THIS) { - - int i; - - running = 0; - - if (channel) { - SndDisposeChannel (channel, true); - channel = NULL; - } - - for ( i=0; i<2; ++i ) { - if ( buffer[i] ) { - SDL_free(buffer[i]); +static void +Mac_CloseAudio (_THIS) +{ + + int i; + + running = 0; + + if (channel) { + SndDisposeChannel (channel, true); + channel = NULL; + } + + for (i = 0; i < 2; ++i) { + if (buffer[i]) { + SDL_free (buffer[i]); buffer[i] = NULL; } } @@ -315,12 +330,14 @@ static void Mac_CloseAudio(_THIS) { #else /* !TARGET_API_MAC_CARBON && !USE_RYANS_SOUNDCODE */ -static void Mac_LockAudio(_THIS) +static void +Mac_LockAudio (_THIS) { /* no-op. */ } -static void Mac_UnlockAudio(_THIS) +static void +Mac_UnlockAudio (_THIS) { /* no-op. */ } @@ -330,79 +347,84 @@ static void Mac_UnlockAudio(_THIS) the buffers, so we'll zero it to silence and fill it with audio if we're not paused. */ -static pascal -void sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf) +static pascal void +sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf) { - SDL_AudioDevice *audio = (SDL_AudioDevice *)newbuf->dbUserInfo[0]; + SDL_AudioDevice *audio = (SDL_AudioDevice *) newbuf->dbUserInfo[0]; /* If audio is quitting, don't do anything */ - if ( ! audio->enabled ) { + if (!audio->enabled) { return; } memset (newbuf->dbSoundData, 0, audio->spec.size); newbuf->dbNumFrames = audio->spec.samples; - if ( ! audio->paused ) { - if ( audio->convert.needed ) { - audio->spec.callback(audio->spec.userdata, - (Uint8 *)audio->convert.buf,audio->convert.len); - SDL_ConvertAudio(&audio->convert); + if (!audio->paused) { + if (audio->convert.needed) { + audio->spec.callback (audio->spec.userdata, + (Uint8 *) audio->convert.buf, + audio->convert.len); + SDL_ConvertAudio (&audio->convert); #if 0 - if ( audio->convert.len_cvt != audio->spec.size ) { - /* Uh oh... probably crashes here */; + if (audio->convert.len_cvt != audio->spec.size) { + /* Uh oh... probably crashes here */ ; } #endif - SDL_memcpy(newbuf->dbSoundData, audio->convert.buf, - audio->convert.len_cvt); + SDL_memcpy (newbuf->dbSoundData, audio->convert.buf, + audio->convert.len_cvt); } else { - audio->spec.callback(audio->spec.userdata, - (Uint8 *)newbuf->dbSoundData, audio->spec.size); + audio->spec.callback (audio->spec.userdata, + (Uint8 *) newbuf->dbSoundData, + audio->spec.size); } } - newbuf->dbFlags |= dbBufferReady; + newbuf->dbFlags |= dbBufferReady; } -static int DoubleBufferAudio_Available(void) +static int +DoubleBufferAudio_Available (void) { int available; NumVersion sndversion; long response; available = 0; - sndversion = SndSoundManagerVersion(); - if ( sndversion.majorRev >= 3 ) { - if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { - if ( (response & (1 << gestaltSndPlayDoubleBuffer)) ) { + sndversion = SndSoundManagerVersion (); + if (sndversion.majorRev >= 3) { + if (Gestalt (gestaltSoundAttr, &response) == noErr) { + if ((response & (1 << gestaltSndPlayDoubleBuffer))) { available = 1; } } } else { - if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { - if ( (response & (1 << gestaltHasASC)) ) { + if (Gestalt (gestaltSoundAttr, &response) == noErr) { + if ((response & (1 << gestaltHasASC))) { available = 1; } } } - return(available); + return (available); } -static void Mac_CloseAudio(_THIS) +static void +Mac_CloseAudio (_THIS) { int i; - if ( channel != NULL ) { + if (channel != NULL) { /* Clean up the audio channel */ - SndDisposeChannel(channel, true); + SndDisposeChannel (channel, true); channel = NULL; } - for ( i=0; i<2; ++i ) { - if ( audio_buf[i] ) { - SDL_free(audio_buf[i]); + for (i = 0; i < 2; ++i) { + if (audio_buf[i]) { + SDL_free (audio_buf[i]); audio_buf[i] = NULL; } } } -static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +Mac_OpenAudio (_THIS, SDL_AudioSpec * spec) { SndDoubleBufferHeader2 audio_dbh; int i; @@ -411,86 +433,86 @@ static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) SndDoubleBackUPP doubleBackProc; /* Check to make sure double-buffered audio is available */ - if ( ! DoubleBufferAudio_Available() ) { - SDL_SetError("Sound manager doesn't support double-buffering"); - return(-1); + if (!DoubleBufferAudio_Available ()) { + SDL_SetError ("Sound manager doesn't support double-buffering"); + return (-1); } /* Very few conversions are required, but... */ switch (spec->format) { - case AUDIO_S8: + case AUDIO_S8: spec->format = AUDIO_U8; break; - case AUDIO_U16LSB: + case AUDIO_U16LSB: spec->format = AUDIO_S16LSB; break; - case AUDIO_U16MSB: + case AUDIO_U16MSB: spec->format = AUDIO_S16MSB; break; } - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); /* initialize the double-back header */ - SDL_memset(&audio_dbh, 0, sizeof(audio_dbh)); + SDL_memset (&audio_dbh, 0, sizeof (audio_dbh)); doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc); sample_bits = spec->size / spec->samples / spec->channels * 8; - + audio_dbh.dbhNumChannels = spec->channels; - audio_dbh.dbhSampleSize = sample_bits; + audio_dbh.dbhSampleSize = sample_bits; audio_dbh.dbhCompressionID = 0; - audio_dbh.dbhPacketSize = 0; - audio_dbh.dbhSampleRate = spec->freq << 16; - audio_dbh.dbhDoubleBack = doubleBackProc; - audio_dbh.dbhFormat = 0; + audio_dbh.dbhPacketSize = 0; + audio_dbh.dbhSampleRate = spec->freq << 16; + audio_dbh.dbhDoubleBack = doubleBackProc; + audio_dbh.dbhFormat = 0; /* Note that we install the 16bitLittleEndian Converter if needed. */ - if ( spec->format == 0x8010 ) { + if (spec->format == 0x8010) { audio_dbh.dbhCompressionID = fixedCompression; audio_dbh.dbhFormat = k16BitLittleEndianFormat; } /* allocate the 2 double-back buffers */ - for ( i=0; i<2; ++i ) { - audio_buf[i] = SDL_calloc(1, sizeof(SndDoubleBuffer)+spec->size); - if ( audio_buf[i] == NULL ) { - SDL_OutOfMemory(); - return(-1); + for (i = 0; i < 2; ++i) { + audio_buf[i] = SDL_calloc (1, sizeof (SndDoubleBuffer) + spec->size); + if (audio_buf[i] == NULL) { + SDL_OutOfMemory (); + return (-1); } audio_buf[i]->dbNumFrames = spec->samples; audio_buf[i]->dbFlags = dbBufferReady; - audio_buf[i]->dbUserInfo[0] = (long)this; + audio_buf[i]->dbUserInfo[0] = (long) this; audio_dbh.dbhBufferPtr[i] = audio_buf[i]; } /* Create the sound manager channel */ - channel = (SndChannelPtr)SDL_malloc(sizeof(*channel)); - if ( channel == NULL ) { - SDL_OutOfMemory(); - return(-1); + channel = (SndChannelPtr) SDL_malloc (sizeof (*channel)); + if (channel == NULL) { + SDL_OutOfMemory (); + return (-1); } - if ( spec->channels >= 2 ) { + if (spec->channels >= 2) { initOptions = initStereo; } else { initOptions = initMono; } channel->userInfo = 0; channel->qLength = 128; - if ( SndNewChannel(&channel, sampledSynth, initOptions, 0L) != noErr ) { - SDL_SetError("Unable to create audio channel"); - SDL_free(channel); + if (SndNewChannel (&channel, sampledSynth, initOptions, 0L) != noErr) { + SDL_SetError ("Unable to create audio channel"); + SDL_free (channel); channel = NULL; - return(-1); + return (-1); } - + /* Start playback */ - if ( SndPlayDoubleBuffer(channel, (SndDoubleBufferHeaderPtr)&audio_dbh) - != noErr ) { - SDL_SetError("Unable to play double buffered audio"); - return(-1); + if (SndPlayDoubleBuffer (channel, (SndDoubleBufferHeaderPtr) & audio_dbh) + != noErr) { + SDL_SetError ("Unable to play double buffered audio"); + return (-1); } - + return 1; } #endif /* TARGET_API_MAC_CARBON || USE_RYANS_SOUNDCODE */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/macrom/SDL_romaudio.h b/src/audio/macrom/SDL_romaudio.h index be5dc6961..23633182f 100644 --- a/src/audio/macrom/SDL_romaudio.h +++ b/src/audio/macrom/SDL_romaudio.h @@ -32,14 +32,15 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* Sound manager audio channel */ - SndChannelPtr channel; +struct SDL_PrivateAudioData +{ + /* Sound manager audio channel */ + SndChannelPtr channel; #if defined(TARGET_API_MAC_CARBON) || defined(USE_RYANS_SOUNDCODE) - /* FIXME: Add Ryan's static data here */ + /* FIXME: Add Ryan's static data here */ #else - /* Double buffering variables */ - SndDoubleBufferPtr audio_buf[2]; + /* Double buffering variables */ + SndDoubleBufferPtr audio_buf[2]; #endif }; @@ -48,3 +49,4 @@ struct SDL_PrivateAudioData { #define audio_buf (this->hidden->audio_buf) #endif /* _SDL_romaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio.c b/src/audio/mint/SDL_mintaudio.c index b98bb3242..8a9d1e6e8 100644 --- a/src/audio/mint/SDL_mintaudio.c +++ b/src/audio/mint/SDL_mintaudio.c @@ -40,12 +40,12 @@ /* The audio device */ SDL_AudioDevice *SDL_MintAudio_device; -Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */ -unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ -volatile unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ +Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */ +unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ +volatile unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ volatile unsigned short SDL_MintAudio_mutex; volatile unsigned long SDL_MintAudio_clocktics; -cookie_stfa_t *SDL_MintAudio_stfa; +cookie_stfa_t *SDL_MintAudio_stfa; /* MiNT thread variables */ SDL_bool SDL_MintAudio_mint_present; @@ -55,139 +55,154 @@ long SDL_MintAudio_thread_pid; /* The callback function, called by each driver whenever needed */ -void SDL_MintAudio_Callback(void) +void +SDL_MintAudio_Callback (void) { - Uint8 *buffer; - SDL_AudioDevice *audio = SDL_MintAudio_device; - - buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; - SDL_memset(buffer, audio->spec.silence, audio->spec.size); - - if (audio->paused) - return; - - if (audio->convert.needed) { - int silence; - - if ( audio->convert.src_format == AUDIO_U8 ) { - silence = 0x80; - } else { - silence = 0; - } - SDL_memset(audio->convert.buf, silence, audio->convert.len); - audio->spec.callback(audio->spec.userdata, - (Uint8 *)audio->convert.buf,audio->convert.len); - SDL_ConvertAudio(&audio->convert); - SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt); - } else { - audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size); - } + Uint8 *buffer; + SDL_AudioDevice *audio = SDL_MintAudio_device; + + buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; + SDL_memset (buffer, audio->spec.silence, audio->spec.size); + + if (audio->paused) + return; + + if (audio->convert.needed) { + int silence; + + if (audio->convert.src_format == AUDIO_U8) { + silence = 0x80; + } else { + silence = 0; + } + SDL_memset (audio->convert.buf, silence, audio->convert.len); + audio->spec.callback (audio->spec.userdata, + (Uint8 *) audio->convert.buf, + audio->convert.len); + SDL_ConvertAudio (&audio->convert); + SDL_memcpy (buffer, audio->convert.buf, audio->convert.len_cvt); + } else { + audio->spec.callback (audio->spec.userdata, buffer, audio->spec.size); + } } /* Add a new frequency/clock/predivisor to the current list */ -void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, - Uint32 prediv, int gpio_bits) +void +SDL_MintAudio_AddFrequency (_THIS, Uint32 frequency, Uint32 clock, + Uint32 prediv, int gpio_bits) { - int i, p; - - if (MINTAUDIO_freqcount==MINTAUDIO_maxfreqs) { - return; - } - - /* Search where to insert the frequency (highest first) */ - for (p=0; p MINTAUDIO_frequencies[p].frequency) { - break; - } - } - - /* Put all following ones farer */ - if (MINTAUDIO_freqcount>0) { - for (i=MINTAUDIO_freqcount; i>p; i--) { - SDL_memcpy(&MINTAUDIO_frequencies[i], &MINTAUDIO_frequencies[i-1], sizeof(mint_frequency_t)); - } - } - - /* And insert new one */ - MINTAUDIO_frequencies[p].frequency = frequency; - MINTAUDIO_frequencies[p].masterclock = clock; - MINTAUDIO_frequencies[p].predivisor = prediv; - MINTAUDIO_frequencies[p].gpio_bits = gpio_bits; - - MINTAUDIO_freqcount++; + int i, p; + + if (MINTAUDIO_freqcount == MINTAUDIO_maxfreqs) { + return; + } + + /* Search where to insert the frequency (highest first) */ + for (p = 0; p < MINTAUDIO_freqcount; p++) { + if (frequency > MINTAUDIO_frequencies[p].frequency) { + break; + } + } + + /* Put all following ones farer */ + if (MINTAUDIO_freqcount > 0) { + for (i = MINTAUDIO_freqcount; i > p; i--) { + SDL_memcpy (&MINTAUDIO_frequencies[i], + &MINTAUDIO_frequencies[i - 1], + sizeof (mint_frequency_t)); + } + } + + /* And insert new one */ + MINTAUDIO_frequencies[p].frequency = frequency; + MINTAUDIO_frequencies[p].masterclock = clock; + MINTAUDIO_frequencies[p].predivisor = prediv; + MINTAUDIO_frequencies[p].gpio_bits = gpio_bits; + + MINTAUDIO_freqcount++; } /* Search for the nearest frequency */ -int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq) +int +SDL_MintAudio_SearchFrequency (_THIS, int desired_freq) { - int i; - - /* Only 1 freq ? */ - if (MINTAUDIO_freqcount==1) { - return 0; - } - - /* Check the array */ - for (i=0; i= ((MINTAUDIO_frequencies[i].frequency+ - MINTAUDIO_frequencies[i+1].frequency)>>1)) { - return i; - } - } - - /* Not in the array, give the latest */ - return MINTAUDIO_freqcount-1; + int i; + + /* Only 1 freq ? */ + if (MINTAUDIO_freqcount == 1) { + return 0; + } + + /* Check the array */ + for (i = 0; i < MINTAUDIO_freqcount; i++) { + if (desired_freq >= ((MINTAUDIO_frequencies[i].frequency + + MINTAUDIO_frequencies[i + 1].frequency) >> 1)) { + return i; + } + } + + /* Not in the array, give the latest */ + return MINTAUDIO_freqcount - 1; } /* The thread function, used under MiNT with xbios */ -int SDL_MintAudio_Thread(long param) +int +SDL_MintAudio_Thread (long param) { - SndBufPtr pointers; - SDL_bool buffers_filled[2] = {SDL_FALSE, SDL_FALSE}; - - SDL_MintAudio_thread_finished = SDL_FALSE; - while (!SDL_MintAudio_quit_thread) { - if (Buffptr(&pointers)!=0) - continue; - - if (( (unsigned long)pointers.play>=(unsigned long)SDL_MintAudio_audiobuf[0]) - && ( (unsigned long)pointers.play<=(unsigned long)SDL_MintAudio_audiobuf[1])) - { - /* DMA is reading buffer #0, setup buffer #1 if not already done */ - if (!buffers_filled[1]) { - SDL_MintAudio_numbuf = 1; - SDL_MintAudio_Callback(); - Setbuffer(0, SDL_MintAudio_audiobuf[1], SDL_MintAudio_audiobuf[1] + SDL_MintAudio_audiosize); - buffers_filled[1]=SDL_TRUE; - buffers_filled[0]=SDL_FALSE; - } - } else { - /* DMA is reading buffer #1, setup buffer #0 if not already done */ - if (!buffers_filled[0]) { - SDL_MintAudio_numbuf = 0; - SDL_MintAudio_Callback(); - Setbuffer(0, SDL_MintAudio_audiobuf[0], SDL_MintAudio_audiobuf[0] + SDL_MintAudio_audiosize); - buffers_filled[0]=SDL_TRUE; - buffers_filled[1]=SDL_FALSE; - } - } - - usleep(100); - } - SDL_MintAudio_thread_finished = SDL_TRUE; - return 0; + SndBufPtr pointers; + SDL_bool buffers_filled[2] = { SDL_FALSE, SDL_FALSE }; + + SDL_MintAudio_thread_finished = SDL_FALSE; + while (!SDL_MintAudio_quit_thread) { + if (Buffptr (&pointers) != 0) + continue; + + if (((unsigned long) pointers.play >= + (unsigned long) SDL_MintAudio_audiobuf[0]) + && ((unsigned long) pointers.play <= + (unsigned long) SDL_MintAudio_audiobuf[1])) { + /* DMA is reading buffer #0, setup buffer #1 if not already done */ + if (!buffers_filled[1]) { + SDL_MintAudio_numbuf = 1; + SDL_MintAudio_Callback (); + Setbuffer (0, SDL_MintAudio_audiobuf[1], + SDL_MintAudio_audiobuf[1] + + SDL_MintAudio_audiosize); + buffers_filled[1] = SDL_TRUE; + buffers_filled[0] = SDL_FALSE; + } + } else { + /* DMA is reading buffer #1, setup buffer #0 if not already done */ + if (!buffers_filled[0]) { + SDL_MintAudio_numbuf = 0; + SDL_MintAudio_Callback (); + Setbuffer (0, SDL_MintAudio_audiobuf[0], + SDL_MintAudio_audiobuf[0] + + SDL_MintAudio_audiosize); + buffers_filled[0] = SDL_TRUE; + buffers_filled[1] = SDL_FALSE; + } + } + + usleep (100); + } + SDL_MintAudio_thread_finished = SDL_TRUE; + return 0; } -void SDL_MintAudio_WaitThread(void) +void +SDL_MintAudio_WaitThread (void) { - if (!SDL_MintAudio_mint_present) - return; + if (!SDL_MintAudio_mint_present) + return; - if (SDL_MintAudio_thread_finished) - return; + if (SDL_MintAudio_thread_finished) + return; - SDL_MintAudio_quit_thread = SDL_TRUE; - while (!SDL_MintAudio_thread_finished) { - Syield(); - } + SDL_MintAudio_quit_thread = SDL_TRUE; + while (!SDL_MintAudio_thread_finished) { + Syield (); + } } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio.h b/src/audio/mint/SDL_mintaudio.h index 970169c17..1f202cc58 100644 --- a/src/audio/mint/SDL_mintaudio.h +++ b/src/audio/mint/SDL_mintaudio.h @@ -37,19 +37,21 @@ #define _THIS SDL_AudioDevice *this /* 16 predivisors with 3 clocks max. */ -#define MINTAUDIO_maxfreqs (16*3) - -typedef struct { - Uint32 frequency; - Uint32 masterclock; - Uint32 predivisor; - int gpio_bits; /* in case of external clock */ +#define MINTAUDIO_maxfreqs (16*3) + +typedef struct +{ + Uint32 frequency; + Uint32 masterclock; + Uint32 predivisor; + int gpio_bits; /* in case of external clock */ } mint_frequency_t; -struct SDL_PrivateAudioData { - mint_frequency_t frequencies[MINTAUDIO_maxfreqs]; - int freq_count; /* Number of frequencies in the array */ - int numfreq; /* Number of selected frequency */ +struct SDL_PrivateAudioData +{ + mint_frequency_t frequencies[MINTAUDIO_maxfreqs]; + int freq_count; /* Number of frequencies in the array */ + int numfreq; /* Number of selected frequency */ }; /* Old variable names */ @@ -59,23 +61,24 @@ struct SDL_PrivateAudioData { #define MINTAUDIO_numfreq (this->hidden->numfreq) /* _MCH cookie (values>>16) */ -enum { - MCH_ST=0, - MCH_STE, - MCH_TT, - MCH_F30, - MCH_CLONE, - MCH_ARANYM +enum +{ + MCH_ST = 0, + MCH_STE, + MCH_TT, + MCH_F30, + MCH_CLONE, + MCH_ARANYM }; /* Master clocks for replay frequencies */ -#define MASTERCLOCK_STE 8010666 /* Not sure of this one */ -#define MASTERCLOCK_TT 16107953 /* Not sure of this one */ +#define MASTERCLOCK_STE 8010666 /* Not sure of this one */ +#define MASTERCLOCK_TT 16107953 /* Not sure of this one */ #define MASTERCLOCK_FALCON1 25175000 -#define MASTERCLOCK_FALCON2 32000000 /* Only usable for DSP56K */ -#define MASTERCLOCK_FALCONEXT -1 /* Clock on DSP56K port, unknown */ -#define MASTERCLOCK_44K 22579200 /* Standard clock for 44.1 Khz */ -#define MASTERCLOCK_48K 24576000 /* Standard clock for 48 Khz */ +#define MASTERCLOCK_FALCON2 32000000 /* Only usable for DSP56K */ +#define MASTERCLOCK_FALCONEXT -1 /* Clock on DSP56K port, unknown */ +#define MASTERCLOCK_44K 22579200 /* Standard clock for 44.1 Khz */ +#define MASTERCLOCK_48K 24576000 /* Standard clock for 48 Khz */ /* Master clock predivisors */ #define MASTERPREDIV_STE 160 @@ -84,68 +87,71 @@ enum { #define MASTERPREDIV_MILAN 256 /* MFP 68901 interrupt sources */ -enum { - MFP_PARALLEL=0, - MFP_DCD, - MFP_CTS, - MFP_BITBLT, - MFP_TIMERD, - MFP_BAUDRATE=MFP_TIMERD, - MFP_TIMERC, - MFP_200HZ=MFP_TIMERC, - MFP_ACIA, - MFP_DISK, - MFP_TIMERB, - MFP_HBLANK=MFP_TIMERB, - MFP_TERR, - MFP_TBE, - MFP_RERR, - MFP_RBF, - MFP_TIMERA, - MFP_DMASOUND=MFP_TIMERA, - MFP_RING, - MFP_MONODETECT +enum +{ + MFP_PARALLEL = 0, + MFP_DCD, + MFP_CTS, + MFP_BITBLT, + MFP_TIMERD, + MFP_BAUDRATE = MFP_TIMERD, + MFP_TIMERC, + MFP_200HZ = MFP_TIMERC, + MFP_ACIA, + MFP_DISK, + MFP_TIMERB, + MFP_HBLANK = MFP_TIMERB, + MFP_TERR, + MFP_TBE, + MFP_RERR, + MFP_RBF, + MFP_TIMERA, + MFP_DMASOUND = MFP_TIMERA, + MFP_RING, + MFP_MONODETECT }; /* Xbtimer() timers */ -enum { - XB_TIMERA=0, - XB_TIMERB, - XB_TIMERC, - XB_TIMERD +enum +{ + XB_TIMERA = 0, + XB_TIMERB, + XB_TIMERC, + XB_TIMERD }; /* Variables */ extern SDL_AudioDevice *SDL_MintAudio_device; -extern Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */ -extern unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ -extern volatile unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ +extern Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */ +extern unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ +extern volatile unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ extern volatile unsigned short SDL_MintAudio_mutex; extern cookie_stfa_t *SDL_MintAudio_stfa; extern volatile unsigned long SDL_MintAudio_clocktics; /* MiNT thread variables */ -extern SDL_bool SDL_MintAudio_mint_present; +extern SDL_bool SDL_MintAudio_mint_present; extern SDL_bool SDL_MintAudio_quit_thread; extern SDL_bool SDL_MintAudio_thread_finished; extern long SDL_MintAudio_thread_pid; /* Functions */ -void SDL_MintAudio_Callback(void); -void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, - Uint32 prediv, int gpio_bits); -int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq); +void SDL_MintAudio_Callback (void); +void SDL_MintAudio_AddFrequency (_THIS, Uint32 frequency, Uint32 clock, + Uint32 prediv, int gpio_bits); +int SDL_MintAudio_SearchFrequency (_THIS, int desired_freq); /* MiNT thread functions */ -int SDL_MintAudio_Thread(long param); -void SDL_MintAudio_WaitThread(void); +int SDL_MintAudio_Thread (long param); +void SDL_MintAudio_WaitThread (void); /* ASM interrupt functions */ -void SDL_MintAudio_GsxbInterrupt(void); -void SDL_MintAudio_EmptyGsxbInterrupt(void); -void SDL_MintAudio_XbiosInterruptMeasureClock(void); -void SDL_MintAudio_XbiosInterrupt(void); -void SDL_MintAudio_Dma8Interrupt(void); -void SDL_MintAudio_StfaInterrupt(void); +void SDL_MintAudio_GsxbInterrupt (void); +void SDL_MintAudio_EmptyGsxbInterrupt (void); +void SDL_MintAudio_XbiosInterruptMeasureClock (void); +void SDL_MintAudio_XbiosInterrupt (void); +void SDL_MintAudio_Dma8Interrupt (void); +void SDL_MintAudio_StfaInterrupt (void); #endif /* _SDL_mintaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_dma8.c b/src/audio/mint/SDL_mintaudio_dma8.c index 39e7a6d22..905fb9691 100644 --- a/src/audio/mint/SDL_mintaudio_dma8.c +++ b/src/audio/mint/SDL_mintaudio_dma8.c @@ -63,294 +63,308 @@ static unsigned long cookie_snd, cookie_mch; /*--- Audio driver functions ---*/ -static void Mint_CloseAudio(_THIS); -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_LockAudio(_THIS); -static void Mint_UnlockAudio(_THIS); +static void Mint_CloseAudio (_THIS); +static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_LockAudio (_THIS); +static void Mint_UnlockAudio (_THIS); /* To check/init hardware audio */ -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec); +static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); /*--- Audio driver bootstrap functions ---*/ -static int Audio_Available(void) +static int +Audio_Available (void) { - const char *envr = SDL_getenv("SDL_AUDIODRIVER"); + const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); - /* Check if user asked a different audio driver */ - if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) { - DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); - return 0; - } + /* Check if user asked a different audio driver */ + if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { + DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); + return 0; + } - /* Cookie _MCH present ? if not, assume ST machine */ - if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) { - cookie_mch = MCH_ST; - } + /* Cookie _MCH present ? if not, assume ST machine */ + if (Getcookie (C__MCH, &cookie_mch) == C_NOTFOUND) { + cookie_mch = MCH_ST; + } - /* Cookie _SND present ? if not, assume ST machine */ - if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { - cookie_snd = SND_PSG; - } + /* Cookie _SND present ? if not, assume ST machine */ + if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { + cookie_snd = SND_PSG; + } - /* Check if we have 8 bits audio */ - if ((cookie_snd & SND_8BIT)==0) { - DEBUG_PRINT((DEBUG_NAME "no 8 bits sound\n")); - return(0); - } + /* Check if we have 8 bits audio */ + if ((cookie_snd & SND_8BIT) == 0) { + DEBUG_PRINT ((DEBUG_NAME "no 8 bits sound\n")); + return (0); + } - /* Check if audio is lockable */ - if (cookie_snd & SND_16BIT) { - if (Locksnd()!=1) { - DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); - return(0); - } + /* Check if audio is lockable */ + if (cookie_snd & SND_16BIT) { + if (Locksnd () != 1) { + DEBUG_PRINT ((DEBUG_NAME "audio locked by other application\n")); + return (0); + } - Unlocksnd(); - } + Unlocksnd (); + } - DEBUG_PRINT((DEBUG_NAME "8 bits audio available!\n")); - return(1); + DEBUG_PRINT ((DEBUG_NAME "8 bits audio available!\n")); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; + SDL_AudioDevice *this; - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ - this->OpenAudio = Mint_OpenAudio; - this->CloseAudio = Mint_CloseAudio; - this->LockAudio = Mint_LockAudio; + this->OpenAudio = Mint_OpenAudio; + this->CloseAudio = Mint_CloseAudio; + this->LockAudio = Mint_LockAudio; this->UnlockAudio = Mint_UnlockAudio; - this->free = Audio_DeleteDevice; + this->free = Audio_DeleteDevice; return this; } AudioBootStrap MINTAUDIO_DMA8_bootstrap = { - MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver", - Audio_Available, Audio_CreateDevice + MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver", + Audio_Available, Audio_CreateDevice }; -static void Mint_LockAudio(_THIS) +static void +Mint_LockAudio (_THIS) { - void *oldpile; + void *oldpile; - /* Stop replay */ - oldpile=(void *)Super(0); - DMAAUDIO_IO.control=0; - Super(oldpile); + /* Stop replay */ + oldpile = (void *) Super (0); + DMAAUDIO_IO.control = 0; + Super (oldpile); } -static void Mint_UnlockAudio(_THIS) +static void +Mint_UnlockAudio (_THIS) { - void *oldpile; + void *oldpile; - /* Restart replay */ - oldpile=(void *)Super(0); - DMAAUDIO_IO.control=3; - Super(oldpile); + /* Restart replay */ + oldpile = (void *) Super (0); + DMAAUDIO_IO.control = 3; + Super (oldpile); } -static void Mint_CloseAudio(_THIS) +static void +Mint_CloseAudio (_THIS) { - void *oldpile; + void *oldpile; - /* Stop replay */ - oldpile=(void *)Super(0); - DMAAUDIO_IO.control=0; - Super(oldpile); + /* Stop replay */ + oldpile = (void *) Super (0); + DMAAUDIO_IO.control = 0; + Super (oldpile); - DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n")); + DEBUG_PRINT ((DEBUG_NAME "closeaudio: replay stopped\n")); - /* Disable interrupt */ - Jdisint(MFP_DMASOUND); + /* Disable interrupt */ + Jdisint (MFP_DMASOUND); - DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n")); + DEBUG_PRINT ((DEBUG_NAME "closeaudio: interrupt disabled\n")); - /* Wait if currently playing sound */ - while (SDL_MintAudio_mutex != 0) { - } + /* Wait if currently playing sound */ + while (SDL_MintAudio_mutex != 0) { + } - DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n")); + DEBUG_PRINT ((DEBUG_NAME "closeaudio: no more interrupt running\n")); - /* Clear buffers */ - if (SDL_MintAudio_audiobuf[0]) { - Mfree(SDL_MintAudio_audiobuf[0]); - SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; - } + /* Clear buffers */ + if (SDL_MintAudio_audiobuf[0]) { + Mfree (SDL_MintAudio_audiobuf[0]); + SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; + } - DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n")); + DEBUG_PRINT ((DEBUG_NAME "closeaudio: buffers freed\n")); } -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) { - int i, masterprediv, sfreq; - unsigned long masterclock; - - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); - - /* Check formats available */ - spec->format = AUDIO_S8; - - /* Calculate and select the closest frequency */ - sfreq=0; - masterclock=MASTERCLOCK_STE; - masterprediv=MASTERPREDIV_STE; - switch(cookie_mch>>16) { + int i, masterprediv, sfreq; + unsigned long masterclock; + + DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); + + /* Check formats available */ + spec->format = AUDIO_S8; + + /* Calculate and select the closest frequency */ + sfreq = 0; + masterclock = MASTERCLOCK_STE; + masterprediv = MASTERPREDIV_STE; + switch (cookie_mch >> 16) { /* case MCH_STE: masterclock=MASTERCLOCK_STE; masterprediv=MASTERPREDIV_STE; break; */ - case MCH_TT: - masterclock=MASTERCLOCK_TT; - masterprediv=MASTERPREDIV_TT; - break; - case MCH_F30: - case MCH_ARANYM: - masterclock=MASTERCLOCK_FALCON1; - masterprediv=MASTERPREDIV_FALCON; - sfreq=1; - break; - } - - MINTAUDIO_freqcount=0; - for (i=sfreq;i<4;i++) { - SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<freq); - spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; + MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); + spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); + DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); - return 0; + return 0; } -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) +static void +Mint_InitAudio (_THIS, SDL_AudioSpec * spec) { - void *oldpile; - unsigned long buffer; - unsigned char mode; - - /* Set replay tracks */ - if (cookie_snd & SND_16BIT) { - Settracks(0,0); - Setmontracks(0); - } + void *oldpile; + unsigned long buffer; + unsigned char mode; + + /* Set replay tracks */ + if (cookie_snd & SND_16BIT) { + Settracks (0, 0); + Setmontracks (0); + } - oldpile=(void *)Super(0); + oldpile = (void *) Super (0); - /* Stop currently playing sound */ - DMAAUDIO_IO.control=0; + /* Stop currently playing sound */ + DMAAUDIO_IO.control = 0; - /* Set buffer */ - buffer = (unsigned long) SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; - DMAAUDIO_IO.start_high = (buffer>>16) & 255; - DMAAUDIO_IO.start_mid = (buffer>>8) & 255; - DMAAUDIO_IO.start_low = buffer & 255; + /* Set buffer */ + buffer = (unsigned long) SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; + DMAAUDIO_IO.start_high = (buffer >> 16) & 255; + DMAAUDIO_IO.start_mid = (buffer >> 8) & 255; + DMAAUDIO_IO.start_low = buffer & 255; - buffer += SDL_MintAudio_audiosize; - DMAAUDIO_IO.end_high = (buffer>>16) & 255; - DMAAUDIO_IO.end_mid = (buffer>>8) & 255; - DMAAUDIO_IO.end_low = buffer & 255; + buffer += SDL_MintAudio_audiosize; + DMAAUDIO_IO.end_high = (buffer >> 16) & 255; + DMAAUDIO_IO.end_mid = (buffer >> 8) & 255; + DMAAUDIO_IO.end_low = buffer & 255; - mode = 3-MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; - if (spec->channels==1) { - mode |= 1<<7; - } - DMAAUDIO_IO.sound_ctrl = mode; + mode = 3 - MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; + if (spec->channels == 1) { + mode |= 1 << 7; + } + DMAAUDIO_IO.sound_ctrl = mode; - /* Set interrupt */ - Jdisint(MFP_DMASOUND); - Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_Dma8Interrupt); - Jenabint(MFP_DMASOUND); + /* Set interrupt */ + Jdisint (MFP_DMASOUND); + Xbtimer (XB_TIMERA, 8, 1, SDL_MintAudio_Dma8Interrupt); + Jenabint (MFP_DMASOUND); - if (cookie_snd & SND_16BIT) { - if (Setinterrupt(SI_TIMERA, SI_PLAY)<0) { - DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n")); - } - } + if (cookie_snd & SND_16BIT) { + if (Setinterrupt (SI_TIMERA, SI_PLAY) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setinterrupt() failed\n")); + } + } - /* Go */ - DMAAUDIO_IO.control = 3; /* playback + repeat */ + /* Go */ + DMAAUDIO_IO.control = 3; /* playback + repeat */ - Super(oldpile); + Super (oldpile); } -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) { - SDL_MintAudio_device = this; + SDL_MintAudio_device = this; - /* Check audio capabilities */ - if (Mint_CheckAudio(this, spec)==-1) { - return -1; - } + /* Check audio capabilities */ + if (Mint_CheckAudio (this, spec) == -1) { + return -1; + } - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); - /* Allocate memory for audio buffers in DMA-able RAM */ - DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); + /* Allocate memory for audio buffers in DMA-able RAM */ + DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); - SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); - if (SDL_MintAudio_audiobuf[0]==NULL) { - SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); - return (-1); - } - SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; - SDL_MintAudio_numbuf=0; - SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); - SDL_MintAudio_audiosize = spec->size; - SDL_MintAudio_mutex = 0; + SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); + if (SDL_MintAudio_audiobuf[0] == NULL) { + SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); + return (-1); + } + SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; + SDL_MintAudio_numbuf = 0; + SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); + SDL_MintAudio_audiosize = spec->size; + SDL_MintAudio_mutex = 0; - DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); - DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); + DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", + SDL_MintAudio_audiobuf[0])); + DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", + SDL_MintAudio_audiobuf[1])); - /* Setup audio hardware */ - Mint_InitAudio(this, spec); + /* Setup audio hardware */ + Mint_InitAudio (this, spec); - return(1); /* We don't use threaded audio */ + return (1); /* We don't use threaded audio */ } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_dma8.h b/src/audio/mint/SDL_mintaudio_dma8.h index 698fed4e5..2bc9a86c9 100644 --- a/src/audio/mint/SDL_mintaudio_dma8.h +++ b/src/audio/mint/SDL_mintaudio_dma8.h @@ -31,55 +31,57 @@ #define _SDL_mintaudio_dma8_h #define DMAAUDIO_IO_BASE (0xffff8900) -struct DMAAUDIO_IO_S { - unsigned char int_ctrl; - unsigned char control; - - unsigned char dummy1; - unsigned char start_high; - unsigned char dummy2; - unsigned char start_mid; - unsigned char dummy3; - unsigned char start_low; - - unsigned char dummy4; - unsigned char cur_high; - unsigned char dummy5; - unsigned char cur_mid; - unsigned char dummy6; - unsigned char cur_low; - - unsigned char dummy7; - unsigned char end_high; - unsigned char dummy8; - unsigned char end_mid; - unsigned char dummy9; - unsigned char end_low; - - unsigned char dummy10[12]; - - unsigned char track_ctrl; /* CODEC only */ - unsigned char sound_ctrl; - unsigned short sound_data; - unsigned short sound_mask; - - unsigned char dummy11[10]; - - unsigned short dev_ctrl; - unsigned short dest_ctrl; - unsigned short sync_div; - unsigned char track_rec; - unsigned char adderin_input; - unsigned char channel_input; - unsigned char channel_amplification; - unsigned char channel_reduction; - - unsigned char dummy12[6]; - - unsigned char data_direction; - unsigned char dummy13; - unsigned char dev_data; +struct DMAAUDIO_IO_S +{ + unsigned char int_ctrl; + unsigned char control; + + unsigned char dummy1; + unsigned char start_high; + unsigned char dummy2; + unsigned char start_mid; + unsigned char dummy3; + unsigned char start_low; + + unsigned char dummy4; + unsigned char cur_high; + unsigned char dummy5; + unsigned char cur_mid; + unsigned char dummy6; + unsigned char cur_low; + + unsigned char dummy7; + unsigned char end_high; + unsigned char dummy8; + unsigned char end_mid; + unsigned char dummy9; + unsigned char end_low; + + unsigned char dummy10[12]; + + unsigned char track_ctrl; /* CODEC only */ + unsigned char sound_ctrl; + unsigned short sound_data; + unsigned short sound_mask; + + unsigned char dummy11[10]; + + unsigned short dev_ctrl; + unsigned short dest_ctrl; + unsigned short sync_div; + unsigned char track_rec; + unsigned char adderin_input; + unsigned char channel_input; + unsigned char channel_amplification; + unsigned char channel_reduction; + + unsigned char dummy12[6]; + + unsigned char data_direction; + unsigned char dummy13; + unsigned char dev_data; }; #define DMAAUDIO_IO ((*(volatile struct DMAAUDIO_IO_S *)DMAAUDIO_IO_BASE)) #endif /* _SDL_mintaudio_dma8_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_gsxb.c b/src/audio/mint/SDL_mintaudio_gsxb.c index de35debf5..ea7aafc6c 100644 --- a/src/audio/mint/SDL_mintaudio_gsxb.c +++ b/src/audio/mint/SDL_mintaudio_gsxb.c @@ -63,352 +63,368 @@ static unsigned long cookie_snd, cookie_gsxb; /*--- Audio driver functions ---*/ -static void Mint_CloseAudio(_THIS); -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_LockAudio(_THIS); -static void Mint_UnlockAudio(_THIS); +static void Mint_CloseAudio (_THIS); +static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_LockAudio (_THIS); +static void Mint_UnlockAudio (_THIS); /* To check/init hardware audio */ -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec); +static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); /* GSXB callbacks */ -static void Mint_GsxbInterrupt(void); -static void Mint_GsxbNullInterrupt(void); +static void Mint_GsxbInterrupt (void); +static void Mint_GsxbNullInterrupt (void); /*--- Audio driver bootstrap functions ---*/ -static int Audio_Available(void) +static int +Audio_Available (void) { - const char *envr = SDL_getenv("SDL_AUDIODRIVER"); + const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); - /* Check if user asked a different audio driver */ - if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) { - DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); - return(0); - } + /* Check if user asked a different audio driver */ + if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { + DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); + return (0); + } - /* Cookie _SND present ? if not, assume ST machine */ - if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { - cookie_snd = SND_PSG; - } + /* Cookie _SND present ? if not, assume ST machine */ + if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { + cookie_snd = SND_PSG; + } - /* Check if we have 16 bits audio */ - if ((cookie_snd & SND_16BIT)==0) { - DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n")); - return(0); - } + /* Check if we have 16 bits audio */ + if ((cookie_snd & SND_16BIT) == 0) { + DEBUG_PRINT ((DEBUG_NAME "no 16 bits sound\n")); + return (0); + } - /* Cookie GSXB present ? */ - cookie_gsxb = (Getcookie(C_GSXB, &cookie_gsxb) == C_FOUND); + /* Cookie GSXB present ? */ + cookie_gsxb = (Getcookie (C_GSXB, &cookie_gsxb) == C_FOUND); - /* Is it GSXB ? */ - if (((cookie_snd & SND_GSXB)==0) || (cookie_gsxb==0)) { - DEBUG_PRINT((DEBUG_NAME "no GSXB audio\n")); - return(0); - } + /* Is it GSXB ? */ + if (((cookie_snd & SND_GSXB) == 0) || (cookie_gsxb == 0)) { + DEBUG_PRINT ((DEBUG_NAME "no GSXB audio\n")); + return (0); + } - /* Check if audio is lockable */ - if (Locksnd()!=1) { - DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); - return(0); - } + /* Check if audio is lockable */ + if (Locksnd () != 1) { + DEBUG_PRINT ((DEBUG_NAME "audio locked by other application\n")); + return (0); + } - Unlocksnd(); + Unlocksnd (); - DEBUG_PRINT((DEBUG_NAME "GSXB audio available!\n")); - return(1); + DEBUG_PRINT ((DEBUG_NAME "GSXB audio available!\n")); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; + SDL_AudioDevice *this; - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ - this->OpenAudio = Mint_OpenAudio; - this->CloseAudio = Mint_CloseAudio; - this->LockAudio = Mint_LockAudio; + this->OpenAudio = Mint_OpenAudio; + this->CloseAudio = Mint_CloseAudio; + this->LockAudio = Mint_LockAudio; this->UnlockAudio = Mint_UnlockAudio; - this->free = Audio_DeleteDevice; + this->free = Audio_DeleteDevice; return this; } AudioBootStrap MINTAUDIO_GSXB_bootstrap = { - MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver", - Audio_Available, Audio_CreateDevice + MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver", + Audio_Available, Audio_CreateDevice }; -static void Mint_LockAudio(_THIS) +static void +Mint_LockAudio (_THIS) { - /* Stop replay */ - Buffoper(0); + /* Stop replay */ + Buffoper (0); } -static void Mint_UnlockAudio(_THIS) +static void +Mint_UnlockAudio (_THIS) { - /* Restart replay */ - Buffoper(SB_PLA_ENA|SB_PLA_RPT); + /* Restart replay */ + Buffoper (SB_PLA_ENA | SB_PLA_RPT); } -static void Mint_CloseAudio(_THIS) +static void +Mint_CloseAudio (_THIS) { - /* Stop replay */ - Buffoper(0); + /* Stop replay */ + Buffoper (0); - /* Uninstall interrupt */ - if (NSetinterrupt(2, SI_NONE, Mint_GsxbNullInterrupt)<0) { - DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n")); - } + /* Uninstall interrupt */ + if (NSetinterrupt (2, SI_NONE, Mint_GsxbNullInterrupt) < 0) { + DEBUG_PRINT ((DEBUG_NAME "NSetinterrupt() failed in close\n")); + } - /* Wait if currently playing sound */ - while (SDL_MintAudio_mutex != 0) { - } + /* Wait if currently playing sound */ + while (SDL_MintAudio_mutex != 0) { + } - /* Clear buffers */ - if (SDL_MintAudio_audiobuf[0]) { - Mfree(SDL_MintAudio_audiobuf[0]); - SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; - } + /* Clear buffers */ + if (SDL_MintAudio_audiobuf[0]) { + Mfree (SDL_MintAudio_audiobuf[0]); + SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; + } - /* Unlock sound system */ - Unlocksnd(); + /* Unlock sound system */ + Unlocksnd (); } -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) { - long snd_format; - int i, resolution, format_signed, format_bigendian; - - resolution = spec->format & 0x00ff; - format_signed = ((spec->format & 0x8000)!=0); - format_bigendian = ((spec->format & 0x1000)!=0); - - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); - - /* Check formats available */ - snd_format = Sndstatus(SND_QUERYFORMATS); - switch (resolution) { - case 8: - if ((snd_format & SND_FORMAT8)==0) { - SDL_SetError("Mint_CheckAudio: 8 bits samples not supported"); - return -1; - } - snd_format = Sndstatus(SND_QUERY8BIT); - break; - case 16: - if ((snd_format & SND_FORMAT16)==0) { - SDL_SetError("Mint_CheckAudio: 16 bits samples not supported"); - return -1; - } - snd_format = Sndstatus(SND_QUERY16BIT); - break; - default: - SDL_SetError("Mint_CheckAudio: Unsupported sample resolution"); - return -1; - break; - } + long snd_format; + int i, resolution, format_signed, format_bigendian; + + resolution = spec->format & 0x00ff; + format_signed = ((spec->format & 0x8000) != 0); + format_bigendian = ((spec->format & 0x1000) != 0); + + DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); + + /* Check formats available */ + snd_format = Sndstatus (SND_QUERYFORMATS); + switch (resolution) { + case 8: + if ((snd_format & SND_FORMAT8) == 0) { + SDL_SetError ("Mint_CheckAudio: 8 bits samples not supported"); + return -1; + } + snd_format = Sndstatus (SND_QUERY8BIT); + break; + case 16: + if ((snd_format & SND_FORMAT16) == 0) { + SDL_SetError ("Mint_CheckAudio: 16 bits samples not supported"); + return -1; + } + snd_format = Sndstatus (SND_QUERY16BIT); + break; + default: + SDL_SetError ("Mint_CheckAudio: Unsupported sample resolution"); + return -1; + break; + } - /* Check signed/unsigned format */ - if (format_signed) { - if (snd_format & SND_FORMATSIGNED) { - /* Ok */ - } else if (snd_format & SND_FORMATUNSIGNED) { - /* Give unsigned format */ - spec->format = spec->format & (~0x8000); - } - } else { - if (snd_format & SND_FORMATUNSIGNED) { - /* Ok */ - } else if (snd_format & SND_FORMATSIGNED) { - /* Give signed format */ - spec->format |= 0x8000; - } - } + /* Check signed/unsigned format */ + if (format_signed) { + if (snd_format & SND_FORMATSIGNED) { + /* Ok */ + } else if (snd_format & SND_FORMATUNSIGNED) { + /* Give unsigned format */ + spec->format = spec->format & (~0x8000); + } + } else { + if (snd_format & SND_FORMATUNSIGNED) { + /* Ok */ + } else if (snd_format & SND_FORMATSIGNED) { + /* Give signed format */ + spec->format |= 0x8000; + } + } - if (format_bigendian) { - if (snd_format & SND_FORMATBIGENDIAN) { - /* Ok */ - } else if (snd_format & SND_FORMATLITTLEENDIAN) { - /* Give little endian format */ - spec->format = spec->format & (~0x1000); - } - } else { - if (snd_format & SND_FORMATLITTLEENDIAN) { - /* Ok */ - } else if (snd_format & SND_FORMATBIGENDIAN) { - /* Give big endian format */ - spec->format |= 0x1000; - } - } - - /* Calculate and select the closest frequency */ - MINTAUDIO_freqcount=0; - for (i=1;i<4;i++) { - SDL_MintAudio_AddFrequency(this, - MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<format = spec->format & (~0x1000); + } + } else { + if (snd_format & SND_FORMATLITTLEENDIAN) { + /* Ok */ + } else if (snd_format & SND_FORMATBIGENDIAN) { + /* Give big endian format */ + spec->format |= 0x1000; + } + } + + /* Calculate and select the closest frequency */ + MINTAUDIO_freqcount = 0; + for (i = 1; i < 4; i++) { + SDL_MintAudio_AddFrequency (this, + MASTERCLOCK_44K / (MASTERPREDIV_MILAN * + (1 << i)), + MASTERCLOCK_44K, (1 << i) - 1, -1); + } #if 1 - for (i=0; ifreq); - spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; + MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); + spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); + DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); - return 0; + return 0; } -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) +static void +Mint_InitAudio (_THIS, SDL_AudioSpec * spec) { - int channels_mode, prediv; - void *buffer; - - /* Stop currently playing sound */ - Buffoper(0); - - /* Set replay tracks */ - Settracks(0,0); - Setmontracks(0); - - /* Select replay format */ - switch (spec->format & 0xff) { - case 8: - if (spec->channels==2) { - channels_mode=STEREO8; - } else { - channels_mode=MONO8; - } - break; - case 16: - if (spec->channels==2) { - channels_mode=STEREO16; - } else { - channels_mode=MONO16; - } - break; - default: - channels_mode=STEREO16; - break; - } - if (Setmode(channels_mode)<0) { - DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); - } + int channels_mode, prediv; + void *buffer; + + /* Stop currently playing sound */ + Buffoper (0); + + /* Set replay tracks */ + Settracks (0, 0); + Setmontracks (0); + + /* Select replay format */ + switch (spec->format & 0xff) { + case 8: + if (spec->channels == 2) { + channels_mode = STEREO8; + } else { + channels_mode = MONO8; + } + break; + case 16: + if (spec->channels == 2) { + channels_mode = STEREO16; + } else { + channels_mode = MONO16; + } + break; + default: + channels_mode = STEREO16; + break; + } + if (Setmode (channels_mode) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setmode() failed\n")); + } - prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; - Devconnect(DMAPLAY, DAC, CLKEXT, prediv, 1); + prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; + Devconnect (DMAPLAY, DAC, CLKEXT, prediv, 1); - /* Set buffer */ - buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; - if (Setbuffer(0, buffer, buffer + spec->size)<0) { - DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); - } - - /* Install interrupt */ - if (NSetinterrupt(2, SI_PLAY, Mint_GsxbInterrupt)<0) { - DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed\n")); - } + /* Set buffer */ + buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; + if (Setbuffer (0, buffer, buffer + spec->size) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setbuffer() failed\n")); + } - /* Go */ - Buffoper(SB_PLA_ENA|SB_PLA_RPT); - DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); + /* Install interrupt */ + if (NSetinterrupt (2, SI_PLAY, Mint_GsxbInterrupt) < 0) { + DEBUG_PRINT ((DEBUG_NAME "NSetinterrupt() failed\n")); + } + + /* Go */ + Buffoper (SB_PLA_ENA | SB_PLA_RPT); + DEBUG_PRINT ((DEBUG_NAME "hardware initialized\n")); } -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) { - /* Lock sound system */ - if (Locksnd()!=1) { - SDL_SetError("Mint_OpenAudio: Audio system already in use"); - return(-1); - } + /* Lock sound system */ + if (Locksnd () != 1) { + SDL_SetError ("Mint_OpenAudio: Audio system already in use"); + return (-1); + } - SDL_MintAudio_device = this; + SDL_MintAudio_device = this; - /* Check audio capabilities */ - if (Mint_CheckAudio(this, spec)==-1) { - return -1; - } + /* Check audio capabilities */ + if (Mint_CheckAudio (this, spec) == -1) { + return -1; + } - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); - /* Allocate memory for audio buffers in DMA-able RAM */ - DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); + /* Allocate memory for audio buffers in DMA-able RAM */ + DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); - SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); - if (SDL_MintAudio_audiobuf[0]==NULL) { - SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); - return (-1); - } - SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; - SDL_MintAudio_numbuf=0; - SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); - SDL_MintAudio_audiosize = spec->size; - SDL_MintAudio_mutex = 0; + SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); + if (SDL_MintAudio_audiobuf[0] == NULL) { + SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); + return (-1); + } + SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; + SDL_MintAudio_numbuf = 0; + SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); + SDL_MintAudio_audiosize = spec->size; + SDL_MintAudio_mutex = 0; - DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); - DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); + DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", + SDL_MintAudio_audiobuf[0])); + DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", + SDL_MintAudio_audiobuf[1])); - /* Setup audio hardware */ - Mint_InitAudio(this, spec); + /* Setup audio hardware */ + Mint_InitAudio (this, spec); - return(1); /* We don't use threaded audio */ + return (1); /* We don't use threaded audio */ } -static void Mint_GsxbInterrupt(void) +static void +Mint_GsxbInterrupt (void) { - Uint8 *newbuf; + Uint8 *newbuf; - if (SDL_MintAudio_mutex) - return; + if (SDL_MintAudio_mutex) + return; - SDL_MintAudio_mutex=1; + SDL_MintAudio_mutex = 1; - SDL_MintAudio_numbuf ^= 1; - SDL_MintAudio_Callback(); - newbuf = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; - Setbuffer(0, newbuf, newbuf + SDL_MintAudio_audiosize); + SDL_MintAudio_numbuf ^= 1; + SDL_MintAudio_Callback (); + newbuf = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; + Setbuffer (0, newbuf, newbuf + SDL_MintAudio_audiosize); - SDL_MintAudio_mutex=0; + SDL_MintAudio_mutex = 0; } -static void Mint_GsxbNullInterrupt(void) +static void +Mint_GsxbNullInterrupt (void) { } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_gsxb.h b/src/audio/mint/SDL_mintaudio_gsxb.h index 595e313db..4e84d5ed0 100644 --- a/src/audio/mint/SDL_mintaudio_gsxb.h +++ b/src/audio/mint/SDL_mintaudio_gsxb.h @@ -30,7 +30,7 @@ #ifndef _SDL_mintaudio_gsxb_h #define _SDL_mintaudio_gsxb_h -#include /* for trap_14_xxx macros */ +#include /* for trap_14_xxx macros */ /* GSXB Cookie */ @@ -42,12 +42,12 @@ /* NSoundcmd modes */ -#define SETRATE 7 /* Set sample rate */ -#define SET8BITFORMAT 8 /* 8 bits format */ -#define SET16BITFORMAT 9 /* 16 bits format */ -#define SET24BITFORMAT 10 /* 24 bits format */ -#define SET32BITFORMAT 11 /* 32 bits format */ -#define LTATTEN_MASTER 12 /* Attenuation */ +#define SETRATE 7 /* Set sample rate */ +#define SET8BITFORMAT 8 /* 8 bits format */ +#define SET16BITFORMAT 9 /* 16 bits format */ +#define SET24BITFORMAT 10 /* 24 bits format */ +#define SET32BITFORMAT 11 /* 32 bits format */ +#define LTATTEN_MASTER 12 /* Attenuation */ #define RTATTEN_MASTER 13 #define LTATTEN_MICIN 14 #define RTATTEN_MICIN 15 @@ -106,3 +106,4 @@ (long)(inth_addr)) #endif /* _SDL_mintaudio_gsxb_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_mcsn.c b/src/audio/mint/SDL_mintaudio_mcsn.c index 9741a3bea..9ddd4de30 100644 --- a/src/audio/mint/SDL_mintaudio_mcsn.c +++ b/src/audio/mint/SDL_mintaudio_mcsn.c @@ -66,333 +66,353 @@ static cookie_mcsn_t *cookie_mcsn; /*--- Audio driver functions ---*/ -static void Mint_CloseAudio(_THIS); -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_LockAudio(_THIS); -static void Mint_UnlockAudio(_THIS); +static void Mint_CloseAudio (_THIS); +static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_LockAudio (_THIS); +static void Mint_UnlockAudio (_THIS); /* To check/init hardware audio */ -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec); +static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); /*--- Audio driver bootstrap functions ---*/ -static int Audio_Available(void) +static int +Audio_Available (void) { - unsigned long dummy; - const char *envr = SDL_getenv("SDL_AUDIODRIVER"); + unsigned long dummy; + const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); - SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); + SDL_MintAudio_mint_present = (Getcookie (C_MiNT, &dummy) == C_FOUND); - /* We can't use XBIOS in interrupt with Magic, don't know about thread */ - if (Getcookie(C_MagX, &dummy) == C_FOUND) { - return(0); - } + /* We can't use XBIOS in interrupt with Magic, don't know about thread */ + if (Getcookie (C_MagX, &dummy) == C_FOUND) { + return (0); + } - /* Check if user asked a different audio driver */ - if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) { - DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); - return(0); - } + /* Check if user asked a different audio driver */ + if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { + DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); + return (0); + } - /* Cookie _MCH present ? if not, assume ST machine */ - if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) { - cookie_mch = MCH_ST; - } + /* Cookie _MCH present ? if not, assume ST machine */ + if (Getcookie (C__MCH, &cookie_mch) == C_NOTFOUND) { + cookie_mch = MCH_ST; + } - /* Cookie _SND present ? if not, assume ST machine */ - if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { - cookie_snd = SND_PSG; - } + /* Cookie _SND present ? if not, assume ST machine */ + if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { + cookie_snd = SND_PSG; + } - /* Check if we have 16 bits audio */ - if ((cookie_snd & SND_16BIT)==0) { - DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n")); - return(0); - } + /* Check if we have 16 bits audio */ + if ((cookie_snd & SND_16BIT) == 0) { + DEBUG_PRINT ((DEBUG_NAME "no 16 bits sound\n")); + return (0); + } - /* Cookie MCSN present ? */ - if (Getcookie(C_McSn, (long *) &cookie_mcsn) != C_FOUND) { - DEBUG_PRINT((DEBUG_NAME "no MCSN audio\n")); - return(0); - } + /* Cookie MCSN present ? */ + if (Getcookie (C_McSn, (long *) &cookie_mcsn) != C_FOUND) { + DEBUG_PRINT ((DEBUG_NAME "no MCSN audio\n")); + return (0); + } - /* Check if interrupt at end of replay */ - if (cookie_mcsn->pint == 0) { - DEBUG_PRINT((DEBUG_NAME "no interrupt at end of replay\n")); - return(0); - } + /* Check if interrupt at end of replay */ + if (cookie_mcsn->pint == 0) { + DEBUG_PRINT ((DEBUG_NAME "no interrupt at end of replay\n")); + return (0); + } - /* Check if audio is lockable */ - if (Locksnd()!=1) { - DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); - return(0); - } + /* Check if audio is lockable */ + if (Locksnd () != 1) { + DEBUG_PRINT ((DEBUG_NAME "audio locked by other application\n")); + return (0); + } - Unlocksnd(); + Unlocksnd (); - DEBUG_PRINT((DEBUG_NAME "MCSN audio available!\n")); - return(1); + DEBUG_PRINT ((DEBUG_NAME "MCSN audio available!\n")); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; + SDL_AudioDevice *this; - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ - this->OpenAudio = Mint_OpenAudio; - this->CloseAudio = Mint_CloseAudio; - this->LockAudio = Mint_LockAudio; + this->OpenAudio = Mint_OpenAudio; + this->CloseAudio = Mint_CloseAudio; + this->LockAudio = Mint_LockAudio; this->UnlockAudio = Mint_UnlockAudio; - this->free = Audio_DeleteDevice; + this->free = Audio_DeleteDevice; return this; } AudioBootStrap MINTAUDIO_MCSN_bootstrap = { - MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver", - Audio_Available, Audio_CreateDevice + MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver", + Audio_Available, Audio_CreateDevice }; -static void Mint_LockAudio(_THIS) +static void +Mint_LockAudio (_THIS) { - /* Stop replay */ - Buffoper(0); + /* Stop replay */ + Buffoper (0); } -static void Mint_UnlockAudio(_THIS) +static void +Mint_UnlockAudio (_THIS) { - /* Restart replay */ - Buffoper(SB_PLA_ENA|SB_PLA_RPT); + /* Restart replay */ + Buffoper (SB_PLA_ENA | SB_PLA_RPT); } -static void Mint_CloseAudio(_THIS) +static void +Mint_CloseAudio (_THIS) { - /* Stop replay */ - SDL_MintAudio_WaitThread(); - Buffoper(0); + /* Stop replay */ + SDL_MintAudio_WaitThread (); + Buffoper (0); - if (!SDL_MintAudio_mint_present) { - /* Uninstall interrupt */ - Jdisint(MFP_DMASOUND); - } + if (!SDL_MintAudio_mint_present) { + /* Uninstall interrupt */ + Jdisint (MFP_DMASOUND); + } - /* Wait if currently playing sound */ - while (SDL_MintAudio_mutex != 0) { - } + /* Wait if currently playing sound */ + while (SDL_MintAudio_mutex != 0) { + } - /* Clear buffers */ - if (SDL_MintAudio_audiobuf[0]) { - Mfree(SDL_MintAudio_audiobuf[0]); - SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; - } + /* Clear buffers */ + if (SDL_MintAudio_audiobuf[0]) { + Mfree (SDL_MintAudio_audiobuf[0]); + SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; + } - /* Unlock sound system */ - Unlocksnd(); + /* Unlock sound system */ + Unlocksnd (); } -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) { - int i; - unsigned long masterclock, masterprediv; - - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); - - /* Check formats available */ - MINTAUDIO_freqcount=0; - switch(cookie_mcsn->play) { - case MCSN_ST: - spec->channels=1; - spec->format=8; /* FIXME: is it signed or unsigned ? */ - SDL_MintAudio_AddFrequency(this, 12500, 0, 0, -1); - break; - case MCSN_TT: /* Also STE, Mega STE */ - spec->format=AUDIO_S8; - masterclock=MASTERCLOCK_STE; - masterprediv=MASTERPREDIV_STE; - if ((cookie_mch>>16)==MCH_TT) { - masterclock=MASTERCLOCK_TT; - masterprediv=MASTERPREDIV_TT; - } - for (i=0; i<4; i++) { - SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<res1 != 0) { - for (i=1; i<4; i++) { - SDL_MintAudio_AddFrequency(this, (cookie_mcsn->res1)/(MASTERPREDIV_FALCON*(1<format |= 0x8000; /* Audio is always signed */ - if ((spec->format & 0x00ff)==16) { - spec->format |= 0x1000; /* Audio is always big endian */ - spec->channels=2; /* 16 bits always stereo */ - } - break; - } + int i; + unsigned long masterclock, masterprediv; + + DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); + + /* Check formats available */ + MINTAUDIO_freqcount = 0; + switch (cookie_mcsn->play) { + case MCSN_ST: + spec->channels = 1; + spec->format = 8; /* FIXME: is it signed or unsigned ? */ + SDL_MintAudio_AddFrequency (this, 12500, 0, 0, -1); + break; + case MCSN_TT: /* Also STE, Mega STE */ + spec->format = AUDIO_S8; + masterclock = MASTERCLOCK_STE; + masterprediv = MASTERPREDIV_STE; + if ((cookie_mch >> 16) == MCH_TT) { + masterclock = MASTERCLOCK_TT; + masterprediv = MASTERPREDIV_TT; + } + for (i = 0; i < 4; i++) { + SDL_MintAudio_AddFrequency (this, + masterclock / (masterprediv * + (1 << i)), + masterclock, 3 - i, -1); + } + break; + case MCSN_FALCON: /* Also Mac */ + for (i = 1; i < 12; i++) { + /* Remove unusable Falcon codec predivisors */ + if ((i == 6) || (i == 8) || (i == 10)) { + continue; + } + SDL_MintAudio_AddFrequency (this, + MASTERCLOCK_FALCON1 / + (MASTERPREDIV_FALCON * (i + 1)), + CLK25M, i + 1, -1); + } + if (cookie_mcsn->res1 != 0) { + for (i = 1; i < 4; i++) { + SDL_MintAudio_AddFrequency (this, + (cookie_mcsn->res1) / + (MASTERPREDIV_FALCON * + (1 << i)), CLKEXT, + (1 << i) - 1, -1); + } + } + spec->format |= 0x8000; /* Audio is always signed */ + if ((spec->format & 0x00ff) == 16) { + spec->format |= 0x1000; /* Audio is always big endian */ + spec->channels = 2; /* 16 bits always stereo */ + } + break; + } #if 1 - for (i=0; ifreq); - spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; + MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); + spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); + DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); - return 0; + return 0; } -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) +static void +Mint_InitAudio (_THIS, SDL_AudioSpec * spec) { - int channels_mode, prediv, dmaclock; - void *buffer; - - /* Stop currently playing sound */ - SDL_MintAudio_quit_thread = SDL_FALSE; - SDL_MintAudio_thread_finished = SDL_TRUE; - SDL_MintAudio_WaitThread(); - Buffoper(0); - - /* Set replay tracks */ - Settracks(0,0); - Setmontracks(0); - - /* Select replay format */ - channels_mode=STEREO16; - switch (spec->format & 0xff) { - case 8: - if (spec->channels==2) { - channels_mode=STEREO8; - } else { - channels_mode=MONO8; - } - break; - } - if (Setmode(channels_mode)<0) { - DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); - } + int channels_mode, prediv, dmaclock; + void *buffer; + + /* Stop currently playing sound */ + SDL_MintAudio_quit_thread = SDL_FALSE; + SDL_MintAudio_thread_finished = SDL_TRUE; + SDL_MintAudio_WaitThread (); + Buffoper (0); + + /* Set replay tracks */ + Settracks (0, 0); + Setmontracks (0); + + /* Select replay format */ + channels_mode = STEREO16; + switch (spec->format & 0xff) { + case 8: + if (spec->channels == 2) { + channels_mode = STEREO8; + } else { + channels_mode = MONO8; + } + break; + } + if (Setmode (channels_mode) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setmode() failed\n")); + } - dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; - prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; - switch(cookie_mcsn->play) { - case MCSN_TT: - Devconnect(DMAPLAY, DAC, CLK25M, CLKOLD, 1); - Soundcmd(SETPRESCALE, prediv); - DEBUG_PRINT((DEBUG_NAME "STE/TT prescaler selected\n")); - break; - case MCSN_FALCON: - Devconnect(DMAPLAY, DAC, dmaclock, prediv, 1); - DEBUG_PRINT((DEBUG_NAME "Falcon prescaler selected\n")); - break; - } + dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; + prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; + switch (cookie_mcsn->play) { + case MCSN_TT: + Devconnect (DMAPLAY, DAC, CLK25M, CLKOLD, 1); + Soundcmd (SETPRESCALE, prediv); + DEBUG_PRINT ((DEBUG_NAME "STE/TT prescaler selected\n")); + break; + case MCSN_FALCON: + Devconnect (DMAPLAY, DAC, dmaclock, prediv, 1); + DEBUG_PRINT ((DEBUG_NAME "Falcon prescaler selected\n")); + break; + } - /* Set buffer */ - buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; - if (Setbuffer(0, buffer, buffer + spec->size)<0) { - DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); - } - - if (SDL_MintAudio_mint_present) { - SDL_MintAudio_thread_pid = tfork(SDL_MintAudio_Thread, 0); - } else { - /* Install interrupt */ - Jdisint(MFP_DMASOUND); - Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); - Jenabint(MFP_DMASOUND); - - if (Setinterrupt(SI_TIMERA, SI_PLAY)<0) { - DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n")); - } - } + /* Set buffer */ + buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; + if (Setbuffer (0, buffer, buffer + spec->size) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setbuffer() failed\n")); + } - /* Go */ - Buffoper(SB_PLA_ENA|SB_PLA_RPT); - DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); + if (SDL_MintAudio_mint_present) { + SDL_MintAudio_thread_pid = tfork (SDL_MintAudio_Thread, 0); + } else { + /* Install interrupt */ + Jdisint (MFP_DMASOUND); + Xbtimer (XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); + Jenabint (MFP_DMASOUND); + + if (Setinterrupt (SI_TIMERA, SI_PLAY) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setinterrupt() failed\n")); + } + } + + /* Go */ + Buffoper (SB_PLA_ENA | SB_PLA_RPT); + DEBUG_PRINT ((DEBUG_NAME "hardware initialized\n")); } -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) { - /* Lock sound system */ - if (Locksnd()!=1) { - SDL_SetError("Mint_OpenAudio: Audio system already in use"); - return(-1); - } + /* Lock sound system */ + if (Locksnd () != 1) { + SDL_SetError ("Mint_OpenAudio: Audio system already in use"); + return (-1); + } - SDL_MintAudio_device = this; + SDL_MintAudio_device = this; - /* Check audio capabilities */ - if (Mint_CheckAudio(this, spec)==-1) { - return -1; - } + /* Check audio capabilities */ + if (Mint_CheckAudio (this, spec) == -1) { + return -1; + } - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); - /* Allocate memory for audio buffers in DMA-able RAM */ - DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); + /* Allocate memory for audio buffers in DMA-able RAM */ + DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); - SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); - if (SDL_MintAudio_audiobuf[0]==NULL) { - SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); - return (-1); - } - SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; - SDL_MintAudio_numbuf=0; - SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); - SDL_MintAudio_audiosize = spec->size; - SDL_MintAudio_mutex = 0; + SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); + if (SDL_MintAudio_audiobuf[0] == NULL) { + SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); + return (-1); + } + SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; + SDL_MintAudio_numbuf = 0; + SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); + SDL_MintAudio_audiosize = spec->size; + SDL_MintAudio_mutex = 0; - DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); - DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); + DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", + SDL_MintAudio_audiobuf[0])); + DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", + SDL_MintAudio_audiobuf[1])); - /* Setup audio hardware */ - Mint_InitAudio(this, spec); + /* Setup audio hardware */ + Mint_InitAudio (this, spec); - return(1); /* We don't use SDL threaded audio */ + return (1); /* We don't use SDL threaded audio */ } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_mcsn.h b/src/audio/mint/SDL_mintaudio_mcsn.h index f253ddd88..c7b5e4de6 100644 --- a/src/audio/mint/SDL_mintaudio_mcsn.h +++ b/src/audio/mint/SDL_mintaudio_mcsn.h @@ -30,30 +30,33 @@ #ifndef _SDL_mintaudio_mcsh_h #define _SDL_mintaudio_mcsh_h -typedef struct { - unsigned short version; /* Version */ - unsigned short size; /* Size of structure */ - - unsigned short play; /* Replay capability */ - unsigned short record; /* Record capability */ - unsigned short dsp; /* DSP56K present */ - unsigned short pint; /* Interrupt at end of replay */ - unsigned short rint; /* Interrupt at end of record */ - - unsigned long res1; /* Frequency of external clock */ - unsigned long res2; - unsigned long res3; - unsigned long res4; -} cookie_mcsn_t __attribute__((packed)); - -enum { - MCSN_ST=0, - MCSN_TT, - MCSN_STE=MCSN_TT, - MCSN_FALCON, - MCSN_MAC=MCSN_FALCON +typedef struct +{ + unsigned short version; /* Version */ + unsigned short size; /* Size of structure */ + + unsigned short play; /* Replay capability */ + unsigned short record; /* Record capability */ + unsigned short dsp; /* DSP56K present */ + unsigned short pint; /* Interrupt at end of replay */ + unsigned short rint; /* Interrupt at end of record */ + + unsigned long res1; /* Frequency of external clock */ + unsigned long res2; + unsigned long res3; + unsigned long res4; +} cookie_mcsn_t __attribute__ ((packed)); + +enum +{ + MCSN_ST = 0, + MCSN_TT, + MCSN_STE = MCSN_TT, + MCSN_FALCON, + MCSN_MAC = MCSN_FALCON }; -#define SETSMPFREQ 7 /* Set sample frequency */ +#define SETSMPFREQ 7 /* Set sample frequency */ #endif /* _SDL_mintaudio_mcsh_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_stfa.c b/src/audio/mint/SDL_mintaudio_stfa.c index 552a7b224..64281299f 100644 --- a/src/audio/mint/SDL_mintaudio_stfa.c +++ b/src/audio/mint/SDL_mintaudio_stfa.c @@ -62,256 +62,270 @@ static unsigned long cookie_snd, cookie_mch; static cookie_stfa_t *cookie_stfa; -static const int freqs[16]={ - 4995, 6269, 7493, 8192, - 9830, 10971, 12538, 14985, - 16384, 19819, 21943, 24576, - 30720, 32336, 43885, 49152 +static const int freqs[16] = { + 4995, 6269, 7493, 8192, + 9830, 10971, 12538, 14985, + 16384, 19819, 21943, 24576, + 30720, 32336, 43885, 49152 }; /*--- Audio driver functions ---*/ -static void Mint_CloseAudio(_THIS); -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_LockAudio(_THIS); -static void Mint_UnlockAudio(_THIS); +static void Mint_CloseAudio (_THIS); +static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_LockAudio (_THIS); +static void Mint_UnlockAudio (_THIS); /* To check/init hardware audio */ -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec); +static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); /*--- Audio driver bootstrap functions ---*/ -static int Audio_Available(void) +static int +Audio_Available (void) { - const char *envr = SDL_getenv("SDL_AUDIODRIVER"); + const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); - /* Check if user asked a different audio driver */ - if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) { - DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); - return(0); - } + /* Check if user asked a different audio driver */ + if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { + DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); + return (0); + } - /* Cookie _MCH present ? if not, assume ST machine */ - if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) { - cookie_mch = MCH_ST; - } + /* Cookie _MCH present ? if not, assume ST machine */ + if (Getcookie (C__MCH, &cookie_mch) == C_NOTFOUND) { + cookie_mch = MCH_ST; + } - /* Cookie _SND present ? if not, assume ST machine */ - if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { - cookie_snd = SND_PSG; - } + /* Cookie _SND present ? if not, assume ST machine */ + if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { + cookie_snd = SND_PSG; + } - /* Cookie STFA present ? */ - if (Getcookie(C_STFA, (long *) &cookie_stfa) != C_FOUND) { - DEBUG_PRINT((DEBUG_NAME "no STFA audio\n")); - return(0); - } + /* Cookie STFA present ? */ + if (Getcookie (C_STFA, (long *) &cookie_stfa) != C_FOUND) { + DEBUG_PRINT ((DEBUG_NAME "no STFA audio\n")); + return (0); + } - SDL_MintAudio_stfa = cookie_stfa; + SDL_MintAudio_stfa = cookie_stfa; - DEBUG_PRINT((DEBUG_NAME "STFA audio available!\n")); - return(1); + DEBUG_PRINT ((DEBUG_NAME "STFA audio available!\n")); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; + SDL_AudioDevice *this; - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ - this->OpenAudio = Mint_OpenAudio; - this->CloseAudio = Mint_CloseAudio; - this->LockAudio = Mint_LockAudio; + this->OpenAudio = Mint_OpenAudio; + this->CloseAudio = Mint_CloseAudio; + this->LockAudio = Mint_LockAudio; this->UnlockAudio = Mint_UnlockAudio; - this->free = Audio_DeleteDevice; + this->free = Audio_DeleteDevice; return this; } AudioBootStrap MINTAUDIO_STFA_bootstrap = { - MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver", - Audio_Available, Audio_CreateDevice + MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver", + Audio_Available, Audio_CreateDevice }; -static void Mint_LockAudio(_THIS) +static void +Mint_LockAudio (_THIS) { - void *oldpile; + void *oldpile; - /* Stop replay */ - oldpile=(void *)Super(0); - cookie_stfa->sound_enable=STFA_PLAY_DISABLE; - Super(oldpile); + /* Stop replay */ + oldpile = (void *) Super (0); + cookie_stfa->sound_enable = STFA_PLAY_DISABLE; + Super (oldpile); } -static void Mint_UnlockAudio(_THIS) +static void +Mint_UnlockAudio (_THIS) { - void *oldpile; + void *oldpile; - /* Restart replay */ - oldpile=(void *)Super(0); - cookie_stfa->sound_enable=STFA_PLAY_ENABLE|STFA_PLAY_REPEAT; - Super(oldpile); + /* Restart replay */ + oldpile = (void *) Super (0); + cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT; + Super (oldpile); } -static void Mint_CloseAudio(_THIS) +static void +Mint_CloseAudio (_THIS) { - void *oldpile; + void *oldpile; - /* Stop replay */ - oldpile=(void *)Super(0); - cookie_stfa->sound_enable=STFA_PLAY_DISABLE; - Super(oldpile); + /* Stop replay */ + oldpile = (void *) Super (0); + cookie_stfa->sound_enable = STFA_PLAY_DISABLE; + Super (oldpile); - /* Wait if currently playing sound */ - while (SDL_MintAudio_mutex != 0) { - } + /* Wait if currently playing sound */ + while (SDL_MintAudio_mutex != 0) { + } - /* Clear buffers */ - if (SDL_MintAudio_audiobuf[0]) { - Mfree(SDL_MintAudio_audiobuf[0]); - SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; - } + /* Clear buffers */ + if (SDL_MintAudio_audiobuf[0]) { + Mfree (SDL_MintAudio_audiobuf[0]); + SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; + } } -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) { - int i; - - DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); - - /* Check formats available */ - MINTAUDIO_freqcount=0; - for (i=0;i<16;i++) { - SDL_MintAudio_AddFrequency(this, freqs[i], 0, i, -1); - } + int i; + + DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); + + /* Check formats available */ + MINTAUDIO_freqcount = 0; + for (i = 0; i < 16; i++) { + SDL_MintAudio_AddFrequency (this, freqs[i], 0, i, -1); + } #if 1 - for (i=0; ifreq); - spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; + MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); + spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); + DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); - return 0; + return 0; } -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) +static void +Mint_InitAudio (_THIS, SDL_AudioSpec * spec) { - void *buffer; - void *oldpile; + void *buffer; + void *oldpile; - buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; + buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; - oldpile=(void *)Super(0); + oldpile = (void *) Super (0); - /* Stop replay */ - cookie_stfa->sound_enable=STFA_PLAY_DISABLE; + /* Stop replay */ + cookie_stfa->sound_enable = STFA_PLAY_DISABLE; - /* Select replay format */ - cookie_stfa->sound_control = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; - if ((spec->format & 0xff)==8) { - cookie_stfa->sound_control |= STFA_FORMAT_8BIT; - } else { - cookie_stfa->sound_control |= STFA_FORMAT_16BIT; - } - if (spec->channels==2) { - cookie_stfa->sound_control |= STFA_FORMAT_STEREO; - } else { - cookie_stfa->sound_control |= STFA_FORMAT_MONO; - } - if ((spec->format & 0x8000)!=0) { - cookie_stfa->sound_control |= STFA_FORMAT_SIGNED; - } else { - cookie_stfa->sound_control |= STFA_FORMAT_UNSIGNED; - } - if ((spec->format & 0x1000)!=0) { - cookie_stfa->sound_control |= STFA_FORMAT_BIGENDIAN; - } else { - cookie_stfa->sound_control |= STFA_FORMAT_LITENDIAN; - } + /* Select replay format */ + cookie_stfa->sound_control = + MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; + if ((spec->format & 0xff) == 8) { + cookie_stfa->sound_control |= STFA_FORMAT_8BIT; + } else { + cookie_stfa->sound_control |= STFA_FORMAT_16BIT; + } + if (spec->channels == 2) { + cookie_stfa->sound_control |= STFA_FORMAT_STEREO; + } else { + cookie_stfa->sound_control |= STFA_FORMAT_MONO; + } + if ((spec->format & 0x8000) != 0) { + cookie_stfa->sound_control |= STFA_FORMAT_SIGNED; + } else { + cookie_stfa->sound_control |= STFA_FORMAT_UNSIGNED; + } + if ((spec->format & 0x1000) != 0) { + cookie_stfa->sound_control |= STFA_FORMAT_BIGENDIAN; + } else { + cookie_stfa->sound_control |= STFA_FORMAT_LITENDIAN; + } - /* Set buffer */ - cookie_stfa->sound_start = (unsigned long) buffer; - cookie_stfa->sound_end = (unsigned long) (buffer + spec->size); + /* Set buffer */ + cookie_stfa->sound_start = (unsigned long) buffer; + cookie_stfa->sound_end = (unsigned long) (buffer + spec->size); - /* Set interrupt */ - cookie_stfa->stfa_it = SDL_MintAudio_StfaInterrupt; + /* Set interrupt */ + cookie_stfa->stfa_it = SDL_MintAudio_StfaInterrupt; - /* Restart replay */ - cookie_stfa->sound_enable=STFA_PLAY_ENABLE|STFA_PLAY_REPEAT; + /* Restart replay */ + cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT; - Super(oldpile); + Super (oldpile); - DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); + DEBUG_PRINT ((DEBUG_NAME "hardware initialized\n")); } -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) { - SDL_MintAudio_device = this; + SDL_MintAudio_device = this; - /* Check audio capabilities */ - if (Mint_CheckAudio(this, spec)==-1) { - return -1; - } + /* Check audio capabilities */ + if (Mint_CheckAudio (this, spec) == -1) { + return -1; + } - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); - /* Allocate memory for audio buffers in DMA-able RAM */ - DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); + /* Allocate memory for audio buffers in DMA-able RAM */ + DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); - SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); - if (SDL_MintAudio_audiobuf[0]==NULL) { - SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); - return (-1); - } - SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; - SDL_MintAudio_numbuf=0; - SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); - SDL_MintAudio_audiosize = spec->size; - SDL_MintAudio_mutex = 0; + SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); + if (SDL_MintAudio_audiobuf[0] == NULL) { + SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); + return (-1); + } + SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; + SDL_MintAudio_numbuf = 0; + SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); + SDL_MintAudio_audiosize = spec->size; + SDL_MintAudio_mutex = 0; - DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); - DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); + DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", + SDL_MintAudio_audiobuf[0])); + DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", + SDL_MintAudio_audiobuf[1])); - /* Setup audio hardware */ - Mint_InitAudio(this, spec); + /* Setup audio hardware */ + Mint_InitAudio (this, spec); - return(1); /* We don't use threaded audio */ + return (1); /* We don't use threaded audio */ } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_stfa.h b/src/audio/mint/SDL_mintaudio_stfa.h index d4bf2d6b4..abf6c3af7 100644 --- a/src/audio/mint/SDL_mintaudio_stfa.h +++ b/src/audio/mint/SDL_mintaudio_stfa.h @@ -32,7 +32,7 @@ /*--- Defines ---*/ -#define C_STFA 0x53544641L /* Sound treiber für atari (seb/The removers) */ +#define C_STFA 0x53544641L /* Sound treiber für atari (seb/The removers) */ #define STFA_PLAY_ENABLE (1<<0) #define STFA_PLAY_DISABLE (0<<0) @@ -48,53 +48,56 @@ #define STFA_FORMAT_LITENDIAN (1<<9) #define STFA_FORMAT_BIGENDIAN (0<<9) #define STFA_FORMAT_FREQ_MASK 0x0f -enum { - STFA_FORMAT_F4995=0, - STFA_FORMAT_F6269, - STFA_FORMAT_F7493, - STFA_FORMAT_F8192, - - STFA_FORMAT_F9830, - STFA_FORMAT_F10971, - STFA_FORMAT_F12538, - STFA_FORMAT_F14985, - - STFA_FORMAT_F16384, - STFA_FORMAT_F19819, - STFA_FORMAT_F21943, - STFA_FORMAT_F24576, - - STFA_FORMAT_F30720, - STFA_FORMAT_F32336, - STFA_FORMAT_F43885, - STFA_FORMAT_F49152 +enum +{ + STFA_FORMAT_F4995 = 0, + STFA_FORMAT_F6269, + STFA_FORMAT_F7493, + STFA_FORMAT_F8192, + + STFA_FORMAT_F9830, + STFA_FORMAT_F10971, + STFA_FORMAT_F12538, + STFA_FORMAT_F14985, + + STFA_FORMAT_F16384, + STFA_FORMAT_F19819, + STFA_FORMAT_F21943, + STFA_FORMAT_F24576, + + STFA_FORMAT_F30720, + STFA_FORMAT_F32336, + STFA_FORMAT_F43885, + STFA_FORMAT_F49152 }; /*--- Types ---*/ -typedef struct { - unsigned short sound_enable; - unsigned short sound_control; - unsigned short sound_output; - unsigned long sound_start; - unsigned long sound_current; - unsigned long sound_end; - unsigned short version; - void *old_vbl; - void *old_timera; - unsigned long old_mfp_status; - void *new_vbl; - void *drivers_list; - void *play_stop; - unsigned short frequency; - void *set_frequency; - - unsigned short frequency_threshold; - unsigned short *custom_freq_table; - unsigned short stfa_on_off; - void *new_drivers_list; - unsigned long old_bit_2_of_cookie_snd; - void (*stfa_it)(void); -} cookie_stfa_t __attribute__((packed)); +typedef struct +{ + unsigned short sound_enable; + unsigned short sound_control; + unsigned short sound_output; + unsigned long sound_start; + unsigned long sound_current; + unsigned long sound_end; + unsigned short version; + void *old_vbl; + void *old_timera; + unsigned long old_mfp_status; + void *new_vbl; + void *drivers_list; + void *play_stop; + unsigned short frequency; + void *set_frequency; + + unsigned short frequency_threshold; + unsigned short *custom_freq_table; + unsigned short stfa_on_off; + void *new_drivers_list; + unsigned long old_bit_2_of_cookie_snd; + void (*stfa_it) (void); +} cookie_stfa_t __attribute__ ((packed)); #endif /* _SDL_mintaudio_stfa_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mint/SDL_mintaudio_xbios.c b/src/audio/mint/SDL_mintaudio_xbios.c index 016d4fa59..a4b83788d 100644 --- a/src/audio/mint/SDL_mintaudio_xbios.c +++ b/src/audio/mint/SDL_mintaudio_xbios.c @@ -66,422 +66,455 @@ static unsigned long cookie_snd; /*--- Audio driver functions ---*/ -static void Mint_CloseAudio(_THIS); -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_LockAudio(_THIS); -static void Mint_UnlockAudio(_THIS); +static void Mint_CloseAudio (_THIS); +static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_LockAudio (_THIS); +static void Mint_UnlockAudio (_THIS); /* To check/init hardware audio */ -static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec); -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec); +static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); +static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); /*--- Audio driver bootstrap functions ---*/ -static int Audio_Available(void) +static int +Audio_Available (void) { - unsigned long dummy; - const char *envr = SDL_getenv("SDL_AUDIODRIVER"); + unsigned long dummy; + const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); - SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); + SDL_MintAudio_mint_present = (Getcookie (C_MiNT, &dummy) == C_FOUND); - /* We can't use XBIOS in interrupt with Magic, don't know about thread */ - if (Getcookie(C_MagX, &dummy) == C_FOUND) { - return(0); - } + /* We can't use XBIOS in interrupt with Magic, don't know about thread */ + if (Getcookie (C_MagX, &dummy) == C_FOUND) { + return (0); + } - /* Check if user asked a different audio driver */ - if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) { - DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); - return(0); - } + /* Check if user asked a different audio driver */ + if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { + DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); + return (0); + } - /* Cookie _SND present ? if not, assume ST machine */ - if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { - cookie_snd = SND_PSG; - } + /* Cookie _SND present ? if not, assume ST machine */ + if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { + cookie_snd = SND_PSG; + } - /* Check if we have 16 bits audio */ - if ((cookie_snd & SND_16BIT)==0) { - DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n")); - return(0); - } + /* Check if we have 16 bits audio */ + if ((cookie_snd & SND_16BIT) == 0) { + DEBUG_PRINT ((DEBUG_NAME "no 16 bits sound\n")); + return (0); + } - /* Check if audio is lockable */ - if (Locksnd()!=1) { - DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); - return(0); - } + /* Check if audio is lockable */ + if (Locksnd () != 1) { + DEBUG_PRINT ((DEBUG_NAME "audio locked by other application\n")); + return (0); + } - Unlocksnd(); + Unlocksnd (); - DEBUG_PRINT((DEBUG_NAME "XBIOS audio available!\n")); - return(1); + DEBUG_PRINT ((DEBUG_NAME "XBIOS audio available!\n")); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; + SDL_AudioDevice *this; - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ - this->OpenAudio = Mint_OpenAudio; - this->CloseAudio = Mint_CloseAudio; - this->LockAudio = Mint_LockAudio; + this->OpenAudio = Mint_OpenAudio; + this->CloseAudio = Mint_CloseAudio; + this->LockAudio = Mint_LockAudio; this->UnlockAudio = Mint_UnlockAudio; - this->free = Audio_DeleteDevice; + this->free = Audio_DeleteDevice; return this; } AudioBootStrap MINTAUDIO_XBIOS_bootstrap = { - MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver", - Audio_Available, Audio_CreateDevice + MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver", + Audio_Available, Audio_CreateDevice }; -static void Mint_LockAudio(_THIS) +static void +Mint_LockAudio (_THIS) { - /* Stop replay */ - Buffoper(0); + /* Stop replay */ + Buffoper (0); } -static void Mint_UnlockAudio(_THIS) +static void +Mint_UnlockAudio (_THIS) { - /* Restart replay */ - Buffoper(SB_PLA_ENA|SB_PLA_RPT); + /* Restart replay */ + Buffoper (SB_PLA_ENA | SB_PLA_RPT); } -static void Mint_CloseAudio(_THIS) +static void +Mint_CloseAudio (_THIS) { - /* Stop replay */ - SDL_MintAudio_WaitThread(); - Buffoper(0); + /* Stop replay */ + SDL_MintAudio_WaitThread (); + Buffoper (0); - if (!SDL_MintAudio_mint_present) { - /* Uninstall interrupt */ - Jdisint(MFP_DMASOUND); - } + if (!SDL_MintAudio_mint_present) { + /* Uninstall interrupt */ + Jdisint (MFP_DMASOUND); + } - /* Wait if currently playing sound */ - while (SDL_MintAudio_mutex != 0) { - } + /* Wait if currently playing sound */ + while (SDL_MintAudio_mutex != 0) { + } - /* Clear buffers */ - if (SDL_MintAudio_audiobuf[0]) { - Mfree(SDL_MintAudio_audiobuf[0]); - SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; - } + /* Clear buffers */ + if (SDL_MintAudio_audiobuf[0]) { + Mfree (SDL_MintAudio_audiobuf[0]); + SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; + } - /* Unlock sound system */ - Unlocksnd(); + /* Unlock sound system */ + Unlocksnd (); } /* Falcon XBIOS implementation of Devconnect() is buggy with external clock */ -static void Devconnect2(int src, int dst, int sclk, int pre) -{ - static const unsigned short MASK1[3] = { 0, 0x6000, 0 }; - static const unsigned short MASK2[4] = { 0xFFF0, 0xFF8F, 0xF0FF, 0x0FFF }; - static const unsigned short INDEX1[4] = { 1, 3, 5, 7 }; - static const unsigned short INDEX2[4] = { 0, 2, 4, 6 }; - unsigned short sync_div,dev_ctrl,dest_ctrl; - void *oldstack; - - if (dst==0) { - return; - } +static void +Devconnect2 (int src, int dst, int sclk, int pre) +{ + static const unsigned short MASK1[3] = { 0, 0x6000, 0 }; + static const unsigned short MASK2[4] = { 0xFFF0, 0xFF8F, 0xF0FF, 0x0FFF }; + static const unsigned short INDEX1[4] = { 1, 3, 5, 7 }; + static const unsigned short INDEX2[4] = { 0, 2, 4, 6 }; + unsigned short sync_div, dev_ctrl, dest_ctrl; + void *oldstack; + + if (dst == 0) { + return; + } - oldstack=(void *)Super(0); + oldstack = (void *) Super (0); - dev_ctrl = DMAAUDIO_IO.dev_ctrl; - dest_ctrl = DMAAUDIO_IO.dest_ctrl; - dev_ctrl &= MASK2[src]; + dev_ctrl = DMAAUDIO_IO.dev_ctrl; + dest_ctrl = DMAAUDIO_IO.dest_ctrl; + dev_ctrl &= MASK2[src]; - if (src==ADC) { - dev_ctrl |= MASK1[sclk]; - } else { - dev_ctrl |= (INDEX1[sclk] << (src<<4)); - } + if (src == ADC) { + dev_ctrl |= MASK1[sclk]; + } else { + dev_ctrl |= (INDEX1[sclk] << (src << 4)); + } - if (dst & DMAREC) { - dest_ctrl &= 0xFFF0; - dest_ctrl |= INDEX1[src]; - } + if (dst & DMAREC) { + dest_ctrl &= 0xFFF0; + dest_ctrl |= INDEX1[src]; + } - if (dst & DSPRECV) { - dest_ctrl &= 0xFF8F; - dest_ctrl |= (INDEX1[src]<<4); - } + if (dst & DSPRECV) { + dest_ctrl &= 0xFF8F; + dest_ctrl |= (INDEX1[src] << 4); + } - if (dst & EXTOUT) { - dest_ctrl &= 0xF0FF; - dest_ctrl |= (INDEX1[src]<<8); - } + if (dst & EXTOUT) { + dest_ctrl &= 0xF0FF; + dest_ctrl |= (INDEX1[src] << 8); + } - if (dst & DAC) { - dev_ctrl &= 0x0FFF; - dev_ctrl |= MASK1[sclk]; - dest_ctrl &= 0x0FFF; - dest_ctrl |= (INDEX2[src]<<12); - } + if (dst & DAC) { + dev_ctrl &= 0x0FFF; + dev_ctrl |= MASK1[sclk]; + dest_ctrl &= 0x0FFF; + dest_ctrl |= (INDEX2[src] << 12); + } - sync_div = DMAAUDIO_IO.sync_div; - if (sclk==CLKEXT) { - pre<<=8; - sync_div &= 0xF0FF; - } else { - sync_div &= 0xFFF0; - } - sync_div |= pre; + sync_div = DMAAUDIO_IO.sync_div; + if (sclk == CLKEXT) { + pre <<= 8; + sync_div &= 0xF0FF; + } else { + sync_div &= 0xFFF0; + } + sync_div |= pre; - DMAAUDIO_IO.dev_ctrl = dev_ctrl; - DMAAUDIO_IO.dest_ctrl = dest_ctrl; - DMAAUDIO_IO.sync_div = sync_div; + DMAAUDIO_IO.dev_ctrl = dev_ctrl; + DMAAUDIO_IO.dest_ctrl = dest_ctrl; + DMAAUDIO_IO.sync_div = sync_div; - Super(oldstack); + Super (oldstack); } -static void Mint_CheckExternalClock(_THIS) +static void +Mint_CheckExternalClock (_THIS) { #define SIZE_BUF_CLOCK_MEASURE (44100/10) - unsigned long cookie_snd; - char *buffer; - int i, j; + unsigned long cookie_snd; + char *buffer; + int i, j; - /* DSP present with its GPIO port ? */ - if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { - return; - } - if ((cookie_snd & SND_DSP)==0) { - return; - } + /* DSP present with its GPIO port ? */ + if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { + return; + } + if ((cookie_snd & SND_DSP) == 0) { + return; + } - buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); - if (buffer==NULL) { - DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); - return; - } - SDL_memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); - - Buffoper(0); - Settracks(0,0); - Setmontracks(0); - Setmode(MONO8); - Jdisint(MFP_TIMERA); - - for (i=0; i<2; i++) { - Gpio(GPIO_SET,7); /* DSP port gpio outputs */ - Gpio(GPIO_WRITE,2+i); /* 22.5792/24.576 MHz for 44.1/48KHz */ - Devconnect2(DMAPLAY, DAC, CLKEXT, CLK50K); /* Matrix and clock source */ - Setbuffer(0, buffer, buffer + SIZE_BUF_CLOCK_MEASURE); /* Set buffer */ - Xbtimer(XB_TIMERA, 5, 38, SDL_MintAudio_XbiosInterruptMeasureClock); /* delay mode timer A, prediv /64, 1KHz */ - Jenabint(MFP_TIMERA); - SDL_MintAudio_clocktics = 0; - Buffoper(SB_PLA_ENA); - usleep(110000); - - if((Buffoper(-1) & 1)==0) { - if (SDL_MintAudio_clocktics) { - unsigned long khz; - - khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE; - DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz)); - - if(khz==44) { - for (j=1; j<4; j++) { - SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_FALCON*(1<format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); - - spec->format |= 0x8000; /* Audio is always signed */ - if ((spec->format & 0x00ff)==16) { - spec->format |= 0x1000; /* Audio is always big endian */ - spec->channels=2; /* 16 bits always stereo */ - } + int i; + Uint32 extclock; + + DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); + + spec->format |= 0x8000; /* Audio is always signed */ + if ((spec->format & 0x00ff) == 16) { + spec->format |= 0x1000; /* Audio is always big endian */ + spec->channels = 2; /* 16 bits always stereo */ + } - MINTAUDIO_freqcount=0; + MINTAUDIO_freqcount = 0; - /* Add external clocks if present */ - Mint_CheckExternalClock(this); + /* Add external clocks if present */ + Mint_CheckExternalClock (this); - /* Standard clocks */ - for (i=1;i<12;i++) { - /* Remove unusable Falcon codec predivisors */ - if ((i==6) || (i==8) || (i==10)) { - continue; - } - SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), MASTERCLOCK_FALCON1, i, -1); - } + /* Standard clocks */ + for (i = 1; i < 12; i++) { + /* Remove unusable Falcon codec predivisors */ + if ((i == 6) || (i == 8) || (i == 10)) { + continue; + } + SDL_MintAudio_AddFrequency (this, + MASTERCLOCK_FALCON1 / + (MASTERPREDIV_FALCON * (i + 1)), + MASTERCLOCK_FALCON1, i, -1); + } #if 1 - for (i=0; ifreq); - spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; + MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); + spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; - DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); - DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); - DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); - DEBUG_PRINT(("channels=%d, ", spec->channels)); - DEBUG_PRINT(("freq=%d\n", spec->freq)); + DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); + DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); + DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); + DEBUG_PRINT (("channels=%d, ", spec->channels)); + DEBUG_PRINT (("freq=%d\n", spec->freq)); - return 0; + return 0; } -static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) +static void +Mint_InitAudio (_THIS, SDL_AudioSpec * spec) { - int channels_mode, dmaclock, prediv; - void *buffer; - - /* Stop currently playing sound */ - SDL_MintAudio_quit_thread = SDL_FALSE; - SDL_MintAudio_thread_finished = SDL_TRUE; - SDL_MintAudio_WaitThread(); - Buffoper(0); - - /* Set replay tracks */ - Settracks(0,0); - Setmontracks(0); - - /* Select replay format */ - channels_mode=STEREO16; - switch (spec->format & 0xff) { - case 8: - if (spec->channels==2) { - channels_mode=STEREO8; - } else { - channels_mode=MONO8; - } - break; - } - if (Setmode(channels_mode)<0) { - DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); - } + int channels_mode, dmaclock, prediv; + void *buffer; + + /* Stop currently playing sound */ + SDL_MintAudio_quit_thread = SDL_FALSE; + SDL_MintAudio_thread_finished = SDL_TRUE; + SDL_MintAudio_WaitThread (); + Buffoper (0); + + /* Set replay tracks */ + Settracks (0, 0); + Setmontracks (0); + + /* Select replay format */ + channels_mode = STEREO16; + switch (spec->format & 0xff) { + case 8: + if (spec->channels == 2) { + channels_mode = STEREO8; + } else { + channels_mode = MONO8; + } + break; + } + if (Setmode (channels_mode) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setmode() failed\n")); + } - dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; - prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; - if (MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits != -1) { - Gpio(GPIO_SET,7); /* DSP port gpio outputs */ - Gpio(GPIO_WRITE, MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits); - Devconnect2(DMAPLAY, DAC|EXTOUT, CLKEXT, prediv); - } else { - Devconnect2(DMAPLAY, DAC, CLK25M, prediv); - } + dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; + prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; + if (MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits != -1) { + Gpio (GPIO_SET, 7); /* DSP port gpio outputs */ + Gpio (GPIO_WRITE, MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits); + Devconnect2 (DMAPLAY, DAC | EXTOUT, CLKEXT, prediv); + } else { + Devconnect2 (DMAPLAY, DAC, CLK25M, prediv); + } - /* Set buffer */ - buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; - if (Setbuffer(0, buffer, buffer + spec->size)<0) { - DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); - } - - if (SDL_MintAudio_mint_present) { - SDL_MintAudio_thread_pid = tfork(SDL_MintAudio_Thread, 0); - } else { - /* Install interrupt */ - Jdisint(MFP_DMASOUND); - Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); - Jenabint(MFP_DMASOUND); - - if (Setinterrupt(SI_TIMERA, SI_PLAY)<0) { - DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n")); - } - } + /* Set buffer */ + buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; + if (Setbuffer (0, buffer, buffer + spec->size) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setbuffer() failed\n")); + } + + if (SDL_MintAudio_mint_present) { + SDL_MintAudio_thread_pid = tfork (SDL_MintAudio_Thread, 0); + } else { + /* Install interrupt */ + Jdisint (MFP_DMASOUND); + Xbtimer (XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); + Jenabint (MFP_DMASOUND); - /* Go */ - Buffoper(SB_PLA_ENA|SB_PLA_RPT); - DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); + if (Setinterrupt (SI_TIMERA, SI_PLAY) < 0) { + DEBUG_PRINT ((DEBUG_NAME "Setinterrupt() failed\n")); + } + } + + /* Go */ + Buffoper (SB_PLA_ENA | SB_PLA_RPT); + DEBUG_PRINT ((DEBUG_NAME "hardware initialized\n")); } -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) { - /* Lock sound system */ - if (Locksnd()!=1) { - SDL_SetError("Mint_OpenAudio: Audio system already in use"); - return(-1); - } + /* Lock sound system */ + if (Locksnd () != 1) { + SDL_SetError ("Mint_OpenAudio: Audio system already in use"); + return (-1); + } - SDL_MintAudio_device = this; + SDL_MintAudio_device = this; - /* Check audio capabilities */ - if (Mint_CheckAudio(this, spec)==-1) { - return -1; - } + /* Check audio capabilities */ + if (Mint_CheckAudio (this, spec) == -1) { + return -1; + } - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); - /* Allocate memory for audio buffers in DMA-able RAM */ - DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); + /* Allocate memory for audio buffers in DMA-able RAM */ + DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); - SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); - if (SDL_MintAudio_audiobuf[0]==NULL) { - SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); - return (-1); - } - SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; - SDL_MintAudio_numbuf=0; - SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); - SDL_MintAudio_audiosize = spec->size; - SDL_MintAudio_mutex = 0; + SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); + if (SDL_MintAudio_audiobuf[0] == NULL) { + SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); + return (-1); + } + SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; + SDL_MintAudio_numbuf = 0; + SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); + SDL_MintAudio_audiosize = spec->size; + SDL_MintAudio_mutex = 0; - DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); - DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); + DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", + SDL_MintAudio_audiobuf[0])); + DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", + SDL_MintAudio_audiobuf[1])); - /* Setup audio hardware */ - Mint_InitAudio(this, spec); + /* Setup audio hardware */ + Mint_InitAudio (this, spec); - return(1); /* We don't use SDL threaded audio */ + return (1); /* We don't use SDL threaded audio */ } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mme/SDL_mmeaudio.c b/src/audio/mme/SDL_mmeaudio.c index cb4d2bed4..ca7ead919 100644 --- a/src/audio/mme/SDL_mmeaudio.c +++ b/src/audio/mme/SDL_mmeaudio.c @@ -32,57 +32,60 @@ static BOOL inUse[NUM_BUFFERS]; /* Audio driver functions */ -static int MME_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void MME_WaitAudio(_THIS); -static Uint8 *MME_GetAudioBuf(_THIS); -static void MME_PlayAudio(_THIS); -static void MME_WaitDone(_THIS); -static void MME_CloseAudio(_THIS); +static int MME_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void MME_WaitAudio (_THIS); +static Uint8 *MME_GetAudioBuf (_THIS); +static void MME_PlayAudio (_THIS); +static void MME_WaitDone (_THIS); +static void MME_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - return(1); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - if ( device ) { - if ( device->hidden ) { - SDL_free(device->hidden); - device->hidden = NULL; - } - SDL_free(device); - device = NULL; + if (device) { + if (device->hidden) { + SDL_free (device->hidden); + device->hidden = NULL; + } + SDL_free (device); + device = NULL; } } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { SDL_AudioDevice *this; /* Initialize all variables that we clean on shutdown */ - this = SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = SDL_malloc((sizeof *this->hidden)); + this = SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ - this->OpenAudio = MME_OpenAudio; - this->WaitAudio = MME_WaitAudio; - this->PlayAudio = MME_PlayAudio; - this->GetAudioBuf = MME_GetAudioBuf; - this->WaitDone = MME_WaitDone; - this->CloseAudio = MME_CloseAudio; - this->free = Audio_DeleteDevice; + this->OpenAudio = MME_OpenAudio; + this->WaitAudio = MME_WaitAudio; + this->PlayAudio = MME_PlayAudio; + this->GetAudioBuf = MME_GetAudioBuf; + this->WaitDone = MME_WaitDone; + this->CloseAudio = MME_CloseAudio; + this->free = Audio_DeleteDevice; return this; } @@ -92,30 +95,30 @@ AudioBootStrap MMEAUDIO_bootstrap = { Audio_Available, Audio_CreateDevice }; -static void SetMMerror(char *function, MMRESULT code) +static void +SetMMerror (char *function, MMRESULT code) { int len; char errbuf[MAXERRORLENGTH]; - SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function); - len = SDL_strlen(errbuf); - waveOutGetErrorText(code, errbuf+len, MAXERRORLENGTH-len); - SDL_SetError("%s",errbuf); + SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: ", function); + len = SDL_strlen (errbuf); + waveOutGetErrorText (code, errbuf + len, MAXERRORLENGTH - len); + SDL_SetError ("%s", errbuf); } -static void CALLBACK MME_CALLBACK(HWAVEOUT hwo, - UINT uMsg, - DWORD dwInstance, - LPARAM dwParam1, - LPARAM dwParam2) +static void CALLBACK +MME_CALLBACK (HWAVEOUT hwo, + UINT uMsg, DWORD dwInstance, LPARAM dwParam1, LPARAM dwParam2) { WAVEHDR *wp = (WAVEHDR *) dwParam1; - if ( uMsg == WOM_DONE ) - inUse[wp->dwUser] = FALSE; + if (uMsg == WOM_DONE) + inUse[wp->dwUser] = FALSE; } -static int MME_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +MME_OpenAudio (_THIS, SDL_AudioSpec * spec) { MMRESULT result; int i; @@ -123,142 +126,147 @@ static int MME_OpenAudio(_THIS, SDL_AudioSpec *spec) mixbuf = NULL; /* Set basic WAVE format parameters */ - shm = mmeAllocMem(sizeof(*shm)); - if ( shm == NULL ) { - SDL_SetError("Out of memory: shm"); - return(-1); + shm = mmeAllocMem (sizeof (*shm)); + if (shm == NULL) { + SDL_SetError ("Out of memory: shm"); + return (-1); } shm->sound = 0; shm->wFmt.wf.wFormatTag = WAVE_FORMAT_PCM; /* Determine the audio parameters from the AudioSpec */ - switch ( spec->format & 0xFF ) { - case 8: - /* Unsigned 8 bit audio data */ - spec->format = AUDIO_U8; - shm->wFmt.wBitsPerSample = 8; - break; - case 16: - /* Signed 16 bit audio data */ - spec->format = AUDIO_S16; - shm->wFmt.wBitsPerSample = 16; - break; - default: - SDL_SetError("Unsupported audio format"); - return(-1); + switch (spec->format & 0xFF) { + case 8: + /* Unsigned 8 bit audio data */ + spec->format = AUDIO_U8; + shm->wFmt.wBitsPerSample = 8; + break; + case 16: + /* Signed 16 bit audio data */ + spec->format = AUDIO_S16; + shm->wFmt.wBitsPerSample = 16; + break; + default: + SDL_SetError ("Unsupported audio format"); + return (-1); } shm->wFmt.wf.nChannels = spec->channels; shm->wFmt.wf.nSamplesPerSec = spec->freq; shm->wFmt.wf.nBlockAlign = - shm->wFmt.wf.nChannels * shm->wFmt.wBitsPerSample / 8; + shm->wFmt.wf.nChannels * shm->wFmt.wBitsPerSample / 8; shm->wFmt.wf.nAvgBytesPerSec = - shm->wFmt.wf.nSamplesPerSec * shm->wFmt.wf.nBlockAlign; + shm->wFmt.wf.nSamplesPerSec * shm->wFmt.wf.nBlockAlign; /* Check the buffer size -- minimum of 1/4 second (word aligned) */ - if ( spec->samples < (spec->freq/4) ) - spec->samples = ((spec->freq/4)+3)&~3; + if (spec->samples < (spec->freq / 4)) + spec->samples = ((spec->freq / 4) + 3) & ~3; /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); /* Open the audio device */ - result = waveOutOpen(&(shm->sound), - WAVE_MAPPER, - &(shm->wFmt.wf), - MME_CALLBACK, - NULL, - (CALLBACK_FUNCTION|WAVE_OPEN_SHAREABLE)); - if ( result != MMSYSERR_NOERROR ) { - SetMMerror("waveOutOpen()", result); - return(-1); + result = waveOutOpen (&(shm->sound), + WAVE_MAPPER, + &(shm->wFmt.wf), + MME_CALLBACK, + NULL, (CALLBACK_FUNCTION | WAVE_OPEN_SHAREABLE)); + if (result != MMSYSERR_NOERROR) { + SetMMerror ("waveOutOpen()", result); + return (-1); } /* Create the sound buffers */ - mixbuf = (Uint8 *)mmeAllocBuffer(NUM_BUFFERS * (spec->size)); - if ( mixbuf == NULL ) { - SDL_SetError("Out of memory: mixbuf"); - return(-1); + mixbuf = (Uint8 *) mmeAllocBuffer (NUM_BUFFERS * (spec->size)); + if (mixbuf == NULL) { + SDL_SetError ("Out of memory: mixbuf"); + return (-1); } for (i = 0; i < NUM_BUFFERS; i++) { - shm->wHdr[i].lpData = &mixbuf[i * (spec->size)]; - shm->wHdr[i].dwBufferLength = spec->size; - shm->wHdr[i].dwFlags = 0; - shm->wHdr[i].dwUser = i; - shm->wHdr[i].dwLoops = 0; /* loop control counter */ - shm->wHdr[i].lpNext = NULL; /* reserved for driver */ - shm->wHdr[i].reserved = 0; - inUse[i] = FALSE; + shm->wHdr[i].lpData = &mixbuf[i * (spec->size)]; + shm->wHdr[i].dwBufferLength = spec->size; + shm->wHdr[i].dwFlags = 0; + shm->wHdr[i].dwUser = i; + shm->wHdr[i].dwLoops = 0; /* loop control counter */ + shm->wHdr[i].lpNext = NULL; /* reserved for driver */ + shm->wHdr[i].reserved = 0; + inUse[i] = FALSE; } next_buffer = 0; return 0; } -static void MME_WaitAudio(_THIS) +static void +MME_WaitAudio (_THIS) { - while ( inUse[next_buffer] ) { - mmeWaitForCallbacks(); - mmeProcessCallbacks(); + while (inUse[next_buffer]) { + mmeWaitForCallbacks (); + mmeProcessCallbacks (); } } -static Uint8 *MME_GetAudioBuf(_THIS) +static Uint8 * +MME_GetAudioBuf (_THIS) { Uint8 *retval; inUse[next_buffer] = TRUE; - retval = (Uint8 *)(shm->wHdr[next_buffer].lpData); + retval = (Uint8 *) (shm->wHdr[next_buffer].lpData); return retval; } -static void MME_PlayAudio(_THIS) +static void +MME_PlayAudio (_THIS) { /* Queue it up */ - waveOutWrite(shm->sound, &(shm->wHdr[next_buffer]), sizeof(WAVEHDR)); - next_buffer = (next_buffer+1)%NUM_BUFFERS; + waveOutWrite (shm->sound, &(shm->wHdr[next_buffer]), sizeof (WAVEHDR)); + next_buffer = (next_buffer + 1) % NUM_BUFFERS; } -static void MME_WaitDone(_THIS) +static void +MME_WaitDone (_THIS) { MMRESULT result; int i; - if ( shm->sound ) { - for (i = 0; i < NUM_BUFFERS; i++) - while ( inUse[i] ) { - mmeWaitForCallbacks(); - mmeProcessCallbacks(); - } - result = waveOutReset(shm->sound); - if ( result != MMSYSERR_NOERROR ) - SetMMerror("waveOutReset()", result); - mmeProcessCallbacks(); + if (shm->sound) { + for (i = 0; i < NUM_BUFFERS; i++) + while (inUse[i]) { + mmeWaitForCallbacks (); + mmeProcessCallbacks (); + } + result = waveOutReset (shm->sound); + if (result != MMSYSERR_NOERROR) + SetMMerror ("waveOutReset()", result); + mmeProcessCallbacks (); } } -static void MME_CloseAudio(_THIS) +static void +MME_CloseAudio (_THIS) { MMRESULT result; - if ( mixbuf ) { - result = mmeFreeBuffer(mixbuf); - if (result != MMSYSERR_NOERROR ) - SetMMerror("mmeFreeBuffer", result); - mixbuf = NULL; + if (mixbuf) { + result = mmeFreeBuffer (mixbuf); + if (result != MMSYSERR_NOERROR) + SetMMerror ("mmeFreeBuffer", result); + mixbuf = NULL; } - if ( shm ) { - if ( shm->sound ) { - result = waveOutClose(shm->sound); - if (result != MMSYSERR_NOERROR ) - SetMMerror("waveOutClose()", result); - mmeProcessCallbacks(); - } - result = mmeFreeMem(shm); - if (result != MMSYSERR_NOERROR ) - SetMMerror("mmeFreeMem()", result); - shm = NULL; + if (shm) { + if (shm->sound) { + result = waveOutClose (shm->sound); + if (result != MMSYSERR_NOERROR) + SetMMerror ("waveOutClose()", result); + mmeProcessCallbacks (); + } + result = mmeFreeMem (shm); + if (result != MMSYSERR_NOERROR) + SetMMerror ("mmeFreeMem()", result); + shm = NULL; } } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/mme/SDL_mmeaudio.h b/src/audio/mme/SDL_mmeaudio.h index 06d9d8385..3d6d86b5e 100644 --- a/src/audio/mme/SDL_mmeaudio.h +++ b/src/audio/mme/SDL_mmeaudio.h @@ -32,14 +32,16 @@ #define _THIS SDL_AudioDevice *this #define NUM_BUFFERS 2 -struct SharedMem { +struct SharedMem +{ HWAVEOUT sound; WAVEHDR wHdr[NUM_BUFFERS]; PCMWAVEFORMAT wFmt; }; -struct SDL_PrivateAudioData { - Uint8 *mixbuf; /* The raw allocated mixing buffer */ +struct SDL_PrivateAudioData +{ + Uint8 *mixbuf; /* The raw allocated mixing buffer */ struct SharedMem *shm; int next_buffer; }; @@ -49,3 +51,4 @@ struct SDL_PrivateAudioData { #define next_buffer (this->hidden->next_buffer) /* Old variable names */ #endif /* _SDL_lowaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/nas/SDL_nasaudio.c b/src/audio/nas/SDL_nasaudio.c index b5d2a3bcf..af0576dc7 100644 --- a/src/audio/nas/SDL_nasaudio.c +++ b/src/audio/nas/SDL_nasaudio.c @@ -43,257 +43,275 @@ static struct SDL_PrivateAudioData *this2 = NULL; /* Audio driver functions */ -static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void NAS_WaitAudio(_THIS); -static void NAS_PlayAudio(_THIS); -static Uint8 *NAS_GetAudioBuf(_THIS); -static void NAS_CloseAudio(_THIS); +static int NAS_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void NAS_WaitAudio (_THIS); +static void NAS_PlayAudio (_THIS); +static Uint8 *NAS_GetAudioBuf (_THIS); +static void NAS_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - AuServer *aud = AuOpenServer("", 0, NULL, 0, NULL, NULL); - if (!aud) return 0; + AuServer *aud = AuOpenServer ("", 0, NULL, 0, NULL, NULL); + if (!aud) + return 0; - AuCloseServer(aud); - return 1; + AuCloseServer (aud); + return 1; } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = NAS_OpenAudio; - this->WaitAudio = NAS_WaitAudio; - this->PlayAudio = NAS_PlayAudio; - this->GetAudioBuf = NAS_GetAudioBuf; - this->CloseAudio = NAS_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = NAS_OpenAudio; + this->WaitAudio = NAS_WaitAudio; + this->PlayAudio = NAS_PlayAudio; + this->GetAudioBuf = NAS_GetAudioBuf; + this->CloseAudio = NAS_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap NAS_bootstrap = { - NAS_DRIVER_NAME, "Network Audio System", - Audio_Available, Audio_CreateDevice + NAS_DRIVER_NAME, "Network Audio System", + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void NAS_WaitAudio(_THIS) +static void +NAS_WaitAudio (_THIS) { - while ( this->hidden->buf_free < this->hidden->mixlen ) { - AuEvent ev; - AuNextEvent(this->hidden->aud, AuTrue, &ev); - AuDispatchEvent(this->hidden->aud, &ev); - } + while (this->hidden->buf_free < this->hidden->mixlen) { + AuEvent ev; + AuNextEvent (this->hidden->aud, AuTrue, &ev); + AuDispatchEvent (this->hidden->aud, &ev); + } } -static void NAS_PlayAudio(_THIS) +static void +NAS_PlayAudio (_THIS) { - while (this->hidden->mixlen > this->hidden->buf_free) { /* We think the buffer is full? Yikes! Ask the server for events, - in the hope that some of them is LowWater events telling us more - of the buffer is free now than what we think. */ - AuEvent ev; - AuNextEvent(this->hidden->aud, AuTrue, &ev); - AuDispatchEvent(this->hidden->aud, &ev); - } - this->hidden->buf_free -= this->hidden->mixlen; - - /* Write the audio data */ - AuWriteElement(this->hidden->aud, this->hidden->flow, 0, this->hidden->mixlen, this->hidden->mixbuf, AuFalse, NULL); - - this->hidden->written += this->hidden->mixlen; - + while (this->hidden->mixlen > this->hidden->buf_free) { /* We think the buffer is full? Yikes! Ask the server for events, + in the hope that some of them is LowWater events telling us more + of the buffer is free now than what we think. */ + AuEvent ev; + AuNextEvent (this->hidden->aud, AuTrue, &ev); + AuDispatchEvent (this->hidden->aud, &ev); + } + this->hidden->buf_free -= this->hidden->mixlen; + + /* Write the audio data */ + AuWriteElement (this->hidden->aud, this->hidden->flow, 0, + this->hidden->mixlen, this->hidden->mixbuf, AuFalse, + NULL); + + this->hidden->written += this->hidden->mixlen; + #ifdef DEBUG_AUDIO - fprintf(stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen); + fprintf (stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen); #endif } -static Uint8 *NAS_GetAudioBuf(_THIS) +static Uint8 * +NAS_GetAudioBuf (_THIS) { - return(this->hidden->mixbuf); + return (this->hidden->mixbuf); } -static void NAS_CloseAudio(_THIS) +static void +NAS_CloseAudio (_THIS) { - if ( this->hidden->mixbuf != NULL ) { - SDL_FreeAudioMem(this->hidden->mixbuf); - this->hidden->mixbuf = NULL; - } - if ( this->hidden->aud ) { - AuCloseServer(this->hidden->aud); - this->hidden->aud = 0; - } + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem (this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } + if (this->hidden->aud) { + AuCloseServer (this->hidden->aud); + this->hidden->aud = 0; + } } -static unsigned char sdlformat_to_auformat(unsigned int fmt) +static unsigned char +sdlformat_to_auformat (unsigned int fmt) { - switch (fmt) - { + switch (fmt) { case AUDIO_U8: - return AuFormatLinearUnsigned8; + return AuFormatLinearUnsigned8; case AUDIO_S8: - return AuFormatLinearSigned8; + return AuFormatLinearSigned8; case AUDIO_U16LSB: - return AuFormatLinearUnsigned16LSB; + return AuFormatLinearUnsigned16LSB; case AUDIO_U16MSB: - return AuFormatLinearUnsigned16MSB; + return AuFormatLinearUnsigned16MSB; case AUDIO_S16LSB: - return AuFormatLinearSigned16LSB; + return AuFormatLinearSigned16LSB; case AUDIO_S16MSB: - return AuFormatLinearSigned16MSB; + return AuFormatLinearSigned16MSB; } - return AuNone; + return AuNone; } static AuBool -event_handler(AuServer* aud, AuEvent* ev, AuEventHandlerRec* hnd) +event_handler (AuServer * aud, AuEvent * ev, AuEventHandlerRec * hnd) { - switch (ev->type) { - case AuEventTypeElementNotify: { - AuElementNotifyEvent* event = (AuElementNotifyEvent *)ev; - - switch (event->kind) { - case AuElementNotifyKindLowWater: - if (this2->buf_free >= 0) { - this2->really += event->num_bytes; - gettimeofday(&this2->last_tv, 0); - this2->buf_free += event->num_bytes; - } else { - this2->buf_free = event->num_bytes; - } - break; - case AuElementNotifyKindState: - switch (event->cur_state) { - case AuStatePause: - if (event->reason != AuReasonUser) { - if (this2->buf_free >= 0) { - this2->really += event->num_bytes; - gettimeofday(&this2->last_tv, 0); - this2->buf_free += event->num_bytes; - } else { - this2->buf_free = event->num_bytes; - } - } - break; - } - } - } - } - return AuTrue; + switch (ev->type) { + case AuEventTypeElementNotify: + { + AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev; + + switch (event->kind) { + case AuElementNotifyKindLowWater: + if (this2->buf_free >= 0) { + this2->really += event->num_bytes; + gettimeofday (&this2->last_tv, 0); + this2->buf_free += event->num_bytes; + } else { + this2->buf_free = event->num_bytes; + } + break; + case AuElementNotifyKindState: + switch (event->cur_state) { + case AuStatePause: + if (event->reason != AuReasonUser) { + if (this2->buf_free >= 0) { + this2->really += event->num_bytes; + gettimeofday (&this2->last_tv, 0); + this2->buf_free += event->num_bytes; + } else { + this2->buf_free = event->num_bytes; + } + } + break; + } + } + } + } + return AuTrue; } static AuDeviceID -find_device(_THIS, int nch) +find_device (_THIS, int nch) { - int i; - for (i = 0; i < AuServerNumDevices(this->hidden->aud); i++) { - if ((AuDeviceKind(AuServerDevice(this->hidden->aud, i)) == - AuComponentKindPhysicalOutput) && - AuDeviceNumTracks(AuServerDevice(this->hidden->aud, i)) == nch) { - return AuDeviceIdentifier(AuServerDevice(this->hidden->aud, i)); - } - } - return AuNone; + int i; + for (i = 0; i < AuServerNumDevices (this->hidden->aud); i++) { + if ((AuDeviceKind (AuServerDevice (this->hidden->aud, i)) == + AuComponentKindPhysicalOutput) && + AuDeviceNumTracks (AuServerDevice (this->hidden->aud, i)) == + nch) { + return AuDeviceIdentifier (AuServerDevice (this->hidden->aud, i)); + } + } + return AuNone; } -static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +NAS_OpenAudio (_THIS, SDL_AudioSpec * spec) { - AuElement elms[3]; - int buffer_size; - Uint16 test_format, format; - - this->hidden->mixbuf = NULL; - - /* Try for a closest match on audio format */ - format = 0; - for ( test_format = SDL_FirstAudioFormat(spec->format); - ! format && test_format; ) { - format = sdlformat_to_auformat(test_format); - - if (format == AuNone) { - test_format = SDL_NextAudioFormat(); - } - } - if ( format == 0 ) { - SDL_SetError("Couldn't find any hardware audio formats"); - return(-1); - } - spec->format = test_format; - - this->hidden->aud = AuOpenServer("", 0, NULL, 0, NULL, NULL); - if (this->hidden->aud == 0) - { - SDL_SetError("Couldn't open connection to NAS server"); - return (-1); - } - - this->hidden->dev = find_device(this, spec->channels); - if ((this->hidden->dev == AuNone) || (!(this->hidden->flow = AuCreateFlow(this->hidden->aud, NULL)))) { - AuCloseServer(this->hidden->aud); - this->hidden->aud = 0; - SDL_SetError("Couldn't find a fitting playback device on NAS server"); - return (-1); - } - - buffer_size = spec->freq; - if (buffer_size < 4096) - buffer_size = 4096; - - if (buffer_size > 32768) - buffer_size = 32768; /* So that the buffer won't get unmanageably big. */ - - /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); - - this2 = this->hidden; - - AuMakeElementImportClient(elms, spec->freq, format, spec->channels, AuTrue, - buffer_size, buffer_size / 4, 0, NULL); - AuMakeElementExportDevice(elms+1, 0, this->hidden->dev, spec->freq, - AuUnlimitedSamples, 0, NULL); - AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue, 2, elms, NULL); - AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0, this->hidden->flow, - event_handler, (AuPointer) NULL); - - AuStartFlow(this->hidden->aud, this->hidden->flow, NULL); - - /* Allocate mixing buffer */ - this->hidden->mixlen = spec->size; - this->hidden->mixbuf = (Uint8 *)SDL_AllocAudioMem(this->hidden->mixlen); - if ( this->hidden->mixbuf == NULL ) { - return(-1); - } - SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); - - /* Get the parent process id (we're the parent of the audio thread) */ - this->hidden->parent = getpid(); - - /* We're ready to rock and roll. :-) */ - return(0); + AuElement elms[3]; + int buffer_size; + Uint16 test_format, format; + + this->hidden->mixbuf = NULL; + + /* Try for a closest match on audio format */ + format = 0; + for (test_format = SDL_FirstAudioFormat (spec->format); + !format && test_format;) { + format = sdlformat_to_auformat (test_format); + + if (format == AuNone) { + test_format = SDL_NextAudioFormat (); + } + } + if (format == 0) { + SDL_SetError ("Couldn't find any hardware audio formats"); + return (-1); + } + spec->format = test_format; + + this->hidden->aud = AuOpenServer ("", 0, NULL, 0, NULL, NULL); + if (this->hidden->aud == 0) { + SDL_SetError ("Couldn't open connection to NAS server"); + return (-1); + } + + this->hidden->dev = find_device (this, spec->channels); + if ((this->hidden->dev == AuNone) + || (!(this->hidden->flow = AuCreateFlow (this->hidden->aud, NULL)))) { + AuCloseServer (this->hidden->aud); + this->hidden->aud = 0; + SDL_SetError + ("Couldn't find a fitting playback device on NAS server"); + return (-1); + } + + buffer_size = spec->freq; + if (buffer_size < 4096) + buffer_size = 4096; + + if (buffer_size > 32768) + buffer_size = 32768; /* So that the buffer won't get unmanageably big. */ + + /* Calculate the final parameters for this audio specification */ + SDL_CalculateAudioSpec (spec); + + this2 = this->hidden; + + AuMakeElementImportClient (elms, spec->freq, format, spec->channels, + AuTrue, buffer_size, buffer_size / 4, 0, NULL); + AuMakeElementExportDevice (elms + 1, 0, this->hidden->dev, spec->freq, + AuUnlimitedSamples, 0, NULL); + AuSetElements (this->hidden->aud, this->hidden->flow, AuTrue, 2, elms, + NULL); + AuRegisterEventHandler (this->hidden->aud, AuEventHandlerIDMask, 0, + this->hidden->flow, event_handler, + (AuPointer) NULL); + + AuStartFlow (this->hidden->aud, this->hidden->flow, NULL); + + /* Allocate mixing buffer */ + this->hidden->mixlen = spec->size; + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen); + if (this->hidden->mixbuf == NULL) { + return (-1); + } + SDL_memset (this->hidden->mixbuf, spec->silence, spec->size); + + /* Get the parent process id (we're the parent of the audio thread) */ + this->hidden->parent = getpid (); + + /* We're ready to rock and roll. :-) */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/nas/SDL_nasaudio.h b/src/audio/nas/SDL_nasaudio.h index 390d6698b..fc1c73d92 100644 --- a/src/audio/nas/SDL_nasaudio.h +++ b/src/audio/nas/SDL_nasaudio.h @@ -40,23 +40,24 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - AuServer* aud; - AuFlowID flow; - AuDeviceID dev; - - /* The parent process id, to detect when application quits */ - pid_t parent; - - /* Raw mixing buffer */ - Uint8 *mixbuf; - int mixlen; - - int written; - int really; - int bps; - struct timeval last_tv; - int buf_free; +struct SDL_PrivateAudioData +{ + AuServer *aud; + AuFlowID flow; + AuDeviceID dev; + + /* The parent process id, to detect when application quits */ + pid_t parent; + + /* Raw mixing buffer */ + Uint8 *mixbuf; + int mixlen; + + int written; + int really; + int bps; + struct timeval last_tv; + int buf_free; }; #endif /* _SDL_nasaudio_h */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/nto/SDL_nto_audio.c b/src/audio/nto/SDL_nto_audio.c index db86bae27..ff59b4388 100644 --- a/src/audio/nto/SDL_nto_audio.c +++ b/src/audio/nto/SDL_nto_audio.c @@ -57,72 +57,70 @@ struct BuggyCards { - char* cardname; - unsigned long bugtype; + char *cardname; + unsigned long bugtype; }; #define QSA_WA_CARDS 3 -struct BuggyCards buggycards[QSA_WA_CARDS]= -{ - {"Sound Blaster Live!", QSA_MMAP_WORKAROUND}, - {"Vortex 8820", QSA_MMAP_WORKAROUND}, - {"Vortex 8830", QSA_MMAP_WORKAROUND}, +struct BuggyCards buggycards[QSA_WA_CARDS] = { + {"Sound Blaster Live!", QSA_MMAP_WORKAROUND}, + {"Vortex 8820", QSA_MMAP_WORKAROUND}, + {"Vortex 8830", QSA_MMAP_WORKAROUND}, }; /* Audio driver functions */ -static void NTO_ThreadInit(_THIS); -static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec); -static void NTO_WaitAudio(_THIS); -static void NTO_PlayAudio(_THIS); -static Uint8* NTO_GetAudioBuf(_THIS); -static void NTO_CloseAudio(_THIS); +static void NTO_ThreadInit (_THIS); +static int NTO_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void NTO_WaitAudio (_THIS); +static void NTO_PlayAudio (_THIS); +static Uint8 *NTO_GetAudioBuf (_THIS); +static void NTO_CloseAudio (_THIS); /* card names check to apply the workarounds */ -static int NTO_CheckBuggyCards(_THIS, unsigned long checkfor) +static int +NTO_CheckBuggyCards (_THIS, unsigned long checkfor) { char scardname[33]; int it; - - if (snd_card_get_name(cardno, scardname, 32)<0) - { + + if (snd_card_get_name (cardno, scardname, 32) < 0) { return 0; } - for (it=0; itchannel = SND_PCM_CHANNEL_PLAYBACK; cpars->mode = SND_PCM_MODE_BLOCK; cpars->start_mode = SND_PCM_START_DATA; - cpars->stop_mode = SND_PCM_STOP_STOP; + cpars->stop_mode = SND_PCM_STOP_STOP; cpars->format.format = SND_PCM_SFMT_S16_LE; cpars->format.interleave = 1; cpars->format.rate = DEFAULT_CPARAMS_RATE; @@ -132,72 +130,70 @@ static void NTO_InitAudioParams(snd_pcm_channel_params_t* cpars) cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX; } -static int NTO_AudioAvailable(void) +static int +NTO_AudioAvailable (void) { /* See if we can open a nonblocking channel. - Return value '1' means we can. - Return value '0' means we cannot. */ + Return value '1' means we can. + Return value '0' means we cannot. */ int available; int rval; - snd_pcm_t* handle; + snd_pcm_t *handle; available = 0; handle = NULL; - rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS); + rval = snd_pcm_open_preferred (&handle, NULL, NULL, OPEN_FLAGS); - if (rval >= 0) - { + if (rval >= 0) { available = 1; - if ((rval = snd_pcm_close(handle)) < 0) - { - SDL_SetError("NTO_AudioAvailable(): snd_pcm_close failed: %s\n", snd_strerror(rval)); + if ((rval = snd_pcm_close (handle)) < 0) { + SDL_SetError + ("NTO_AudioAvailable(): snd_pcm_close failed: %s\n", + snd_strerror (rval)); available = 0; } - } - else - { - SDL_SetError("NTO_AudioAvailable(): there are no available audio devices.\n"); + } else { + SDL_SetError + ("NTO_AudioAvailable(): there are no available audio devices.\n"); } return (available); } -static void NTO_DeleteAudioDevice(SDL_AudioDevice *device) +static void +NTO_DeleteAudioDevice (SDL_AudioDevice * device) { - if ((device)&&(device->hidden)) - { - SDL_free(device->hidden); + if ((device) && (device->hidden)) { + SDL_free (device->hidden); } - if (device) - { - SDL_free(device); + if (device) { + SDL_free (device); } } -static SDL_AudioDevice* NTO_CreateAudioDevice(int devindex) +static SDL_AudioDevice * +NTO_CreateAudioDevice (int devindex) { SDL_AudioDevice *this; /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if (this) - { - SDL_memset(this, 0, sizeof(SDL_AudioDevice)); - this->hidden = (struct SDL_PrivateAudioData *)SDL_malloc(sizeof(struct SDL_PrivateAudioData)); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, sizeof (SDL_AudioDevice)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc (sizeof (struct SDL_PrivateAudioData)); } - if ((this == NULL) || (this->hidden == NULL)) - { - SDL_OutOfMemory(); - if (this) - { - SDL_free(this); - } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } return (0); } - SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData)); + SDL_memset (this->hidden, 0, sizeof (struct SDL_PrivateAudioData)); audio_handle = NULL; /* Set the function pointers */ @@ -213,138 +209,143 @@ static SDL_AudioDevice* NTO_CreateAudioDevice(int devindex) return this; } -AudioBootStrap QNXNTOAUDIO_bootstrap = -{ +AudioBootStrap QNXNTOAUDIO_bootstrap = { DRIVER_NAME, "QNX6 QSA-NTO Audio", NTO_AudioAvailable, NTO_CreateAudioDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void NTO_WaitAudio(_THIS) +static void +NTO_WaitAudio (_THIS) { fd_set wfds; int selectret; - FD_ZERO(&wfds); - FD_SET(audio_fd, &wfds); + FD_ZERO (&wfds); + FD_SET (audio_fd, &wfds); do { - selectret=select(audio_fd + 1, NULL, &wfds, NULL, NULL); - switch (selectret) - { - case -1: - case 0: SDL_SetError("NTO_WaitAudio(): select() failed: %s\n", strerror(errno)); - return; - default: if (FD_ISSET(audio_fd, &wfds)) - { - return; - } - break; + selectret = select (audio_fd + 1, NULL, &wfds, NULL, NULL); + switch (selectret) { + case -1: + case 0: + SDL_SetError ("NTO_WaitAudio(): select() failed: %s\n", + strerror (errno)); + return; + default: + if (FD_ISSET (audio_fd, &wfds)) { + return; + } + break; } - } while(1); + } + while (1); } -static void NTO_PlayAudio(_THIS) +static void +NTO_PlayAudio (_THIS) { int written, rval; int towrite; - void* pcmbuffer; + void *pcmbuffer; - if (!this->enabled) - { + if (!this->enabled) { return; } - + towrite = this->spec.size; pcmbuffer = pcm_buf; /* Write the audio data, checking for EAGAIN (buffer full) and underrun */ do { - written = snd_pcm_plugin_write(audio_handle, pcm_buf, towrite); - if (written != towrite) - { - if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) - { + written = snd_pcm_plugin_write (audio_handle, pcm_buf, towrite); + if (written != towrite) { + if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { /* Let a little CPU time go by and try to write again */ - SDL_Delay(1); + SDL_Delay (1); /* if we wrote some data */ towrite -= written; pcmbuffer += written * this->spec.channels; continue; - } - else - { - if ((errno == EINVAL) || (errno == EIO)) - { - SDL_memset(&cstatus, 0, sizeof(cstatus)); + } else { + if ((errno == EINVAL) || (errno == EIO)) { + SDL_memset (&cstatus, 0, sizeof (cstatus)); cstatus.channel = SND_PCM_CHANNEL_PLAYBACK; - if ((rval = snd_pcm_plugin_status(audio_handle, &cstatus)) < 0) - { - SDL_SetError("NTO_PlayAudio(): snd_pcm_plugin_status failed: %s\n", snd_strerror(rval)); + if ((rval = + snd_pcm_plugin_status (audio_handle, + &cstatus)) < 0) { + SDL_SetError + ("NTO_PlayAudio(): snd_pcm_plugin_status failed: %s\n", + snd_strerror (rval)); return; - } - if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY)) - { - if ((rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) - { - SDL_SetError("NTO_PlayAudio(): snd_pcm_plugin_prepare failed: %s\n", snd_strerror(rval)); + } + if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) + || (cstatus.status == SND_PCM_STATUS_READY)) { + if ((rval = + snd_pcm_plugin_prepare (audio_handle, + SND_PCM_CHANNEL_PLAYBACK)) + < 0) { + SDL_SetError + ("NTO_PlayAudio(): snd_pcm_plugin_prepare failed: %s\n", + snd_strerror (rval)); return; } - } + } continue; - } - else - { + } else { return; } } - } - else - { + } else { /* we wrote all remaining data */ towrite -= written; pcmbuffer += written * this->spec.channels; } - } while ((towrite > 0) && (this->enabled)); + } + while ((towrite > 0) && (this->enabled)); /* If we couldn't write, assume fatal error for now */ - if (towrite != 0) - { + if (towrite != 0) { this->enabled = 0; } return; } -static Uint8* NTO_GetAudioBuf(_THIS) +static Uint8 * +NTO_GetAudioBuf (_THIS) { return pcm_buf; } -static void NTO_CloseAudio(_THIS) +static void +NTO_CloseAudio (_THIS) { int rval; this->enabled = 0; - if (audio_handle != NULL) - { - if ((rval = snd_pcm_plugin_flush(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) - { - SDL_SetError("NTO_CloseAudio(): snd_pcm_plugin_flush failed: %s\n", snd_strerror(rval)); + if (audio_handle != NULL) { + if ((rval = + snd_pcm_plugin_flush (audio_handle, + SND_PCM_CHANNEL_PLAYBACK)) < 0) { + SDL_SetError + ("NTO_CloseAudio(): snd_pcm_plugin_flush failed: %s\n", + snd_strerror (rval)); return; } - if ((rval = snd_pcm_close(audio_handle)) < 0) - { - SDL_SetError("NTO_CloseAudio(): snd_pcm_close failed: %s\n",snd_strerror(rval)); + if ((rval = snd_pcm_close (audio_handle)) < 0) { + SDL_SetError ("NTO_CloseAudio(): snd_pcm_close failed: %s\n", + snd_strerror (rval)); return; } audio_handle = NULL; } } -static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec) +static int +NTO_OpenAudio (_THIS, SDL_AudioSpec * spec) { int rval; int format; @@ -354,29 +355,31 @@ static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec) audio_handle = NULL; this->enabled = 0; - if (pcm_buf != NULL) - { - SDL_FreeAudioMem(pcm_buf); + if (pcm_buf != NULL) { + SDL_FreeAudioMem (pcm_buf); pcm_buf = NULL; } /* initialize channel transfer parameters to default */ - NTO_InitAudioParams(&cparams); + NTO_InitAudioParams (&cparams); /* Open the audio device */ - rval = snd_pcm_open_preferred(&audio_handle, &cardno, &deviceno, OPEN_FLAGS); - if (rval < 0) - { - SDL_SetError("NTO_OpenAudio(): snd_pcm_open failed: %s\n", snd_strerror(rval)); + rval = + snd_pcm_open_preferred (&audio_handle, &cardno, &deviceno, + OPEN_FLAGS); + if (rval < 0) { + SDL_SetError ("NTO_OpenAudio(): snd_pcm_open failed: %s\n", + snd_strerror (rval)); return (-1); } - if (!NTO_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) - { + if (!NTO_CheckBuggyCards (this, QSA_MMAP_WORKAROUND)) { /* enable count status parameter */ - if ((rval = snd_pcm_plugin_set_disable(audio_handle, PLUGIN_DISABLE_MMAP)) < 0) - { - SDL_SetError("snd_pcm_plugin_set_disable failed: %s\n", snd_strerror(rval)); + if ((rval = + snd_pcm_plugin_set_disable (audio_handle, + PLUGIN_DISABLE_MMAP)) < 0) { + SDL_SetError ("snd_pcm_plugin_set_disable failed: %s\n", + snd_strerror (rval)); return (-1); } } @@ -386,49 +389,46 @@ static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec) /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */ found = 0; - for (test_format=SDL_FirstAudioFormat(spec->format); !found ;) - { + for (test_format = SDL_FirstAudioFormat (spec->format); !found;) { /* if match found set format to equivalent ALSA format */ - switch (test_format) - { - case AUDIO_U8: - format = SND_PCM_SFMT_U8; - found = 1; - break; - case AUDIO_S8: - format = SND_PCM_SFMT_S8; - found = 1; - break; - case AUDIO_S16LSB: - format = SND_PCM_SFMT_S16_LE; - found = 1; - break; - case AUDIO_S16MSB: - format = SND_PCM_SFMT_S16_BE; - found = 1; - break; - case AUDIO_U16LSB: - format = SND_PCM_SFMT_U16_LE; - found = 1; - break; - case AUDIO_U16MSB: - format = SND_PCM_SFMT_U16_BE; - found = 1; - break; - default: - break; + switch (test_format) { + case AUDIO_U8: + format = SND_PCM_SFMT_U8; + found = 1; + break; + case AUDIO_S8: + format = SND_PCM_SFMT_S8; + found = 1; + break; + case AUDIO_S16LSB: + format = SND_PCM_SFMT_S16_LE; + found = 1; + break; + case AUDIO_S16MSB: + format = SND_PCM_SFMT_S16_BE; + found = 1; + break; + case AUDIO_U16LSB: + format = SND_PCM_SFMT_U16_LE; + found = 1; + break; + case AUDIO_U16MSB: + format = SND_PCM_SFMT_U16_BE; + found = 1; + break; + default: + break; } - if (!found) - { - test_format = SDL_NextAudioFormat(); + if (!found) { + test_format = SDL_NextAudioFormat (); } } /* assumes test_format not 0 on success */ - if (test_format == 0) - { - SDL_SetError("NTO_OpenAudio(): Couldn't find any hardware audio formats"); + if (test_format == 0) { + SDL_SetError + ("NTO_OpenAudio(): Couldn't find any hardware audio formats"); return (-1); } @@ -439,69 +439,74 @@ static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec) /* Set mono or stereo audio (currently only two channels supported) */ cparams.format.voices = spec->channels; - + /* Set rate */ cparams.format.rate = spec->freq; /* Setup the transfer parameters according to cparams */ - rval = snd_pcm_plugin_params(audio_handle, &cparams); - if (rval < 0) - { - SDL_SetError("NTO_OpenAudio(): snd_pcm_channel_params failed: %s\n", snd_strerror(rval)); + rval = snd_pcm_plugin_params (audio_handle, &cparams); + if (rval < 0) { + SDL_SetError + ("NTO_OpenAudio(): snd_pcm_channel_params failed: %s\n", + snd_strerror (rval)); return (-1); } /* Make sure channel is setup right one last time */ - SDL_memset(&csetup, 0x00, sizeof(csetup)); + SDL_memset (&csetup, 0x00, sizeof (csetup)); csetup.channel = SND_PCM_CHANNEL_PLAYBACK; - if (snd_pcm_plugin_setup(audio_handle, &csetup) < 0) - { - SDL_SetError("NTO_OpenAudio(): Unable to setup playback channel\n"); + if (snd_pcm_plugin_setup (audio_handle, &csetup) < 0) { + SDL_SetError ("NTO_OpenAudio(): Unable to setup playback channel\n"); return -1; } /* Calculate the final parameters for this audio specification */ - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec (spec); pcm_len = spec->size; - if (pcm_len==0) - { - pcm_len = csetup.buf.block.frag_size * spec->channels * (snd_pcm_format_width(format)/8); + if (pcm_len == 0) { + pcm_len = + csetup.buf.block.frag_size * spec->channels * + (snd_pcm_format_width (format) / 8); } /* Allocate memory to the audio buffer and initialize with silence (Note that buffer size must be a multiple of fragment size, so find closest multiple) - */ - pcm_buf = (Uint8*)SDL_AllocAudioMem(pcm_len); - if (pcm_buf == NULL) - { - SDL_SetError("NTO_OpenAudio(): pcm buffer allocation failed\n"); + */ + pcm_buf = (Uint8 *) SDL_AllocAudioMem (pcm_len); + if (pcm_buf == NULL) { + SDL_SetError ("NTO_OpenAudio(): pcm buffer allocation failed\n"); return (-1); } - SDL_memset(pcm_buf, spec->silence, pcm_len); + SDL_memset (pcm_buf, spec->silence, pcm_len); /* get the file descriptor */ - if ((audio_fd = snd_pcm_file_descriptor(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) - { - SDL_SetError("NTO_OpenAudio(): snd_pcm_file_descriptor failed with error code: %s\n", snd_strerror(rval)); + if ((audio_fd = + snd_pcm_file_descriptor (audio_handle, + SND_PCM_CHANNEL_PLAYBACK)) < 0) { + SDL_SetError + ("NTO_OpenAudio(): snd_pcm_file_descriptor failed with error code: %s\n", + snd_strerror (rval)); return (-1); } /* Trigger audio playback */ - rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK); - if (rval < 0) - { - SDL_SetError("snd_pcm_plugin_prepare failed: %s\n", snd_strerror(rval)); + rval = snd_pcm_plugin_prepare (audio_handle, SND_PCM_CHANNEL_PLAYBACK); + if (rval < 0) { + SDL_SetError ("snd_pcm_plugin_prepare failed: %s\n", + snd_strerror (rval)); return (-1); } this->enabled = 1; /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); + parent = getpid (); /* We're really ready to rock and roll. :-) */ return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/nto/SDL_nto_audio.h b/src/audio/nto/SDL_nto_audio.h index 14fd00d47..ed4a8b25b 100644 --- a/src/audio/nto/SDL_nto_audio.h +++ b/src/audio/nto/SDL_nto_audio.h @@ -36,7 +36,7 @@ struct SDL_PrivateAudioData /* The audio device handle */ int cardno; int deviceno; - snd_pcm_t* audio_handle; + snd_pcm_t *audio_handle; /* The audio file descriptor */ int audio_fd; @@ -45,13 +45,13 @@ struct SDL_PrivateAudioData pid_t parent; /* Raw mixing buffer */ - Uint8* pcm_buf; + Uint8 *pcm_buf; Uint32 pcm_len; /* QSA parameters */ snd_pcm_channel_status_t cstatus; snd_pcm_channel_params_t cparams; - snd_pcm_channel_setup_t csetup; + snd_pcm_channel_setup_t csetup; }; #define cardno (this->hidden->cardno) @@ -66,3 +66,4 @@ struct SDL_PrivateAudioData #define csetup (this->hidden->csetup) #endif /* __SDL_NTO_AUDIO_H__ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/paudio/SDL_paudio.c b/src/audio/paudio/SDL_paudio.c index 7b07b5981..462de1d68 100644 --- a/src/audio/paudio/SDL_paudio.c +++ b/src/audio/paudio/SDL_paudio.c @@ -55,457 +55,461 @@ #define OPEN_FLAGS O_WRONLY /* Audio driver functions */ -static int Paud_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void Paud_WaitAudio(_THIS); -static void Paud_PlayAudio(_THIS); -static Uint8 *Paud_GetAudioBuf(_THIS); -static void Paud_CloseAudio(_THIS); +static int Paud_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void Paud_WaitAudio (_THIS); +static void Paud_PlayAudio (_THIS); +static Uint8 *Paud_GetAudioBuf (_THIS); +static void Paud_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - int fd; - int available; - - available = 0; - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0); - if ( fd >= 0 ) { - available = 1; - close(fd); - } - return(available); + int fd; + int available; + + available = 0; + fd = SDL_OpenAudioPath (NULL, 0, OPEN_FLAGS, 0); + if (fd >= 0) { + available = 1; + close (fd); + } + return (available); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = Paud_OpenAudio; - this->WaitAudio = Paud_WaitAudio; - this->PlayAudio = Paud_PlayAudio; - this->GetAudioBuf = Paud_GetAudioBuf; - this->CloseAudio = Paud_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + audio_fd = -1; + + /* Set the function pointers */ + this->OpenAudio = Paud_OpenAudio; + this->WaitAudio = Paud_WaitAudio; + this->PlayAudio = Paud_PlayAudio; + this->GetAudioBuf = Paud_GetAudioBuf; + this->CloseAudio = Paud_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap Paud_bootstrap = { - Paud_DRIVER_NAME, "AIX Paudio", - Audio_Available, Audio_CreateDevice + Paud_DRIVER_NAME, "AIX Paudio", + Audio_Available, Audio_CreateDevice }; /* This function waits until it is possible to write a full sound buffer */ -static void Paud_WaitAudio(_THIS) +static void +Paud_WaitAudio (_THIS) { fd_set fdset; /* See if we need to use timed audio synchronization */ - if ( frame_ticks ) { + if (frame_ticks) { /* Use timer for general audio synchronization */ Sint32 ticks; - ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; - if ( ticks > 0 ) { - SDL_Delay(ticks); + ticks = ((Sint32) (next_frame - SDL_GetTicks ())) - FUDGE_TICKS; + if (ticks > 0) { + SDL_Delay (ticks); } } else { - audio_buffer paud_bufinfo; + audio_buffer paud_bufinfo; /* Use select() for audio synchronization */ struct timeval timeout; - FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); + FD_ZERO (&fdset); + FD_SET (audio_fd, &fdset); - if ( ioctl(audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0 ) { + if (ioctl (audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Couldn't get audio buffer information\n"); + fprintf (stderr, "Couldn't get audio buffer information\n"); #endif - timeout.tv_sec = 10; + timeout.tv_sec = 10; timeout.tv_usec = 0; } else { - long ms_in_buf = paud_bufinfo.write_buf_time; - timeout.tv_sec = ms_in_buf/1000; - ms_in_buf = ms_in_buf - timeout.tv_sec*1000; - timeout.tv_usec = ms_in_buf*1000; + long ms_in_buf = paud_bufinfo.write_buf_time; + timeout.tv_sec = ms_in_buf / 1000; + ms_in_buf = ms_in_buf - timeout.tv_sec * 1000; + timeout.tv_usec = ms_in_buf * 1000; #ifdef DEBUG_AUDIO - fprintf( stderr, - "Waiting for write_buf_time=%ld,%ld\n", - timeout.tv_sec, - timeout.tv_usec ); + fprintf (stderr, + "Waiting for write_buf_time=%ld,%ld\n", + timeout.tv_sec, timeout.tv_usec); #endif - } + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Waiting for audio to get ready\n"); + fprintf (stderr, "Waiting for audio to get ready\n"); #endif - if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) { - const char *message = "Audio timeout - buggy audio driver? (disabled)"; + if (select (audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) { + const char *message = + "Audio timeout - buggy audio driver? (disabled)"; /* - * In general we should never print to the screen, + * In general we should never print to the screen, * but in this case we have no other way of letting * the user know what happened. */ - fprintf(stderr, "SDL: %s - %s\n", strerror(errno), message); + fprintf (stderr, "SDL: %s - %s\n", strerror (errno), message); this->enabled = 0; /* Don't try to close - may hang */ audio_fd = -1; #ifdef DEBUG_AUDIO - fprintf(stderr, "Done disabling audio\n"); + fprintf (stderr, "Done disabling audio\n"); #endif } #ifdef DEBUG_AUDIO - fprintf(stderr, "Ready!\n"); + fprintf (stderr, "Ready!\n"); #endif } } -static void Paud_PlayAudio(_THIS) +static void +Paud_PlayAudio (_THIS) { - int written; - - /* Write the audio data, checking for EAGAIN on broken audio drivers */ - do { - written = write(audio_fd, mixbuf, mixlen); - if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) { - SDL_Delay(1); /* Let a little CPU time go by */ - } - } while ( (written < 0) && - ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) ); - - /* If timer synchronization is enabled, set the next write frame */ - if ( frame_ticks ) { - next_frame += frame_ticks; - } - - /* If we couldn't write, assume fatal error for now */ - if ( written < 0 ) { - this->enabled = 0; - } + int written; + + /* Write the audio data, checking for EAGAIN on broken audio drivers */ + do { + written = write (audio_fd, mixbuf, mixlen); + if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) { + SDL_Delay (1); /* Let a little CPU time go by */ + } + } + while ((written < 0) && + ((errno == 0) || (errno == EAGAIN) || (errno == EINTR))); + + /* If timer synchronization is enabled, set the next write frame */ + if (frame_ticks) { + next_frame += frame_ticks; + } + + /* If we couldn't write, assume fatal error for now */ + if (written < 0) { + this->enabled = 0; + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Wrote %d bytes of audio data\n", written); + fprintf (stderr, "Wrote %d bytes of audio data\n", written); #endif } -static Uint8 *Paud_GetAudioBuf(_THIS) +static Uint8 * +Paud_GetAudioBuf (_THIS) { - return mixbuf; + return mixbuf; } -static void Paud_CloseAudio(_THIS) +static void +Paud_CloseAudio (_THIS) { - if ( mixbuf != NULL ) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if ( audio_fd >= 0 ) { - close(audio_fd); - audio_fd = -1; - } + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; + } + if (audio_fd >= 0) { + close (audio_fd); + audio_fd = -1; + } } -static int Paud_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +Paud_OpenAudio (_THIS, SDL_AudioSpec * spec) { - char audiodev[1024]; - int format; - int bytes_per_sample; - Uint16 test_format; - audio_init paud_init; - audio_buffer paud_bufinfo; - audio_status paud_status; - audio_control paud_control; - audio_change paud_change; - - /* Reset the timer synchronization flag */ - frame_ticks = 0.0; - - /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0); - if ( audio_fd < 0 ) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return -1; - } - - /* - * We can't set the buffer size - just ask the device for the maximum - * that we can have. - */ - if ( ioctl(audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0 ) { - SDL_SetError("Couldn't get audio buffer information"); - return -1; - } - - mixbuf = NULL; - - if ( spec->channels > 1 ) - spec->channels = 2; - else - spec->channels = 1; - - /* - * Fields in the audio_init structure: - * - * Ignored by us: - * - * paud.loadpath[LOAD_PATH]; * DSP code to load, MWave chip only? - * paud.slot_number; * slot number of the adapter - * paud.device_id; * adapter identification number - * - * Input: - * - * paud.srate; * the sampling rate in Hz - * paud.bits_per_sample; * 8, 16, 32, ... - * paud.bsize; * block size for this rate - * paud.mode; * ADPCM, PCM, MU_LAW, A_LAW, SOURCE_MIX - * paud.channels; * 1=mono, 2=stereo - * paud.flags; * FIXED - fixed length data - * * LEFT_ALIGNED, RIGHT_ALIGNED (var len only) - * * TWOS_COMPLEMENT - 2's complement data - * * SIGNED - signed? comment seems wrong in sys/audio.h - * * BIG_ENDIAN - * paud.operation; * PLAY, RECORD - * - * Output: - * - * paud.flags; * PITCH - pitch is supported - * * INPUT - input is supported - * * OUTPUT - output is supported - * * MONITOR - monitor is supported - * * VOLUME - volume is supported - * * VOLUME_DELAY - volume delay is supported - * * BALANCE - balance is supported - * * BALANCE_DELAY - balance delay is supported - * * TREBLE - treble control is supported - * * BASS - bass control is supported - * * BESTFIT_PROVIDED - best fit returned - * * LOAD_CODE - DSP load needed - * paud.rc; * NO_PLAY - DSP code can't do play requests - * * NO_RECORD - DSP code can't do record requests - * * INVALID_REQUEST - request was invalid - * * CONFLICT - conflict with open's flags - * * OVERLOADED - out of DSP MIPS or memory - * paud.position_resolution; * smallest increment for position - */ - - paud_init.srate = spec->freq; - paud_init.mode = PCM; - paud_init.operation = PLAY; - paud_init.channels = spec->channels; - - /* Try for a closest match on audio format */ - format = 0; - for ( test_format = SDL_FirstAudioFormat(spec->format); - ! format && test_format; ) { + char audiodev[1024]; + int format; + int bytes_per_sample; + Uint16 test_format; + audio_init paud_init; + audio_buffer paud_bufinfo; + audio_status paud_status; + audio_control paud_control; + audio_change paud_change; + + /* Reset the timer synchronization flag */ + frame_ticks = 0.0; + + /* Open the audio device */ + audio_fd = SDL_OpenAudioPath (audiodev, sizeof (audiodev), OPEN_FLAGS, 0); + if (audio_fd < 0) { + SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); + return -1; + } + + /* + * We can't set the buffer size - just ask the device for the maximum + * that we can have. + */ + if (ioctl (audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0) { + SDL_SetError ("Couldn't get audio buffer information"); + return -1; + } + + mixbuf = NULL; + + if (spec->channels > 1) + spec->channels = 2; + else + spec->channels = 1; + + /* + * Fields in the audio_init structure: + * + * Ignored by us: + * + * paud.loadpath[LOAD_PATH]; * DSP code to load, MWave chip only? + * paud.slot_number; * slot number of the adapter + * paud.device_id; * adapter identification number + * + * Input: + * + * paud.srate; * the sampling rate in Hz + * paud.bits_per_sample; * 8, 16, 32, ... + * paud.bsize; * block size for this rate + * paud.mode; * ADPCM, PCM, MU_LAW, A_LAW, SOURCE_MIX + * paud.channels; * 1=mono, 2=stereo + * paud.flags; * FIXED - fixed length data + * * LEFT_ALIGNED, RIGHT_ALIGNED (var len only) + * * TWOS_COMPLEMENT - 2's complement data + * * SIGNED - signed? comment seems wrong in sys/audio.h + * * BIG_ENDIAN + * paud.operation; * PLAY, RECORD + * + * Output: + * + * paud.flags; * PITCH - pitch is supported + * * INPUT - input is supported + * * OUTPUT - output is supported + * * MONITOR - monitor is supported + * * VOLUME - volume is supported + * * VOLUME_DELAY - volume delay is supported + * * BALANCE - balance is supported + * * BALANCE_DELAY - balance delay is supported + * * TREBLE - treble control is supported + * * BASS - bass control is supported + * * BESTFIT_PROVIDED - best fit returned + * * LOAD_CODE - DSP load needed + * paud.rc; * NO_PLAY - DSP code can't do play requests + * * NO_RECORD - DSP code can't do record requests + * * INVALID_REQUEST - request was invalid + * * CONFLICT - conflict with open's flags + * * OVERLOADED - out of DSP MIPS or memory + * paud.position_resolution; * smallest increment for position + */ + + paud_init.srate = spec->freq; + paud_init.mode = PCM; + paud_init.operation = PLAY; + paud_init.channels = spec->channels; + + /* Try for a closest match on audio format */ + format = 0; + for (test_format = SDL_FirstAudioFormat (spec->format); + !format && test_format;) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Trying format 0x%4.4x\n", test_format); + fprintf (stderr, "Trying format 0x%4.4x\n", test_format); #endif - switch ( test_format ) { - case AUDIO_U8: - bytes_per_sample = 1; - paud_init.bits_per_sample = 8; - paud_init.flags = TWOS_COMPLEMENT | FIXED; - format = 1; - break; - case AUDIO_S8: - bytes_per_sample = 1; - paud_init.bits_per_sample = 8; - paud_init.flags = SIGNED | - TWOS_COMPLEMENT | FIXED; - format = 1; - break; - case AUDIO_S16LSB: - bytes_per_sample = 2; - paud_init.bits_per_sample = 16; - paud_init.flags = SIGNED | - TWOS_COMPLEMENT | FIXED; - format = 1; - break; - case AUDIO_S16MSB: - bytes_per_sample = 2; - paud_init.bits_per_sample = 16; - paud_init.flags = BIG_ENDIAN | - SIGNED | - TWOS_COMPLEMENT | FIXED; - format = 1; - break; - case AUDIO_U16LSB: - bytes_per_sample = 2; - paud_init.bits_per_sample = 16; - paud_init.flags = TWOS_COMPLEMENT | FIXED; - format = 1; - break; - case AUDIO_U16MSB: - bytes_per_sample = 2; - paud_init.bits_per_sample = 16; - paud_init.flags = BIG_ENDIAN | - TWOS_COMPLEMENT | FIXED; - format = 1; - break; - default: - break; - } - if ( ! format ) { - test_format = SDL_NextAudioFormat(); - } - } - if ( format == 0 ) { + switch (test_format) { + case AUDIO_U8: + bytes_per_sample = 1; + paud_init.bits_per_sample = 8; + paud_init.flags = TWOS_COMPLEMENT | FIXED; + format = 1; + break; + case AUDIO_S8: + bytes_per_sample = 1; + paud_init.bits_per_sample = 8; + paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED; + format = 1; + break; + case AUDIO_S16LSB: + bytes_per_sample = 2; + paud_init.bits_per_sample = 16; + paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED; + format = 1; + break; + case AUDIO_S16MSB: + bytes_per_sample = 2; + paud_init.bits_per_sample = 16; + paud_init.flags = BIG_ENDIAN | SIGNED | TWOS_COMPLEMENT | FIXED; + format = 1; + break; + case AUDIO_U16LSB: + bytes_per_sample = 2; + paud_init.bits_per_sample = 16; + paud_init.flags = TWOS_COMPLEMENT | FIXED; + format = 1; + break; + case AUDIO_U16MSB: + bytes_per_sample = 2; + paud_init.bits_per_sample = 16; + paud_init.flags = BIG_ENDIAN | TWOS_COMPLEMENT | FIXED; + format = 1; + break; + default: + break; + } + if (!format) { + test_format = SDL_NextAudioFormat (); + } + } + if (format == 0) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Couldn't find any hardware audio formats\n"); + fprintf (stderr, "Couldn't find any hardware audio formats\n"); #endif - SDL_SetError("Couldn't find any hardware audio formats"); - return -1; - } - spec->format = test_format; - - /* - * We know the buffer size and the max number of subsequent writes - * that can be pending. If more than one can pend, allow the application - * to do something like double buffering between our write buffer and - * the device's own buffer that we are filling with write() anyway. - * - * We calculate spec->samples like this because SDL_CalculateAudioSpec() - * will give put paud_bufinfo.write_buf_cap (or paud_bufinfo.write_buf_cap/2) - * into spec->size in return. - */ - if ( paud_bufinfo.request_buf_cap == 1 ) - { - spec->samples = paud_bufinfo.write_buf_cap - / bytes_per_sample - / spec->channels; - } - else - { - spec->samples = paud_bufinfo.write_buf_cap - / bytes_per_sample - / spec->channels - / 2; - } - paud_init.bsize = bytes_per_sample * spec->channels; - - SDL_CalculateAudioSpec(spec); - - /* - * The AIX paud device init can't modify the values of the audio_init - * structure that we pass to it. So we don't need any recalculation - * of this stuff and no reinit call as in linux dsp and dma code. - * - * /dev/paud supports all of the encoding formats, so we don't need - * to do anything like reopening the device, either. - */ - if ( ioctl(audio_fd, AUDIO_INIT, &paud_init) < 0 ) { - switch ( paud_init.rc ) - { - case 1 : - SDL_SetError("Couldn't set audio format: DSP can't do play requests"); - return -1; - break; - case 2 : - SDL_SetError("Couldn't set audio format: DSP can't do record requests"); - return -1; - break; - case 4 : - SDL_SetError("Couldn't set audio format: request was invalid"); - return -1; - break; - case 5 : - SDL_SetError("Couldn't set audio format: conflict with open's flags"); - return -1; - break; - case 6 : - SDL_SetError("Couldn't set audio format: out of DSP MIPS or memory"); - return -1; - break; - default : - SDL_SetError("Couldn't set audio format: not documented in sys/audio.h"); - return -1; - break; - } - } - - /* Allocate mixing buffer */ - mixlen = spec->size; - mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); - if ( mixbuf == NULL ) { - return -1; - } - SDL_memset(mixbuf, spec->silence, spec->size); - - /* - * Set some paramters: full volume, first speaker that we can find. - * Ignore the other settings for now. - */ - paud_change.input = AUDIO_IGNORE; /* the new input source */ - paud_change.output = OUTPUT_1; /* EXTERNAL_SPEAKER,INTERNAL_SPEAKER,OUTPUT_1 */ - paud_change.monitor = AUDIO_IGNORE; /* the new monitor state */ - paud_change.volume = 0x7fffffff; /* volume level [0-0x7fffffff] */ - paud_change.volume_delay = AUDIO_IGNORE; /* the new volume delay */ - paud_change.balance = 0x3fffffff; /* the new balance */ - paud_change.balance_delay = AUDIO_IGNORE; /* the new balance delay */ - paud_change.treble = AUDIO_IGNORE; /* the new treble state */ - paud_change.bass = AUDIO_IGNORE; /* the new bass state */ - paud_change.pitch = AUDIO_IGNORE; /* the new pitch state */ - - paud_control.ioctl_request = AUDIO_CHANGE; - paud_control.request_info = (char*)&paud_change; - if ( ioctl(audio_fd, AUDIO_CONTROL, &paud_control) < 0 ) { + SDL_SetError ("Couldn't find any hardware audio formats"); + return -1; + } + spec->format = test_format; + + /* + * We know the buffer size and the max number of subsequent writes + * that can be pending. If more than one can pend, allow the application + * to do something like double buffering between our write buffer and + * the device's own buffer that we are filling with write() anyway. + * + * We calculate spec->samples like this because SDL_CalculateAudioSpec() + * will give put paud_bufinfo.write_buf_cap (or paud_bufinfo.write_buf_cap/2) + * into spec->size in return. + */ + if (paud_bufinfo.request_buf_cap == 1) { + spec->samples = paud_bufinfo.write_buf_cap + / bytes_per_sample / spec->channels; + } else { + spec->samples = paud_bufinfo.write_buf_cap + / bytes_per_sample / spec->channels / 2; + } + paud_init.bsize = bytes_per_sample * spec->channels; + + SDL_CalculateAudioSpec (spec); + + /* + * The AIX paud device init can't modify the values of the audio_init + * structure that we pass to it. So we don't need any recalculation + * of this stuff and no reinit call as in linux dsp and dma code. + * + * /dev/paud supports all of the encoding formats, so we don't need + * to do anything like reopening the device, either. + */ + if (ioctl (audio_fd, AUDIO_INIT, &paud_init) < 0) { + switch (paud_init.rc) { + case 1: + SDL_SetError + ("Couldn't set audio format: DSP can't do play requests"); + return -1; + break; + case 2: + SDL_SetError + ("Couldn't set audio format: DSP can't do record requests"); + return -1; + break; + case 4: + SDL_SetError ("Couldn't set audio format: request was invalid"); + return -1; + break; + case 5: + SDL_SetError + ("Couldn't set audio format: conflict with open's flags"); + return -1; + break; + case 6: + SDL_SetError + ("Couldn't set audio format: out of DSP MIPS or memory"); + return -1; + break; + default: + SDL_SetError + ("Couldn't set audio format: not documented in sys/audio.h"); + return -1; + break; + } + } + + /* Allocate mixing buffer */ + mixlen = spec->size; + mixbuf = (Uint8 *) SDL_AllocAudioMem (mixlen); + if (mixbuf == NULL) { + return -1; + } + SDL_memset (mixbuf, spec->silence, spec->size); + + /* + * Set some paramters: full volume, first speaker that we can find. + * Ignore the other settings for now. + */ + paud_change.input = AUDIO_IGNORE; /* the new input source */ + paud_change.output = OUTPUT_1; /* EXTERNAL_SPEAKER,INTERNAL_SPEAKER,OUTPUT_1 */ + paud_change.monitor = AUDIO_IGNORE; /* the new monitor state */ + paud_change.volume = 0x7fffffff; /* volume level [0-0x7fffffff] */ + paud_change.volume_delay = AUDIO_IGNORE; /* the new volume delay */ + paud_change.balance = 0x3fffffff; /* the new balance */ + paud_change.balance_delay = AUDIO_IGNORE; /* the new balance delay */ + paud_change.treble = AUDIO_IGNORE; /* the new treble state */ + paud_change.bass = AUDIO_IGNORE; /* the new bass state */ + paud_change.pitch = AUDIO_IGNORE; /* the new pitch state */ + + paud_control.ioctl_request = AUDIO_CHANGE; + paud_control.request_info = (char *) &paud_change; + if (ioctl (audio_fd, AUDIO_CONTROL, &paud_control) < 0) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Can't change audio display settings\n" ); + fprintf (stderr, "Can't change audio display settings\n"); #endif - } - - /* - * Tell the device to expect data. Actual start will wait for - * the first write() call. - */ - paud_control.ioctl_request = AUDIO_START; - paud_control.position = 0; - if ( ioctl(audio_fd, AUDIO_CONTROL, &paud_control) < 0 ) { + } + + /* + * Tell the device to expect data. Actual start will wait for + * the first write() call. + */ + paud_control.ioctl_request = AUDIO_START; + paud_control.position = 0; + if (ioctl (audio_fd, AUDIO_CONTROL, &paud_control) < 0) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Can't start audio play\n" ); + fprintf (stderr, "Can't start audio play\n"); #endif - SDL_SetError("Can't start audio play"); - return -1; - } - - /* Check to see if we need to use select() workaround */ - { char *workaround; - workaround = SDL_getenv("SDL_DSP_NOSELECT"); - if ( workaround ) { - frame_ticks = (float)(spec->samples*1000)/spec->freq; - next_frame = SDL_GetTicks()+frame_ticks; - } + SDL_SetError ("Can't start audio play"); + return -1; + } + + /* Check to see if we need to use select() workaround */ + { + char *workaround; + workaround = SDL_getenv ("SDL_DSP_NOSELECT"); + if (workaround) { + frame_ticks = (float) (spec->samples * 1000) / spec->freq; + next_frame = SDL_GetTicks () + frame_ticks; } + } - /* Get the parent process id (we're the parent of the audio thread) */ - parent = getpid(); + /* Get the parent process id (we're the parent of the audio thread) */ + parent = getpid (); - /* We're ready to rock and roll. :-) */ - return 0; + /* We're ready to rock and roll. :-) */ + return 0; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/paudio/SDL_paudio.h b/src/audio/paudio/SDL_paudio.h index a3f22edae..757dadd55 100644 --- a/src/audio/paudio/SDL_paudio.h +++ b/src/audio/paudio/SDL_paudio.h @@ -29,22 +29,23 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - int audio_fd; +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + int audio_fd; - /* The parent process id, to detect when application quits */ - pid_t parent; + /* The parent process id, to detect when application quits */ + pid_t parent; - /* Raw mixing buffer */ - Uint8 *mixbuf; - int mixlen; + /* Raw mixing buffer */ + Uint8 *mixbuf; + int mixlen; - /* Support for audio timing using a timer, in addition to select() */ - float frame_ticks; - float next_frame; + /* Support for audio timing using a timer, in addition to select() */ + float frame_ticks; + float next_frame; }; -#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ +#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ /* Old variable names */ #define audio_fd (this->hidden->audio_fd) @@ -55,3 +56,4 @@ struct SDL_PrivateAudioData { #define next_frame (this->hidden->next_frame) #endif /* _SDL_paudaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c index 5ddaba108..828dd5ea1 100644 --- a/src/audio/sun/SDL_sunaudio.c +++ b/src/audio/sun/SDL_sunaudio.c @@ -48,335 +48,348 @@ #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) /* Audio driver functions */ -static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DSP_WaitAudio(_THIS); -static void DSP_PlayAudio(_THIS); -static Uint8 *DSP_GetAudioBuf(_THIS); -static void DSP_CloseAudio(_THIS); +static int DSP_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DSP_WaitAudio (_THIS); +static void DSP_PlayAudio (_THIS); +static Uint8 *DSP_GetAudioBuf (_THIS); +static void DSP_CloseAudio (_THIS); -static Uint8 snd2au(int sample); +static Uint8 snd2au (int sample); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - int fd; - int available; - - available = 0; - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 1); - if ( fd >= 0 ) { - available = 1; - close(fd); - } - return(available); + int fd; + int available; + + available = 0; + fd = SDL_OpenAudioPath (NULL, 0, OPEN_FLAGS, 1); + if (fd >= 0) { + available = 1; + close (fd); + } + return (available); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = DSP_OpenAudio; - this->WaitAudio = DSP_WaitAudio; - this->PlayAudio = DSP_PlayAudio; - this->GetAudioBuf = DSP_GetAudioBuf; - this->CloseAudio = DSP_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + audio_fd = -1; + + /* Set the function pointers */ + this->OpenAudio = DSP_OpenAudio; + this->WaitAudio = DSP_WaitAudio; + this->PlayAudio = DSP_PlayAudio; + this->GetAudioBuf = DSP_GetAudioBuf; + this->CloseAudio = DSP_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap SUNAUDIO_bootstrap = { - "audio", "UNIX /dev/audio interface", - Audio_Available, Audio_CreateDevice + "audio", "UNIX /dev/audio interface", + Audio_Available, Audio_CreateDevice }; #ifdef DEBUG_AUDIO -void CheckUnderflow(_THIS) +void +CheckUnderflow (_THIS) { #ifdef AUDIO_GETINFO - audio_info_t info; - int left; - - ioctl(audio_fd, AUDIO_GETINFO, &info); - left = (written - info.play.samples); - if ( written && (left == 0) ) { - fprintf(stderr, "audio underflow!\n"); - } + audio_info_t info; + int left; + + ioctl (audio_fd, AUDIO_GETINFO, &info); + left = (written - info.play.samples); + if (written && (left == 0)) { + fprintf (stderr, "audio underflow!\n"); + } #endif } #endif -void DSP_WaitAudio(_THIS) +void +DSP_WaitAudio (_THIS) { #ifdef AUDIO_GETINFO -#define SLEEP_FUDGE 10 /* 10 ms scheduling fudge factor */ - audio_info_t info; - Sint32 left; - - ioctl(audio_fd, AUDIO_GETINFO, &info); - left = (written - info.play.samples); - if ( left > fragsize ) { - Sint32 sleepy; - - sleepy = ((left - fragsize)/frequency); - sleepy -= SLEEP_FUDGE; - if ( sleepy > 0 ) { - SDL_Delay(sleepy); - } - } +#define SLEEP_FUDGE 10 /* 10 ms scheduling fudge factor */ + audio_info_t info; + Sint32 left; + + ioctl (audio_fd, AUDIO_GETINFO, &info); + left = (written - info.play.samples); + if (left > fragsize) { + Sint32 sleepy; + + sleepy = ((left - fragsize) / frequency); + sleepy -= SLEEP_FUDGE; + if (sleepy > 0) { + SDL_Delay (sleepy); + } + } #else - fd_set fdset; + fd_set fdset; - FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); - select(audio_fd+1, NULL, &fdset, NULL, NULL); + FD_ZERO (&fdset); + FD_SET (audio_fd, &fdset); + select (audio_fd + 1, NULL, &fdset, NULL, NULL); #endif } -void DSP_PlayAudio(_THIS) +void +DSP_PlayAudio (_THIS) { - /* Write the audio data */ - if ( ulaw_only ) { - /* Assuming that this->spec.freq >= 8000 Hz */ - int accum, incr, pos; - Uint8 *aubuf; - - accum = 0; - incr = this->spec.freq/8; - aubuf = ulaw_buf; - switch (audio_fmt & 0xFF) { - case 8: { - Uint8 *sndbuf; - - sndbuf = mixbuf; - for ( pos=0; pos < fragsize; ++pos ) { - *aubuf = snd2au((0x80-*sndbuf)*64); - accum += incr; - while ( accum > 0 ) { - accum -= 1000; - sndbuf += 1; - } - aubuf += 1; - } - } - break; - case 16: { - Sint16 *sndbuf; - - sndbuf = (Sint16 *)mixbuf; - for ( pos=0; pos < fragsize; ++pos ) { - *aubuf = snd2au(*sndbuf/4); - accum += incr; - while ( accum > 0 ) { - accum -= 1000; - sndbuf += 1; - } - aubuf += 1; - } - } - break; - } + /* Write the audio data */ + if (ulaw_only) { + /* Assuming that this->spec.freq >= 8000 Hz */ + int accum, incr, pos; + Uint8 *aubuf; + + accum = 0; + incr = this->spec.freq / 8; + aubuf = ulaw_buf; + switch (audio_fmt & 0xFF) { + case 8: + { + Uint8 *sndbuf; + + sndbuf = mixbuf; + for (pos = 0; pos < fragsize; ++pos) { + *aubuf = snd2au ((0x80 - *sndbuf) * 64); + accum += incr; + while (accum > 0) { + accum -= 1000; + sndbuf += 1; + } + aubuf += 1; + } + } + break; + case 16: + { + Sint16 *sndbuf; + + sndbuf = (Sint16 *) mixbuf; + for (pos = 0; pos < fragsize; ++pos) { + *aubuf = snd2au (*sndbuf / 4); + accum += incr; + while (accum > 0) { + accum -= 1000; + sndbuf += 1; + } + aubuf += 1; + } + } + break; + } #ifdef DEBUG_AUDIO - CheckUnderflow(this); + CheckUnderflow (this); #endif - if ( write(audio_fd, ulaw_buf, fragsize) < 0 ) { - /* Assume fatal error, for now */ - this->enabled = 0; - } - written += fragsize; - } else { + if (write (audio_fd, ulaw_buf, fragsize) < 0) { + /* Assume fatal error, for now */ + this->enabled = 0; + } + written += fragsize; + } else { #ifdef DEBUG_AUDIO - CheckUnderflow(this); + CheckUnderflow (this); #endif - if ( write(audio_fd, mixbuf, this->spec.size) < 0 ) { - /* Assume fatal error, for now */ - this->enabled = 0; - } - written += fragsize; - } + if (write (audio_fd, mixbuf, this->spec.size) < 0) { + /* Assume fatal error, for now */ + this->enabled = 0; + } + written += fragsize; + } } -Uint8 *DSP_GetAudioBuf(_THIS) +Uint8 * +DSP_GetAudioBuf (_THIS) { - return(mixbuf); + return (mixbuf); } -void DSP_CloseAudio(_THIS) +void +DSP_CloseAudio (_THIS) { - if ( mixbuf != NULL ) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if ( ulaw_buf != NULL ) { - SDL_free(ulaw_buf); - ulaw_buf = NULL; - } - close(audio_fd); + if (mixbuf != NULL) { + SDL_FreeAudioMem (mixbuf); + mixbuf = NULL; + } + if (ulaw_buf != NULL) { + SDL_free (ulaw_buf); + ulaw_buf = NULL; + } + close (audio_fd); } -int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec) +int +DSP_OpenAudio (_THIS, SDL_AudioSpec * spec) { - char audiodev[1024]; + char audiodev[1024]; #ifdef AUDIO_SETINFO - int enc; + int enc; #endif - int desired_freq = spec->freq; + int desired_freq = spec->freq; - /* Initialize our freeable variables, in case we fail*/ - audio_fd = -1; - mixbuf = NULL; - ulaw_buf = NULL; + /* Initialize our freeable variables, in case we fail */ + audio_fd = -1; + mixbuf = NULL; + ulaw_buf = NULL; - /* Determine the audio parameters from the AudioSpec */ - switch ( spec->format & 0xFF ) { + /* Determine the audio parameters from the AudioSpec */ + switch (spec->format & 0xFF) { - case 8: { /* Unsigned 8 bit audio data */ - spec->format = AUDIO_U8; + case 8: + { /* Unsigned 8 bit audio data */ + spec->format = AUDIO_U8; #ifdef AUDIO_SETINFO - enc = AUDIO_ENCODING_LINEAR8; + enc = AUDIO_ENCODING_LINEAR8; #endif - } - break; + } + break; - case 16: { /* Signed 16 bit audio data */ - spec->format = AUDIO_S16SYS; + case 16: + { /* Signed 16 bit audio data */ + spec->format = AUDIO_S16SYS; #ifdef AUDIO_SETINFO - enc = AUDIO_ENCODING_LINEAR; + enc = AUDIO_ENCODING_LINEAR; #endif - } - break; - - default: { - SDL_SetError("Unsupported audio format"); - return(-1); - } - } - audio_fmt = spec->format; - - /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 1); - if ( audio_fd < 0 ) { - SDL_SetError("Couldn't open %s: %s", audiodev, - strerror(errno)); - return(-1); - } - - ulaw_only = 0; /* modern Suns do support linear audio */ + } + break; + + default: + { + SDL_SetError ("Unsupported audio format"); + return (-1); + } + } + audio_fmt = spec->format; + + /* Open the audio device */ + audio_fd = SDL_OpenAudioPath (audiodev, sizeof (audiodev), OPEN_FLAGS, 1); + if (audio_fd < 0) { + SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); + return (-1); + } + + ulaw_only = 0; /* modern Suns do support linear audio */ #ifdef AUDIO_SETINFO - for(;;) { - audio_info_t info; - AUDIO_INITINFO(&info); /* init all fields to "no change" */ - - /* Try to set the requested settings */ - info.play.sample_rate = spec->freq; - info.play.channels = spec->channels; - info.play.precision = (enc == AUDIO_ENCODING_ULAW) - ? 8 : spec->format & 0xff; - info.play.encoding = enc; - if( ioctl(audio_fd, AUDIO_SETINFO, &info) == 0 ) { - - /* Check to be sure we got what we wanted */ - if(ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { - SDL_SetError("Error getting audio parameters: %s", - strerror(errno)); - return -1; - } - if(info.play.encoding == enc - && info.play.precision == (spec->format & 0xff) - && info.play.channels == spec->channels) { - /* Yow! All seems to be well! */ - spec->freq = info.play.sample_rate; - break; - } - } - - switch(enc) { - case AUDIO_ENCODING_LINEAR8: - /* unsigned 8bit apparently not supported here */ - enc = AUDIO_ENCODING_LINEAR; - spec->format = AUDIO_S16SYS; - break; /* try again */ - - case AUDIO_ENCODING_LINEAR: - /* linear 16bit didn't work either, resort to µ-law */ - enc = AUDIO_ENCODING_ULAW; - spec->channels = 1; - spec->freq = 8000; - spec->format = AUDIO_U8; - ulaw_only = 1; - break; - - default: - /* oh well... */ - SDL_SetError("Error setting audio parameters: %s", - strerror(errno)); - return -1; - } - } + for (;;) { + audio_info_t info; + AUDIO_INITINFO (&info); /* init all fields to "no change" */ + + /* Try to set the requested settings */ + info.play.sample_rate = spec->freq; + info.play.channels = spec->channels; + info.play.precision = (enc == AUDIO_ENCODING_ULAW) + ? 8 : spec->format & 0xff; + info.play.encoding = enc; + if (ioctl (audio_fd, AUDIO_SETINFO, &info) == 0) { + + /* Check to be sure we got what we wanted */ + if (ioctl (audio_fd, AUDIO_GETINFO, &info) < 0) { + SDL_SetError ("Error getting audio parameters: %s", + strerror (errno)); + return -1; + } + if (info.play.encoding == enc + && info.play.precision == (spec->format & 0xff) + && info.play.channels == spec->channels) { + /* Yow! All seems to be well! */ + spec->freq = info.play.sample_rate; + break; + } + } + + switch (enc) { + case AUDIO_ENCODING_LINEAR8: + /* unsigned 8bit apparently not supported here */ + enc = AUDIO_ENCODING_LINEAR; + spec->format = AUDIO_S16SYS; + break; /* try again */ + + case AUDIO_ENCODING_LINEAR: + /* linear 16bit didn't work either, resort to µ-law */ + enc = AUDIO_ENCODING_ULAW; + spec->channels = 1; + spec->freq = 8000; + spec->format = AUDIO_U8; + ulaw_only = 1; + break; + + default: + /* oh well... */ + SDL_SetError ("Error setting audio parameters: %s", + strerror (errno)); + return -1; + } + } #endif /* AUDIO_SETINFO */ - written = 0; - - /* We can actually convert on-the-fly to U-Law */ - if ( ulaw_only ) { - spec->freq = desired_freq; - fragsize = (spec->samples*1000)/(spec->freq/8); - frequency = 8; - ulaw_buf = (Uint8 *)SDL_malloc(fragsize); - if ( ulaw_buf == NULL ) { - SDL_OutOfMemory(); - return(-1); - } - spec->channels = 1; - } else { - fragsize = spec->samples; - frequency = spec->freq/1000; - } + written = 0; + + /* We can actually convert on-the-fly to U-Law */ + if (ulaw_only) { + spec->freq = desired_freq; + fragsize = (spec->samples * 1000) / (spec->freq / 8); + frequency = 8; + ulaw_buf = (Uint8 *) SDL_malloc (fragsize); + if (ulaw_buf == NULL) { + SDL_OutOfMemory (); + return (-1); + } + spec->channels = 1; + } else { + fragsize = spec->samples; + frequency = spec->freq / 1000; + } #ifdef DEBUG_AUDIO - fprintf(stderr, "Audio device %s U-Law only\n", - ulaw_only ? "is" : "is not"); - fprintf(stderr, "format=0x%x chan=%d freq=%d\n", - spec->format, spec->channels, spec->freq); + fprintf (stderr, "Audio device %s U-Law only\n", + ulaw_only ? "is" : "is not"); + fprintf (stderr, "format=0x%x chan=%d freq=%d\n", + spec->format, spec->channels, spec->freq); #endif - /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec (spec); - /* Allocate mixing buffer */ - mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size); - if ( mixbuf == NULL ) { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(mixbuf, spec->silence, spec->size); + /* Allocate mixing buffer */ + mixbuf = (Uint8 *) SDL_AllocAudioMem (spec->size); + if (mixbuf == NULL) { + SDL_OutOfMemory (); + return (-1); + } + SDL_memset (mixbuf, spec->silence, spec->size); - /* We're ready to rock and roll. :-) */ - return(0); + /* We're ready to rock and roll. :-) */ + return (0); } /************************************************************************/ @@ -397,36 +410,39 @@ int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec) /* provided "as is" without express or implied warranty. */ /************************************************************************/ -static Uint8 snd2au(int sample) +static Uint8 +snd2au (int sample) { - int mask; - - if (sample < 0) { - sample = -sample; - mask = 0x7f; - } else { - mask = 0xff; - } - - if (sample < 32) { - sample = 0xF0 | (15 - sample / 2); - } else if (sample < 96) { - sample = 0xE0 | (15 - (sample - 32) / 4); - } else if (sample < 224) { - sample = 0xD0 | (15 - (sample - 96) / 8); - } else if (sample < 480) { - sample = 0xC0 | (15 - (sample - 224) / 16); - } else if (sample < 992) { - sample = 0xB0 | (15 - (sample - 480) / 32); - } else if (sample < 2016) { - sample = 0xA0 | (15 - (sample - 992) / 64); - } else if (sample < 4064) { - sample = 0x90 | (15 - (sample - 2016) / 128); - } else if (sample < 8160) { - sample = 0x80 | (15 - (sample - 4064) / 256); - } else { - sample = 0x80; - } - return (mask & sample); + int mask; + + if (sample < 0) { + sample = -sample; + mask = 0x7f; + } else { + mask = 0xff; + } + + if (sample < 32) { + sample = 0xF0 | (15 - sample / 2); + } else if (sample < 96) { + sample = 0xE0 | (15 - (sample - 32) / 4); + } else if (sample < 224) { + sample = 0xD0 | (15 - (sample - 96) / 8); + } else if (sample < 480) { + sample = 0xC0 | (15 - (sample - 224) / 16); + } else if (sample < 992) { + sample = 0xB0 | (15 - (sample - 480) / 32); + } else if (sample < 2016) { + sample = 0xA0 | (15 - (sample - 992) / 64); + } else if (sample < 4064) { + sample = 0x90 | (15 - (sample - 2016) / 128); + } else if (sample < 8160) { + sample = 0x80 | (15 - (sample - 4064) / 256); + } else { + sample = 0x80; + } + return (mask & sample); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/sun/SDL_sunaudio.h b/src/audio/sun/SDL_sunaudio.h index 51b0d5e85..7f33a2f32 100644 --- a/src/audio/sun/SDL_sunaudio.h +++ b/src/audio/sun/SDL_sunaudio.h @@ -29,17 +29,18 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData { - /* The file descriptor for the audio device */ - int audio_fd; - - Uint16 audio_fmt; /* The app audio format */ - Uint8 *mixbuf; /* The app mixing buffer */ - int ulaw_only; /* Flag -- does hardware only output U-law? */ - Uint8 *ulaw_buf; /* The U-law mixing buffer */ - Sint32 written; /* The number of samples written */ - int fragsize; /* The audio fragment size in samples */ - int frequency; /* The audio frequency in KHz */ +struct SDL_PrivateAudioData +{ + /* The file descriptor for the audio device */ + int audio_fd; + + Uint16 audio_fmt; /* The app audio format */ + Uint8 *mixbuf; /* The app mixing buffer */ + int ulaw_only; /* Flag -- does hardware only output U-law? */ + Uint8 *ulaw_buf; /* The U-law mixing buffer */ + Sint32 written; /* The number of samples written */ + int fragsize; /* The audio fragment size in samples */ + int frequency; /* The audio frequency in KHz */ }; /* Old variable names */ @@ -53,3 +54,4 @@ struct SDL_PrivateAudioData { #define frequency (this->hidden->frequency) #endif /* _SDL_lowaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/ums/SDL_umsaudio.c b/src/audio/ums/SDL_umsaudio.c index 90bcd9b5b..76934e1e3 100644 --- a/src/audio/ums/SDL_umsaudio.c +++ b/src/audio/ums/SDL_umsaudio.c @@ -45,50 +45,64 @@ #define DEBUG_AUDIO 1 /* Audio driver functions */ -static int UMS_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void UMS_PlayAudio(_THIS); -static Uint8 *UMS_GetAudioBuf(_THIS); -static void UMS_CloseAudio(_THIS); - -static UMSAudioDevice_ReturnCode UADOpen(_THIS, string device, string mode, long flags); -static UMSAudioDevice_ReturnCode UADClose(_THIS); -static UMSAudioDevice_ReturnCode UADGetBitsPerSample(_THIS, long* bits); -static UMSAudioDevice_ReturnCode UADSetBitsPerSample(_THIS, long bits); -static UMSAudioDevice_ReturnCode UADSetSampleRate(_THIS, long rate, long* set_rate); -static UMSAudioDevice_ReturnCode UADSetByteOrder(_THIS, string byte_order); -static UMSAudioDevice_ReturnCode UADSetAudioFormatType(_THIS, string fmt); -static UMSAudioDevice_ReturnCode UADSetNumberFormat(_THIS, string fmt); -static UMSAudioDevice_ReturnCode UADInitialize(_THIS); -static UMSAudioDevice_ReturnCode UADStart(_THIS); -static UMSAudioDevice_ReturnCode UADStop(_THIS); -static UMSAudioDevice_ReturnCode UADSetTimeFormat(_THIS, UMSAudioTypes_TimeFormat fmt ); -static UMSAudioDevice_ReturnCode UADWriteBuffSize(_THIS, long* buff_size ); -static UMSAudioDevice_ReturnCode UADWriteBuffRemain(_THIS, long* buff_size ); -static UMSAudioDevice_ReturnCode UADWriteBuffUsed(_THIS, long* buff_size ); -static UMSAudioDevice_ReturnCode UADSetDMABufferSize(_THIS, long bytes, long* bytes_ret ); -static UMSAudioDevice_ReturnCode UADSetVolume(_THIS, long volume ); -static UMSAudioDevice_ReturnCode UADSetBalance(_THIS, long balance ); -static UMSAudioDevice_ReturnCode UADSetChannels(_THIS, long channels ); -static UMSAudioDevice_ReturnCode UADPlayRemainingData(_THIS, boolean block ); -static UMSAudioDevice_ReturnCode UADEnableOutput(_THIS, string output, long* left_gain, long* right_gain); -static UMSAudioDevice_ReturnCode UADWrite(_THIS, UMSAudioTypes_Buffer* buff, long samples, long* samples_written); +static int UMS_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void UMS_PlayAudio (_THIS); +static Uint8 *UMS_GetAudioBuf (_THIS); +static void UMS_CloseAudio (_THIS); + +static UMSAudioDevice_ReturnCode UADOpen (_THIS, string device, string mode, + long flags); +static UMSAudioDevice_ReturnCode UADClose (_THIS); +static UMSAudioDevice_ReturnCode UADGetBitsPerSample (_THIS, long *bits); +static UMSAudioDevice_ReturnCode UADSetBitsPerSample (_THIS, long bits); +static UMSAudioDevice_ReturnCode UADSetSampleRate (_THIS, long rate, + long *set_rate); +static UMSAudioDevice_ReturnCode UADSetByteOrder (_THIS, string byte_order); +static UMSAudioDevice_ReturnCode UADSetAudioFormatType (_THIS, string fmt); +static UMSAudioDevice_ReturnCode UADSetNumberFormat (_THIS, string fmt); +static UMSAudioDevice_ReturnCode UADInitialize (_THIS); +static UMSAudioDevice_ReturnCode UADStart (_THIS); +static UMSAudioDevice_ReturnCode UADStop (_THIS); +static UMSAudioDevice_ReturnCode UADSetTimeFormat (_THIS, + UMSAudioTypes_TimeFormat + fmt); +static UMSAudioDevice_ReturnCode UADWriteBuffSize (_THIS, long *buff_size); +static UMSAudioDevice_ReturnCode UADWriteBuffRemain (_THIS, long *buff_size); +static UMSAudioDevice_ReturnCode UADWriteBuffUsed (_THIS, long *buff_size); +static UMSAudioDevice_ReturnCode UADSetDMABufferSize (_THIS, long bytes, + long *bytes_ret); +static UMSAudioDevice_ReturnCode UADSetVolume (_THIS, long volume); +static UMSAudioDevice_ReturnCode UADSetBalance (_THIS, long balance); +static UMSAudioDevice_ReturnCode UADSetChannels (_THIS, long channels); +static UMSAudioDevice_ReturnCode UADPlayRemainingData (_THIS, boolean block); +static UMSAudioDevice_ReturnCode UADEnableOutput (_THIS, string output, + long *left_gain, + long *right_gain); +static UMSAudioDevice_ReturnCode UADWrite (_THIS, UMSAudioTypes_Buffer * buff, + long samples, + long *samples_written); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { return 1; } -static void Audio_DeleteDevice(_THIS) +static void +Audio_DeleteDevice (_THIS) { - if(this->hidden->playbuf._buffer) SDL_free(this->hidden->playbuf._buffer); - if(this->hidden->fillbuf._buffer) SDL_free(this->hidden->fillbuf._buffer); - _somFree( this->hidden->umsdev ); - SDL_free(this->hidden); - SDL_free(this); + if (this->hidden->playbuf._buffer) + SDL_free (this->hidden->playbuf._buffer); + if (this->hidden->fillbuf._buffer) + SDL_free (this->hidden->fillbuf._buffer); + _somFree (this->hidden->umsdev); + SDL_free (this->hidden); + SDL_free (this); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { SDL_AudioDevice *this; @@ -96,54 +110,56 @@ static SDL_AudioDevice *Audio_CreateDevice(int devindex) * Allocate and initialize management storage and private management * storage for this SDL-using library. */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *)SDL_malloc((sizeof *this->hidden)); + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); } - return(0); + return (0); } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); #ifdef DEBUG_AUDIO - fprintf(stderr, "Creating UMS Audio device\n"); + fprintf (stderr, "Creating UMS Audio device\n"); #endif /* * Calls for UMS env initialization and audio object construction. */ - this->hidden->ev = somGetGlobalEnvironment(); - this->hidden->umsdev = UMSAudioDeviceNew(); + this->hidden->ev = somGetGlobalEnvironment (); + this->hidden->umsdev = UMSAudioDeviceNew (); /* * Set the function pointers. */ - this->OpenAudio = UMS_OpenAudio; - this->WaitAudio = NULL; /* we do blocking output */ - this->PlayAudio = UMS_PlayAudio; + this->OpenAudio = UMS_OpenAudio; + this->WaitAudio = NULL; /* we do blocking output */ + this->PlayAudio = UMS_PlayAudio; this->GetAudioBuf = UMS_GetAudioBuf; - this->CloseAudio = UMS_CloseAudio; - this->free = Audio_DeleteDevice; + this->CloseAudio = UMS_CloseAudio; + this->free = Audio_DeleteDevice; #ifdef DEBUG_AUDIO - fprintf(stderr, "done\n"); + fprintf (stderr, "done\n"); #endif return this; } AudioBootStrap UMS_bootstrap = { - UMS_DRIVER_NAME, "AUX UMS audio", - Audio_Available, Audio_CreateDevice + UMS_DRIVER_NAME, "AUX UMS audio", + Audio_Available, Audio_CreateDevice }; -static Uint8 *UMS_GetAudioBuf(_THIS) +static Uint8 * +UMS_GetAudioBuf (_THIS) { #ifdef DEBUG_AUDIO - fprintf(stderr, "enter UMS_GetAudioBuf\n"); + fprintf (stderr, "enter UMS_GetAudioBuf\n"); #endif return this->hidden->fillbuf._buffer; /* @@ -155,393 +171,393 @@ static Uint8 *UMS_GetAudioBuf(_THIS) */ } -static void UMS_CloseAudio(_THIS) +static void +UMS_CloseAudio (_THIS) { UMSAudioDevice_ReturnCode rc; #ifdef DEBUG_AUDIO - fprintf(stderr, "enter UMS_CloseAudio\n"); + fprintf (stderr, "enter UMS_CloseAudio\n"); #endif - rc = UADPlayRemainingData(this, TRUE); - rc = UADStop(this); - rc = UADClose(this); + rc = UADPlayRemainingData (this, TRUE); + rc = UADStop (this); + rc = UADClose (this); } -static void UMS_PlayAudio(_THIS) +static void +UMS_PlayAudio (_THIS) { UMSAudioDevice_ReturnCode rc; - long samplesToWrite; - long samplesWritten; - UMSAudioTypes_Buffer swpbuf; + long samplesToWrite; + long samplesWritten; + UMSAudioTypes_Buffer swpbuf; #ifdef DEBUG_AUDIO - fprintf(stderr, "enter UMS_PlayAudio\n"); + fprintf (stderr, "enter UMS_PlayAudio\n"); #endif - samplesToWrite = this->hidden->playbuf._length/this->hidden->bytesPerSample; - do - { - rc = UADWrite(this, &this->hidden->playbuf, - samplesToWrite, - &samplesWritten ); - samplesToWrite -= samplesWritten; - - /* rc values: UMSAudioDevice_Success - * UMSAudioDevice_Failure - * UMSAudioDevice_Preempted - * UMSAudioDevice_Interrupted - * UMSAudioDevice_DeviceError - */ - if ( rc == UMSAudioDevice_DeviceError ) { + samplesToWrite = + this->hidden->playbuf._length / this->hidden->bytesPerSample; + do { + rc = UADWrite (this, &this->hidden->playbuf, + samplesToWrite, &samplesWritten); + samplesToWrite -= samplesWritten; + + /* rc values: UMSAudioDevice_Success + * UMSAudioDevice_Failure + * UMSAudioDevice_Preempted + * UMSAudioDevice_Interrupted + * UMSAudioDevice_DeviceError + */ + if (rc == UMSAudioDevice_DeviceError) { #ifdef DEBUG_AUDIO - fprintf(stderr, "Returning from PlayAudio with devices error\n"); + fprintf (stderr, "Returning from PlayAudio with devices error\n"); #endif - return; - } + return; + } } - while(samplesToWrite>0); + while (samplesToWrite > 0); - SDL_LockAudio(); - SDL_memcpy( &swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer) ); - SDL_memcpy( &this->hidden->playbuf, &this->hidden->fillbuf, sizeof(UMSAudioTypes_Buffer) ); - SDL_memcpy( &this->hidden->fillbuf, &swpbuf, sizeof(UMSAudioTypes_Buffer) ); - SDL_UnlockAudio(); + SDL_LockAudio (); + SDL_memcpy (&swpbuf, &this->hidden->playbuf, + sizeof (UMSAudioTypes_Buffer)); + SDL_memcpy (&this->hidden->playbuf, &this->hidden->fillbuf, + sizeof (UMSAudioTypes_Buffer)); + SDL_memcpy (&this->hidden->fillbuf, &swpbuf, + sizeof (UMSAudioTypes_Buffer)); + SDL_UnlockAudio (); #ifdef DEBUG_AUDIO - fprintf(stderr, "Wrote audio data and swapped buffer\n"); + fprintf (stderr, "Wrote audio data and swapped buffer\n"); #endif } #if 0 -// /* Set the DSP frequency */ -// value = spec->freq; -// if ( ioctl(this->hidden->audio_fd, SOUND_PCM_WRITE_RATE, &value) < 0 ) { -// SDL_SetError("Couldn't set audio frequency"); -// return(-1); -// } -// spec->freq = value; +// /* Set the DSP frequency */ +// value = spec->freq; +// if ( ioctl(this->hidden->audio_fd, SOUND_PCM_WRITE_RATE, &value) < 0 ) { +// SDL_SetError("Couldn't set audio frequency"); +// return(-1); +// } +// spec->freq = value; #endif -static int UMS_OpenAudio(_THIS, SDL_AudioSpec *spec) +static int +UMS_OpenAudio (_THIS, SDL_AudioSpec * spec) { - char* audiodev = "/dev/paud0"; - long lgain; - long rgain; - long outRate; - long outBufSize; - long bitsPerSample; - long samplesPerSec; - long success; + char *audiodev = "/dev/paud0"; + long lgain; + long rgain; + long outRate; + long outBufSize; + long bitsPerSample; + long samplesPerSec; + long success; Uint16 test_format; - int frag_spec; + int frag_spec; UMSAudioDevice_ReturnCode rc; #ifdef DEBUG_AUDIO - fprintf(stderr, "enter UMS_OpenAudio\n"); + fprintf (stderr, "enter UMS_OpenAudio\n"); #endif - rc = UADOpen(this, audiodev,"PLAY", UMSAudioDevice_BlockingIO); - if ( rc != UMSAudioDevice_Success ) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return -1; + rc = UADOpen (this, audiodev, "PLAY", UMSAudioDevice_BlockingIO); + if (rc != UMSAudioDevice_Success) { + SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); + return -1; } - - rc = UADSetAudioFormatType(this, "PCM"); + + rc = UADSetAudioFormatType (this, "PCM"); success = 0; - test_format = SDL_FirstAudioFormat(spec->format); - do - { + test_format = SDL_FirstAudioFormat (spec->format); + do { #ifdef DEBUG_AUDIO - fprintf(stderr, "Trying format 0x%4.4x\n", test_format); + fprintf (stderr, "Trying format 0x%4.4x\n", test_format); #endif - switch ( test_format ) - { + switch (test_format) { case AUDIO_U8: /* from the mac code: better ? */ /* sample_bits = spec->size / spec->samples / spec->channels * 8; */ - success = 1; + success = 1; bitsPerSample = 8; - rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); - rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ - rc = UADSetNumberFormat(this, "UNSIGNED"); + rc = UADSetSampleRate (this, spec->freq << 16, &outRate); + rc = UADSetByteOrder (this, "MSB"); /* irrelevant */ + rc = UADSetNumberFormat (this, "UNSIGNED"); break; case AUDIO_S8: - success = 1; + success = 1; bitsPerSample = 8; - rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); - rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ - rc = UADSetNumberFormat(this, "SIGNED"); + rc = UADSetSampleRate (this, spec->freq << 16, &outRate); + rc = UADSetByteOrder (this, "MSB"); /* irrelevant */ + rc = UADSetNumberFormat (this, "SIGNED"); break; case AUDIO_S16LSB: - success = 1; + success = 1; bitsPerSample = 16; - rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); - rc = UADSetByteOrder(this, "LSB"); - rc = UADSetNumberFormat(this, "SIGNED"); + rc = UADSetSampleRate (this, spec->freq << 16, &outRate); + rc = UADSetByteOrder (this, "LSB"); + rc = UADSetNumberFormat (this, "SIGNED"); break; case AUDIO_S16MSB: - success = 1; + success = 1; bitsPerSample = 16; - rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); - rc = UADSetByteOrder(this, "MSB"); - rc = UADSetNumberFormat(this, "SIGNED"); + rc = UADSetSampleRate (this, spec->freq << 16, &outRate); + rc = UADSetByteOrder (this, "MSB"); + rc = UADSetNumberFormat (this, "SIGNED"); break; case AUDIO_U16LSB: - success = 1; + success = 1; bitsPerSample = 16; - rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); - rc = UADSetByteOrder(this, "LSB"); - rc = UADSetNumberFormat(this, "UNSIGNED"); + rc = UADSetSampleRate (this, spec->freq << 16, &outRate); + rc = UADSetByteOrder (this, "LSB"); + rc = UADSetNumberFormat (this, "UNSIGNED"); break; case AUDIO_U16MSB: - success = 1; + success = 1; bitsPerSample = 16; - rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); - rc = UADSetByteOrder(this, "MSB"); - rc = UADSetNumberFormat(this, "UNSIGNED"); + rc = UADSetSampleRate (this, spec->freq << 16, &outRate); + rc = UADSetByteOrder (this, "MSB"); + rc = UADSetNumberFormat (this, "UNSIGNED"); break; default: break; } - if ( ! success ) { - test_format = SDL_NextAudioFormat(); + if (!success) { + test_format = SDL_NextAudioFormat (); } } - while ( ! success && test_format ); + while (!success && test_format); - if ( success == 0 ) { - SDL_SetError("Couldn't find any hardware audio formats"); + if (success == 0) { + SDL_SetError ("Couldn't find any hardware audio formats"); return -1; } spec->format = test_format; - for ( frag_spec = 0; (0x01<size; ++frag_spec ); - if ( (0x01<size ) { - SDL_SetError("Fragment size must be a power of two"); + for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec); + if ((0x01 << frag_spec) != spec->size) { + SDL_SetError ("Fragment size must be a power of two"); return -1; } - if ( frag_spec > 2048 ) frag_spec = 2048; + if (frag_spec > 2048) + frag_spec = 2048; - this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels; - samplesPerSec = this->hidden->bytesPerSample * outRate; + this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels; + samplesPerSec = this->hidden->bytesPerSample * outRate; - this->hidden->playbuf._length = 0; + this->hidden->playbuf._length = 0; this->hidden->playbuf._maximum = spec->size; - this->hidden->playbuf._buffer = (unsigned char*)SDL_malloc(spec->size); - this->hidden->fillbuf._length = 0; + this->hidden->playbuf._buffer = (unsigned char *) SDL_malloc (spec->size); + this->hidden->fillbuf._length = 0; this->hidden->fillbuf._maximum = spec->size; - this->hidden->fillbuf._buffer = (unsigned char*)SDL_malloc(spec->size); + this->hidden->fillbuf._buffer = (unsigned char *) SDL_malloc (spec->size); - rc = UADSetBitsPerSample(this, bitsPerSample ); - rc = UADSetDMABufferSize(this, frag_spec, &outBufSize ); - rc = UADSetChannels(this, spec->channels); /* functions reduces to mono or stereo */ + rc = UADSetBitsPerSample (this, bitsPerSample); + rc = UADSetDMABufferSize (this, frag_spec, &outBufSize); + rc = UADSetChannels (this, spec->channels); /* functions reduces to mono or stereo */ - lgain = 100; /*maximum left input gain*/ - rgain = 100; /*maimum right input gain*/ - rc = UADEnableOutput(this, "LINE_OUT",&lgain,&rgain); - rc = UADInitialize(this); - rc = UADStart(this); - rc = UADSetVolume(this, 100); - rc = UADSetBalance(this, 0); + lgain = 100; /*maximum left input gain */ + rgain = 100; /*maimum right input gain */ + rc = UADEnableOutput (this, "LINE_OUT", &lgain, &rgain); + rc = UADInitialize (this); + rc = UADStart (this); + rc = UADSetVolume (this, 100); + rc = UADSetBalance (this, 0); /* We're ready to rock and roll. :-) */ return 0; } - -static UMSAudioDevice_ReturnCode UADGetBitsPerSample(_THIS, long* bits) + +static UMSAudioDevice_ReturnCode +UADGetBitsPerSample (_THIS, long *bits) { - return UMSAudioDevice_get_bits_per_sample( this->hidden->umsdev, - this->hidden->ev, - bits ); + return UMSAudioDevice_get_bits_per_sample (this->hidden->umsdev, + this->hidden->ev, bits); } -static UMSAudioDevice_ReturnCode UADSetBitsPerSample(_THIS, long bits) +static UMSAudioDevice_ReturnCode +UADSetBitsPerSample (_THIS, long bits) { - return UMSAudioDevice_set_bits_per_sample( this->hidden->umsdev, - this->hidden->ev, - bits ); + return UMSAudioDevice_set_bits_per_sample (this->hidden->umsdev, + this->hidden->ev, bits); } -static UMSAudioDevice_ReturnCode UADSetSampleRate(_THIS, long rate, long* set_rate) +static UMSAudioDevice_ReturnCode +UADSetSampleRate (_THIS, long rate, long *set_rate) { /* from the mac code: sample rate = spec->freq << 16; */ - return UMSAudioDevice_set_sample_rate( this->hidden->umsdev, - this->hidden->ev, - rate, - set_rate ); + return UMSAudioDevice_set_sample_rate (this->hidden->umsdev, + this->hidden->ev, rate, set_rate); } -static UMSAudioDevice_ReturnCode UADSetByteOrder(_THIS, string byte_order) +static UMSAudioDevice_ReturnCode +UADSetByteOrder (_THIS, string byte_order) { - return UMSAudioDevice_set_byte_order( this->hidden->umsdev, - this->hidden->ev, - byte_order ); + return UMSAudioDevice_set_byte_order (this->hidden->umsdev, + this->hidden->ev, byte_order); } -static UMSAudioDevice_ReturnCode UADSetAudioFormatType(_THIS, string fmt) +static UMSAudioDevice_ReturnCode +UADSetAudioFormatType (_THIS, string fmt) { /* possible PCM, A_LAW or MU_LAW */ - return UMSAudioDevice_set_audio_format_type( this->hidden->umsdev, - this->hidden->ev, - fmt ); + return UMSAudioDevice_set_audio_format_type (this->hidden->umsdev, + this->hidden->ev, fmt); } -static UMSAudioDevice_ReturnCode UADSetNumberFormat(_THIS, string fmt) +static UMSAudioDevice_ReturnCode +UADSetNumberFormat (_THIS, string fmt) { /* possible SIGNED, UNSIGNED, or TWOS_COMPLEMENT */ - return UMSAudioDevice_set_number_format( this->hidden->umsdev, - this->hidden->ev, - fmt ); + return UMSAudioDevice_set_number_format (this->hidden->umsdev, + this->hidden->ev, fmt); } -static UMSAudioDevice_ReturnCode UADInitialize(_THIS) +static UMSAudioDevice_ReturnCode +UADInitialize (_THIS) { - return UMSAudioDevice_initialize( this->hidden->umsdev, - this->hidden->ev ); + return UMSAudioDevice_initialize (this->hidden->umsdev, this->hidden->ev); } -static UMSAudioDevice_ReturnCode UADStart(_THIS) +static UMSAudioDevice_ReturnCode +UADStart (_THIS) { - return UMSAudioDevice_start( this->hidden->umsdev, - this->hidden->ev ); + return UMSAudioDevice_start (this->hidden->umsdev, this->hidden->ev); } -static UMSAudioDevice_ReturnCode UADSetTimeFormat(_THIS, UMSAudioTypes_TimeFormat fmt ) +static UMSAudioDevice_ReturnCode +UADSetTimeFormat (_THIS, UMSAudioTypes_TimeFormat fmt) { /* * Switches the time format to the new format, immediately. * possible UMSAudioTypes_Msecs, UMSAudioTypes_Bytes or UMSAudioTypes_Samples */ - return UMSAudioDevice_set_time_format( this->hidden->umsdev, - this->hidden->ev, - fmt ); + return UMSAudioDevice_set_time_format (this->hidden->umsdev, + this->hidden->ev, fmt); } -static UMSAudioDevice_ReturnCode UADWriteBuffSize(_THIS, long* buff_size ) +static UMSAudioDevice_ReturnCode +UADWriteBuffSize (_THIS, long *buff_size) { /* * returns write buffer size in the current time format */ - return UMSAudioDevice_write_buff_size( this->hidden->umsdev, - this->hidden->ev, - buff_size ); + return UMSAudioDevice_write_buff_size (this->hidden->umsdev, + this->hidden->ev, buff_size); } -static UMSAudioDevice_ReturnCode UADWriteBuffRemain(_THIS, long* buff_size ) +static UMSAudioDevice_ReturnCode +UADWriteBuffRemain (_THIS, long *buff_size) { /* * returns amount of available space in the write buffer * in the current time format */ - return UMSAudioDevice_write_buff_remain( this->hidden->umsdev, - this->hidden->ev, - buff_size ); + return UMSAudioDevice_write_buff_remain (this->hidden->umsdev, + this->hidden->ev, buff_size); } -static UMSAudioDevice_ReturnCode UADWriteBuffUsed(_THIS, long* buff_size ) +static UMSAudioDevice_ReturnCode +UADWriteBuffUsed (_THIS, long *buff_size) { /* * returns amount of filled space in the write buffer * in the current time format */ - return UMSAudioDevice_write_buff_used( this->hidden->umsdev, - this->hidden->ev, - buff_size ); + return UMSAudioDevice_write_buff_used (this->hidden->umsdev, + this->hidden->ev, buff_size); } -static UMSAudioDevice_ReturnCode UADSetDMABufferSize(_THIS, long bytes, long* bytes_ret ) +static UMSAudioDevice_ReturnCode +UADSetDMABufferSize (_THIS, long bytes, long *bytes_ret) { /* * Request a new DMA buffer size, maximum requested size 2048. * Takes effect with next initialize() call. * Devices may or may not support DMA. */ - return UMSAudioDevice_set_DMA_buffer_size( this->hidden->umsdev, - this->hidden->ev, - bytes, - bytes_ret ); + return UMSAudioDevice_set_DMA_buffer_size (this->hidden->umsdev, + this->hidden->ev, + bytes, bytes_ret); } -static UMSAudioDevice_ReturnCode UADSetVolume(_THIS, long volume ) +static UMSAudioDevice_ReturnCode +UADSetVolume (_THIS, long volume) { /* * Set the volume. * Takes effect immediately. */ - return UMSAudioDevice_set_volume( this->hidden->umsdev, - this->hidden->ev, - volume ); + return UMSAudioDevice_set_volume (this->hidden->umsdev, + this->hidden->ev, volume); } -static UMSAudioDevice_ReturnCode UADSetBalance(_THIS, long balance ) +static UMSAudioDevice_ReturnCode +UADSetBalance (_THIS, long balance) { /* * Set the balance. * Takes effect immediately. */ - return UMSAudioDevice_set_balance( this->hidden->umsdev, - this->hidden->ev, - balance ); + return UMSAudioDevice_set_balance (this->hidden->umsdev, + this->hidden->ev, balance); } -static UMSAudioDevice_ReturnCode UADSetChannels(_THIS, long channels ) +static UMSAudioDevice_ReturnCode +UADSetChannels (_THIS, long channels) { /* * Set mono or stereo. * Takes effect with next initialize() call. */ - if ( channels != 1 ) channels = 2; - return UMSAudioDevice_set_number_of_channels( this->hidden->umsdev, - this->hidden->ev, - channels ); + if (channels != 1) + channels = 2; + return UMSAudioDevice_set_number_of_channels (this->hidden->umsdev, + this->hidden->ev, channels); } -static UMSAudioDevice_ReturnCode UADOpen(_THIS, string device, string mode, long flags) +static UMSAudioDevice_ReturnCode +UADOpen (_THIS, string device, string mode, long flags) { - return UMSAudioDevice_open( this->hidden->umsdev, - this->hidden->ev, - device, - mode, - flags ); + return UMSAudioDevice_open (this->hidden->umsdev, + this->hidden->ev, device, mode, flags); } -static UMSAudioDevice_ReturnCode UADWrite(_THIS, UMSAudioTypes_Buffer* buff, - long samples, - long* samples_written) +static UMSAudioDevice_ReturnCode +UADWrite (_THIS, UMSAudioTypes_Buffer * buff, + long samples, long *samples_written) { - return UMSAudioDevice_write( this->hidden->umsdev, - this->hidden->ev, - buff, - samples, - samples_written ); + return UMSAudioDevice_write (this->hidden->umsdev, + this->hidden->ev, + buff, samples, samples_written); } -static UMSAudioDevice_ReturnCode UADPlayRemainingData(_THIS, boolean block ) +static UMSAudioDevice_ReturnCode +UADPlayRemainingData (_THIS, boolean block) { - return UMSAudioDevice_play_remaining_data( this->hidden->umsdev, - this->hidden->ev, - block); + return UMSAudioDevice_play_remaining_data (this->hidden->umsdev, + this->hidden->ev, block); } -static UMSAudioDevice_ReturnCode UADStop(_THIS) +static UMSAudioDevice_ReturnCode +UADStop (_THIS) { - return UMSAudioDevice_stop( this->hidden->umsdev, - this->hidden->ev ); + return UMSAudioDevice_stop (this->hidden->umsdev, this->hidden->ev); } -static UMSAudioDevice_ReturnCode UADClose(_THIS) +static UMSAudioDevice_ReturnCode +UADClose (_THIS) { - return UMSAudioDevice_close( this->hidden->umsdev, - this->hidden->ev ); + return UMSAudioDevice_close (this->hidden->umsdev, this->hidden->ev); } -static UMSAudioDevice_ReturnCode UADEnableOutput(_THIS, string output, long* left_gain, long* right_gain) +static UMSAudioDevice_ReturnCode +UADEnableOutput (_THIS, string output, long *left_gain, long *right_gain) { - return UMSAudioDevice_enable_output( this->hidden->umsdev, - this->hidden->ev, - output, - left_gain, - right_gain ); + return UMSAudioDevice_enable_output (this->hidden->umsdev, + this->hidden->ev, + output, left_gain, right_gain); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/ums/SDL_umsaudio.h b/src/audio/ums/SDL_umsaudio.h index 97410cc2f..e7c95d444 100644 --- a/src/audio/ums/SDL_umsaudio.h +++ b/src/audio/ums/SDL_umsaudio.h @@ -36,7 +36,7 @@ struct SDL_PrivateAudioData { /* Pointer to the (open) UMS audio device */ - Environment* ev; + Environment *ev; UMSAudioDevice umsdev; /* Raw mixing buffer */ @@ -47,4 +47,4 @@ struct SDL_PrivateAudioData }; #endif /* _SDL_UMSaudio_h */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/windib/SDL_dibaudio.c b/src/audio/windib/SDL_dibaudio.c index 9c10db52d..2a8a346a8 100644 --- a/src/audio/windib/SDL_dibaudio.c +++ b/src/audio/windib/SDL_dibaudio.c @@ -37,286 +37,301 @@ /* Audio driver functions */ -static int DIB_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DIB_ThreadInit(_THIS); -static void DIB_WaitAudio(_THIS); -static Uint8 *DIB_GetAudioBuf(_THIS); -static void DIB_PlayAudio(_THIS); -static void DIB_WaitDone(_THIS); -static void DIB_CloseAudio(_THIS); +static int DIB_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DIB_ThreadInit (_THIS); +static void DIB_WaitAudio (_THIS); +static Uint8 *DIB_GetAudioBuf (_THIS); +static void DIB_PlayAudio (_THIS); +static void DIB_WaitDone (_THIS); +static void DIB_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - return(1); + return (1); } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = DIB_OpenAudio; - this->ThreadInit = DIB_ThreadInit; - this->WaitAudio = DIB_WaitAudio; - this->PlayAudio = DIB_PlayAudio; - this->GetAudioBuf = DIB_GetAudioBuf; - this->WaitDone = DIB_WaitDone; - this->CloseAudio = DIB_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = DIB_OpenAudio; + this->ThreadInit = DIB_ThreadInit; + this->WaitAudio = DIB_WaitAudio; + this->PlayAudio = DIB_PlayAudio; + this->GetAudioBuf = DIB_GetAudioBuf; + this->WaitDone = DIB_WaitDone; + this->CloseAudio = DIB_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap WAVEOUT_bootstrap = { - "waveout", "Win95/98/NT/2000 WaveOut", - Audio_Available, Audio_CreateDevice + "waveout", "Win95/98/NT/2000 WaveOut", + Audio_Available, Audio_CreateDevice }; /* The Win32 callback for filling the WAVE device */ -static void CALLBACK FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, - DWORD dwParam1, DWORD dwParam2) +static void CALLBACK +FillSound (HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, + DWORD dwParam1, DWORD dwParam2) { - SDL_AudioDevice *this = (SDL_AudioDevice *)dwInstance; + SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance; - /* Only service "buffer done playing" messages */ - if ( uMsg != WOM_DONE ) - return; + /* Only service "buffer done playing" messages */ + if (uMsg != WOM_DONE) + return; - /* Signal that we are done playing a buffer */ + /* Signal that we are done playing a buffer */ #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - ReleaseSemaphoreCE(audio_sem, 1, NULL); + ReleaseSemaphoreCE (audio_sem, 1, NULL); #else - ReleaseSemaphore(audio_sem, 1, NULL); + ReleaseSemaphore (audio_sem, 1, NULL); #endif } -static void SetMMerror(char *function, MMRESULT code) +static void +SetMMerror (char *function, MMRESULT code) { - size_t len; - char errbuf[MAXERRORLENGTH]; + size_t len; + char errbuf[MAXERRORLENGTH]; #ifdef _WIN32_WCE - wchar_t werrbuf[MAXERRORLENGTH]; + wchar_t werrbuf[MAXERRORLENGTH]; #endif - SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function); - len = SDL_strlen(errbuf); + SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: ", function); + len = SDL_strlen (errbuf); #ifdef _WIN32_WCE - /* UNICODE version */ - waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH-len); - WideCharToMultiByte(CP_ACP,0,werrbuf,-1,errbuf+len,MAXERRORLENGTH-len,NULL,NULL); + /* UNICODE version */ + waveOutGetErrorText (code, werrbuf, MAXERRORLENGTH - len); + WideCharToMultiByte (CP_ACP, 0, werrbuf, -1, errbuf + len, + MAXERRORLENGTH - len, NULL, NULL); #else - waveOutGetErrorText(code, errbuf+len, (UINT)(MAXERRORLENGTH-len)); + waveOutGetErrorText (code, errbuf + len, (UINT) (MAXERRORLENGTH - len)); #endif - SDL_SetError("%s",errbuf); + SDL_SetError ("%s", errbuf); } /* Set high priority for the audio thread */ -static void DIB_ThreadInit(_THIS) +static void +DIB_ThreadInit (_THIS) { - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST); } -void DIB_WaitAudio(_THIS) +void +DIB_WaitAudio (_THIS) { - /* Wait for an audio chunk to finish */ + /* Wait for an audio chunk to finish */ #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - WaitForSemaphoreCE(audio_sem, INFINITE); + WaitForSemaphoreCE (audio_sem, INFINITE); #else - WaitForSingleObject(audio_sem, INFINITE); + WaitForSingleObject (audio_sem, INFINITE); #endif } -Uint8 *DIB_GetAudioBuf(_THIS) +Uint8 * +DIB_GetAudioBuf (_THIS) { - Uint8 *retval; + Uint8 *retval; - retval = (Uint8 *)(wavebuf[next_buffer].lpData); - return retval; + retval = (Uint8 *) (wavebuf[next_buffer].lpData); + return retval; } -void DIB_PlayAudio(_THIS) +void +DIB_PlayAudio (_THIS) { - /* Queue it up */ - waveOutWrite(sound, &wavebuf[next_buffer], sizeof(wavebuf[0])); - next_buffer = (next_buffer+1)%NUM_BUFFERS; + /* Queue it up */ + waveOutWrite (sound, &wavebuf[next_buffer], sizeof (wavebuf[0])); + next_buffer = (next_buffer + 1) % NUM_BUFFERS; } -void DIB_WaitDone(_THIS) +void +DIB_WaitDone (_THIS) { - int i, left; - - do { - left = NUM_BUFFERS; - for ( i=0; i 0 ) { - SDL_Delay(100); - } - } while ( left > 0 ); + int i, left; + + do { + left = NUM_BUFFERS; + for (i = 0; i < NUM_BUFFERS; ++i) { + if (wavebuf[i].dwFlags & WHDR_DONE) { + --left; + } + } + if (left > 0) { + SDL_Delay (100); + } + } + while (left > 0); } -void DIB_CloseAudio(_THIS) +void +DIB_CloseAudio (_THIS) { - int i; + int i; - /* Close up audio */ - if ( audio_sem ) { + /* Close up audio */ + if (audio_sem) { #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - CloseSynchHandle(audio_sem); + CloseSynchHandle (audio_sem); #else - CloseHandle(audio_sem); + CloseHandle (audio_sem); #endif - } - if ( sound ) { - waveOutClose(sound); - } - - /* Clean up mixing buffers */ - for ( i=0; iformat & 0xFF ) { - case 8: - /* Unsigned 8 bit audio data */ - spec->format = AUDIO_U8; - waveformat.wBitsPerSample = 8; - break; - case 16: - /* Signed 16 bit audio data */ - spec->format = AUDIO_S16; - waveformat.wBitsPerSample = 16; - break; - default: - SDL_SetError("Unsupported audio format"); - return(-1); - } - waveformat.nChannels = spec->channels; - waveformat.nSamplesPerSec = spec->freq; - waveformat.nBlockAlign = - waveformat.nChannels * (waveformat.wBitsPerSample/8); - waveformat.nAvgBytesPerSec = - waveformat.nSamplesPerSec * waveformat.nBlockAlign; - - /* Check the buffer size -- minimum of 1/4 second (word aligned) */ - if ( spec->samples < (spec->freq/4) ) - spec->samples = ((spec->freq/4)+3)&~3; - - /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); - - /* Open the audio device */ - result = waveOutOpen(&sound, WAVE_MAPPER, &waveformat, - (DWORD_PTR)FillSound, (DWORD_PTR)this, CALLBACK_FUNCTION); - if ( result != MMSYSERR_NOERROR ) { - SetMMerror("waveOutOpen()", result); - return(-1); - } - + MMRESULT result; + int i; + WAVEFORMATEX waveformat; + + /* Initialize the wavebuf structures for closing */ + sound = NULL; + audio_sem = NULL; + for (i = 0; i < NUM_BUFFERS; ++i) + wavebuf[i].dwUser = 0xFFFF; + mixbuf = NULL; + + /* Set basic WAVE format parameters */ + SDL_memset (&waveformat, 0, sizeof (waveformat)); + waveformat.wFormatTag = WAVE_FORMAT_PCM; + + /* Determine the audio parameters from the AudioSpec */ + switch (spec->format & 0xFF) { + case 8: + /* Unsigned 8 bit audio data */ + spec->format = AUDIO_U8; + waveformat.wBitsPerSample = 8; + break; + case 16: + /* Signed 16 bit audio data */ + spec->format = AUDIO_S16; + waveformat.wBitsPerSample = 16; + break; + default: + SDL_SetError ("Unsupported audio format"); + return (-1); + } + waveformat.nChannels = spec->channels; + waveformat.nSamplesPerSec = spec->freq; + waveformat.nBlockAlign = + waveformat.nChannels * (waveformat.wBitsPerSample / 8); + waveformat.nAvgBytesPerSec = + waveformat.nSamplesPerSec * waveformat.nBlockAlign; + + /* Check the buffer size -- minimum of 1/4 second (word aligned) */ + if (spec->samples < (spec->freq / 4)) + spec->samples = ((spec->freq / 4) + 3) & ~3; + + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec (spec); + + /* Open the audio device */ + result = waveOutOpen (&sound, WAVE_MAPPER, &waveformat, + (DWORD_PTR) FillSound, (DWORD_PTR) this, + CALLBACK_FUNCTION); + if (result != MMSYSERR_NOERROR) { + SetMMerror ("waveOutOpen()", result); + return (-1); + } #ifdef SOUND_DEBUG - /* Check the sound device we retrieved */ - { - WAVEOUTCAPS caps; - - result = waveOutGetDevCaps((UINT)sound, &caps, sizeof(caps)); - if ( result != MMSYSERR_NOERROR ) { - SetMMerror("waveOutGetDevCaps()", result); - return(-1); - } - printf("Audio device: %s\n", caps.szPname); - } + /* Check the sound device we retrieved */ + { + WAVEOUTCAPS caps; + + result = waveOutGetDevCaps ((UINT) sound, &caps, sizeof (caps)); + if (result != MMSYSERR_NOERROR) { + SetMMerror ("waveOutGetDevCaps()", result); + return (-1); + } + printf ("Audio device: %s\n", caps.szPname); + } #endif - /* Create the audio buffer semaphore */ + /* Create the audio buffer semaphore */ #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - audio_sem = CreateSemaphoreCE(NULL, NUM_BUFFERS-1, NUM_BUFFERS, NULL); + audio_sem = CreateSemaphoreCE (NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); #else - audio_sem = CreateSemaphore(NULL, NUM_BUFFERS-1, NUM_BUFFERS, NULL); + audio_sem = CreateSemaphore (NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); #endif - if ( audio_sem == NULL ) { - SDL_SetError("Couldn't create semaphore"); - return(-1); - } - - /* Create the sound buffers */ - mixbuf = (Uint8 *)SDL_malloc(NUM_BUFFERS*spec->size); - if ( mixbuf == NULL ) { - SDL_SetError("Out of memory"); - return(-1); - } - for ( i = 0; i < NUM_BUFFERS; ++i ) { - SDL_memset(&wavebuf[i], 0, sizeof(wavebuf[i])); - wavebuf[i].lpData = (LPSTR) &mixbuf[i*spec->size]; - wavebuf[i].dwBufferLength = spec->size; - wavebuf[i].dwFlags = WHDR_DONE; - result = waveOutPrepareHeader(sound, &wavebuf[i], - sizeof(wavebuf[i])); - if ( result != MMSYSERR_NOERROR ) { - SetMMerror("waveOutPrepareHeader()", result); - return(-1); - } - } - - /* Ready to go! */ - next_buffer = 0; - return(0); + if (audio_sem == NULL) { + SDL_SetError ("Couldn't create semaphore"); + return (-1); + } + + /* Create the sound buffers */ + mixbuf = (Uint8 *) SDL_malloc (NUM_BUFFERS * spec->size); + if (mixbuf == NULL) { + SDL_SetError ("Out of memory"); + return (-1); + } + for (i = 0; i < NUM_BUFFERS; ++i) { + SDL_memset (&wavebuf[i], 0, sizeof (wavebuf[i])); + wavebuf[i].lpData = (LPSTR) & mixbuf[i * spec->size]; + wavebuf[i].dwBufferLength = spec->size; + wavebuf[i].dwFlags = WHDR_DONE; + result = waveOutPrepareHeader (sound, &wavebuf[i], + sizeof (wavebuf[i])); + if (result != MMSYSERR_NOERROR) { + SetMMerror ("waveOutPrepareHeader()", result); + return (-1); + } + } + + /* Ready to go! */ + next_buffer = 0; + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/windib/SDL_dibaudio.h b/src/audio/windib/SDL_dibaudio.h index f6a6e0857..c5e7d1468 100644 --- a/src/audio/windib/SDL_dibaudio.h +++ b/src/audio/windib/SDL_dibaudio.h @@ -29,14 +29,15 @@ /* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -#define NUM_BUFFERS 2 /* -- Don't lower this! */ - -struct SDL_PrivateAudioData { - HWAVEOUT sound; - HANDLE audio_sem; - Uint8 *mixbuf; /* The raw allocated mixing buffer */ - WAVEHDR wavebuf[NUM_BUFFERS]; /* Wave audio fragments */ - int next_buffer; +#define NUM_BUFFERS 2 /* -- Don't lower this! */ + +struct SDL_PrivateAudioData +{ + HWAVEOUT sound; + HANDLE audio_sem; + Uint8 *mixbuf; /* The raw allocated mixing buffer */ + WAVEHDR wavebuf[NUM_BUFFERS]; /* Wave audio fragments */ + int next_buffer; }; /* Old variable names */ @@ -47,3 +48,4 @@ struct SDL_PrivateAudioData { #define next_buffer (this->hidden->next_buffer) #endif /* _SDL_lowaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/windx5/SDL_dx5audio.c b/src/audio/windx5/SDL_dx5audio.c index 48714dd11..ee65e9c43 100644 --- a/src/audio/windx5/SDL_dx5audio.c +++ b/src/audio/windx5/SDL_dx5audio.c @@ -32,664 +32,693 @@ //#define USE_POSITION_NOTIFY /* DirectX function pointers for audio */ -HRESULT (WINAPI *DSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN); +HRESULT (WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN); /* Audio driver functions */ -static int DX5_OpenAudio(_THIS, SDL_AudioSpec *spec); -static void DX5_ThreadInit(_THIS); -static void DX5_WaitAudio_BusyWait(_THIS); +static int DX5_OpenAudio (_THIS, SDL_AudioSpec * spec); +static void DX5_ThreadInit (_THIS); +static void DX5_WaitAudio_BusyWait (_THIS); #ifdef USE_POSITION_NOTIFY -static void DX6_WaitAudio_EventWait(_THIS); +static void DX6_WaitAudio_EventWait (_THIS); #endif -static void DX5_PlayAudio(_THIS); -static Uint8 *DX5_GetAudioBuf(_THIS); -static void DX5_WaitDone(_THIS); -static void DX5_CloseAudio(_THIS); +static void DX5_PlayAudio (_THIS); +static Uint8 *DX5_GetAudioBuf (_THIS); +static void DX5_WaitDone (_THIS); +static void DX5_CloseAudio (_THIS); /* Audio driver bootstrap functions */ -static int Audio_Available(void) +static int +Audio_Available (void) { - HINSTANCE DSoundDLL; - int dsound_ok; - - /* Version check DSOUND.DLL (Is DirectX okay?) */ - dsound_ok = 0; - DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL")); - if ( DSoundDLL != NULL ) { - /* We just use basic DirectSound, we're okay */ - /* Yay! */ - /* Unfortunately, the sound drivers on NT have - higher latencies than the audio buffers used - by many SDL applications, so there are gaps - in the audio - it sounds terrible. Punt for now. - */ - OSVERSIONINFO ver; - ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - GetVersionEx(&ver); - switch (ver.dwPlatformId) { - case VER_PLATFORM_WIN32_NT: - if ( ver.dwMajorVersion > 4 ) { - /* Win2K */ - dsound_ok = 1; - } else { - /* WinNT */ - dsound_ok = 0; - } - break; - default: - /* Win95 or Win98 */ - dsound_ok = 1; - break; - } - /* Now check for DirectX 5 or better - otherwise - * we will fail later in DX5_OpenAudio without a chance - * to fall back to the DIB driver. */ - if (dsound_ok) { - /* DirectSoundCaptureCreate was added in DX5 */ - if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) - dsound_ok = 0; - - } - /* Clean up.. */ - FreeLibrary(DSoundDLL); - } - return(dsound_ok); + HINSTANCE DSoundDLL; + int dsound_ok; + + /* Version check DSOUND.DLL (Is DirectX okay?) */ + dsound_ok = 0; + DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL")); + if (DSoundDLL != NULL) { + /* We just use basic DirectSound, we're okay */ + /* Yay! */ + /* Unfortunately, the sound drivers on NT have + higher latencies than the audio buffers used + by many SDL applications, so there are gaps + in the audio - it sounds terrible. Punt for now. + */ + OSVERSIONINFO ver; + ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + GetVersionEx (&ver); + switch (ver.dwPlatformId) { + case VER_PLATFORM_WIN32_NT: + if (ver.dwMajorVersion > 4) { + /* Win2K */ + dsound_ok = 1; + } else { + /* WinNT */ + dsound_ok = 0; + } + break; + default: + /* Win95 or Win98 */ + dsound_ok = 1; + break; + } + /* Now check for DirectX 5 or better - otherwise + * we will fail later in DX5_OpenAudio without a chance + * to fall back to the DIB driver. */ + if (dsound_ok) { + /* DirectSoundCaptureCreate was added in DX5 */ + if (!GetProcAddress + (DSoundDLL, TEXT ("DirectSoundCaptureCreate"))) + dsound_ok = 0; + + } + /* Clean up.. */ + FreeLibrary (DSoundDLL); + } + return (dsound_ok); } /* Functions for loading the DirectX functions dynamically */ static HINSTANCE DSoundDLL = NULL; -static void DX5_Unload(void) +static void +DX5_Unload (void) { - if ( DSoundDLL != NULL ) { - FreeLibrary(DSoundDLL); - DSoundCreate = NULL; - DSoundDLL = NULL; - } + if (DSoundDLL != NULL) { + FreeLibrary (DSoundDLL); + DSoundCreate = NULL; + DSoundDLL = NULL; + } } -static int DX5_Load(void) +static int +DX5_Load (void) { - int status; - - DX5_Unload(); - DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL")); - if ( DSoundDLL != NULL ) { - DSoundCreate = (void *)GetProcAddress(DSoundDLL, - TEXT("DirectSoundCreate")); - } - if ( DSoundDLL && DSoundCreate ) { - status = 0; - } else { - DX5_Unload(); - status = -1; - } - return status; + int status; + + DX5_Unload (); + DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL")); + if (DSoundDLL != NULL) { + DSoundCreate = (void *) GetProcAddress (DSoundDLL, + TEXT ("DirectSoundCreate")); + } + if (DSoundDLL && DSoundCreate) { + status = 0; + } else { + DX5_Unload (); + status = -1; + } + return status; } -static void Audio_DeleteDevice(SDL_AudioDevice *device) +static void +Audio_DeleteDevice (SDL_AudioDevice * device) { - DX5_Unload(); - SDL_free(device->hidden); - SDL_free(device); + DX5_Unload (); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_AudioDevice *Audio_CreateDevice(int devindex) +static SDL_AudioDevice * +Audio_CreateDevice (int devindex) { - SDL_AudioDevice *this; - - /* Load DirectX */ - if ( DX5_Load() < 0 ) { - return(NULL); - } - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); - if ( this ) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ( (this == NULL) || (this->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( this ) { - SDL_free(this); - } - return(0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - /* Set the function pointers */ - this->OpenAudio = DX5_OpenAudio; - this->ThreadInit = DX5_ThreadInit; - this->WaitAudio = DX5_WaitAudio_BusyWait; - this->PlayAudio = DX5_PlayAudio; - this->GetAudioBuf = DX5_GetAudioBuf; - this->WaitDone = DX5_WaitDone; - this->CloseAudio = DX5_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_AudioDevice *this; + + /* Load DirectX */ + if (DX5_Load () < 0) { + return (NULL); + } + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + if (this) { + SDL_memset (this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc ((sizeof *this->hidden)); + } + if ((this == NULL) || (this->hidden == NULL)) { + SDL_OutOfMemory (); + if (this) { + SDL_free (this); + } + return (0); + } + SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = DX5_OpenAudio; + this->ThreadInit = DX5_ThreadInit; + this->WaitAudio = DX5_WaitAudio_BusyWait; + this->PlayAudio = DX5_PlayAudio; + this->GetAudioBuf = DX5_GetAudioBuf; + this->WaitDone = DX5_WaitDone; + this->CloseAudio = DX5_CloseAudio; + + this->free = Audio_DeleteDevice; + + return this; } AudioBootStrap DSOUND_bootstrap = { - "dsound", "Win95/98/2000 DirectSound", - Audio_Available, Audio_CreateDevice + "dsound", "Win95/98/2000 DirectSound", + Audio_Available, Audio_CreateDevice }; -static void SetDSerror(const char *function, int code) +static void +SetDSerror (const char *function, int code) { - static const char *error; - static char errbuf[1024]; - - errbuf[0] = 0; - switch (code) { - case E_NOINTERFACE: - error = - "Unsupported interface\n-- Is DirectX 5.0 or later installed?"; - break; - case DSERR_ALLOCATED: - error = "Audio device in use"; - break; - case DSERR_BADFORMAT: - error = "Unsupported audio format"; - break; - case DSERR_BUFFERLOST: - error = "Mixing buffer was lost"; - break; - case DSERR_CONTROLUNAVAIL: - error = "Control requested is not available"; - break; - case DSERR_INVALIDCALL: - error = "Invalid call for the current state"; - break; - case DSERR_INVALIDPARAM: - error = "Invalid parameter"; - break; - case DSERR_NODRIVER: - error = "No audio device found"; - break; - case DSERR_OUTOFMEMORY: - error = "Out of memory"; - break; - case DSERR_PRIOLEVELNEEDED: - error = "Caller doesn't have priority"; - break; - case DSERR_UNSUPPORTED: - error = "Function not supported"; - break; - default: - SDL_snprintf(errbuf, SDL_arraysize(errbuf), - "%s: Unknown DirectSound error: 0x%x", - function, code); - break; - } - if ( ! errbuf[0] ) { - SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); - } - SDL_SetError("%s", errbuf); - return; + static const char *error; + static char errbuf[1024]; + + errbuf[0] = 0; + switch (code) { + case E_NOINTERFACE: + error = + "Unsupported interface\n-- Is DirectX 5.0 or later installed?"; + break; + case DSERR_ALLOCATED: + error = "Audio device in use"; + break; + case DSERR_BADFORMAT: + error = "Unsupported audio format"; + break; + case DSERR_BUFFERLOST: + error = "Mixing buffer was lost"; + break; + case DSERR_CONTROLUNAVAIL: + error = "Control requested is not available"; + break; + case DSERR_INVALIDCALL: + error = "Invalid call for the current state"; + break; + case DSERR_INVALIDPARAM: + error = "Invalid parameter"; + break; + case DSERR_NODRIVER: + error = "No audio device found"; + break; + case DSERR_OUTOFMEMORY: + error = "Out of memory"; + break; + case DSERR_PRIOLEVELNEEDED: + error = "Caller doesn't have priority"; + break; + case DSERR_UNSUPPORTED: + error = "Function not supported"; + break; + default: + SDL_snprintf (errbuf, SDL_arraysize (errbuf), + "%s: Unknown DirectSound error: 0x%x", function, code); + break; + } + if (!errbuf[0]) { + SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: %s", function, + error); + } + SDL_SetError ("%s", errbuf); + return; } /* DirectSound needs to be associated with a window */ static HWND mainwin = NULL; /* */ -void DX5_SoundFocus(HWND hwnd) +void +DX5_SoundFocus (HWND hwnd) { - mainwin = hwnd; + mainwin = hwnd; } -static void DX5_ThreadInit(_THIS) +static void +DX5_ThreadInit (_THIS) { - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST); } -static void DX5_WaitAudio_BusyWait(_THIS) +static void +DX5_WaitAudio_BusyWait (_THIS) { - DWORD status; - DWORD cursor, junk; - HRESULT result; - - /* Semi-busy wait, since we have no way of getting play notification - on a primary mixing buffer located in hardware (DirectX 5.0) - */ - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk); - if ( result != DS_OK ) { - if ( result == DSERR_BUFFERLOST ) { - IDirectSoundBuffer_Restore(mixbuf); - } + DWORD status; + DWORD cursor, junk; + HRESULT result; + + /* Semi-busy wait, since we have no way of getting play notification + on a primary mixing buffer located in hardware (DirectX 5.0) + */ + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk); + if (result != DS_OK) { + if (result == DSERR_BUFFERLOST) { + IDirectSoundBuffer_Restore (mixbuf); + } #ifdef DEBUG_SOUND - SetDSerror("DirectSound GetCurrentPosition", result); + SetDSerror ("DirectSound GetCurrentPosition", result); #endif - return; - } - cursor /= mixlen; - - while ( cursor == playing ) { - /* FIXME: find out how much time is left and sleep that long */ - SDL_Delay(10); - - /* Try to restore a lost sound buffer */ - IDirectSoundBuffer_GetStatus(mixbuf, &status); - if ( (status&DSBSTATUS_BUFFERLOST) ) { - IDirectSoundBuffer_Restore(mixbuf); - IDirectSoundBuffer_GetStatus(mixbuf, &status); - if ( (status&DSBSTATUS_BUFFERLOST) ) { - break; - } - } - if ( ! (status&DSBSTATUS_PLAYING) ) { - result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING); - if ( result == DS_OK ) { - continue; - } + return; + } + cursor /= mixlen; + + while (cursor == playing) { + /* FIXME: find out how much time is left and sleep that long */ + SDL_Delay (10); + + /* Try to restore a lost sound buffer */ + IDirectSoundBuffer_GetStatus (mixbuf, &status); + if ((status & DSBSTATUS_BUFFERLOST)) { + IDirectSoundBuffer_Restore (mixbuf); + IDirectSoundBuffer_GetStatus (mixbuf, &status); + if ((status & DSBSTATUS_BUFFERLOST)) { + break; + } + } + if (!(status & DSBSTATUS_PLAYING)) { + result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING); + if (result == DS_OK) { + continue; + } #ifdef DEBUG_SOUND - SetDSerror("DirectSound Play", result); + SetDSerror ("DirectSound Play", result); #endif - return; - } - - /* Find out where we are playing */ - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, - &cursor, &junk); - if ( result != DS_OK ) { - SetDSerror("DirectSound GetCurrentPosition", result); - return; - } - cursor /= mixlen; - } + return; + } + + /* Find out where we are playing */ + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, + &cursor, &junk); + if (result != DS_OK) { + SetDSerror ("DirectSound GetCurrentPosition", result); + return; + } + cursor /= mixlen; + } } #ifdef USE_POSITION_NOTIFY -static void DX6_WaitAudio_EventWait(_THIS) +static void +DX6_WaitAudio_EventWait (_THIS) { - DWORD status; - HRESULT result; - - /* Try to restore a lost sound buffer */ - IDirectSoundBuffer_GetStatus(mixbuf, &status); - if ( (status&DSBSTATUS_BUFFERLOST) ) { - IDirectSoundBuffer_Restore(mixbuf); - IDirectSoundBuffer_GetStatus(mixbuf, &status); - if ( (status&DSBSTATUS_BUFFERLOST) ) { - return; - } - } - if ( ! (status&DSBSTATUS_PLAYING) ) { - result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING); - if ( result != DS_OK ) { + DWORD status; + HRESULT result; + + /* Try to restore a lost sound buffer */ + IDirectSoundBuffer_GetStatus (mixbuf, &status); + if ((status & DSBSTATUS_BUFFERLOST)) { + IDirectSoundBuffer_Restore (mixbuf); + IDirectSoundBuffer_GetStatus (mixbuf, &status); + if ((status & DSBSTATUS_BUFFERLOST)) { + return; + } + } + if (!(status & DSBSTATUS_PLAYING)) { + result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING); + if (result != DS_OK) { #ifdef DEBUG_SOUND - SetDSerror("DirectSound Play", result); + SetDSerror ("DirectSound Play", result); #endif - return; - } - } - WaitForSingleObject(audio_event, INFINITE); + return; + } + } + WaitForSingleObject (audio_event, INFINITE); } #endif /* USE_POSITION_NOTIFY */ -static void DX5_PlayAudio(_THIS) +static void +DX5_PlayAudio (_THIS) { - /* Unlock the buffer, allowing it to play */ - if ( locked_buf ) { - IDirectSoundBuffer_Unlock(mixbuf, locked_buf, mixlen, NULL, 0); - } + /* Unlock the buffer, allowing it to play */ + if (locked_buf) { + IDirectSoundBuffer_Unlock (mixbuf, locked_buf, mixlen, NULL, 0); + } } -static Uint8 *DX5_GetAudioBuf(_THIS) +static Uint8 * +DX5_GetAudioBuf (_THIS) { - DWORD cursor, junk; - HRESULT result; - DWORD rawlen; - - /* Figure out which blocks to fill next */ - locked_buf = NULL; - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk); - if ( result == DSERR_BUFFERLOST ) { - IDirectSoundBuffer_Restore(mixbuf); - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, - &cursor, &junk); - } - if ( result != DS_OK ) { - SetDSerror("DirectSound GetCurrentPosition", result); - return(NULL); - } - cursor /= mixlen; - playing = cursor; - cursor = (cursor+1)%NUM_BUFFERS; - cursor *= mixlen; - - /* Lock the audio buffer */ - result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen, - (LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0); - if ( result == DSERR_BUFFERLOST ) { - IDirectSoundBuffer_Restore(mixbuf); - result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen, - (LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0); - } - if ( result != DS_OK ) { - SetDSerror("DirectSound Lock", result); - return(NULL); - } - return(locked_buf); + DWORD cursor, junk; + HRESULT result; + DWORD rawlen; + + /* Figure out which blocks to fill next */ + locked_buf = NULL; + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk); + if (result == DSERR_BUFFERLOST) { + IDirectSoundBuffer_Restore (mixbuf); + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, + &cursor, &junk); + } + if (result != DS_OK) { + SetDSerror ("DirectSound GetCurrentPosition", result); + return (NULL); + } + cursor /= mixlen; + playing = cursor; + cursor = (cursor + 1) % NUM_BUFFERS; + cursor *= mixlen; + + /* Lock the audio buffer */ + result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen, + (LPVOID *) & locked_buf, &rawlen, NULL, + &junk, 0); + if (result == DSERR_BUFFERLOST) { + IDirectSoundBuffer_Restore (mixbuf); + result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen, + (LPVOID *) & locked_buf, &rawlen, + NULL, &junk, 0); + } + if (result != DS_OK) { + SetDSerror ("DirectSound Lock", result); + return (NULL); + } + return (locked_buf); } -static void DX5_WaitDone(_THIS) +static void +DX5_WaitDone (_THIS) { - Uint8 *stream; - - /* Wait for the playing chunk to finish */ - stream = this->GetAudioBuf(this); - if ( stream != NULL ) { - SDL_memset(stream, silence, mixlen); - this->PlayAudio(this); - } - this->WaitAudio(this); - - /* Stop the looping sound buffer */ - IDirectSoundBuffer_Stop(mixbuf); + Uint8 *stream; + + /* Wait for the playing chunk to finish */ + stream = this->GetAudioBuf (this); + if (stream != NULL) { + SDL_memset (stream, silence, mixlen); + this->PlayAudio (this); + } + this->WaitAudio (this); + + /* Stop the looping sound buffer */ + IDirectSoundBuffer_Stop (mixbuf); } -static void DX5_CloseAudio(_THIS) +static void +DX5_CloseAudio (_THIS) { - if ( sound != NULL ) { - if ( mixbuf != NULL ) { - /* Clean up the audio buffer */ - IDirectSoundBuffer_Release(mixbuf); - mixbuf = NULL; - } - if ( audio_event != NULL ) { - CloseHandle(audio_event); - audio_event = NULL; - } - IDirectSound_Release(sound); - sound = NULL; - } + if (sound != NULL) { + if (mixbuf != NULL) { + /* Clean up the audio buffer */ + IDirectSoundBuffer_Release (mixbuf); + mixbuf = NULL; + } + if (audio_event != NULL) { + CloseHandle (audio_event); + audio_event = NULL; + } + IDirectSound_Release (sound); + sound = NULL; + } } #ifdef USE_PRIMARY_BUFFER /* This function tries to create a primary audio buffer, and returns the number of audio chunks available in the created buffer. */ -static int CreatePrimary(LPDIRECTSOUND sndObj, HWND focus, - LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize) +static int +CreatePrimary (LPDIRECTSOUND sndObj, HWND focus, + LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt, + Uint32 chunksize) { - HRESULT result; - DSBUFFERDESC format; - DSBCAPS caps; - int numchunks; - - /* Try to set primary mixing privileges */ - result = IDirectSound_SetCooperativeLevel(sndObj, focus, - DSSCL_WRITEPRIMARY); - if ( result != DS_OK ) { + HRESULT result; + DSBUFFERDESC format; + DSBCAPS caps; + int numchunks; + + /* Try to set primary mixing privileges */ + result = IDirectSound_SetCooperativeLevel (sndObj, focus, + DSSCL_WRITEPRIMARY); + if (result != DS_OK) { #ifdef DEBUG_SOUND - SetDSerror("DirectSound SetCooperativeLevel", result); + SetDSerror ("DirectSound SetCooperativeLevel", result); #endif - return(-1); - } - - /* Try to create the primary buffer */ - SDL_memset(&format, 0, sizeof(format)); - format.dwSize = sizeof(format); - format.dwFlags=(DSBCAPS_PRIMARYBUFFER|DSBCAPS_GETCURRENTPOSITION2); - format.dwFlags |= DSBCAPS_STICKYFOCUS; + return (-1); + } + + /* Try to create the primary buffer */ + SDL_memset (&format, 0, sizeof (format)); + format.dwSize = sizeof (format); + format.dwFlags = (DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2); + format.dwFlags |= DSBCAPS_STICKYFOCUS; #ifdef USE_POSITION_NOTIFY - format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; + format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; #endif - result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL); - if ( result != DS_OK ) { + result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL); + if (result != DS_OK) { #ifdef DEBUG_SOUND - SetDSerror("DirectSound CreateSoundBuffer", result); + SetDSerror ("DirectSound CreateSoundBuffer", result); #endif - return(-1); - } - - /* Check the size of the fragment buffer */ - SDL_memset(&caps, 0, sizeof(caps)); - caps.dwSize = sizeof(caps); - result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps); - if ( result != DS_OK ) { + return (-1); + } + + /* Check the size of the fragment buffer */ + SDL_memset (&caps, 0, sizeof (caps)); + caps.dwSize = sizeof (caps); + result = IDirectSoundBuffer_GetCaps (*sndbuf, &caps); + if (result != DS_OK) { #ifdef DEBUG_SOUND - SetDSerror("DirectSound GetCaps", result); + SetDSerror ("DirectSound GetCaps", result); #endif - IDirectSoundBuffer_Release(*sndbuf); - return(-1); - } - if ( (chunksize > caps.dwBufferBytes) || - ((caps.dwBufferBytes%chunksize) != 0) ) { - /* The primary buffer size is not a multiple of 'chunksize' - -- this hopefully doesn't happen when 'chunksize' is a - power of 2. - */ - IDirectSoundBuffer_Release(*sndbuf); - SDL_SetError( -"Primary buffer size is: %d, cannot break it into chunks of %d bytes\n", - caps.dwBufferBytes, chunksize); - return(-1); - } - numchunks = (caps.dwBufferBytes/chunksize); - - /* Set the primary audio format */ - result = IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); - if ( result != DS_OK ) { + IDirectSoundBuffer_Release (*sndbuf); + return (-1); + } + if ((chunksize > caps.dwBufferBytes) || + ((caps.dwBufferBytes % chunksize) != 0)) { + /* The primary buffer size is not a multiple of 'chunksize' + -- this hopefully doesn't happen when 'chunksize' is a + power of 2. + */ + IDirectSoundBuffer_Release (*sndbuf); + SDL_SetError + ("Primary buffer size is: %d, cannot break it into chunks of %d bytes\n", + caps.dwBufferBytes, chunksize); + return (-1); + } + numchunks = (caps.dwBufferBytes / chunksize); + + /* Set the primary audio format */ + result = IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt); + if (result != DS_OK) { #ifdef DEBUG_SOUND - SetDSerror("DirectSound SetFormat", result); + SetDSerror ("DirectSound SetFormat", result); #endif - IDirectSoundBuffer_Release(*sndbuf); - return(-1); - } - return(numchunks); + IDirectSoundBuffer_Release (*sndbuf); + return (-1); + } + return (numchunks); } #endif /* USE_PRIMARY_BUFFER */ /* This function tries to create a secondary audio buffer, and returns the number of audio chunks available in the created buffer. */ -static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus, - LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize) +static int +CreateSecondary (LPDIRECTSOUND sndObj, HWND focus, + LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt, + Uint32 chunksize) { - const int numchunks = 2; - HRESULT result; - DSBUFFERDESC format; - LPVOID pvAudioPtr1, pvAudioPtr2; - DWORD dwAudioBytes1, dwAudioBytes2; - - /* Try to set primary mixing privileges */ - if ( focus ) { - result = IDirectSound_SetCooperativeLevel(sndObj, - focus, DSSCL_PRIORITY); - } else { - result = IDirectSound_SetCooperativeLevel(sndObj, - GetDesktopWindow(), DSSCL_NORMAL); - } - if ( result != DS_OK ) { + const int numchunks = 2; + HRESULT result; + DSBUFFERDESC format; + LPVOID pvAudioPtr1, pvAudioPtr2; + DWORD dwAudioBytes1, dwAudioBytes2; + + /* Try to set primary mixing privileges */ + if (focus) { + result = IDirectSound_SetCooperativeLevel (sndObj, + focus, DSSCL_PRIORITY); + } else { + result = IDirectSound_SetCooperativeLevel (sndObj, + GetDesktopWindow (), + DSSCL_NORMAL); + } + if (result != DS_OK) { #ifdef DEBUG_SOUND - SetDSerror("DirectSound SetCooperativeLevel", result); + SetDSerror ("DirectSound SetCooperativeLevel", result); #endif - return(-1); - } + return (-1); + } - /* Try to create the secondary buffer */ - SDL_memset(&format, 0, sizeof(format)); - format.dwSize = sizeof(format); - format.dwFlags = DSBCAPS_GETCURRENTPOSITION2; + /* Try to create the secondary buffer */ + SDL_memset (&format, 0, sizeof (format)); + format.dwSize = sizeof (format); + format.dwFlags = DSBCAPS_GETCURRENTPOSITION2; #ifdef USE_POSITION_NOTIFY - format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; + format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; #endif - if ( ! focus ) { - format.dwFlags |= DSBCAPS_GLOBALFOCUS; - } else { - format.dwFlags |= DSBCAPS_STICKYFOCUS; - } - format.dwBufferBytes = numchunks*chunksize; - if ( (format.dwBufferBytes < DSBSIZE_MIN) || - (format.dwBufferBytes > DSBSIZE_MAX) ) { - SDL_SetError("Sound buffer size must be between %d and %d", - DSBSIZE_MIN/numchunks, DSBSIZE_MAX/numchunks); - return(-1); - } - format.dwReserved = 0; - format.lpwfxFormat = wavefmt; - result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL); - if ( result != DS_OK ) { - SetDSerror("DirectSound CreateSoundBuffer", result); - return(-1); - } - IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); - - /* Silence the initial audio buffer */ - result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes, - (LPVOID *)&pvAudioPtr1, &dwAudioBytes1, - (LPVOID *)&pvAudioPtr2, &dwAudioBytes2, - DSBLOCK_ENTIREBUFFER); - if ( result == DS_OK ) { - if ( wavefmt->wBitsPerSample == 8 ) { - SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1); - } else { - SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1); - } - IDirectSoundBuffer_Unlock(*sndbuf, - (LPVOID)pvAudioPtr1, dwAudioBytes1, - (LPVOID)pvAudioPtr2, dwAudioBytes2); - } - - /* We're ready to go */ - return(numchunks); + if (!focus) { + format.dwFlags |= DSBCAPS_GLOBALFOCUS; + } else { + format.dwFlags |= DSBCAPS_STICKYFOCUS; + } + format.dwBufferBytes = numchunks * chunksize; + if ((format.dwBufferBytes < DSBSIZE_MIN) || + (format.dwBufferBytes > DSBSIZE_MAX)) { + SDL_SetError ("Sound buffer size must be between %d and %d", + DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks); + return (-1); + } + format.dwReserved = 0; + format.lpwfxFormat = wavefmt; + result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL); + if (result != DS_OK) { + SetDSerror ("DirectSound CreateSoundBuffer", result); + return (-1); + } + IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt); + + /* Silence the initial audio buffer */ + result = IDirectSoundBuffer_Lock (*sndbuf, 0, format.dwBufferBytes, + (LPVOID *) & pvAudioPtr1, + &dwAudioBytes1, + (LPVOID *) & pvAudioPtr2, + &dwAudioBytes2, DSBLOCK_ENTIREBUFFER); + if (result == DS_OK) { + if (wavefmt->wBitsPerSample == 8) { + SDL_memset (pvAudioPtr1, 0x80, dwAudioBytes1); + } else { + SDL_memset (pvAudioPtr1, 0x00, dwAudioBytes1); + } + IDirectSoundBuffer_Unlock (*sndbuf, + (LPVOID) pvAudioPtr1, dwAudioBytes1, + (LPVOID) pvAudioPtr2, dwAudioBytes2); + } + + /* We're ready to go */ + return (numchunks); } /* This function tries to set position notify events on the mixing buffer */ #ifdef USE_POSITION_NOTIFY -static int CreateAudioEvent(_THIS) +static int +CreateAudioEvent (_THIS) { - LPDIRECTSOUNDNOTIFY notify; - DSBPOSITIONNOTIFY *notify_positions; - int i, retval; - HRESULT result; - - /* Default to fail on exit */ - retval = -1; - notify = NULL; - - /* Query for the interface */ - result = IDirectSoundBuffer_QueryInterface(mixbuf, - &IID_IDirectSoundNotify, (void *)¬ify); - if ( result != DS_OK ) { - goto done; - } - - /* Allocate the notify structures */ - notify_positions = (DSBPOSITIONNOTIFY *)SDL_malloc(NUM_BUFFERS* - sizeof(*notify_positions)); - if ( notify_positions == NULL ) { - goto done; - } - - /* Create the notify event */ - audio_event = CreateEvent(NULL, FALSE, FALSE, NULL); - if ( audio_event == NULL ) { - goto done; - } - - /* Set up the notify structures */ - for ( i=0; iformat & 0xFF ) { - case 8: - /* Unsigned 8 bit audio data */ - spec->format = AUDIO_U8; - silence = 0x80; - waveformat.wBitsPerSample = 8; - break; - case 16: - /* Signed 16 bit audio data */ - spec->format = AUDIO_S16; - silence = 0x00; - waveformat.wBitsPerSample = 16; - break; - default: - SDL_SetError("Unsupported audio format"); - return(-1); - } - waveformat.nChannels = spec->channels; - waveformat.nSamplesPerSec = spec->freq; - waveformat.nBlockAlign = - waveformat.nChannels * (waveformat.wBitsPerSample/8); - waveformat.nAvgBytesPerSec = - waveformat.nSamplesPerSec * waveformat.nBlockAlign; - - /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); - - /* Open the audio device */ - result = DSoundCreate(NULL, &sound, NULL); - if ( result != DS_OK ) { - SetDSerror("DirectSoundCreate", result); - return(-1); - } - - /* Create the audio buffer to which we write */ - NUM_BUFFERS = -1; + HRESULT result; + WAVEFORMATEX waveformat; + + /* Set basic WAVE format parameters */ + SDL_memset (&waveformat, 0, sizeof (waveformat)); + waveformat.wFormatTag = WAVE_FORMAT_PCM; + + /* Determine the audio parameters from the AudioSpec */ + switch (spec->format & 0xFF) { + case 8: + /* Unsigned 8 bit audio data */ + spec->format = AUDIO_U8; + silence = 0x80; + waveformat.wBitsPerSample = 8; + break; + case 16: + /* Signed 16 bit audio data */ + spec->format = AUDIO_S16; + silence = 0x00; + waveformat.wBitsPerSample = 16; + break; + default: + SDL_SetError ("Unsupported audio format"); + return (-1); + } + waveformat.nChannels = spec->channels; + waveformat.nSamplesPerSec = spec->freq; + waveformat.nBlockAlign = + waveformat.nChannels * (waveformat.wBitsPerSample / 8); + waveformat.nAvgBytesPerSec = + waveformat.nSamplesPerSec * waveformat.nBlockAlign; + + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec (spec); + + /* Open the audio device */ + result = DSoundCreate (NULL, &sound, NULL); + if (result != DS_OK) { + SetDSerror ("DirectSoundCreate", result); + return (-1); + } + + /* Create the audio buffer to which we write */ + NUM_BUFFERS = -1; #ifdef USE_PRIMARY_BUFFER - if ( mainwin ) { - NUM_BUFFERS = CreatePrimary(sound, mainwin, &mixbuf, - &waveformat, spec->size); - } + if (mainwin) { + NUM_BUFFERS = CreatePrimary (sound, mainwin, &mixbuf, + &waveformat, spec->size); + } #endif /* USE_PRIMARY_BUFFER */ - if ( NUM_BUFFERS < 0 ) { - NUM_BUFFERS = CreateSecondary(sound, mainwin, &mixbuf, - &waveformat, spec->size); - if ( NUM_BUFFERS < 0 ) { - return(-1); - } + if (NUM_BUFFERS < 0) { + NUM_BUFFERS = CreateSecondary (sound, mainwin, &mixbuf, + &waveformat, spec->size); + if (NUM_BUFFERS < 0) { + return (-1); + } #ifdef DEBUG_SOUND - fprintf(stderr, "Using secondary audio buffer\n"); + fprintf (stderr, "Using secondary audio buffer\n"); #endif - } + } #ifdef DEBUG_SOUND - else - fprintf(stderr, "Using primary audio buffer\n"); + else + fprintf (stderr, "Using primary audio buffer\n"); #endif - /* The buffer will auto-start playing in DX5_WaitAudio() */ - playing = 0; - mixlen = spec->size; + /* The buffer will auto-start playing in DX5_WaitAudio() */ + playing = 0; + mixlen = spec->size; #ifdef USE_POSITION_NOTIFY - /* See if we can use DirectX 6 event notification */ - if ( CreateAudioEvent(this) == 0 ) { - this->WaitAudio = DX6_WaitAudio_EventWait; - } else { - this->WaitAudio = DX5_WaitAudio_BusyWait; - } + /* See if we can use DirectX 6 event notification */ + if (CreateAudioEvent (this) == 0) { + this->WaitAudio = DX6_WaitAudio_EventWait; + } else { + this->WaitAudio = DX5_WaitAudio_BusyWait; + } #endif - return(0); + return (0); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/windx5/SDL_dx5audio.h b/src/audio/windx5/SDL_dx5audio.h index 52cec130e..bf66d1f49 100644 --- a/src/audio/windx5/SDL_dx5audio.h +++ b/src/audio/windx5/SDL_dx5audio.h @@ -32,14 +32,15 @@ #define _THIS SDL_AudioDevice *this /* The DirectSound objects */ -struct SDL_PrivateAudioData { - LPDIRECTSOUND sound; - LPDIRECTSOUNDBUFFER mixbuf; - int NUM_BUFFERS; - int mixlen, silence; - DWORD playing; - Uint8 *locked_buf; - HANDLE audio_event; +struct SDL_PrivateAudioData +{ + LPDIRECTSOUND sound; + LPDIRECTSOUNDBUFFER mixbuf; + int NUM_BUFFERS; + int mixlen, silence; + DWORD playing; + Uint8 *locked_buf; + HANDLE audio_event; }; /* Old variable names */ @@ -53,3 +54,4 @@ struct SDL_PrivateAudioData { #define audio_event (this->hidden->audio_event) #endif /* _SDL_lowaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/windx5/directx.h b/src/audio/windx5/directx.h index d14d6c637..bb9f2d2e1 100644 --- a/src/audio/windx5/directx.h +++ b/src/audio/windx5/directx.h @@ -82,3 +82,4 @@ #include #endif /* _directx_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/SDL_cdrom.c b/src/cdrom/SDL_cdrom.c index e842b5a68..bfbc9475c 100644 --- a/src/cdrom/SDL_cdrom.c +++ b/src/cdrom/SDL_cdrom.c @@ -27,7 +27,7 @@ #include "SDL_syscdrom.h" #if !defined(__MACOS__) -#define CLIP_FRAMES 10 /* Some CD-ROMs won't go all the way */ +#define CLIP_FRAMES 10 /* Some CD-ROMs won't go all the way */ #endif static int SDL_cdinitted = 0; @@ -35,307 +35,324 @@ static SDL_CD *default_cdrom; /* The system level CD-ROM control functions */ struct CDcaps SDL_CDcaps = { - NULL, /* Name */ - NULL, /* Open */ - NULL, /* GetTOC */ - NULL, /* Status */ - NULL, /* Play */ - NULL, /* Pause */ - NULL, /* Resume */ - NULL, /* Stop */ - NULL, /* Eject */ - NULL, /* Close */ + NULL, /* Name */ + NULL, /* Open */ + NULL, /* GetTOC */ + NULL, /* Status */ + NULL, /* Play */ + NULL, /* Pause */ + NULL, /* Resume */ + NULL, /* Stop */ + NULL, /* Eject */ + NULL, /* Close */ }; int SDL_numcds; -int SDL_CDROMInit(void) +int +SDL_CDROMInit (void) { - int retval; - - SDL_numcds = 0; - retval = SDL_SYS_CDInit(); - if ( retval == 0 ) { - SDL_cdinitted = 1; - } - default_cdrom = NULL; - return(retval); + int retval; + + SDL_numcds = 0; + retval = SDL_SYS_CDInit (); + if (retval == 0) { + SDL_cdinitted = 1; + } + default_cdrom = NULL; + return (retval); } /* Check to see if the CD-ROM subsystem has been initialized */ -static int CheckInit(int check_cdrom, SDL_CD **cdrom) +static int +CheckInit (int check_cdrom, SDL_CD ** cdrom) { - int okay; - - okay = SDL_cdinitted; - if ( check_cdrom && (*cdrom == NULL) ) { - *cdrom = default_cdrom; - if ( *cdrom == NULL ) { - SDL_SetError("CD-ROM not opened"); - okay = 0; - } - } - if ( ! SDL_cdinitted ) { - SDL_SetError("CD-ROM subsystem not initialized"); - } - return(okay); + int okay; + + okay = SDL_cdinitted; + if (check_cdrom && (*cdrom == NULL)) { + *cdrom = default_cdrom; + if (*cdrom == NULL) { + SDL_SetError ("CD-ROM not opened"); + okay = 0; + } + } + if (!SDL_cdinitted) { + SDL_SetError ("CD-ROM subsystem not initialized"); + } + return (okay); } -int SDL_CDNumDrives(void) +int +SDL_CDNumDrives (void) { - if ( ! CheckInit(0, NULL) ) { - return(-1); - } - return(SDL_numcds); + if (!CheckInit (0, NULL)) { + return (-1); + } + return (SDL_numcds); } -const char *SDL_CDName(int drive) +const char * +SDL_CDName (int drive) { - if ( ! CheckInit(0, NULL) ) { - return(NULL); - } - if ( drive >= SDL_numcds ) { - SDL_SetError("Invalid CD-ROM drive index"); - return(NULL); - } - if ( SDL_CDcaps.Name ) { - return(SDL_CDcaps.Name(drive)); - } else { - return(""); - } + if (!CheckInit (0, NULL)) { + return (NULL); + } + if (drive >= SDL_numcds) { + SDL_SetError ("Invalid CD-ROM drive index"); + return (NULL); + } + if (SDL_CDcaps.Name) { + return (SDL_CDcaps.Name (drive)); + } else { + return (""); + } } -SDL_CD *SDL_CDOpen(int drive) +SDL_CD * +SDL_CDOpen (int drive) { - struct SDL_CD *cdrom; - - if ( ! CheckInit(0, NULL) ) { - return(NULL); - } - if ( drive >= SDL_numcds ) { - SDL_SetError("Invalid CD-ROM drive index"); - return(NULL); - } - cdrom = (SDL_CD *)SDL_malloc(sizeof(*cdrom)); - if ( cdrom == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - SDL_memset(cdrom, 0, sizeof(*cdrom)); - cdrom->id = SDL_CDcaps.Open(drive); - if ( cdrom->id < 0 ) { - SDL_free(cdrom); - return(NULL); - } - default_cdrom = cdrom; - return(cdrom); + struct SDL_CD *cdrom; + + if (!CheckInit (0, NULL)) { + return (NULL); + } + if (drive >= SDL_numcds) { + SDL_SetError ("Invalid CD-ROM drive index"); + return (NULL); + } + cdrom = (SDL_CD *) SDL_malloc (sizeof (*cdrom)); + if (cdrom == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + SDL_memset (cdrom, 0, sizeof (*cdrom)); + cdrom->id = SDL_CDcaps.Open (drive); + if (cdrom->id < 0) { + SDL_free (cdrom); + return (NULL); + } + default_cdrom = cdrom; + return (cdrom); } -CDstatus SDL_CDStatus(SDL_CD *cdrom) +CDstatus +SDL_CDStatus (SDL_CD * cdrom) { - CDstatus status; - int i; - Uint32 position; - - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return(CD_ERROR); - } - - /* Get the current status of the drive */ - cdrom->numtracks = 0; - cdrom->cur_track = 0; - cdrom->cur_frame = 0; - status = SDL_CDcaps.Status(cdrom, &i); - position = (Uint32)i; - cdrom->status = status; - - /* Get the table of contents, if there's a CD available */ - if ( CD_INDRIVE(status) ) { - if ( SDL_CDcaps.GetTOC(cdrom) < 0 ) { - status = CD_ERROR; - } - /* If the drive is playing, get current play position */ - if ( (status == CD_PLAYING) || (status == CD_PAUSED) ) { - for ( i=1; cdrom->track[i].offset <= position; ++i ) { - /* Keep looking */; - } + CDstatus status; + int i; + Uint32 position; + + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return (CD_ERROR); + } + + /* Get the current status of the drive */ + cdrom->numtracks = 0; + cdrom->cur_track = 0; + cdrom->cur_frame = 0; + status = SDL_CDcaps.Status (cdrom, &i); + position = (Uint32) i; + cdrom->status = status; + + /* Get the table of contents, if there's a CD available */ + if (CD_INDRIVE (status)) { + if (SDL_CDcaps.GetTOC (cdrom) < 0) { + status = CD_ERROR; + } + /* If the drive is playing, get current play position */ + if ((status == CD_PLAYING) || (status == CD_PAUSED)) { + for (i = 1; cdrom->track[i].offset <= position; ++i) { + /* Keep looking */ ; + } #ifdef DEBUG_CDROM - fprintf(stderr, "Current position: %d, track = %d (offset is %d)\n", - position, i-1, cdrom->track[i-1].offset); + fprintf (stderr, + "Current position: %d, track = %d (offset is %d)\n", + position, i - 1, cdrom->track[i - 1].offset); #endif - cdrom->cur_track = i-1; - position -= cdrom->track[cdrom->cur_track].offset; - cdrom->cur_frame = position; - } - } - return(status); + cdrom->cur_track = i - 1; + position -= cdrom->track[cdrom->cur_track].offset; + cdrom->cur_frame = position; + } + } + return (status); } -int SDL_CDPlayTracks(SDL_CD *cdrom, - int strack, int sframe, int ntracks, int nframes) +int +SDL_CDPlayTracks (SDL_CD * cdrom, + int strack, int sframe, int ntracks, int nframes) { - int etrack, eframe; - int start, length; - - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return(CD_ERROR); - } - - /* Determine the starting and ending tracks */ - if ( (strack < 0) || (strack >= cdrom->numtracks) ) { - SDL_SetError("Invalid starting track"); - return(CD_ERROR); - } - if ( ! ntracks && ! nframes ) { - etrack = cdrom->numtracks; - eframe = 0; - } else { - etrack = strack+ntracks; - if ( etrack == strack ) { - eframe = sframe + nframes; - } else { - eframe = nframes; - } - } - if ( etrack > cdrom->numtracks ) { - SDL_SetError("Invalid play length"); - return(CD_ERROR); - } - - /* Skip data tracks and verify frame offsets */ - while ( (strack <= etrack) && - (cdrom->track[strack].type == SDL_DATA_TRACK) ) { - ++strack; - } - if ( sframe >= (int)cdrom->track[strack].length ) { - SDL_SetError("Invalid starting frame for track %d", strack); - return(CD_ERROR); - } - while ( (etrack > strack) && - (cdrom->track[etrack-1].type == SDL_DATA_TRACK) ) { - --etrack; - } - if ( eframe > (int)cdrom->track[etrack].length ) { - SDL_SetError("Invalid ending frame for track %d", etrack); - return(CD_ERROR); - } - - /* Determine start frame and play length */ - start = (cdrom->track[strack].offset+sframe); - length = (cdrom->track[etrack].offset+eframe)-start; + int etrack, eframe; + int start, length; + + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return (CD_ERROR); + } + + /* Determine the starting and ending tracks */ + if ((strack < 0) || (strack >= cdrom->numtracks)) { + SDL_SetError ("Invalid starting track"); + return (CD_ERROR); + } + if (!ntracks && !nframes) { + etrack = cdrom->numtracks; + eframe = 0; + } else { + etrack = strack + ntracks; + if (etrack == strack) { + eframe = sframe + nframes; + } else { + eframe = nframes; + } + } + if (etrack > cdrom->numtracks) { + SDL_SetError ("Invalid play length"); + return (CD_ERROR); + } + + /* Skip data tracks and verify frame offsets */ + while ((strack <= etrack) && + (cdrom->track[strack].type == SDL_DATA_TRACK)) { + ++strack; + } + if (sframe >= (int) cdrom->track[strack].length) { + SDL_SetError ("Invalid starting frame for track %d", strack); + return (CD_ERROR); + } + while ((etrack > strack) && + (cdrom->track[etrack - 1].type == SDL_DATA_TRACK)) { + --etrack; + } + if (eframe > (int) cdrom->track[etrack].length) { + SDL_SetError ("Invalid ending frame for track %d", etrack); + return (CD_ERROR); + } + + /* Determine start frame and play length */ + start = (cdrom->track[strack].offset + sframe); + length = (cdrom->track[etrack].offset + eframe) - start; #ifdef CLIP_FRAMES - /* I've never seen this necessary, but xmcd does it.. */ - length -= CLIP_FRAMES; /* CLIP_FRAMES == 10 */ + /* I've never seen this necessary, but xmcd does it.. */ + length -= CLIP_FRAMES; /* CLIP_FRAMES == 10 */ #endif - if ( length < 0 ) { - return(0); - } + if (length < 0) { + return (0); + } - /* Play! */ + /* Play! */ #ifdef DEBUG_CDROM - fprintf(stderr, "Playing %d frames at offset %d\n", length, start); + fprintf (stderr, "Playing %d frames at offset %d\n", length, start); #endif - return(SDL_CDcaps.Play(cdrom, start, length)); + return (SDL_CDcaps.Play (cdrom, start, length)); } -int SDL_CDPlay(SDL_CD *cdrom, int sframe, int length) +int +SDL_CDPlay (SDL_CD * cdrom, int sframe, int length) { - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return(CD_ERROR); - } + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return (CD_ERROR); + } - return(SDL_CDcaps.Play(cdrom, sframe, length)); + return (SDL_CDcaps.Play (cdrom, sframe, length)); } -int SDL_CDPause(SDL_CD *cdrom) +int +SDL_CDPause (SDL_CD * cdrom) { - CDstatus status; - int retval; - - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return(CD_ERROR); - } - - status = SDL_CDcaps.Status(cdrom, NULL); - switch (status) { - case CD_PLAYING: - retval = SDL_CDcaps.Pause(cdrom); - break; - default: - retval = 0; - break; - } - return(retval); + CDstatus status; + int retval; + + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return (CD_ERROR); + } + + status = SDL_CDcaps.Status (cdrom, NULL); + switch (status) { + case CD_PLAYING: + retval = SDL_CDcaps.Pause (cdrom); + break; + default: + retval = 0; + break; + } + return (retval); } -int SDL_CDResume(SDL_CD *cdrom) +int +SDL_CDResume (SDL_CD * cdrom) { - CDstatus status; - int retval; - - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return(CD_ERROR); - } - - status = SDL_CDcaps.Status(cdrom, NULL); - switch (status) { - case CD_PAUSED: - retval = SDL_CDcaps.Resume(cdrom); - default: - retval = 0; - break; - } - return(retval); + CDstatus status; + int retval; + + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return (CD_ERROR); + } + + status = SDL_CDcaps.Status (cdrom, NULL); + switch (status) { + case CD_PAUSED: + retval = SDL_CDcaps.Resume (cdrom); + default: + retval = 0; + break; + } + return (retval); } -int SDL_CDStop(SDL_CD *cdrom) +int +SDL_CDStop (SDL_CD * cdrom) { - CDstatus status; - int retval; - - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return(CD_ERROR); - } - - status = SDL_CDcaps.Status(cdrom, NULL); - switch (status) { - case CD_PLAYING: - case CD_PAUSED: - retval = SDL_CDcaps.Stop(cdrom); - default: - retval = 0; - break; - } - return(retval); + CDstatus status; + int retval; + + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return (CD_ERROR); + } + + status = SDL_CDcaps.Status (cdrom, NULL); + switch (status) { + case CD_PLAYING: + case CD_PAUSED: + retval = SDL_CDcaps.Stop (cdrom); + default: + retval = 0; + break; + } + return (retval); } -int SDL_CDEject(SDL_CD *cdrom) +int +SDL_CDEject (SDL_CD * cdrom) { - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return(CD_ERROR); - } - return(SDL_CDcaps.Eject(cdrom)); + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return (CD_ERROR); + } + return (SDL_CDcaps.Eject (cdrom)); } -void SDL_CDClose(SDL_CD *cdrom) +void +SDL_CDClose (SDL_CD * cdrom) { - /* Check if the CD-ROM subsystem has been initialized */ - if ( ! CheckInit(1, &cdrom) ) { - return; - } - SDL_CDcaps.Close(cdrom); - SDL_free(cdrom); - default_cdrom = NULL; + /* Check if the CD-ROM subsystem has been initialized */ + if (!CheckInit (1, &cdrom)) { + return; + } + SDL_CDcaps.Close (cdrom); + SDL_free (cdrom); + default_cdrom = NULL; } -void SDL_CDROMQuit(void) +void +SDL_CDROMQuit (void) { - SDL_SYS_CDQuit(); - SDL_cdinitted = 0; + SDL_SYS_CDQuit (); + SDL_cdinitted = 0; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/SDL_syscdrom.h b/src/cdrom/SDL_syscdrom.h index b51e07b5e..28b54e70e 100644 --- a/src/cdrom/SDL_syscdrom.h +++ b/src/cdrom/SDL_syscdrom.h @@ -24,41 +24,42 @@ /* This is the system specific header for the SDL CD-ROM API */ /* Structure of CD audio control functions */ -extern struct CDcaps { - /* Get the name of the specified drive */ - const char *(*Name)(int drive); +extern struct CDcaps +{ + /* Get the name of the specified drive */ + const char *(*Name) (int drive); - /* Open the specified drive, returning a drive id, or -1 on error */ - int (*Open)(int drive); + /* Open the specified drive, returning a drive id, or -1 on error */ + int (*Open) (int drive); - /* Get table-of-contents (number of tracks + track info) for disk. - The TOC information should be stored in the cdrom structure. - This function should return 0 on success, or -1 on error. - */ - int (*GetTOC)(SDL_CD *cdrom); + /* Get table-of-contents (number of tracks + track info) for disk. + The TOC information should be stored in the cdrom structure. + This function should return 0 on success, or -1 on error. + */ + int (*GetTOC) (SDL_CD * cdrom); - /* Return the current status and play position, in frames, of the - drive. 'position' may be NULL, and if so, should be ignored. - */ - CDstatus (*Status)(SDL_CD *cdrom, int *position); + /* Return the current status and play position, in frames, of the + drive. 'position' may be NULL, and if so, should be ignored. + */ + CDstatus (*Status) (SDL_CD * cdrom, int *position); - /* Play from frame 'start' to 'start+len' */ - int (*Play)(SDL_CD *cdrom, int start, int len); + /* Play from frame 'start' to 'start+len' */ + int (*Play) (SDL_CD * cdrom, int start, int len); - /* Pause play */ - int (*Pause)(SDL_CD *cdrom); + /* Pause play */ + int (*Pause) (SDL_CD * cdrom); - /* Resume play */ - int (*Resume)(SDL_CD *cdrom); + /* Resume play */ + int (*Resume) (SDL_CD * cdrom); - /* Stop play */ - int (*Stop)(SDL_CD *cdrom); + /* Stop play */ + int (*Stop) (SDL_CD * cdrom); - /* Eject the current disk */ - int (*Eject)(SDL_CD *cdrom); + /* Eject the current disk */ + int (*Eject) (SDL_CD * cdrom); - /* Close the specified drive */ - void (*Close)(SDL_CD *cdrom); + /* Close the specified drive */ + void (*Close) (SDL_CD * cdrom); } SDL_CDcaps; /* The number of available CD-ROM drives on the system */ @@ -69,8 +70,8 @@ extern int SDL_numcds; * drives. Drive 0 should be the system default CD-ROM. * It should return 0, or -1 on an unrecoverable fatal error. */ -extern int SDL_SYS_CDInit(void); +extern int SDL_SYS_CDInit (void); /* Function to perform any system-specific CD-ROM related cleanup */ -extern void SDL_SYS_CDQuit(void); - +extern void SDL_SYS_CDQuit (void); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/aix/SDL_syscdrom.c b/src/cdrom/aix/SDL_syscdrom.c index 41f23a9c1..53bf4b373 100644 --- a/src/cdrom/aix/SDL_syscdrom.c +++ b/src/cdrom/aix/SDL_syscdrom.c @@ -47,27 +47,28 @@ #include "../SDL_syscdrom.h" /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 16 +#define MAX_DRIVES 16 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; static dev_t SDL_cdmode[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); -static int SDL_SYS_CDioctl(int id, int command, void *arg); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); +static int SDL_SYS_CDioctl (int id, int command, void *arg); /* Check a drive to see if it is a CD-ROM */ -static int CheckDrive(char *drive, struct stat *stbuf) +static int +CheckDrive (char *drive, struct stat *stbuf) { int is_cd; int cdfd; @@ -75,316 +76,320 @@ static int CheckDrive(char *drive, struct stat *stbuf) struct devinfo info; /* If it doesn't exist, return -1 */ - if ( stat(drive, stbuf) < 0 ) { + if (stat (drive, stbuf) < 0) { return -1; } /* If it does exist, verify that it's an available CD-ROM */ is_cd = 0; - if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { - cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); - if ( cdfd >= 0 ) { - ret = SDL_SYS_CDioctl( cdfd, IOCINFO, &info ); - if ( ret < 0 ) { - /* Some kind of error */ - is_cd = 0; - } else { - if ( info.devtype == DD_CDROM ) { - is_cd = 1; - } else { - is_cd = 0; - } - } - close(cdfd); - } + if (S_ISCHR (stbuf->st_mode) || S_ISBLK (stbuf->st_mode)) { + cdfd = open (drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0); + if (cdfd >= 0) { + ret = SDL_SYS_CDioctl (cdfd, IOCINFO, &info); + if (ret < 0) { + /* Some kind of error */ + is_cd = 0; + } else { + if (info.devtype == DD_CDROM) { + is_cd = 1; + } else { + is_cd = 0; + } + } + close (cdfd); + } #ifdef DEBUG_CDROM - else - { - fprintf(stderr, "Could not open drive %s (%s)\n", drive, strerror(errno)); - } + else { + fprintf (stderr, "Could not open drive %s (%s)\n", drive, + strerror (errno)); + } #endif } return is_cd; } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive, struct stat *stbuf) +static void +AddDrive (char *drive, struct stat *stbuf) { - int i; - - if ( SDL_numcds < MAX_DRIVES ) { - /* Check to make sure it's not already in our list. - This can happen when we see a drive via symbolic link. - */ - for ( i=0; ist_rdev == SDL_cdmode[i] ) { + int i; + + if (SDL_numcds < MAX_DRIVES) { + /* Check to make sure it's not already in our list. + This can happen when we see a drive via symbolic link. + */ + for (i = 0; i < SDL_numcds; ++i) { + if (stbuf->st_rdev == SDL_cdmode[i]) { #ifdef DEBUG_CDROM - fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); + fprintf (stderr, "Duplicate drive detected: %s == %s\n", + drive, SDL_cdlist[i]); #endif - return; - } - } - - /* Add this drive to our list */ - i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - SDL_cdmode[i] = stbuf->st_rdev; - ++SDL_numcds; + return; + } + } + + /* Add this drive to our list */ + i = SDL_numcds; + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + SDL_cdmode[i] = stbuf->st_rdev; + ++SDL_numcds; #ifdef DEBUG_CDROM - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif - } + } } -static void CheckMounts() +static void +CheckMounts () { - char* buffer; - int bufsz; - struct vmount* ptr; - int ret; - - buffer = (char*)SDL_malloc(10); - bufsz = 10; - if ( buffer==NULL ) - { - fprintf(stderr, "Could not allocate 10 bytes in aix/SDL_syscdrom.c:CheckMounts\n" ); - exit ( -10 ); + char *buffer; + int bufsz; + struct vmount *ptr; + int ret; + + buffer = (char *) SDL_malloc (10); + bufsz = 10; + if (buffer == NULL) { + fprintf (stderr, + "Could not allocate 10 bytes in aix/SDL_syscdrom.c:CheckMounts\n"); + exit (-10); } - do - { - /* mntctrl() returns an array of all mounted filesystems */ - ret = mntctl ( MCTL_QUERY, bufsz, buffer ); - if ( ret == 0 ) - { - /* Buffer was too small, realloc. */ - bufsz = *(int*)buffer; /* Required size is in first word. */ - /* (whatever a word is in AIX 4.3.3) */ - /* int seems to be OK in 32bit mode. */ - SDL_free(buffer); - buffer = (char*)SDL_malloc(bufsz); - if ( buffer==NULL ) - { - fprintf(stderr, - "Could not allocate %d bytes in aix/SDL_syscdrom.c:CheckMounts\n", - bufsz ); - exit ( -10 ); + do { + /* mntctrl() returns an array of all mounted filesystems */ + ret = mntctl (MCTL_QUERY, bufsz, buffer); + if (ret == 0) { + /* Buffer was too small, realloc. */ + bufsz = *(int *) buffer; /* Required size is in first word. */ + /* (whatever a word is in AIX 4.3.3) */ + /* int seems to be OK in 32bit mode. */ + SDL_free (buffer); + buffer = (char *) SDL_malloc (bufsz); + if (buffer == NULL) { + fprintf (stderr, + "Could not allocate %d bytes in aix/SDL_syscdrom.c:CheckMounts\n", + bufsz); + exit (-10); } - } - else if ( ret < 0 ) - { + } else if (ret < 0) { #ifdef DEBUG_CDROM - fprintf(stderr, "Error reading vmount structures\n"); + fprintf (stderr, "Error reading vmount structures\n"); #endif - return; - } + return; + } } - while ( ret == 0 ); + while (ret == 0); #ifdef DEBUG_CDROM - fprintf ( stderr, "Read %d vmount structures\n",ret ); + fprintf (stderr, "Read %d vmount structures\n", ret); #endif - ptr = (struct vmount*)buffer; - do - { - switch(ptr->vmt_gfstype) + ptr = (struct vmount *) buffer; + do { + switch (ptr->vmt_gfstype) { + case MNT_CDROM: { - case MNT_CDROM : - { - struct stat stbuf; - char* text; + struct stat stbuf; + char *text; - text = (char*)ptr + ptr->vmt_data[VMT_OBJECT].vmt_off; + text = (char *) ptr + ptr->vmt_data[VMT_OBJECT].vmt_off; #ifdef DEBUG_CDROM - fprintf(stderr, "Checking mount path: %s mounted on %s\n", - text, (char*)ptr + ptr->vmt_data[VMT_STUB].vmt_off ); + fprintf (stderr, + "Checking mount path: %s mounted on %s\n", text, + (char *) ptr + ptr->vmt_data[VMT_STUB].vmt_off); #endif - if ( CheckDrive( text, &stbuf) > 0) - { - AddDrive( text, &stbuf); - } + if (CheckDrive (text, &stbuf) > 0) { + AddDrive (text, &stbuf); } - break; - default : - break; } - ptr = (struct vmount*)((char*)ptr + ptr->vmt_length); - ret--; + break; + default: + break; + } + ptr = (struct vmount *) ((char *) ptr + ptr->vmt_length); + ret--; } - while ( ret > 0 ); + while (ret > 0); - free ( buffer ); + free (buffer); } -static int CheckNonmounts() +static int +CheckNonmounts () { #ifdef _THREAD_SAFE - AFILE_t fsFile = NULL; - int passNo = 0; - int ret; + AFILE_t fsFile = NULL; + int passNo = 0; + int ret; struct fstab entry; - struct stat stbuf; - - ret = setfsent_r( &fsFile, &passNo ); - if ( ret != 0 ) return -1; - do - { - ret = getfsent_r ( &entry, &fsFile, &passNo ); - if ( ret == 0 ) { - char* l = SDL_strrchr(entry.fs_spec,'/'); - if ( l != NULL ) { - if ( !SDL_strncmp("cd",++l,2) ) { + struct stat stbuf; + + ret = setfsent_r (&fsFile, &passNo); + if (ret != 0) + return -1; + do { + ret = getfsent_r (&entry, &fsFile, &passNo); + if (ret == 0) { + char *l = SDL_strrchr (entry.fs_spec, '/'); + if (l != NULL) { + if (!SDL_strncmp ("cd", ++l, 2)) { #ifdef DEBUG_CDROM - fprintf(stderr, - "Found unmounted CD ROM drive with device name %s\n", - entry.fs_spec); + fprintf (stderr, + "Found unmounted CD ROM drive with device name %s\n", + entry.fs_spec); #endif - if ( CheckDrive( entry.fs_spec, &stbuf) > 0) - { - AddDrive( entry.fs_spec, &stbuf); - } + if (CheckDrive (entry.fs_spec, &stbuf) > 0) { + AddDrive (entry.fs_spec, &stbuf); + } } } } } - while ( ret == 0 ); - ret = endfsent_r ( &fsFile ); - if ( ret != 0 ) return -1; + while (ret == 0); + ret = endfsent_r (&fsFile); + if (ret != 0) + return -1; return 0; #else - struct fstab* entry; - struct stat stbuf; - - setfsent(); - do - { - entry = getfsent(); - if ( entry != NULL ) { - char* l = SDL_strrchr(entry->fs_spec,'/'); - if ( l != NULL ) { - if ( !SDL_strncmp("cd",++l,2) ) { + struct fstab *entry; + struct stat stbuf; + + setfsent (); + do { + entry = getfsent (); + if (entry != NULL) { + char *l = SDL_strrchr (entry->fs_spec, '/'); + if (l != NULL) { + if (!SDL_strncmp ("cd", ++l, 2)) { #ifdef DEBUG_CDROM - fprintf(stderr,"Found unmounted CD ROM drive with device name %s", entry->fs_spec); + fprintf (stderr, + "Found unmounted CD ROM drive with device name %s", + entry->fs_spec); #endif - if ( CheckDrive( entry->fs_spec, &stbuf) > 0) - { - AddDrive( entry->fs_spec, &stbuf); - } + if (CheckDrive (entry->fs_spec, &stbuf) > 0) { + AddDrive (entry->fs_spec, &stbuf); + } } } } } - while ( entry != NULL ); - endfsent(); + while (entry != NULL); + endfsent (); #endif } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - char *SDLcdrom; - struct stat stbuf; - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Look in the environment for our CD-ROM drive list */ - SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ - if ( SDLcdrom != NULL ) { - char *cdpath, *delim; - size_t len = SDL_strlen(SDLcdrom)+1; - cdpath = SDL_stack_alloc(char, len); - if ( cdpath != NULL ) { - SDL_strlcpy(cdpath, SDLcdrom, len); - SDLcdrom = cdpath; - do { - delim = SDL_strchr(SDLcdrom, ':'); - if ( delim ) { - *delim++ = '\0'; - } + char *SDLcdrom; + struct stat stbuf; + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Look in the environment for our CD-ROM drive list */ + SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ + if (SDLcdrom != NULL) { + char *cdpath, *delim; + size_t len = SDL_strlen (SDLcdrom) + 1; + cdpath = SDL_stack_alloc (char, len); + if (cdpath != NULL) { + SDL_strlcpy (cdpath, SDLcdrom, len); + SDLcdrom = cdpath; + do { + delim = SDL_strchr (SDLcdrom, ':'); + if (delim) { + *delim++ = '\0'; + } #ifdef DEBUG_CDROM - fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); + fprintf (stderr, + "Checking CD-ROM drive from SDL_CDROM: %s\n", + SDLcdrom); #endif - if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { - AddDrive(SDLcdrom, &stbuf); - } - if ( delim ) { - SDLcdrom = delim; - } else { - SDLcdrom = NULL; - } - } while ( SDLcdrom ); - SDL_stack_free(cdpath); - } - - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } - } - - CheckMounts(); - CheckNonmounts(); - - return 0; + if (CheckDrive (SDLcdrom, &stbuf) > 0) { + AddDrive (SDLcdrom, &stbuf); + } + if (delim) { + SDLcdrom = delim; + } else { + SDLcdrom = NULL; + } + } + while (SDLcdrom); + SDL_stack_free (cdpath); + } + + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } + } + + CheckMounts (); + CheckNonmounts (); + + return 0; } /* General ioctl() CD-ROM command function */ -static int SDL_SYS_CDioctl(int id, int command, void *arg) +static int +SDL_SYS_CDioctl (int id, int command, void *arg) { int retval; - retval = ioctl(id, command, arg); - if ( retval < 0 ) { - SDL_SetError("ioctl() error: %s", strerror(errno)); + retval = ioctl (id, command, arg); + if (retval < 0) { + SDL_SetError ("ioctl() error: %s", strerror (errno)); } return retval; } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - int fd; - char* lastsl; - char* cdromname; + int fd; + char *lastsl; + char *cdromname; size_t len; /* * We found /dev/cd? drives and that is in our list. But we can * open only the /dev/rcd? versions of those devices for Audio CD. */ - len = SDL_strlen(SDL_cdlist[drive])+2; - cdromname = (char*)SDL_malloc(len); - SDL_strlcpy(cdromname,SDL_cdlist[drive],len); - lastsl = SDL_strrchr(cdromname,'/'); + len = SDL_strlen (SDL_cdlist[drive]) + 2; + cdromname = (char *) SDL_malloc (len); + SDL_strlcpy (cdromname, SDL_cdlist[drive], len); + lastsl = SDL_strrchr (cdromname, '/'); if (lastsl) { - *lastsl = 0; - SDL_strlcat(cdromname,"/r",len); - lastsl = SDL_strrchr(SDL_cdlist[drive],'/'); - if (lastsl) { - lastsl++; - SDL_strlcat(cdromname,lastsl,len); - } + *lastsl = 0; + SDL_strlcat (cdromname, "/r", len); + lastsl = SDL_strrchr (SDL_cdlist[drive], '/'); + if (lastsl) { + lastsl++; + SDL_strlcat (cdromname, lastsl, len); + } } - #ifdef DEBUG_CDROM - fprintf(stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive], cdromname); + fprintf (stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive], + cdromname); #endif /* @@ -392,177 +397,176 @@ static int SDL_SYS_CDOpen(int drive) * require root priviledges, and we don't want that. SC_SINGLE provides * exclusive access with less trouble. */ - fd = openx(cdromname, O_RDONLY, NULL, SC_SINGLE); - if ( fd < 0 ) - { + fd = openx (cdromname, O_RDONLY, NULL, SC_SINGLE); + if (fd < 0) { #ifdef DEBUG_CDROM - fprintf(stderr, "Could not open drive %s (%s)\n", cdromname, strerror(errno)); + fprintf (stderr, "Could not open drive %s (%s)\n", cdromname, + strerror (errno)); #endif - } - else - { - struct mode_form_op cdMode; - int ret; + } else { + struct mode_form_op cdMode; + int ret; #ifdef DEBUG_CDROM - cdMode.action = CD_GET_MODE; - ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode); - if ( ret < 0 ) { - fprintf(stderr, - "Could not get drive mode for %s (%s)\n", - cdromname, strerror(errno)); - } else { - switch(cdMode.cd_mode_form) { - case CD_MODE1 : - fprintf(stderr, - "Drive mode for %s is %s\n", - cdromname, "CD-ROM Data Mode 1"); - break; - case CD_MODE2_FORM1 : - fprintf(stderr, - "Drive mode for %s is %s\n", - cdromname, "CD-ROM XA Data Mode 2 Form 1"); - break; - case CD_MODE2_FORM2 : - fprintf(stderr, - "Drive mode for %s is %s\n", - cdromname, "CD-ROM XA Data Mode 2 Form 2"); - break; - case CD_DA : - fprintf(stderr, - "Drive mode for %s is %s\n", - cdromname, "CD-DA"); - break; - default : - fprintf(stderr, - "Drive mode for %s is %s\n", - cdromname, "unknown"); - break; - } - } + cdMode.action = CD_GET_MODE; + ret = SDL_SYS_CDioctl (fd, DK_CD_MODE, &cdMode); + if (ret < 0) { + fprintf (stderr, + "Could not get drive mode for %s (%s)\n", + cdromname, strerror (errno)); + } else { + switch (cdMode.cd_mode_form) { + case CD_MODE1: + fprintf (stderr, + "Drive mode for %s is %s\n", + cdromname, "CD-ROM Data Mode 1"); + break; + case CD_MODE2_FORM1: + fprintf (stderr, + "Drive mode for %s is %s\n", + cdromname, "CD-ROM XA Data Mode 2 Form 1"); + break; + case CD_MODE2_FORM2: + fprintf (stderr, + "Drive mode for %s is %s\n", + cdromname, "CD-ROM XA Data Mode 2 Form 2"); + break; + case CD_DA: + fprintf (stderr, + "Drive mode for %s is %s\n", cdromname, "CD-DA"); + break; + default: + fprintf (stderr, + "Drive mode for %s is %s\n", cdromname, "unknown"); + break; + } + } #endif - cdMode.action = CD_CHG_MODE; - cdMode.cd_mode_form = CD_DA; - ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode); - if ( ret < 0 ) { + cdMode.action = CD_CHG_MODE; + cdMode.cd_mode_form = CD_DA; + ret = SDL_SYS_CDioctl (fd, DK_CD_MODE, &cdMode); + if (ret < 0) { #ifdef DEBUG_CDROM - fprintf(stderr, - "Could not set drive mode for %s (%s)\n", - cdromname, strerror(errno)); + fprintf (stderr, + "Could not set drive mode for %s (%s)\n", + cdromname, strerror (errno)); #endif - SDL_SetError("ioctl() error: Could not set CD drive mode, %s", - strerror(errno)); - } else { + SDL_SetError + ("ioctl() error: Could not set CD drive mode, %s", + strerror (errno)); + } else { #ifdef DEBUG_CDROM - fprintf(stderr, - "Drive mode for %s set to CD_DA\n", - cdromname); + fprintf (stderr, "Drive mode for %s set to CD_DA\n", cdromname); #endif - } + } } - SDL_free(cdromname); + SDL_free (cdromname); return fd; } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { struct cd_audio_cmd cmd; struct cd_audio_cmd entry; - int i; - int okay; + int i; + int okay; cmd.audio_cmds = CD_TRK_INFO_AUDIO; - cmd.msf_flag = FALSE; - if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0 ) { - return -1; + cmd.msf_flag = FALSE; + if (SDL_SYS_CDioctl (cdrom->id, DKAUDIO, &cmd) < 0) { + return -1; } okay = 0; cdrom->numtracks = cmd.indexing.track_index.last_track - - cmd.indexing.track_index.first_track+1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { + - cmd.indexing.track_index.first_track + 1; + if (cdrom->numtracks > SDL_MAX_TRACKS) { cdrom->numtracks = SDL_MAX_TRACKS; } /* Read all the track TOC entries */ - for ( i=0; i<=cdrom->numtracks; ++i ) { - if ( i == cdrom->numtracks ) { + for (i = 0; i <= cdrom->numtracks; ++i) { + if (i == cdrom->numtracks) { cdrom->track[i].id = 0xAA;; } else { - cdrom->track[i].id = cmd.indexing.track_index.first_track+i; + cdrom->track[i].id = cmd.indexing.track_index.first_track + i; } - entry.audio_cmds = CD_GET_TRK_MSF; - entry.indexing.track_msf.track = cdrom->track[i].id; - if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &entry) < 0 ) { + entry.audio_cmds = CD_GET_TRK_MSF; + entry.indexing.track_msf.track = cdrom->track[i].id; + if (SDL_SYS_CDioctl (cdrom->id, DKAUDIO, &entry) < 0) { break; } else { - cdrom->track[i].type = 0; /* don't know how to detect 0x04 data track */ - cdrom->track[i].offset = MSF_TO_FRAMES( - entry.indexing.track_msf.mins, - entry.indexing.track_msf.secs, - entry.indexing.track_msf.frames); + cdrom->track[i].type = 0; /* don't know how to detect 0x04 data track */ + cdrom->track[i].offset = + MSF_TO_FRAMES (entry.indexing.track_msf.mins, + entry.indexing.track_msf.secs, + entry.indexing.track_msf.frames); cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i-1].length = cdrom->track[i].offset - - cdrom->track[i-1].offset; + if (i > 0) { + cdrom->track[i - 1].length = cdrom->track[i].offset + - cdrom->track[i - 1].offset; } } } - if ( i == (cdrom->numtracks+1) ) { + if (i == (cdrom->numtracks + 1)) { okay = 1; } - return(okay ? 0 : -1); + return (okay ? 0 : -1); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; + CDstatus status; struct cd_audio_cmd cmd; cmd.audio_cmds = CD_INFO_AUDIO; - if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0 ) { + if (SDL_SYS_CDioctl (cdrom->id, DKAUDIO, &cmd) < 0) { #ifdef DEBUG_CDROM - fprintf(stderr, "ioctl failed in SDL_SYS_CDStatus (%s)\n", SDL_GetError()); + fprintf (stderr, "ioctl failed in SDL_SYS_CDStatus (%s)\n", + SDL_GetError ()); #endif status = CD_ERROR; } else { switch (cmd.status) { - case CD_NO_AUDIO: - case CD_COMPLETED: - status = CD_STOPPED; - break; - case CD_PLAY_AUDIO: - status = CD_PLAYING; - break; - case CD_PAUSE_AUDIO: - status = CD_PAUSED; - break; - case CD_NOT_VALID: + case CD_NO_AUDIO: + case CD_COMPLETED: + status = CD_STOPPED; + break; + case CD_PLAY_AUDIO: + status = CD_PLAYING; + break; + case CD_PAUSE_AUDIO: + status = CD_PAUSED; + break; + case CD_NOT_VALID: #ifdef DEBUG_CDROM - fprintf(stderr, "cdStatus failed with CD_NOT_VALID\n"); + fprintf (stderr, "cdStatus failed with CD_NOT_VALID\n"); #endif - status = CD_ERROR; - break; - case CD_STATUS_ERROR: + status = CD_ERROR; + break; + case CD_STATUS_ERROR: #ifdef DEBUG_CDROM - fprintf(stderr, "cdStatus failed with CD_STATUS_ERROR\n"); + fprintf (stderr, "cdStatus failed with CD_STATUS_ERROR\n"); #endif - status = CD_ERROR; - break; - default: + status = CD_ERROR; + break; + default: #ifdef DEBUG_CDROM - fprintf(stderr, "cdStatus failed with unknown error\n"); + fprintf (stderr, "cdStatus failed with unknown error\n"); #endif - status = CD_ERROR; - break; + status = CD_ERROR; + break; } } - if ( position ) { - if ( status == CD_PLAYING || (status == CD_PAUSED) ) { - *position = MSF_TO_FRAMES( cmd.indexing.info_audio.current_mins, - cmd.indexing.info_audio.current_secs, - cmd.indexing.info_audio.current_frames); + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) { + *position = + MSF_TO_FRAMES (cmd.indexing.info_audio.current_mins, + cmd.indexing.info_audio.current_secs, + cmd.indexing.info_audio.current_frames); } else { *position = 0; } @@ -571,7 +575,8 @@ static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { struct cd_audio_cmd cmd; @@ -581,80 +586,86 @@ static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) * its better to do this elsewhere? */ cmd.audio_cmds = CD_PLAY_AUDIO | CD_SET_VOLUME; - cmd.msf_flag = TRUE; - FRAMES_TO_MSF(start, - &cmd.indexing.msf.first_mins, - &cmd.indexing.msf.first_secs, - &cmd.indexing.msf.first_frames); - FRAMES_TO_MSF(start+length, - &cmd.indexing.msf.last_mins, - &cmd.indexing.msf.last_secs, - &cmd.indexing.msf.last_frames); - cmd.volume_type = CD_VOLUME_ALL; - cmd.all_channel_vol = 255; /* This is a uchar. What is a good value? No docu! */ - cmd.out_port_0_sel = CD_AUDIO_CHNL_0; - cmd.out_port_1_sel = CD_AUDIO_CHNL_1; - cmd.out_port_2_sel = CD_AUDIO_CHNL_2; - cmd.out_port_3_sel = CD_AUDIO_CHNL_3; + cmd.msf_flag = TRUE; + FRAMES_TO_MSF (start, + &cmd.indexing.msf.first_mins, + &cmd.indexing.msf.first_secs, + &cmd.indexing.msf.first_frames); + FRAMES_TO_MSF (start + length, + &cmd.indexing.msf.last_mins, + &cmd.indexing.msf.last_secs, + &cmd.indexing.msf.last_frames); + cmd.volume_type = CD_VOLUME_ALL; + cmd.all_channel_vol = 255; /* This is a uchar. What is a good value? No docu! */ + cmd.out_port_0_sel = CD_AUDIO_CHNL_0; + cmd.out_port_1_sel = CD_AUDIO_CHNL_1; + cmd.out_port_2_sel = CD_AUDIO_CHNL_2; + cmd.out_port_3_sel = CD_AUDIO_CHNL_3; #ifdef DEBUG_CDROM - fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", - cmd.indexing.msf.first_mins, - cmd.indexing.msf.first_secs, - cmd.indexing.msf.first_frames, - cmd.indexing.msf.last_mins, - cmd.indexing.msf.last_secs, - cmd.indexing.msf.last_frames); + fprintf (stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", + cmd.indexing.msf.first_mins, + cmd.indexing.msf.first_secs, + cmd.indexing.msf.first_frames, + cmd.indexing.msf.last_mins, + cmd.indexing.msf.last_secs, cmd.indexing.msf.last_frames); #endif - return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); + return (SDL_SYS_CDioctl (cdrom->id, DKAUDIO, &cmd)); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { struct cd_audio_cmd cmd; cmd.audio_cmds = CD_PAUSE_AUDIO; - return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); + return (SDL_SYS_CDioctl (cdrom->id, DKAUDIO, &cmd)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { struct cd_audio_cmd cmd; cmd.audio_cmds = CD_RESUME_AUDIO; - return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); + return (SDL_SYS_CDioctl (cdrom->id, DKAUDIO, &cmd)); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { struct cd_audio_cmd cmd; cmd.audio_cmds = CD_STOP_AUDIO; - return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); + return (SDL_SYS_CDioctl (cdrom->id, DKAUDIO, &cmd)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, DKEJECT, 0)); + return (SDL_SYS_CDioctl (cdrom->id, DKEJECT, 0)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - close(cdrom->id); + close (cdrom->id); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - int i; - - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; + } } #endif /* SDL_CDROM_AIX */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/beos/SDL_syscdrom.cc b/src/cdrom/beos/SDL_syscdrom.cc index af9094ab7..cfd693cef 100644 --- a/src/cdrom/beos/SDL_syscdrom.cc +++ b/src/cdrom/beos/SDL_syscdrom.cc @@ -37,7 +37,8 @@ #include #include "SDL_cdrom.h" -extern "C" { +extern "C" +{ #include "../SDL_syscdrom.h" } @@ -59,354 +60,370 @@ extern "C" { #define POS_REL_F(pos) pos.position[15] /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 16 +#define MAX_DRIVES 16 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); -int try_dir(const char *directory); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); +int try_dir (const char *directory); /* Check a drive to see if it is a CD-ROM */ -static int CheckDrive(char *drive) +static int +CheckDrive (char *drive) { - struct stat stbuf; - int is_cd, cdfd; - device_geometry info; - - /* If it doesn't exist, return -1 */ - if ( stat(drive, &stbuf) < 0 ) { - return(-1); - } - - /* If it does exist, verify that it's an available CD-ROM */ - is_cd = 0; - cdfd = open(drive, 0); - if ( cdfd >= 0 ) { - if ( ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR ) { - if ( info.device_type == B_CD ) { - is_cd = 1; - } - } - close(cdfd); - } else { - /* This can happen when the drive is open .. (?) */; - is_cd = 1; - } - return(is_cd); + struct stat stbuf; + int is_cd, cdfd; + device_geometry info; + + /* If it doesn't exist, return -1 */ + if (stat (drive, &stbuf) < 0) { + return (-1); + } + + /* If it does exist, verify that it's an available CD-ROM */ + is_cd = 0; + cdfd = open (drive, 0); + if (cdfd >= 0) { + if (ioctl (cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR) { + if (info.device_type == B_CD) { + is_cd = 1; + } + } + close (cdfd); + } else { + /* This can happen when the drive is open .. (?) */ ; + is_cd = 1; + } + return (is_cd); } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive) +static void +AddDrive (char *drive) { - int i; - size_t len; - - if ( SDL_numcds < MAX_DRIVES ) { - /* Add this drive to our list */ - i = SDL_numcds; - len = SDL_strlen(drive)+1; - SDL_cdlist[i] = (char *)SDL_malloc(len); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - SDL_strlcpy(SDL_cdlist[i], drive, len); - ++SDL_numcds; + int i; + size_t len; + + if (SDL_numcds < MAX_DRIVES) { + /* Add this drive to our list */ + i = SDL_numcds; + len = SDL_strlen (drive) + 1; + SDL_cdlist[i] = (char *) SDL_malloc (len); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + SDL_strlcpy (SDL_cdlist[i], drive, len); + ++SDL_numcds; #ifdef CDROM_DEBUG - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif - } + } } /* IDE bus scanning magic */ -enum { - IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50, +enum +{ + IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50, }; -struct ide_ctrl_info { - bool ide_0_present; - bool ide_0_master_present; - bool ide_0_slave_present; - int ide_0_master_type; - int ide_0_slave_type; - bool ide_1_present; - bool ide_1_master_present; - bool ide_1_slave_present; - int ide_1_master_type; - int ide_1_slave_type; +struct ide_ctrl_info +{ + bool ide_0_present; + bool ide_0_master_present; + bool ide_0_slave_present; + int ide_0_master_type; + int ide_0_slave_type; + bool ide_1_present; + bool ide_1_master_present; + bool ide_1_slave_present; + int ide_1_master_type; + int ide_1_slave_type; }; -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - char *SDLcdrom; - int raw_fd; - struct ide_ctrl_info info; - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Look in the environment for our CD-ROM drive list */ - SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ - if ( SDLcdrom != NULL ) { - char *cdpath, *delim; - size_t len = SDL_strlen(SDLcdrom)+1; - cdpath = SDL_stack_alloc(char, len); - if ( cdpath != NULL ) { - SDL_strlcpy(cdpath, SDLcdrom, len); - SDLcdrom = cdpath; - do { - delim = SDL_strchr(SDLcdrom, ':'); - if ( delim ) { - *delim++ = '\0'; - } - if ( CheckDrive(SDLcdrom) > 0 ) { - AddDrive(SDLcdrom); - } - if ( delim ) { - SDLcdrom = delim; - } else { - SDLcdrom = NULL; - } - } while ( SDLcdrom ); - SDL_stack_free(cdpath); - } - - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } - } - - /* Scan the system for CD-ROM drives */ - try_dir("/dev/disk"); - return 0; + char *SDLcdrom; + int raw_fd; + struct ide_ctrl_info info; + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Look in the environment for our CD-ROM drive list */ + SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ + if (SDLcdrom != NULL) { + char *cdpath, *delim; + size_t len = SDL_strlen (SDLcdrom) + 1; + cdpath = SDL_stack_alloc (char, len); + if (cdpath != NULL) { + SDL_strlcpy (cdpath, SDLcdrom, len); + SDLcdrom = cdpath; + do { + delim = SDL_strchr (SDLcdrom, ':'); + if (delim) { + *delim++ = '\0'; + } + if (CheckDrive (SDLcdrom) > 0) { + AddDrive (SDLcdrom); + } + if (delim) { + SDLcdrom = delim; + } else { + SDLcdrom = NULL; + } + } + while (SDLcdrom); + SDL_stack_free (cdpath); + } + + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } + } + + /* Scan the system for CD-ROM drives */ + try_dir ("/dev/disk"); + return 0; } -int try_dir(const char *directory) -{ - BDirectory dir; - dir.SetTo(directory); - if(dir.InitCheck() != B_NO_ERROR) { - return false; - } - dir.Rewind(); - BEntry entry; - while(dir.GetNextEntry(&entry) >= 0) { - BPath path; - const char *name; - entry_ref e; - - if(entry.GetPath(&path) != B_NO_ERROR) - continue; - name = path.Path(); - - if(entry.GetRef(&e) != B_NO_ERROR) - continue; - - if(entry.IsDirectory()) { - if(SDL_strcmp(e.name, "floppy") == 0) - continue; /* ignore floppy (it is not silent) */ - int devfd = try_dir(name); - if(devfd >= 0) - return devfd; - } - else { - int devfd; - device_geometry g; - - if(SDL_strcmp(e.name, "raw") != 0) - continue; /* ignore partitions */ - - devfd = open(name, O_RDONLY); - if(devfd < 0) - continue; - - if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) { - if(g.device_type == B_CD) - { - AddDrive(strdup(name)); - } - } - close(devfd); - } - } - return B_ERROR; +int +try_dir (const char *directory) +{ + BDirectory dir; + dir.SetTo (directory); + if (dir.InitCheck () != B_NO_ERROR) { + return false; + } + dir.Rewind (); + BEntry entry; + while (dir.GetNextEntry (&entry) >= 0) { + BPath path; + const char *name; + entry_ref e; + + if (entry.GetPath (&path) != B_NO_ERROR) + continue; + name = path.Path (); + + if (entry.GetRef (&e) != B_NO_ERROR) + continue; + + if (entry.IsDirectory ()) { + if (SDL_strcmp (e.name, "floppy") == 0) + continue; /* ignore floppy (it is not silent) */ + int devfd = try_dir (name); + if (devfd >= 0) + return devfd; + } else { + int devfd; + device_geometry g; + + if (SDL_strcmp (e.name, "raw") != 0) + continue; /* ignore partitions */ + + devfd = open (name, O_RDONLY); + if (devfd < 0) + continue; + + if (ioctl (devfd, B_GET_GEOMETRY, &g, sizeof (g)) >= 0) { + if (g.device_type == B_CD) { + AddDrive (strdup (name)); + } + } + close (devfd); + } + } + return B_ERROR; } /* General ioctl() CD-ROM command function */ -static int SDL_SYS_CDioctl(int index, int command, void *arg) +static int +SDL_SYS_CDioctl (int index, int command, void *arg) { - int okay; - int fd; - - okay = 0; - fd = open(SDL_cdlist[index], 0); - if ( fd >= 0 ) { - if ( ioctl(fd, command, arg) == B_NO_ERROR ) { - okay = 1; - } - close(fd); - } - return(okay ? 0 : -1); + int okay; + int fd; + + okay = 0; + fd = open (SDL_cdlist[index], 0); + if (fd >= 0) { + if (ioctl (fd, command, arg) == B_NO_ERROR) { + okay = 1; + } + close (fd); + } + return (okay ? 0 : -1); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); -} + return (SDL_cdlist[drive]); +} -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - return(drive); + return (drive); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - int i; - scsi_toc toc; - - if ( SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0 ) { - cdrom->numtracks = CD_NUMTRACKS(toc); - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { - cdrom->numtracks = SDL_MAX_TRACKS; - } - for ( i=0; i<=cdrom->numtracks; ++i ) { - cdrom->track[i].id = CD_TRACK_N(toc, i); - /* FIXME: How do we tell on BeOS? */ - cdrom->track[i].type = SDL_AUDIO_TRACK; - cdrom->track[i].offset = MSF_TO_FRAMES( - CD_TRACK_M(toc, i), - CD_TRACK_S(toc, i), - CD_TRACK_F(toc, i)); - cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i-1].length = - cdrom->track[i].offset- - cdrom->track[i-1].offset; - } - } - return(0); - } else { - return(-1); - } + int i; + scsi_toc toc; + + if (SDL_SYS_CDioctl (cdrom->id, B_SCSI_GET_TOC, &toc) == 0) { + cdrom->numtracks = CD_NUMTRACKS (toc); + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; + } + for (i = 0; i <= cdrom->numtracks; ++i) { + cdrom->track[i].id = CD_TRACK_N (toc, i); + /* FIXME: How do we tell on BeOS? */ + cdrom->track[i].type = SDL_AUDIO_TRACK; + cdrom->track[i].offset = MSF_TO_FRAMES (CD_TRACK_M (toc, i), + CD_TRACK_S (toc, i), + CD_TRACK_F (toc, i)); + cdrom->track[i].length = 0; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; + } + } + return (0); + } else { + return (-1); + } } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; - int fd; - int cur_frame; - scsi_position pos; - - fd = open(SDL_cdlist[cdrom->id], 0); - cur_frame = 0; - if ( fd >= 0 ) { - if ( ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR ) { - cur_frame = MSF_TO_FRAMES( - POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos)); - } - if ( ! pos.position[1] || (pos.position[1] >= 0x13) || - ((pos.position[1] == 0x12) && (!pos.position[6])) ) { - status = CD_STOPPED; - } else - if ( pos.position[1] == 0x11 ) { - status = CD_PLAYING; - } else { - status = CD_PAUSED; - } - close(fd); - } else { - status = CD_TRAYEMPTY; - } - if ( position ) { - *position = cur_frame; - } - return(status); + CDstatus status; + int fd; + int cur_frame; + scsi_position pos; + + fd = open (SDL_cdlist[cdrom->id], 0); + cur_frame = 0; + if (fd >= 0) { + if (ioctl (fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR) { + cur_frame = + MSF_TO_FRAMES (POS_ABS_M (pos), POS_ABS_S (pos), + POS_ABS_F (pos)); + } + if (!pos.position[1] || (pos.position[1] >= 0x13) || + ((pos.position[1] == 0x12) && (!pos.position[6]))) { + status = CD_STOPPED; + } else if (pos.position[1] == 0x11) { + status = CD_PLAYING; + } else { + status = CD_PAUSED; + } + close (fd); + } else { + status = CD_TRAYEMPTY; + } + if (position) { + *position = cur_frame; + } + return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - int okay; - int fd; - scsi_play_position pos; - - okay = 0; - fd = open(SDL_cdlist[cdrom->id], 0); - if ( fd >= 0 ) { - FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f); - FRAMES_TO_MSF(start+length, &pos.end_m, &pos.end_s, &pos.end_f); - if ( ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR ) { - okay = 1; - } - close(fd); - } - return(okay ? 0 : -1); + int okay; + int fd; + scsi_play_position pos; + + okay = 0; + fd = open (SDL_cdlist[cdrom->id], 0); + if (fd >= 0) { + FRAMES_TO_MSF (start, &pos.start_m, &pos.start_s, &pos.start_f); + FRAMES_TO_MSF (start + length, &pos.end_m, &pos.end_s, &pos.end_f); + if (ioctl (fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR) { + okay = 1; + } + close (fd); + } + return (okay ? 0 : -1); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0)); + return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_PAUSE_AUDIO, 0)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0)); + return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_RESUME_AUDIO, 0)); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0)); + return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_STOP_AUDIO, 0)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0)); + return (SDL_SYS_CDioctl (cdrom->id, B_SCSI_EJECT, 0)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - close(cdrom->id); + close (cdrom->id); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - int i; - - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; + } } #endif /* SDL_CDROM_BEOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/bsdi/SDL_syscdrom.c b/src/cdrom/bsdi/SDL_syscdrom.c index 7687f21c4..3d65eb7c4 100644 --- a/src/cdrom/bsdi/SDL_syscdrom.c +++ b/src/cdrom/bsdi/SDL_syscdrom.c @@ -52,491 +52,501 @@ #define FRAMES_PER_MINUTE (FRAMES_PER_SECOND * 60) int -msf_to_frame(int minute, int second, int frame) - { - return(minute * FRAMES_PER_MINUTE + second * FRAMES_PER_SECOND + frame); - } +msf_to_frame (int minute, int second, int frame) +{ + return (minute * FRAMES_PER_MINUTE + second * FRAMES_PER_SECOND + frame); +} void -frame_to_msf(int frame, int *minp, int *secp, int *framep) - { - *minp = frame / FRAMES_PER_MINUTE; - *secp = (frame % FRAMES_PER_MINUTE) / FRAMES_PER_SECOND; - *framep = frame % FRAMES_PER_SECOND; - } +frame_to_msf (int frame, int *minp, int *secp, int *framep) +{ + *minp = frame / FRAMES_PER_MINUTE; + *secp = (frame % FRAMES_PER_MINUTE) / FRAMES_PER_SECOND; + *framep = frame % FRAMES_PER_SECOND; +} /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 16 +#define MAX_DRIVES 16 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; static dev_t SDL_cdmode[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); - -typedef struct scsi_cdb cdb_t; - -static int scsi_cmd(int fd, - struct scsi_cdb *cdb, - int cdblen, - int rw, - caddr_t data, - int datalen, - struct scsi_user_cdb *sus) - { - int scsistatus; - unsigned char *cp; - struct scsi_user_cdb suc; +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); + +typedef struct scsi_cdb cdb_t; + +static int +scsi_cmd (int fd, + struct scsi_cdb *cdb, + int cdblen, + int rw, caddr_t data, int datalen, struct scsi_user_cdb *sus) +{ + int scsistatus; + unsigned char *cp; + struct scsi_user_cdb suc; /* safety checks */ - if (!cdb) return(-1); - if (rw != SUC_READ && rw != SUC_WRITE) return(-1); - - suc.suc_flags = rw; - suc.suc_cdblen = cdblen; - bcopy(cdb, suc.suc_cdb, cdblen); - suc.suc_datalen = datalen; - suc.suc_data = data; - suc.suc_timeout = 10; /* 10 secs max for TUR or SENSE */ - if (ioctl(fd, SCSIRAWCDB, &suc) == -1) - return(-11); - scsistatus = suc.suc_sus.sus_status; - cp = suc.suc_sus.sus_sense; + if (!cdb) + return (-1); + if (rw != SUC_READ && rw != SUC_WRITE) + return (-1); + + suc.suc_flags = rw; + suc.suc_cdblen = cdblen; + bcopy (cdb, suc.suc_cdb, cdblen); + suc.suc_datalen = datalen; + suc.suc_data = data; + suc.suc_timeout = 10; /* 10 secs max for TUR or SENSE */ + if (ioctl (fd, SCSIRAWCDB, &suc) == -1) + return (-11); + scsistatus = suc.suc_sus.sus_status; + cp = suc.suc_sus.sus_sense; /* * If a place to copy the sense data back to has been provided then the * caller is responsible for checking the errors and printing any information * out if the status was not successful. */ - if (scsistatus != 0 && !sus) - { - fprintf(stderr,"scsistatus = %x cmd = %x\n", - scsistatus, cdb[0]); - fprintf(stderr, "sense %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", - cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], - cp[6], cp[7], cp[8], cp[9], cp[10], cp[11], - cp[12], cp[13], cp[14], cp[15]); - return(1); - } - if (sus) - bcopy(&suc, sus, sizeof (struct scsi_user_cdb)); - if (scsistatus) - return(1); /* Return non-zero for unsuccessful status */ - return(0); - } + if (scsistatus != 0 && !sus) { + fprintf (stderr, "scsistatus = %x cmd = %x\n", scsistatus, cdb[0]); + fprintf (stderr, + "sense %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", + cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7], + cp[8], cp[9], cp[10], cp[11], cp[12], cp[13], cp[14], + cp[15]); + return (1); + } + if (sus) + bcopy (&suc, sus, sizeof (struct scsi_user_cdb)); + if (scsistatus) + return (1); /* Return non-zero for unsuccessful status */ + return (0); +} /* request vendor brand and model */ -unsigned char *Inquiry(int fd) - { - static struct scsi_cdb6 cdb = - { - 0x12, - 0, 0, 0, - 56, - 0 - }; - static unsigned char Inqbuffer[56]; - - if (scsi_cmd(fd, (cdb_t *)&cdb, 6, SUC_READ, Inqbuffer, - sizeof(Inqbuffer), 0)) - return("\377"); - return(Inqbuffer); - } +unsigned char * +Inquiry (int fd) +{ + static struct scsi_cdb6 cdb = { + 0x12, + 0, 0, 0, + 56, + 0 + }; + static unsigned char Inqbuffer[56]; + + if (scsi_cmd (fd, (cdb_t *) & cdb, 6, SUC_READ, Inqbuffer, + sizeof (Inqbuffer), 0)) + return ("\377"); + return (Inqbuffer); +} #define ADD_SENSECODE 12 #define ADD_SC_QUALIFIER 13 -int TestForMedium(int fd) - { - int sts, asc, ascq; - struct scsi_user_cdb sus; - static struct scsi_cdb6 cdb = - { - CMD_TEST_UNIT_READY, /* command */ - 0, /* reserved */ - 0, /* reserved */ - 0, /* reserved */ - 0, /* reserved */ - 0 /* reserved */ - }; - -again: sts = scsi_cmd(fd, (cdb_t *)&cdb, 6, SUC_READ, 0, 0, &sus); - asc = sus.suc_sus.sus_sense[ADD_SENSECODE]; - ascq = sus.suc_sus.sus_sense[ADD_SC_QUALIFIER]; - if (asc == 0x3a && ascq == 0x0) /* no medium */ - return(0); - if (asc == 0x28 && ascq == 0x0) /* medium changed */ - goto again; - if (asc == 0x4 && ascq == 0x1 ) /* coming ready */ - { - sleep(2); - goto again; - } - return(1); - } +int +TestForMedium (int fd) +{ + int sts, asc, ascq; + struct scsi_user_cdb sus; + static struct scsi_cdb6 cdb = { + CMD_TEST_UNIT_READY, /* command */ + 0, /* reserved */ + 0, /* reserved */ + 0, /* reserved */ + 0, /* reserved */ + 0 /* reserved */ + }; + + again:sts = scsi_cmd (fd, (cdb_t *) & cdb, 6, SUC_READ, 0, 0, &sus); + asc = sus.suc_sus.sus_sense[ADD_SENSECODE]; + ascq = sus.suc_sus.sus_sense[ADD_SC_QUALIFIER]; + if (asc == 0x3a && ascq == 0x0) /* no medium */ + return (0); + if (asc == 0x28 && ascq == 0x0) /* medium changed */ + goto again; + if (asc == 0x4 && ascq == 0x1) { /* coming ready */ + sleep (2); + goto again; + } + return (1); +} /* Check a drive to see if it is a CD-ROM */ -static int CheckDrive(char *drive, struct stat *stbuf) +static int +CheckDrive (char *drive, struct stat *stbuf) { - int is_cd = 0, cdfd; - char *p; - - /* If it doesn't exist, return -1 */ - if ( stat(drive, stbuf) < 0 ) { - return(-1); - } - - /* If it does exist, verify that it's an available CD-ROM */ - cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); - if ( cdfd >= 0 ) { - p = Inquiry(cdfd); - if (*p == TYPE_ROM) - is_cd = 1; - close(cdfd); - } - return(is_cd); + int is_cd = 0, cdfd; + char *p; + + /* If it doesn't exist, return -1 */ + if (stat (drive, stbuf) < 0) { + return (-1); + } + + /* If it does exist, verify that it's an available CD-ROM */ + cdfd = open (drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0); + if (cdfd >= 0) { + p = Inquiry (cdfd); + if (*p == TYPE_ROM) + is_cd = 1; + close (cdfd); + } + return (is_cd); } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive, struct stat *stbuf) +static void +AddDrive (char *drive, struct stat *stbuf) { - int i; - - if ( SDL_numcds < MAX_DRIVES ) { - /* Check to make sure it's not already in our list. - This can happen when we see a drive via symbolic link. - */ - for ( i=0; ist_rdev == SDL_cdmode[i] ) { + int i; + + if (SDL_numcds < MAX_DRIVES) { + /* Check to make sure it's not already in our list. + This can happen when we see a drive via symbolic link. + */ + for (i = 0; i < SDL_numcds; ++i) { + if (stbuf->st_rdev == SDL_cdmode[i]) { #ifdef DEBUG_CDROM - fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); + fprintf (stderr, "Duplicate drive detected: %s == %s\n", + drive, SDL_cdlist[i]); #endif - return; - } - } - - /* Add this drive to our list */ - i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - SDL_cdmode[i] = stbuf->st_rdev; - ++SDL_numcds; + return; + } + } + + /* Add this drive to our list */ + i = SDL_numcds; + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + SDL_cdmode[i] = stbuf->st_rdev; + ++SDL_numcds; #ifdef DEBUG_CDROM - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif - } + } } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - /* checklist: /dev/rsr?c */ - static char *checklist[] = { - "?0 rsr?", NULL - }; - char *SDLcdrom; - int i, j, exists; - char drive[32]; - struct stat stbuf; - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Look in the environment for our CD-ROM drive list */ - SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ - if ( SDLcdrom != NULL ) { - char *cdpath, *delim; - size_t len = SDL_strlen(SDLcdrom)+1; - cdpath = SDL_stack_alloc(char, len); - if ( cdpath != NULL ) { - SDL_strlcpy(cdpath, SDLcdrom, len); - SDLcdrom = cdpath; - do { - delim = SDL_strchr(SDLcdrom, ':'); - if ( delim ) { - *delim++ = '\0'; - } - if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { - AddDrive(SDLcdrom, &stbuf); - } - if ( delim ) { - SDLcdrom = delim; - } else { - SDLcdrom = NULL; - } - } while ( SDLcdrom ); - SDL_stack_free(cdpath); - } - - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } - } - - /* Scan the system for CD-ROM drives */ - for ( i=0; checklist[i]; ++i ) { - if ( checklist[i][0] == '?' ) { - char *insert; - exists = 1; - for ( j=checklist[i][1]; exists; ++j ) { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc", &checklist[i][3]); - insert = SDL_strchr(drive, '?'); - if ( insert != NULL ) { - *insert = j; - } - switch (CheckDrive(drive, &stbuf)) { - /* Drive exists and is a CD-ROM */ - case 1: - AddDrive(drive, &stbuf); - break; - /* Drive exists, but isn't a CD-ROM */ - case 0: - break; - /* Drive doesn't exist */ - case -1: - exists = 0; - break; - } - } - } else { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); - if ( CheckDrive(drive, &stbuf) > 0 ) { - AddDrive(drive, &stbuf); - } - } - } - return(0); + /* checklist: /dev/rsr?c */ + static char *checklist[] = { + "?0 rsr?", NULL + }; + char *SDLcdrom; + int i, j, exists; + char drive[32]; + struct stat stbuf; + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Look in the environment for our CD-ROM drive list */ + SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ + if (SDLcdrom != NULL) { + char *cdpath, *delim; + size_t len = SDL_strlen (SDLcdrom) + 1; + cdpath = SDL_stack_alloc (char, len); + if (cdpath != NULL) { + SDL_strlcpy (cdpath, SDLcdrom, len); + SDLcdrom = cdpath; + do { + delim = SDL_strchr (SDLcdrom, ':'); + if (delim) { + *delim++ = '\0'; + } + if (CheckDrive (SDLcdrom, &stbuf) > 0) { + AddDrive (SDLcdrom, &stbuf); + } + if (delim) { + SDLcdrom = delim; + } else { + SDLcdrom = NULL; + } + } + while (SDLcdrom); + SDL_stack_free (cdpath); + } + + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } + } + + /* Scan the system for CD-ROM drives */ + for (i = 0; checklist[i]; ++i) { + if (checklist[i][0] == '?') { + char *insert; + exists = 1; + for (j = checklist[i][1]; exists; ++j) { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%sc", + &checklist[i][3]); + insert = SDL_strchr (drive, '?'); + if (insert != NULL) { + *insert = j; + } + switch (CheckDrive (drive, &stbuf)) { + /* Drive exists and is a CD-ROM */ + case 1: + AddDrive (drive, &stbuf); + break; + /* Drive exists, but isn't a CD-ROM */ + case 0: + break; + /* Drive doesn't exist */ + case -1: + exists = 0; + break; + } + } + } else { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + checklist[i]); + if (CheckDrive (drive, &stbuf) > 0) { + AddDrive (drive, &stbuf); + } + } + } + return (0); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - return(open(SDL_cdlist[drive], O_RDONLY | O_NONBLOCK | O_EXCL, 0)); + return (open (SDL_cdlist[drive], O_RDONLY | O_NONBLOCK | O_EXCL, 0)); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) - { - u_char cdb[10], buf[4], *p, *toc; - struct scsi_user_cdb sus; - int i, sts, first_track, last_track, ntracks, toc_size; - - bzero(cdb, sizeof (cdb)); - cdb[0] = 0x43; /* Read TOC */ - cdb[1] = 0x2; /* MSF */ - cdb[8] = 4; /* size TOC header */ - sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, buf, 4, &sus); - if (sts < 0) - return(-1); - first_track = buf[2]; - last_track = buf[3]; - ntracks = last_track - first_track + 1; - cdrom->numtracks = ntracks; - toc_size = 4 + (ntracks + 1) * 8; - toc = (u_char *)SDL_malloc(toc_size); - if (toc == NULL) - return(-1); - bzero(cdb, sizeof (cdb)); - cdb[0] = 0x43; - cdb[1] = 0x2; - cdb[6] = first_track; - cdb[7] = toc_size >> 8; - cdb[8] = toc_size & 0xff; - sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, toc, toc_size, - &sus); - if (sts < 0) - { - SDL_free(toc); - return(-1); - } - - for (i = 0, p = toc+4; i <= ntracks; i++, p+= 8) - { - if (i == ntracks) - cdrom->track[i].id = 0xAA; /* Leadout */ - else - cdrom->track[i].id = first_track + i; - if (p[1] & 0x20) - cdrom->track[i].type = SDL_DATA_TRACK; - else - cdrom->track[i].type = SDL_AUDIO_TRACK; - cdrom->track[i].offset = msf_to_frame(p[5], p[6], p[7]); - cdrom->track[i].length = 0; - if (i > 0) - cdrom->track[i-1].length = cdrom->track[i].offset - - cdrom->track[i-1].offset; - } - SDL_free(toc); - return(0); - } +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) +{ + u_char cdb[10], buf[4], *p, *toc; + struct scsi_user_cdb sus; + int i, sts, first_track, last_track, ntracks, toc_size; + + bzero (cdb, sizeof (cdb)); + cdb[0] = 0x43; /* Read TOC */ + cdb[1] = 0x2; /* MSF */ + cdb[8] = 4; /* size TOC header */ + sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, buf, 4, &sus); + if (sts < 0) + return (-1); + first_track = buf[2]; + last_track = buf[3]; + ntracks = last_track - first_track + 1; + cdrom->numtracks = ntracks; + toc_size = 4 + (ntracks + 1) * 8; + toc = (u_char *) SDL_malloc (toc_size); + if (toc == NULL) + return (-1); + bzero (cdb, sizeof (cdb)); + cdb[0] = 0x43; + cdb[1] = 0x2; + cdb[6] = first_track; + cdb[7] = toc_size >> 8; + cdb[8] = toc_size & 0xff; + sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, toc, toc_size, + &sus); + if (sts < 0) { + SDL_free (toc); + return (-1); + } + + for (i = 0, p = toc + 4; i <= ntracks; i++, p += 8) { + if (i == ntracks) + cdrom->track[i].id = 0xAA; /* Leadout */ + else + cdrom->track[i].id = first_track + i; + if (p[1] & 0x20) + cdrom->track[i].type = SDL_DATA_TRACK; + else + cdrom->track[i].type = SDL_AUDIO_TRACK; + cdrom->track[i].offset = msf_to_frame (p[5], p[6], p[7]); + cdrom->track[i].length = 0; + if (i > 0) + cdrom->track[i - 1].length = cdrom->track[i].offset - + cdrom->track[i - 1].offset; + } + SDL_free (toc); + return (0); +} /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) - { - CDstatus status; - u_char cdb[10], buf[16]; - int sts; - struct scsi_user_cdb sus; - - bzero(cdb, sizeof (cdb)); - cdb[0] = 0x42; /* read subq */ - cdb[1] = 0x2; /* MSF */ - cdb[2] = 0x40; /* q channel */ - cdb[3] = 1; /* current pos */ - cdb[7] = sizeof (buf) >> 8; - cdb[8] = sizeof (buf) & 0xff; - sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, buf, sizeof (buf), - &sus); - if (sts < 0) - return(-1); - if (sts) - { - if (TestForMedium(cdrom->id) == 0) - status = CD_TRAYEMPTY; - else - status = CD_ERROR; - } - else - { - switch (buf[1]) - { - case 0x11: - status = CD_PLAYING; - break; - case 0x12: - status = CD_PAUSED; - break; - case 0x13: - case 0x14: - case 0x15: - status = CD_STOPPED; - break; - default: - status = CD_ERROR; - break; - } - } - if (position) - { - if ( status == CD_PLAYING || (status == CD_PAUSED) ) - *position = msf_to_frame(buf[9], buf[10], buf[11]); - else - *position = 0; - } - return(status); - } +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) +{ + CDstatus status; + u_char cdb[10], buf[16]; + int sts; + struct scsi_user_cdb sus; + + bzero (cdb, sizeof (cdb)); + cdb[0] = 0x42; /* read subq */ + cdb[1] = 0x2; /* MSF */ + cdb[2] = 0x40; /* q channel */ + cdb[3] = 1; /* current pos */ + cdb[7] = sizeof (buf) >> 8; + cdb[8] = sizeof (buf) & 0xff; + sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, buf, sizeof (buf), + &sus); + if (sts < 0) + return (-1); + if (sts) { + if (TestForMedium (cdrom->id) == 0) + status = CD_TRAYEMPTY; + else + status = CD_ERROR; + } else { + switch (buf[1]) { + case 0x11: + status = CD_PLAYING; + break; + case 0x12: + status = CD_PAUSED; + break; + case 0x13: + case 0x14: + case 0x15: + status = CD_STOPPED; + break; + default: + status = CD_ERROR; + break; + } + } + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) + *position = msf_to_frame (buf[9], buf[10], buf[11]); + else + *position = 0; + } + return (status); +} /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) - { - u_char cdb[10]; - int sts, minute, second, frame, eminute, esecond, eframe; - struct scsi_user_cdb sus; - - bzero(cdb, sizeof(cdb)); - cdb[0] = 0x47; /* Play */ - frame_to_msf(start, &minute, &second, &frame); - frame_to_msf(start + length, &eminute, &esecond, &eframe); - cdb[3] = minute; - cdb[4] = second; - cdb[5] = frame; - cdb[6] = eminute; - cdb[7] = esecond; - cdb[8] = eframe; - sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, 0, 0, &sus); - return(sts); - } - -static int -pauseresume(SDL_CD *cdrom, int flag) - { - u_char cdb[10]; - struct scsi_user_cdb sus; - - bzero(cdb, sizeof (cdb)); - cdb[0] = 0x4b; - cdb[8] = flag & 0x1; - return(scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, 0, 0, &sus)); - } +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) +{ + u_char cdb[10]; + int sts, minute, second, frame, eminute, esecond, eframe; + struct scsi_user_cdb sus; + + bzero (cdb, sizeof (cdb)); + cdb[0] = 0x47; /* Play */ + frame_to_msf (start, &minute, &second, &frame); + frame_to_msf (start + length, &eminute, &esecond, &eframe); + cdb[3] = minute; + cdb[4] = second; + cdb[5] = frame; + cdb[6] = eminute; + cdb[7] = esecond; + cdb[8] = eframe; + sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, 0, 0, &sus); + return (sts); +} + +static int +pauseresume (SDL_CD * cdrom, int flag) +{ + u_char cdb[10]; + struct scsi_user_cdb sus; + + bzero (cdb, sizeof (cdb)); + cdb[0] = 0x4b; + cdb[8] = flag & 0x1; + return (scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, 0, 0, &sus)); +} /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - return(pauseresume(cdrom, 0)); + return (pauseresume (cdrom, 0)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - return(pauseresume(cdrom, 1)); + return (pauseresume (cdrom, 1)); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - u_char cdb[6]; - struct scsi_user_cdb sus; + u_char cdb[6]; + struct scsi_user_cdb sus; - bzero(cdb, sizeof (cdb)); - cdb[0] = 0x1b; /* stop */ - cdb[1] = 1; /* immediate */ - return(scsi_cmd(cdrom->id, (cdb_t *)cdb, 6, SUC_READ, 0, 0, &sus)); + bzero (cdb, sizeof (cdb)); + cdb[0] = 0x1b; /* stop */ + cdb[1] = 1; /* immediate */ + return (scsi_cmd (cdrom->id, (cdb_t *) cdb, 6, SUC_READ, 0, 0, &sus)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - u_char cdb[6]; - struct scsi_user_cdb sus; - - bzero(cdb, sizeof (cdb)); - cdb[0] = 0x1b; /* stop */ - cdb[1] = 1; /* immediate */ - cdb[4] = 2; /* eject */ - return(scsi_cmd(cdrom->id, (cdb_t *)cdb, 6, SUC_READ, 0, 0, &sus)); + u_char cdb[6]; + struct scsi_user_cdb sus; + + bzero (cdb, sizeof (cdb)); + cdb[0] = 0x1b; /* stop */ + cdb[1] = 1; /* immediate */ + cdb[4] = 2; /* eject */ + return (scsi_cmd (cdrom->id, (cdb_t *) cdb, 6, SUC_READ, 0, 0, &sus)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) - { - close(cdrom->id); - } +static void +SDL_SYS_CDClose (SDL_CD * cdrom) +{ + close (cdrom->id); +} -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - int i; - - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + } + SDL_numcds = 0; } #endif /* SDL_CDROM_BSDI */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/dc/SDL_syscdrom.c b/src/cdrom/dc/SDL_syscdrom.c index d89e08968..a473b67d1 100644 --- a/src/cdrom/dc/SDL_syscdrom.c +++ b/src/cdrom/dc/SDL_syscdrom.c @@ -32,136 +32,156 @@ #include "../SDL_syscdrom.h" /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); - - -int SDL_SYS_CDInit(void) +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); + + +int +SDL_SYS_CDInit (void) { - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - return(0); + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + return (0); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return "/cd"; + return "/cd"; } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - return(drive); + return (drive); } #define TRACK_CDDA 0 -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - CDROM_TOC toc; - int ret,i; - - ret = cdrom_read_toc(&toc,0); - if (ret!=ERR_OK) { - return -1; - } - - cdrom->numtracks = TOC_TRACK(toc.last)-TOC_TRACK(toc.first)+1; - for(i=0;inumtracks;i++) { - unsigned long entry = toc.entry[i]; - cdrom->track[i].id = i+1; - cdrom->track[i].type = (TOC_CTRL(toc.entry[i])==TRACK_CDDA)?SDL_AUDIO_TRACK:SDL_DATA_TRACK; - cdrom->track[i].offset = TOC_LBA(entry)-150; - cdrom->track[i].length = TOC_LBA((i+1numtracks = TOC_TRACK (toc.last) - TOC_TRACK (toc.first) + 1; + for (i = 0; i < cdrom->numtracks; i++) { + unsigned long entry = toc.entry[i]; + cdrom->track[i].id = i + 1; + cdrom->track[i].type = + (TOC_CTRL (toc.entry[i]) == + TRACK_CDDA) ? SDL_AUDIO_TRACK : SDL_DATA_TRACK; + cdrom->track[i].offset = TOC_LBA (entry) - 150; + cdrom->track[i].length = + TOC_LBA ((i + 1 < + toc.last) ? toc.entry[i + 1] : toc.leadout_sector) - + TOC_LBA (entry); + } + + return 0; } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - int ret,dc_status,disc_type; - - ret = cdrom_get_status(&dc_status,&disc_type); - if (ret!=ERR_OK) return CD_ERROR; - - switch(dc_status) { -// case CD_STATUS_BUSY: - case CD_STATUS_PAUSED: - return CD_PAUSED; - case CD_STATUS_STANDBY: - return CD_STOPPED; - case CD_STATUS_PLAYING: - return CD_PLAYING; -// case CD_STATUS_SEEKING: -// case CD_STATUS_SCANING: - case CD_STATUS_OPEN: - case CD_STATUS_NO_DISC: - return CD_TRAYEMPTY; - default: - return CD_ERROR; - } + int ret, dc_status, disc_type; + + ret = cdrom_get_status (&dc_status, &disc_type); + if (ret != ERR_OK) + return CD_ERROR; + + switch (dc_status) { +// case CD_STATUS_BUSY: + case CD_STATUS_PAUSED: + return CD_PAUSED; + case CD_STATUS_STANDBY: + return CD_STOPPED; + case CD_STATUS_PLAYING: + return CD_PLAYING; +// case CD_STATUS_SEEKING: +// case CD_STATUS_SCANING: + case CD_STATUS_OPEN: + case CD_STATUS_NO_DISC: + return CD_TRAYEMPTY; + default: + return CD_ERROR; + } } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - int ret = cdrom_cdda_play(start-150,start-150+length,1,CDDA_SECTORS); - return ret==ERR_OK?0:-1; + int ret = + cdrom_cdda_play (start - 150, start - 150 + length, 1, CDDA_SECTORS); + return ret == ERR_OK ? 0 : -1; } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - int ret=cdrom_cdda_pause(); - return ret==ERR_OK?0:-1; + int ret = cdrom_cdda_pause (); + return ret == ERR_OK ? 0 : -1; } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - int ret=cdrom_cdda_resume(); - return ret==ERR_OK?0:-1; + int ret = cdrom_cdda_resume (); + return ret == ERR_OK ? 0 : -1; } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - int ret=cdrom_spin_down(); - return ret==ERR_OK?0:-1; + int ret = cdrom_spin_down (); + return ret == ERR_OK ? 0 : -1; } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return -1; + return -1; } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { } #endif /* SDL_CDROM_DC */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/dummy/SDL_syscdrom.c b/src/cdrom/dummy/SDL_syscdrom.c index 4a99303cc..6e9cebb7a 100644 --- a/src/cdrom/dummy/SDL_syscdrom.c +++ b/src/cdrom/dummy/SDL_syscdrom.c @@ -28,14 +28,17 @@ #include "SDL_cdrom.h" #include "../SDL_syscdrom.h" -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - return(0); + return (0); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - return; + return; } #endif /* SDL_CDROM_DUMMY || SDL_CDROM_DISABLED */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/freebsd/SDL_syscdrom.c b/src/cdrom/freebsd/SDL_syscdrom.c index 30b5c907e..e0b459355 100644 --- a/src/cdrom/freebsd/SDL_syscdrom.c +++ b/src/cdrom/freebsd/SDL_syscdrom.c @@ -37,370 +37,387 @@ /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 16 +#define MAX_DRIVES 16 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; static dev_t SDL_cdmode[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); /* Some ioctl() errno values which occur when the tray is empty */ #define ERRNO_TRAYEMPTY(errno) \ ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL)) /* Check a drive to see if it is a CD-ROM */ -static int CheckDrive(char *drive, struct stat *stbuf) +static int +CheckDrive (char *drive, struct stat *stbuf) { - int is_cd, cdfd; - struct ioc_read_subchannel info; - - /* If it doesn't exist, return -1 */ - if ( stat(drive, stbuf) < 0 ) { - return(-1); - } - - /* If it does exist, verify that it's an available CD-ROM */ - is_cd = 0; - if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { - cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); - if ( cdfd >= 0 ) { - info.address_format = CD_MSF_FORMAT; - info.data_format = CD_CURRENT_POSITION; - info.data_len = 0; - info.data = NULL; - /* Under Linux, EIO occurs when a disk is not present. - This isn't 100% reliable, so we use the USE_MNTENT - code above instead. - */ - if ( (ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) || - ERRNO_TRAYEMPTY(errno) ) { - is_cd = 1; - } - close(cdfd); - } - } - return(is_cd); + int is_cd, cdfd; + struct ioc_read_subchannel info; + + /* If it doesn't exist, return -1 */ + if (stat (drive, stbuf) < 0) { + return (-1); + } + + /* If it does exist, verify that it's an available CD-ROM */ + is_cd = 0; + if (S_ISCHR (stbuf->st_mode) || S_ISBLK (stbuf->st_mode)) { + cdfd = open (drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0); + if (cdfd >= 0) { + info.address_format = CD_MSF_FORMAT; + info.data_format = CD_CURRENT_POSITION; + info.data_len = 0; + info.data = NULL; + /* Under Linux, EIO occurs when a disk is not present. + This isn't 100% reliable, so we use the USE_MNTENT + code above instead. + */ + if ((ioctl (cdfd, CDIOCREADSUBCHANNEL, &info) == 0) || + ERRNO_TRAYEMPTY (errno)) { + is_cd = 1; + } + close (cdfd); + } + } + return (is_cd); } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive, struct stat *stbuf) +static void +AddDrive (char *drive, struct stat *stbuf) { - int i; - - if ( SDL_numcds < MAX_DRIVES ) { - /* Check to make sure it's not already in our list. - This can happen when we see a drive via symbolic link. - */ - for ( i=0; ist_rdev == SDL_cdmode[i] ) { + int i; + + if (SDL_numcds < MAX_DRIVES) { + /* Check to make sure it's not already in our list. + This can happen when we see a drive via symbolic link. + */ + for (i = 0; i < SDL_numcds; ++i) { + if (stbuf->st_rdev == SDL_cdmode[i]) { #ifdef DEBUG_CDROM - fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); + fprintf (stderr, "Duplicate drive detected: %s == %s\n", + drive, SDL_cdlist[i]); #endif - return; - } - } - - /* Add this drive to our list */ - i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - SDL_cdmode[i] = stbuf->st_rdev; - ++SDL_numcds; + return; + } + } + + /* Add this drive to our list */ + i = SDL_numcds; + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + SDL_cdmode[i] = stbuf->st_rdev; + ++SDL_numcds; #ifdef DEBUG_CDROM - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif - } + } } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c - /dev/matcd?c /dev/mcd?c /dev/scd?c */ - static char *checklist[] = { - "cdrom", "?0 cd?", "?0 acd?", "?0 matcd?", "?0 mcd?", "?0 scd?",NULL - }; - char *SDLcdrom; - int i, j, exists; - char drive[32]; - struct stat stbuf; - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Look in the environment for our CD-ROM drive list */ - SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ - if ( SDLcdrom != NULL ) { - char *cdpath, *delim; - size_t len = SDL_strlen(SDLcdrom)+1; - cdpath = SDL_stack_alloc(char, len); - if ( cdpath != NULL ) { - SDL_strlcpy(cdpath, SDLcdrom, len); - SDLcdrom = cdpath; - do { - delim = SDL_strchr(SDLcdrom, ':'); - if ( delim ) { - *delim++ = '\0'; - } - if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { - AddDrive(SDLcdrom, &stbuf); - } - if ( delim ) { - SDLcdrom = delim; - } else { - SDLcdrom = NULL; - } - } while ( SDLcdrom ); - SDL_stack_free(cdpath); - } - - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } - } - - /* Scan the system for CD-ROM drives */ - for ( i=0; checklist[i]; ++i ) { - if ( checklist[i][0] == '?' ) { - char *insert; - exists = 1; - for ( j=checklist[i][1]; exists; ++j ) { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc", &checklist[i][3]); - insert = SDL_strchr(drive, '?'); - if ( insert != NULL ) { - *insert = j; - } - switch (CheckDrive(drive, &stbuf)) { - /* Drive exists and is a CD-ROM */ - case 1: - AddDrive(drive, &stbuf); - break; - /* Drive exists, but isn't a CD-ROM */ - case 0: - break; - /* Drive doesn't exist */ - case -1: - exists = 0; - break; - } - } - } else { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); - if ( CheckDrive(drive, &stbuf) > 0 ) { - AddDrive(drive, &stbuf); - } - } - } - return(0); + /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c + /dev/matcd?c /dev/mcd?c /dev/scd?c */ + static char *checklist[] = { + "cdrom", "?0 cd?", "?0 acd?", "?0 matcd?", "?0 mcd?", "?0 scd?", NULL + }; + char *SDLcdrom; + int i, j, exists; + char drive[32]; + struct stat stbuf; + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Look in the environment for our CD-ROM drive list */ + SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ + if (SDLcdrom != NULL) { + char *cdpath, *delim; + size_t len = SDL_strlen (SDLcdrom) + 1; + cdpath = SDL_stack_alloc (char, len); + if (cdpath != NULL) { + SDL_strlcpy (cdpath, SDLcdrom, len); + SDLcdrom = cdpath; + do { + delim = SDL_strchr (SDLcdrom, ':'); + if (delim) { + *delim++ = '\0'; + } + if (CheckDrive (SDLcdrom, &stbuf) > 0) { + AddDrive (SDLcdrom, &stbuf); + } + if (delim) { + SDLcdrom = delim; + } else { + SDLcdrom = NULL; + } + } + while (SDLcdrom); + SDL_stack_free (cdpath); + } + + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } + } + + /* Scan the system for CD-ROM drives */ + for (i = 0; checklist[i]; ++i) { + if (checklist[i][0] == '?') { + char *insert; + exists = 1; + for (j = checklist[i][1]; exists; ++j) { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%sc", + &checklist[i][3]); + insert = SDL_strchr (drive, '?'); + if (insert != NULL) { + *insert = j; + } + switch (CheckDrive (drive, &stbuf)) { + /* Drive exists and is a CD-ROM */ + case 1: + AddDrive (drive, &stbuf); + break; + /* Drive exists, but isn't a CD-ROM */ + case 0: + break; + /* Drive doesn't exist */ + case -1: + exists = 0; + break; + } + } + } else { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + checklist[i]); + if (CheckDrive (drive, &stbuf) > 0) { + AddDrive (drive, &stbuf); + } + } + } + return (0); } /* General ioctl() CD-ROM command function */ -static int SDL_SYS_CDioctl(int id, int command, void *arg) +static int +SDL_SYS_CDioctl (int id, int command, void *arg) { - int retval; + int retval; - retval = ioctl(id, command, arg); - if ( retval < 0 ) { - SDL_SetError("ioctl() error: %s", strerror(errno)); - } - return(retval); + retval = ioctl (id, command, arg); + if (retval < 0) { + SDL_SetError ("ioctl() error: %s", strerror (errno)); + } + return (retval); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - return(open(SDL_cdlist[drive], (O_RDONLY|O_EXCL|O_NONBLOCK), 0)); + return (open (SDL_cdlist[drive], (O_RDONLY | O_EXCL | O_NONBLOCK), 0)); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - struct ioc_toc_header toc; - int i, okay; - struct ioc_read_toc_entry entry; - struct cd_toc_entry data; - - okay = 0; - if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0 ) { - cdrom->numtracks = toc.ending_track-toc.starting_track+1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { - cdrom->numtracks = SDL_MAX_TRACKS; - } - /* Read all the track TOC entries */ - for ( i=0; i<=cdrom->numtracks; ++i ) { - if ( i == cdrom->numtracks ) { - cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */ - } else { - cdrom->track[i].id = toc.starting_track+i; - } - entry.starting_track = cdrom->track[i].id; - entry.address_format = CD_MSF_FORMAT; - entry.data_len = sizeof(data); - entry.data = &data; - if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, - &entry) < 0 ) { - break; - } else { - cdrom->track[i].type = data.control; - cdrom->track[i].offset = MSF_TO_FRAMES( - data.addr.msf.minute, - data.addr.msf.second, - data.addr.msf.frame); - cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i-1].length = - cdrom->track[i].offset- - cdrom->track[i-1].offset; - } - } - } - if ( i == (cdrom->numtracks+1) ) { - okay = 1; - } - } - return(okay ? 0 : -1); + struct ioc_toc_header toc; + int i, okay; + struct ioc_read_toc_entry entry; + struct cd_toc_entry data; + + okay = 0; + if (SDL_SYS_CDioctl (cdrom->id, CDIOREADTOCHEADER, &toc) == 0) { + cdrom->numtracks = toc.ending_track - toc.starting_track + 1; + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; + } + /* Read all the track TOC entries */ + for (i = 0; i <= cdrom->numtracks; ++i) { + if (i == cdrom->numtracks) { + cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */ + } else { + cdrom->track[i].id = toc.starting_track + i; + } + entry.starting_track = cdrom->track[i].id; + entry.address_format = CD_MSF_FORMAT; + entry.data_len = sizeof (data); + entry.data = &data; + if (SDL_SYS_CDioctl (cdrom->id, CDIOREADTOCENTRYS, &entry) < 0) { + break; + } else { + cdrom->track[i].type = data.control; + cdrom->track[i].offset = + MSF_TO_FRAMES (data.addr.msf.minute, + data.addr.msf.second, data.addr.msf.frame); + cdrom->track[i].length = 0; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; + } + } + } + if (i == (cdrom->numtracks + 1)) { + okay = 1; + } + } + return (okay ? 0 : -1); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; - struct ioc_toc_header toc; - struct ioc_read_subchannel info; - struct cd_sub_channel_info data; - - info.address_format = CD_MSF_FORMAT; - info.data_format = CD_CURRENT_POSITION; - info.track = 0; - info.data_len = sizeof(data); - info.data = &data; - if ( ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0 ) { - if ( ERRNO_TRAYEMPTY(errno) ) { - status = CD_TRAYEMPTY; - } else { - status = CD_ERROR; - } - } else { - switch (data.header.audio_status) { - case CD_AS_AUDIO_INVALID: - case CD_AS_NO_STATUS: - /* Try to determine if there's a CD available */ - if (ioctl(cdrom->id,CDIOREADTOCHEADER,&toc)==0) - status = CD_STOPPED; - else - status = CD_TRAYEMPTY; - break; - case CD_AS_PLAY_COMPLETED: - status = CD_STOPPED; - break; - case CD_AS_PLAY_IN_PROGRESS: - status = CD_PLAYING; - break; - case CD_AS_PLAY_PAUSED: - status = CD_PAUSED; - break; - default: - status = CD_ERROR; - break; - } - } - if ( position ) { - if ( status == CD_PLAYING || (status == CD_PAUSED) ) { - *position = MSF_TO_FRAMES( - data.what.position.absaddr.msf.minute, - data.what.position.absaddr.msf.second, - data.what.position.absaddr.msf.frame); - } else { - *position = 0; - } - } - return(status); + CDstatus status; + struct ioc_toc_header toc; + struct ioc_read_subchannel info; + struct cd_sub_channel_info data; + + info.address_format = CD_MSF_FORMAT; + info.data_format = CD_CURRENT_POSITION; + info.track = 0; + info.data_len = sizeof (data); + info.data = &data; + if (ioctl (cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0) { + if (ERRNO_TRAYEMPTY (errno)) { + status = CD_TRAYEMPTY; + } else { + status = CD_ERROR; + } + } else { + switch (data.header.audio_status) { + case CD_AS_AUDIO_INVALID: + case CD_AS_NO_STATUS: + /* Try to determine if there's a CD available */ + if (ioctl (cdrom->id, CDIOREADTOCHEADER, &toc) == 0) + status = CD_STOPPED; + else + status = CD_TRAYEMPTY; + break; + case CD_AS_PLAY_COMPLETED: + status = CD_STOPPED; + break; + case CD_AS_PLAY_IN_PROGRESS: + status = CD_PLAYING; + break; + case CD_AS_PLAY_PAUSED: + status = CD_PAUSED; + break; + default: + status = CD_ERROR; + break; + } + } + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) { + *position = + MSF_TO_FRAMES (data.what.position.absaddr.msf.minute, + data.what.position.absaddr.msf.second, + data.what.position.absaddr.msf.frame); + } else { + *position = 0; + } + } + return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - struct ioc_play_msf playtime; + struct ioc_play_msf playtime; - FRAMES_TO_MSF(start, - &playtime.start_m, &playtime.start_s, &playtime.start_f); - FRAMES_TO_MSF(start+length, - &playtime.end_m, &playtime.end_s, &playtime.end_f); + FRAMES_TO_MSF (start, + &playtime.start_m, &playtime.start_s, &playtime.start_f); + FRAMES_TO_MSF (start + length, + &playtime.end_m, &playtime.end_s, &playtime.end_f); #ifdef DEBUG_CDROM - fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", - playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, - playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); + fprintf (stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", + playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, + playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); #endif - ioctl(cdrom->id, CDIOCSTART, 0); - return(SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime)); + ioctl (cdrom->id, CDIOCSTART, 0); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCPLAYMSF, &playtime)); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCPAUSE, 0)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCRESUME, 0)); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCSTOP, 0)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCEJECT, 0)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - close(cdrom->id); + close (cdrom->id); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - int i; - - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; + } } #endif /* SDL_CDROM_FREEBSD */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/linux/SDL_syscdrom.c b/src/cdrom/linux/SDL_syscdrom.c index 4d3e70cd0..7da3b19d6 100644 --- a/src/cdrom/linux/SDL_syscdrom.c +++ b/src/cdrom/linux/SDL_syscdrom.c @@ -25,7 +25,7 @@ /* Functions for system-level CD-ROM audio control */ -#include /* For strerror() */ +#include /* For strerror() */ #include #include #include @@ -89,23 +89,23 @@ /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 16 +#define MAX_DRIVES 16 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; static dev_t SDL_cdmode[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); /* Some ioctl() errno values which occur when the tray is empty */ #ifndef ENOMEDIUM @@ -116,449 +116,471 @@ static void SDL_SYS_CDClose(SDL_CD *cdrom); (errno == EINVAL) || (errno == ENOMEDIUM)) /* Check a drive to see if it is a CD-ROM */ -static int CheckDrive(char *drive, char *mnttype, struct stat *stbuf) +static int +CheckDrive (char *drive, char *mnttype, struct stat *stbuf) { - int is_cd, cdfd; - struct cdrom_subchnl info; - - /* If it doesn't exist, return -1 */ - if ( stat(drive, stbuf) < 0 ) { - return(-1); - } - - /* If it does exist, verify that it's an available CD-ROM */ - is_cd = 0; - if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { - cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0); - if ( cdfd >= 0 ) { - info.cdsc_format = CDROM_MSF; - /* Under Linux, EIO occurs when a disk is not present. - */ - if ( (ioctl(cdfd, CDROMSUBCHNL, &info) == 0) || - ERRNO_TRAYEMPTY(errno) ) { - is_cd = 1; - } - close(cdfd); - } + int is_cd, cdfd; + struct cdrom_subchnl info; + + /* If it doesn't exist, return -1 */ + if (stat (drive, stbuf) < 0) { + return (-1); + } + + /* If it does exist, verify that it's an available CD-ROM */ + is_cd = 0; + if (S_ISCHR (stbuf->st_mode) || S_ISBLK (stbuf->st_mode)) { + cdfd = open (drive, (O_RDONLY | O_NONBLOCK), 0); + if (cdfd >= 0) { + info.cdsc_format = CDROM_MSF; + /* Under Linux, EIO occurs when a disk is not present. + */ + if ((ioctl (cdfd, CDROMSUBCHNL, &info) == 0) || + ERRNO_TRAYEMPTY (errno)) { + is_cd = 1; + } + close (cdfd); + } #ifdef USE_MNTENT - /* Even if we can't read it, it might be mounted */ - else if ( mnttype && (SDL_strcmp(mnttype, MNTTYPE_CDROM) == 0) ) { - is_cd = 1; - } + /* Even if we can't read it, it might be mounted */ + else if (mnttype && (SDL_strcmp (mnttype, MNTTYPE_CDROM) == 0)) { + is_cd = 1; + } #endif - } - return(is_cd); + } + return (is_cd); } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive, struct stat *stbuf) +static void +AddDrive (char *drive, struct stat *stbuf) { - int i; - - if ( SDL_numcds < MAX_DRIVES ) { - /* Check to make sure it's not already in our list. - This can happen when we see a drive via symbolic link. - */ - for ( i=0; ist_rdev == SDL_cdmode[i] ) { + int i; + + if (SDL_numcds < MAX_DRIVES) { + /* Check to make sure it's not already in our list. + This can happen when we see a drive via symbolic link. + */ + for (i = 0; i < SDL_numcds; ++i) { + if (stbuf->st_rdev == SDL_cdmode[i]) { #ifdef DEBUG_CDROM - fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); + fprintf (stderr, "Duplicate drive detected: %s == %s\n", + drive, SDL_cdlist[i]); #endif - return; - } - } - - /* Add this drive to our list */ - i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - SDL_cdmode[i] = stbuf->st_rdev; - ++SDL_numcds; + return; + } + } + + /* Add this drive to our list */ + i = SDL_numcds; + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + SDL_cdmode[i] = stbuf->st_rdev; + ++SDL_numcds; #ifdef DEBUG_CDROM - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif - } + } } #ifdef USE_MNTENT -static void CheckMounts(const char *mtab) +static void +CheckMounts (const char *mtab) { - FILE *mntfp; - struct mntent *mntent; - struct stat stbuf; - - mntfp = setmntent(mtab, "r"); - if ( mntfp != NULL ) { - char *tmp; - char *mnt_type; - size_t mnt_type_len; - char *mnt_dev; - size_t mnt_dev_len; - - while ( (mntent=getmntent(mntfp)) != NULL ) { - mnt_type_len = SDL_strlen(mntent->mnt_type) + 1; - mnt_type = SDL_stack_alloc(char, mnt_type_len); - if (mnt_type == NULL) - continue; /* maybe you'll get lucky next time. */ - - mnt_dev_len = SDL_strlen(mntent->mnt_fsname) + 1; - mnt_dev = SDL_stack_alloc(char, mnt_dev_len); - if (mnt_dev == NULL) { - SDL_stack_free(mnt_type); - continue; - } - - SDL_strlcpy(mnt_type, mntent->mnt_type, mnt_type_len); - SDL_strlcpy(mnt_dev, mntent->mnt_fsname, mnt_dev_len); - - /* Handle "supermount" filesystem mounts */ - if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { - tmp = SDL_strstr(mntent->mnt_opts, "fs="); - if ( tmp ) { - SDL_free(mnt_type); - mnt_type = SDL_strdup(tmp + SDL_strlen("fs=")); - if ( mnt_type ) { - tmp = SDL_strchr(mnt_type, ','); - if ( tmp ) { - *tmp = '\0'; - } - } - } - tmp = SDL_strstr(mntent->mnt_opts, "dev="); - if ( tmp ) { - SDL_free(mnt_dev); - mnt_dev = SDL_strdup(tmp + SDL_strlen("dev=")); - if ( mnt_dev ) { - tmp = SDL_strchr(mnt_dev, ','); - if ( tmp ) { - *tmp = '\0'; - } - } - } - } - if ( SDL_strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) { + FILE *mntfp; + struct mntent *mntent; + struct stat stbuf; + + mntfp = setmntent (mtab, "r"); + if (mntfp != NULL) { + char *tmp; + char *mnt_type; + size_t mnt_type_len; + char *mnt_dev; + size_t mnt_dev_len; + + while ((mntent = getmntent (mntfp)) != NULL) { + mnt_type_len = SDL_strlen (mntent->mnt_type) + 1; + mnt_type = SDL_stack_alloc (char, mnt_type_len); + if (mnt_type == NULL) + continue; /* maybe you'll get lucky next time. */ + + mnt_dev_len = SDL_strlen (mntent->mnt_fsname) + 1; + mnt_dev = SDL_stack_alloc (char, mnt_dev_len); + if (mnt_dev == NULL) { + SDL_stack_free (mnt_type); + continue; + } + + SDL_strlcpy (mnt_type, mntent->mnt_type, mnt_type_len); + SDL_strlcpy (mnt_dev, mntent->mnt_fsname, mnt_dev_len); + + /* Handle "supermount" filesystem mounts */ + if (SDL_strcmp (mnt_type, MNTTYPE_SUPER) == 0) { + tmp = SDL_strstr (mntent->mnt_opts, "fs="); + if (tmp) { + SDL_free (mnt_type); + mnt_type = SDL_strdup (tmp + SDL_strlen ("fs=")); + if (mnt_type) { + tmp = SDL_strchr (mnt_type, ','); + if (tmp) { + *tmp = '\0'; + } + } + } + tmp = SDL_strstr (mntent->mnt_opts, "dev="); + if (tmp) { + SDL_free (mnt_dev); + mnt_dev = SDL_strdup (tmp + SDL_strlen ("dev=")); + if (mnt_dev) { + tmp = SDL_strchr (mnt_dev, ','); + if (tmp) { + *tmp = '\0'; + } + } + } + } + if (SDL_strcmp (mnt_type, MNTTYPE_CDROM) == 0) { #ifdef DEBUG_CDROM - fprintf(stderr, "Checking mount path from %s: %s mounted on %s of %s\n", - mtab, mnt_dev, mntent->mnt_dir, mnt_type); + fprintf (stderr, + "Checking mount path from %s: %s mounted on %s of %s\n", + mtab, mnt_dev, mntent->mnt_dir, mnt_type); #endif - if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { - AddDrive(mnt_dev, &stbuf); - } - } - SDL_stack_free(mnt_dev); - SDL_stack_free(mnt_type); - } - endmntent(mntfp); - } + if (CheckDrive (mnt_dev, mnt_type, &stbuf) > 0) { + AddDrive (mnt_dev, &stbuf); + } + } + SDL_stack_free (mnt_dev); + SDL_stack_free (mnt_type); + } + endmntent (mntfp); + } } #endif /* USE_MNTENT */ -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */ - static char *checklist[] = { - "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL - }; - char *SDLcdrom; - int i, j, exists; - char drive[32]; - struct stat stbuf; - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Look in the environment for our CD-ROM drive list */ - SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ - if ( SDLcdrom != NULL ) { - char *cdpath, *delim; - size_t len = SDL_strlen(SDLcdrom)+1; - cdpath = SDL_stack_alloc(char, len); - if ( cdpath != NULL ) { - SDL_strlcpy(cdpath, SDLcdrom, len); - SDLcdrom = cdpath; - do { - delim = SDL_strchr(SDLcdrom, ':'); - if ( delim ) { - *delim++ = '\0'; - } + /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */ + static char *checklist[] = { + "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL + }; + char *SDLcdrom; + int i, j, exists; + char drive[32]; + struct stat stbuf; + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Look in the environment for our CD-ROM drive list */ + SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ + if (SDLcdrom != NULL) { + char *cdpath, *delim; + size_t len = SDL_strlen (SDLcdrom) + 1; + cdpath = SDL_stack_alloc (char, len); + if (cdpath != NULL) { + SDL_strlcpy (cdpath, SDLcdrom, len); + SDLcdrom = cdpath; + do { + delim = SDL_strchr (SDLcdrom, ':'); + if (delim) { + *delim++ = '\0'; + } #ifdef DEBUG_CDROM - fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); + fprintf (stderr, + "Checking CD-ROM drive from SDL_CDROM: %s\n", + SDLcdrom); #endif - if ( CheckDrive(SDLcdrom, NULL, &stbuf) > 0 ) { - AddDrive(SDLcdrom, &stbuf); - } - if ( delim ) { - SDLcdrom = delim; - } else { - SDLcdrom = NULL; - } - } while ( SDLcdrom ); - SDL_stack_free(cdpath); - } - - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } - } - + if (CheckDrive (SDLcdrom, NULL, &stbuf) > 0) { + AddDrive (SDLcdrom, &stbuf); + } + if (delim) { + SDLcdrom = delim; + } else { + SDLcdrom = NULL; + } + } + while (SDLcdrom); + SDL_stack_free (cdpath); + } + + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } + } #ifdef USE_MNTENT - /* Check /dev/cdrom first :-) */ - if (CheckDrive("/dev/cdrom", NULL, &stbuf) > 0) { - AddDrive("/dev/cdrom", &stbuf); - } + /* Check /dev/cdrom first :-) */ + if (CheckDrive ("/dev/cdrom", NULL, &stbuf) > 0) { + AddDrive ("/dev/cdrom", &stbuf); + } - /* Now check the currently mounted CD drives */ - CheckMounts(_PATH_MOUNTED); + /* Now check the currently mounted CD drives */ + CheckMounts (_PATH_MOUNTED); - /* Finally check possible mountable drives in /etc/fstab */ - CheckMounts(_PATH_MNTTAB); + /* Finally check possible mountable drives in /etc/fstab */ + CheckMounts (_PATH_MNTTAB); - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } #endif /* USE_MNTENT */ - /* Scan the system for CD-ROM drives. - Not always 100% reliable, so use the USE_MNTENT code above first. - */ - for ( i=0; checklist[i]; ++i ) { - if ( checklist[i][0] == '?' ) { - char *insert; - exists = 1; - for ( j=checklist[i][1]; exists; ++j ) { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]); - insert = SDL_strchr(drive, '?'); - if ( insert != NULL ) { - *insert = j; - } + /* Scan the system for CD-ROM drives. + Not always 100% reliable, so use the USE_MNTENT code above first. + */ + for (i = 0; checklist[i]; ++i) { + if (checklist[i][0] == '?') { + char *insert; + exists = 1; + for (j = checklist[i][1]; exists; ++j) { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + &checklist[i][3]); + insert = SDL_strchr (drive, '?'); + if (insert != NULL) { + *insert = j; + } #ifdef DEBUG_CDROM - fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); + fprintf (stderr, "Checking possible CD-ROM drive: %s\n", + drive); #endif - switch (CheckDrive(drive, NULL, &stbuf)) { - /* Drive exists and is a CD-ROM */ - case 1: - AddDrive(drive, &stbuf); - break; - /* Drive exists, but isn't a CD-ROM */ - case 0: - break; - /* Drive doesn't exist */ - case -1: - exists = 0; - break; - } - } - } else { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); + switch (CheckDrive (drive, NULL, &stbuf)) { + /* Drive exists and is a CD-ROM */ + case 1: + AddDrive (drive, &stbuf); + break; + /* Drive exists, but isn't a CD-ROM */ + case 0: + break; + /* Drive doesn't exist */ + case -1: + exists = 0; + break; + } + } + } else { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + checklist[i]); #ifdef DEBUG_CDROM - fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); + fprintf (stderr, "Checking possible CD-ROM drive: %s\n", drive); #endif - if ( CheckDrive(drive, NULL, &stbuf) > 0 ) { - AddDrive(drive, &stbuf); - } - } - } - return(0); + if (CheckDrive (drive, NULL, &stbuf) > 0) { + AddDrive (drive, &stbuf); + } + } + } + return (0); } /* General ioctl() CD-ROM command function */ -static int SDL_SYS_CDioctl(int id, int command, void *arg) +static int +SDL_SYS_CDioctl (int id, int command, void *arg) { - int retval; + int retval; - retval = ioctl(id, command, arg); - if ( retval < 0 ) { - SDL_SetError("ioctl() error: %s", strerror(errno)); - } - return(retval); + retval = ioctl (id, command, arg); + if (retval < 0) { + SDL_SetError ("ioctl() error: %s", strerror (errno)); + } + return (retval); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - return(open(SDL_cdlist[drive], (O_RDONLY|O_NONBLOCK), 0)); + return (open (SDL_cdlist[drive], (O_RDONLY | O_NONBLOCK), 0)); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - struct cdrom_tochdr toc; - int i, okay; - struct cdrom_tocentry entry; - - okay = 0; - if ( SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc) == 0 ) { - cdrom->numtracks = toc.cdth_trk1-toc.cdth_trk0+1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { - cdrom->numtracks = SDL_MAX_TRACKS; - } - /* Read all the track TOC entries */ - for ( i=0; i<=cdrom->numtracks; ++i ) { - if ( i == cdrom->numtracks ) { - cdrom->track[i].id = CDROM_LEADOUT; - } else { - cdrom->track[i].id = toc.cdth_trk0+i; - } - entry.cdte_track = cdrom->track[i].id; - entry.cdte_format = CDROM_MSF; - if ( SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, - &entry) < 0 ) { - break; - } else { - if ( entry.cdte_ctrl & CDROM_DATA_TRACK ) { - cdrom->track[i].type = SDL_DATA_TRACK; - } else { - cdrom->track[i].type = SDL_AUDIO_TRACK; - } - cdrom->track[i].offset = MSF_TO_FRAMES( - entry.cdte_addr.msf.minute, - entry.cdte_addr.msf.second, - entry.cdte_addr.msf.frame); - cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i-1].length = - cdrom->track[i].offset- - cdrom->track[i-1].offset; - } - } - } - if ( i == (cdrom->numtracks+1) ) { - okay = 1; - } - } - return(okay ? 0 : -1); + struct cdrom_tochdr toc; + int i, okay; + struct cdrom_tocentry entry; + + okay = 0; + if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCHDR, &toc) == 0) { + cdrom->numtracks = toc.cdth_trk1 - toc.cdth_trk0 + 1; + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; + } + /* Read all the track TOC entries */ + for (i = 0; i <= cdrom->numtracks; ++i) { + if (i == cdrom->numtracks) { + cdrom->track[i].id = CDROM_LEADOUT; + } else { + cdrom->track[i].id = toc.cdth_trk0 + i; + } + entry.cdte_track = cdrom->track[i].id; + entry.cdte_format = CDROM_MSF; + if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCENTRY, &entry) < 0) { + break; + } else { + if (entry.cdte_ctrl & CDROM_DATA_TRACK) { + cdrom->track[i].type = SDL_DATA_TRACK; + } else { + cdrom->track[i].type = SDL_AUDIO_TRACK; + } + cdrom->track[i].offset = + MSF_TO_FRAMES (entry.cdte_addr.msf.minute, + entry.cdte_addr.msf.second, + entry.cdte_addr.msf.frame); + cdrom->track[i].length = 0; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; + } + } + } + if (i == (cdrom->numtracks + 1)) { + okay = 1; + } + } + return (okay ? 0 : -1); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; - struct cdrom_tochdr toc; - struct cdrom_subchnl info; - - info.cdsc_format = CDROM_MSF; - if ( ioctl(cdrom->id, CDROMSUBCHNL, &info) < 0 ) { - if ( ERRNO_TRAYEMPTY(errno) ) { - status = CD_TRAYEMPTY; - } else { - status = CD_ERROR; - } - } else { - switch (info.cdsc_audiostatus) { - case CDROM_AUDIO_INVALID: - case CDROM_AUDIO_NO_STATUS: - /* Try to determine if there's a CD available */ - if (ioctl(cdrom->id, CDROMREADTOCHDR, &toc)==0) - status = CD_STOPPED; - else - status = CD_TRAYEMPTY; - break; - case CDROM_AUDIO_COMPLETED: - status = CD_STOPPED; - break; - case CDROM_AUDIO_PLAY: - status = CD_PLAYING; - break; - case CDROM_AUDIO_PAUSED: - /* Workaround buggy CD-ROM drive */ - if ( info.cdsc_trk == CDROM_LEADOUT ) { - status = CD_STOPPED; - } else { - status = CD_PAUSED; - } - break; - default: - status = CD_ERROR; - break; - } - } - if ( position ) { - if ( status == CD_PLAYING || (status == CD_PAUSED) ) { - *position = MSF_TO_FRAMES( - info.cdsc_absaddr.msf.minute, - info.cdsc_absaddr.msf.second, - info.cdsc_absaddr.msf.frame); - } else { - *position = 0; - } - } - return(status); + CDstatus status; + struct cdrom_tochdr toc; + struct cdrom_subchnl info; + + info.cdsc_format = CDROM_MSF; + if (ioctl (cdrom->id, CDROMSUBCHNL, &info) < 0) { + if (ERRNO_TRAYEMPTY (errno)) { + status = CD_TRAYEMPTY; + } else { + status = CD_ERROR; + } + } else { + switch (info.cdsc_audiostatus) { + case CDROM_AUDIO_INVALID: + case CDROM_AUDIO_NO_STATUS: + /* Try to determine if there's a CD available */ + if (ioctl (cdrom->id, CDROMREADTOCHDR, &toc) == 0) + status = CD_STOPPED; + else + status = CD_TRAYEMPTY; + break; + case CDROM_AUDIO_COMPLETED: + status = CD_STOPPED; + break; + case CDROM_AUDIO_PLAY: + status = CD_PLAYING; + break; + case CDROM_AUDIO_PAUSED: + /* Workaround buggy CD-ROM drive */ + if (info.cdsc_trk == CDROM_LEADOUT) { + status = CD_STOPPED; + } else { + status = CD_PAUSED; + } + break; + default: + status = CD_ERROR; + break; + } + } + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) { + *position = MSF_TO_FRAMES (info.cdsc_absaddr.msf.minute, + info.cdsc_absaddr.msf.second, + info.cdsc_absaddr.msf.frame); + } else { + *position = 0; + } + } + return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - struct cdrom_msf playtime; + struct cdrom_msf playtime; - FRAMES_TO_MSF(start, - &playtime.cdmsf_min0, &playtime.cdmsf_sec0, &playtime.cdmsf_frame0); - FRAMES_TO_MSF(start+length, - &playtime.cdmsf_min1, &playtime.cdmsf_sec1, &playtime.cdmsf_frame1); + FRAMES_TO_MSF (start, + &playtime.cdmsf_min0, &playtime.cdmsf_sec0, + &playtime.cdmsf_frame0); + FRAMES_TO_MSF (start + length, &playtime.cdmsf_min1, &playtime.cdmsf_sec1, + &playtime.cdmsf_frame1); #ifdef DEBUG_CDROM - fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", - playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, - playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); + fprintf (stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", + playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, + playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); #endif - return(SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime)); + return (SDL_SYS_CDioctl (cdrom->id, CDROMPLAYMSF, &playtime)); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDROMPAUSE, 0)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDROMRESUME, 0)); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDROMSTOP, 0)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDROMEJECT, 0)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - close(cdrom->id); + close (cdrom->id); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - int i; - - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; + } } #endif /* SDL_CDROM_LINUX */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macos/SDL_syscdrom.c b/src/cdrom/macos/SDL_syscdrom.c index bbe69e957..6407d2562 100644 --- a/src/cdrom/macos/SDL_syscdrom.c +++ b/src/cdrom/macos/SDL_syscdrom.c @@ -27,7 +27,7 @@ #include #include -#include /* Use entry table macros, not functions in InterfaceLib */ +#include /* Use entry table macros, not functions in InterfaceLib */ #include "SDL_cdrom.h" #include "../SDL_syscdrom.h" @@ -35,491 +35,509 @@ /* Added by Matt Slot */ #if !defined(LMGetUnitTableEntryCount) - #define LMGetUnitTableEntryCount() *(short *)0x01D2 +#define LMGetUnitTableEntryCount() *(short *)0x01D2 #endif /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 26 +#define MAX_DRIVES 26 /* A list of available CD-ROM drives */ static long SDL_cdversion = 0; -static struct { - short dRefNum; - short driveNum; - long frames; - char name[256]; - Boolean hasAudio; - } SDL_cdlist[MAX_DRIVES]; +static struct +{ + short dRefNum; + short driveNum; + long frames; + char name[256]; + Boolean hasAudio; +} SDL_cdlist[MAX_DRIVES]; static StringPtr gDriverName = "\p.AppleCD"; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); - -static short SDL_SYS_ShortToBCD(short value) +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); + +static short +SDL_SYS_ShortToBCD (short value) { - return((value % 10) + (value / 10) * 0x10); /* Convert value to BCD */ + return ((value % 10) + (value / 10) * 0x10); /* Convert value to BCD */ } -static short SDL_SYS_BCDToShort(short value) +static short +SDL_SYS_BCDToShort (short value) { - return((value % 0x10) + (value / 0x10) * 10); /* Convert value from BCD */ + return ((value % 0x10) + (value / 0x10) * 10); /* Convert value from BCD */ } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - SInt16 dRefNum = 0; - SInt16 first, last; - - SDL_numcds = 0; - - /* Check that the software is available */ - if (Gestalt(kGestaltAudioCDSelector, &SDL_cdversion) || - !SDL_cdversion) return(0); - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Walk the list, count each AudioCD driver, and save the refnums */ - first = -1; - last = 0 - LMGetUnitTableEntryCount(); - for(dRefNum = first; dRefNum >= last; dRefNum--) { - Str255 driverName; - StringPtr namePtr; - DCtlHandle deviceEntry; - - deviceEntry = GetDCtlEntry(dRefNum); - if (! deviceEntry) continue; - - /* Is this an .AppleCD ? */ - namePtr = (*deviceEntry)->dCtlFlags & (1L << dRAMBased) ? - ((StringPtr) ((DCtlPtr) deviceEntry)->dCtlDriver + 18) : - ((StringPtr) (*deviceEntry)->dCtlDriver + 18); - BlockMoveData(namePtr, driverName, namePtr[0]+1); - if (driverName[0] > gDriverName[0]) driverName[0] = gDriverName[0]; - if (! EqualString(driverName, gDriverName, false, false)) continue; - - /* Record the basic info for each drive */ - SDL_cdlist[SDL_numcds].dRefNum = dRefNum; - BlockMoveData(namePtr + 1, SDL_cdlist[SDL_numcds].name, namePtr[0]); - SDL_cdlist[SDL_numcds].name[namePtr[0]] = 0; - SDL_cdlist[SDL_numcds].hasAudio = false; - SDL_numcds++; - } - return(0); + SInt16 dRefNum = 0; + SInt16 first, last; + + SDL_numcds = 0; + + /* Check that the software is available */ + if (Gestalt (kGestaltAudioCDSelector, &SDL_cdversion) || !SDL_cdversion) + return (0); + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Walk the list, count each AudioCD driver, and save the refnums */ + first = -1; + last = 0 - LMGetUnitTableEntryCount (); + for (dRefNum = first; dRefNum >= last; dRefNum--) { + Str255 driverName; + StringPtr namePtr; + DCtlHandle deviceEntry; + + deviceEntry = GetDCtlEntry (dRefNum); + if (!deviceEntry) + continue; + + /* Is this an .AppleCD ? */ + namePtr = (*deviceEntry)->dCtlFlags & (1L << dRAMBased) ? + ((StringPtr) ((DCtlPtr) deviceEntry)->dCtlDriver + 18) : + ((StringPtr) (*deviceEntry)->dCtlDriver + 18); + BlockMoveData (namePtr, driverName, namePtr[0] + 1); + if (driverName[0] > gDriverName[0]) + driverName[0] = gDriverName[0]; + if (!EqualString (driverName, gDriverName, false, false)) + continue; + + /* Record the basic info for each drive */ + SDL_cdlist[SDL_numcds].dRefNum = dRefNum; + BlockMoveData (namePtr + 1, SDL_cdlist[SDL_numcds].name, namePtr[0]); + SDL_cdlist[SDL_numcds].name[namePtr[0]] = 0; + SDL_cdlist[SDL_numcds].hasAudio = false; + SDL_numcds++; + } + return (0); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive].name); + return (SDL_cdlist[drive].name); } -static int get_drivenum(int drive) +static int +get_drivenum (int drive) { - QHdr *driveQ = GetDrvQHdr(); - DrvQEl *driveElem; - - /* Update the drive number */ - SDL_cdlist[drive].driveNum = 0; - if ( driveQ->qTail ) { - driveQ->qTail->qLink = 0; - } - for ( driveElem=(DrvQEl *)driveQ->qHead; driveElem; - driveElem = (DrvQEl *)driveElem->qLink ) { - if ( driveElem->dQRefNum == SDL_cdlist[drive].dRefNum ) { - SDL_cdlist[drive].driveNum = driveElem->dQDrive; - break; - } - } - return(SDL_cdlist[drive].driveNum); + QHdr *driveQ = GetDrvQHdr (); + DrvQEl *driveElem; + + /* Update the drive number */ + SDL_cdlist[drive].driveNum = 0; + if (driveQ->qTail) { + driveQ->qTail->qLink = 0; + } + for (driveElem = (DrvQEl *) driveQ->qHead; driveElem; + driveElem = (DrvQEl *) driveElem->qLink) { + if (driveElem->dQRefNum == SDL_cdlist[drive].dRefNum) { + SDL_cdlist[drive].driveNum = driveElem->dQDrive; + break; + } + } + return (SDL_cdlist[drive].driveNum); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - return(drive); + return (drive); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - CDCntrlParam cdpb; - CDTrackData tracks[SDL_MAX_TRACKS]; - long i, leadout; - - /* Get the number of tracks on the CD by examining the TOC */ - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kReadTOC; - cdpb.csParam.words[0] = kGetTrackRange; - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - - cdrom->numtracks = - SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - - SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) - cdrom->numtracks = SDL_MAX_TRACKS; - cdrom->status = CD_STOPPED; - cdrom->cur_track = 0; /* Apparently these are set elsewhere */ - cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ - - - /* Get the lead out area of the CD by examining the TOC */ - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kReadTOC; - cdpb.csParam.words[0] = kGetLeadOutArea; - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - - leadout = MSF_TO_FRAMES( - SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]), - SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]), - SDL_SYS_BCDToShort(cdpb.csParam.bytes[2])); - - /* Get an array of track locations by examining the TOC */ - SDL_memset(tracks, 0, sizeof(tracks)); - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kReadTOC; - cdpb.csParam.words[0] = kGetTrackEntries; /* Type of Query */ - * ((long *) (cdpb.csParam.words+1)) = (long) tracks; - cdpb.csParam.words[3] = cdrom->numtracks * sizeof(tracks[0]); - * ((char *) (cdpb.csParam.words+4)) = 1; /* First track */ - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - - /* Read all the track TOC entries */ - SDL_cdlist[cdrom->id].hasAudio = false; - for ( i=0; inumtracks; ++i ) - { - cdrom->track[i].id = i+1; - if (tracks[i].entry.control & kDataTrackMask) - cdrom->track[i].type = SDL_DATA_TRACK; - else - { - cdrom->track[i].type = SDL_AUDIO_TRACK; - SDL_cdlist[SDL_numcds].hasAudio = true; - } - - cdrom->track[i].offset = MSF_TO_FRAMES( - SDL_SYS_BCDToShort(tracks[i].entry.min), - SDL_SYS_BCDToShort(tracks[i].entry.min), - SDL_SYS_BCDToShort(tracks[i].entry.frame)); - cdrom->track[i].length = MSF_TO_FRAMES( - SDL_SYS_BCDToShort(tracks[i+1].entry.min), - SDL_SYS_BCDToShort(tracks[i+1].entry.min), - SDL_SYS_BCDToShort(tracks[i+1].entry.frame)) - - cdrom->track[i].offset; - } - - /* Apparently SDL wants a fake last entry */ - cdrom->track[i].offset = leadout; - cdrom->track[i].length = 0; - - return(0); + CDCntrlParam cdpb; + CDTrackData tracks[SDL_MAX_TRACKS]; + long i, leadout; + + /* Get the number of tracks on the CD by examining the TOC */ + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kReadTOC; + cdpb.csParam.words[0] = kGetTrackRange; + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + + cdrom->numtracks = + SDL_SYS_BCDToShort (cdpb.csParam.bytes[1]) - + SDL_SYS_BCDToShort (cdpb.csParam.bytes[0]) + 1; + if (cdrom->numtracks > SDL_MAX_TRACKS) + cdrom->numtracks = SDL_MAX_TRACKS; + cdrom->status = CD_STOPPED; + cdrom->cur_track = 0; /* Apparently these are set elsewhere */ + cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ + + + /* Get the lead out area of the CD by examining the TOC */ + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kReadTOC; + cdpb.csParam.words[0] = kGetLeadOutArea; + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + + leadout = MSF_TO_FRAMES (SDL_SYS_BCDToShort (cdpb.csParam.bytes[0]), + SDL_SYS_BCDToShort (cdpb.csParam.bytes[1]), + SDL_SYS_BCDToShort (cdpb.csParam.bytes[2])); + + /* Get an array of track locations by examining the TOC */ + SDL_memset (tracks, 0, sizeof (tracks)); + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kReadTOC; + cdpb.csParam.words[0] = kGetTrackEntries; /* Type of Query */ + *((long *) (cdpb.csParam.words + 1)) = (long) tracks; + cdpb.csParam.words[3] = cdrom->numtracks * sizeof (tracks[0]); + *((char *) (cdpb.csParam.words + 4)) = 1; /* First track */ + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + + /* Read all the track TOC entries */ + SDL_cdlist[cdrom->id].hasAudio = false; + for (i = 0; i < cdrom->numtracks; ++i) { + cdrom->track[i].id = i + 1; + if (tracks[i].entry.control & kDataTrackMask) + cdrom->track[i].type = SDL_DATA_TRACK; + else { + cdrom->track[i].type = SDL_AUDIO_TRACK; + SDL_cdlist[SDL_numcds].hasAudio = true; + } + + cdrom->track[i].offset = + MSF_TO_FRAMES (SDL_SYS_BCDToShort (tracks[i].entry.min), + SDL_SYS_BCDToShort (tracks[i].entry.min), + SDL_SYS_BCDToShort (tracks[i].entry.frame)); + cdrom->track[i].length = + MSF_TO_FRAMES (SDL_SYS_BCDToShort (tracks[i + 1].entry.min), + SDL_SYS_BCDToShort (tracks[i + 1].entry.min), + SDL_SYS_BCDToShort (tracks[i + 1].entry.frame)) - + cdrom->track[i].offset; + } + + /* Apparently SDL wants a fake last entry */ + cdrom->track[i].offset = leadout; + cdrom->track[i].length = 0; + + return (0); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDCntrlParam cdpb; - CDstatus status = CD_ERROR; - Boolean spinning = false; - - if (position) *position = 0; - - /* Get the number of tracks on the CD by examining the TOC */ - if ( ! get_drivenum(cdrom->id) ) { - return(CD_TRAYEMPTY); - } - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kReadTOC; - cdpb.csParam.words[0] = kGetTrackRange; - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(CD_ERROR); - } - - cdrom->numtracks = - SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - - SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) - cdrom->numtracks = SDL_MAX_TRACKS; - cdrom->cur_track = 0; /* Apparently these are set elsewhere */ - cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ - - - if (1 || SDL_cdlist[cdrom->id].hasAudio) { - /* Get the current playback status */ - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioStatus; - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - - switch(cdpb.csParam.cd.status) { - case kStatusPlaying: - status = CD_PLAYING; - spinning = true; - break; - case kStatusPaused: - status = CD_PAUSED; - spinning = true; - break; - case kStatusMuted: - status = CD_PLAYING; /* What should I do here? */ - spinning = true; - break; - case kStatusDone: - status = CD_STOPPED; - spinning = true; - break; - case kStatusStopped: - status = CD_STOPPED; - spinning = false; - break; - case kStatusError: - default: - status = CD_ERROR; - spinning = false; - break; - } - - if (spinning && position) *position = MSF_TO_FRAMES( - SDL_SYS_BCDToShort(cdpb.csParam.cd.minute), - SDL_SYS_BCDToShort(cdpb.csParam.cd.second), - SDL_SYS_BCDToShort(cdpb.csParam.cd.frame)); - } - else - status = CD_ERROR; /* What should I do here? */ - - return(status); + CDCntrlParam cdpb; + CDstatus status = CD_ERROR; + Boolean spinning = false; + + if (position) + *position = 0; + + /* Get the number of tracks on the CD by examining the TOC */ + if (!get_drivenum (cdrom->id)) { + return (CD_TRAYEMPTY); + } + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kReadTOC; + cdpb.csParam.words[0] = kGetTrackRange; + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (CD_ERROR); + } + + cdrom->numtracks = + SDL_SYS_BCDToShort (cdpb.csParam.bytes[1]) - + SDL_SYS_BCDToShort (cdpb.csParam.bytes[0]) + 1; + if (cdrom->numtracks > SDL_MAX_TRACKS) + cdrom->numtracks = SDL_MAX_TRACKS; + cdrom->cur_track = 0; /* Apparently these are set elsewhere */ + cdrom->cur_frame = 0; /* Apparently these are set elsewhere */ + + + if (1 || SDL_cdlist[cdrom->id].hasAudio) { + /* Get the current playback status */ + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioStatus; + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + + switch (cdpb.csParam.cd.status) { + case kStatusPlaying: + status = CD_PLAYING; + spinning = true; + break; + case kStatusPaused: + status = CD_PAUSED; + spinning = true; + break; + case kStatusMuted: + status = CD_PLAYING; /* What should I do here? */ + spinning = true; + break; + case kStatusDone: + status = CD_STOPPED; + spinning = true; + break; + case kStatusStopped: + status = CD_STOPPED; + spinning = false; + break; + case kStatusError: + default: + status = CD_ERROR; + spinning = false; + break; + } + + if (spinning && position) + *position = + MSF_TO_FRAMES (SDL_SYS_BCDToShort (cdpb.csParam.cd.minute), + SDL_SYS_BCDToShort (cdpb.csParam.cd.second), + SDL_SYS_BCDToShort (cdpb.csParam.cd.frame)); + } else + status = CD_ERROR; /* What should I do here? */ + + return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - CDCntrlParam cdpb; - - /* Pause the current audio playback to avoid audible artifacts */ - if ( SDL_SYS_CDPause(cdrom) < 0 ) { - return(-1); - } - - /* Specify the AudioCD playback mode */ - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kSetPlayMode; - cdpb.csParam.bytes[0] = false; /* Repeat? */ - cdpb.csParam.bytes[1] = kPlayModeSequential; /* Play mode */ - /* ¥¥¥ÊTreat as soft error, NEC Drive doesnt support this call ¥¥¥ */ - PBControlSync((ParmBlkPtr) &cdpb); + CDCntrlParam cdpb; + + /* Pause the current audio playback to avoid audible artifacts */ + if (SDL_SYS_CDPause (cdrom) < 0) { + return (-1); + } + + /* Specify the AudioCD playback mode */ + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kSetPlayMode; + cdpb.csParam.bytes[0] = false; /* Repeat? */ + cdpb.csParam.bytes[1] = kPlayModeSequential; /* Play mode */ + /* ¥¥¥ÊTreat as soft error, NEC Drive doesnt support this call ¥¥¥ */ + PBControlSync ((ParmBlkPtr) & cdpb); #if 1 - /* Specify the end of audio playback */ - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioStop; - cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ - *(long *) (cdpb.csParam.words + 1) = start+length-1; /* Search Address */ - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - - /* Specify the start of audio playback, and start it */ - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioPlay; - cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ - *(long *) (cdpb.csParam.words + 1) = start+1; /* Search Address */ - cdpb.csParam.words[3] = false; /* Stop address? */ - cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } + /* Specify the end of audio playback */ + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioStop; + cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ + *(long *) (cdpb.csParam.words + 1) = start + length - 1; /* Search Address */ + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + + /* Specify the start of audio playback, and start it */ + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioPlay; + cdpb.csParam.words[0] = kBlockPosition; /* Position Mode */ + *(long *) (cdpb.csParam.words + 1) = start + 1; /* Search Address */ + cdpb.csParam.words[3] = false; /* Stop address? */ + cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } #else - /* Specify the end of audio playback */ - FRAMES_TO_MSF(start+length, &m, &s, &f); - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioStop; - cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ - cdpb.csParam.words[1] = 0; /* Search Address (hiword)*/ - cdpb.csParam.words[2] = /* Search Address (loword)*/ - SDL_SYS_ShortToBCD(cdrom->numtracks); - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - - /* Specify the start of audio playback, and start it */ - FRAMES_TO_MSF(start, &m, &s, &f); - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioPlay; - cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ - cdpb.csParam.words[1] = 0; /* Search Address (hiword)*/ - cdpb.csParam.words[2] = SDL_SYS_ShortToBCD(1); /* Search Address (loword)*/ - cdpb.csParam.words[3] = false; /* Stop address? */ - cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } + /* Specify the end of audio playback */ + FRAMES_TO_MSF (start + length, &m, &s, &f); + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioStop; + cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ + cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ + cdpb.csParam.words[2] = /* Search Address (loword) */ + SDL_SYS_ShortToBCD (cdrom->numtracks); + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + + /* Specify the start of audio playback, and start it */ + FRAMES_TO_MSF (start, &m, &s, &f); + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioPlay; + cdpb.csParam.words[0] = kTrackPosition; /* Position Mode */ + cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ + cdpb.csParam.words[2] = SDL_SYS_ShortToBCD (1); /* Search Address (loword) */ + cdpb.csParam.words[3] = false; /* Stop address? */ + cdpb.csParam.words[4] = kStereoPlayMode; /* Audio Play Mode */ + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } #endif - return(0); + return (0); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - CDCntrlParam cdpb; - - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioPause; - cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ - cdpb.csParam.words[1] = 1; /* Pause/Continue Flag (loword) */ - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - return(0); + CDCntrlParam cdpb; + + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioPause; + cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ + cdpb.csParam.words[1] = 1; /* Pause/Continue Flag (loword) */ + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + return (0); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - CDCntrlParam cdpb; - - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioPause; - cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ - cdpb.csParam.words[1] = 0; /* Pause/Continue Flag (loword) */ - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - return(0); + CDCntrlParam cdpb; + + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioPause; + cdpb.csParam.words[0] = 0; /* Pause/Continue Flag (hiword) */ + cdpb.csParam.words[1] = 0; /* Pause/Continue Flag (loword) */ + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + return (0); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - CDCntrlParam cdpb; - - SDL_memset(&cdpb, 0, sizeof(cdpb)); - cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; - cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cdpb.csCode = kAudioStop; - cdpb.csParam.words[0] = 0; /* Position Mode */ - cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ - cdpb.csParam.words[2] = 0; /* Search Address (loword) */ - if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - return(0); + CDCntrlParam cdpb; + + SDL_memset (&cdpb, 0, sizeof (cdpb)); + cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; + cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cdpb.csCode = kAudioStop; + cdpb.csParam.words[0] = 0; /* Position Mode */ + cdpb.csParam.words[1] = 0; /* Search Address (hiword) */ + cdpb.csParam.words[2] = 0; /* Search Address (loword) */ + if (PBControlSync ((ParmBlkPtr) & cdpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + return (0); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - Boolean disk = false; - QHdr *driveQ = GetDrvQHdr(); - DrvQEl *driveElem; - HParamBlockRec hpb; - ParamBlockRec cpb; - - for ( driveElem = (DrvQEl *) driveQ->qHead; driveElem; driveElem = - (driveElem) ? ((DrvQEl *) driveElem->qLink) : - ((DrvQEl *) driveQ->qHead) ) { - if ( driveQ->qTail ) { - driveQ->qTail->qLink = 0; - } - if ( driveElem->dQRefNum != SDL_cdlist[cdrom->id].dRefNum ) { - continue; - } - - /* Does drive contain mounted volume? If not, skip */ - SDL_memset(&hpb, 0, sizeof(hpb)); - hpb.volumeParam.ioVRefNum = driveElem->dQDrive; - if ( PBHGetVInfoSync(&hpb) != noErr ) { - continue; - } - if ( (UnmountVol(0, driveElem->dQDrive) == noErr) && - (Eject(0, driveElem->dQDrive) == noErr) ) { - driveElem = 0; /* Clear pointer to reset our loop */ - disk = true; - } - } - - /* If no disk is present, just eject the tray */ - if (! disk) { - SDL_memset(&cpb, 0, sizeof(cpb)); - cpb.cntrlParam.ioVRefNum = 0; /* No Drive */ - cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; - cpb.cntrlParam.csCode = kEjectTheDisc; - if ( PBControlSync((ParmBlkPtr)&cpb) != noErr ) { - SDL_SetError("PBControlSync() failed"); - return(-1); - } - } - return(0); + Boolean disk = false; + QHdr *driveQ = GetDrvQHdr (); + DrvQEl *driveElem; + HParamBlockRec hpb; + ParamBlockRec cpb; + + for (driveElem = (DrvQEl *) driveQ->qHead; driveElem; driveElem = + (driveElem) ? ((DrvQEl *) driveElem->qLink) : + ((DrvQEl *) driveQ->qHead)) { + if (driveQ->qTail) { + driveQ->qTail->qLink = 0; + } + if (driveElem->dQRefNum != SDL_cdlist[cdrom->id].dRefNum) { + continue; + } + + /* Does drive contain mounted volume? If not, skip */ + SDL_memset (&hpb, 0, sizeof (hpb)); + hpb.volumeParam.ioVRefNum = driveElem->dQDrive; + if (PBHGetVInfoSync (&hpb) != noErr) { + continue; + } + if ((UnmountVol (0, driveElem->dQDrive) == noErr) && + (Eject (0, driveElem->dQDrive) == noErr)) { + driveElem = 0; /* Clear pointer to reset our loop */ + disk = true; + } + } + + /* If no disk is present, just eject the tray */ + if (!disk) { + SDL_memset (&cpb, 0, sizeof (cpb)); + cpb.cntrlParam.ioVRefNum = 0; /* No Drive */ + cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; + cpb.cntrlParam.csCode = kEjectTheDisc; + if (PBControlSync ((ParmBlkPtr) & cpb) != noErr) { + SDL_SetError ("PBControlSync() failed"); + return (-1); + } + } + return (0); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - return; + return; } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - while(SDL_numcds--) - SDL_memset(SDL_cdlist + SDL_numcds, 0, sizeof(SDL_cdlist[0])); + while (SDL_numcds--) + SDL_memset (SDL_cdlist + SDL_numcds, 0, sizeof (SDL_cdlist[0])); } #endif /* SDL_CDROM_MACOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macos/SDL_syscdrom_c.h b/src/cdrom/macos/SDL_syscdrom_c.h index 835826e27..07ea54d80 100644 --- a/src/cdrom/macos/SDL_syscdrom_c.h +++ b/src/cdrom/macos/SDL_syscdrom_c.h @@ -26,55 +26,55 @@ */ /* AppleCD Control calls */ -#define kVerifyTheDisc 5 /* Returns noErr if there is disc inserted */ -#define kEjectTheDisc 7 /* Eject disc from drive */ -#define kUserEject 80 /* Enable/disable the CD-ROM eject button */ -#define kReadTOC 100 /* Extract various TOC information from the disc */ -#define kReadQ 101 /* Extract Q subcode info for the current track */ -#define kAudioTrackSearch 103 /* Start playback from the indicated position */ -#define kAudioPlay 104 /* Start playback from the indicated position */ -#define kAudioPause 105 /* Pause/continue the playback */ -#define kAudioStop 106 /* Stop playback at the indicated position */ -#define kAudioStatus 107 /* Return audio play status */ -#define kAudioControl 109 /* Set the output volume for the audio channels */ -#define kReadAudioVolume 112 /* Get the output volume for the audio channels */ -#define kSetTrackList 122 /* Set the track program for the audio CD to play */ -#define kGetTrackList 123 /* Get the track program the audio CD is playing */ -#define kGetTrackIndex 124 /* Get the track index the audio CD is playing */ -#define kSetPlayMode 125 /* Set the audio tracks play mode */ -#define kGetPlayMode 126 /* Get the audio tracks play mode */ +#define kVerifyTheDisc 5 /* Returns noErr if there is disc inserted */ +#define kEjectTheDisc 7 /* Eject disc from drive */ +#define kUserEject 80 /* Enable/disable the CD-ROM eject button */ +#define kReadTOC 100 /* Extract various TOC information from the disc */ +#define kReadQ 101 /* Extract Q subcode info for the current track */ +#define kAudioTrackSearch 103 /* Start playback from the indicated position */ +#define kAudioPlay 104 /* Start playback from the indicated position */ +#define kAudioPause 105 /* Pause/continue the playback */ +#define kAudioStop 106 /* Stop playback at the indicated position */ +#define kAudioStatus 107 /* Return audio play status */ +#define kAudioControl 109 /* Set the output volume for the audio channels */ +#define kReadAudioVolume 112 /* Get the output volume for the audio channels */ +#define kSetTrackList 122 /* Set the track program for the audio CD to play */ +#define kGetTrackList 123 /* Get the track program the audio CD is playing */ +#define kGetTrackIndex 124 /* Get the track index the audio CD is playing */ +#define kSetPlayMode 125 /* Set the audio tracks play mode */ +#define kGetPlayMode 126 /* Get the audio tracks play mode */ /* AppleCD Status calls */ -#define kGetDriveType 96 /* Get the type of the physical CD-ROM drive */ -#define kWhoIsThere 97 /* Get a bitmap of SCSI IDs the driver controls */ -#define kGetBlockSize 98 /* Get current block size of the CD-ROM drive */ - +#define kGetDriveType 96 /* Get the type of the physical CD-ROM drive */ +#define kWhoIsThere 97 /* Get a bitmap of SCSI IDs the driver controls */ +#define kGetBlockSize 98 /* Get current block size of the CD-ROM drive */ + /* AppleCD other constants */ -#define kBlockPosition 0 /* Position at the specified logical block number */ -#define kAbsMSFPosition 1 /* Position at the specified Min/Sec/Frame (in BCD) */ -#define kTrackPosition 2 /* Position at the specified track number (in BCD) */ -#define kIndexPosition 3 /* Position at the nth track in program (in BCD) */ +#define kBlockPosition 0 /* Position at the specified logical block number */ +#define kAbsMSFPosition 1 /* Position at the specified Min/Sec/Frame (in BCD) */ +#define kTrackPosition 2 /* Position at the specified track number (in BCD) */ +#define kIndexPosition 3 /* Position at the nth track in program (in BCD) */ -#define kMutedPlayMode 0 /* Play the audio track with no output */ -#define kStereoPlayMode 9 /* Play the audio track in normal stereo */ +#define kMutedPlayMode 0 /* Play the audio track with no output */ +#define kStereoPlayMode 9 /* Play the audio track in normal stereo */ -#define kControlFieldMask 0x0D /* Bits 3,2,0 in the nibble */ -#define kDataTrackMask 0x04 /* Indicates Data Track */ +#define kControlFieldMask 0x0D /* Bits 3,2,0 in the nibble */ +#define kDataTrackMask 0x04 /* Indicates Data Track */ -#define kGetTrackRange 1 /* Query TOC for track numbers */ -#define kGetLeadOutArea 2 /* Query TOC for "Lead Out" end of audio data */ -#define kGetTrackEntries 3 /* Query TOC for track starts and data types */ +#define kGetTrackRange 1 /* Query TOC for track numbers */ +#define kGetLeadOutArea 2 /* Query TOC for "Lead Out" end of audio data */ +#define kGetTrackEntries 3 /* Query TOC for track starts and data types */ -#define kStatusPlaying 0 /* Audio Play operation in progress */ -#define kStatusPaused 1 /* CD-ROM device in Hold Track ("Pause") state */ -#define kStatusMuted 2 /* MUTING-ON operation in progress */ -#define kStatusDone 3 /* Audio Play completed */ -#define kStatusError 4 /* Error occurred during audio play operation */ -#define kStatusStopped 5 /* Audio play operation not requested */ +#define kStatusPlaying 0 /* Audio Play operation in progress */ +#define kStatusPaused 1 /* CD-ROM device in Hold Track ("Pause") state */ +#define kStatusMuted 2 /* MUTING-ON operation in progress */ +#define kStatusDone 3 /* Audio Play completed */ +#define kStatusError 4 /* Error occurred during audio play operation */ +#define kStatusStopped 5 /* Audio play operation not requested */ -#define kPlayModeSequential 0 /* Play tracks in order */ -#define kPlayModeShuffled 1 /* Play tracks randomly */ -#define kPlayModeProgrammed 2 /* Use custom playlist */ +#define kPlayModeSequential 0 /* Play tracks in order */ +#define kPlayModeShuffled 1 /* Play tracks randomly */ +#define kPlayModeProgrammed 2 /* Use custom playlist */ /* AppleCD Gestalt selectors */ #define kGestaltAudioCDSelector 'aucd' @@ -92,49 +92,55 @@ #define kLastSCSIDevice -40 #if PRAGMA_STRUCT_ALIGN - #pragma options align=mac68k +#pragma options align=mac68k #endif /* AppleCD driver parameter block */ -typedef struct CDCntrlParam { - QElemPtr qLink; - short qType; - short ioTrap; - Ptr ioCmdAddr; - IOCompletionUPP ioCompletion; - OSErr ioResult; - StringPtr ioNamePtr; - short ioVRefNum; - short ioCRefNum; - short csCode; - - union { - long longs[6]; - short words[11]; - unsigned char bytes[22]; - struct { - unsigned char status; - unsigned char play; - unsigned char control; - unsigned char minute; - unsigned char second; - unsigned char frame; - } cd; - } csParam; - - } CDCntrlParam, *CDCntrlParamPtr; - -typedef union CDTrackData { - long value; /* Treat as a longword value */ - struct { - unsigned char reserved : 4; /* Unused by AppleCD driver */ - unsigned char control : 4; /* Track flags (data track?) */ - unsigned char min; /* Start of track (BCD) */ - unsigned char sec; /* Start of track (BCD) */ - unsigned char frame; /* Start of track (BCD) */ - } entry; /* Broken into fields */ - } CDTrackData, *CDTrackPtr; - +typedef struct CDCntrlParam +{ + QElemPtr qLink; + short qType; + short ioTrap; + Ptr ioCmdAddr; + IOCompletionUPP ioCompletion; + OSErr ioResult; + StringPtr ioNamePtr; + short ioVRefNum; + short ioCRefNum; + short csCode; + + union + { + long longs[6]; + short words[11]; + unsigned char bytes[22]; + struct + { + unsigned char status; + unsigned char play; + unsigned char control; + unsigned char minute; + unsigned char second; + unsigned char frame; + } cd; + } csParam; + +} CDCntrlParam, *CDCntrlParamPtr; + +typedef union CDTrackData +{ + long value; /* Treat as a longword value */ + struct + { + unsigned char reserved:4; /* Unused by AppleCD driver */ + unsigned char control:4; /* Track flags (data track?) */ + unsigned char min; /* Start of track (BCD) */ + unsigned char sec; /* Start of track (BCD) */ + unsigned char frame; /* Start of track (BCD) */ + } entry; /* Broken into fields */ +} CDTrackData, *CDTrackPtr; + #if PRAGMA_STRUCT_ALIGN - #pragma options align=reset +#pragma options align=reset #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/AudioFilePlayer.c b/src/cdrom/macosx/AudioFilePlayer.c index 333eb0c1c..719750c4e 100644 --- a/src/cdrom/macosx/AudioFilePlayer.c +++ b/src/cdrom/macosx/AudioFilePlayer.c @@ -38,16 +38,17 @@ void ThrowResult (OSStatus result, const char* str) */ #if DEBUG -static void PrintStreamDesc (AudioStreamBasicDescription *inDesc) +static void +PrintStreamDesc (AudioStreamBasicDescription * inDesc) { if (!inDesc) { printf ("Can't print a NULL desc!\n"); return; } - + printf ("- - - - - - - - - - - - - - - - - - - -\n"); printf (" Sample Rate:%f\n", inDesc->mSampleRate); - printf (" Format ID:%s\n", (char*)&inDesc->mFormatID); + printf (" Format ID:%s\n", (char *) &inDesc->mFormatID); printf (" Format Flags:%lX\n", inDesc->mFormatFlags); printf (" Bytes per Packet:%ld\n", inDesc->mBytesPerPacket); printf (" Frames per Packet:%ld\n", inDesc->mFramesPerPacket); @@ -59,68 +60,78 @@ static void PrintStreamDesc (AudioStreamBasicDescription *inDesc) #endif -static int AudioFilePlayer_SetDestination (AudioFilePlayer *afp, AudioUnit *inDestUnit) +static int +AudioFilePlayer_SetDestination (AudioFilePlayer * afp, AudioUnit * inDestUnit) { - /*if (afp->mConnected) throw static_cast(-1);*/ /* can't set dest if already engaged */ + /*if (afp->mConnected) throw static_cast(-1); *//* can't set dest if already engaged */ if (afp->mConnected) - return 0 ; + return 0; - SDL_memcpy(&afp->mPlayUnit, inDestUnit, sizeof (afp->mPlayUnit)); + SDL_memcpy (&afp->mPlayUnit, inDestUnit, sizeof (afp->mPlayUnit)); OSStatus result = noErr; - - /* we can "down" cast a component instance to a component */ + + /* we can "down" cast a component instance to a component */ ComponentDescription desc; - result = GetComponentInfo ((Component)*inDestUnit, &desc, 0, 0, 0); - if (result) return 0; /*THROW_RESULT("GetComponentInfo")*/ - - /* we're going to use this to know which convert routine to call - a v1 audio unit will have a type of 'aunt' - a v2 audio unit will have one of several different types. */ + result = GetComponentInfo ((Component) * inDestUnit, &desc, 0, 0, 0); + if (result) + return 0; /*THROW_RESULT("GetComponentInfo") */ + + /* we're going to use this to know which convert routine to call + a v1 audio unit will have a type of 'aunt' + a v2 audio unit will have one of several different types. */ if (desc.componentType != kAudioUnitComponentType) { result = badComponentInstance; - /*THROW_RESULT("BAD COMPONENT")*/ - if (result) return 0; + /*THROW_RESULT("BAD COMPONENT") */ + if (result) + return 0; } /* Set the input format of the audio unit. */ result = AudioUnitSetProperty (*inDestUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &afp->mFileDescription, - sizeof (afp->mFileDescription)); - /*THROW_RESULT("AudioUnitSetProperty")*/ - if (result) return 0; + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &afp->mFileDescription, + sizeof (afp->mFileDescription)); + /*THROW_RESULT("AudioUnitSetProperty") */ + if (result) + return 0; return 1; } -static void AudioFilePlayer_SetNotifier(AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon) +static void +AudioFilePlayer_SetNotifier (AudioFilePlayer * afp, + AudioFilePlayNotifier inNotifier, void *inRefCon) { afp->mNotifier = inNotifier; afp->mRefCon = inRefCon; } -static int AudioFilePlayer_IsConnected(AudioFilePlayer *afp) +static int +AudioFilePlayer_IsConnected (AudioFilePlayer * afp) { return afp->mConnected; } -static AudioUnit AudioFilePlayer_GetDestUnit(AudioFilePlayer *afp) +static AudioUnit +AudioFilePlayer_GetDestUnit (AudioFilePlayer * afp) { - return afp->mPlayUnit; + return afp->mPlayUnit; } -static void AudioFilePlayer_Print(AudioFilePlayer *afp) +static void +AudioFilePlayer_Print (AudioFilePlayer * afp) { -#if DEBUG - printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false")); +#if DEBUG + printf ("Is Connected:%s\n", (IsConnected ()? "true" : "false")); printf ("- - - - - - - - - - - - - - \n"); #endif } -static void AudioFilePlayer_SetStartFrame (AudioFilePlayer *afp, int frame) +static void +AudioFilePlayer_SetStartFrame (AudioFilePlayer * afp, int frame) { SInt64 position = frame * 2352; @@ -128,59 +139,65 @@ static void AudioFilePlayer_SetStartFrame (AudioFilePlayer *afp, int frame) afp->mAudioFileManager->SetPosition (afp->mAudioFileManager, position); } - -static int AudioFilePlayer_GetCurrentFrame (AudioFilePlayer *afp) + +static int +AudioFilePlayer_GetCurrentFrame (AudioFilePlayer * afp) { - return afp->mStartFrame + (afp->mAudioFileManager->GetByteCounter(afp->mAudioFileManager) / 2352); + return afp->mStartFrame + + (afp->mAudioFileManager->GetByteCounter (afp->mAudioFileManager) / + 2352); } - -static void AudioFilePlayer_SetStopFrame (AudioFilePlayer *afp, int frame) + +static void +AudioFilePlayer_SetStopFrame (AudioFilePlayer * afp, int frame) { - SInt64 position = frame * 2352; - + SInt64 position = frame * 2352; + afp->mAudioFileManager->SetEndOfFile (afp->mAudioFileManager, position); } - -void delete_AudioFilePlayer(AudioFilePlayer *afp) + +void +delete_AudioFilePlayer (AudioFilePlayer * afp) { - if (afp != NULL) - { - afp->Disconnect(afp); - + if (afp != NULL) { + afp->Disconnect (afp); + if (afp->mAudioFileManager) { - delete_AudioFileManager(afp->mAudioFileManager); + delete_AudioFileManager (afp->mAudioFileManager); afp->mAudioFileManager = 0; } - + if (afp->mForkRefNum) { FSCloseFork (afp->mForkRefNum); afp->mForkRefNum = 0; } - SDL_free(afp); + SDL_free (afp); } } -static int AudioFilePlayer_Connect(AudioFilePlayer *afp) +static int +AudioFilePlayer_Connect (AudioFilePlayer * afp) { #if DEBUG - printf ("Connect:%x, engaged=%d\n", (int)afp->mPlayUnit, (afp->mConnected ? 1 : 0)); + printf ("Connect:%x, engaged=%d\n", (int) afp->mPlayUnit, + (afp->mConnected ? 1 : 0)); #endif - if (!afp->mConnected) - { - if (!afp->mAudioFileManager->DoConnect(afp->mAudioFileManager)) + if (!afp->mConnected) { + if (!afp->mAudioFileManager->DoConnect (afp->mAudioFileManager)) return 0; /* set the render callback for the file data to be supplied to the sound converter AU */ afp->mInputCallback.inputProc = afp->mAudioFileManager->FileInputProc; afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager; - OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, - kAudioUnitProperty_SetInputCallback, - kAudioUnitScope_Input, - 0, - &afp->mInputCallback, - sizeof(afp->mInputCallback)); - if (result) return 0; /*THROW_RESULT("AudioUnitSetProperty")*/ + OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, + kAudioUnitProperty_SetInputCallback, + kAudioUnitScope_Input, + 0, + &afp->mInputCallback, + sizeof (afp->mInputCallback)); + if (result) + return 0; /*THROW_RESULT("AudioUnitSetProperty") */ afp->mConnected = 1; } @@ -189,50 +206,56 @@ static int AudioFilePlayer_Connect(AudioFilePlayer *afp) /* warning noted, now please go away ;-) */ /* #warning This should redirect the calling of notification code to some other thread */ -static void AudioFilePlayer_DoNotification (AudioFilePlayer *afp, OSStatus inStatus) +static void +AudioFilePlayer_DoNotification (AudioFilePlayer * afp, OSStatus inStatus) { if (afp->mNotifier) { (*afp->mNotifier) (afp->mRefCon, inStatus); } else { SDL_SetError ("Notification posted with no notifier in place"); - + if (inStatus == kAudioFilePlay_FileIsFinished) - afp->Disconnect(afp); + afp->Disconnect (afp); else if (inStatus != kAudioFilePlayErr_FilePlayUnderrun) - afp->Disconnect(afp); + afp->Disconnect (afp); } } -static void AudioFilePlayer_Disconnect (AudioFilePlayer *afp) +static void +AudioFilePlayer_Disconnect (AudioFilePlayer * afp) { #if DEBUG - printf ("Disconnect:%x,%ld, engaged=%d\n", (int)afp->mPlayUnit, 0, (afp->mConnected ? 1 : 0)); + printf ("Disconnect:%x,%ld, engaged=%d\n", (int) afp->mPlayUnit, 0, + (afp->mConnected ? 1 : 0)); #endif - if (afp->mConnected) - { + if (afp->mConnected) { afp->mConnected = 0; - + afp->mInputCallback.inputProc = 0; afp->mInputCallback.inputProcRefCon = 0; - OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, - kAudioUnitProperty_SetInputCallback, - kAudioUnitScope_Input, - 0, - &afp->mInputCallback, - sizeof(afp->mInputCallback)); - if (result) - SDL_SetError ("AudioUnitSetProperty:RemoveInputCallback:%ld", result); - - afp->mAudioFileManager->Disconnect(afp->mAudioFileManager); + OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, + kAudioUnitProperty_SetInputCallback, + kAudioUnitScope_Input, + 0, + &afp->mInputCallback, + sizeof (afp->mInputCallback)); + if (result) + SDL_SetError ("AudioUnitSetProperty:RemoveInputCallback:%ld", + result); + + afp->mAudioFileManager->Disconnect (afp->mAudioFileManager); } } -typedef struct { +typedef struct +{ UInt32 offset; UInt32 blockSize; } SSNDData; -static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileDataSize) +static int +AudioFilePlayer_OpenFile (AudioFilePlayer * afp, const FSRef * inRef, + SInt64 * outFileDataSize) { ContainerChunk chunkHeader; ChunkHeader chunk; @@ -244,47 +267,65 @@ static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef SInt64 offset; /* Open the data fork of the input file */ - result = FSGetDataForkName(&dfName); - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName")*/ + result = FSGetDataForkName (&dfName); + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName") */ + + result = + FSOpenFork (inRef, dfName.length, dfName.unicode, fsRdPerm, + &afp->mForkRefNum); + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork") */ - result = FSOpenFork(inRef, dfName.length, dfName.unicode, fsRdPerm, &afp->mForkRefNum); - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork")*/ - /* Read the file header, and check if it's indeed an AIFC file */ - result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader), &chunkHeader, &actual); - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/ + result = + FSReadFork (afp->mForkRefNum, fsAtMark, 0, sizeof (chunkHeader), + &chunkHeader, &actual); + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */ if (chunkHeader.ckID != 'FORM') { result = -1; - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'");*/ + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'"); */ } if (chunkHeader.formType != 'AIFC') { result = -1; - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'");*/ + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'"); */ } /* Search for the SSND chunk. We ignore all compression etc. information in other chunks. Of course that is kind of evil, but for now we are lazy and rely on the cdfs to always give us the same fixed format. TODO: Parse the COMM chunk we currently skip to fill in mFileDescription. - */ + */ offset = 0; do { - result = FSReadFork(afp->mForkRefNum, fsFromMark, offset, sizeof(chunk), &chunk, &actual); - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/ - + result = + FSReadFork (afp->mForkRefNum, fsFromMark, offset, + sizeof (chunk), &chunk, &actual); + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */ + /* Skip the chunk data */ offset = chunk.ckSize; - } while (chunk.ckID != 'SSND'); + } + while (chunk.ckID != 'SSND'); /* Read the header of the SSND chunk. After this, we are positioned right at the start of the audio data. */ - result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData), &ssndData, &actual); - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/ + result = + FSReadFork (afp->mForkRefNum, fsAtMark, 0, sizeof (ssndData), + &ssndData, &actual); + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */ - result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset); - if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/ + result = + FSSetForkPosition (afp->mForkRefNum, fsFromMark, ssndData.offset); + if (result) + return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition") */ /* Data size */ *outFileDataSize = chunk.ckSize - ssndData.offset - 8; @@ -292,7 +333,8 @@ static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef /* File format */ afp->mFileDescription.mSampleRate = 44100; afp->mFileDescription.mFormatID = kAudioFormatLinearPCM; - afp->mFileDescription.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; + afp->mFileDescription.mFormatFlags = + kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; afp->mFileDescription.mBytesPerPacket = 4; afp->mFileDescription.mFramesPerPacket = 1; afp->mFileDescription.mBytesPerFrame = 4; @@ -302,53 +344,56 @@ static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef return 1; } -AudioFilePlayer *new_AudioFilePlayer (const FSRef *inFileRef) +AudioFilePlayer * +new_AudioFilePlayer (const FSRef * inFileRef) { - SInt64 fileDataSize = 0; + SInt64 fileDataSize = 0; - AudioFilePlayer *afp = (AudioFilePlayer *) SDL_malloc(sizeof (AudioFilePlayer)); + AudioFilePlayer *afp = + (AudioFilePlayer *) SDL_malloc (sizeof (AudioFilePlayer)); if (afp == NULL) return NULL; - SDL_memset(afp, '\0', sizeof (*afp)); - - #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m - SET_AUDIOFILEPLAYER_METHOD(SetDestination); - SET_AUDIOFILEPLAYER_METHOD(SetNotifier); - SET_AUDIOFILEPLAYER_METHOD(SetStartFrame); - SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame); - SET_AUDIOFILEPLAYER_METHOD(SetStopFrame); - SET_AUDIOFILEPLAYER_METHOD(Connect); - SET_AUDIOFILEPLAYER_METHOD(Disconnect); - SET_AUDIOFILEPLAYER_METHOD(DoNotification); - SET_AUDIOFILEPLAYER_METHOD(IsConnected); - SET_AUDIOFILEPLAYER_METHOD(GetDestUnit); - SET_AUDIOFILEPLAYER_METHOD(Print); - SET_AUDIOFILEPLAYER_METHOD(OpenFile); - #undef SET_AUDIOFILEPLAYER_METHOD - - if (!afp->OpenFile (afp, inFileRef, &fileDataSize)) - { - SDL_free(afp); + SDL_memset (afp, '\0', sizeof (*afp)); + +#define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m + SET_AUDIOFILEPLAYER_METHOD (SetDestination); + SET_AUDIOFILEPLAYER_METHOD (SetNotifier); + SET_AUDIOFILEPLAYER_METHOD (SetStartFrame); + SET_AUDIOFILEPLAYER_METHOD (GetCurrentFrame); + SET_AUDIOFILEPLAYER_METHOD (SetStopFrame); + SET_AUDIOFILEPLAYER_METHOD (Connect); + SET_AUDIOFILEPLAYER_METHOD (Disconnect); + SET_AUDIOFILEPLAYER_METHOD (DoNotification); + SET_AUDIOFILEPLAYER_METHOD (IsConnected); + SET_AUDIOFILEPLAYER_METHOD (GetDestUnit); + SET_AUDIOFILEPLAYER_METHOD (Print); + SET_AUDIOFILEPLAYER_METHOD (OpenFile); +#undef SET_AUDIOFILEPLAYER_METHOD + + if (!afp->OpenFile (afp, inFileRef, &fileDataSize)) { + SDL_free (afp); return NULL; } - + /* we want about 4 seconds worth of data for the buffer */ - int bytesPerSecond = (UInt32) (4 * afp->mFileDescription.mSampleRate * afp->mFileDescription.mBytesPerFrame); - + int bytesPerSecond = + (UInt32) (4 * afp->mFileDescription.mSampleRate * + afp->mFileDescription.mBytesPerFrame); + #if DEBUG - printf("File format:\n"); + printf ("File format:\n"); PrintStreamDesc (&afp->mFileDescription); #endif - - afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum, - fileDataSize, - bytesPerSecond); - if (afp->mAudioFileManager == NULL) - { - delete_AudioFilePlayer(afp); + + afp->mAudioFileManager = new_AudioFileManager (afp, afp->mForkRefNum, + fileDataSize, + bytesPerSecond); + if (afp->mAudioFileManager == NULL) { + delete_AudioFilePlayer (afp); return NULL; } return afp; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/AudioFilePlayer.h b/src/cdrom/macosx/AudioFilePlayer.h index 1d7eb19d4..49705e81b 100644 --- a/src/cdrom/macosx/AudioFilePlayer.h +++ b/src/cdrom/macosx/AudioFilePlayer.h @@ -36,7 +36,7 @@ #include "SDL_error.h" -const char* AudioFilePlayerErrorStr (OSStatus error); +const char *AudioFilePlayerErrorStr (OSStatus error); /* void ThrowResult (OSStatus result, const char *str); @@ -47,10 +47,10 @@ void ThrowResult (OSStatus result, const char *str); } */ -typedef void (*AudioFilePlayNotifier)(void *inRefCon, - OSStatus inStatus); +typedef void (*AudioFilePlayNotifier) (void *inRefCon, OSStatus inStatus); -enum { +enum +{ kAudioFilePlayErr_FilePlayUnderrun = -10000, kAudioFilePlay_FileIsFinished = -10001, kAudioFilePlay_PlayerIsUninitialized = -10002 @@ -63,43 +63,46 @@ struct S_AudioFileManager; typedef struct S_AudioFilePlayer { /*public:*/ - int (*SetDestination)(struct S_AudioFilePlayer *afp, AudioUnit *inDestUnit); - void (*SetNotifier)(struct S_AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon); - void (*SetStartFrame)(struct S_AudioFilePlayer *afp, int frame); /* seek in the file */ - int (*GetCurrentFrame)(struct S_AudioFilePlayer *afp); /* get the current frame position */ - void (*SetStopFrame)(struct S_AudioFilePlayer *afp, int frame); /* set limit in the file */ - int (*Connect)(struct S_AudioFilePlayer *afp); - void (*Disconnect)(struct S_AudioFilePlayer *afp); - void (*DoNotification)(struct S_AudioFilePlayer *afp, OSStatus inError); - int (*IsConnected)(struct S_AudioFilePlayer *afp); - AudioUnit (*GetDestUnit)(struct S_AudioFilePlayer *afp); - void (*Print)(struct S_AudioFilePlayer *afp); + int (*SetDestination) (struct S_AudioFilePlayer * afp, + AudioUnit * inDestUnit); + void (*SetNotifier) (struct S_AudioFilePlayer * afp, + AudioFilePlayNotifier inNotifier, void *inRefCon); + void (*SetStartFrame) (struct S_AudioFilePlayer * afp, int frame); /* seek in the file */ + int (*GetCurrentFrame) (struct S_AudioFilePlayer * afp); /* get the current frame position */ + void (*SetStopFrame) (struct S_AudioFilePlayer * afp, int frame); /* set limit in the file */ + int (*Connect) (struct S_AudioFilePlayer * afp); + void (*Disconnect) (struct S_AudioFilePlayer * afp); + void (*DoNotification) (struct S_AudioFilePlayer * afp, OSStatus inError); + int (*IsConnected) (struct S_AudioFilePlayer * afp); + AudioUnit (*GetDestUnit) (struct S_AudioFilePlayer * afp); + void (*Print) (struct S_AudioFilePlayer * afp); /*private:*/ - AudioUnit mPlayUnit; - SInt16 mForkRefNum; - - AudioUnitInputCallback mInputCallback; - - AudioStreamBasicDescription mFileDescription; - - int mConnected; - - struct S_AudioFileManager* mAudioFileManager; - - AudioFilePlayNotifier mNotifier; - void* mRefCon; - - int mStartFrame; - + AudioUnit mPlayUnit; + SInt16 mForkRefNum; + + AudioUnitInputCallback mInputCallback; + + AudioStreamBasicDescription mFileDescription; + + int mConnected; + + struct S_AudioFileManager *mAudioFileManager; + + AudioFilePlayNotifier mNotifier; + void *mRefCon; + + int mStartFrame; + #pragma mark __________ Private_Methods - - int (*OpenFile)(struct S_AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileSize); + + int (*OpenFile) (struct S_AudioFilePlayer * afp, const FSRef * inRef, + SInt64 * outFileSize); } AudioFilePlayer; -AudioFilePlayer *new_AudioFilePlayer(const FSRef *inFileRef); -void delete_AudioFilePlayer(AudioFilePlayer *afp); +AudioFilePlayer *new_AudioFilePlayer (const FSRef * inFileRef); +void delete_AudioFilePlayer (AudioFilePlayer * afp); @@ -107,64 +110,66 @@ void delete_AudioFilePlayer(AudioFilePlayer *afp); typedef struct S_AudioFileManager { /*public:*/ - /* this method should NOT be called by an object of this class - as it is called by the parent's Disconnect() method */ - void (*Disconnect)(struct S_AudioFileManager *afm); - int (*DoConnect)(struct S_AudioFileManager *afm); - OSStatus (*Read)(struct S_AudioFileManager *afm, char *buffer, UInt32 *len); - const char* (*GetFileBuffer)(struct S_AudioFileManager *afm); - const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm); - void (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos); /* seek/rewind in the file */ - int (*GetByteCounter)(struct S_AudioFileManager *afm); /* return actual bytes streamed to audio hardware */ - void (*SetEndOfFile)(struct S_AudioFileManager *afm, SInt64 pos); /* set the "EOF" (will behave just like it reached eof) */ - + /* this method should NOT be called by an object of this class + as it is called by the parent's Disconnect() method */ + void (*Disconnect) (struct S_AudioFileManager * afm); + int (*DoConnect) (struct S_AudioFileManager * afm); + OSStatus (*Read) (struct S_AudioFileManager * afm, char *buffer, + UInt32 * len); + const char *(*GetFileBuffer) (struct S_AudioFileManager * afm); + const AudioFilePlayer *(*GetParent) (struct S_AudioFileManager * afm); + void (*SetPosition) (struct S_AudioFileManager * afm, SInt64 pos); /* seek/rewind in the file */ + int (*GetByteCounter) (struct S_AudioFileManager * afm); /* return actual bytes streamed to audio hardware */ + void (*SetEndOfFile) (struct S_AudioFileManager * afm, SInt64 pos); /* set the "EOF" (will behave just like it reached eof) */ + /*protected:*/ - AudioFilePlayer* mParent; - SInt16 mForkRefNum; - SInt64 mAudioDataOffset; - - char* mFileBuffer; + AudioFilePlayer *mParent; + SInt16 mForkRefNum; + SInt64 mAudioDataOffset; + + char *mFileBuffer; - int mByteCounter; + int mByteCounter; - int mReadFromFirstBuffer; - int mLockUnsuccessful; - int mIsEngaged; - - int mNumTimesAskedSinceFinished; + int mReadFromFirstBuffer; + int mLockUnsuccessful; + int mIsEngaged; + int mNumTimesAskedSinceFinished; - void* mTmpBuffer; - UInt32 mBufferSize; - UInt32 mBufferOffset; + + void *mTmpBuffer; + UInt32 mBufferSize; + UInt32 mBufferOffset; /*public:*/ - UInt32 mChunkSize; - SInt64 mFileLength; - SInt64 mReadFilePosition; - int mWriteToFirstBuffer; - int mFinishedReadingData; + UInt32 mChunkSize; + SInt64 mFileLength; + SInt64 mReadFilePosition; + int mWriteToFirstBuffer; + int mFinishedReadingData; /*protected:*/ - OSStatus (*Render)(struct S_AudioFileManager *afm, AudioBuffer *ioData); - OSStatus (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize); - void (*AfterRender)(struct S_AudioFileManager *afm); + OSStatus (*Render) (struct S_AudioFileManager * afm, + AudioBuffer * ioData); + OSStatus (*GetFileData) (struct S_AudioFileManager * afm, + void **inOutData, UInt32 * inOutDataSize); + void (*AfterRender) (struct S_AudioFileManager * afm); /*public:*/ - /*static*/ - OSStatus (*FileInputProc)(void *inRefCon, - AudioUnitRenderActionFlags inActionFlags, - const AudioTimeStamp *inTimeStamp, - UInt32 inBusNumber, - AudioBuffer *ioData); + /*static */ + OSStatus (*FileInputProc) (void *inRefCon, + AudioUnitRenderActionFlags inActionFlags, + const AudioTimeStamp * inTimeStamp, + UInt32 inBusNumber, AudioBuffer * ioData); } AudioFileManager; -AudioFileManager *new_AudioFileManager (AudioFilePlayer *inParent, - SInt16 inForkRefNum, - SInt64 inFileLength, - UInt32 inChunkSize); - -void delete_AudioFileManager(AudioFileManager *afm); +AudioFileManager *new_AudioFileManager (AudioFilePlayer * inParent, + SInt16 inForkRefNum, + SInt64 inFileLength, + UInt32 inChunkSize); -#endif +void delete_AudioFileManager (AudioFileManager * afm); +#endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/AudioFileReaderThread.c b/src/cdrom/macosx/AudioFileReaderThread.c index db7fe9b22..354faf00f 100644 --- a/src/cdrom/macosx/AudioFileReaderThread.c +++ b/src/cdrom/macosx/AudioFileReaderThread.c @@ -28,7 +28,7 @@ AudioFileManager.cpp */ #include "AudioFilePlayer.h" -#include /* used for setting policy of thread */ +#include /* used for setting policy of thread */ #include "SDLOSXCAGuard.h" #include @@ -42,283 +42,322 @@ typedef struct S_FileData } FileData; -typedef struct S_FileReaderThread { +typedef struct S_FileReaderThread +{ /*public:*/ - SDLOSXCAGuard* (*GetGuard)(struct S_FileReaderThread *frt); - void (*AddReader)(struct S_FileReaderThread *frt); - void (*RemoveReader)(struct S_FileReaderThread *frt, AudioFileManager* inItem); - int (*TryNextRead)(struct S_FileReaderThread *frt, AudioFileManager* inItem); + SDLOSXCAGuard *(*GetGuard) (struct S_FileReaderThread * frt); + void (*AddReader) (struct S_FileReaderThread * frt); + void (*RemoveReader) (struct S_FileReaderThread * frt, + AudioFileManager * inItem); + int (*TryNextRead) (struct S_FileReaderThread * frt, + AudioFileManager * inItem); + + int mThreadShouldDie; - int mThreadShouldDie; - /*private:*/ - /*typedef std::list FileData;*/ + /*typedef std::list FileData; */ - SDLOSXCAGuard *mGuard; - UInt32 mThreadPriority; - - int mNumReaders; - FileData *mFileData; + SDLOSXCAGuard *mGuard; + UInt32 mThreadPriority; + int mNumReaders; + FileData *mFileData; - void (*ReadNextChunk)(struct S_FileReaderThread *frt); - int (*StartFixedPriorityThread)(struct S_FileReaderThread *frt); - /*static*/ - UInt32 (*GetThreadBasePriority)(pthread_t inThread); - /*static*/ - void* (*DiskReaderEntry)(void *inRefCon); + + void (*ReadNextChunk) (struct S_FileReaderThread * frt); + int (*StartFixedPriorityThread) (struct S_FileReaderThread * frt); + /*static */ + UInt32 (*GetThreadBasePriority) (pthread_t inThread); + /*static */ + void *(*DiskReaderEntry) (void *inRefCon); } FileReaderThread; -static SDLOSXCAGuard* FileReaderThread_GetGuard(FileReaderThread *frt) +static SDLOSXCAGuard * +FileReaderThread_GetGuard (FileReaderThread * frt) { return frt->mGuard; } /* returns 1 if succeeded */ -static int FileReaderThread_TryNextRead (FileReaderThread *frt, AudioFileManager* inItem) +static int +FileReaderThread_TryNextRead (FileReaderThread * frt, + AudioFileManager * inItem) { int didLock = 0; int succeeded = 0; - if (frt->mGuard->Try(frt->mGuard, &didLock)) - { - /*frt->mFileData.push_back (inItem);*/ + if (frt->mGuard->Try (frt->mGuard, &didLock)) { + /*frt->mFileData.push_back (inItem); */ /* !!! FIXME: this could be faster with a "tail" member. --ryan. */ FileData *i = frt->mFileData; FileData *prev = NULL; - FileData *newfd = (FileData *) SDL_malloc(sizeof (FileData)); + FileData *newfd = (FileData *) SDL_malloc (sizeof (FileData)); newfd->obj = inItem; newfd->next = NULL; - while (i != NULL) { prev = i; i = i->next; } + while (i != NULL) { + prev = i; + i = i->next; + } if (prev == NULL) frt->mFileData = newfd; else prev->next = newfd; - frt->mGuard->Notify(frt->mGuard); + frt->mGuard->Notify (frt->mGuard); succeeded = 1; if (didLock) - frt->mGuard->Unlock(frt->mGuard); + frt->mGuard->Unlock (frt->mGuard); } - + return succeeded; } -static void FileReaderThread_AddReader(FileReaderThread *frt) +static void +FileReaderThread_AddReader (FileReaderThread * frt) { - if (frt->mNumReaders == 0) - { + if (frt->mNumReaders == 0) { frt->mThreadShouldDie = 0; frt->StartFixedPriorityThread (frt); } frt->mNumReaders++; } -static void FileReaderThread_RemoveReader (FileReaderThread *frt, AudioFileManager* inItem) +static void +FileReaderThread_RemoveReader (FileReaderThread * frt, + AudioFileManager * inItem) { - if (frt->mNumReaders > 0) - { - int bNeedsRelease = frt->mGuard->Lock(frt->mGuard); - - /*frt->mFileData.remove (inItem);*/ + if (frt->mNumReaders > 0) { + int bNeedsRelease = frt->mGuard->Lock (frt->mGuard); + + /*frt->mFileData.remove (inItem); */ FileData *i = frt->mFileData; FileData *prev = NULL; - while (i != NULL) - { + while (i != NULL) { FileData *next = i->next; if (i->obj != inItem) prev = i; - else - { + else { if (prev == NULL) frt->mFileData = next; else prev->next = next; - SDL_free(i); + SDL_free (i); } i = next; } if (--frt->mNumReaders == 0) { frt->mThreadShouldDie = 1; - frt->mGuard->Notify(frt->mGuard); /* wake up thread so it will quit */ - frt->mGuard->Wait(frt->mGuard); /* wait for thread to die */ + frt->mGuard->Notify (frt->mGuard); /* wake up thread so it will quit */ + frt->mGuard->Wait (frt->mGuard); /* wait for thread to die */ } - if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard); - } + if (bNeedsRelease) + frt->mGuard->Unlock (frt->mGuard); + } } -static int FileReaderThread_StartFixedPriorityThread (FileReaderThread *frt) +static int +FileReaderThread_StartFixedPriorityThread (FileReaderThread * frt) { - pthread_attr_t theThreadAttrs; - pthread_t pThread; - - OSStatus result = pthread_attr_init(&theThreadAttrs); - if (result) return 0; /*THROW_RESULT("pthread_attr_init - Thread attributes could not be created.")*/ - - result = pthread_attr_setdetachstate(&theThreadAttrs, PTHREAD_CREATE_DETACHED); - if (result) return 0; /*THROW_RESULT("pthread_attr_setdetachstate - Thread attributes could not be detached.")*/ - - result = pthread_create (&pThread, &theThreadAttrs, frt->DiskReaderEntry, frt); - if (result) return 0; /*THROW_RESULT("pthread_create - Create and start the thread.")*/ - - pthread_attr_destroy(&theThreadAttrs); - + pthread_attr_t theThreadAttrs; + pthread_t pThread; + + OSStatus result = pthread_attr_init (&theThreadAttrs); + if (result) + return 0; /*THROW_RESULT("pthread_attr_init - Thread attributes could not be created.") */ + + result = + pthread_attr_setdetachstate (&theThreadAttrs, + PTHREAD_CREATE_DETACHED); + if (result) + return 0; /*THROW_RESULT("pthread_attr_setdetachstate - Thread attributes could not be detached.") */ + + result = + pthread_create (&pThread, &theThreadAttrs, frt->DiskReaderEntry, frt); + if (result) + return 0; /*THROW_RESULT("pthread_create - Create and start the thread.") */ + + pthread_attr_destroy (&theThreadAttrs); + /* we've now created the thread and started it we'll now set the priority of the thread to the nominated priority and we'll also make the thread fixed */ - thread_extended_policy_data_t theFixedPolicy; - thread_precedence_policy_data_t thePrecedencePolicy; - SInt32 relativePriority; - + thread_extended_policy_data_t theFixedPolicy; + thread_precedence_policy_data_t thePrecedencePolicy; + SInt32 relativePriority; + /* make thread fixed */ - theFixedPolicy.timeshare = 0; /* set to 1 for a non-fixed thread */ - result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); - if (result) return 0; /*THROW_RESULT("thread_policy - Couldn't set thread as fixed priority.")*/ + theFixedPolicy.timeshare = 0; /* set to 1 for a non-fixed thread */ + result = + thread_policy_set (pthread_mach_thread_np (pThread), + THREAD_EXTENDED_POLICY, + (thread_policy_t) & theFixedPolicy, + THREAD_EXTENDED_POLICY_COUNT); + if (result) + return 0; /*THROW_RESULT("thread_policy - Couldn't set thread as fixed priority.") */ /* set priority */ /* precedency policy's "importance" value is relative to spawning thread's priority */ - relativePriority = frt->mThreadPriority - frt->GetThreadBasePriority(pthread_self()); - + relativePriority = + frt->mThreadPriority - frt->GetThreadBasePriority (pthread_self ()); + thePrecedencePolicy.importance = relativePriority; - result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); - if (result) return 0; /*THROW_RESULT("thread_policy - Couldn't set thread priority.")*/ + result = + thread_policy_set (pthread_mach_thread_np (pThread), + THREAD_PRECEDENCE_POLICY, + (thread_policy_t) & thePrecedencePolicy, + THREAD_PRECEDENCE_POLICY_COUNT); + if (result) + return 0; /*THROW_RESULT("thread_policy - Couldn't set thread priority.") */ return 1; } -static UInt32 FileReaderThread_GetThreadBasePriority (pthread_t inThread) +static UInt32 +FileReaderThread_GetThreadBasePriority (pthread_t inThread) { - thread_basic_info_data_t threadInfo; - policy_info_data_t thePolicyInfo; - unsigned int count; - + thread_basic_info_data_t threadInfo; + policy_info_data_t thePolicyInfo; + unsigned int count; + /* get basic info */ count = THREAD_BASIC_INFO_COUNT; - thread_info (pthread_mach_thread_np (inThread), THREAD_BASIC_INFO, (integer_t*)&threadInfo, &count); - + thread_info (pthread_mach_thread_np (inThread), THREAD_BASIC_INFO, + (integer_t *) & threadInfo, &count); + switch (threadInfo.policy) { - case POLICY_TIMESHARE: - count = POLICY_TIMESHARE_INFO_COUNT; - thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_TIMESHARE_INFO, (integer_t*)&(thePolicyInfo.ts), &count); - return thePolicyInfo.ts.base_priority; - break; - - case POLICY_FIFO: - count = POLICY_FIFO_INFO_COUNT; - thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_FIFO_INFO, (integer_t*)&(thePolicyInfo.fifo), &count); - if (thePolicyInfo.fifo.depressed) { - return thePolicyInfo.fifo.depress_priority; - } else { - return thePolicyInfo.fifo.base_priority; - } - break; - - case POLICY_RR: - count = POLICY_RR_INFO_COUNT; - thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_RR_INFO, (integer_t*)&(thePolicyInfo.rr), &count); - if (thePolicyInfo.rr.depressed) { - return thePolicyInfo.rr.depress_priority; - } else { - return thePolicyInfo.rr.base_priority; - } - break; + case POLICY_TIMESHARE: + count = POLICY_TIMESHARE_INFO_COUNT; + thread_info (pthread_mach_thread_np (inThread), + THREAD_SCHED_TIMESHARE_INFO, + (integer_t *) & (thePolicyInfo.ts), &count); + return thePolicyInfo.ts.base_priority; + break; + + case POLICY_FIFO: + count = POLICY_FIFO_INFO_COUNT; + thread_info (pthread_mach_thread_np (inThread), + THREAD_SCHED_FIFO_INFO, + (integer_t *) & (thePolicyInfo.fifo), &count); + if (thePolicyInfo.fifo.depressed) { + return thePolicyInfo.fifo.depress_priority; + } else { + return thePolicyInfo.fifo.base_priority; + } + break; + + case POLICY_RR: + count = POLICY_RR_INFO_COUNT; + thread_info (pthread_mach_thread_np (inThread), + THREAD_SCHED_RR_INFO, + (integer_t *) & (thePolicyInfo.rr), &count); + if (thePolicyInfo.rr.depressed) { + return thePolicyInfo.rr.depress_priority; + } else { + return thePolicyInfo.rr.base_priority; + } + break; } - + return 0; } -static void *FileReaderThread_DiskReaderEntry (void *inRefCon) +static void * +FileReaderThread_DiskReaderEntry (void *inRefCon) { - FileReaderThread *frt = (FileReaderThread *)inRefCon; - frt->ReadNextChunk(frt); - #if DEBUG + FileReaderThread *frt = (FileReaderThread *) inRefCon; + frt->ReadNextChunk (frt); +#if DEBUG printf ("finished with reading file\n"); - #endif - +#endif + return 0; } -static void FileReaderThread_ReadNextChunk (FileReaderThread *frt) +static void +FileReaderThread_ReadNextChunk (FileReaderThread * frt) { OSStatus result; - UInt32 dataChunkSize; - AudioFileManager* theItem = 0; - - for (;;) - { - { /* this is a scoped based lock */ - int bNeedsRelease = frt->mGuard->Lock(frt->mGuard); - + UInt32 dataChunkSize; + AudioFileManager *theItem = 0; + + for (;;) { + { /* this is a scoped based lock */ + int bNeedsRelease = frt->mGuard->Lock (frt->mGuard); + if (frt->mThreadShouldDie) { - frt->mGuard->Notify(frt->mGuard); - if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard); + frt->mGuard->Notify (frt->mGuard); + if (bNeedsRelease) + frt->mGuard->Unlock (frt->mGuard); return; } - - /*if (frt->mFileData.empty())*/ - if (frt->mFileData == NULL) - { - frt->mGuard->Wait(frt->mGuard); + + /*if (frt->mFileData.empty()) */ + if (frt->mFileData == NULL) { + frt->mGuard->Wait (frt->mGuard); } - + /* kill thread */ if (frt->mThreadShouldDie) { - - frt->mGuard->Notify(frt->mGuard); - if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard); + + frt->mGuard->Notify (frt->mGuard); + if (bNeedsRelease) + frt->mGuard->Unlock (frt->mGuard); return; } - /*theItem = frt->mFileData.front();*/ - /*frt->mFileData.pop_front();*/ + /*theItem = frt->mFileData.front(); */ + /*frt->mFileData.pop_front(); */ theItem = NULL; - if (frt->mFileData != NULL) - { + if (frt->mFileData != NULL) { FileData *next = frt->mFileData->next; theItem = frt->mFileData->obj; - SDL_free(frt->mFileData); + SDL_free (frt->mFileData); frt->mFileData = next; } - if (bNeedsRelease) frt->mGuard->Unlock(frt->mGuard); + if (bNeedsRelease) + frt->mGuard->Unlock (frt->mGuard); } - - if ((theItem->mFileLength - theItem->mReadFilePosition) < theItem->mChunkSize) + + if ((theItem->mFileLength - theItem->mReadFilePosition) < + theItem->mChunkSize) dataChunkSize = theItem->mFileLength - theItem->mReadFilePosition; else dataChunkSize = theItem->mChunkSize; - - /* this is the exit condition for the thread */ + + /* this is the exit condition for the thread */ if (dataChunkSize <= 0) { theItem->mFinishedReadingData = 1; continue; } - /* construct pointer */ - char* writePtr = (char *) (theItem->GetFileBuffer(theItem) + - (theItem->mWriteToFirstBuffer ? 0 : theItem->mChunkSize)); - - /* read data */ - result = theItem->Read(theItem, writePtr, &dataChunkSize); + /* construct pointer */ + char *writePtr = (char *) (theItem->GetFileBuffer (theItem) + + (theItem-> + mWriteToFirstBuffer ? 0 : theItem-> + mChunkSize)); + + /* read data */ + result = theItem->Read (theItem, writePtr, &dataChunkSize); if (result != noErr && result != eofErr) { - AudioFilePlayer *afp = (AudioFilePlayer *) theItem->GetParent(theItem); - afp->DoNotification(afp, result); + AudioFilePlayer *afp = + (AudioFilePlayer *) theItem->GetParent (theItem); + afp->DoNotification (afp, result); continue; } - - if (dataChunkSize != theItem->mChunkSize) - { + + if (dataChunkSize != theItem->mChunkSize) { writePtr += dataChunkSize; /* can't exit yet.. we still have to pass the partial buffer back */ - SDL_memset(writePtr, 0, (theItem->mChunkSize - dataChunkSize)); + SDL_memset (writePtr, 0, (theItem->mChunkSize - dataChunkSize)); } - + theItem->mWriteToFirstBuffer = !theItem->mWriteToFirstBuffer; /* switch buffers */ - + if (result == eofErr) theItem->mReadFilePosition = theItem->mFileLength; else @@ -326,39 +365,39 @@ static void FileReaderThread_ReadNextChunk (FileReaderThread *frt) } } -void delete_FileReaderThread(FileReaderThread *frt) +void +delete_FileReaderThread (FileReaderThread * frt) { - if (frt != NULL) - { - delete_SDLOSXCAGuard(frt->mGuard); - SDL_free(frt); + if (frt != NULL) { + delete_SDLOSXCAGuard (frt->mGuard); + SDL_free (frt); } } -FileReaderThread *new_FileReaderThread () +FileReaderThread * +new_FileReaderThread () { - FileReaderThread *frt = (FileReaderThread *) SDL_malloc(sizeof (FileReaderThread)); + FileReaderThread *frt = + (FileReaderThread *) SDL_malloc (sizeof (FileReaderThread)); if (frt == NULL) return NULL; - SDL_memset(frt, '\0', sizeof (*frt)); + SDL_memset (frt, '\0', sizeof (*frt)); - frt->mGuard = new_SDLOSXCAGuard(); - if (frt->mGuard == NULL) - { - SDL_free(frt); + frt->mGuard = new_SDLOSXCAGuard (); + if (frt->mGuard == NULL) { + SDL_free (frt); return NULL; } - - #define SET_FILEREADERTHREAD_METHOD(m) frt->m = FileReaderThread_##m - SET_FILEREADERTHREAD_METHOD(GetGuard); - SET_FILEREADERTHREAD_METHOD(AddReader); - SET_FILEREADERTHREAD_METHOD(RemoveReader); - SET_FILEREADERTHREAD_METHOD(TryNextRead); - SET_FILEREADERTHREAD_METHOD(ReadNextChunk); - SET_FILEREADERTHREAD_METHOD(StartFixedPriorityThread); - SET_FILEREADERTHREAD_METHOD(GetThreadBasePriority); - SET_FILEREADERTHREAD_METHOD(DiskReaderEntry); - #undef SET_FILEREADERTHREAD_METHOD +#define SET_FILEREADERTHREAD_METHOD(m) frt->m = FileReaderThread_##m + SET_FILEREADERTHREAD_METHOD (GetGuard); + SET_FILEREADERTHREAD_METHOD (AddReader); + SET_FILEREADERTHREAD_METHOD (RemoveReader); + SET_FILEREADERTHREAD_METHOD (TryNextRead); + SET_FILEREADERTHREAD_METHOD (ReadNextChunk); + SET_FILEREADERTHREAD_METHOD (StartFixedPriorityThread); + SET_FILEREADERTHREAD_METHOD (GetThreadBasePriority); + SET_FILEREADERTHREAD_METHOD (DiskReaderEntry); +#undef SET_FILEREADERTHREAD_METHOD frt->mThreadPriority = 62; return frt; @@ -368,228 +407,243 @@ FileReaderThread *new_FileReaderThread () static FileReaderThread *sReaderThread; -static int AudioFileManager_DoConnect (AudioFileManager *afm) +static int +AudioFileManager_DoConnect (AudioFileManager * afm) { - if (!afm->mIsEngaged) - { + if (!afm->mIsEngaged) { OSStatus result; - /*afm->mReadFilePosition = 0;*/ + /*afm->mReadFilePosition = 0; */ afm->mFinishedReadingData = 0; afm->mNumTimesAskedSinceFinished = 0; afm->mLockUnsuccessful = 0; - + UInt32 dataChunkSize; - + if ((afm->mFileLength - afm->mReadFilePosition) < afm->mChunkSize) dataChunkSize = afm->mFileLength - afm->mReadFilePosition; else dataChunkSize = afm->mChunkSize; - - result = afm->Read(afm, afm->mFileBuffer, &dataChunkSize); - if (result) return 0; /*THROW_RESULT("AudioFileManager::DoConnect(): Read")*/ + + result = afm->Read (afm, afm->mFileBuffer, &dataChunkSize); + if (result) + return 0; /*THROW_RESULT("AudioFileManager::DoConnect(): Read") */ afm->mReadFilePosition += dataChunkSize; - + afm->mWriteToFirstBuffer = 0; afm->mReadFromFirstBuffer = 1; - sReaderThread->AddReader(sReaderThread); - + sReaderThread->AddReader (sReaderThread); + afm->mIsEngaged = 1; } /* - else - throw static_cast(-1); */ /* thread has already been started */ + else + throw static_cast(-1); *//* thread has already been started */ return 1; } -static void AudioFileManager_Disconnect (AudioFileManager *afm) +static void +AudioFileManager_Disconnect (AudioFileManager * afm) { - if (afm->mIsEngaged) - { + if (afm->mIsEngaged) { sReaderThread->RemoveReader (sReaderThread, afm); afm->mIsEngaged = 0; } } -static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, UInt32 *len) +static OSStatus +AudioFileManager_Read (AudioFileManager * afm, char *buffer, UInt32 * len) { return FSReadFork (afm->mForkRefNum, fsFromStart, afm->mReadFilePosition + afm->mAudioDataOffset, - *len, - buffer, - len); + *len, buffer, len); } -static OSStatus AudioFileManager_GetFileData (AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize) +static OSStatus +AudioFileManager_GetFileData (AudioFileManager * afm, void **inOutData, + UInt32 * inOutDataSize) { - if (afm->mFinishedReadingData) - { + if (afm->mFinishedReadingData) { ++afm->mNumTimesAskedSinceFinished; *inOutDataSize = 0; *inOutData = 0; return noErr; } - + if (afm->mReadFromFirstBuffer == afm->mWriteToFirstBuffer) { - #if DEBUG +#if DEBUG printf ("* * * * * * * Can't keep up with reading file\n"); - #endif - - afm->mParent->DoNotification (afm->mParent, kAudioFilePlayErr_FilePlayUnderrun); +#endif + + afm->mParent->DoNotification (afm->mParent, + kAudioFilePlayErr_FilePlayUnderrun); *inOutDataSize = 0; *inOutData = 0; } else { *inOutDataSize = afm->mChunkSize; - *inOutData = afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer + afm->mChunkSize); + *inOutData = + afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm-> + mFileBuffer + + afm->mChunkSize); } afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, afm); - + afm->mReadFromFirstBuffer = !afm->mReadFromFirstBuffer; return noErr; } -static void AudioFileManager_AfterRender (AudioFileManager *afm) +static void +AudioFileManager_AfterRender (AudioFileManager * afm) { - if (afm->mNumTimesAskedSinceFinished > 0) - { + if (afm->mNumTimesAskedSinceFinished > 0) { int didLock = 0; - SDLOSXCAGuard *guard = sReaderThread->GetGuard(sReaderThread); - if (guard->Try(guard, &didLock)) { - afm->mParent->DoNotification (afm->mParent, kAudioFilePlay_FileIsFinished); + SDLOSXCAGuard *guard = sReaderThread->GetGuard (sReaderThread); + if (guard->Try (guard, &didLock)) { + afm->mParent->DoNotification (afm->mParent, + kAudioFilePlay_FileIsFinished); if (didLock) - guard->Unlock(guard); + guard->Unlock (guard); } } if (afm->mLockUnsuccessful) - afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, afm); + afm->mLockUnsuccessful = + !sReaderThread->TryNextRead (sReaderThread, afm); } -static void AudioFileManager_SetPosition (AudioFileManager *afm, SInt64 pos) +static void +AudioFileManager_SetPosition (AudioFileManager * afm, SInt64 pos) { if (pos < 0 || pos >= afm->mFileLength) { - SDL_SetError ("AudioFileManager::SetPosition - position invalid: %d filelen=%d\n", - (unsigned int)pos, (unsigned int)afm->mFileLength); + SDL_SetError + ("AudioFileManager::SetPosition - position invalid: %d filelen=%d\n", + (unsigned int) pos, (unsigned int) afm->mFileLength); pos = 0; } - + afm->mReadFilePosition = pos; } - -static void AudioFileManager_SetEndOfFile (AudioFileManager *afm, SInt64 pos) + +static void +AudioFileManager_SetEndOfFile (AudioFileManager * afm, SInt64 pos) { if (pos <= 0 || pos > afm->mFileLength) { - SDL_SetError ("AudioFileManager::SetEndOfFile - position beyond actual eof\n"); + SDL_SetError + ("AudioFileManager::SetEndOfFile - position beyond actual eof\n"); pos = afm->mFileLength; } - + afm->mFileLength = pos; } -static const char *AudioFileManager_GetFileBuffer(AudioFileManager *afm) +static const char * +AudioFileManager_GetFileBuffer (AudioFileManager * afm) { return afm->mFileBuffer; } -const AudioFilePlayer *AudioFileManager_GetParent(AudioFileManager *afm) +const AudioFilePlayer * +AudioFileManager_GetParent (AudioFileManager * afm) { return afm->mParent; } -static int AudioFileManager_GetByteCounter(AudioFileManager *afm) +static int +AudioFileManager_GetByteCounter (AudioFileManager * afm) { return afm->mByteCounter; } -static OSStatus AudioFileManager_FileInputProc (void *inRefCon, - AudioUnitRenderActionFlags inActionFlags, - const AudioTimeStamp *inTimeStamp, - UInt32 inBusNumber, - AudioBuffer *ioData) +static OSStatus +AudioFileManager_FileInputProc (void *inRefCon, + AudioUnitRenderActionFlags inActionFlags, + const AudioTimeStamp * inTimeStamp, + UInt32 inBusNumber, AudioBuffer * ioData) { - AudioFileManager* afm = (AudioFileManager*)inRefCon; - return afm->Render(afm, ioData); + AudioFileManager *afm = (AudioFileManager *) inRefCon; + return afm->Render (afm, ioData); } -static OSStatus AudioFileManager_Render (AudioFileManager *afm, AudioBuffer *ioData) +static OSStatus +AudioFileManager_Render (AudioFileManager * afm, AudioBuffer * ioData) { OSStatus result = noErr; - - if (afm->mBufferOffset >= afm->mBufferSize) { - result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize); - if (result) { - SDL_SetError ("AudioConverterFillBuffer:%ld\n", result); - afm->mParent->DoNotification(afm->mParent, result); - return result; - } - - afm->mBufferOffset = 0; - } - + + if (afm->mBufferOffset >= afm->mBufferSize) { + result = afm->GetFileData (afm, &afm->mTmpBuffer, &afm->mBufferSize); + if (result) { + SDL_SetError ("AudioConverterFillBuffer:%ld\n", result); + afm->mParent->DoNotification (afm->mParent, result); + return result; + } + + afm->mBufferOffset = 0; + } + if (ioData->mDataByteSize > afm->mBufferSize - afm->mBufferOffset) - ioData->mDataByteSize = afm->mBufferSize - afm->mBufferOffset; - ioData->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset; + ioData->mDataByteSize = afm->mBufferSize - afm->mBufferOffset; + ioData->mData = (char *) afm->mTmpBuffer + afm->mBufferOffset; afm->mBufferOffset += ioData->mDataByteSize; - - afm->mByteCounter += ioData->mDataByteSize; - afm->AfterRender(afm); + + afm->mByteCounter += ioData->mDataByteSize; + afm->AfterRender (afm); return result; } -void delete_AudioFileManager (AudioFileManager *afm) +void +delete_AudioFileManager (AudioFileManager * afm) { if (afm != NULL) { if (afm->mFileBuffer) { - free(afm->mFileBuffer); + free (afm->mFileBuffer); } - SDL_free(afm); + SDL_free (afm); } } -AudioFileManager *new_AudioFileManager(AudioFilePlayer *inParent, - SInt16 inForkRefNum, - SInt64 inFileLength, - UInt32 inChunkSize) +AudioFileManager * +new_AudioFileManager (AudioFilePlayer * inParent, + SInt16 inForkRefNum, + SInt64 inFileLength, UInt32 inChunkSize) { AudioFileManager *afm; - if (sReaderThread == NULL) - { - sReaderThread = new_FileReaderThread(); + if (sReaderThread == NULL) { + sReaderThread = new_FileReaderThread (); if (sReaderThread == NULL) return NULL; } - afm = (AudioFileManager *) SDL_malloc(sizeof (AudioFileManager)); + afm = (AudioFileManager *) SDL_malloc (sizeof (AudioFileManager)); if (afm == NULL) return NULL; - SDL_memset(afm, '\0', sizeof (*afm)); - - #define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m - SET_AUDIOFILEMANAGER_METHOD(Disconnect); - SET_AUDIOFILEMANAGER_METHOD(DoConnect); - SET_AUDIOFILEMANAGER_METHOD(Read); - SET_AUDIOFILEMANAGER_METHOD(GetFileBuffer); - SET_AUDIOFILEMANAGER_METHOD(GetParent); - SET_AUDIOFILEMANAGER_METHOD(SetPosition); - SET_AUDIOFILEMANAGER_METHOD(GetByteCounter); - SET_AUDIOFILEMANAGER_METHOD(SetEndOfFile); - SET_AUDIOFILEMANAGER_METHOD(Render); - SET_AUDIOFILEMANAGER_METHOD(GetFileData); - SET_AUDIOFILEMANAGER_METHOD(AfterRender); - SET_AUDIOFILEMANAGER_METHOD(FileInputProc); - #undef SET_AUDIOFILEMANAGER_METHOD + SDL_memset (afm, '\0', sizeof (*afm)); + +#define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m + SET_AUDIOFILEMANAGER_METHOD (Disconnect); + SET_AUDIOFILEMANAGER_METHOD (DoConnect); + SET_AUDIOFILEMANAGER_METHOD (Read); + SET_AUDIOFILEMANAGER_METHOD (GetFileBuffer); + SET_AUDIOFILEMANAGER_METHOD (GetParent); + SET_AUDIOFILEMANAGER_METHOD (SetPosition); + SET_AUDIOFILEMANAGER_METHOD (GetByteCounter); + SET_AUDIOFILEMANAGER_METHOD (SetEndOfFile); + SET_AUDIOFILEMANAGER_METHOD (Render); + SET_AUDIOFILEMANAGER_METHOD (GetFileData); + SET_AUDIOFILEMANAGER_METHOD (AfterRender); + SET_AUDIOFILEMANAGER_METHOD (FileInputProc); +#undef SET_AUDIOFILEMANAGER_METHOD afm->mParent = inParent; afm->mForkRefNum = inForkRefNum; @@ -597,9 +651,10 @@ AudioFileManager *new_AudioFileManager(AudioFilePlayer *inParent, afm->mBufferOffset = inChunkSize; afm->mChunkSize = inChunkSize; afm->mFileLength = inFileLength; - afm->mFileBuffer = (char*) SDL_malloc(afm->mChunkSize * 2); - FSGetForkPosition(afm->mForkRefNum, &afm->mAudioDataOffset); + afm->mFileBuffer = (char *) SDL_malloc (afm->mChunkSize * 2); + FSGetForkPosition (afm->mForkRefNum, &afm->mAudioDataOffset); assert (afm->mFileBuffer != NULL); return afm; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/CDPlayer.c b/src/cdrom/macosx/CDPlayer.c index 16dc21397..99a901adc 100644 --- a/src/cdrom/macosx/CDPlayer.c +++ b/src/cdrom/macosx/CDPlayer.c @@ -32,7 +32,7 @@ Constants //////////////////////////////////////////////////////////////////////////*/ -#define kAudioCDFilesystemID (UInt16)(('J' << 8) | 'H') /* 'JH'; this avoids compiler warning */ +#define kAudioCDFilesystemID (UInt16)(('J' << 8) | 'H') /* 'JH'; this avoids compiler warning */ /* XML PList keys */ #define kRawTOCDataString "Format 0x02 TOC Data" @@ -45,21 +45,21 @@ #define kDataKeyString "Data" #define kPointKeyString "Point" #define kSessionNumberKeyString "Session Number" -#define kStartBlockKeyString "Start Block" - +#define kStartBlockKeyString "Start Block" + /*/////////////////////////////////////////////////////////////////////////// Globals //////////////////////////////////////////////////////////////////////////*/ #pragma mark -- Globals -- -static int playBackWasInit = 0; -static AudioUnit theUnit; -static AudioFilePlayer* thePlayer = NULL; -static CDPlayerCompletionProc completionProc = NULL; -static SDL_mutex *apiMutex = NULL; -static SDL_sem *callbackSem; -static SDL_CD* theCDROM; +static int playBackWasInit = 0; +static AudioUnit theUnit; +static AudioFilePlayer *thePlayer = NULL; +static CDPlayerCompletionProc completionProc = NULL; +static SDL_mutex *apiMutex = NULL; +static SDL_sem *callbackSem; +static SDL_CD *theCDROM; /*/////////////////////////////////////////////////////////////////////////// Prototypes @@ -69,96 +69,92 @@ static SDL_CD* theCDROM; static OSStatus CheckInit (); -static void FilePlayNotificationHandler (void* inRefCon, OSStatus inStatus); +static void FilePlayNotificationHandler (void *inRefCon, OSStatus inStatus); -static int RunCallBackThread (void* inRefCon); +static int RunCallBackThread (void *inRefCon); #pragma mark -- Public Functions -- -void Lock () +void +Lock () { if (!apiMutex) { - apiMutex = SDL_CreateMutex(); + apiMutex = SDL_CreateMutex (); } - SDL_mutexP(apiMutex); + SDL_mutexP (apiMutex); } -void Unlock () +void +Unlock () { - SDL_mutexV(apiMutex); + SDL_mutexV (apiMutex); } -int DetectAudioCDVolumes(FSVolumeRefNum *volumes, int numVolumes) +int +DetectAudioCDVolumes (FSVolumeRefNum * volumes, int numVolumes) { int volumeIndex; int cdVolumeCount = 0; OSStatus result = noErr; - - for (volumeIndex = 1; result == noErr || result != nsvErr; volumeIndex++) - { - FSVolumeRefNum actualVolume; - FSVolumeInfo volumeInfo; - - memset (&volumeInfo, 0, sizeof(volumeInfo)); - + + for (volumeIndex = 1; result == noErr || result != nsvErr; volumeIndex++) { + FSVolumeRefNum actualVolume; + FSVolumeInfo volumeInfo; + + memset (&volumeInfo, 0, sizeof (volumeInfo)); + result = FSGetVolumeInfo (kFSInvalidVolumeRefNum, volumeIndex, &actualVolume, - kFSVolInfoFSInfo, - &volumeInfo, - NULL, - NULL); - - if (result == noErr) - { - if (volumeInfo.filesystemID == kAudioCDFilesystemID) /* It's an audio CD */ - { + kFSVolInfoFSInfo, &volumeInfo, NULL, NULL); + + if (result == noErr) { + if (volumeInfo.filesystemID == kAudioCDFilesystemID) { /* It's an audio CD */ if (volumes != NULL && cdVolumeCount < numVolumes) volumes[cdVolumeCount] = actualVolume; - + cdVolumeCount++; } - } - else - { + } else { /* I'm commenting this out because it seems to be harmless */ - /*SDL_SetError ("DetectAudioCDVolumes: FSGetVolumeInfo returned %d", result);*/ + /*SDL_SetError ("DetectAudioCDVolumes: FSGetVolumeInfo returned %d", result); */ } } - + return cdVolumeCount; } -int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD *theCD) +int +ReadTOCData (FSVolumeRefNum theVolume, SDL_CD * theCD) { - HFSUniStr255 dataForkName; - OSStatus theErr; - SInt16 forkRefNum; - SInt64 forkSize; - Ptr forkData = 0; - ByteCount actualRead; - CFDataRef dataRef = 0; + HFSUniStr255 dataForkName; + OSStatus theErr; + SInt16 forkRefNum; + SInt64 forkSize; + Ptr forkData = 0; + ByteCount actualRead; + CFDataRef dataRef = 0; CFPropertyListRef propertyListRef = 0; - FSRefParam fsRefPB; - FSRef tocPlistFSRef; - - const char* error = "Unspecified Error"; - + FSRefParam fsRefPB; + FSRef tocPlistFSRef; + + const char *error = "Unspecified Error"; + /* get stuff from .TOC.plist */ fsRefPB.ioCompletion = NULL; fsRefPB.ioNamePtr = "\p.TOC.plist"; fsRefPB.ioVRefNum = theVolume; fsRefPB.ioDirID = 0; fsRefPB.newRef = &tocPlistFSRef; - + theErr = PBMakeFSRefSync (&fsRefPB); - if(theErr != noErr) { + if (theErr != noErr) { error = "PBMakeFSRefSync"; goto bail; } - + /* Load and parse the TOC XML data */ theErr = FSGetDataForkName (&dataForkName); @@ -166,34 +162,38 @@ int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD *theCD) error = "FSGetDataForkName"; goto bail; } - - theErr = FSOpenFork (&tocPlistFSRef, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum); + + theErr = + FSOpenFork (&tocPlistFSRef, dataForkName.length, dataForkName.unicode, + fsRdPerm, &forkRefNum); if (theErr != noErr) { error = "FSOpenFork"; goto bail; } - + theErr = FSGetForkSize (forkRefNum, &forkSize); if (theErr != noErr) { error = "FSGetForkSize"; goto bail; } - + /* Allocate some memory for the XML data */ forkData = NewPtr (forkSize); - if(forkData == NULL) { + if (forkData == NULL) { error = "NewPtr"; goto bail; } - - theErr = FSReadFork (forkRefNum, fsFromStart, 0 /* offset location */, forkSize, forkData, &actualRead); - if(theErr != noErr) { + + theErr = FSReadFork (forkRefNum, fsFromStart, 0 /* offset location */ , + forkSize, forkData, &actualRead); + if (theErr != noErr) { error = "FSReadFork"; goto bail; } - - dataRef = CFDataCreate (kCFAllocatorDefault, (UInt8 *)forkData, forkSize); - if(dataRef == 0) { + + dataRef = + CFDataCreate (kCFAllocatorDefault, (UInt8 *) forkData, forkSize); + if (dataRef == 0) { error = "CFDataCreate"; goto bail; } @@ -208,127 +208,150 @@ int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD *theCD) } /* Now we got the Property List in memory. Parse it. */ - + /* First, make sure the root item is a CFDictionary. If not, release and bail. */ - if(CFGetTypeID(propertyListRef)== CFDictionaryGetTypeID()) - { - CFDictionaryRef dictRef = (CFDictionaryRef)propertyListRef; - - CFDataRef theRawTOCDataRef; - CFArrayRef theSessionArrayRef; - CFIndex numSessions; - CFIndex index; - + if (CFGetTypeID (propertyListRef) == CFDictionaryGetTypeID ()) { + CFDictionaryRef dictRef = (CFDictionaryRef) propertyListRef; + + CFDataRef theRawTOCDataRef; + CFArrayRef theSessionArrayRef; + CFIndex numSessions; + CFIndex index; + /* This is how we get the Raw TOC Data */ - theRawTOCDataRef = (CFDataRef)CFDictionaryGetValue (dictRef, CFSTR(kRawTOCDataString)); - + theRawTOCDataRef = + (CFDataRef) CFDictionaryGetValue (dictRef, + CFSTR (kRawTOCDataString)); + /* Get the session array info. */ - theSessionArrayRef = (CFArrayRef)CFDictionaryGetValue (dictRef, CFSTR(kSessionsString)); - + theSessionArrayRef = + (CFArrayRef) CFDictionaryGetValue (dictRef, + CFSTR (kSessionsString)); + /* Find out how many sessions there are. */ numSessions = CFArrayGetCount (theSessionArrayRef); - + /* Initialize the total number of tracks to 0 */ theCD->numtracks = 0; - + /* Iterate over all sessions, collecting the track data */ - for(index = 0; index < numSessions; index++) - { + for (index = 0; index < numSessions; index++) { CFDictionaryRef theSessionDict; - CFNumberRef leadoutBlock; - CFArrayRef trackArray; - CFIndex numTracks; - CFIndex trackIndex; - UInt32 value = 0; - - theSessionDict = (CFDictionaryRef) CFArrayGetValueAtIndex (theSessionArrayRef, index); - leadoutBlock = (CFNumberRef) CFDictionaryGetValue (theSessionDict, CFSTR(kLeadoutBlockString)); - - trackArray = (CFArrayRef)CFDictionaryGetValue (theSessionDict, CFSTR(kTrackArrayString)); - + CFNumberRef leadoutBlock; + CFArrayRef trackArray; + CFIndex numTracks; + CFIndex trackIndex; + UInt32 value = 0; + + theSessionDict = (CFDictionaryRef) + CFArrayGetValueAtIndex (theSessionArrayRef, index); + leadoutBlock = + (CFNumberRef) CFDictionaryGetValue (theSessionDict, + CFSTR + (kLeadoutBlockString)); + + trackArray = + (CFArrayRef) CFDictionaryGetValue (theSessionDict, + CFSTR (kTrackArrayString)); + numTracks = CFArrayGetCount (trackArray); - for(trackIndex = 0; trackIndex < numTracks; trackIndex++) { - + for (trackIndex = 0; trackIndex < numTracks; trackIndex++) { + CFDictionaryRef theTrackDict; - CFNumberRef trackNumber; - CFNumberRef sessionNumber; - CFNumberRef startBlock; - CFBooleanRef isDataTrack; - UInt32 value; - - theTrackDict = (CFDictionaryRef) CFArrayGetValueAtIndex (trackArray, trackIndex); - - trackNumber = (CFNumberRef) CFDictionaryGetValue (theTrackDict, CFSTR(kPointKeyString)); - sessionNumber = (CFNumberRef) CFDictionaryGetValue (theTrackDict, CFSTR(kSessionNumberKeyString)); - startBlock = (CFNumberRef) CFDictionaryGetValue (theTrackDict, CFSTR(kStartBlockKeyString)); - isDataTrack = (CFBooleanRef) CFDictionaryGetValue (theTrackDict, CFSTR(kDataKeyString)); - + CFNumberRef trackNumber; + CFNumberRef sessionNumber; + CFNumberRef startBlock; + CFBooleanRef isDataTrack; + UInt32 value; + + theTrackDict = (CFDictionaryRef) + CFArrayGetValueAtIndex (trackArray, trackIndex); + + trackNumber = + (CFNumberRef) CFDictionaryGetValue (theTrackDict, + CFSTR + (kPointKeyString)); + sessionNumber = + (CFNumberRef) CFDictionaryGetValue (theTrackDict, + CFSTR + (kSessionNumberKeyString)); + startBlock = + (CFNumberRef) CFDictionaryGetValue (theTrackDict, + CFSTR + (kStartBlockKeyString)); + isDataTrack = + (CFBooleanRef) CFDictionaryGetValue (theTrackDict, + CFSTR + (kDataKeyString)); + /* Fill in the SDL_CD struct */ int idx = theCD->numtracks++; CFNumberGetValue (trackNumber, kCFNumberSInt32Type, &value); theCD->track[idx].id = value; - + CFNumberGetValue (startBlock, kCFNumberSInt32Type, &value); theCD->track[idx].offset = value; - theCD->track[idx].type = (isDataTrack == kCFBooleanTrue) ? SDL_DATA_TRACK : SDL_AUDIO_TRACK; + theCD->track[idx].type = + (isDataTrack == + kCFBooleanTrue) ? SDL_DATA_TRACK : SDL_AUDIO_TRACK; /* Since the track lengths are not stored in .TOC.plist we compute them. */ if (trackIndex > 0) { - theCD->track[idx-1].length = theCD->track[idx].offset - theCD->track[idx-1].offset; + theCD->track[idx - 1].length = + theCD->track[idx].offset - theCD->track[idx - + 1].offset; } } - + /* Compute the length of the last track */ CFNumberGetValue (leadoutBlock, kCFNumberSInt32Type, &value); - - theCD->track[theCD->numtracks-1].length = - value - theCD->track[theCD->numtracks-1].offset; + + theCD->track[theCD->numtracks - 1].length = + value - theCD->track[theCD->numtracks - 1].offset; /* Set offset to leadout track */ theCD->track[theCD->numtracks].offset = value; } - + } theErr = 0; goto cleanup; -bail: + bail: SDL_SetError ("ReadTOCData: %s returned %d", error, theErr); theErr = -1; -cleanup: + cleanup: if (propertyListRef != NULL) - CFRelease(propertyListRef); + CFRelease (propertyListRef); if (dataRef != NULL) - CFRelease(dataRef); + CFRelease (dataRef); if (forkData != NULL) - DisposePtr(forkData); - + DisposePtr (forkData); + FSCloseFork (forkRefNum); return theErr; } -int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks) +int +ListTrackFiles (FSVolumeRefNum theVolume, FSRef * trackFiles, int numTracks) { - OSStatus result = -1; - FSIterator iterator; - ItemCount actualObjects; - FSRef rootDirectory; - FSRef ref; - HFSUniStr255 nameStr; - + OSStatus result = -1; + FSIterator iterator; + ItemCount actualObjects; + FSRef rootDirectory; + FSRef ref; + HFSUniStr255 nameStr; + result = FSGetVolumeInfo (theVolume, 0, NULL, - kFSVolInfoFSInfo, - NULL, - NULL, - &rootDirectory); - + kFSVolInfoFSInfo, NULL, NULL, &rootDirectory); + if (result != noErr) { SDL_SetError ("ListTrackFiles: FSGetVolumeInfo returned %d", result); return result; @@ -336,293 +359,314 @@ int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks) result = FSOpenIterator (&rootDirectory, kFSIterateFlat, &iterator); if (result == noErr) { - do - { + do { result = FSGetCatalogInfoBulk (iterator, 1, &actualObjects, - NULL, kFSCatInfoNone, NULL, &ref, NULL, &nameStr); + NULL, kFSCatInfoNone, NULL, + &ref, NULL, &nameStr); if (result == noErr) { - - CFStringRef name; - name = CFStringCreateWithCharacters (NULL, nameStr.unicode, nameStr.length); - + + CFStringRef name; + name = + CFStringCreateWithCharacters (NULL, nameStr.unicode, + nameStr.length); + /* Look for .aiff extension */ - if (CFStringHasSuffix (name, CFSTR(".aiff")) || - CFStringHasSuffix (name, CFSTR(".cdda"))) { - + if (CFStringHasSuffix (name, CFSTR (".aiff")) || + CFStringHasSuffix (name, CFSTR (".cdda"))) { + /* Extract the track id from the filename */ int trackID = 0, i = 0; - while (i < nameStr.length && !isdigit(nameStr.unicode[i])) { + while (i < nameStr.length + && !isdigit (nameStr.unicode[i])) { ++i; } - while (i < nameStr.length && isdigit(nameStr.unicode[i])) { - trackID = 10 * trackID +(nameStr.unicode[i] - '0'); + while (i < nameStr.length && isdigit (nameStr.unicode[i])) { + trackID = 10 * trackID + (nameStr.unicode[i] - '0'); ++i; } - #if DEBUG_CDROM - printf("Found AIFF for track %d: '%s'\n", trackID, - CFStringGetCStringPtr (name, CFStringGetSystemEncoding())); - #endif - +#if DEBUG_CDROM + printf ("Found AIFF for track %d: '%s'\n", + trackID, CFStringGetCStringPtr (name, + CFStringGetSystemEncoding + ())); +#endif + /* Track ID's start at 1, but we want to start at 0 */ trackID--; - - assert(0 <= trackID && trackID <= SDL_MAX_TRACKS); - + + assert (0 <= trackID && trackID <= SDL_MAX_TRACKS); + if (trackID < numTracks) - memcpy (&trackFiles[trackID], &ref, sizeof(FSRef)); + memcpy (&trackFiles[trackID], &ref, sizeof (FSRef)); } CFRelease (name); } - } while(noErr == result); + } + while (noErr == result); FSCloseIterator (iterator); } - + return 0; } -int LoadFile (const FSRef *ref, int startFrame, int stopFrame) +int +LoadFile (const FSRef * ref, int startFrame, int stopFrame) { int error = -1; - + if (CheckInit () < 0) goto bail; - + /* release any currently playing file */ if (ReleaseFile () < 0) goto bail; - - #if DEBUG_CDROM + +#if DEBUG_CDROM printf ("LoadFile: %d %d\n", startFrame, stopFrame); - #endif - - /*try {*/ - - /* create a new player, and attach to the audio unit */ - - thePlayer = new_AudioFilePlayer(ref); - if (thePlayer == NULL) { - SDL_SetError ("LoadFile: Could not create player"); - return -3; /*throw (-3);*/ - } - - if (!thePlayer->SetDestination(thePlayer, &theUnit)) - goto bail; - - if (startFrame >= 0) - thePlayer->SetStartFrame (thePlayer, startFrame); - - if (stopFrame >= 0 && stopFrame > startFrame) - thePlayer->SetStopFrame (thePlayer, stopFrame); - - /* we set the notifier later */ - /*thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, NULL);*/ - - if (!thePlayer->Connect(thePlayer)) - goto bail; - - #if DEBUG_CDROM - thePlayer->Print(thePlayer); - fflush (stdout); - #endif +#endif + + /*try { */ + + /* create a new player, and attach to the audio unit */ + + thePlayer = new_AudioFilePlayer (ref); + if (thePlayer == NULL) { + SDL_SetError ("LoadFile: Could not create player"); + return -3; /*throw (-3); */ + } + + if (!thePlayer->SetDestination (thePlayer, &theUnit)) + goto bail; + + if (startFrame >= 0) + thePlayer->SetStartFrame (thePlayer, startFrame); + + if (stopFrame >= 0 && stopFrame > startFrame) + thePlayer->SetStopFrame (thePlayer, stopFrame); + + /* we set the notifier later */ + /*thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, NULL); */ + + if (!thePlayer->Connect (thePlayer)) + goto bail; + +#if DEBUG_CDROM + thePlayer->Print (thePlayer); + fflush (stdout); +#endif /*} - catch (...) - { - goto bail; - }*/ - + catch (...) + { + goto bail; + } */ + error = 0; - bail: + bail: return error; } -int ReleaseFile () +int +ReleaseFile () { int error = -1; - + /* (Don't see any way that the original C++ code could throw here.) --ryan. */ - /*try {*/ - if (thePlayer != NULL) { - - thePlayer->Disconnect(thePlayer); - - delete_AudioFilePlayer(thePlayer); - - thePlayer = NULL; - } + /*try { */ + if (thePlayer != NULL) { + + thePlayer->Disconnect (thePlayer); + + delete_AudioFilePlayer (thePlayer); + + thePlayer = NULL; + } /*} - catch (...) - { - goto bail; - }*/ - + catch (...) + { + goto bail; + } */ + error = 0; - + /* bail: */ return error; } -int PlayFile () +int +PlayFile () { OSStatus result = -1; - + if (CheckInit () < 0) goto bail; - - /*try {*/ - - // start processing of the audio unit - result = AudioOutputUnitStart (theUnit); - if (result) goto bail; //THROW_RESULT("PlayFile: AudioOutputUnitStart") - + + /*try { */ + + // start processing of the audio unit + result = AudioOutputUnitStart (theUnit); + if (result) + goto bail; //THROW_RESULT("PlayFile: AudioOutputUnitStart") + /*} - catch (...) - { - goto bail; - }*/ - + catch (...) + { + goto bail; + } */ + result = 0; - -bail: + + bail: return result; } -int PauseFile () +int +PauseFile () { OSStatus result = -1; - + if (CheckInit () < 0) goto bail; - - /*try {*/ - - /* stop processing the audio unit */ - result = AudioOutputUnitStop (theUnit); - if (result) goto bail; /*THROW_RESULT("PauseFile: AudioOutputUnitStop")*/ + + /*try { */ + + /* stop processing the audio unit */ + result = AudioOutputUnitStop (theUnit); + if (result) + goto bail; /*THROW_RESULT("PauseFile: AudioOutputUnitStop") */ /*} - catch (...) - { - goto bail; - }*/ - + catch (...) + { + goto bail; + } */ + result = 0; -bail: + bail: return result; } -void SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD *cdrom) +void +SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD * cdrom) { - assert(thePlayer != NULL); + assert (thePlayer != NULL); theCDROM = cdrom; completionProc = proc; thePlayer->SetNotifier (thePlayer, FilePlayNotificationHandler, cdrom); } -int GetCurrentFrame () -{ +int +GetCurrentFrame () +{ int frame; - + if (thePlayer == NULL) frame = 0; else frame = thePlayer->GetCurrentFrame (thePlayer); - - return frame; + + return frame; } #pragma mark -- Private Functions -- -static OSStatus CheckInit () -{ +static OSStatus +CheckInit () +{ if (playBackWasInit) return 0; - + OSStatus result = noErr; - + /* Create the callback semaphore */ - callbackSem = SDL_CreateSemaphore(0); + callbackSem = SDL_CreateSemaphore (0); /* Start callback thread */ - SDL_CreateThread(RunCallBackThread, NULL); + SDL_CreateThread (RunCallBackThread, NULL); - { /*try {*/ + { /*try { */ ComponentDescription desc; - + desc.componentType = kAudioUnitComponentType; desc.componentSubType = kAudioUnitSubType_Output; desc.componentManufacturer = kAudioUnitID_DefaultOutput; desc.componentFlags = 0; desc.componentFlagsMask = 0; - + Component comp = FindNextComponent (NULL, &desc); if (comp == NULL) { SDL_SetError ("CheckInit: FindNextComponent returned NULL"); - if (result) return -1; //throw(internalComponentErr); + if (result) + return -1; //throw(internalComponentErr); } - + result = OpenAComponent (comp, &theUnit); - if (result) return -1; //THROW_RESULT("CheckInit: OpenAComponent") - + if (result) + return -1; //THROW_RESULT("CheckInit: OpenAComponent") + // you need to initialize the output unit before you set it as a destination result = AudioUnitInitialize (theUnit); - if (result) return -1; //THROW_RESULT("CheckInit: AudioUnitInitialize") - - + if (result) + return -1; //THROW_RESULT("CheckInit: AudioUnitInitialize") + + playBackWasInit = true; } /*catch (...) - { - return -1; - }*/ - + { + return -1; + } */ + return 0; } -static void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus) +static void +FilePlayNotificationHandler (void *inRefCon, OSStatus inStatus) { if (inStatus == kAudioFilePlay_FileIsFinished) { - + /* notify non-CA thread to perform the callback */ - SDL_SemPost(callbackSem); - + SDL_SemPost (callbackSem); + } else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) { - + SDL_SetError ("CDPlayer Notification: buffer underrun"); } else if (inStatus == kAudioFilePlay_PlayerIsUninitialized) { - + SDL_SetError ("CDPlayer Notification: player is uninitialized"); } else { - + SDL_SetError ("CDPlayer Notification: unknown error %ld", inStatus); } } -static int RunCallBackThread (void *param) +static int +RunCallBackThread (void *param) { for (;;) { - - SDL_SemWait(callbackSem); + + SDL_SemWait (callbackSem); if (completionProc && theCDROM) { - #if DEBUG_CDROM +#if DEBUG_CDROM printf ("callback!\n"); - #endif - (*completionProc)(theCDROM); +#endif + (*completionProc) (theCDROM); } else { - #if DEBUG_CDROM +#if DEBUG_CDROM printf ("callback?\n"); - #endif +#endif } } - - #if DEBUG_CDROM + +#if DEBUG_CDROM printf ("thread dying now...\n"); - #endif - +#endif + return 0; } /*}; // extern "C" */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/CDPlayer.h b/src/cdrom/macosx/CDPlayer.h index 5b41128dd..3077c8890 100644 --- a/src/cdrom/macosx/CDPlayer.h +++ b/src/cdrom/macosx/CDPlayer.h @@ -35,35 +35,38 @@ #include "SDL_mutex.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -typedef void (*CDPlayerCompletionProc)(SDL_CD *cdrom) ; + typedef void (*CDPlayerCompletionProc) (SDL_CD * cdrom); -void Lock (); + void Lock (); -void Unlock(); + void Unlock (); -int LoadFile (const FSRef *ref, int startFrame, int endFrame); /* pass -1 to do nothing */ + int LoadFile (const FSRef * ref, int startFrame, int endFrame); /* pass -1 to do nothing */ -int ReleaseFile (); + int ReleaseFile (); -int PlayFile (); + int PlayFile (); -int PauseFile (); + int PauseFile (); -void SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD *cdrom); + void SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD * cdrom); -int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD *theCD); + int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD * theCD); -int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks); + int ListTrackFiles (FSVolumeRefNum theVolume, FSRef * trackFiles, + int numTracks); -int DetectAudioCDVolumes (FSVolumeRefNum *volumes, int numVolumes); + int DetectAudioCDVolumes (FSVolumeRefNum * volumes, int numVolumes); -int GetCurrentFrame (); + int GetCurrentFrame (); #ifdef __cplusplus }; #endif #endif /* __CD_Player__H__ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/SDLOSXCAGuard.c b/src/cdrom/macosx/SDLOSXCAGuard.c index 7689c4ed9..f3e0cee44 100644 --- a/src/cdrom/macosx/SDLOSXCAGuard.c +++ b/src/cdrom/macosx/SDLOSXCAGuard.c @@ -91,109 +91,116 @@ SDLOSXCAGuard =============================================================================*/ -static int SDLOSXCAGuard_Lock(SDLOSXCAGuard *cag) +static int +SDLOSXCAGuard_Lock (SDLOSXCAGuard * cag) { int theAnswer = 0; - - if(pthread_self() != cag->mOwner) - { - OSStatus theError = pthread_mutex_lock(&cag->mMutex); - (void)theError; - assert(theError == 0); - cag->mOwner = pthread_self(); + + if (pthread_self () != cag->mOwner) { + OSStatus theError = pthread_mutex_lock (&cag->mMutex); + (void) theError; + assert (theError == 0); + cag->mOwner = pthread_self (); theAnswer = 1; } return theAnswer; } -static void SDLOSXCAGuard_Unlock(SDLOSXCAGuard *cag) +static void +SDLOSXCAGuard_Unlock (SDLOSXCAGuard * cag) { OSStatus theError; - assert(pthread_self() == cag->mOwner); + assert (pthread_self () == cag->mOwner); cag->mOwner = 0; - theError = pthread_mutex_unlock(&cag->mMutex); - (void)theError; - assert(theError == 0); + theError = pthread_mutex_unlock (&cag->mMutex); + (void) theError; + assert (theError == 0); } -static int SDLOSXCAGuard_Try (SDLOSXCAGuard *cag, int *outWasLocked) +static int +SDLOSXCAGuard_Try (SDLOSXCAGuard * cag, int *outWasLocked) { int theAnswer = 0; *outWasLocked = 0; - - if (pthread_self() == cag->mOwner) { + + if (pthread_self () == cag->mOwner) { theAnswer = 1; *outWasLocked = 0; } else { - OSStatus theError = pthread_mutex_trylock(&cag->mMutex); + OSStatus theError = pthread_mutex_trylock (&cag->mMutex); if (theError == 0) { - cag->mOwner = pthread_self(); + cag->mOwner = pthread_self (); theAnswer = 1; *outWasLocked = 1; } } - + return theAnswer; } -static void SDLOSXCAGuard_Wait(SDLOSXCAGuard *cag) +static void +SDLOSXCAGuard_Wait (SDLOSXCAGuard * cag) { OSStatus theError; - assert(pthread_self() == cag->mOwner); + assert (pthread_self () == cag->mOwner); cag->mOwner = 0; - theError = pthread_cond_wait(&cag->mCondVar, &cag->mMutex); - (void)theError; - assert(theError == 0); - cag->mOwner = pthread_self(); + theError = pthread_cond_wait (&cag->mCondVar, &cag->mMutex); + (void) theError; + assert (theError == 0); + cag->mOwner = pthread_self (); } -static void SDLOSXCAGuard_Notify(SDLOSXCAGuard *cag) +static void +SDLOSXCAGuard_Notify (SDLOSXCAGuard * cag) { - OSStatus theError = pthread_cond_signal(&cag->mCondVar); - (void)theError; - assert(theError == 0); + OSStatus theError = pthread_cond_signal (&cag->mCondVar); + (void) theError; + assert (theError == 0); } -SDLOSXCAGuard *new_SDLOSXCAGuard(void) +SDLOSXCAGuard * +new_SDLOSXCAGuard (void) { OSStatus theError; - SDLOSXCAGuard *cag = (SDLOSXCAGuard *) SDL_malloc(sizeof (SDLOSXCAGuard)); + SDLOSXCAGuard *cag = + (SDLOSXCAGuard *) SDL_malloc (sizeof (SDLOSXCAGuard)); if (cag == NULL) return NULL; - SDL_memset(cag, '\0', sizeof (*cag)); - - #define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m - SET_SDLOSXCAGUARD_METHOD(Lock); - SET_SDLOSXCAGUARD_METHOD(Unlock); - SET_SDLOSXCAGUARD_METHOD(Try); - SET_SDLOSXCAGUARD_METHOD(Wait); - SET_SDLOSXCAGUARD_METHOD(Notify); - #undef SET_SDLOSXCAGUARD_METHOD - - theError = pthread_mutex_init(&cag->mMutex, NULL); - (void)theError; - assert(theError == 0); - - theError = pthread_cond_init(&cag->mCondVar, NULL); - (void)theError; - assert(theError == 0); - + SDL_memset (cag, '\0', sizeof (*cag)); + +#define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m + SET_SDLOSXCAGUARD_METHOD (Lock); + SET_SDLOSXCAGUARD_METHOD (Unlock); + SET_SDLOSXCAGUARD_METHOD (Try); + SET_SDLOSXCAGUARD_METHOD (Wait); + SET_SDLOSXCAGUARD_METHOD (Notify); +#undef SET_SDLOSXCAGUARD_METHOD + + theError = pthread_mutex_init (&cag->mMutex, NULL); + (void) theError; + assert (theError == 0); + + theError = pthread_cond_init (&cag->mCondVar, NULL); + (void) theError; + assert (theError == 0); + cag->mOwner = 0; return cag; } -void delete_SDLOSXCAGuard(SDLOSXCAGuard *cag) +void +delete_SDLOSXCAGuard (SDLOSXCAGuard * cag) { - if (cag != NULL) - { - pthread_mutex_destroy(&cag->mMutex); - pthread_cond_destroy(&cag->mCondVar); - SDL_free(cag); + if (cag != NULL) { + pthread_mutex_destroy (&cag->mMutex); + pthread_cond_destroy (&cag->mCondVar); + SDL_free (cag); } } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/SDLOSXCAGuard.h b/src/cdrom/macosx/SDLOSXCAGuard.h index 520387a5f..f41b11987 100644 --- a/src/cdrom/macosx/SDLOSXCAGuard.h +++ b/src/cdrom/macosx/SDLOSXCAGuard.h @@ -96,21 +96,21 @@ typedef struct S_SDLOSXCAGuard /*public:*/ /* Actions */ /*public:*/ - int (*Lock)(struct S_SDLOSXCAGuard *cag); - void (*Unlock)(struct S_SDLOSXCAGuard *cag); - int (*Try)(struct S_SDLOSXCAGuard *cag, int *outWasLocked); /* returns true if lock is free, false if not */ - void (*Wait)(struct S_SDLOSXCAGuard *cag); - void (*Notify)(struct S_SDLOSXCAGuard *cag); + int (*Lock) (struct S_SDLOSXCAGuard * cag); + void (*Unlock) (struct S_SDLOSXCAGuard * cag); + int (*Try) (struct S_SDLOSXCAGuard * cag, int *outWasLocked); /* returns true if lock is free, false if not */ + void (*Wait) (struct S_SDLOSXCAGuard * cag); + void (*Notify) (struct S_SDLOSXCAGuard * cag); /* Implementation */ /*protected:*/ pthread_mutex_t mMutex; - pthread_cond_t mCondVar; - pthread_t mOwner; + pthread_cond_t mCondVar; + pthread_t mOwner; } SDLOSXCAGuard; -SDLOSXCAGuard *new_SDLOSXCAGuard(void); -void delete_SDLOSXCAGuard(SDLOSXCAGuard *cag); +SDLOSXCAGuard *new_SDLOSXCAGuard (void); +void delete_SDLOSXCAGuard (SDLOSXCAGuard * cag); #endif - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/SDL_syscdrom.c b/src/cdrom/macosx/SDL_syscdrom.c index ea43d8bde..1bc120156 100644 --- a/src/cdrom/macosx/SDL_syscdrom.c +++ b/src/cdrom/macosx/SDL_syscdrom.c @@ -27,126 +27,131 @@ #pragma mark -- Globals -- -static FSRef** tracks; -static FSVolumeRefNum* volumes; -static CDstatus status; -static int nextTrackFrame; -static int nextTrackFramesRemaining; -static int fakeCD; -static int currentTrack; -static int didReadTOC; -static int cacheTOCNumTracks; -static int currentDrive; /* Only allow 1 drive in use at a time */ +static FSRef **tracks; +static FSVolumeRefNum *volumes; +static CDstatus status; +static int nextTrackFrame; +static int nextTrackFramesRemaining; +static int fakeCD; +static int currentTrack; +static int didReadTOC; +static int cacheTOCNumTracks; +static int currentDrive; /* Only allow 1 drive in use at a time */ #pragma mark -- Prototypes -- -static const char *SDL_SYS_CDName (int drive); -static int SDL_SYS_CDOpen (int drive); -static int SDL_SYS_CDGetTOC (SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay (SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause (SDL_CD *cdrom); -static int SDL_SYS_CDResume (SDL_CD *cdrom); -static int SDL_SYS_CDStop (SDL_CD *cdrom); -static int SDL_SYS_CDEject (SDL_CD *cdrom); -static void SDL_SYS_CDClose (SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); #pragma mark -- Helper Functions -- /* Read a list of tracks from the volume */ -static int LoadTracks (SDL_CD *cdrom) +static int +LoadTracks (SDL_CD * cdrom) { /* Check if tracks are already loaded */ - if ( tracks[cdrom->id] != NULL ) + if (tracks[cdrom->id] != NULL) return 0; - + /* Allocate memory for tracks */ - tracks[cdrom->id] = (FSRef*) SDL_calloc (1, sizeof(**tracks) * cdrom->numtracks); + tracks[cdrom->id] = + (FSRef *) SDL_calloc (1, sizeof (**tracks) * cdrom->numtracks); if (tracks[cdrom->id] == NULL) { SDL_OutOfMemory (); return -1; } - + /* Load tracks */ - if (ListTrackFiles (volumes[cdrom->id], tracks[cdrom->id], cdrom->numtracks) < 0) + if (ListTrackFiles + (volumes[cdrom->id], tracks[cdrom->id], cdrom->numtracks) < 0) return -1; return 0; } /* Find a file for a given start frame and length */ -static FSRef* GetFileForOffset (SDL_CD *cdrom, int start, int length, int *outStartFrame, int *outStopFrame) +static FSRef * +GetFileForOffset (SDL_CD * cdrom, int start, int length, int *outStartFrame, + int *outStopFrame) { int i; - + for (i = 0; i < cdrom->numtracks; i++) { - + if (cdrom->track[i].offset <= start && start < (cdrom->track[i].offset + cdrom->track[i].length)) break; } - + if (i == cdrom->numtracks) return NULL; - + currentTrack = i; *outStartFrame = start - cdrom->track[i].offset; - + if ((*outStartFrame + length) < cdrom->track[i].length) { *outStopFrame = *outStartFrame + length; length = 0; nextTrackFrame = -1; nextTrackFramesRemaining = -1; - } - else { + } else { *outStopFrame = -1; length -= cdrom->track[i].length - *outStartFrame; - nextTrackFrame = cdrom->track[i+1].offset; + nextTrackFrame = cdrom->track[i + 1].offset; nextTrackFramesRemaining = length; } - + return &tracks[cdrom->id][i]; } /* Setup another file for playback, or stop playback (called from another thread) */ -static void CompletionProc (SDL_CD *cdrom) +static void +CompletionProc (SDL_CD * cdrom) { - + Lock (); - + if (nextTrackFrame > 0 && nextTrackFramesRemaining > 0) { - + /* Load the next file to play */ int startFrame, stopFrame; FSRef *file; - + PauseFile (); ReleaseFile (); - - file = GetFileForOffset (cdrom, nextTrackFrame, - nextTrackFramesRemaining, &startFrame, &stopFrame); - + + file = GetFileForOffset (cdrom, nextTrackFrame, + nextTrackFramesRemaining, &startFrame, + &stopFrame); + if (file == NULL) { status = CD_STOPPED; Unlock (); return; } - + LoadFile (file, startFrame, stopFrame); - + SetCompletionProc (CompletionProc, cdrom); - + PlayFile (); - } - else { - + } else { + /* Release the current file */ PauseFile (); ReleaseFile (); status = CD_STOPPED; } - + Unlock (); } @@ -154,127 +159,131 @@ static void CompletionProc (SDL_CD *cdrom) #pragma mark -- Driver Functions -- /* Initialize */ -int SDL_SYS_CDInit (void) +int +SDL_SYS_CDInit (void) { /* Initialize globals */ volumes = NULL; - tracks = NULL; - status = CD_STOPPED; + tracks = NULL; + status = CD_STOPPED; nextTrackFrame = -1; nextTrackFramesRemaining = -1; - fakeCD = SDL_FALSE; + fakeCD = SDL_FALSE; currentTrack = -1; didReadTOC = SDL_FALSE; cacheTOCNumTracks = -1; currentDrive = -1; - + /* Fill in function pointers */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; /* - Read the list of "drives" - - This is currently a hack that infers drives from - mounted audio CD volumes, rather than - actual CD-ROM devices - which means it may not - act as expected sometimes. - */ - + Read the list of "drives" + + This is currently a hack that infers drives from + mounted audio CD volumes, rather than + actual CD-ROM devices - which means it may not + act as expected sometimes. + */ + /* Find out how many cd volumes are mounted */ SDL_numcds = DetectAudioCDVolumes (NULL, 0); /* - If there are no volumes, fake a cd device - so tray empty can be reported. - */ + If there are no volumes, fake a cd device + so tray empty can be reported. + */ if (SDL_numcds == 0) { - + fakeCD = SDL_TRUE; SDL_numcds = 1; status = CD_TRAYEMPTY; - + return 0; } - + /* Allocate space for volumes */ - volumes = (FSVolumeRefNum*) SDL_calloc (1, sizeof(*volumes) * SDL_numcds); + volumes = + (FSVolumeRefNum *) SDL_calloc (1, sizeof (*volumes) * SDL_numcds); if (volumes == NULL) { SDL_OutOfMemory (); return -1; } - + /* Allocate space for tracks */ - tracks = (FSRef**) SDL_calloc (1, sizeof(*tracks) * (SDL_numcds + 1)); + tracks = (FSRef **) SDL_calloc (1, sizeof (*tracks) * (SDL_numcds + 1)); if (tracks == NULL) { SDL_OutOfMemory (); return -1; } - + /* Mark the end of the tracks array */ - tracks[ SDL_numcds ] = (FSRef*)-1; - + tracks[SDL_numcds] = (FSRef *) - 1; + /* - Redetect, now save all volumes for later - Update SDL_numcds just in case it changed - */ + Redetect, now save all volumes for later + Update SDL_numcds just in case it changed + */ { int numVolumes = SDL_numcds; - + SDL_numcds = DetectAudioCDVolumes (volumes, numVolumes); - + /* If more cds suddenly show up, ignore them */ if (SDL_numcds > numVolumes) { SDL_SetError ("Some CD's were added but they will be ignored"); SDL_numcds = numVolumes; } } - + return 0; } /* Shutdown and cleanup */ -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - ReleaseFile(); - + ReleaseFile (); + if (volumes != NULL) free (volumes); - + if (tracks != NULL) { - + FSRef **ptr; - for (ptr = tracks; *ptr != (FSRef*)-1; ptr++) + for (ptr = tracks; *ptr != (FSRef *) - 1; ptr++) if (*ptr != NULL) free (*ptr); - + free (tracks); } } /* Get the Unix disk name of the volume */ -static const char *SDL_SYS_CDName (int drive) +static const char * +SDL_SYS_CDName (int drive) { - OSStatus err = noErr; - HParamBlockRec pb; - GetVolParmsInfoBuffer volParmsInfo; - + OSStatus err = noErr; + HParamBlockRec pb; + GetVolParmsInfoBuffer volParmsInfo; + if (fakeCD) return "Fake CD-ROM Device"; pb.ioParam.ioNamePtr = NULL; pb.ioParam.ioVRefNum = volumes[drive]; - pb.ioParam.ioBuffer = (Ptr)&volParmsInfo; - pb.ioParam.ioReqCount = (SInt32)sizeof(volParmsInfo); - err = PBHGetVolParmsSync(&pb); + pb.ioParam.ioBuffer = (Ptr) & volParmsInfo; + pb.ioParam.ioReqCount = (SInt32) sizeof (volParmsInfo); + err = PBHGetVolParmsSync (&pb); if (err != noErr) { SDL_SetError ("PBHGetVolParmsSync returned %d", err); @@ -285,172 +294,180 @@ static const char *SDL_SYS_CDName (int drive) } /* Open the "device" */ -static int SDL_SYS_CDOpen (int drive) +static int +SDL_SYS_CDOpen (int drive) { /* Only allow 1 device to be open */ if (currentDrive >= 0) { SDL_SetError ("Only one cdrom is supported"); return -1; - } - else + } else currentDrive = drive; return drive; } /* Get the table of contents */ -static int SDL_SYS_CDGetTOC (SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { if (fakeCD) { SDL_SetError (kErrorFakeDevice); return -1; } - + if (didReadTOC) { cdrom->numtracks = cacheTOCNumTracks; return 0; } - - + + ReadTOCData (volumes[cdrom->id], cdrom); didReadTOC = SDL_TRUE; cacheTOCNumTracks = cdrom->numtracks; - + return 0; } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { if (position) { int trackFrame; - + Lock (); trackFrame = GetCurrentFrame (); Unlock (); - + *position = cdrom->track[currentTrack].offset + trackFrame; } - + return status; } /* Start playback */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { int startFrame, stopFrame; FSRef *ref; - + if (fakeCD) { SDL_SetError (kErrorFakeDevice); return -1; } - - Lock(); - + + Lock (); + if (LoadTracks (cdrom) < 0) return -2; - + if (PauseFile () < 0) return -3; - + if (ReleaseFile () < 0) return -4; - + ref = GetFileForOffset (cdrom, start, length, &startFrame, &stopFrame); if (ref == NULL) { - SDL_SetError ("SDL_SYS_CDPlay: No file for start=%d, length=%d", start, length); + SDL_SetError ("SDL_SYS_CDPlay: No file for start=%d, length=%d", + start, length); return -5; } - + if (LoadFile (ref, startFrame, stopFrame) < 0) return -6; - + SetCompletionProc (CompletionProc, cdrom); - + if (PlayFile () < 0) return -7; - + status = CD_PLAYING; - - Unlock(); - + + Unlock (); + return 0; } /* Pause playback */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { if (fakeCD) { SDL_SetError (kErrorFakeDevice); return -1; } - + Lock (); - + if (PauseFile () < 0) { Unlock (); return -2; } - + status = CD_PAUSED; - + Unlock (); - + return 0; } /* Resume playback */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { if (fakeCD) { SDL_SetError (kErrorFakeDevice); return -1; } - + Lock (); - + if (PlayFile () < 0) { Unlock (); return -2; } - + status = CD_PLAYING; - + Unlock (); - + return 0; } /* Stop playback */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { if (fakeCD) { SDL_SetError (kErrorFakeDevice); return -1; } - + Lock (); - + if (PauseFile () < 0) { Unlock (); return -2; } - + if (ReleaseFile () < 0) { Unlock (); return -3; } - + status = CD_STOPPED; - + Unlock (); - + return 0; } /* Eject the CD-ROM (Unmount the volume) */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { OSStatus err; pid_t dissenter; @@ -459,47 +476,49 @@ static int SDL_SYS_CDEject(SDL_CD *cdrom) SDL_SetError (kErrorFakeDevice); return -1; } - + Lock (); - + if (PauseFile () < 0) { Unlock (); return -2; } - + if (ReleaseFile () < 0) { Unlock (); return -3; } - + status = CD_STOPPED; - - /* Eject the volume */ - err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter); - if (err != noErr) { + /* Eject the volume */ + err = FSEjectVolumeSync (volumes[cdrom->id], kNilOptions, &dissenter); + + if (err != noErr) { Unlock (); - SDL_SetError ("PBUnmountVol returned %d", err); - return -4; - } - + SDL_SetError ("PBUnmountVol returned %d", err); + return -4; + } + status = CD_TRAYEMPTY; /* Invalidate volume and track info */ volumes[cdrom->id] = 0; free (tracks[cdrom->id]); tracks[cdrom->id] = NULL; - + Unlock (); - + return 0; } /* Close the CD-ROM */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { currentDrive = -1; return; } #endif /* SDL_CDROM_MACOSX */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/macosx/SDL_syscdrom_c.h b/src/cdrom/macosx/SDL_syscdrom_c.h index cc13198ef..4c263a47a 100644 --- a/src/cdrom/macosx/SDL_syscdrom_c.h +++ b/src/cdrom/macosx/SDL_syscdrom_c.h @@ -133,4 +133,4 @@ #include "CDPlayer.h" #define kErrorFakeDevice "Error: Cannot proceed since we're faking a CD-ROM device. Reinit the CD-ROM subsystem to scan for new volumes." - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/mint/SDL_syscdrom.c b/src/cdrom/mint/SDL_syscdrom.c index c817899b0..ce9ebe860 100644 --- a/src/cdrom/mint/SDL_syscdrom.c +++ b/src/cdrom/mint/SDL_syscdrom.c @@ -46,272 +46,294 @@ (errno == EINVAL) || (errno == ENOMEDIUM)) /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 32 +#define MAX_DRIVES 32 -typedef struct { - unsigned char device[3]; /* Physical device letter + ':' + '\0' */ - metaopen_t metaopen; /* Infos on opened drive */ +typedef struct +{ + unsigned char device[3]; /* Physical device letter + ':' + '\0' */ + metaopen_t metaopen; /* Infos on opened drive */ } metados_drive_t; static metados_drive_t metados_drives[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static void SDL_SYS_CDClose(SDL_CD *cdrom); -static int SDL_SYS_CDioctl(int id, int command, void *arg); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); - -int SDL_SYS_CDInit(void) +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static void SDL_SYS_CDClose (SDL_CD * cdrom); +static int SDL_SYS_CDioctl (int id, int command, void *arg); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); + +int +SDL_SYS_CDInit (void) { - metainit_t metainit={0,0,0,0}; - metaopen_t metaopen; - int i, handle; - struct cdrom_subchnl info; + metainit_t metainit = { 0, 0, 0, 0 }; + metaopen_t metaopen; + int i, handle; + struct cdrom_subchnl info; - Metainit(&metainit); - if (metainit.version == NULL) { + Metainit (&metainit); + if (metainit.version == NULL) { #ifdef DEBUG_CDROM - fprintf(stderr, "MetaDOS not installed\n"); + fprintf (stderr, "MetaDOS not installed\n"); #endif - return -1; - } + return -1; + } - if (metainit.drives_map == 0) { + if (metainit.drives_map == 0) { #ifdef DEBUG_CDROM - fprintf(stderr, "No MetaDOS devices present\n"); + fprintf (stderr, "No MetaDOS devices present\n"); #endif - return -1; - } - - SDL_numcds = 0; - - for (i='A'; i<='Z'; i++) { - metados_drives[SDL_numcds].device[0] = 0; - metados_drives[SDL_numcds].device[1] = ':'; - metados_drives[SDL_numcds].device[2] = 0; - - if (metainit.drives_map & (1<<(i-'A'))) { - handle = Metaopen(i, &metaopen); - if (handle == 0) { - - info.cdsc_format = CDROM_MSF; - if ( (Metaioctl(i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0) || ERRNO_TRAYEMPTY(errno) ) { - metados_drives[SDL_numcds].device[0] = i; - ++SDL_numcds; - } - - Metaclose(i); - } - } - } - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - - return 0; + return -1; + } + + SDL_numcds = 0; + + for (i = 'A'; i <= 'Z'; i++) { + metados_drives[SDL_numcds].device[0] = 0; + metados_drives[SDL_numcds].device[1] = ':'; + metados_drives[SDL_numcds].device[2] = 0; + + if (metainit.drives_map & (1 << (i - 'A'))) { + handle = Metaopen (i, &metaopen); + if (handle == 0) { + + info.cdsc_format = CDROM_MSF; + if ((Metaioctl + (i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0) + || ERRNO_TRAYEMPTY (errno)) { + metados_drives[SDL_numcds].device[0] = i; + ++SDL_numcds; + } + + Metaclose (i); + } + } + } + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + + return 0; } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - SDL_numcds = 0; + SDL_numcds = 0; } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(metados_drives[drive].device); + return (metados_drives[drive].device); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - int handle; + int handle; - handle = Metaopen(metados_drives[drive].device[0], &(metados_drives[drive].metaopen)); - if (handle == 0) { - return drive; - } + handle = + Metaopen (metados_drives[drive].device[0], + &(metados_drives[drive].metaopen)); + if (handle == 0) { + return drive; + } - return -1; + return -1; } -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - Metaclose(metados_drives[cdrom->id].device[0]); + Metaclose (metados_drives[cdrom->id].device[0]); } -static int SDL_SYS_CDioctl(int id, int command, void *arg) +static int +SDL_SYS_CDioctl (int id, int command, void *arg) { - int retval; - - retval = Metaioctl(metados_drives[id].device[0], METADOS_IOCTL_MAGIC, command, arg); - if ( retval < 0 ) { - SDL_SetError("ioctl() error: %s", strerror(errno)); - } - return(retval); + int retval; + + retval = + Metaioctl (metados_drives[id].device[0], METADOS_IOCTL_MAGIC, command, + arg); + if (retval < 0) { + SDL_SetError ("ioctl() error: %s", strerror (errno)); + } + return (retval); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - int i,okay; - struct cdrom_tochdr toc; - struct cdrom_tocentry entry; - - /* Use standard ioctl() */ - if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc)<0) { - return -1; - } - - cdrom->numtracks = toc.cdth_trk1-toc.cdth_trk0+1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { - cdrom->numtracks = SDL_MAX_TRACKS; - } - - /* Read all the track TOC entries */ - okay=1; - for ( i=0; i<=cdrom->numtracks; ++i ) { - if ( i == cdrom->numtracks ) { - cdrom->track[i].id = CDROM_LEADOUT; - } else { - cdrom->track[i].id = toc.cdth_trk0+i; - } - entry.cdte_track = cdrom->track[i].id; - entry.cdte_format = CDROM_MSF; - if ( SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, &entry) < 0 ) { - okay=0; - break; - } else { - if ( entry.cdte_ctrl & CDROM_DATA_TRACK ) { - cdrom->track[i].type = SDL_DATA_TRACK; - } else { - cdrom->track[i].type = SDL_AUDIO_TRACK; - } - cdrom->track[i].offset = MSF_TO_FRAMES( - entry.cdte_addr.msf.minute, - entry.cdte_addr.msf.second, - entry.cdte_addr.msf.frame); - cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i-1].length = cdrom->track[i].offset-cdrom->track[i-1].offset; - } - } - } - - return(okay ? 0 : -1); + int i, okay; + struct cdrom_tochdr toc; + struct cdrom_tocentry entry; + + /* Use standard ioctl() */ + if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCHDR, &toc) < 0) { + return -1; + } + + cdrom->numtracks = toc.cdth_trk1 - toc.cdth_trk0 + 1; + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; + } + + /* Read all the track TOC entries */ + okay = 1; + for (i = 0; i <= cdrom->numtracks; ++i) { + if (i == cdrom->numtracks) { + cdrom->track[i].id = CDROM_LEADOUT; + } else { + cdrom->track[i].id = toc.cdth_trk0 + i; + } + entry.cdte_track = cdrom->track[i].id; + entry.cdte_format = CDROM_MSF; + if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCENTRY, &entry) < 0) { + okay = 0; + break; + } else { + if (entry.cdte_ctrl & CDROM_DATA_TRACK) { + cdrom->track[i].type = SDL_DATA_TRACK; + } else { + cdrom->track[i].type = SDL_AUDIO_TRACK; + } + cdrom->track[i].offset = + MSF_TO_FRAMES (entry.cdte_addr.msf.minute, + entry.cdte_addr.msf.second, + entry.cdte_addr.msf.frame); + cdrom->track[i].length = 0; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; + } + } + } + + return (okay ? 0 : -1); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; - struct cdrom_tochdr toc; - struct cdrom_subchnl info; - - info.cdsc_format = CDROM_MSF; - if ( SDL_SYS_CDioctl(cdrom->id, CDROMSUBCHNL, &info) < 0 ) { - if ( ERRNO_TRAYEMPTY(errno) ) { - status = CD_TRAYEMPTY; - } else { - status = CD_ERROR; - } - } else { - switch (info.cdsc_audiostatus) { - case CDROM_AUDIO_INVALID: - case CDROM_AUDIO_NO_STATUS: - /* Try to determine if there's a CD available */ - if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc)==0) { - status = CD_STOPPED; - } else { - status = CD_TRAYEMPTY; - } - break; - case CDROM_AUDIO_COMPLETED: - status = CD_STOPPED; - break; - case CDROM_AUDIO_PLAY: - status = CD_PLAYING; - break; - case CDROM_AUDIO_PAUSED: - /* Workaround buggy CD-ROM drive */ - if ( info.cdsc_trk == CDROM_LEADOUT ) { - status = CD_STOPPED; - } else { - status = CD_PAUSED; - } - break; - default: - status = CD_ERROR; - break; - } - } - if ( position ) { - if ( status == CD_PLAYING || (status == CD_PAUSED) ) { - *position = MSF_TO_FRAMES( - info.cdsc_absaddr.msf.minute, - info.cdsc_absaddr.msf.second, - info.cdsc_absaddr.msf.frame); - } else { - *position = 0; - } - } - return(status); + CDstatus status; + struct cdrom_tochdr toc; + struct cdrom_subchnl info; + + info.cdsc_format = CDROM_MSF; + if (SDL_SYS_CDioctl (cdrom->id, CDROMSUBCHNL, &info) < 0) { + if (ERRNO_TRAYEMPTY (errno)) { + status = CD_TRAYEMPTY; + } else { + status = CD_ERROR; + } + } else { + switch (info.cdsc_audiostatus) { + case CDROM_AUDIO_INVALID: + case CDROM_AUDIO_NO_STATUS: + /* Try to determine if there's a CD available */ + if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCHDR, &toc) == 0) { + status = CD_STOPPED; + } else { + status = CD_TRAYEMPTY; + } + break; + case CDROM_AUDIO_COMPLETED: + status = CD_STOPPED; + break; + case CDROM_AUDIO_PLAY: + status = CD_PLAYING; + break; + case CDROM_AUDIO_PAUSED: + /* Workaround buggy CD-ROM drive */ + if (info.cdsc_trk == CDROM_LEADOUT) { + status = CD_STOPPED; + } else { + status = CD_PAUSED; + } + break; + default: + status = CD_ERROR; + break; + } + } + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) { + *position = MSF_TO_FRAMES (info.cdsc_absaddr.msf.minute, + info.cdsc_absaddr.msf.second, + info.cdsc_absaddr.msf.frame); + } else { + *position = 0; + } + } + return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - struct cdrom_msf playtime; + struct cdrom_msf playtime; - FRAMES_TO_MSF(start, - &playtime.cdmsf_min0, &playtime.cdmsf_sec0, &playtime.cdmsf_frame0); - FRAMES_TO_MSF(start+length, - &playtime.cdmsf_min1, &playtime.cdmsf_sec1, &playtime.cdmsf_frame1); + FRAMES_TO_MSF (start, + &playtime.cdmsf_min0, &playtime.cdmsf_sec0, + &playtime.cdmsf_frame0); + FRAMES_TO_MSF (start + length, &playtime.cdmsf_min1, &playtime.cdmsf_sec1, + &playtime.cdmsf_frame1); #ifdef DEBUG_CDROM - fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", - playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, - playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); + fprintf (stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", + playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, + playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); #endif - return SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime); + return SDL_SYS_CDioctl (cdrom->id, CDROMPLAYMSF, &playtime); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - return SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0); + return SDL_SYS_CDioctl (cdrom->id, CDROMPAUSE, 0); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - return SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0); + return SDL_SYS_CDioctl (cdrom->id, CDROMRESUME, 0); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - return SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0); + return SDL_SYS_CDioctl (cdrom->id, CDROMSTOP, 0); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0); + return SDL_SYS_CDioctl (cdrom->id, CDROMEJECT, 0); } #endif /* SDL_CDROM_MINT */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/openbsd/SDL_syscdrom.c b/src/cdrom/openbsd/SDL_syscdrom.c index 1d77c82c4..766678004 100644 --- a/src/cdrom/openbsd/SDL_syscdrom.c +++ b/src/cdrom/openbsd/SDL_syscdrom.c @@ -39,23 +39,23 @@ /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 16 +#define MAX_DRIVES 16 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; static dev_t SDL_cdmode[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); /* Some ioctl() errno values which occur when the tray is empty */ #define ERRNO_TRAYEMPTY(errno) \ @@ -63,353 +63,369 @@ static void SDL_SYS_CDClose(SDL_CD *cdrom); (errno == ENODEV)) /* Check a drive to see if it is a CD-ROM */ -static int CheckDrive(char *drive, struct stat *stbuf) +static int +CheckDrive (char *drive, struct stat *stbuf) { - int is_cd, cdfd; - struct ioc_read_subchannel info; - - /* If it doesn't exist, return -1 */ - if ( stat(drive, stbuf) < 0 ) { - return(-1); - } - - /* If it does exist, verify that it's an available CD-ROM */ - is_cd = 0; - if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { - cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); - if ( cdfd >= 0 ) { - info.address_format = CD_MSF_FORMAT; - info.data_format = CD_CURRENT_POSITION; - info.data_len = 0; - info.data = NULL; - /* Under Linux, EIO occurs when a disk is not present. - This isn't 100% reliable, so we use the USE_MNTENT - code above instead. - */ - if ( (ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) || - ERRNO_TRAYEMPTY(errno) ) { - is_cd = 1; - } - close(cdfd); - } - else if (ERRNO_TRAYEMPTY(errno)) - is_cd = 1; - } - return(is_cd); + int is_cd, cdfd; + struct ioc_read_subchannel info; + + /* If it doesn't exist, return -1 */ + if (stat (drive, stbuf) < 0) { + return (-1); + } + + /* If it does exist, verify that it's an available CD-ROM */ + is_cd = 0; + if (S_ISCHR (stbuf->st_mode) || S_ISBLK (stbuf->st_mode)) { + cdfd = open (drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0); + if (cdfd >= 0) { + info.address_format = CD_MSF_FORMAT; + info.data_format = CD_CURRENT_POSITION; + info.data_len = 0; + info.data = NULL; + /* Under Linux, EIO occurs when a disk is not present. + This isn't 100% reliable, so we use the USE_MNTENT + code above instead. + */ + if ((ioctl (cdfd, CDIOCREADSUBCHANNEL, &info) == 0) || + ERRNO_TRAYEMPTY (errno)) { + is_cd = 1; + } + close (cdfd); + } else if (ERRNO_TRAYEMPTY (errno)) + is_cd = 1; + } + return (is_cd); } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive, struct stat *stbuf) +static void +AddDrive (char *drive, struct stat *stbuf) { - int i; - - if ( SDL_numcds < MAX_DRIVES ) { - /* Check to make sure it's not already in our list. - This can happen when we see a drive via symbolic link. - */ - for ( i=0; ist_rdev == SDL_cdmode[i] ) { + int i; + + if (SDL_numcds < MAX_DRIVES) { + /* Check to make sure it's not already in our list. + This can happen when we see a drive via symbolic link. + */ + for (i = 0; i < SDL_numcds; ++i) { + if (stbuf->st_rdev == SDL_cdmode[i]) { #ifdef DEBUG_CDROM - fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); + fprintf (stderr, "Duplicate drive detected: %s == %s\n", + drive, SDL_cdlist[i]); #endif - return; - } - } - - /* Add this drive to our list */ - i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - SDL_cdmode[i] = stbuf->st_rdev; - ++SDL_numcds; + return; + } + } + + /* Add this drive to our list */ + i = SDL_numcds; + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + SDL_cdmode[i] = stbuf->st_rdev; + ++SDL_numcds; #ifdef DEBUG_CDROM - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif - } + } } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - static char *checklist[] = { + static char *checklist[] = { #if defined(__OPENBSD__) - "?0 cd?c", "cdrom", NULL + "?0 cd?c", "cdrom", NULL #elif defined(__NETBSD__) - "?0 cd?d", "?0 cd?c", "cdrom", NULL + "?0 cd?d", "?0 cd?c", "cdrom", NULL #else - "?0 cd?c", "?0 acd?c", "cdrom", NULL + "?0 cd?c", "?0 acd?c", "cdrom", NULL #endif - }; - char *SDLcdrom; - int i, j, exists; - char drive[32]; - struct stat stbuf; - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Look in the environment for our CD-ROM drive list */ - SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ - if ( SDLcdrom != NULL ) { - char *cdpath, *delim; - size_t len = SDL_strlen(SDLcdrom)+1; - cdpath = SDL_stack_alloc(char, len); - if ( cdpath != NULL ) { - SDL_strlcpy(cdpath, SDLcdrom, len); - SDLcdrom = cdpath; - do { - delim = SDL_strchr(SDLcdrom, ':'); - if ( delim ) { - *delim++ = '\0'; - } - if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { - AddDrive(SDLcdrom, &stbuf); - } - if ( delim ) { - SDLcdrom = delim; - } else { - SDLcdrom = NULL; - } - } while ( SDLcdrom ); - SDL_stack_free(cdpath); - } - - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } - } - - /* Scan the system for CD-ROM drives */ - for ( i=0; checklist[i]; ++i ) { - if ( checklist[i][0] == '?' ) { - char *insert; - exists = 1; - for ( j=checklist[i][1]; exists; ++j ) { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]); - insert = SDL_strchr(drive, '?'); - if ( insert != NULL ) { - *insert = j; - } - switch (CheckDrive(drive, &stbuf)) { - /* Drive exists and is a CD-ROM */ - case 1: - AddDrive(drive, &stbuf); - break; - /* Drive exists, but isn't a CD-ROM */ - case 0: - break; - /* Drive doesn't exist */ - case -1: - exists = 0; - break; - } - } - } else { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); - if ( CheckDrive(drive, &stbuf) > 0 ) { - AddDrive(drive, &stbuf); - } - } - } - return(0); + }; + char *SDLcdrom; + int i, j, exists; + char drive[32]; + struct stat stbuf; + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Look in the environment for our CD-ROM drive list */ + SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ + if (SDLcdrom != NULL) { + char *cdpath, *delim; + size_t len = SDL_strlen (SDLcdrom) + 1; + cdpath = SDL_stack_alloc (char, len); + if (cdpath != NULL) { + SDL_strlcpy (cdpath, SDLcdrom, len); + SDLcdrom = cdpath; + do { + delim = SDL_strchr (SDLcdrom, ':'); + if (delim) { + *delim++ = '\0'; + } + if (CheckDrive (SDLcdrom, &stbuf) > 0) { + AddDrive (SDLcdrom, &stbuf); + } + if (delim) { + SDLcdrom = delim; + } else { + SDLcdrom = NULL; + } + } + while (SDLcdrom); + SDL_stack_free (cdpath); + } + + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } + } + + /* Scan the system for CD-ROM drives */ + for (i = 0; checklist[i]; ++i) { + if (checklist[i][0] == '?') { + char *insert; + exists = 1; + for (j = checklist[i][1]; exists; ++j) { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + &checklist[i][3]); + insert = SDL_strchr (drive, '?'); + if (insert != NULL) { + *insert = j; + } + switch (CheckDrive (drive, &stbuf)) { + /* Drive exists and is a CD-ROM */ + case 1: + AddDrive (drive, &stbuf); + break; + /* Drive exists, but isn't a CD-ROM */ + case 0: + break; + /* Drive doesn't exist */ + case -1: + exists = 0; + break; + } + } + } else { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + checklist[i]); + if (CheckDrive (drive, &stbuf) > 0) { + AddDrive (drive, &stbuf); + } + } + } + return (0); } /* General ioctl() CD-ROM command function */ -static int SDL_SYS_CDioctl(int id, int command, void *arg) +static int +SDL_SYS_CDioctl (int id, int command, void *arg) { - int retval; + int retval; - retval = ioctl(id, command, arg); - if ( retval < 0 ) { - SDL_SetError("ioctl() error: %s", strerror(errno)); - } - return(retval); + retval = ioctl (id, command, arg); + if (retval < 0) { + SDL_SetError ("ioctl() error: %s", strerror (errno)); + } + return (retval); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - return(open(SDL_cdlist[drive], (O_RDONLY|O_EXCL|O_NONBLOCK), 0)); + return (open (SDL_cdlist[drive], (O_RDONLY | O_EXCL | O_NONBLOCK), 0)); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - struct ioc_toc_header toc; - int i, okay; - struct ioc_read_toc_entry entry; - struct cd_toc_entry data; - - okay = 0; - if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0 ) { - cdrom->numtracks = toc.ending_track-toc.starting_track+1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { - cdrom->numtracks = SDL_MAX_TRACKS; - } - /* Read all the track TOC entries */ - for ( i=0; i<=cdrom->numtracks; ++i ) { - if ( i == cdrom->numtracks ) { - cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */ - } else { - cdrom->track[i].id = toc.starting_track+i; - } - entry.starting_track = cdrom->track[i].id; - entry.address_format = CD_MSF_FORMAT; - entry.data_len = sizeof(data); - entry.data = &data; - if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, - &entry) < 0 ) { - break; - } else { - cdrom->track[i].type = data.control; - cdrom->track[i].offset = MSF_TO_FRAMES( - data.addr.msf.minute, - data.addr.msf.second, - data.addr.msf.frame); - cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i-1].length = - cdrom->track[i].offset- - cdrom->track[i-1].offset; - } - } - } - if ( i == (cdrom->numtracks+1) ) { - okay = 1; - } - } - return(okay ? 0 : -1); + struct ioc_toc_header toc; + int i, okay; + struct ioc_read_toc_entry entry; + struct cd_toc_entry data; + + okay = 0; + if (SDL_SYS_CDioctl (cdrom->id, CDIOREADTOCHEADER, &toc) == 0) { + cdrom->numtracks = toc.ending_track - toc.starting_track + 1; + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; + } + /* Read all the track TOC entries */ + for (i = 0; i <= cdrom->numtracks; ++i) { + if (i == cdrom->numtracks) { + cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */ + } else { + cdrom->track[i].id = toc.starting_track + i; + } + entry.starting_track = cdrom->track[i].id; + entry.address_format = CD_MSF_FORMAT; + entry.data_len = sizeof (data); + entry.data = &data; + if (SDL_SYS_CDioctl (cdrom->id, CDIOREADTOCENTRYS, &entry) < 0) { + break; + } else { + cdrom->track[i].type = data.control; + cdrom->track[i].offset = + MSF_TO_FRAMES (data.addr.msf.minute, + data.addr.msf.second, data.addr.msf.frame); + cdrom->track[i].length = 0; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; + } + } + } + if (i == (cdrom->numtracks + 1)) { + okay = 1; + } + } + return (okay ? 0 : -1); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; - struct ioc_toc_header toc; - struct ioc_read_subchannel info; - struct cd_sub_channel_info data; - - info.address_format = CD_MSF_FORMAT; - info.data_format = CD_CURRENT_POSITION; - info.track = 0; - info.data_len = sizeof(data); - info.data = &data; - if ( ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0 ) { - if ( ERRNO_TRAYEMPTY(errno) ) { - status = CD_TRAYEMPTY; - } else { - status = CD_ERROR; - } - } else { - switch (data.header.audio_status) { - case CD_AS_AUDIO_INVALID: - case CD_AS_NO_STATUS: - /* Try to determine if there's a CD available */ - if (ioctl(cdrom->id,CDIOREADTOCHEADER,&toc)==0) - status = CD_STOPPED; - else - status = CD_TRAYEMPTY; - break; - case CD_AS_PLAY_COMPLETED: - status = CD_STOPPED; - break; - case CD_AS_PLAY_IN_PROGRESS: - status = CD_PLAYING; - break; - case CD_AS_PLAY_PAUSED: - status = CD_PAUSED; - break; - default: - status = CD_ERROR; - break; - } - } - if ( position ) { - if ( status == CD_PLAYING || (status == CD_PAUSED) ) { - *position = MSF_TO_FRAMES( - data.what.position.absaddr.msf.minute, - data.what.position.absaddr.msf.second, - data.what.position.absaddr.msf.frame); - } else { - *position = 0; - } - } - return(status); + CDstatus status; + struct ioc_toc_header toc; + struct ioc_read_subchannel info; + struct cd_sub_channel_info data; + + info.address_format = CD_MSF_FORMAT; + info.data_format = CD_CURRENT_POSITION; + info.track = 0; + info.data_len = sizeof (data); + info.data = &data; + if (ioctl (cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0) { + if (ERRNO_TRAYEMPTY (errno)) { + status = CD_TRAYEMPTY; + } else { + status = CD_ERROR; + } + } else { + switch (data.header.audio_status) { + case CD_AS_AUDIO_INVALID: + case CD_AS_NO_STATUS: + /* Try to determine if there's a CD available */ + if (ioctl (cdrom->id, CDIOREADTOCHEADER, &toc) == 0) + status = CD_STOPPED; + else + status = CD_TRAYEMPTY; + break; + case CD_AS_PLAY_COMPLETED: + status = CD_STOPPED; + break; + case CD_AS_PLAY_IN_PROGRESS: + status = CD_PLAYING; + break; + case CD_AS_PLAY_PAUSED: + status = CD_PAUSED; + break; + default: + status = CD_ERROR; + break; + } + } + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) { + *position = + MSF_TO_FRAMES (data.what.position.absaddr.msf.minute, + data.what.position.absaddr.msf.second, + data.what.position.absaddr.msf.frame); + } else { + *position = 0; + } + } + return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - struct ioc_play_msf playtime; + struct ioc_play_msf playtime; - FRAMES_TO_MSF(start, - &playtime.start_m, &playtime.start_s, &playtime.start_f); - FRAMES_TO_MSF(start+length, - &playtime.end_m, &playtime.end_s, &playtime.end_f); + FRAMES_TO_MSF (start, + &playtime.start_m, &playtime.start_s, &playtime.start_f); + FRAMES_TO_MSF (start + length, + &playtime.end_m, &playtime.end_s, &playtime.end_f); #ifdef DEBUG_CDROM - fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", - playtime.start_m, playtime.start_s, playtime.start_f, - playtime.end_m, playtime.end_s, playtime.end_f); + fprintf (stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", + playtime.start_m, playtime.start_s, playtime.start_f, + playtime.end_m, playtime.end_s, playtime.end_f); #endif - ioctl(cdrom->id, CDIOCSTART, 0); - return(SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime)); + ioctl (cdrom->id, CDIOCSTART, 0); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCPLAYMSF, &playtime)); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCPAUSE, 0)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCRESUME, 0)); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCSTOP, 0)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0)); + return (SDL_SYS_CDioctl (cdrom->id, CDIOCEJECT, 0)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - close(cdrom->id); + close (cdrom->id); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - int i; - - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; + } } #endif /* SDL_CDROM_OPENBSD */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/os2/SDL_syscdrom.c b/src/cdrom/os2/SDL_syscdrom.c index 56205fd7f..b63001ddf 100644 --- a/src/cdrom/os2/SDL_syscdrom.c +++ b/src/cdrom/os2/SDL_syscdrom.c @@ -36,23 +36,23 @@ #define MCI_CMDRETBUFSIZE 128 /* The maximum number of CD-ROM drives we'll detect */ -#define MAX_DRIVES 16 +#define MAX_DRIVES 16 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; //static dev_t SDL_cdmode[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); /* MCI Timing Functions */ #define MCI_MMTIMEPERSECOND 3000 @@ -60,334 +60,384 @@ static void SDL_SYS_CDClose(SDL_CD *cdrom); /* Ready for MCI CDAudio Devices */ -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { -int i; /* generig counter */ -MCI_SYSINFO_PARMS msp; /* Structure to MCI SysInfo parameters */ -CHAR SysInfoRet[MCI_CMDRETBUFSIZE]; /* Buffer for MCI Command result */ + int i; /* generig counter */ + MCI_SYSINFO_PARMS msp; /* Structure to MCI SysInfo parameters */ + CHAR SysInfoRet[MCI_CMDRETBUFSIZE]; /* Buffer for MCI Command result */ /* Fill in our driver capabilities */ -SDL_CDcaps.Name = SDL_SYS_CDName; -SDL_CDcaps.Open = SDL_SYS_CDOpen; -SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; -SDL_CDcaps.Status = SDL_SYS_CDStatus; -SDL_CDcaps.Play = SDL_SYS_CDPlay; -SDL_CDcaps.Pause = SDL_SYS_CDPause; -SDL_CDcaps.Resume = SDL_SYS_CDResume; -SDL_CDcaps.Stop = SDL_SYS_CDStop; -SDL_CDcaps.Eject = SDL_SYS_CDEject; -SDL_CDcaps.Close = SDL_SYS_CDClose; + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; /* Get the number of CD ROMs in the System */ /* Clean SysInfo structure */ -SDL_memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS)); + SDL_memset (&msp, 0x00, sizeof (MCI_SYSINFO_PARMS)); /* Prepare structure to Ask Numer of Audio CDs */ -msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO; /* CD Audio Type */ -msp.pszReturn = (PSZ)&SysInfoRet; /* Return Structure */ -msp.ulRetSize = MCI_CMDRETBUFSIZE; /* Size of ret struct */ -if (LOUSHORT(mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID)&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR); -SDL_numcds = atoi(SysInfoRet); -if (SDL_numcds > MAX_DRIVES) SDL_numcds = MAX_DRIVES; /* Limit maximum CD number */ + msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO; /* CD Audio Type */ + msp.pszReturn = (PSZ) & SysInfoRet; /* Return Structure */ + msp.ulRetSize = MCI_CMDRETBUFSIZE; /* Size of ret struct */ + if (LOUSHORT + (mciSendCommand + (0, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID) & msp, + 0)) != MCIERR_SUCCESS) + return (CD_ERROR); + SDL_numcds = atoi (SysInfoRet); + if (SDL_numcds > MAX_DRIVES) + SDL_numcds = MAX_DRIVES; /* Limit maximum CD number */ /* Get and Add their system name to the SDL_cdlist */ -msp.pszReturn = (PSZ)&SysInfoRet; /* Return Structure */ -msp.ulRetSize = MCI_CMDRETBUFSIZE; /* Size of ret struct */ -msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO; /* CD Audio Type */ -for (i=0; istatus == CD_PLAYING || cdrom->status == CD_PAUSED) return 0; + if (cdrom->status == CD_PLAYING || cdrom->status == CD_PAUSED) + return 0; /* Get Number of Tracks */ -msp.hwndCallback = (HWND)NULL; /* None */ -msp.ulReturn = (ULONG)NULL; /* We want this information */ -msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS; -msp.ulValue = (ULONG)NULL; /* No additional information */ -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return(CD_ERROR); -cdrom->numtracks = msp.ulReturn; -if ( cdrom->numtracks > SDL_MAX_TRACKS ) - { - cdrom->numtracks = SDL_MAX_TRACKS; - } + msp.hwndCallback = (HWND) NULL; /* None */ + msp.ulReturn = (ULONG) NULL; /* We want this information */ + msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS; + msp.ulValue = (ULONG) NULL; /* No additional information */ + if (LOUSHORT + (mciSendCommand + (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, + 0)) != MCIERR_SUCCESS) + return (CD_ERROR); + cdrom->numtracks = msp.ulReturn; + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; + } /* Alocate space for TOC data */ -mtr = (MCI_TOC_REC *)SDL_malloc(cdrom->numtracks*sizeof(MCI_TOC_REC)); -if ( mtr == NULL ) - { - SDL_OutOfMemory(); - return(-1); - } + mtr = + (MCI_TOC_REC *) SDL_malloc (cdrom->numtracks * sizeof (MCI_TOC_REC)); + if (mtr == NULL) { + SDL_OutOfMemory (); + return (-1); + } /* Get TOC from CD */ -mtp.pBuf = mtr; -mtp.ulBufSize = cdrom->numtracks*sizeof(MCI_TOC_REC); -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_GETTOC,MCI_WAIT,&mtp, 0)) != MCIERR_SUCCESS) - { - SDL_OutOfMemory(); - SDL_free(mtr); - return(CD_ERROR); - } + mtp.pBuf = mtr; + mtp.ulBufSize = cdrom->numtracks * sizeof (MCI_TOC_REC); + if (LOUSHORT (mciSendCommand (cdrom->id, MCI_GETTOC, MCI_WAIT, &mtp, 0)) + != MCIERR_SUCCESS) { + SDL_OutOfMemory (); + SDL_free (mtr); + return (CD_ERROR); + } /* Fill SDL Tracks Structure */ -for (i=0; inumtracks; i++) - { - /* Set Track ID */ - cdrom->track[i].id = (mtr+i)->TrackNum; - /* Set Track Type */ - msp.hwndCallback = (HWND)NULL; /* None */ - msp.ulReturn = (ULONG)NULL; /* We want this information */ - msp.ulItem = MCI_CD_STATUS_TRACK_TYPE; - msp.ulValue = (ULONG)((mtr+i)->TrackNum); /* Track Number? */ - if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) - { - SDL_free(mtr); - return (CD_ERROR); - } - if (msp.ulReturn==MCI_CD_TRACK_AUDIO) cdrom->track[i].type = SDL_AUDIO_TRACK; - else cdrom->track[i].type = SDL_DATA_TRACK; - /* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */ - cdrom->track[i].length = FRAMESFROMMM((mtr+i)->ulEndAddr - (mtr+i)->ulStartAddr); - /* Set Track Offset */ - cdrom->track[i].offset = FRAMESFROMMM((mtr+i)->ulStartAddr); - } -SDL_free(mtr); -return(0); + for (i = 0; i < cdrom->numtracks; i++) { + /* Set Track ID */ + cdrom->track[i].id = (mtr + i)->TrackNum; + /* Set Track Type */ + msp.hwndCallback = (HWND) NULL; /* None */ + msp.ulReturn = (ULONG) NULL; /* We want this information */ + msp.ulItem = MCI_CD_STATUS_TRACK_TYPE; + msp.ulValue = (ULONG) ((mtr + i)->TrackNum); /* Track Number? */ + if (LOUSHORT + (mciSendCommand + (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM, + &msp, 0)) != MCIERR_SUCCESS) { + SDL_free (mtr); + return (CD_ERROR); + } + if (msp.ulReturn == MCI_CD_TRACK_AUDIO) + cdrom->track[i].type = SDL_AUDIO_TRACK; + else + cdrom->track[i].type = SDL_DATA_TRACK; + /* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */ + cdrom->track[i].length = + FRAMESFROMMM ((mtr + i)->ulEndAddr - (mtr + i)->ulStartAddr); + /* Set Track Offset */ + cdrom->track[i].offset = FRAMESFROMMM ((mtr + i)->ulStartAddr); + } + SDL_free (mtr); + return (0); } /* Get CD-ROM status - Ready for MCI */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { -CDstatus status; -MCI_STATUS_PARMS msp; + CDstatus status; + MCI_STATUS_PARMS msp; /* Get Status from MCI */ -msp.hwndCallback = (HWND)NULL; /* None */ -msp.ulReturn = (ULONG)NULL; /* We want this information */ -msp.ulItem = MCI_STATUS_MODE; -msp.ulValue = (ULONG)NULL; /* No additional information */ -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) status = CD_ERROR; -else - { - switch(msp.ulReturn) - { - case MCI_MODE_NOT_READY: - status = CD_TRAYEMPTY; - break; - case MCI_MODE_PAUSE: - status = CD_PAUSED; - break; - case MCI_MODE_PLAY: - status = CD_PLAYING; - break; - case MCI_MODE_STOP: - status = CD_STOPPED; - break; - /* These cases should not occour */ - case MCI_MODE_RECORD: - case MCI_MODE_SEEK: - default: - status = CD_ERROR; - break; - } - } + msp.hwndCallback = (HWND) NULL; /* None */ + msp.ulReturn = (ULONG) NULL; /* We want this information */ + msp.ulItem = MCI_STATUS_MODE; + msp.ulValue = (ULONG) NULL; /* No additional information */ + if (LOUSHORT + (mciSendCommand + (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, + 0)) != MCIERR_SUCCESS) + status = CD_ERROR; + else { + switch (msp.ulReturn) { + case MCI_MODE_NOT_READY: + status = CD_TRAYEMPTY; + break; + case MCI_MODE_PAUSE: + status = CD_PAUSED; + break; + case MCI_MODE_PLAY: + status = CD_PLAYING; + break; + case MCI_MODE_STOP: + status = CD_STOPPED; + break; + /* These cases should not occour */ + case MCI_MODE_RECORD: + case MCI_MODE_SEEK: + default: + status = CD_ERROR; + break; + } + } /* Determine position */ -if (position != NULL) /* The SDL $&$&%# CDROM call sends NULL pointer here! */ - { - if ((status == CD_PLAYING) || (status == CD_PAUSED)) - { - /* Get Position */ - msp.hwndCallback = (HWND)NULL; /* None */ - msp.ulReturn = (ULONG)NULL; /* We want this information */ - msp.ulItem = MCI_STATUS_POSITION; - msp.ulValue = (ULONG)NULL; /* No additiona info */ - if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS) return (CD_ERROR); - /* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */ - *position = MSF_TO_FRAMES(MSF_MINUTE(msp.ulReturn),MSF_SECOND(msp.ulReturn),MSF_FRAME(msp.ulReturn)); - } - else *position = 0; - } -return(status); + if (position != NULL) { /* The SDL $&$&%# CDROM call sends NULL pointer here! */ + if ((status == CD_PLAYING) || (status == CD_PAUSED)) { + /* Get Position */ + msp.hwndCallback = (HWND) NULL; /* None */ + msp.ulReturn = (ULONG) NULL; /* We want this information */ + msp.ulItem = MCI_STATUS_POSITION; + msp.ulValue = (ULONG) NULL; /* No additiona info */ + if (LOUSHORT + (mciSendCommand + (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, + 0)) != MCIERR_SUCCESS) + return (CD_ERROR); + /* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */ + *position = + MSF_TO_FRAMES (MSF_MINUTE (msp.ulReturn), + MSF_SECOND (msp.ulReturn), + MSF_FRAME (msp.ulReturn)); + } else + *position = 0; + } + return (status); } /* Start play - Ready for MCI */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { -MCI_GENERIC_PARMS mgp; -MCI_STATUS_PARMS msp; -MCI_PLAY_PARMS mpp; -ULONG min,sec,frm; + MCI_GENERIC_PARMS mgp; + MCI_STATUS_PARMS msp; + MCI_PLAY_PARMS mpp; + ULONG min, sec, frm; /* Start MSF */ -FRAMES_TO_MSF(start, &min, &sec, &frm); -MSF_MINUTE(mpp.ulFrom) = min; -MSF_SECOND(mpp.ulFrom) = sec; -MSF_FRAME(mpp.ulFrom) = frm; + FRAMES_TO_MSF (start, &min, &sec, &frm); + MSF_MINUTE (mpp.ulFrom) = min; + MSF_SECOND (mpp.ulFrom) = sec; + MSF_FRAME (mpp.ulFrom) = frm; /* End MSF */ -FRAMES_TO_MSF(start+length, &min, &sec, &frm); -MSF_MINUTE(mpp.ulTo) = min; -MSF_SECOND(mpp.ulTo) = sec; -MSF_FRAME(mpp.ulTo) = frm; + FRAMES_TO_MSF (start + length, &min, &sec, &frm); + MSF_MINUTE (mpp.ulTo) = min; + MSF_SECOND (mpp.ulTo) = sec; + MSF_FRAME (mpp.ulTo) = frm; #ifdef DEBUG_CDROM - fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", - playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, - playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); + fprintf (stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", + playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, + playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); #endif /* Verifies if it is paused first... and if it is, unpause before stopping it. */ -msp.hwndCallback = (HWND)NULL; /* None */ -msp.ulReturn = (ULONG)NULL; /* We want this information */ -msp.ulItem = MCI_STATUS_MODE; -msp.ulValue = (ULONG)NULL; /* No additional information */ -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS) - { - if (msp.ulReturn == MCI_MODE_PAUSE) - { - mgp.hwndCallback = (HWND)NULL; // None - mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0); - } - } + msp.hwndCallback = (HWND) NULL; /* None */ + msp.ulReturn = (ULONG) NULL; /* We want this information */ + msp.ulItem = MCI_STATUS_MODE; + msp.ulValue = (ULONG) NULL; /* No additional information */ + if (LOUSHORT + (mciSendCommand + (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, + 0)) == MCIERR_SUCCESS) { + if (msp.ulReturn == MCI_MODE_PAUSE) { + mgp.hwndCallback = (HWND) NULL; // None + mciSendCommand (cdrom->id, MCI_RESUME, 0, &mgp, 0); + } + } /* Now play it. */ -mpp.hwndCallback = (HWND)NULL; // We do not want the info. temp -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PLAY,MCI_FROM | MCI_TO,&mpp, 0)) == MCIERR_SUCCESS) return 0; -return (CD_ERROR); + mpp.hwndCallback = (HWND) NULL; // We do not want the info. temp + if (LOUSHORT + (mciSendCommand (cdrom->id, MCI_PLAY, MCI_FROM | MCI_TO, &mpp, 0)) == + MCIERR_SUCCESS) + return 0; + return (CD_ERROR); } /* Pause play - Ready for MCI */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { -MCI_GENERIC_PARMS mgp; + MCI_GENERIC_PARMS mgp; -mgp.hwndCallback = (HWND)NULL; // None -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_PAUSE,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0; -return(CD_ERROR); + mgp.hwndCallback = (HWND) NULL; // None + if (LOUSHORT (mciSendCommand (cdrom->id, MCI_PAUSE, MCI_WAIT, &mgp, 0)) == + MCIERR_SUCCESS) + return 0; + return (CD_ERROR); } /* Resume play - Ready for MCI */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { -MCI_GENERIC_PARMS mgp; + MCI_GENERIC_PARMS mgp; -mgp.hwndCallback = (HWND)NULL; // None -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_RESUME,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0; -return(CD_ERROR); + mgp.hwndCallback = (HWND) NULL; // None + if (LOUSHORT (mciSendCommand (cdrom->id, MCI_RESUME, MCI_WAIT, &mgp, 0)) + == MCIERR_SUCCESS) + return 0; + return (CD_ERROR); } /* Stop play - Ready for MCI */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { -MCI_GENERIC_PARMS mgp; -MCI_STATUS_PARMS msp; + MCI_GENERIC_PARMS mgp; + MCI_STATUS_PARMS msp; /* Verifies if it is paused first... and if it is, unpause before stopping it. */ -msp.hwndCallback = (HWND)NULL; /* None */ -msp.ulReturn = (ULONG)NULL; /* We want this information */ -msp.ulItem = MCI_STATUS_MODE; -msp.ulValue = (ULONG)NULL; /* No additional information */ -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,&msp, 0)) == MCIERR_SUCCESS) - { - if (msp.ulReturn == MCI_MODE_PAUSE) - { - mgp.hwndCallback = (HWND)NULL; // None - mciSendCommand(cdrom->id,MCI_RESUME,0,&mgp, 0); - } - } + msp.hwndCallback = (HWND) NULL; /* None */ + msp.ulReturn = (ULONG) NULL; /* We want this information */ + msp.ulItem = MCI_STATUS_MODE; + msp.ulValue = (ULONG) NULL; /* No additional information */ + if (LOUSHORT + (mciSendCommand + (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp, + 0)) == MCIERR_SUCCESS) { + if (msp.ulReturn == MCI_MODE_PAUSE) { + mgp.hwndCallback = (HWND) NULL; // None + mciSendCommand (cdrom->id, MCI_RESUME, 0, &mgp, 0); + } + } /* Now stops the media */ -mgp.hwndCallback = (HWND)NULL; // None -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STOP,MCI_WAIT,&mgp, 0)) == MCIERR_SUCCESS) return 0; -return(CD_ERROR); + mgp.hwndCallback = (HWND) NULL; // None + if (LOUSHORT (mciSendCommand (cdrom->id, MCI_STOP, MCI_WAIT, &mgp, 0)) == + MCIERR_SUCCESS) + return 0; + return (CD_ERROR); } /* Eject the CD-ROM - Ready for MCI */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { -MCI_SET_PARMS msp; - -msp.hwndCallback = (HWND)NULL; // None -msp.ulTimeFormat = (ULONG)NULL; // No change -msp.ulSpeedFormat = (ULONG)NULL; // No change -msp.ulAudio = (ULONG)NULL; // No Channel -msp.ulLevel = (ULONG)NULL; // No Volume -msp.ulOver = (ULONG)NULL; // No Delay -msp.ulItem = (ULONG)NULL; // No item -msp.ulValue = (ULONG)NULL; // No value for item flag -if (LOUSHORT(mciSendCommand(cdrom->id,MCI_SET,MCI_WAIT | MCI_SET_DOOR_OPEN,&msp, 0)) == MCIERR_SUCCESS) return 0; -return(CD_ERROR); + MCI_SET_PARMS msp; + + msp.hwndCallback = (HWND) NULL; // None + msp.ulTimeFormat = (ULONG) NULL; // No change + msp.ulSpeedFormat = (ULONG) NULL; // No change + msp.ulAudio = (ULONG) NULL; // No Channel + msp.ulLevel = (ULONG) NULL; // No Volume + msp.ulOver = (ULONG) NULL; // No Delay + msp.ulItem = (ULONG) NULL; // No item + msp.ulValue = (ULONG) NULL; // No value for item flag + if (LOUSHORT + (mciSendCommand + (cdrom->id, MCI_SET, MCI_WAIT | MCI_SET_DOOR_OPEN, &msp, + 0)) == MCIERR_SUCCESS) + return 0; + return (CD_ERROR); } /* Close the CD-ROM handle - Ready for MCI */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { -MCI_GENERIC_PARMS mgp; + MCI_GENERIC_PARMS mgp; -mgp.hwndCallback = (HWND)NULL; // None -mciSendCommand(cdrom->id,MCI_CLOSE,MCI_WAIT,&mgp, 0); + mgp.hwndCallback = (HWND) NULL; // None + mciSendCommand (cdrom->id, MCI_CLOSE, MCI_WAIT, &mgp, 0); } /* Finalize CDROM Subsystem - Ready for MCI */ -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { -int i; - -if ( SDL_numcds > 0 ) - { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; + } } #endif /* SDL_CDROM_OS2 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/osf/SDL_syscdrom.c b/src/cdrom/osf/SDL_syscdrom.c index 8478a7b4c..0379fee9c 100644 --- a/src/cdrom/osf/SDL_syscdrom.c +++ b/src/cdrom/osf/SDL_syscdrom.c @@ -45,96 +45,101 @@ static char *SDL_cdlist[MAX_DRIVES]; static dev_t SDL_cdmode[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); /* Check a drive to see if it is a CD-ROM */ -/* Caution!! Not tested. */ -static int CheckDrive(char *drive, struct stat *stbuf) +/* Caution!! Not tested. */ +static int +CheckDrive (char *drive, struct stat *stbuf) { int cdfd, is_cd = 0; struct mode_sel_sns_params msp; struct inquiry_info inq; #ifdef DEBUG_CDROM - char *devtype[] = {"Disk", "Tape", "Printer", "Processor", "WORM", - "CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"}; + char *devtype[] = { "Disk", "Tape", "Printer", "Processor", "WORM", + "CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown" + }; #endif - bzero(&msp, sizeof(msp)); - bzero(&inq, sizeof(inq)); + bzero (&msp, sizeof (msp)); + bzero (&inq, sizeof (inq)); /* If it doesn't exist, return -1 */ - if ( stat(drive, stbuf) < 0 ) { - return(-1); + if (stat (drive, stbuf) < 0) { + return (-1); } - if ( (cdfd = open(drive, (O_RDWR|O_NDELAY), 0)) >= 0 ) { - msp.msp_addr = (caddr_t) &inq; - msp.msp_pgcode = 0; - msp.msp_pgctrl = 0; - msp.msp_length = sizeof(inq); - msp.msp_setps = 0; + if ((cdfd = open (drive, (O_RDWR | O_NDELAY), 0)) >= 0) { + msp.msp_addr = (caddr_t) & inq; + msp.msp_pgcode = 0; + msp.msp_pgctrl = 0; + msp.msp_length = sizeof (inq); + msp.msp_setps = 0; - if ( ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp) ) - return (0); + if (ioctl (cdfd, SCSI_GET_INQUIRY_DATA, &msp)) + return (0); #ifdef DEBUG_CDROM - fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]); - fprintf(stderr, "Vendor: %.8s\n", inq.vndrid); - fprintf(stderr, "Product: %.8s\n", inq.prodid); - fprintf(stderr, "Revision: %.8s\n", inq.revlvl); + fprintf (stderr, "Device Type: %s\n", devtype[inq.perfdt]); + fprintf (stderr, "Vendor: %.8s\n", inq.vndrid); + fprintf (stderr, "Product: %.8s\n", inq.prodid); + fprintf (stderr, "Revision: %.8s\n", inq.revlvl); #endif - if ( inq.perfdt == DTYPE_RODIRECT ) - is_cd = 1; + if (inq.perfdt == DTYPE_RODIRECT) + is_cd = 1; } - return(is_cd); + return (is_cd); } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive, struct stat *stbuf) +static void +AddDrive (char *drive, struct stat *stbuf) { int i; - if ( SDL_numcds < MAX_DRIVES ) { - /* Check to make sure it's not already in our list. - * This can happen when we see a drive via symbolic link. - * - */ - for ( i=0; ist_rdev == SDL_cdmode[i] ) { + if (SDL_numcds < MAX_DRIVES) { + /* Check to make sure it's not already in our list. + * This can happen when we see a drive via symbolic link. + * + */ + for (i = 0; i < SDL_numcds; ++i) { + if (stbuf->st_rdev == SDL_cdmode[i]) { #ifdef DEBUG_CDROM - fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); + fprintf (stderr, "Duplicate drive detected: %s == %s\n", + drive, SDL_cdlist[i]); #endif - return; - } - } - - /* Add this drive to our list */ - i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - SDL_cdmode[i] = stbuf->st_rdev; - ++SDL_numcds; + return; + } + } + + /* Add this drive to our list */ + i = SDL_numcds; + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + SDL_cdmode[i] = stbuf->st_rdev; + ++SDL_numcds; #ifdef DEBUG_CDROM - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif } } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { /* checklist: * @@ -145,239 +150,250 @@ int SDL_SYS_CDInit(void) * dir: /dev, name: rrz * */ - struct { - char *dir; - char *name; + struct + { + char *dir; + char *name; } checklist[] = { - {"/dev/rdisk", "cdrom"}, - {"/dev", "rrz"}, - {NULL, NULL}}; + { + "/dev/rdisk", "cdrom"}, { + "/dev", "rrz"}, { + NULL, NULL}}; char drive[32]; char *SDLcdrom; int i, j, exists; struct stat stbuf; /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ - SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ - if ( SDLcdrom != NULL ) { - char *cdpath, *delim; - size_t len = SDL_strlen(SDLcdrom)+1; - cdpath = SDL_stack_alloc(char, len); - if ( cdpath != NULL ) { - SDL_strlcpy(cdpath, SDLcdrom, len); - SDLcdrom = cdpath; - do { - delim = SDL_strchr(SDLcdrom, ':'); - if ( delim ) { - *delim++ = '\0'; - } - if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { - AddDrive(SDLcdrom, &stbuf); - } - if ( delim ) { - SDLcdrom = delim; - } else { - SDLcdrom = NULL; - } - } while ( SDLcdrom ); - SDL_stack_free(cdpath); - } - - /* If we found our drives, there's nothing left to do */ - if ( SDL_numcds > 0 ) { - return(0); - } + SDLcdrom = SDL_getenv ("SDL_CDROM"); /* ':' separated list of devices */ + if (SDLcdrom != NULL) { + char *cdpath, *delim; + size_t len = SDL_strlen (SDLcdrom) + 1; + cdpath = SDL_stack_alloc (char, len); + if (cdpath != NULL) { + SDL_strlcpy (cdpath, SDLcdrom, len); + SDLcdrom = cdpath; + do { + delim = SDL_strchr (SDLcdrom, ':'); + if (delim) { + *delim++ = '\0'; + } + if (CheckDrive (SDLcdrom, &stbuf) > 0) { + AddDrive (SDLcdrom, &stbuf); + } + if (delim) { + SDLcdrom = delim; + } else { + SDLcdrom = NULL; + } + } + while (SDLcdrom); + SDL_stack_free (cdpath); + } + + /* If we found our drives, there's nothing left to do */ + if (SDL_numcds > 0) { + return (0); + } } /* Scan the system for CD-ROM drives */ - for ( i = 0; checklist[i].dir; ++i) { - DIR *devdir; - struct dirent *devent; - int name_len; - - devdir = opendir(checklist[i].dir); - if (devdir) { - name_len = SDL_strlen(checklist[i].name); - while (devent = readdir(devdir)) - if (SDL_memcmp(checklist[i].name, devent->d_name, name_len) == 0) - if (devent->d_name[devent->d_namlen-1] == 'c') { - SDL_snprintf(drive, SDL_arraysize(drive), "%s/%s", checklist[i].dir, devent->d_name); + for (i = 0; checklist[i].dir; ++i) { + DIR *devdir; + struct dirent *devent; + int name_len; + + devdir = opendir (checklist[i].dir); + if (devdir) { + name_len = SDL_strlen (checklist[i].name); + while (devent = readdir (devdir)) + if (SDL_memcmp + (checklist[i].name, devent->d_name, name_len) == 0) + if (devent->d_name[devent->d_namlen - 1] == 'c') { + SDL_snprintf (drive, SDL_arraysize (drive), + "%s/%s", checklist[i].dir, + devent->d_name); #ifdef DEBUG_CDROM - fprintf(stderr, "Try to add drive: %s\n", drive); + fprintf (stderr, "Try to add drive: %s\n", drive); #endif - if ( CheckDrive(drive, &stbuf) > 0 ) - AddDrive(drive, &stbuf); - } - closedir(devdir); - } else { + if (CheckDrive (drive, &stbuf) > 0) + AddDrive (drive, &stbuf); + } + closedir (devdir); + } else { #ifdef DEBUG_CDROM - fprintf(stderr, "cannot open dir: %s\n", checklist[i].dir); + fprintf (stderr, "cannot open dir: %s\n", checklist[i].dir); #endif - } + } } return (0); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { /* O_RDWR: To use ioctl(fd, SCSI_STOP_UNIT) */ - return(open(SDL_cdlist[drive], (O_RDWR|O_NDELAY), 0)); + return (open (SDL_cdlist[drive], (O_RDWR | O_NDELAY), 0)); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - struct cd_toc toc; - struct cd_toc_header hdr; - struct cd_toc_entry *cdte; + struct cd_toc toc; + struct cd_toc_header hdr; + struct cd_toc_entry *cdte; int i; int okay = 0; - if ( ioctl(cdrom->id, CDROM_TOC_HEADER, &hdr) ) { - fprintf(stderr,"ioctl error CDROM_TOC_HEADER\n"); - return -1; + if (ioctl (cdrom->id, CDROM_TOC_HEADER, &hdr)) { + fprintf (stderr, "ioctl error CDROM_TOC_HEADER\n"); + return -1; } cdrom->numtracks = hdr.th_ending_track - hdr.th_starting_track + 1; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { - cdrom->numtracks = SDL_MAX_TRACKS; + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; } #ifdef DEBUG_CDROM - fprintf(stderr,"hdr.th_data_len1 = %d\n", hdr.th_data_len1); - fprintf(stderr,"hdr.th_data_len0 = %d\n", hdr.th_data_len0); - fprintf(stderr,"hdr.th_starting_track = %d\n", hdr.th_starting_track); - fprintf(stderr,"hdr.th_ending_track = %d\n", hdr.th_ending_track); - fprintf(stderr,"cdrom->numtracks = %d\n", cdrom->numtracks); + fprintf (stderr, "hdr.th_data_len1 = %d\n", hdr.th_data_len1); + fprintf (stderr, "hdr.th_data_len0 = %d\n", hdr.th_data_len0); + fprintf (stderr, "hdr.th_starting_track = %d\n", hdr.th_starting_track); + fprintf (stderr, "hdr.th_ending_track = %d\n", hdr.th_ending_track); + fprintf (stderr, "cdrom->numtracks = %d\n", cdrom->numtracks); #endif toc.toc_address_format = CDROM_LBA_FORMAT; toc.toc_starting_track = 0; toc.toc_alloc_length = (hdr.th_data_len1 << 8) + - hdr.th_data_len0 + sizeof(hdr); - if ( (toc.toc_buffer = alloca(toc.toc_alloc_length)) == NULL) { - fprintf(stderr,"cannot allocate toc.toc_buffer\n"); - return -1; + hdr.th_data_len0 + sizeof (hdr); + if ((toc.toc_buffer = alloca (toc.toc_alloc_length)) == NULL) { + fprintf (stderr, "cannot allocate toc.toc_buffer\n"); + return -1; } bzero (toc.toc_buffer, toc.toc_alloc_length); - if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) { - fprintf(stderr,"ioctl error CDROM_TOC_ENTRYS\n"); - return -1; + if (ioctl (cdrom->id, CDROM_TOC_ENTRYS, &toc)) { + fprintf (stderr, "ioctl error CDROM_TOC_ENTRYS\n"); + return -1; } - cdte =(struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr)); - for (i=0; i <= cdrom->numtracks; ++i) { - if (i == cdrom->numtracks ) { - cdrom->track[i].id = 0xAA;; - } else { - cdrom->track[i].id = hdr.th_starting_track + i; - } - - cdrom->track[i].type = - cdte[i].te_control & CDROM_DATA_TRACK; - cdrom->track[i].offset = - cdte[i].te_absaddr.lba.addr3 << 24 | - cdte[i].te_absaddr.lba.addr2 << 16 | - cdte[i].te_absaddr.lba.addr1 << 8 | - cdte[i].te_absaddr.lba.addr0; - cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i - 1].length = - cdrom->track[i].offset - - cdrom->track[i - 1].offset; - } + cdte = (struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof (hdr)); + for (i = 0; i <= cdrom->numtracks; ++i) { + if (i == cdrom->numtracks) { + cdrom->track[i].id = 0xAA;; + } else { + cdrom->track[i].id = hdr.th_starting_track + i; + } + + cdrom->track[i].type = cdte[i].te_control & CDROM_DATA_TRACK; + cdrom->track[i].offset = + cdte[i].te_absaddr.lba.addr3 << 24 | + cdte[i].te_absaddr.lba.addr2 << 16 | + cdte[i].te_absaddr.lba.addr1 << 8 | cdte[i].te_absaddr.lba.addr0; + cdrom->track[i].length = 0; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; + } } #ifdef DEBUG_CDROM - for (i = 0; i <= cdrom->numtracks; i++) { - fprintf(stderr,"toc_entry[%d].te_track_number = %d\n", - i,cdte[i].te_track_number); - fprintf(stderr,"cdrom->track[%d].id = %d\n", i,cdrom->track[i].id); - fprintf(stderr,"cdrom->track[%d].type = %x\n", i,cdrom->track[i].type); - fprintf(stderr,"cdrom->track[%d].offset = %d\n", i,cdrom->track[i].offset); - fprintf(stderr,"cdrom->track[%d].length = %d\n", i,cdrom->track[i].length); - } + for (i = 0; i <= cdrom->numtracks; i++) { + fprintf (stderr, "toc_entry[%d].te_track_number = %d\n", + i, cdte[i].te_track_number); + fprintf (stderr, "cdrom->track[%d].id = %d\n", i, cdrom->track[i].id); + fprintf (stderr, "cdrom->track[%d].type = %x\n", i, + cdrom->track[i].type); + fprintf (stderr, "cdrom->track[%d].offset = %d\n", i, + cdrom->track[i].offset); + fprintf (stderr, "cdrom->track[%d].length = %d\n", i, + cdrom->track[i].length); + } #endif - if ( i == (cdrom->numtracks+1) ) { - okay = 1; + if (i == (cdrom->numtracks + 1)) { + okay = 1; } - return(okay ? 0 : -1); + return (okay ? 0 : -1); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; - struct cd_sub_channel sc; - struct cd_subc_channel_data scd; + CDstatus status; + struct cd_sub_channel sc; + struct cd_subc_channel_data scd; sc.sch_address_format = CDROM_LBA_FORMAT; - sc.sch_data_format = CDROM_CURRENT_POSITION; - sc.sch_track_number = 0; - sc.sch_alloc_length = sizeof(scd); - sc.sch_buffer = (caddr_t)&scd; - if ( ioctl(cdrom->id, CDROM_READ_SUBCHANNEL, &sc) ) { - status = CD_ERROR; - fprintf(stderr,"ioctl error CDROM_READ_SUBCHANNEL \n"); + sc.sch_data_format = CDROM_CURRENT_POSITION; + sc.sch_track_number = 0; + sc.sch_alloc_length = sizeof (scd); + sc.sch_buffer = (caddr_t) & scd; + if (ioctl (cdrom->id, CDROM_READ_SUBCHANNEL, &sc)) { + status = CD_ERROR; + fprintf (stderr, "ioctl error CDROM_READ_SUBCHANNEL \n"); } else { - switch (scd.scd_header.sh_audio_status) { - case AS_AUDIO_INVALID: - status = CD_STOPPED; - break; - case AS_PLAY_IN_PROGRESS: - status = CD_PLAYING; - break; - case AS_PLAY_PAUSED: - status = CD_PAUSED; - break; - case AS_PLAY_COMPLETED: - status = CD_STOPPED; - break; - case AS_PLAY_ERROR: - status = CD_ERROR; - break; - case AS_NO_STATUS: - status = CD_STOPPED; - break; - default: - status = CD_ERROR; - break; - } + switch (scd.scd_header.sh_audio_status) { + case AS_AUDIO_INVALID: + status = CD_STOPPED; + break; + case AS_PLAY_IN_PROGRESS: + status = CD_PLAYING; + break; + case AS_PLAY_PAUSED: + status = CD_PAUSED; + break; + case AS_PLAY_COMPLETED: + status = CD_STOPPED; + break; + case AS_PLAY_ERROR: + status = CD_ERROR; + break; + case AS_NO_STATUS: + status = CD_STOPPED; + break; + default: + status = CD_ERROR; + break; + } #ifdef DEBUG_CDROM - fprintf(stderr,"scd.scd_header.sh_audio_status = %x\n", - scd.scd_header.sh_audio_status); + fprintf (stderr, "scd.scd_header.sh_audio_status = %x\n", + scd.scd_header.sh_audio_status); #endif } if (position) { - if (status == CD_PLAYING || (status == CD_PAUSED) ) { - *position = - scd.scd_position_data.scp_absaddr.lba.addr3 << 24 | - scd.scd_position_data.scp_absaddr.lba.addr2 << 16 | - scd.scd_position_data.scp_absaddr.lba.addr1 << 8 | - scd.scd_position_data.scp_absaddr.lba.addr0; - } else { - *position = 0; - } + if (status == CD_PLAYING || (status == CD_PAUSED)) { + *position = + scd.scd_position_data.scp_absaddr.lba.addr3 << 24 | + scd.scd_position_data.scp_absaddr.lba.addr2 << 16 | + scd.scd_position_data.scp_absaddr.lba.addr1 << 8 | + scd.scd_position_data.scp_absaddr.lba.addr0; + } else { + *position = 0; + } } return status; } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { /* * Play MSF @@ -385,60 +401,65 @@ static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) struct cd_play_audio_msf msf; int end; - bzero(&msf, sizeof(msf)); - end = start +length; - FRAMES_TO_MSF(start + 150, /* LBA = 4500*M + 75*S + F - 150 */ - &msf.msf_starting_M_unit, - &msf.msf_starting_S_unit, - &msf.msf_starting_F_unit); - FRAMES_TO_MSF(end + 150, /* LBA = 4500*M + 75*S + F - 150 */ - &msf.msf_ending_M_unit, - &msf.msf_ending_S_unit, - &msf.msf_ending_F_unit); - - return(ioctl(cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf)); + bzero (&msf, sizeof (msf)); + end = start + length; + FRAMES_TO_MSF (start + 150, /* LBA = 4500*M + 75*S + F - 150 */ + &msf.msf_starting_M_unit, + &msf.msf_starting_S_unit, &msf.msf_starting_F_unit); + FRAMES_TO_MSF (end + 150, /* LBA = 4500*M + 75*S + F - 150 */ + &msf.msf_ending_M_unit, + &msf.msf_ending_S_unit, &msf.msf_ending_F_unit); + + return (ioctl (cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf)); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - return(ioctl(cdrom->id, CDROM_PAUSE_PLAY)); + return (ioctl (cdrom->id, CDROM_PAUSE_PLAY)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - return(ioctl(cdrom->id, CDROM_RESUME_PLAY)); + return (ioctl (cdrom->id, CDROM_RESUME_PLAY)); } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - return(ioctl(cdrom->id, SCSI_STOP_UNIT)); + return (ioctl (cdrom->id, SCSI_STOP_UNIT)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return(ioctl(cdrom->id, CDROM_EJECT_CADDY)); + return (ioctl (cdrom->id, CDROM_EJECT_CADDY)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - close(cdrom->id); + close (cdrom->id); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { int i; - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; } } #endif /* SDL_CDROM_OSF */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/qnx/SDL_syscdrom.c b/src/cdrom/qnx/SDL_syscdrom.c index d41d64084..a7c261802 100644 --- a/src/cdrom/qnx/SDL_syscdrom.c +++ b/src/cdrom/qnx/SDL_syscdrom.c @@ -46,80 +46,76 @@ /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; static dev_t SDL_cdmode[MAX_DRIVES]; -static int SDL_cdopen[MAX_DRIVES]; +static int SDL_cdopen[MAX_DRIVES]; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); /* Check a drive to see if it is a CD-ROM */ -static int CheckDrive(char *drive, struct stat *stbuf) +static int +CheckDrive (char *drive, struct stat *stbuf) { int is_cd, cdfd; cam_devinfo_t dinfo; - int devctlret=0; + int devctlret = 0; int atapi; int removable; int cdb10; /* If it doesn't exist, return -1 */ - if (stat(drive, stbuf) < 0) - { - return(-1); + if (stat (drive, stbuf) < 0) { + return (-1); } /* If it does exist, verify that it's an available CD-ROM */ is_cd = 0; - if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) - { - cdfd = open(drive, QNX_CD_OPENMODE); - if ( cdfd >= 0 ) - { - devctlret=devctl(cdfd, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t), NULL); - - if (devctlret==EOK) - { - atapi=dinfo.flags & DEV_ATAPI; - removable=dinfo.flags & DEV_REMOVABLE; - cdb10=dinfo.flags & DEV_CDB_10; /* I'm not sure about that flag */ - - /* in the near future need to add more checks for splitting cdroms from other devices */ - if ((atapi)&&(removable)) - { - is_cd = 1; - } + if (S_ISCHR (stbuf->st_mode) || S_ISBLK (stbuf->st_mode)) { + cdfd = open (drive, QNX_CD_OPENMODE); + if (cdfd >= 0) { + devctlret = + devctl (cdfd, DCMD_CAM_DEVINFO, &dinfo, + sizeof (cam_devinfo_t), NULL); + + if (devctlret == EOK) { + atapi = dinfo.flags & DEV_ATAPI; + removable = dinfo.flags & DEV_REMOVABLE; + cdb10 = dinfo.flags & DEV_CDB_10; /* I'm not sure about that flag */ + + /* in the near future need to add more checks for splitting cdroms from other devices */ + if ((atapi) && (removable)) { + is_cd = 1; + } } - close(cdfd); + close (cdfd); } } - return(is_cd); + return (is_cd); } /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive, struct stat *stbuf) +static void +AddDrive (char *drive, struct stat *stbuf) { int i; - if (SDL_numcds < MAX_DRIVES) - { + if (SDL_numcds < MAX_DRIVES) { /* Check to make sure it's not already in our list. - This can happen when we see a drive via symbolic link. */ + This can happen when we see a drive via symbolic link. */ - for (i=0; ist_rdev == SDL_cdmode[i]) - { + for (i = 0; i < SDL_numcds; ++i) { + if (stbuf->st_rdev == SDL_cdmode[i]) { return; } } @@ -127,10 +123,9 @@ static void AddDrive(char *drive, struct stat *stbuf) /* Add this drive to our list */ i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if (SDL_cdlist[i] == NULL) - { - SDL_OutOfMemory(); + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); return; } SDL_cdmode[i] = stbuf->st_rdev; @@ -138,10 +133,12 @@ static void AddDrive(char *drive, struct stat *stbuf) } } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { /* checklist: /dev/cdrom, /dev/cd?, /dev/scd? */ - static char *checklist[]={"cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL}; + static char *checklist[] = + { "cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL }; char *SDLcdrom; int i, j, exists; @@ -161,150 +158,132 @@ int SDL_SYS_CDInit(void) SDL_CDcaps.Close = SDL_SYS_CDClose; /* clearing device open status */ - for (i=0; i 0) - { - AddDrive(SDLcdrom, &stbuf); + if (CheckDrive (SDLcdrom, &stbuf) > 0) { + AddDrive (SDLcdrom, &stbuf); } - if (delim) - { + if (delim) { SDLcdrom = delim; - } - else - { + } else { SDLcdrom = NULL; } - } while (SDLcdrom); - SDL_stack_free(cdpath); + } + while (SDLcdrom); + SDL_stack_free (cdpath); } /* If we found our drives, there's nothing left to do */ - if (SDL_numcds > 0) - { - return(0); + if (SDL_numcds > 0) { + return (0); } } /* Scan the system for CD-ROM drives */ - for ( i=0; checklist[i]; ++i ) - { - if (checklist[i][0] == '?') - { - char* insert; + for (i = 0; checklist[i]; ++i) { + if (checklist[i][0] == '?') { + char *insert; exists = 1; - for ( j=checklist[i][1]; exists; ++j ) - { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]); - insert = SDL_strchr(drive, '?'); - if (insert != NULL) - { + for (j = checklist[i][1]; exists; ++j) { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + &checklist[i][3]); + insert = SDL_strchr (drive, '?'); + if (insert != NULL) { *insert = j; } - switch (CheckDrive(drive, &stbuf)) - { + switch (CheckDrive (drive, &stbuf)) { /* Drive exists and is a CD-ROM */ - case 1: - AddDrive(drive, &stbuf); - break; + case 1: + AddDrive (drive, &stbuf); + break; /* Drive exists, but isn't a CD-ROM */ - case 0: - break; + case 0: + break; /* Drive doesn't exist */ - case -1: - exists = 0; - break; + case -1: + exists = 0; + break; } } - } - else - { - SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); - if (CheckDrive(drive, &stbuf) > 0) - { - AddDrive(drive, &stbuf); + } else { + SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s", + checklist[i]); + if (CheckDrive (drive, &stbuf) > 0) { + AddDrive (drive, &stbuf); } } } - return(0); + return (0); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { int handle; - handle=open(SDL_cdlist[drive], QNX_CD_OPENMODE); + handle = open (SDL_cdlist[drive], QNX_CD_OPENMODE); - if (handle>0) - { - SDL_cdopen[drive]=handle; + if (handle > 0) { + SDL_cdopen[drive] = handle; } return (handle); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { cdrom_read_toc_t toc; int i, okay; okay = 0; - if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL) == 0) - { + if (devctl (cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof (toc), NULL) == + 0) { cdrom->numtracks = toc.last_track - toc.first_track + 1; - if (cdrom->numtracks > SDL_MAX_TRACKS) - { + if (cdrom->numtracks > SDL_MAX_TRACKS) { cdrom->numtracks = SDL_MAX_TRACKS; } /* Read all the track TOC entries */ - for (i=0; i<=cdrom->numtracks; ++i) - { - if (i == cdrom->numtracks) - { + for (i = 0; i <= cdrom->numtracks; ++i) { + if (i == cdrom->numtracks) { cdrom->track[i].id = CDROM_LEADOUT; - } - else - { - cdrom->track[i].id = toc.first_track+i; + } else { + cdrom->track[i].id = toc.first_track + i; } cdrom->track[i].type = toc.toc_entry[i].control_adr & 0x0F; cdrom->track[i].offset = toc.toc_entry[i].addr.lba; cdrom->track[i].length = 0; - if (i > 0) - { - cdrom->track[i-1].length = cdrom->track[i].offset-cdrom->track[i-1].offset; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; } } - if (i == (cdrom->numtracks+1)) - { + if (i == (cdrom->numtracks + 1)) { okay = 1; } } @@ -312,7 +291,8 @@ static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { CDstatus status; @@ -320,22 +300,21 @@ static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) cdrom_subch_data_t info; cam_devinfo_t dinfo; - int devctlret=0; - int drive=-1; + int devctlret = 0; + int drive = -1; int i; - int eagaincnt=0; + int eagaincnt = 0; /* check media presence before read subchannel call, some cdroms can lockups */ /* if no media, while calling read subchannel functions. */ - devctlret=devctl(cdrom->id, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t), NULL); + devctlret = + devctl (cdrom->id, DCMD_CAM_DEVINFO, &dinfo, sizeof (cam_devinfo_t), + NULL); - if (devctlret==EOK) - { - if ((dinfo.flags & DEV_NO_MEDIA)!=0) - { + if (devctlret == EOK) { + if ((dinfo.flags & DEV_NO_MEDIA) != 0) { status = CD_TRAYEMPTY; - if (position) - { + if (position) { *position = 0; } return (status); @@ -344,208 +323,187 @@ static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) /* if media exists, then do other stuff */ - SDL_memset(&info, 0x00, sizeof(info)); + SDL_memset (&info, 0x00, sizeof (info)); info.subch_command.data_format = CDROM_SUBCH_CURRENT_POSITION; do { - devctlret=devctl(cdrom->id, DCMD_CAM_CDROMSUBCHNL, &info, sizeof(info), NULL); - if (devctlret==EIO) - { + devctlret = + devctl (cdrom->id, DCMD_CAM_CDROMSUBCHNL, &info, sizeof (info), + NULL); + if (devctlret == EIO) { /* big workaround for media change, handle is unusable after that, that bug was found in QNX 6.2, 6.2.1 is not released yet. */ - for (i=0; iid) - { - drive=i; + for (i = 0; i < MAX_DRIVES; i++) { + if (SDL_cdopen[i] == cdrom->id) { + drive = i; break; } } - if (drive==-1) - { - /* that cannot happen, but ... */ - break; + if (drive == -1) { + /* that cannot happen, but ... */ + break; } - close(cdrom->id); - cdrom->id=open(SDL_cdlist[drive], QNX_CD_OPENMODE); - devctlret=EAGAIN; + close (cdrom->id); + cdrom->id = open (SDL_cdlist[drive], QNX_CD_OPENMODE); + devctlret = EAGAIN; } - if (devctlret==EAGAIN) - { + if (devctlret == EAGAIN) { eagaincnt++; } - if (eagaincnt==2) - { + if (eagaincnt == 2) { /* workaround for broken cdroms, which can return always EAGAIN when its not ready, */ /* that mean errornous media or just no media avail */ - devctlret=ENXIO; + devctlret = ENXIO; break; } - } while ((devctlret==EAGAIN)||(devctlret==ESTALE)); + } + while ((devctlret == EAGAIN) || (devctlret == ESTALE)); - if (devctlret != 0) - { - if (devctlret==ENXIO) - { + if (devctlret != 0) { + if (devctlret == ENXIO) { status = CD_TRAYEMPTY; - } - else - { + } else { status = CD_ERROR; } - } - else - { - switch (info.current_position.header.audio_status) - { - case CDROM_AUDIO_INVALID: - case CDROM_AUDIO_NO_STATUS: - /* Try to determine if there's a CD available */ - if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL)==0) - status = CD_STOPPED; - else - status = CD_TRAYEMPTY; - break; - case CDROM_AUDIO_COMPLETED: - status = CD_STOPPED; - break; - case CDROM_AUDIO_PLAY: - status = CD_PLAYING; - break; - case CDROM_AUDIO_PAUSED: - /* Workaround buggy CD-ROM drive */ - if (info.current_position.data_format == CDROM_LEADOUT) - { - status = CD_STOPPED; - } - else - { - status = CD_PAUSED; - } - break; - default: - status = CD_ERROR; - break; + } else { + switch (info.current_position.header.audio_status) { + case CDROM_AUDIO_INVALID: + case CDROM_AUDIO_NO_STATUS: + /* Try to determine if there's a CD available */ + if (devctl + (cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof (toc), + NULL) == 0) + status = CD_STOPPED; + else + status = CD_TRAYEMPTY; + break; + case CDROM_AUDIO_COMPLETED: + status = CD_STOPPED; + break; + case CDROM_AUDIO_PLAY: + status = CD_PLAYING; + break; + case CDROM_AUDIO_PAUSED: + /* Workaround buggy CD-ROM drive */ + if (info.current_position.data_format == CDROM_LEADOUT) { + status = CD_STOPPED; + } else { + status = CD_PAUSED; + } + break; + default: + status = CD_ERROR; + break; } } - if (position) - { - if (status==CD_PLAYING || (status==CD_PAUSED)) - { - *position = MSF_TO_FRAMES(info.current_position.addr.msf.minute, - info.current_position.addr.msf.second, - info.current_position.addr.msf.frame); - } - else - { - *position = 0; - } + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) { + *position = + MSF_TO_FRAMES (info.current_position.addr.msf.minute, + info.current_position.addr.msf.second, + info.current_position.addr.msf.frame); + } else { + *position = 0; + } } return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { cdrom_playmsf_t playtime; - FRAMES_TO_MSF(start, &playtime.start_minute, &playtime.start_second, &playtime.start_frame); - FRAMES_TO_MSF(start+length, &playtime.end_minute, &playtime.end_second, &playtime.end_frame); - - if (devctl(cdrom->id, DCMD_CAM_CDROMPLAYMSF, &playtime, sizeof(playtime), NULL) != 0) - { - return -1; - } - else - { - return 0; + FRAMES_TO_MSF (start, &playtime.start_minute, &playtime.start_second, + &playtime.start_frame); + FRAMES_TO_MSF (start + length, &playtime.end_minute, &playtime.end_second, + &playtime.end_frame); + + if (devctl + (cdrom->id, DCMD_CAM_CDROMPLAYMSF, &playtime, sizeof (playtime), + NULL) != 0) { + return -1; + } else { + return 0; } } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { - if (devctl(cdrom->id, DCMD_CAM_CDROMPAUSE, NULL, 0, NULL)!=0) - { - return -1; - } - else - { - return 0; + if (devctl (cdrom->id, DCMD_CAM_CDROMPAUSE, NULL, 0, NULL) != 0) { + return -1; + } else { + return 0; } } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { - if (devctl(cdrom->id, DCMD_CAM_CDROMRESUME, NULL, 0, NULL)!=0) - { - return -1; - } - else - { - return 0; + if (devctl (cdrom->id, DCMD_CAM_CDROMRESUME, NULL, 0, NULL) != 0) { + return -1; + } else { + return 0; } } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - if (devctl(cdrom->id, DCMD_CAM_CDROMSTOP, NULL, 0, NULL)!=0) - { - return -1; - } - else - { - return 0; + if (devctl (cdrom->id, DCMD_CAM_CDROMSTOP, NULL, 0, NULL) != 0) { + return -1; + } else { + return 0; } } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - if (devctl(cdrom->id, DCMD_CAM_EJECT_MEDIA, NULL, 0, NULL)!=0) - { - return -1; - } - else - { - return 0; + if (devctl (cdrom->id, DCMD_CAM_EJECT_MEDIA, NULL, 0, NULL) != 0) { + return -1; + } else { + return 0; } } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { int i; - for (i=0; iid) - { - SDL_cdopen[i]=0; - break; - } + for (i = 0; i < MAX_DRIVES; i++) { + if (SDL_cdopen[i] == cdrom->id) { + SDL_cdopen[i] = 0; + break; + } } - close(cdrom->id); + close (cdrom->id); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { int i; - if (SDL_numcds > 0) - { - for (i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); } SDL_numcds = 0; } } #endif /* SDL_CDROM_QNX */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cdrom/win32/SDL_syscdrom.c b/src/cdrom/win32/SDL_syscdrom.c index 3d0587dad..2aa1b06ce 100644 --- a/src/cdrom/win32/SDL_syscdrom.c +++ b/src/cdrom/win32/SDL_syscdrom.c @@ -33,10 +33,10 @@ #include "../SDL_syscdrom.h" /* This really broken?? */ -#define BROKEN_MCI_PAUSE /* Pausing actually stops play -- Doh! */ +#define BROKEN_MCI_PAUSE /* Pausing actually stops play -- Doh! */ /* The maximum number of CD-ROM drives we'll detect (Don't change!) */ -#define MAX_DRIVES 26 +#define MAX_DRIVES 26 /* A list of available CD-ROM drives */ static char *SDL_cdlist[MAX_DRIVES]; @@ -47,339 +47,354 @@ static int SDL_paused[MAX_DRIVES]; static int SDL_CD_end_position; /* The system-dependent CD control functions */ -static const char *SDL_SYS_CDName(int drive); -static int SDL_SYS_CDOpen(int drive); -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); -static int SDL_SYS_CDPause(SDL_CD *cdrom); -static int SDL_SYS_CDResume(SDL_CD *cdrom); -static int SDL_SYS_CDStop(SDL_CD *cdrom); -static int SDL_SYS_CDEject(SDL_CD *cdrom); -static void SDL_SYS_CDClose(SDL_CD *cdrom); +static const char *SDL_SYS_CDName (int drive); +static int SDL_SYS_CDOpen (int drive); +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom); +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position); +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length); +static int SDL_SYS_CDPause (SDL_CD * cdrom); +static int SDL_SYS_CDResume (SDL_CD * cdrom); +static int SDL_SYS_CDStop (SDL_CD * cdrom); +static int SDL_SYS_CDEject (SDL_CD * cdrom); +static void SDL_SYS_CDClose (SDL_CD * cdrom); /* Add a CD-ROM drive to our list of valid drives */ -static void AddDrive(char *drive) +static void +AddDrive (char *drive) { - int i; - - if ( SDL_numcds < MAX_DRIVES ) { - /* Add this drive to our list */ - i = SDL_numcds; - SDL_cdlist[i] = SDL_strdup(drive); - if ( SDL_cdlist[i] == NULL ) { - SDL_OutOfMemory(); - return; - } - ++SDL_numcds; + int i; + + if (SDL_numcds < MAX_DRIVES) { + /* Add this drive to our list */ + i = SDL_numcds; + SDL_cdlist[i] = SDL_strdup (drive); + if (SDL_cdlist[i] == NULL) { + SDL_OutOfMemory (); + return; + } + ++SDL_numcds; #ifdef CDROM_DEBUG - fprintf(stderr, "Added CD-ROM drive: %s\n", drive); + fprintf (stderr, "Added CD-ROM drive: %s\n", drive); #endif - } + } } -int SDL_SYS_CDInit(void) +int +SDL_SYS_CDInit (void) { - /* checklist: Drive 'A' - 'Z' */ - int i; - char drive[4]; - - /* Fill in our driver capabilities */ - SDL_CDcaps.Name = SDL_SYS_CDName; - SDL_CDcaps.Open = SDL_SYS_CDOpen; - SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; - SDL_CDcaps.Status = SDL_SYS_CDStatus; - SDL_CDcaps.Play = SDL_SYS_CDPlay; - SDL_CDcaps.Pause = SDL_SYS_CDPause; - SDL_CDcaps.Resume = SDL_SYS_CDResume; - SDL_CDcaps.Stop = SDL_SYS_CDStop; - SDL_CDcaps.Eject = SDL_SYS_CDEject; - SDL_CDcaps.Close = SDL_SYS_CDClose; - - /* Scan the system for CD-ROM drives */ - for ( i='A'; i<='Z'; ++i ) { - SDL_snprintf(drive, SDL_arraysize(drive), "%c:\\", i); - if ( GetDriveType(drive) == DRIVE_CDROM ) { - AddDrive(drive); - } - } - SDL_memset(SDL_mciID, 0, sizeof(SDL_mciID)); - return(0); + /* checklist: Drive 'A' - 'Z' */ + int i; + char drive[4]; + + /* Fill in our driver capabilities */ + SDL_CDcaps.Name = SDL_SYS_CDName; + SDL_CDcaps.Open = SDL_SYS_CDOpen; + SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; + SDL_CDcaps.Status = SDL_SYS_CDStatus; + SDL_CDcaps.Play = SDL_SYS_CDPlay; + SDL_CDcaps.Pause = SDL_SYS_CDPause; + SDL_CDcaps.Resume = SDL_SYS_CDResume; + SDL_CDcaps.Stop = SDL_SYS_CDStop; + SDL_CDcaps.Eject = SDL_SYS_CDEject; + SDL_CDcaps.Close = SDL_SYS_CDClose; + + /* Scan the system for CD-ROM drives */ + for (i = 'A'; i <= 'Z'; ++i) { + SDL_snprintf (drive, SDL_arraysize (drive), "%c:\\", i); + if (GetDriveType (drive) == DRIVE_CDROM) { + AddDrive (drive); + } + } + SDL_memset (SDL_mciID, 0, sizeof (SDL_mciID)); + return (0); } /* General ioctl() CD-ROM command function */ -static int SDL_SYS_CDioctl(int id, UINT msg, DWORD flags, void *arg) +static int +SDL_SYS_CDioctl (int id, UINT msg, DWORD flags, void *arg) { - MCIERROR mci_error; + MCIERROR mci_error; - mci_error = mciSendCommand(SDL_mciID[id], msg, flags, (DWORD_PTR)arg); - if ( mci_error ) { - char error[256]; + mci_error = mciSendCommand (SDL_mciID[id], msg, flags, (DWORD_PTR) arg); + if (mci_error) { + char error[256]; - mciGetErrorString(mci_error, error, 256); - SDL_SetError("mciSendCommand() error: %s", error); - } - return(!mci_error ? 0 : -1); + mciGetErrorString (mci_error, error, 256); + SDL_SetError ("mciSendCommand() error: %s", error); + } + return (!mci_error ? 0 : -1); } -static const char *SDL_SYS_CDName(int drive) +static const char * +SDL_SYS_CDName (int drive) { - return(SDL_cdlist[drive]); + return (SDL_cdlist[drive]); } -static int SDL_SYS_CDOpen(int drive) +static int +SDL_SYS_CDOpen (int drive) { - MCI_OPEN_PARMS mci_open; - MCI_SET_PARMS mci_set; - char device[3]; - DWORD flags; - - /* Open the requested device */ - mci_open.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO; - device[0] = *SDL_cdlist[drive]; - device[1] = ':'; - device[2] = '\0'; - mci_open.lpstrElementName = device; - flags = - (MCI_OPEN_TYPE|MCI_OPEN_SHAREABLE|MCI_OPEN_TYPE_ID|MCI_OPEN_ELEMENT); - if ( SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0 ) { - flags &= ~MCI_OPEN_SHAREABLE; - if ( SDL_SYS_CDioctl(0, MCI_OPEN, flags, &mci_open) < 0 ) { - return(-1); - } - } - SDL_mciID[drive] = mci_open.wDeviceID; - - /* Set the minute-second-frame time format */ - mci_set.dwTimeFormat = MCI_FORMAT_MSF; - SDL_SYS_CDioctl(drive, MCI_SET, MCI_SET_TIME_FORMAT, &mci_set); + MCI_OPEN_PARMS mci_open; + MCI_SET_PARMS mci_set; + char device[3]; + DWORD flags; + + /* Open the requested device */ + mci_open.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO; + device[0] = *SDL_cdlist[drive]; + device[1] = ':'; + device[2] = '\0'; + mci_open.lpstrElementName = device; + flags = + (MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE | MCI_OPEN_TYPE_ID | + MCI_OPEN_ELEMENT); + if (SDL_SYS_CDioctl (0, MCI_OPEN, flags, &mci_open) < 0) { + flags &= ~MCI_OPEN_SHAREABLE; + if (SDL_SYS_CDioctl (0, MCI_OPEN, flags, &mci_open) < 0) { + return (-1); + } + } + SDL_mciID[drive] = mci_open.wDeviceID; + + /* Set the minute-second-frame time format */ + mci_set.dwTimeFormat = MCI_FORMAT_MSF; + SDL_SYS_CDioctl (drive, MCI_SET, MCI_SET_TIME_FORMAT, &mci_set); #ifdef BROKEN_MCI_PAUSE - SDL_paused[drive] = 0; + SDL_paused[drive] = 0; #endif - return(drive); + return (drive); } -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) +static int +SDL_SYS_CDGetTOC (SDL_CD * cdrom) { - MCI_STATUS_PARMS mci_status; - int i, okay; - DWORD flags; - - okay = 0; - mci_status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS; - flags = MCI_STATUS_ITEM | MCI_WAIT; - if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0 ) { - cdrom->numtracks = mci_status.dwReturn; - if ( cdrom->numtracks > SDL_MAX_TRACKS ) { - cdrom->numtracks = SDL_MAX_TRACKS; - } - /* Read all the track TOC entries */ - flags = MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT; - for ( i=0; inumtracks; ++i ) { - cdrom->track[i].id = i+1; - mci_status.dwTrack = cdrom->track[i].id; + MCI_STATUS_PARMS mci_status; + int i, okay; + DWORD flags; + + okay = 0; + mci_status.dwItem = MCI_STATUS_NUMBER_OF_TRACKS; + flags = MCI_STATUS_ITEM | MCI_WAIT; + if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, &mci_status) == 0) { + cdrom->numtracks = mci_status.dwReturn; + if (cdrom->numtracks > SDL_MAX_TRACKS) { + cdrom->numtracks = SDL_MAX_TRACKS; + } + /* Read all the track TOC entries */ + flags = MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT; + for (i = 0; i < cdrom->numtracks; ++i) { + cdrom->track[i].id = i + 1; + mci_status.dwTrack = cdrom->track[i].id; #ifdef MCI_CDA_STATUS_TYPE_TRACK - mci_status.dwItem = MCI_CDA_STATUS_TYPE_TRACK; - if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, - &mci_status) < 0 ) { - break; - } - if ( mci_status.dwReturn == MCI_CDA_TRACK_AUDIO ) { - cdrom->track[i].type = SDL_AUDIO_TRACK; - } else { - cdrom->track[i].type = SDL_DATA_TRACK; - } + mci_status.dwItem = MCI_CDA_STATUS_TYPE_TRACK; + if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, + &mci_status) < 0) { + break; + } + if (mci_status.dwReturn == MCI_CDA_TRACK_AUDIO) { + cdrom->track[i].type = SDL_AUDIO_TRACK; + } else { + cdrom->track[i].type = SDL_DATA_TRACK; + } #else - cdrom->track[i].type = SDL_AUDIO_TRACK; + cdrom->track[i].type = SDL_AUDIO_TRACK; #endif - mci_status.dwItem = MCI_STATUS_POSITION; - if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, - &mci_status) < 0 ) { - break; - } - cdrom->track[i].offset = MSF_TO_FRAMES( - MCI_MSF_MINUTE(mci_status.dwReturn), - MCI_MSF_SECOND(mci_status.dwReturn), - MCI_MSF_FRAME(mci_status.dwReturn)); - cdrom->track[i].length = 0; - if ( i > 0 ) { - cdrom->track[i-1].length = - cdrom->track[i].offset- - cdrom->track[i-1].offset; - } - } - if ( i == cdrom->numtracks ) { - mci_status.dwTrack = cdrom->track[i - 1].id; - mci_status.dwItem = MCI_STATUS_LENGTH; - if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, - &mci_status) == 0 ) { - cdrom->track[i - 1].length = MSF_TO_FRAMES( - MCI_MSF_MINUTE(mci_status.dwReturn), - MCI_MSF_SECOND(mci_status.dwReturn), - MCI_MSF_FRAME(mci_status.dwReturn)); - /* compute lead-out offset */ - cdrom->track[i].offset = cdrom->track[i - 1].offset + - cdrom->track[i - 1].length; - cdrom->track[i].length = 0; - okay = 1; - } - } - } - return(okay ? 0 : -1); + mci_status.dwItem = MCI_STATUS_POSITION; + if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, + &mci_status) < 0) { + break; + } + cdrom->track[i].offset = + MSF_TO_FRAMES (MCI_MSF_MINUTE (mci_status.dwReturn), + MCI_MSF_SECOND (mci_status.dwReturn), + MCI_MSF_FRAME (mci_status.dwReturn)); + cdrom->track[i].length = 0; + if (i > 0) { + cdrom->track[i - 1].length = + cdrom->track[i].offset - cdrom->track[i - 1].offset; + } + } + if (i == cdrom->numtracks) { + mci_status.dwTrack = cdrom->track[i - 1].id; + mci_status.dwItem = MCI_STATUS_LENGTH; + if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, + &mci_status) == 0) { + cdrom->track[i - 1].length = + MSF_TO_FRAMES (MCI_MSF_MINUTE (mci_status.dwReturn), + MCI_MSF_SECOND (mci_status.dwReturn), + MCI_MSF_FRAME (mci_status.dwReturn)); + /* compute lead-out offset */ + cdrom->track[i].offset = cdrom->track[i - 1].offset + + cdrom->track[i - 1].length; + cdrom->track[i].length = 0; + okay = 1; + } + } + } + return (okay ? 0 : -1); } /* Get CD-ROM status */ -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) +static CDstatus +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position) { - CDstatus status; - MCI_STATUS_PARMS mci_status; - DWORD flags; - - flags = MCI_STATUS_ITEM | MCI_WAIT; - mci_status.dwItem = MCI_STATUS_MODE; - if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) < 0 ) { - status = CD_ERROR; - } else { - switch (mci_status.dwReturn) { - case MCI_MODE_NOT_READY: - case MCI_MODE_OPEN: - status = CD_TRAYEMPTY; - break; - case MCI_MODE_STOP: + CDstatus status; + MCI_STATUS_PARMS mci_status; + DWORD flags; + + flags = MCI_STATUS_ITEM | MCI_WAIT; + mci_status.dwItem = MCI_STATUS_MODE; + if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, &mci_status) < 0) { + status = CD_ERROR; + } else { + switch (mci_status.dwReturn) { + case MCI_MODE_NOT_READY: + case MCI_MODE_OPEN: + status = CD_TRAYEMPTY; + break; + case MCI_MODE_STOP: #ifdef BROKEN_MCI_PAUSE - if ( SDL_paused[cdrom->id] ) { - status = CD_PAUSED; - } else { - status = CD_STOPPED; - } + if (SDL_paused[cdrom->id]) { + status = CD_PAUSED; + } else { + status = CD_STOPPED; + } #else - status = CD_STOPPED; + status = CD_STOPPED; #endif /* BROKEN_MCI_PAUSE */ - break; - case MCI_MODE_PLAY: + break; + case MCI_MODE_PLAY: #ifdef BROKEN_MCI_PAUSE - if ( SDL_paused[cdrom->id] ) { - status = CD_PAUSED; - } else { - status = CD_PLAYING; - } + if (SDL_paused[cdrom->id]) { + status = CD_PAUSED; + } else { + status = CD_PLAYING; + } #else - status = CD_PLAYING; + status = CD_PLAYING; #endif /* BROKEN_MCI_PAUSE */ - break; - case MCI_MODE_PAUSE: - status = CD_PAUSED; - break; - default: - status = CD_ERROR; - break; - } - } - if ( position ) { - if ( status == CD_PLAYING || (status == CD_PAUSED) ) { - mci_status.dwItem = MCI_STATUS_POSITION; - if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, - &mci_status) == 0 ) { - *position = MSF_TO_FRAMES( - MCI_MSF_MINUTE(mci_status.dwReturn), - MCI_MSF_SECOND(mci_status.dwReturn), - MCI_MSF_FRAME(mci_status.dwReturn)); - } else { - *position = 0; - } - } else { - *position = 0; - } - } - return(status); + break; + case MCI_MODE_PAUSE: + status = CD_PAUSED; + break; + default: + status = CD_ERROR; + break; + } + } + if (position) { + if (status == CD_PLAYING || (status == CD_PAUSED)) { + mci_status.dwItem = MCI_STATUS_POSITION; + if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, + &mci_status) == 0) { + *position = + MSF_TO_FRAMES (MCI_MSF_MINUTE (mci_status.dwReturn), + MCI_MSF_SECOND (mci_status.dwReturn), + MCI_MSF_FRAME (mci_status.dwReturn)); + } else { + *position = 0; + } + } else { + *position = 0; + } + } + return (status); } /* Start play */ -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) +static int +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length) { - MCI_PLAY_PARMS mci_play; - int m, s, f; - DWORD flags; - - flags = MCI_FROM | MCI_TO | MCI_NOTIFY; - mci_play.dwCallback = 0; - FRAMES_TO_MSF(start, &m, &s, &f); - mci_play.dwFrom = MCI_MAKE_MSF(m, s, f); - FRAMES_TO_MSF(start+length, &m, &s, &f); - mci_play.dwTo = MCI_MAKE_MSF(m, s, f); - SDL_CD_end_position = mci_play.dwTo; - return(SDL_SYS_CDioctl(cdrom->id, MCI_PLAY, flags, &mci_play)); + MCI_PLAY_PARMS mci_play; + int m, s, f; + DWORD flags; + + flags = MCI_FROM | MCI_TO | MCI_NOTIFY; + mci_play.dwCallback = 0; + FRAMES_TO_MSF (start, &m, &s, &f); + mci_play.dwFrom = MCI_MAKE_MSF (m, s, f); + FRAMES_TO_MSF (start + length, &m, &s, &f); + mci_play.dwTo = MCI_MAKE_MSF (m, s, f); + SDL_CD_end_position = mci_play.dwTo; + return (SDL_SYS_CDioctl (cdrom->id, MCI_PLAY, flags, &mci_play)); } /* Pause play */ -static int SDL_SYS_CDPause(SDL_CD *cdrom) +static int +SDL_SYS_CDPause (SDL_CD * cdrom) { #ifdef BROKEN_MCI_PAUSE - SDL_paused[cdrom->id] = 1; + SDL_paused[cdrom->id] = 1; #endif - return(SDL_SYS_CDioctl(cdrom->id, MCI_PAUSE, MCI_WAIT, NULL)); + return (SDL_SYS_CDioctl (cdrom->id, MCI_PAUSE, MCI_WAIT, NULL)); } /* Resume play */ -static int SDL_SYS_CDResume(SDL_CD *cdrom) +static int +SDL_SYS_CDResume (SDL_CD * cdrom) { #ifdef BROKEN_MCI_PAUSE - MCI_STATUS_PARMS mci_status; - int okay; - int flags; - - okay = 0; - /* Play from the current play position to the end position set earlier */ - flags = MCI_STATUS_ITEM | MCI_WAIT; - mci_status.dwItem = MCI_STATUS_POSITION; - if ( SDL_SYS_CDioctl(cdrom->id, MCI_STATUS, flags, &mci_status) == 0 ) { - MCI_PLAY_PARMS mci_play; - - flags = MCI_FROM | MCI_TO | MCI_NOTIFY; - mci_play.dwCallback = 0; - mci_play.dwFrom = mci_status.dwReturn; - mci_play.dwTo = SDL_CD_end_position; - if (SDL_SYS_CDioctl(cdrom->id,MCI_PLAY,flags,&mci_play) == 0) { - okay = 1; - SDL_paused[cdrom->id] = 0; - } - } - return(okay ? 0 : -1); + MCI_STATUS_PARMS mci_status; + int okay; + int flags; + + okay = 0; + /* Play from the current play position to the end position set earlier */ + flags = MCI_STATUS_ITEM | MCI_WAIT; + mci_status.dwItem = MCI_STATUS_POSITION; + if (SDL_SYS_CDioctl (cdrom->id, MCI_STATUS, flags, &mci_status) == 0) { + MCI_PLAY_PARMS mci_play; + + flags = MCI_FROM | MCI_TO | MCI_NOTIFY; + mci_play.dwCallback = 0; + mci_play.dwFrom = mci_status.dwReturn; + mci_play.dwTo = SDL_CD_end_position; + if (SDL_SYS_CDioctl (cdrom->id, MCI_PLAY, flags, &mci_play) == 0) { + okay = 1; + SDL_paused[cdrom->id] = 0; + } + } + return (okay ? 0 : -1); #else - return(SDL_SYS_CDioctl(cdrom->id, MCI_RESUME, MCI_WAIT, NULL)); + return (SDL_SYS_CDioctl (cdrom->id, MCI_RESUME, MCI_WAIT, NULL)); #endif /* BROKEN_MCI_PAUSE */ } /* Stop play */ -static int SDL_SYS_CDStop(SDL_CD *cdrom) +static int +SDL_SYS_CDStop (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, MCI_STOP, MCI_WAIT, NULL)); + return (SDL_SYS_CDioctl (cdrom->id, MCI_STOP, MCI_WAIT, NULL)); } /* Eject the CD-ROM */ -static int SDL_SYS_CDEject(SDL_CD *cdrom) +static int +SDL_SYS_CDEject (SDL_CD * cdrom) { - return(SDL_SYS_CDioctl(cdrom->id, MCI_SET, MCI_SET_DOOR_OPEN, NULL)); + return (SDL_SYS_CDioctl (cdrom->id, MCI_SET, MCI_SET_DOOR_OPEN, NULL)); } /* Close the CD-ROM handle */ -static void SDL_SYS_CDClose(SDL_CD *cdrom) +static void +SDL_SYS_CDClose (SDL_CD * cdrom) { - SDL_SYS_CDioctl(cdrom->id, MCI_CLOSE, MCI_WAIT, NULL); + SDL_SYS_CDioctl (cdrom->id, MCI_CLOSE, MCI_WAIT, NULL); } -void SDL_SYS_CDQuit(void) +void +SDL_SYS_CDQuit (void) { - int i; - - if ( SDL_numcds > 0 ) { - for ( i=0; i 0) { + for (i = 0; i < SDL_numcds; ++i) { + SDL_free (SDL_cdlist[i]); + } + SDL_numcds = 0; + } } #endif /* SDL_CDROM_WIN32 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index b74a6f306..84e53145a 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -27,7 +27,7 @@ #include "SDL_cpuinfo.h" #if defined(__MACOSX__) && defined(__ppc__) -#include /* For AltiVec check */ +#include /* For AltiVec check */ #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP #include #include @@ -47,400 +47,351 @@ the idea is borrowed from the libmpeg2 library - thanks! */ static jmp_buf jmpbuf; -static void illegal_instruction(int sig) +static void +illegal_instruction (int sig) { - longjmp(jmpbuf, 1); + longjmp (jmpbuf, 1); } #endif /* HAVE_SETJMP */ -static __inline__ int CPU_haveCPUID(void) +static __inline__ int +CPU_haveCPUID (void) { - int has_CPUID = 0; + int has_CPUID = 0; #if defined(__GNUC__) && defined(i386) - __asm__ ( -" pushfl # Get original EFLAGS \n" -" popl %%eax \n" -" movl %%eax,%%ecx \n" -" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n" -" pushl %%eax # Save new EFLAGS value on stack \n" -" popfl # Replace current EFLAGS value \n" -" pushfl # Get new EFLAGS \n" -" popl %%eax # Store new EFLAGS in EAX \n" -" xorl %%ecx,%%eax # Can not toggle ID bit, \n" -" jz 1f # Processor=80486 \n" -" movl $1,%0 # We have CPUID support \n" -"1: \n" - : "=m" (has_CPUID) - : - : "%eax", "%ecx" - ); + __asm__ (" pushfl # Get original EFLAGS \n" " popl %%eax \n" " movl %%eax,%%ecx \n" " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n" " pushl %%eax # Save new EFLAGS value on stack \n" " popfl # Replace current EFLAGS value \n" " pushfl # Get new EFLAGS \n" " popl %%eax # Store new EFLAGS in EAX \n" " xorl %%ecx,%%eax # Can not toggle ID bit, \n" " jz 1f # Processor=80486 \n" " movl $1,%0 # We have CPUID support \n" "1: \n": "=m" (has_CPUID): + :"%eax", "%ecx"); #elif defined(__GNUC__) && defined(__x86_64__) /* Technically, if this is being compiled under __x86_64__ then it has CPUid by definition. But it's nice to be able to prove it. :) */ - __asm__ ( -" pushfq # Get original EFLAGS \n" -" popq %%rax \n" -" movq %%rax,%%rcx \n" -" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n" -" pushq %%rax # Save new EFLAGS value on stack \n" -" popfq # Replace current EFLAGS value \n" -" pushfq # Get new EFLAGS \n" -" popq %%rax # Store new EFLAGS in EAX \n" -" xorl %%ecx,%%eax # Can not toggle ID bit, \n" -" jz 1f # Processor=80486 \n" -" movl $1,%0 # We have CPUID support \n" -"1: \n" - : "=m" (has_CPUID) - : - : "%rax", "%rcx" - ); + __asm__ (" pushfq # Get original EFLAGS \n" " popq %%rax \n" " movq %%rax,%%rcx \n" " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n" " pushq %%rax # Save new EFLAGS value on stack \n" " popfq # Replace current EFLAGS value \n" " pushfq # Get new EFLAGS \n" " popq %%rax # Store new EFLAGS in EAX \n" " xorl %%ecx,%%eax # Can not toggle ID bit, \n" " jz 1f # Processor=80486 \n" " movl $1,%0 # We have CPUID support \n" "1: \n": "=m" (has_CPUID): + :"%rax", "%rcx"); #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) - __asm { - pushfd ; Get original EFLAGS - pop eax - mov ecx, eax - xor eax, 200000h ; Flip ID bit in EFLAGS - push eax ; Save new EFLAGS value on stack - popfd ; Replace current EFLAGS value - pushfd ; Get new EFLAGS - pop eax ; Store new EFLAGS in EAX - xor eax, ecx ; Can not toggle ID bit, - jz done ; Processor=80486 - mov has_CPUID,1 ; We have CPUID support -done: - } + __asm { + pushfd; + Get original EFLAGS pop eax mov ecx, eax xor eax, 200000 h; + Flip ID bit in EFLAGS push eax; + Save new EFLAGS value on stack popfd; + Replace current EFLAGS value pushfd; + Get new EFLAGS pop eax; + Store new EFLAGS in EAX xor eax, ecx; + Can not toggle ID bit, jz done; + Processor = 80486 mov has_CPUID, 1; + We have CPUID support done:} #elif defined(__sun) && defined(__x86) - __asm ( -" pushfl \n" -" popl %eax \n" -" movl %eax,%ecx \n" -" xorl $0x200000,%eax \n" -" pushl %eax \n" -" popfl \n" -" pushfl \n" -" popl %eax \n" -" xorl %ecx,%eax \n" -" jz 1f \n" -" movl $1,-8(%ebp) \n" -"1: \n" - ); + __asm (" pushfl \n" + " popl %eax \n" + " movl %eax,%ecx \n" + " xorl $0x200000,%eax \n" + " pushl %eax \n" + " popfl \n" + " pushfl \n" + " popl %eax \n" + " xorl %ecx,%eax \n" + " jz 1f \n" + " movl $1,-8(%ebp) \n" + "1: \n"); #elif defined(__sun) && defined(__amd64) - __asm ( -" pushfq \n" -" popq %rax \n" -" movq %rax,%rcx \n" -" xorl $0x200000,%eax \n" -" pushq %rax \n" -" popfq \n" -" pushfq \n" -" popq %rax \n" -" xorl %ecx,%eax \n" -" jz 1f \n" -" movl $1,-8(%rbp) \n" -"1: \n" - ); + __asm (" pushfq \n" + " popq %rax \n" + " movq %rax,%rcx \n" + " xorl $0x200000,%eax \n" + " pushq %rax \n" + " popfq \n" + " pushfq \n" + " popq %rax \n" + " xorl %ecx,%eax \n" + " jz 1f \n" + " movl $1,-8(%rbp) \n" + "1: \n"); #endif - return has_CPUID; + return has_CPUID; } -static __inline__ int CPU_getCPUIDFeatures(void) +static __inline__ int +CPU_getCPUIDFeatures (void) { - int features = 0; + int features = 0; #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) ) - __asm__ ( -" movl %%ebx,%%edi\n" -" xorl %%eax,%%eax # Set up for CPUID instruction \n" -" cpuid # Get and save vendor ID \n" -" cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" -" jl 1f # We dont have the CPUID instruction\n" -" xorl %%eax,%%eax \n" -" incl %%eax \n" -" cpuid # Get family/model/stepping/features\n" -" movl %%edx,%0 \n" -"1: \n" -" movl %%edi,%%ebx\n" - : "=m" (features) - : - : "%eax", "%ecx", "%edx", "%edi" - ); + __asm__ (" movl %%ebx,%%edi\n" " xorl %%eax,%%eax # Set up for CPUID instruction \n" " cpuid # Get and save vendor ID \n" " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" " jl 1f # We dont have the CPUID instruction\n" " xorl %%eax,%%eax \n" " incl %%eax \n" " cpuid # Get family/model/stepping/features\n" " movl %%edx,%0 \n" "1: \n" " movl %%edi,%%ebx\n": "=m" (features): + :"%eax", "%ecx", "%edx", "%edi"); #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) - __asm { - xor eax, eax ; Set up for CPUID instruction - cpuid ; Get and save vendor ID - cmp eax, 1 ; Make sure 1 is valid input for CPUID - jl done ; We dont have the CPUID instruction - xor eax, eax - inc eax - cpuid ; Get family/model/stepping/features - mov features, edx -done: - } + __asm { + xor eax, eax; + Set up for CPUID instruction + cpuid; Get and save vendor ID + cmp eax, 1; Make sure 1 is valid input for CPUID + jl done; We dont have the CPUID instruction + xor eax, eax + inc eax + cpuid; Get family / model / stepping / features + mov features, edx done:} #elif defined(__sun) && (defined(__x86) || defined(__amd64)) - __asm( -" movl %ebx,%edi\n" -" xorl %eax,%eax \n" -" cpuid \n" -" cmpl $1,%eax \n" -" jl 1f \n" -" xorl %eax,%eax \n" -" incl %eax \n" -" cpuid \n" + __asm + (" movl %ebx,%edi\n" + " xorl %eax,%eax \n" + " cpuid \n" + " cmpl $1,%eax \n" + " jl 1f \n" + " xorl %eax,%eax \n" + " incl %eax \n" + " cpuid \n" #ifdef __i386 -" movl %edx,-8(%ebp) \n" + " movl %edx,-8(%ebp) \n" #else -" movl %edx,-8(%rbp) \n" + " movl %edx,-8(%rbp) \n" #endif -"1: \n" -" movl %edi,%ebx\n" ); + "1: \n" + " movl %edi,%ebx\n"); #endif - return features; + return features; } -static __inline__ int CPU_getCPUIDFeaturesExt(void) +static __inline__ int +CPU_getCPUIDFeaturesExt (void) { - int features = 0; + int features = 0; #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) ) - __asm__ ( -" movl %%ebx,%%edi\n" -" movl $0x80000000,%%eax # Query for extended functions \n" -" cpuid # Get extended function limit \n" -" cmpl $0x80000001,%%eax \n" -" jl 1f # Nope, we dont have function 800000001h\n" -" movl $0x80000001,%%eax # Setup extended function 800000001h\n" -" cpuid # and get the information \n" -" movl %%edx,%0 \n" -"1: \n" -" movl %%edi,%%ebx\n" - : "=m" (features) - : - : "%eax", "%ecx", "%edx", "%edi" - ); + __asm__ (" movl %%ebx,%%edi\n" " movl $0x80000000,%%eax # Query for extended functions \n" " cpuid # Get extended function limit \n" " cmpl $0x80000001,%%eax \n" " jl 1f # Nope, we dont have function 800000001h\n" " movl $0x80000001,%%eax # Setup extended function 800000001h\n" " cpuid # and get the information \n" " movl %%edx,%0 \n" "1: \n" " movl %%edi,%%ebx\n": "=m" (features): + :"%eax", "%ecx", "%edx", "%edi"); #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) - __asm { - mov eax,80000000h ; Query for extended functions - cpuid ; Get extended function limit - cmp eax,80000001h - jl done ; Nope, we dont have function 800000001h - mov eax,80000001h ; Setup extended function 800000001h - cpuid ; and get the information - mov features,edx -done: - } + __asm { + mov eax, 80000000 h; + Query for extended functions + cpuid; Get extended function limit + cmp eax, 80000001 h jl done; Nope + , we dont have function 800000001 h mov eax, 80000001 h; + Setup extended function 800000001 h cpuid; + and get the information mov features, edx done:} #elif defined(__sun) && ( defined(__i386) || defined(__amd64) ) - __asm ( -" movl %ebx,%edi\n" -" movl $0x80000000,%eax \n" -" cpuid \n" -" cmpl $0x80000001,%eax \n" -" jl 1f \n" -" movl $0x80000001,%eax \n" -" cpuid \n" + __asm (" movl %ebx,%edi\n" + " movl $0x80000000,%eax \n" + " cpuid \n" + " cmpl $0x80000001,%eax \n" + " jl 1f \n" + " movl $0x80000001,%eax \n" + " cpuid \n" #ifdef __i386 -" movl %edx,-8(%ebp) \n" + " movl %edx,-8(%ebp) \n" #else -" movl %edx,-8(%rbp) \n" + " movl %edx,-8(%rbp) \n" #endif -"1: \n" -" movl %edi,%ebx\n" - ); + "1: \n" + " movl %edi,%ebx\n"); #endif - return features; + return features; } -static __inline__ int CPU_haveRDTSC(void) +static __inline__ int +CPU_haveRDTSC (void) { - if ( CPU_haveCPUID() ) { - return (CPU_getCPUIDFeatures() & 0x00000010); - } - return 0; + if (CPU_haveCPUID ()) { + return (CPU_getCPUIDFeatures () & 0x00000010); + } + return 0; } -static __inline__ int CPU_haveMMX(void) +static __inline__ int +CPU_haveMMX (void) { - if ( CPU_haveCPUID() ) { - return (CPU_getCPUIDFeatures() & 0x00800000); - } - return 0; + if (CPU_haveCPUID ()) { + return (CPU_getCPUIDFeatures () & 0x00800000); + } + return 0; } -static __inline__ int CPU_haveMMXExt(void) +static __inline__ int +CPU_haveMMXExt (void) { - if ( CPU_haveCPUID() ) { - return (CPU_getCPUIDFeaturesExt() & 0x00400000); - } - return 0; + if (CPU_haveCPUID ()) { + return (CPU_getCPUIDFeaturesExt () & 0x00400000); + } + return 0; } -static __inline__ int CPU_have3DNow(void) +static __inline__ int +CPU_have3DNow (void) { - if ( CPU_haveCPUID() ) { - return (CPU_getCPUIDFeaturesExt() & 0x80000000); - } - return 0; + if (CPU_haveCPUID ()) { + return (CPU_getCPUIDFeaturesExt () & 0x80000000); + } + return 0; } -static __inline__ int CPU_have3DNowExt(void) +static __inline__ int +CPU_have3DNowExt (void) { - if ( CPU_haveCPUID() ) { - return (CPU_getCPUIDFeaturesExt() & 0x40000000); - } - return 0; + if (CPU_haveCPUID ()) { + return (CPU_getCPUIDFeaturesExt () & 0x40000000); + } + return 0; } -static __inline__ int CPU_haveSSE(void) +static __inline__ int +CPU_haveSSE (void) { - if ( CPU_haveCPUID() ) { - return (CPU_getCPUIDFeatures() & 0x02000000); - } - return 0; + if (CPU_haveCPUID ()) { + return (CPU_getCPUIDFeatures () & 0x02000000); + } + return 0; } -static __inline__ int CPU_haveSSE2(void) +static __inline__ int +CPU_haveSSE2 (void) { - if ( CPU_haveCPUID() ) { - return (CPU_getCPUIDFeatures() & 0x04000000); - } - return 0; + if (CPU_haveCPUID ()) { + return (CPU_getCPUIDFeatures () & 0x04000000); + } + return 0; } -static __inline__ int CPU_haveAltiVec(void) +static __inline__ int +CPU_haveAltiVec (void) { - volatile int altivec = 0; + volatile int altivec = 0; #if defined(__MACOSX__) && defined(__ppc__) - int selectors[2] = { CTL_HW, HW_VECTORUNIT }; - int hasVectorUnit = 0; - size_t length = sizeof(hasVectorUnit); - int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); - if( 0 == error ) - altivec = (hasVectorUnit != 0); + int selectors[2] = { CTL_HW, HW_VECTORUNIT }; + int hasVectorUnit = 0; + size_t length = sizeof (hasVectorUnit); + int error = sysctl (selectors, 2, &hasVectorUnit, &length, NULL, 0); + if (0 == error) + altivec = (hasVectorUnit != 0); #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP - void (*handler)(int sig); - handler = signal(SIGILL, illegal_instruction); - if ( setjmp(jmpbuf) == 0 ) { - asm volatile ("mtspr 256, %0\n\t" - "vand %%v0, %%v0, %%v0" - : - : "r" (-1)); - altivec = 1; - } - signal(SIGILL, handler); + void (*handler) (int sig); + handler = signal (SIGILL, illegal_instruction); + if (setjmp (jmpbuf) == 0) { + asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1)); + altivec = 1; + } + signal (SIGILL, handler); #endif - return altivec; + return altivec; } static Uint32 SDL_CPUFeatures = 0xFFFFFFFF; -static Uint32 SDL_GetCPUFeatures(void) +static Uint32 +SDL_GetCPUFeatures (void) { - if ( SDL_CPUFeatures == 0xFFFFFFFF ) { - SDL_CPUFeatures = 0; - if ( CPU_haveRDTSC() ) { - SDL_CPUFeatures |= CPU_HAS_RDTSC; - } - if ( CPU_haveMMX() ) { - SDL_CPUFeatures |= CPU_HAS_MMX; - } - if ( CPU_haveMMXExt() ) { - SDL_CPUFeatures |= CPU_HAS_MMXEXT; - } - if ( CPU_have3DNow() ) { - SDL_CPUFeatures |= CPU_HAS_3DNOW; - } - if ( CPU_have3DNowExt() ) { - SDL_CPUFeatures |= CPU_HAS_3DNOWEXT; - } - if ( CPU_haveSSE() ) { - SDL_CPUFeatures |= CPU_HAS_SSE; - } - if ( CPU_haveSSE2() ) { - SDL_CPUFeatures |= CPU_HAS_SSE2; - } - if ( CPU_haveAltiVec() ) { - SDL_CPUFeatures |= CPU_HAS_ALTIVEC; - } - } - return SDL_CPUFeatures; + if (SDL_CPUFeatures == 0xFFFFFFFF) { + SDL_CPUFeatures = 0; + if (CPU_haveRDTSC ()) { + SDL_CPUFeatures |= CPU_HAS_RDTSC; + } + if (CPU_haveMMX ()) { + SDL_CPUFeatures |= CPU_HAS_MMX; + } + if (CPU_haveMMXExt ()) { + SDL_CPUFeatures |= CPU_HAS_MMXEXT; + } + if (CPU_have3DNow ()) { + SDL_CPUFeatures |= CPU_HAS_3DNOW; + } + if (CPU_have3DNowExt ()) { + SDL_CPUFeatures |= CPU_HAS_3DNOWEXT; + } + if (CPU_haveSSE ()) { + SDL_CPUFeatures |= CPU_HAS_SSE; + } + if (CPU_haveSSE2 ()) { + SDL_CPUFeatures |= CPU_HAS_SSE2; + } + if (CPU_haveAltiVec ()) { + SDL_CPUFeatures |= CPU_HAS_ALTIVEC; + } + } + return SDL_CPUFeatures; } -SDL_bool SDL_HasRDTSC(void) +SDL_bool +SDL_HasRDTSC (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_RDTSC) { + return SDL_TRUE; + } + return SDL_FALSE; } -SDL_bool SDL_HasMMX(void) +SDL_bool +SDL_HasMMX (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_MMX) { + return SDL_TRUE; + } + return SDL_FALSE; } -SDL_bool SDL_HasMMXExt(void) +SDL_bool +SDL_HasMMXExt (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_MMXEXT) { + return SDL_TRUE; + } + return SDL_FALSE; } -SDL_bool SDL_Has3DNow(void) +SDL_bool +SDL_Has3DNow (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_3DNOW) { + return SDL_TRUE; + } + return SDL_FALSE; } -SDL_bool SDL_Has3DNowExt(void) +SDL_bool +SDL_Has3DNowExt (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_3DNOWEXT) { + return SDL_TRUE; + } + return SDL_FALSE; } -SDL_bool SDL_HasSSE(void) +SDL_bool +SDL_HasSSE (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_SSE) { + return SDL_TRUE; + } + return SDL_FALSE; } -SDL_bool SDL_HasSSE2(void) +SDL_bool +SDL_HasSSE2 (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_SSE2) { + return SDL_TRUE; + } + return SDL_FALSE; } -SDL_bool SDL_HasAltiVec(void) +SDL_bool +SDL_HasAltiVec (void) { - if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) { - return SDL_TRUE; - } - return SDL_FALSE; + if (SDL_GetCPUFeatures () & CPU_HAS_ALTIVEC) { + return SDL_TRUE; + } + return SDL_FALSE; } #ifdef TEST_MAIN #include -int main() +int +main () { - printf("RDTSC: %d\n", SDL_HasRDTSC()); - printf("MMX: %d\n", SDL_HasMMX()); - printf("MMXExt: %d\n", SDL_HasMMXExt()); - printf("3DNow: %d\n", SDL_Has3DNow()); - printf("3DNowExt: %d\n", SDL_Has3DNowExt()); - printf("SSE: %d\n", SDL_HasSSE()); - printf("SSE2: %d\n", SDL_HasSSE2()); - printf("AltiVec: %d\n", SDL_HasAltiVec()); - return 0; + printf ("RDTSC: %d\n", SDL_HasRDTSC ()); + printf ("MMX: %d\n", SDL_HasMMX ()); + printf ("MMXExt: %d\n", SDL_HasMMXExt ()); + printf ("3DNow: %d\n", SDL_Has3DNow ()); + printf ("3DNowExt: %d\n", SDL_Has3DNowExt ()); + printf ("SSE: %d\n", SDL_HasSSE ()); + printf ("SSE2: %d\n", SDL_HasSSE2 ()); + printf ("AltiVec: %d\n", SDL_HasAltiVec ()); + return 0; } #endif /* TEST_MAIN */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_active.c b/src/events/SDL_active.c deleted file mode 100644 index 17b5908a8..000000000 --- a/src/events/SDL_active.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* Application focus/iconification handling code for SDL */ - -#include "SDL_events.h" -#include "SDL_events_c.h" - - -/* These are static for our active event handling code */ -static Uint8 SDL_appstate = 0; - -/* Public functions */ -int SDL_AppActiveInit(void) -{ - /* Start completely active */ - SDL_appstate = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); - - /* That's it! */ - return(0); -} -void SDL_AppActiveQuit(void) -{ -} - -Uint8 SDL_GetAppState(void) -{ - return(SDL_appstate); -} - -/* This is global for SDL_eventloop.c */ -int SDL_PrivateAppActive(Uint8 gain, Uint8 state) -{ - int posted; - Uint8 new_state; - - /* Modify the current state with the given mask */ - if ( gain ) { - new_state = (SDL_appstate | state); - } else { - new_state = (SDL_appstate & ~state); - } - - /* Drop events that don't change state */ - if ( new_state == SDL_appstate ) { - return(0); - } - - /* Update internal active state */ - SDL_appstate = new_state; - - /* Post the event, if desired */ - posted = 0; - if ( SDL_ProcessEvents[SDL_ACTIVEEVENT] == SDL_ENABLE ) { - SDL_Event event; - SDL_memset(&event, 0, sizeof(event)); - event.type = SDL_ACTIVEEVENT; - event.active.gain = gain; - event.active.state = state; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - - /* If we lost keyboard focus, post key-up events */ - if ( (state & SDL_APPINPUTFOCUS) && !gain ) { - SDL_ResetKeyboard(); - } - return(posted); -} diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 1a51dbd7e..76cb30a98 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -39,41 +39,45 @@ static Uint32 SDL_eventstate = 0; /* Private data -- event queue */ #define MAXEVENTS 128 -static struct { - SDL_mutex *lock; - int active; - int head; - int tail; - SDL_Event event[MAXEVENTS]; - int wmmsg_next; - struct SDL_SysWMmsg wmmsg[MAXEVENTS]; +static struct +{ + SDL_mutex *lock; + int active; + int head; + int tail; + SDL_Event event[MAXEVENTS]; + int wmmsg_next; + struct SDL_SysWMmsg wmmsg[MAXEVENTS]; } SDL_EventQ; /* Private data -- event locking structure */ -static struct { - SDL_mutex *lock; - int safe; +static struct +{ + SDL_mutex *lock; + int safe; } SDL_EventLock; /* Thread functions */ -static SDL_Thread *SDL_EventThread = NULL; /* Thread handle */ -static Uint32 event_thread; /* The event thread id */ +static SDL_Thread *SDL_EventThread = NULL; /* Thread handle */ +static Uint32 event_thread; /* The event thread id */ -void SDL_Lock_EventThread(void) +void +SDL_Lock_EventThread (void) { - if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) { - /* Grab lock and spin until we're sure event thread stopped */ - SDL_mutexP(SDL_EventLock.lock); - while ( ! SDL_EventLock.safe ) { - SDL_Delay(1); - } - } + if (SDL_EventThread && (SDL_ThreadID () != event_thread)) { + /* Grab lock and spin until we're sure event thread stopped */ + SDL_mutexP (SDL_EventLock.lock); + while (!SDL_EventLock.safe) { + SDL_Delay (1); + } + } } -void SDL_Unlock_EventThread(void) +void +SDL_Unlock_EventThread (void) { - if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) { - SDL_mutexV(SDL_EventLock.lock); - } + if (SDL_EventThread && (SDL_ThreadID () != event_thread)) { + SDL_mutexV (SDL_EventLock.lock); + } } #ifdef __OS2__ @@ -87,414 +91,431 @@ void SDL_Unlock_EventThread(void) #include #endif -static int SDLCALL SDL_GobbleEvents(void *unused) +static int SDLCALL +SDL_GobbleEvents (void *unused) { - event_thread = SDL_ThreadID(); + event_thread = SDL_ThreadID (); #ifdef __OS2__ #ifdef USE_DOSSETPRIORITY - /* Increase thread priority, so it will process events in time for sure! */ - DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0); + /* Increase thread priority, so it will process events in time for sure! */ + DosSetPriority (PRTYS_THREAD, PRTYC_REGULAR, +16, 0); #endif #endif - while ( SDL_EventQ.active ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; + while (SDL_EventQ.active) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); - /* Get events from the video subsystem */ - if ( video ) { - video->PumpEvents(this); - } + /* Get events from the video subsystem */ + if (_this) { + _this->PumpEvents (_this); + } - /* Queue pending key-repeat events */ - SDL_CheckKeyRepeat(); + /* Queue pending key-repeat events */ + SDL_CheckKeyRepeat (); #if !SDL_JOYSTICK_DISABLED - /* Check for joystick state change */ - if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) { - SDL_JoystickUpdate(); - } + /* Check for joystick state change */ + if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) { + SDL_JoystickUpdate (); + } #endif - /* Give up the CPU for the rest of our timeslice */ - SDL_EventLock.safe = 1; - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(1); - - /* Check for event locking. - On the P of the lock mutex, if the lock is held, this thread - will wait until the lock is released before continuing. The - safe flag will be set, meaning that the other thread can go - about it's business. The safe flag is reset before the V, - so as soon as the mutex is free, other threads can see that - it's not safe to interfere with the event thread. - */ - SDL_mutexP(SDL_EventLock.lock); - SDL_EventLock.safe = 0; - SDL_mutexV(SDL_EventLock.lock); - } - SDL_SetTimerThreaded(0); - event_thread = 0; - return(0); + /* Give up the CPU for the rest of our timeslice */ + SDL_EventLock.safe = 1; + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); + } + SDL_Delay (1); + + /* Check for event locking. + On the P of the lock mutex, if the lock is held, this thread + will wait until the lock is released before continuing. The + safe flag will be set, meaning that the other thread can go + about it's business. The safe flag is reset before the V, + so as soon as the mutex is free, other threads can see that + it's not safe to interfere with the event thread. + */ + SDL_mutexP (SDL_EventLock.lock); + SDL_EventLock.safe = 0; + SDL_mutexV (SDL_EventLock.lock); + } + SDL_SetTimerThreaded (0); + event_thread = 0; + return (0); } -static int SDL_StartEventThread(Uint32 flags) +static int +SDL_StartEventThread (Uint32 flags) { - /* Reset everything to zero */ - SDL_EventThread = NULL; - SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock)); + /* Reset everything to zero */ + SDL_EventThread = NULL; + SDL_memset (&SDL_EventLock, 0, sizeof (SDL_EventLock)); - /* Create the lock and set ourselves active */ + /* Create the lock and set ourselves active */ #if !SDL_THREADS_DISABLED - SDL_EventQ.lock = SDL_CreateMutex(); - if ( SDL_EventQ.lock == NULL ) { -#ifdef __MACOS__ /* MacOS classic you can't multithread, so no lock needed */ - ; + SDL_EventQ.lock = SDL_CreateMutex (); + if (SDL_EventQ.lock == NULL) { +#ifdef __MACOS__ /* MacOS classic you can't multithread, so no lock needed */ + ; #else - return(-1); + return (-1); #endif - } + } #endif /* !SDL_THREADS_DISABLED */ - SDL_EventQ.active = 1; + SDL_EventQ.active = 1; - if ( (flags&SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) { - SDL_EventLock.lock = SDL_CreateMutex(); - if ( SDL_EventLock.lock == NULL ) { - return(-1); - } - SDL_EventLock.safe = 0; + if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { + SDL_EventLock.lock = SDL_CreateMutex (); + if (SDL_EventLock.lock == NULL) { + return (-1); + } + SDL_EventLock.safe = 0; - /* The event thread will handle timers too */ - SDL_SetTimerThreaded(2); + /* The event thread will handle timers too */ + SDL_SetTimerThreaded (2); #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) #undef SDL_CreateThread - SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL); + SDL_EventThread = + SDL_CreateThread (SDL_GobbleEvents, NULL, NULL, NULL); #else - SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL); + SDL_EventThread = SDL_CreateThread (SDL_GobbleEvents, NULL); #endif - if ( SDL_EventThread == NULL ) { - return(-1); - } - } else { - event_thread = 0; - } - return(0); + if (SDL_EventThread == NULL) { + return (-1); + } + } else { + event_thread = 0; + } + return (0); } -static void SDL_StopEventThread(void) +static void +SDL_StopEventThread (void) { - SDL_EventQ.active = 0; - if ( SDL_EventThread ) { - SDL_WaitThread(SDL_EventThread, NULL); - SDL_EventThread = NULL; - SDL_DestroyMutex(SDL_EventLock.lock); - } + SDL_EventQ.active = 0; + if (SDL_EventThread) { + SDL_WaitThread (SDL_EventThread, NULL); + SDL_EventThread = NULL; + SDL_DestroyMutex (SDL_EventLock.lock); + } #ifndef IPOD - SDL_DestroyMutex(SDL_EventQ.lock); + SDL_DestroyMutex (SDL_EventQ.lock); #endif } -Uint32 SDL_EventThreadID(void) +Uint32 +SDL_EventThreadID (void) { - return(event_thread); + return (event_thread); } /* Public functions */ -void SDL_StopEventLoop(void) +void +SDL_StopEventLoop (void) { - /* Halt the event thread, if running */ - SDL_StopEventThread(); - - /* Shutdown event handlers */ - SDL_AppActiveQuit(); - SDL_KeyboardQuit(); - SDL_MouseQuit(); - SDL_QuitQuit(); - - /* Clean out EventQ */ - SDL_EventQ.head = 0; - SDL_EventQ.tail = 0; - SDL_EventQ.wmmsg_next = 0; + /* Halt the event thread, if running */ + SDL_StopEventThread (); + + /* Shutdown event handlers */ + SDL_AppActiveQuit (); + SDL_KeyboardQuit (); + SDL_MouseQuit (); + SDL_QuitQuit (); + + /* Clean out EventQ */ + SDL_EventQ.head = 0; + SDL_EventQ.tail = 0; + SDL_EventQ.wmmsg_next = 0; } /* This function (and associated calls) may be called more than once */ -int SDL_StartEventLoop(Uint32 flags) +int +SDL_StartEventLoop (Uint32 flags) { - int retcode; - - /* Clean out the event queue */ - SDL_EventThread = NULL; - SDL_EventQ.lock = NULL; - SDL_StopEventLoop(); - - /* No filter to start with, process most event types */ - SDL_EventOK = NULL; - SDL_memset(SDL_ProcessEvents,SDL_ENABLE,sizeof(SDL_ProcessEvents)); - SDL_eventstate = ~0; - /* It's not save to call SDL_EventState() yet */ - SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT); - SDL_ProcessEvents[SDL_SYSWMEVENT] = SDL_IGNORE; - - /* Initialize event handlers */ - retcode = 0; - retcode += SDL_AppActiveInit(); - retcode += SDL_KeyboardInit(); - retcode += SDL_MouseInit(); - retcode += SDL_QuitInit(); - if ( retcode < 0 ) { - /* We don't expect them to fail, but... */ - return(-1); - } - - /* Create the lock and event thread */ - if ( SDL_StartEventThread(flags) < 0 ) { - SDL_StopEventLoop(); - return(-1); - } - return(0); + int retcode; + + /* Clean out the event queue */ + SDL_EventThread = NULL; + SDL_EventQ.lock = NULL; + SDL_StopEventLoop (); + + /* No filter to start with, process most event types */ + SDL_EventOK = NULL; + SDL_memset (SDL_ProcessEvents, SDL_ENABLE, sizeof (SDL_ProcessEvents)); + SDL_eventstate = ~0; + /* It's not save to call SDL_EventState() yet */ + SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT); + SDL_ProcessEvents[SDL_SYSWMEVENT] = SDL_IGNORE; + + /* Initialize event handlers */ + retcode = 0; + retcode += SDL_AppActiveInit (); + retcode += SDL_KeyboardInit (); + retcode += SDL_MouseInit (); + retcode += SDL_QuitInit (); + if (retcode < 0) { + /* We don't expect them to fail, but... */ + return (-1); + } + + /* Create the lock and event thread */ + if (SDL_StartEventThread (flags) < 0) { + SDL_StopEventLoop (); + return (-1); + } + return (0); } /* Add an event to the event queue -- called with the queue locked */ -static int SDL_AddEvent(SDL_Event *event) +static int +SDL_AddEvent (SDL_Event * event) { - int tail, added; - - tail = (SDL_EventQ.tail+1)%MAXEVENTS; - if ( tail == SDL_EventQ.head ) { - /* Overflow, drop event */ - added = 0; - } else { - SDL_EventQ.event[SDL_EventQ.tail] = *event; - if (event->type == SDL_SYSWMEVENT) { - /* Note that it's possible to lose an event */ - int next = SDL_EventQ.wmmsg_next; - SDL_EventQ.wmmsg[next] = *event->syswm.msg; - SDL_EventQ.event[SDL_EventQ.tail].syswm.msg = - &SDL_EventQ.wmmsg[next]; - SDL_EventQ.wmmsg_next = (next+1)%MAXEVENTS; - } - SDL_EventQ.tail = tail; - added = 1; - } - return(added); + int tail, added; + + tail = (SDL_EventQ.tail + 1) % MAXEVENTS; + if (tail == SDL_EventQ.head) { + /* Overflow, drop event */ + added = 0; + } else { + SDL_EventQ.event[SDL_EventQ.tail] = *event; + if (event->type == SDL_SYSWMEVENT) { + /* Note that it's possible to lose an event */ + int next = SDL_EventQ.wmmsg_next; + SDL_EventQ.wmmsg[next] = *event->syswm.msg; + SDL_EventQ.event[SDL_EventQ.tail].syswm.msg = + &SDL_EventQ.wmmsg[next]; + SDL_EventQ.wmmsg_next = (next + 1) % MAXEVENTS; + } + SDL_EventQ.tail = tail; + added = 1; + } + return (added); } /* Cut an event, and return the next valid spot, or the tail */ /* -- called with the queue locked */ -static int SDL_CutEvent(int spot) +static int +SDL_CutEvent (int spot) { - if ( spot == SDL_EventQ.head ) { - SDL_EventQ.head = (SDL_EventQ.head+1)%MAXEVENTS; - return(SDL_EventQ.head); - } else - if ( (spot+1)%MAXEVENTS == SDL_EventQ.tail ) { - SDL_EventQ.tail = spot; - return(SDL_EventQ.tail); - } else - /* We cut the middle -- shift everything over */ - { - int here, next; - - /* This can probably be optimized with SDL_memcpy() -- careful! */ - if ( --SDL_EventQ.tail < 0 ) { - SDL_EventQ.tail = MAXEVENTS-1; - } - for ( here=spot; here != SDL_EventQ.tail; here = next ) { - next = (here+1)%MAXEVENTS; - SDL_EventQ.event[here] = SDL_EventQ.event[next]; - } - return(spot); - } - /* NOTREACHED */ + if (spot == SDL_EventQ.head) { + SDL_EventQ.head = (SDL_EventQ.head + 1) % MAXEVENTS; + return (SDL_EventQ.head); + } else if ((spot + 1) % MAXEVENTS == SDL_EventQ.tail) { + SDL_EventQ.tail = spot; + return (SDL_EventQ.tail); + } else + /* We cut the middle -- shift everything over */ + { + int here, next; + + /* This can probably be optimized with SDL_memcpy() -- careful! */ + if (--SDL_EventQ.tail < 0) { + SDL_EventQ.tail = MAXEVENTS - 1; + } + for (here = spot; here != SDL_EventQ.tail; here = next) { + next = (here + 1) % MAXEVENTS; + SDL_EventQ.event[here] = SDL_EventQ.event[next]; + } + return (spot); + } + /* NOTREACHED */ } /* Lock the event queue, take a peep at it, and unlock it */ -int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, - Uint32 mask) +int +SDL_PeepEvents (SDL_Event * events, int numevents, SDL_eventaction action, + Uint32 mask) { - int i, used; - - /* Don't look after we've quit */ - if ( ! SDL_EventQ.active ) { - return(-1); - } - /* Lock the event queue */ - used = 0; - if ( SDL_mutexP(SDL_EventQ.lock) == 0 ) { - if ( action == SDL_ADDEVENT ) { - for ( i=0; iPumpEvents(this); - } + /* Get events from the video subsystem */ + if (_this) { + _this->PumpEvents (_this); + } - /* Queue pending key-repeat events */ - SDL_CheckKeyRepeat(); + /* Queue pending key-repeat events */ + SDL_CheckKeyRepeat (); #if !SDL_JOYSTICK_DISABLED - /* Check for joystick state change */ - if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) { - SDL_JoystickUpdate(); - } + /* Check for joystick state change */ + if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) { + SDL_JoystickUpdate (); + } #endif - } + } } /* Public functions */ -int SDL_PollEvent (SDL_Event *event) +int +SDL_PollEvent (SDL_Event * event) { - SDL_PumpEvents(); + SDL_PumpEvents (); - /* We can't return -1, just return 0 (no event) on error */ - if ( SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0 ) - return 0; - return 1; + /* We can't return -1, just return 0 (no event) on error */ + if (SDL_PeepEvents (event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0) + return 0; + return 1; } -int SDL_WaitEvent (SDL_Event *event) +int +SDL_WaitEvent (SDL_Event * event) { - while ( 1 ) { - SDL_PumpEvents(); - switch(SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { - case -1: return 0; - case 1: return 1; - case 0: SDL_Delay(10); - } - } + while (1) { + SDL_PumpEvents (); + switch (SDL_PeepEvents (event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { + case -1: + return 0; + case 1: + return 1; + case 0: + SDL_Delay (10); + } + } } -int SDL_PushEvent(SDL_Event *event) +int +SDL_PushEvent (SDL_Event * event) { - if ( SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0) <= 0 ) - return -1; - return 0; + if (SDL_PeepEvents (event, 1, SDL_ADDEVENT, 0) <= 0) + return -1; + return 0; } -void SDL_SetEventFilter (SDL_EventFilter filter) +void +SDL_SetEventFilter (SDL_EventFilter filter) { - SDL_Event bitbucket; + SDL_Event bitbucket; - /* Set filter and discard pending events */ - SDL_EventOK = filter; - while ( SDL_PollEvent(&bitbucket) > 0 ) - ; + /* Set filter and discard pending events */ + SDL_EventOK = filter; + while (SDL_PollEvent (&bitbucket) > 0); } -SDL_EventFilter SDL_GetEventFilter(void) +SDL_EventFilter +SDL_GetEventFilter (void) { - return(SDL_EventOK); + return (SDL_EventOK); } -Uint8 SDL_EventState (Uint8 type, int state) +Uint8 +SDL_EventState (Uint8 type, int state) { - SDL_Event bitbucket; - Uint8 current_state; - - /* If SDL_ALLEVENTS was specified... */ - if ( type == 0xFF ) { - current_state = SDL_IGNORE; - for ( type=0; type 0 ) - ; - return(current_state); - } - - /* Just set the state for one event type */ - current_state = SDL_ProcessEvents[type]; - switch (state) { - case SDL_IGNORE: - case SDL_ENABLE: - /* Set state and discard pending events */ - SDL_ProcessEvents[type] = state; - if ( state == SDL_ENABLE ) { - SDL_eventstate |= (0x00000001 << (type)); - } else { - SDL_eventstate &= ~(0x00000001 << (type)); - } - while ( SDL_PollEvent(&bitbucket) > 0 ) - ; - break; - default: - /* Querying state? */ - break; - } - return(current_state); + SDL_Event bitbucket; + Uint8 current_state; + + /* If SDL_ALLEVENTS was specified... */ + if (type == 0xFF) { + current_state = SDL_IGNORE; + for (type = 0; type < SDL_NUMEVENTS; ++type) { + if (SDL_ProcessEvents[type] != SDL_IGNORE) { + current_state = SDL_ENABLE; + } + SDL_ProcessEvents[type] = state; + if (state == SDL_ENABLE) { + SDL_eventstate |= (0x00000001 << (type)); + } else { + SDL_eventstate &= ~(0x00000001 << (type)); + } + } + while (SDL_PollEvent (&bitbucket) > 0); + return (current_state); + } + + /* Just set the state for one event type */ + current_state = SDL_ProcessEvents[type]; + switch (state) { + case SDL_IGNORE: + case SDL_ENABLE: + /* Set state and discard pending events */ + SDL_ProcessEvents[type] = state; + if (state == SDL_ENABLE) { + SDL_eventstate |= (0x00000001 << (type)); + } else { + SDL_eventstate &= ~(0x00000001 << (type)); + } + while (SDL_PollEvent (&bitbucket) > 0); + break; + default: + /* Querying state? */ + break; + } + return (current_state); } /* This is a generic event handler. */ -int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message) +int +SDL_PrivateSysWMEvent (SDL_SysWMmsg * message) { - int posted; - - posted = 0; - if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { - SDL_Event event; - SDL_memset(&event, 0, sizeof(event)); - event.type = SDL_SYSWMEVENT; - event.syswm.msg = message; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - /* Update internal event state */ - return(posted); + int posted; + + posted = 0; + if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { + SDL_Event event; + SDL_memset (&event, 0, sizeof (event)); + event.type = SDL_SYSWMEVENT; + event.syswm.msg = message; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } + /* Update internal event state */ + return (posted); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h index 6b5a38c01..6937eeea2 100644 --- a/src/events/SDL_events_c.h +++ b/src/events/SDL_events_c.h @@ -25,25 +25,23 @@ #include "SDL_events.h" /* Start and stop the event processing loop */ -extern int SDL_StartEventLoop(Uint32 flags); -extern void SDL_StopEventLoop(void); -extern void SDL_QuitInterrupt(void); +extern int SDL_StartEventLoop (Uint32 flags); +extern void SDL_StopEventLoop (void); +extern void SDL_QuitInterrupt (void); -extern void SDL_Lock_EventThread(void); -extern void SDL_Unlock_EventThread(void); -extern Uint32 SDL_EventThreadID(void); +extern void SDL_Lock_EventThread (void); +extern void SDL_Unlock_EventThread (void); +extern Uint32 SDL_EventThreadID (void); /* Event handler init routines */ -extern int SDL_AppActiveInit(void); -extern int SDL_KeyboardInit(void); -extern int SDL_MouseInit(void); -extern int SDL_QuitInit(void); +extern int SDL_KeyboardInit (void); +extern int SDL_MouseInit (void); +extern int SDL_QuitInit (void); /* Event handler quit routines */ -extern void SDL_AppActiveQuit(void); -extern void SDL_KeyboardQuit(void); -extern void SDL_MouseQuit(void); -extern void SDL_QuitQuit(void); +extern void SDL_KeyboardQuit (void); +extern void SDL_MouseQuit (void); +extern void SDL_QuitQuit (void); /* The event filter function */ extern SDL_EventFilter SDL_EventOK; @@ -52,29 +50,31 @@ extern SDL_EventFilter SDL_EventOK; extern Uint8 SDL_ProcessEvents[SDL_NUMEVENTS]; /* Internal event queueing functions - (from SDL_active.c, SDL_mouse.c, SDL_keyboard.c, SDL_quit.c, SDL_events.c) + (from SDL_mouse.c, SDL_keyboard.c, SDL_quit.c, SDL_events.c, SDL_windowevents.c) */ -extern int SDL_PrivateAppActive(Uint8 gain, Uint8 state); -extern int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, - Sint16 x, Sint16 y); -extern int SDL_PrivateMouseButton(Uint8 state, Uint8 button,Sint16 x,Sint16 y); -extern int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *key); -extern int SDL_PrivateResize(int w, int h); -extern int SDL_PrivateExpose(void); -extern int SDL_PrivateQuit(void); -extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message); +extern int SDL_PrivateWindowEvent (SDL_WindowID windowID, Uint8 windowevent, + int data1, int data2); +extern int SDL_PrivateMouseMotion (Uint8 buttonstate, int relative, Sint16 x, + Sint16 y); +extern int SDL_PrivateMouseButton (Uint8 state, Uint8 button, Sint16 x, + Sint16 y); +extern int SDL_PrivateKeyboard (Uint8 state, SDL_keysym * key); +extern int SDL_PrivateQuit (void); +extern int SDL_PrivateSysWMEvent (SDL_SysWMmsg * message); /* Used by the activity event handler to remove mouse focus */ -extern void SDL_ResetMouse(void); +extern void SDL_ResetMouse (void); /* Used by the activity event handler to remove keyboard focus */ -extern void SDL_ResetKeyboard(void); +extern void SDL_ResetKeyboard (void); /* Used by the event loop to queue pending keyboard repeat events */ -extern void SDL_CheckKeyRepeat(void); +extern void SDL_CheckKeyRepeat (void); /* Used by the OS keyboard code to detect whether or not to do UNICODE */ #ifndef DEFAULT_UNICODE_TRANSLATION -#define DEFAULT_UNICODE_TRANSLATION 0 /* Default off because of overhead */ +#define DEFAULT_UNICODE_TRANSLATION 0 /* Default off because of overhead */ #endif extern int SDL_TranslateUNICODE; + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 5f7af429c..ace7f3cb1 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -30,549 +30,566 @@ /* Global keystate information */ -static Uint8 SDL_KeyState[SDLK_LAST]; +static Uint8 SDL_KeyState[SDLK_LAST]; static SDLMod SDL_ModState; int SDL_TranslateUNICODE = 0; -static const char *keynames[SDLK_LAST]; /* Array of keycode names */ +static const char *keynames[SDLK_LAST]; /* Array of keycode names */ /* * jk 991215 - added */ -struct { - int firsttime; /* if we check against the delay or repeat value */ - int delay; /* the delay before we start repeating */ - int interval; /* the delay between key repeat events */ - Uint32 timestamp; /* the time the first keydown event occurred */ +struct +{ + int firsttime; /* if we check against the delay or repeat value */ + int delay; /* the delay before we start repeating */ + int interval; /* the delay between key repeat events */ + Uint32 timestamp; /* the time the first keydown event occurred */ - SDL_Event evt; /* the event we are supposed to repeat */ + SDL_Event evt; /* the event we are supposed to repeat */ } SDL_KeyRepeat; /* Public functions */ -int SDL_KeyboardInit(void) +int +SDL_KeyboardInit (void) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - /* Set default mode of UNICODE translation */ - SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION); - - /* Initialize the tables */ - SDL_ModState = KMOD_NONE; - SDL_memset((void*)keynames, 0, sizeof(keynames)); - SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState)); - video->InitOSKeymap(this); - - SDL_EnableKeyRepeat(0, 0); - - /* Fill in the blanks in keynames */ - keynames[SDLK_BACKSPACE] = "backspace"; - keynames[SDLK_TAB] = "tab"; - keynames[SDLK_CLEAR] = "clear"; - keynames[SDLK_RETURN] = "return"; - keynames[SDLK_PAUSE] = "pause"; - keynames[SDLK_ESCAPE] = "escape"; - keynames[SDLK_SPACE] = "space"; - keynames[SDLK_EXCLAIM] = "!"; - keynames[SDLK_QUOTEDBL] = "\""; - keynames[SDLK_HASH] = "#"; - keynames[SDLK_DOLLAR] = "$"; - keynames[SDLK_AMPERSAND] = "&"; - keynames[SDLK_QUOTE] = "'"; - keynames[SDLK_LEFTPAREN] = "("; - keynames[SDLK_RIGHTPAREN] = ")"; - keynames[SDLK_ASTERISK] = "*"; - keynames[SDLK_PLUS] = "+"; - keynames[SDLK_COMMA] = ","; - keynames[SDLK_MINUS] = "-"; - keynames[SDLK_PERIOD] = "."; - keynames[SDLK_SLASH] = "/"; - keynames[SDLK_0] = "0"; - keynames[SDLK_1] = "1"; - keynames[SDLK_2] = "2"; - keynames[SDLK_3] = "3"; - keynames[SDLK_4] = "4"; - keynames[SDLK_5] = "5"; - keynames[SDLK_6] = "6"; - keynames[SDLK_7] = "7"; - keynames[SDLK_8] = "8"; - keynames[SDLK_9] = "9"; - keynames[SDLK_COLON] = ":"; - keynames[SDLK_SEMICOLON] = ";"; - keynames[SDLK_LESS] = "<"; - keynames[SDLK_EQUALS] = "="; - keynames[SDLK_GREATER] = ">"; - keynames[SDLK_QUESTION] = "?"; - keynames[SDLK_AT] = "@"; - keynames[SDLK_LEFTBRACKET] = "["; - keynames[SDLK_BACKSLASH] = "\\"; - keynames[SDLK_RIGHTBRACKET] = "]"; - keynames[SDLK_CARET] = "^"; - keynames[SDLK_UNDERSCORE] = "_"; - keynames[SDLK_BACKQUOTE] = "`"; - keynames[SDLK_a] = "a"; - keynames[SDLK_b] = "b"; - keynames[SDLK_c] = "c"; - keynames[SDLK_d] = "d"; - keynames[SDLK_e] = "e"; - keynames[SDLK_f] = "f"; - keynames[SDLK_g] = "g"; - keynames[SDLK_h] = "h"; - keynames[SDLK_i] = "i"; - keynames[SDLK_j] = "j"; - keynames[SDLK_k] = "k"; - keynames[SDLK_l] = "l"; - keynames[SDLK_m] = "m"; - keynames[SDLK_n] = "n"; - keynames[SDLK_o] = "o"; - keynames[SDLK_p] = "p"; - keynames[SDLK_q] = "q"; - keynames[SDLK_r] = "r"; - keynames[SDLK_s] = "s"; - keynames[SDLK_t] = "t"; - keynames[SDLK_u] = "u"; - keynames[SDLK_v] = "v"; - keynames[SDLK_w] = "w"; - keynames[SDLK_x] = "x"; - keynames[SDLK_y] = "y"; - keynames[SDLK_z] = "z"; - keynames[SDLK_DELETE] = "delete"; - - keynames[SDLK_WORLD_0] = "world 0"; - keynames[SDLK_WORLD_1] = "world 1"; - keynames[SDLK_WORLD_2] = "world 2"; - keynames[SDLK_WORLD_3] = "world 3"; - keynames[SDLK_WORLD_4] = "world 4"; - keynames[SDLK_WORLD_5] = "world 5"; - keynames[SDLK_WORLD_6] = "world 6"; - keynames[SDLK_WORLD_7] = "world 7"; - keynames[SDLK_WORLD_8] = "world 8"; - keynames[SDLK_WORLD_9] = "world 9"; - keynames[SDLK_WORLD_10] = "world 10"; - keynames[SDLK_WORLD_11] = "world 11"; - keynames[SDLK_WORLD_12] = "world 12"; - keynames[SDLK_WORLD_13] = "world 13"; - keynames[SDLK_WORLD_14] = "world 14"; - keynames[SDLK_WORLD_15] = "world 15"; - keynames[SDLK_WORLD_16] = "world 16"; - keynames[SDLK_WORLD_17] = "world 17"; - keynames[SDLK_WORLD_18] = "world 18"; - keynames[SDLK_WORLD_19] = "world 19"; - keynames[SDLK_WORLD_20] = "world 20"; - keynames[SDLK_WORLD_21] = "world 21"; - keynames[SDLK_WORLD_22] = "world 22"; - keynames[SDLK_WORLD_23] = "world 23"; - keynames[SDLK_WORLD_24] = "world 24"; - keynames[SDLK_WORLD_25] = "world 25"; - keynames[SDLK_WORLD_26] = "world 26"; - keynames[SDLK_WORLD_27] = "world 27"; - keynames[SDLK_WORLD_28] = "world 28"; - keynames[SDLK_WORLD_29] = "world 29"; - keynames[SDLK_WORLD_30] = "world 30"; - keynames[SDLK_WORLD_31] = "world 31"; - keynames[SDLK_WORLD_32] = "world 32"; - keynames[SDLK_WORLD_33] = "world 33"; - keynames[SDLK_WORLD_34] = "world 34"; - keynames[SDLK_WORLD_35] = "world 35"; - keynames[SDLK_WORLD_36] = "world 36"; - keynames[SDLK_WORLD_37] = "world 37"; - keynames[SDLK_WORLD_38] = "world 38"; - keynames[SDLK_WORLD_39] = "world 39"; - keynames[SDLK_WORLD_40] = "world 40"; - keynames[SDLK_WORLD_41] = "world 41"; - keynames[SDLK_WORLD_42] = "world 42"; - keynames[SDLK_WORLD_43] = "world 43"; - keynames[SDLK_WORLD_44] = "world 44"; - keynames[SDLK_WORLD_45] = "world 45"; - keynames[SDLK_WORLD_46] = "world 46"; - keynames[SDLK_WORLD_47] = "world 47"; - keynames[SDLK_WORLD_48] = "world 48"; - keynames[SDLK_WORLD_49] = "world 49"; - keynames[SDLK_WORLD_50] = "world 50"; - keynames[SDLK_WORLD_51] = "world 51"; - keynames[SDLK_WORLD_52] = "world 52"; - keynames[SDLK_WORLD_53] = "world 53"; - keynames[SDLK_WORLD_54] = "world 54"; - keynames[SDLK_WORLD_55] = "world 55"; - keynames[SDLK_WORLD_56] = "world 56"; - keynames[SDLK_WORLD_57] = "world 57"; - keynames[SDLK_WORLD_58] = "world 58"; - keynames[SDLK_WORLD_59] = "world 59"; - keynames[SDLK_WORLD_60] = "world 60"; - keynames[SDLK_WORLD_61] = "world 61"; - keynames[SDLK_WORLD_62] = "world 62"; - keynames[SDLK_WORLD_63] = "world 63"; - keynames[SDLK_WORLD_64] = "world 64"; - keynames[SDLK_WORLD_65] = "world 65"; - keynames[SDLK_WORLD_66] = "world 66"; - keynames[SDLK_WORLD_67] = "world 67"; - keynames[SDLK_WORLD_68] = "world 68"; - keynames[SDLK_WORLD_69] = "world 69"; - keynames[SDLK_WORLD_70] = "world 70"; - keynames[SDLK_WORLD_71] = "world 71"; - keynames[SDLK_WORLD_72] = "world 72"; - keynames[SDLK_WORLD_73] = "world 73"; - keynames[SDLK_WORLD_74] = "world 74"; - keynames[SDLK_WORLD_75] = "world 75"; - keynames[SDLK_WORLD_76] = "world 76"; - keynames[SDLK_WORLD_77] = "world 77"; - keynames[SDLK_WORLD_78] = "world 78"; - keynames[SDLK_WORLD_79] = "world 79"; - keynames[SDLK_WORLD_80] = "world 80"; - keynames[SDLK_WORLD_81] = "world 81"; - keynames[SDLK_WORLD_82] = "world 82"; - keynames[SDLK_WORLD_83] = "world 83"; - keynames[SDLK_WORLD_84] = "world 84"; - keynames[SDLK_WORLD_85] = "world 85"; - keynames[SDLK_WORLD_86] = "world 86"; - keynames[SDLK_WORLD_87] = "world 87"; - keynames[SDLK_WORLD_88] = "world 88"; - keynames[SDLK_WORLD_89] = "world 89"; - keynames[SDLK_WORLD_90] = "world 90"; - keynames[SDLK_WORLD_91] = "world 91"; - keynames[SDLK_WORLD_92] = "world 92"; - keynames[SDLK_WORLD_93] = "world 93"; - keynames[SDLK_WORLD_94] = "world 94"; - keynames[SDLK_WORLD_95] = "world 95"; - - keynames[SDLK_KP0] = "[0]"; - keynames[SDLK_KP1] = "[1]"; - keynames[SDLK_KP2] = "[2]"; - keynames[SDLK_KP3] = "[3]"; - keynames[SDLK_KP4] = "[4]"; - keynames[SDLK_KP5] = "[5]"; - keynames[SDLK_KP6] = "[6]"; - keynames[SDLK_KP7] = "[7]"; - keynames[SDLK_KP8] = "[8]"; - keynames[SDLK_KP9] = "[9]"; - keynames[SDLK_KP_PERIOD] = "[.]"; - keynames[SDLK_KP_DIVIDE] = "[/]"; - keynames[SDLK_KP_MULTIPLY] = "[*]"; - keynames[SDLK_KP_MINUS] = "[-]"; - keynames[SDLK_KP_PLUS] = "[+]"; - keynames[SDLK_KP_ENTER] = "enter"; - keynames[SDLK_KP_EQUALS] = "equals"; - - keynames[SDLK_UP] = "up"; - keynames[SDLK_DOWN] = "down"; - keynames[SDLK_RIGHT] = "right"; - keynames[SDLK_LEFT] = "left"; - keynames[SDLK_DOWN] = "down"; - keynames[SDLK_INSERT] = "insert"; - keynames[SDLK_HOME] = "home"; - keynames[SDLK_END] = "end"; - keynames[SDLK_PAGEUP] = "page up"; - keynames[SDLK_PAGEDOWN] = "page down"; - - keynames[SDLK_F1] = "f1"; - keynames[SDLK_F2] = "f2"; - keynames[SDLK_F3] = "f3"; - keynames[SDLK_F4] = "f4"; - keynames[SDLK_F5] = "f5"; - keynames[SDLK_F6] = "f6"; - keynames[SDLK_F7] = "f7"; - keynames[SDLK_F8] = "f8"; - keynames[SDLK_F9] = "f9"; - keynames[SDLK_F10] = "f10"; - keynames[SDLK_F11] = "f11"; - keynames[SDLK_F12] = "f12"; - keynames[SDLK_F13] = "f13"; - keynames[SDLK_F14] = "f14"; - keynames[SDLK_F15] = "f15"; - - keynames[SDLK_NUMLOCK] = "numlock"; - keynames[SDLK_CAPSLOCK] = "caps lock"; - keynames[SDLK_SCROLLOCK] = "scroll lock"; - keynames[SDLK_RSHIFT] = "right shift"; - keynames[SDLK_LSHIFT] = "left shift"; - keynames[SDLK_RCTRL] = "right ctrl"; - keynames[SDLK_LCTRL] = "left ctrl"; - keynames[SDLK_RALT] = "right alt"; - keynames[SDLK_LALT] = "left alt"; - keynames[SDLK_RMETA] = "right meta"; - keynames[SDLK_LMETA] = "left meta"; - keynames[SDLK_LSUPER] = "left super"; /* "Windows" keys */ - keynames[SDLK_RSUPER] = "right super"; - keynames[SDLK_MODE] = "alt gr"; - keynames[SDLK_COMPOSE] = "compose"; - - keynames[SDLK_HELP] = "help"; - keynames[SDLK_PRINT] = "print screen"; - keynames[SDLK_SYSREQ] = "sys req"; - keynames[SDLK_BREAK] = "break"; - keynames[SDLK_MENU] = "menu"; - keynames[SDLK_POWER] = "power"; - keynames[SDLK_EURO] = "euro"; - keynames[SDLK_UNDO] = "undo"; - - /* Done. Whew. */ - return(0); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + /* Set default mode of UNICODE translation */ + SDL_EnableUNICODE (DEFAULT_UNICODE_TRANSLATION); + + /* Initialize the tables */ + SDL_ModState = KMOD_NONE; + SDL_memset ((void *) keynames, 0, sizeof (keynames)); + SDL_memset (SDL_KeyState, 0, sizeof (SDL_KeyState)); + _this->InitOSKeymap (_this); + + SDL_EnableKeyRepeat (0, 0); + + /* Fill in the blanks in keynames */ + keynames[SDLK_BACKSPACE] = "backspace"; + keynames[SDLK_TAB] = "tab"; + keynames[SDLK_CLEAR] = "clear"; + keynames[SDLK_RETURN] = "return"; + keynames[SDLK_PAUSE] = "pause"; + keynames[SDLK_ESCAPE] = "escape"; + keynames[SDLK_SPACE] = "space"; + keynames[SDLK_EXCLAIM] = "!"; + keynames[SDLK_QUOTEDBL] = "\""; + keynames[SDLK_HASH] = "#"; + keynames[SDLK_DOLLAR] = "$"; + keynames[SDLK_AMPERSAND] = "&"; + keynames[SDLK_QUOTE] = "'"; + keynames[SDLK_LEFTPAREN] = "("; + keynames[SDLK_RIGHTPAREN] = ")"; + keynames[SDLK_ASTERISK] = "*"; + keynames[SDLK_PLUS] = "+"; + keynames[SDLK_COMMA] = ","; + keynames[SDLK_MINUS] = "-"; + keynames[SDLK_PERIOD] = "."; + keynames[SDLK_SLASH] = "/"; + keynames[SDLK_0] = "0"; + keynames[SDLK_1] = "1"; + keynames[SDLK_2] = "2"; + keynames[SDLK_3] = "3"; + keynames[SDLK_4] = "4"; + keynames[SDLK_5] = "5"; + keynames[SDLK_6] = "6"; + keynames[SDLK_7] = "7"; + keynames[SDLK_8] = "8"; + keynames[SDLK_9] = "9"; + keynames[SDLK_COLON] = ":"; + keynames[SDLK_SEMICOLON] = ";"; + keynames[SDLK_LESS] = "<"; + keynames[SDLK_EQUALS] = "="; + keynames[SDLK_GREATER] = ">"; + keynames[SDLK_QUESTION] = "?"; + keynames[SDLK_AT] = "@"; + keynames[SDLK_LEFTBRACKET] = "["; + keynames[SDLK_BACKSLASH] = "\\"; + keynames[SDLK_RIGHTBRACKET] = "]"; + keynames[SDLK_CARET] = "^"; + keynames[SDLK_UNDERSCORE] = "_"; + keynames[SDLK_BACKQUOTE] = "`"; + keynames[SDLK_a] = "a"; + keynames[SDLK_b] = "b"; + keynames[SDLK_c] = "c"; + keynames[SDLK_d] = "d"; + keynames[SDLK_e] = "e"; + keynames[SDLK_f] = "f"; + keynames[SDLK_g] = "g"; + keynames[SDLK_h] = "h"; + keynames[SDLK_i] = "i"; + keynames[SDLK_j] = "j"; + keynames[SDLK_k] = "k"; + keynames[SDLK_l] = "l"; + keynames[SDLK_m] = "m"; + keynames[SDLK_n] = "n"; + keynames[SDLK_o] = "o"; + keynames[SDLK_p] = "p"; + keynames[SDLK_q] = "q"; + keynames[SDLK_r] = "r"; + keynames[SDLK_s] = "s"; + keynames[SDLK_t] = "t"; + keynames[SDLK_u] = "u"; + keynames[SDLK_v] = "v"; + keynames[SDLK_w] = "w"; + keynames[SDLK_x] = "x"; + keynames[SDLK_y] = "y"; + keynames[SDLK_z] = "z"; + keynames[SDLK_DELETE] = "delete"; + + keynames[SDLK_WORLD_0] = "world 0"; + keynames[SDLK_WORLD_1] = "world 1"; + keynames[SDLK_WORLD_2] = "world 2"; + keynames[SDLK_WORLD_3] = "world 3"; + keynames[SDLK_WORLD_4] = "world 4"; + keynames[SDLK_WORLD_5] = "world 5"; + keynames[SDLK_WORLD_6] = "world 6"; + keynames[SDLK_WORLD_7] = "world 7"; + keynames[SDLK_WORLD_8] = "world 8"; + keynames[SDLK_WORLD_9] = "world 9"; + keynames[SDLK_WORLD_10] = "world 10"; + keynames[SDLK_WORLD_11] = "world 11"; + keynames[SDLK_WORLD_12] = "world 12"; + keynames[SDLK_WORLD_13] = "world 13"; + keynames[SDLK_WORLD_14] = "world 14"; + keynames[SDLK_WORLD_15] = "world 15"; + keynames[SDLK_WORLD_16] = "world 16"; + keynames[SDLK_WORLD_17] = "world 17"; + keynames[SDLK_WORLD_18] = "world 18"; + keynames[SDLK_WORLD_19] = "world 19"; + keynames[SDLK_WORLD_20] = "world 20"; + keynames[SDLK_WORLD_21] = "world 21"; + keynames[SDLK_WORLD_22] = "world 22"; + keynames[SDLK_WORLD_23] = "world 23"; + keynames[SDLK_WORLD_24] = "world 24"; + keynames[SDLK_WORLD_25] = "world 25"; + keynames[SDLK_WORLD_26] = "world 26"; + keynames[SDLK_WORLD_27] = "world 27"; + keynames[SDLK_WORLD_28] = "world 28"; + keynames[SDLK_WORLD_29] = "world 29"; + keynames[SDLK_WORLD_30] = "world 30"; + keynames[SDLK_WORLD_31] = "world 31"; + keynames[SDLK_WORLD_32] = "world 32"; + keynames[SDLK_WORLD_33] = "world 33"; + keynames[SDLK_WORLD_34] = "world 34"; + keynames[SDLK_WORLD_35] = "world 35"; + keynames[SDLK_WORLD_36] = "world 36"; + keynames[SDLK_WORLD_37] = "world 37"; + keynames[SDLK_WORLD_38] = "world 38"; + keynames[SDLK_WORLD_39] = "world 39"; + keynames[SDLK_WORLD_40] = "world 40"; + keynames[SDLK_WORLD_41] = "world 41"; + keynames[SDLK_WORLD_42] = "world 42"; + keynames[SDLK_WORLD_43] = "world 43"; + keynames[SDLK_WORLD_44] = "world 44"; + keynames[SDLK_WORLD_45] = "world 45"; + keynames[SDLK_WORLD_46] = "world 46"; + keynames[SDLK_WORLD_47] = "world 47"; + keynames[SDLK_WORLD_48] = "world 48"; + keynames[SDLK_WORLD_49] = "world 49"; + keynames[SDLK_WORLD_50] = "world 50"; + keynames[SDLK_WORLD_51] = "world 51"; + keynames[SDLK_WORLD_52] = "world 52"; + keynames[SDLK_WORLD_53] = "world 53"; + keynames[SDLK_WORLD_54] = "world 54"; + keynames[SDLK_WORLD_55] = "world 55"; + keynames[SDLK_WORLD_56] = "world 56"; + keynames[SDLK_WORLD_57] = "world 57"; + keynames[SDLK_WORLD_58] = "world 58"; + keynames[SDLK_WORLD_59] = "world 59"; + keynames[SDLK_WORLD_60] = "world 60"; + keynames[SDLK_WORLD_61] = "world 61"; + keynames[SDLK_WORLD_62] = "world 62"; + keynames[SDLK_WORLD_63] = "world 63"; + keynames[SDLK_WORLD_64] = "world 64"; + keynames[SDLK_WORLD_65] = "world 65"; + keynames[SDLK_WORLD_66] = "world 66"; + keynames[SDLK_WORLD_67] = "world 67"; + keynames[SDLK_WORLD_68] = "world 68"; + keynames[SDLK_WORLD_69] = "world 69"; + keynames[SDLK_WORLD_70] = "world 70"; + keynames[SDLK_WORLD_71] = "world 71"; + keynames[SDLK_WORLD_72] = "world 72"; + keynames[SDLK_WORLD_73] = "world 73"; + keynames[SDLK_WORLD_74] = "world 74"; + keynames[SDLK_WORLD_75] = "world 75"; + keynames[SDLK_WORLD_76] = "world 76"; + keynames[SDLK_WORLD_77] = "world 77"; + keynames[SDLK_WORLD_78] = "world 78"; + keynames[SDLK_WORLD_79] = "world 79"; + keynames[SDLK_WORLD_80] = "world 80"; + keynames[SDLK_WORLD_81] = "world 81"; + keynames[SDLK_WORLD_82] = "world 82"; + keynames[SDLK_WORLD_83] = "world 83"; + keynames[SDLK_WORLD_84] = "world 84"; + keynames[SDLK_WORLD_85] = "world 85"; + keynames[SDLK_WORLD_86] = "world 86"; + keynames[SDLK_WORLD_87] = "world 87"; + keynames[SDLK_WORLD_88] = "world 88"; + keynames[SDLK_WORLD_89] = "world 89"; + keynames[SDLK_WORLD_90] = "world 90"; + keynames[SDLK_WORLD_91] = "world 91"; + keynames[SDLK_WORLD_92] = "world 92"; + keynames[SDLK_WORLD_93] = "world 93"; + keynames[SDLK_WORLD_94] = "world 94"; + keynames[SDLK_WORLD_95] = "world 95"; + + keynames[SDLK_KP0] = "[0]"; + keynames[SDLK_KP1] = "[1]"; + keynames[SDLK_KP2] = "[2]"; + keynames[SDLK_KP3] = "[3]"; + keynames[SDLK_KP4] = "[4]"; + keynames[SDLK_KP5] = "[5]"; + keynames[SDLK_KP6] = "[6]"; + keynames[SDLK_KP7] = "[7]"; + keynames[SDLK_KP8] = "[8]"; + keynames[SDLK_KP9] = "[9]"; + keynames[SDLK_KP_PERIOD] = "[.]"; + keynames[SDLK_KP_DIVIDE] = "[/]"; + keynames[SDLK_KP_MULTIPLY] = "[*]"; + keynames[SDLK_KP_MINUS] = "[-]"; + keynames[SDLK_KP_PLUS] = "[+]"; + keynames[SDLK_KP_ENTER] = "enter"; + keynames[SDLK_KP_EQUALS] = "equals"; + + keynames[SDLK_UP] = "up"; + keynames[SDLK_DOWN] = "down"; + keynames[SDLK_RIGHT] = "right"; + keynames[SDLK_LEFT] = "left"; + keynames[SDLK_DOWN] = "down"; + keynames[SDLK_INSERT] = "insert"; + keynames[SDLK_HOME] = "home"; + keynames[SDLK_END] = "end"; + keynames[SDLK_PAGEUP] = "page up"; + keynames[SDLK_PAGEDOWN] = "page down"; + + keynames[SDLK_F1] = "f1"; + keynames[SDLK_F2] = "f2"; + keynames[SDLK_F3] = "f3"; + keynames[SDLK_F4] = "f4"; + keynames[SDLK_F5] = "f5"; + keynames[SDLK_F6] = "f6"; + keynames[SDLK_F7] = "f7"; + keynames[SDLK_F8] = "f8"; + keynames[SDLK_F9] = "f9"; + keynames[SDLK_F10] = "f10"; + keynames[SDLK_F11] = "f11"; + keynames[SDLK_F12] = "f12"; + keynames[SDLK_F13] = "f13"; + keynames[SDLK_F14] = "f14"; + keynames[SDLK_F15] = "f15"; + + keynames[SDLK_NUMLOCK] = "numlock"; + keynames[SDLK_CAPSLOCK] = "caps lock"; + keynames[SDLK_SCROLLOCK] = "scroll lock"; + keynames[SDLK_RSHIFT] = "right shift"; + keynames[SDLK_LSHIFT] = "left shift"; + keynames[SDLK_RCTRL] = "right ctrl"; + keynames[SDLK_LCTRL] = "left ctrl"; + keynames[SDLK_RALT] = "right alt"; + keynames[SDLK_LALT] = "left alt"; + keynames[SDLK_RMETA] = "right meta"; + keynames[SDLK_LMETA] = "left meta"; + keynames[SDLK_LSUPER] = "left super"; /* "Windows" keys */ + keynames[SDLK_RSUPER] = "right super"; + keynames[SDLK_MODE] = "alt gr"; + keynames[SDLK_COMPOSE] = "compose"; + + keynames[SDLK_HELP] = "help"; + keynames[SDLK_PRINT] = "print screen"; + keynames[SDLK_SYSREQ] = "sys req"; + keynames[SDLK_BREAK] = "break"; + keynames[SDLK_MENU] = "menu"; + keynames[SDLK_POWER] = "power"; + keynames[SDLK_EURO] = "euro"; + keynames[SDLK_UNDO] = "undo"; + + /* Done. Whew. */ + return (0); } -void SDL_KeyboardQuit(void) + +void +SDL_KeyboardQuit (void) { } /* We lost the keyboard, so post key up messages for all pressed keys */ -void SDL_ResetKeyboard(void) +void +SDL_ResetKeyboard (void) { - SDL_keysym keysym; - SDLKey key; - - SDL_memset(&keysym, 0, (sizeof keysym)); - for ( key=SDLK_FIRST; key= 0 ) { - SDL_TranslateUNICODE = enable; - } - return(old_mode); + old_mode = SDL_TranslateUNICODE; + if (enable >= 0) { + SDL_TranslateUNICODE = enable; + } + return (old_mode); } -Uint8 * SDL_GetKeyState (int *numkeys) +Uint8 * +SDL_GetKeyState (int *numkeys) { - if ( numkeys != (int *)0 ) - *numkeys = SDLK_LAST; - return(SDL_KeyState); + if (numkeys != (int *) 0) + *numkeys = SDLK_LAST; + return (SDL_KeyState); } -SDLMod SDL_GetModState (void) + +SDLMod +SDL_GetModState (void) { - return(SDL_ModState); + return (SDL_ModState); } -void SDL_SetModState (SDLMod modstate) + +void +SDL_SetModState (SDLMod modstate) { - SDL_ModState = modstate; + SDL_ModState = modstate; } -char *SDL_GetKeyName(SDLKey key) +char * +SDL_GetKeyName (SDLKey key) { - const char *keyname; - - keyname = NULL; - if ( key < SDLK_LAST ) { - keyname = keynames[key]; - } - if ( keyname == NULL ) { - keyname = "unknown key"; - } - /* FIXME: make this function const in 1.3 */ - return (char *)(keyname); + const char *keyname; + + keyname = NULL; + if (key < SDLK_LAST) { + keyname = keynames[key]; + } + if (keyname == NULL) { + keyname = "unknown key"; + } + /* FIXME: make this function const in 1.3 */ + return (char *) (keyname); } /* These are global for SDL_eventloop.c */ -int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *keysym) +int +SDL_PrivateKeyboard (Uint8 state, SDL_keysym * keysym) { - SDL_Event event; - int posted, repeatable; - Uint16 modstate; + SDL_Event event; + int posted, repeatable; + Uint16 modstate; - SDL_memset(&event, 0, sizeof(event)); + SDL_memset (&event, 0, sizeof (event)); #if 0 -printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym), - state == SDL_PRESSED ? "pressed" : "released"); + printf ("The '%s' key has been %s\n", SDL_GetKeyName (keysym->sym), + state == SDL_PRESSED ? "pressed" : "released"); #endif - /* Set up the keysym */ - modstate = (Uint16)SDL_ModState; - - repeatable = 0; - - if ( state == SDL_PRESSED ) { - keysym->mod = (SDLMod)modstate; - switch (keysym->sym) { - case SDLK_UNKNOWN: - break; - case SDLK_NUMLOCK: - modstate ^= KMOD_NUM; - if ( ! (modstate&KMOD_NUM) ) - state = SDL_RELEASED; - keysym->mod = (SDLMod)modstate; - break; - case SDLK_CAPSLOCK: - modstate ^= KMOD_CAPS; - if ( ! (modstate&KMOD_CAPS) ) - state = SDL_RELEASED; - keysym->mod = (SDLMod)modstate; - break; - case SDLK_LCTRL: - modstate |= KMOD_LCTRL; - break; - case SDLK_RCTRL: - modstate |= KMOD_RCTRL; - break; - case SDLK_LSHIFT: - modstate |= KMOD_LSHIFT; - break; - case SDLK_RSHIFT: - modstate |= KMOD_RSHIFT; - break; - case SDLK_LALT: - modstate |= KMOD_LALT; - break; - case SDLK_RALT: - modstate |= KMOD_RALT; - break; - case SDLK_LMETA: - modstate |= KMOD_LMETA; - break; - case SDLK_RMETA: - modstate |= KMOD_RMETA; - break; - case SDLK_MODE: - modstate |= KMOD_MODE; - break; - default: - repeatable = 1; - break; - } - } else { - switch (keysym->sym) { - case SDLK_UNKNOWN: - break; - case SDLK_NUMLOCK: - case SDLK_CAPSLOCK: - /* Only send keydown events */ - return(0); - case SDLK_LCTRL: - modstate &= ~KMOD_LCTRL; - break; - case SDLK_RCTRL: - modstate &= ~KMOD_RCTRL; - break; - case SDLK_LSHIFT: - modstate &= ~KMOD_LSHIFT; - break; - case SDLK_RSHIFT: - modstate &= ~KMOD_RSHIFT; - break; - case SDLK_LALT: - modstate &= ~KMOD_LALT; - break; - case SDLK_RALT: - modstate &= ~KMOD_RALT; - break; - case SDLK_LMETA: - modstate &= ~KMOD_LMETA; - break; - case SDLK_RMETA: - modstate &= ~KMOD_RMETA; - break; - case SDLK_MODE: - modstate &= ~KMOD_MODE; - break; - default: - break; - } - keysym->mod = (SDLMod)modstate; - } - - /* Figure out what type of event this is */ - switch (state) { - case SDL_PRESSED: - event.type = SDL_KEYDOWN; - break; - case SDL_RELEASED: - event.type = SDL_KEYUP; - /* - * jk 991215 - Added - */ - if ( SDL_KeyRepeat.timestamp && - SDL_KeyRepeat.evt.key.keysym.sym == keysym->sym ) { - SDL_KeyRepeat.timestamp = 0; - } - break; - default: - /* Invalid state -- bail */ - return(0); - } - - if ( keysym->sym != SDLK_UNKNOWN ) { - /* Drop events that don't change state */ - if ( SDL_KeyState[keysym->sym] == state ) { + /* Set up the keysym */ + modstate = (Uint16) SDL_ModState; + + repeatable = 0; + + if (state == SDL_PRESSED) { + keysym->mod = (SDLMod) modstate; + switch (keysym->sym) { + case SDLK_UNKNOWN: + break; + case SDLK_NUMLOCK: + modstate ^= KMOD_NUM; + if (!(modstate & KMOD_NUM)) + state = SDL_RELEASED; + keysym->mod = (SDLMod) modstate; + break; + case SDLK_CAPSLOCK: + modstate ^= KMOD_CAPS; + if (!(modstate & KMOD_CAPS)) + state = SDL_RELEASED; + keysym->mod = (SDLMod) modstate; + break; + case SDLK_LCTRL: + modstate |= KMOD_LCTRL; + break; + case SDLK_RCTRL: + modstate |= KMOD_RCTRL; + break; + case SDLK_LSHIFT: + modstate |= KMOD_LSHIFT; + break; + case SDLK_RSHIFT: + modstate |= KMOD_RSHIFT; + break; + case SDLK_LALT: + modstate |= KMOD_LALT; + break; + case SDLK_RALT: + modstate |= KMOD_RALT; + break; + case SDLK_LMETA: + modstate |= KMOD_LMETA; + break; + case SDLK_RMETA: + modstate |= KMOD_RMETA; + break; + case SDLK_MODE: + modstate |= KMOD_MODE; + break; + default: + repeatable = 1; + break; + } + } else { + switch (keysym->sym) { + case SDLK_UNKNOWN: + break; + case SDLK_NUMLOCK: + case SDLK_CAPSLOCK: + /* Only send keydown events */ + return (0); + case SDLK_LCTRL: + modstate &= ~KMOD_LCTRL; + break; + case SDLK_RCTRL: + modstate &= ~KMOD_RCTRL; + break; + case SDLK_LSHIFT: + modstate &= ~KMOD_LSHIFT; + break; + case SDLK_RSHIFT: + modstate &= ~KMOD_RSHIFT; + break; + case SDLK_LALT: + modstate &= ~KMOD_LALT; + break; + case SDLK_RALT: + modstate &= ~KMOD_RALT; + break; + case SDLK_LMETA: + modstate &= ~KMOD_LMETA; + break; + case SDLK_RMETA: + modstate &= ~KMOD_RMETA; + break; + case SDLK_MODE: + modstate &= ~KMOD_MODE; + break; + default: + break; + } + keysym->mod = (SDLMod) modstate; + } + + /* Figure out what type of event this is */ + switch (state) { + case SDL_PRESSED: + event.type = SDL_KEYDOWN; + break; + case SDL_RELEASED: + event.type = SDL_KEYUP; + /* + * jk 991215 - Added + */ + if (SDL_KeyRepeat.timestamp && + SDL_KeyRepeat.evt.key.keysym.sym == keysym->sym) { + SDL_KeyRepeat.timestamp = 0; + } + break; + default: + /* Invalid state -- bail */ + return (0); + } + + if (keysym->sym != SDLK_UNKNOWN) { + /* Drop events that don't change state */ + if (SDL_KeyState[keysym->sym] == state) { #if 0 -printf("Keyboard event didn't change state - dropped!\n"); + printf ("Keyboard event didn't change state - dropped!\n"); #endif - return(0); - } - - /* Update internal keyboard state */ - SDL_ModState = (SDLMod)modstate; - SDL_KeyState[keysym->sym] = state; - } - - /* Post the event, if desired */ - posted = 0; - if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { - event.key.state = state; - event.key.keysym = *keysym; - /* - * jk 991215 - Added - */ - if (repeatable && (SDL_KeyRepeat.delay != 0)) { - SDL_KeyRepeat.evt = event; - SDL_KeyRepeat.firsttime = 1; - SDL_KeyRepeat.timestamp=SDL_GetTicks(); - } - if ( (SDL_EventOK == NULL) || SDL_EventOK(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - return(posted); + return (0); + } + + /* Update internal keyboard state */ + SDL_ModState = (SDLMod) modstate; + SDL_KeyState[keysym->sym] = state; + } + + /* Post the event, if desired */ + posted = 0; + if (SDL_ProcessEvents[event.type] == SDL_ENABLE) { + event.key.state = state; + event.key.keysym = *keysym; + /* + * jk 991215 - Added + */ + if (repeatable && (SDL_KeyRepeat.delay != 0)) { + SDL_KeyRepeat.evt = event; + SDL_KeyRepeat.firsttime = 1; + SDL_KeyRepeat.timestamp = SDL_GetTicks (); + } + if ((SDL_EventOK == NULL) || SDL_EventOK (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } + return (posted); } /* * jk 991215 - Added */ -void SDL_CheckKeyRepeat(void) +void +SDL_CheckKeyRepeat (void) { - if ( SDL_KeyRepeat.timestamp ) { - Uint32 now, interval; - - now = SDL_GetTicks(); - interval = (now - SDL_KeyRepeat.timestamp); - if ( SDL_KeyRepeat.firsttime ) { - if ( interval > (Uint32)SDL_KeyRepeat.delay ) { - SDL_KeyRepeat.timestamp = now; - SDL_KeyRepeat.firsttime = 0; - } - } else { - if ( interval > (Uint32)SDL_KeyRepeat.interval ) { - SDL_KeyRepeat.timestamp = now; - if ( (SDL_EventOK == NULL) || SDL_EventOK(&SDL_KeyRepeat.evt) ) { - SDL_PushEvent(&SDL_KeyRepeat.evt); - } - } - } - } + if (SDL_KeyRepeat.timestamp) { + Uint32 now, interval; + + now = SDL_GetTicks (); + interval = (now - SDL_KeyRepeat.timestamp); + if (SDL_KeyRepeat.firsttime) { + if (interval > (Uint32) SDL_KeyRepeat.delay) { + SDL_KeyRepeat.timestamp = now; + SDL_KeyRepeat.firsttime = 0; + } + } else { + if (interval > (Uint32) SDL_KeyRepeat.interval) { + SDL_KeyRepeat.timestamp = now; + if ((SDL_EventOK == NULL) + || SDL_EventOK (&SDL_KeyRepeat.evt)) { + SDL_PushEvent (&SDL_KeyRepeat.evt); + } + } + } + } } -int SDL_EnableKeyRepeat(int delay, int interval) +int +SDL_EnableKeyRepeat (int delay, int interval) { - if ( (delay < 0) || (interval < 0) ) { - SDL_SetError("keyboard repeat value less than zero"); - return(-1); - } - SDL_KeyRepeat.firsttime = 0; - SDL_KeyRepeat.delay = delay; - SDL_KeyRepeat.interval = interval; - SDL_KeyRepeat.timestamp = 0; - return(0); + if ((delay < 0) || (interval < 0)) { + SDL_SetError ("keyboard repeat value less than zero"); + return (-1); + } + SDL_KeyRepeat.firsttime = 0; + SDL_KeyRepeat.delay = delay; + SDL_KeyRepeat.interval = interval; + SDL_KeyRepeat.timestamp = 0; + return (0); } -void SDL_GetKeyRepeat(int *delay, int *interval) +void +SDL_GetKeyRepeat (int *delay, int *interval) { - *delay = SDL_KeyRepeat.delay; - *interval = SDL_KeyRepeat.interval; + *delay = SDL_KeyRepeat.delay; + *interval = SDL_KeyRepeat.interval; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index f72ef3c80..e5d54a9b1 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -34,230 +34,240 @@ static Sint16 SDL_MouseX = 0; static Sint16 SDL_MouseY = 0; static Sint16 SDL_DeltaX = 0; static Sint16 SDL_DeltaY = 0; -static Uint8 SDL_ButtonState = 0; +static Uint8 SDL_ButtonState = 0; /* Public functions */ -int SDL_MouseInit(void) +int +SDL_MouseInit (void) { - /* The mouse is at (0,0) */ - SDL_MouseX = 0; - SDL_MouseY = 0; - SDL_DeltaX = 0; - SDL_DeltaY = 0; - SDL_ButtonState = 0; - - /* That's it! */ - return(0); + /* The mouse is at (0,0) */ + SDL_MouseX = 0; + SDL_MouseY = 0; + SDL_DeltaX = 0; + SDL_DeltaY = 0; + SDL_ButtonState = 0; + + /* That's it! */ + return (0); } -void SDL_MouseQuit(void) + +void +SDL_MouseQuit (void) { } /* We lost the mouse, so post button up messages for all pressed buttons */ -void SDL_ResetMouse(void) +void +SDL_ResetMouse (void) { - Uint8 i; - for ( i = 0; i < sizeof(SDL_ButtonState)*8; ++i ) { - if ( SDL_ButtonState & SDL_BUTTON(i) ) { - SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0); - } - } + Uint8 i; + for (i = 0; i < sizeof (SDL_ButtonState) * 8; ++i) { + if (SDL_ButtonState & SDL_BUTTON (i)) { + SDL_PrivateMouseButton (SDL_RELEASED, i, 0, 0); + } + } } -Uint8 SDL_GetMouseState (int *x, int *y) +Uint8 +SDL_GetMouseState (int *x, int *y) { - if ( x ) { - *x = SDL_MouseX; - } - if ( y ) { - *y = SDL_MouseY; - } - return(SDL_ButtonState); + if (x) { + *x = SDL_MouseX; + } + if (y) { + *y = SDL_MouseY; + } + return (SDL_ButtonState); } -Uint8 SDL_GetRelativeMouseState (int *x, int *y) +Uint8 +SDL_GetRelativeMouseState (int *x, int *y) { - if ( x ) - *x = SDL_DeltaX; - if ( y ) - *y = SDL_DeltaY; - SDL_DeltaX = 0; - SDL_DeltaY = 0; - return(SDL_ButtonState); + if (x) + *x = SDL_DeltaX; + if (y) + *y = SDL_DeltaY; + SDL_DeltaX = 0; + SDL_DeltaY = 0; + return (SDL_ButtonState); } -static void ClipOffset(Sint16 *x, Sint16 *y) +static void +ClipOffset (Sint16 * x, Sint16 * y) { - /* This clips absolute mouse coordinates when the apparent - display surface is smaller than the real display surface. - */ - if ( SDL_VideoSurface->offset ) { - *y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch; - *x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/ - SDL_VideoSurface->format->BytesPerPixel; - } + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + /* This clips absolute mouse coordinates when the apparent + display surface is smaller than the real display surface. + */ + if (SDL_VideoSurface->offset) { + *y -= SDL_VideoSurface->offset / SDL_VideoSurface->pitch; + *x -= (SDL_VideoSurface->offset % SDL_VideoSurface->pitch) / + SDL_VideoSurface->format->BytesPerPixel; + } } /* These are global for SDL_eventloop.c */ -int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y) +int +SDL_PrivateMouseMotion (Uint8 buttonstate, int relative, Sint16 x, Sint16 y) { - int posted; - Uint16 X, Y; - Sint16 Xrel; - Sint16 Yrel; - - /* Don't handle mouse motion if there's no cursor surface */ - if ( SDL_VideoSurface == NULL ) { - return(0); - } - - /* Default buttonstate is the current one */ - if ( ! buttonstate ) { - buttonstate = SDL_ButtonState; - } - - Xrel = x; - Yrel = y; - if ( relative ) { - /* Push the cursor around */ - x = (SDL_MouseX+x); - y = (SDL_MouseY+y); - } else { - /* Do we need to clip {x,y} ? */ - ClipOffset(&x, &y); - } - - /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ - if ( x < 0 ) - X = 0; - else - if ( x >= SDL_VideoSurface->w ) - X = SDL_VideoSurface->w-1; - else - X = (Uint16)x; - - if ( y < 0 ) - Y = 0; - else - if ( y >= SDL_VideoSurface->h ) - Y = SDL_VideoSurface->h-1; - else - Y = (Uint16)y; - - /* If not relative mode, generate relative motion from clamped X/Y. - This prevents lots of extraneous large delta relative motion when - the screen is windowed mode and the mouse is outside the window. - */ - if ( ! relative ) { - Xrel = X-SDL_MouseX; - Yrel = Y-SDL_MouseY; - } - - /* Drop events that don't change state */ - if ( ! Xrel && ! Yrel ) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + int posted; + Uint16 X, Y; + Sint16 Xrel; + Sint16 Yrel; + + /* Don't handle mouse motion if there's no cursor surface */ + if (SDL_VideoSurface == NULL) { + return (0); + } + + /* Default buttonstate is the current one */ + if (!buttonstate) { + buttonstate = SDL_ButtonState; + } + + Xrel = x; + Yrel = y; + if (relative) { + /* Push the cursor around */ + x = (SDL_MouseX + x); + y = (SDL_MouseY + y); + } else { + /* Do we need to clip {x,y} ? */ + ClipOffset (&x, &y); + } + + /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ + if (x < 0) + X = 0; + else if (x >= SDL_VideoSurface->w) + X = SDL_VideoSurface->w - 1; + else + X = (Uint16) x; + + if (y < 0) + Y = 0; + else if (y >= SDL_VideoSurface->h) + Y = SDL_VideoSurface->h - 1; + else + Y = (Uint16) y; + + /* If not relative mode, generate relative motion from clamped X/Y. + This prevents lots of extraneous large delta relative motion when + the screen is windowed mode and the mouse is outside the window. + */ + if (!relative) { + Xrel = X - SDL_MouseX; + Yrel = Y - SDL_MouseY; + } + + /* Drop events that don't change state */ + if (!Xrel && !Yrel) { #if 0 -printf("Mouse event didn't change state - dropped!\n"); + printf ("Mouse event didn't change state - dropped!\n"); #endif - return(0); - } - - /* Update internal mouse state */ - SDL_ButtonState = buttonstate; - SDL_MouseX = X; - SDL_MouseY = Y; - SDL_DeltaX += Xrel; - SDL_DeltaY += Yrel; - SDL_MoveCursor(SDL_MouseX, SDL_MouseY); - - /* Post the event, if desired */ - posted = 0; - if ( SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE ) { - SDL_Event event; - SDL_memset(&event, 0, sizeof(event)); - event.type = SDL_MOUSEMOTION; - event.motion.state = buttonstate; - event.motion.x = X; - event.motion.y = Y; - event.motion.xrel = Xrel; - event.motion.yrel = Yrel; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - return(posted); + return (0); + } + + /* Update internal mouse state */ + SDL_ButtonState = buttonstate; + SDL_MouseX = X; + SDL_MouseY = Y; + SDL_DeltaX += Xrel; + SDL_DeltaY += Yrel; + SDL_MoveCursor (SDL_MouseX, SDL_MouseY); + + /* Post the event, if desired */ + posted = 0; + if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) { + SDL_Event event; + SDL_memset (&event, 0, sizeof (event)); + event.type = SDL_MOUSEMOTION; + event.motion.state = buttonstate; + event.motion.x = X; + event.motion.y = Y; + event.motion.xrel = Xrel; + event.motion.yrel = Yrel; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } + return (posted); } -int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y) +int +SDL_PrivateMouseButton (Uint8 state, Uint8 button, Sint16 x, Sint16 y) { - SDL_Event event; - int posted; - int move_mouse; - Uint8 buttonstate; - - SDL_memset(&event, 0, sizeof(event)); - - /* Check parameters */ - if ( x || y ) { - ClipOffset(&x, &y); - move_mouse = 1; - /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ - if ( x < 0 ) - x = 0; - else - if ( x >= SDL_VideoSurface->w ) - x = SDL_VideoSurface->w-1; - - if ( y < 0 ) - y = 0; - else - if ( y >= SDL_VideoSurface->h ) - y = SDL_VideoSurface->h-1; - } else { - move_mouse = 0; - } - if ( ! x ) - x = SDL_MouseX; - if ( ! y ) - y = SDL_MouseY; - - /* Figure out which event to perform */ - buttonstate = SDL_ButtonState; - switch ( state ) { - case SDL_PRESSED: - event.type = SDL_MOUSEBUTTONDOWN; - buttonstate |= SDL_BUTTON(button); - break; - case SDL_RELEASED: - event.type = SDL_MOUSEBUTTONUP; - buttonstate &= ~SDL_BUTTON(button); - break; - default: - /* Invalid state -- bail */ - return(0); - } - - /* Update internal mouse state */ - SDL_ButtonState = buttonstate; - if ( move_mouse ) { - SDL_MouseX = x; - SDL_MouseY = y; - SDL_MoveCursor(SDL_MouseX, SDL_MouseY); - } - - /* Post the event, if desired */ - posted = 0; - if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { - event.button.state = state; - event.button.button = button; - event.button.x = x; - event.button.y = y; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - return(posted); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Event event; + int posted; + int move_mouse; + Uint8 buttonstate; + + SDL_memset (&event, 0, sizeof (event)); + + /* Check parameters */ + if (x || y) { + ClipOffset (&x, &y); + move_mouse = 1; + /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ + if (x < 0) + x = 0; + else if (x >= SDL_VideoSurface->w) + x = SDL_VideoSurface->w - 1; + + if (y < 0) + y = 0; + else if (y >= SDL_VideoSurface->h) + y = SDL_VideoSurface->h - 1; + } else { + move_mouse = 0; + } + if (!x) + x = SDL_MouseX; + if (!y) + y = SDL_MouseY; + + /* Figure out which event to perform */ + buttonstate = SDL_ButtonState; + switch (state) { + case SDL_PRESSED: + event.type = SDL_MOUSEBUTTONDOWN; + buttonstate |= SDL_BUTTON (button); + break; + case SDL_RELEASED: + event.type = SDL_MOUSEBUTTONUP; + buttonstate &= ~SDL_BUTTON (button); + break; + default: + /* Invalid state -- bail */ + return (0); + } + + /* Update internal mouse state */ + SDL_ButtonState = buttonstate; + if (move_mouse) { + SDL_MouseX = x; + SDL_MouseY = y; + SDL_MoveCursor (SDL_MouseX, SDL_MouseY); + } + + /* Post the event, if desired */ + posted = 0; + if (SDL_ProcessEvents[event.type] == SDL_ENABLE) { + event.button.state = state; + event.button.button = button; + event.button.x = x; + event.button.y = y; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } + return (posted); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_quit.c b/src/events/SDL_quit.c index 591f3274a..434432c85 100644 --- a/src/events/SDL_quit.c +++ b/src/events/SDL_quit.c @@ -32,61 +32,68 @@ #ifdef HAVE_SIGNAL_H -static void SDL_HandleSIG(int sig) +static void +SDL_HandleSIG (int sig) { - /* Reset the signal handler */ - signal(sig, SDL_HandleSIG); + /* Reset the signal handler */ + signal (sig, SDL_HandleSIG); - /* Signal a quit interrupt */ - SDL_PrivateQuit(); + /* Signal a quit interrupt */ + SDL_PrivateQuit (); } #endif /* HAVE_SIGNAL_H */ /* Public functions */ -int SDL_QuitInit(void) +int +SDL_QuitInit (void) { #ifdef HAVE_SIGNAL_H - void (*ohandler)(int); - - /* Both SIGINT and SIGTERM are translated into quit interrupts */ - ohandler = signal(SIGINT, SDL_HandleSIG); - if ( ohandler != SIG_DFL ) - signal(SIGINT, ohandler); - ohandler = signal(SIGTERM, SDL_HandleSIG); - if ( ohandler != SIG_DFL ) - signal(SIGTERM, ohandler); + void (*ohandler) (int); + + /* Both SIGINT and SIGTERM are translated into quit interrupts */ + ohandler = signal (SIGINT, SDL_HandleSIG); + if (ohandler != SIG_DFL) + signal (SIGINT, ohandler); + ohandler = signal (SIGTERM, SDL_HandleSIG); + if (ohandler != SIG_DFL) + signal (SIGTERM, ohandler); #endif /* HAVE_SIGNAL_H */ - /* That's it! */ - return(0); + /* That's it! */ + return (0); } -void SDL_QuitQuit(void) + +void +SDL_QuitQuit (void) { #ifdef HAVE_SIGNAL_H - void (*ohandler)(int); - - ohandler = signal(SIGINT, SIG_DFL); - if ( ohandler != SDL_HandleSIG ) - signal(SIGINT, ohandler); - ohandler = signal(SIGTERM, SIG_DFL); - if ( ohandler != SDL_HandleSIG ) - signal(SIGTERM, ohandler); + void (*ohandler) (int); + + ohandler = signal (SIGINT, SIG_DFL); + if (ohandler != SDL_HandleSIG) + signal (SIGINT, ohandler); + ohandler = signal (SIGTERM, SIG_DFL); + if (ohandler != SDL_HandleSIG) + signal (SIGTERM, ohandler); #endif /* HAVE_SIGNAL_H */ } /* This function returns 1 if it's okay to close the application window */ -int SDL_PrivateQuit(void) +int +SDL_PrivateQuit (void) { - int posted; - - posted = 0; - if ( SDL_ProcessEvents[SDL_QUIT] == SDL_ENABLE ) { - SDL_Event event; - event.type = SDL_QUIT; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - return(posted); + int posted; + + posted = 0; + if (SDL_ProcessEvents[SDL_QUIT] == SDL_ENABLE) { + SDL_Event event; + event.type = SDL_QUIT; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } + return (posted); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_resize.c b/src/events/SDL_resize.c deleted file mode 100644 index f625f706c..000000000 --- a/src/events/SDL_resize.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* Resize event handling code for SDL */ - -#include "SDL_events.h" -#include "SDL_events_c.h" -#include "../video/SDL_sysvideo.h" - - -/* Keep the last resize event so we don't post duplicates */ -static struct { - int w; - int h; -} last_resize; - -/* This is global for SDL_eventloop.c */ -int SDL_PrivateResize(int w, int h) -{ - int posted; - SDL_Event events[32]; - - /* See if this event would change the video surface */ - if ( !w || !h -#ifndef __OS2__ - || ((last_resize.w == w) && (last_resize.h == h)) -#endif - ) { - return(0); - } - last_resize.w = w; - last_resize.h = h; - if ( ! SDL_VideoSurface || - ((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) { - return(0); - } - - /* Pull out all old resize events */ - SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]), - SDL_GETEVENT, SDL_VIDEORESIZEMASK); - - /* Post the event, if desired */ - posted = 0; - if ( SDL_ProcessEvents[SDL_VIDEORESIZE] == SDL_ENABLE ) { - SDL_Event event; - event.type = SDL_VIDEORESIZE; - event.resize.w = w; - event.resize.h = h; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - return(posted); -} diff --git a/src/events/SDL_sysevents.h b/src/events/SDL_sysevents.h index 07d55b421..8c515d9b5 100644 --- a/src/events/SDL_sysevents.h +++ b/src/events/SDL_sysevents.h @@ -25,22 +25,23 @@ /* Useful functions and variables from SDL_sysevents.c */ -#ifdef __BEOS__ /* The Be event loop runs in a separate thread */ +#ifdef __BEOS__ /* The Be event loop runs in a separate thread */ #define MUST_THREAD_EVENTS #endif -#ifdef __WIN32__ /* Win32 doesn't allow a separate event thread */ +#ifdef __WIN32__ /* Win32 doesn't allow a separate event thread */ #define CANT_THREAD_EVENTS #endif -#ifdef IPOD /* iPod doesn't support threading at all */ +#ifdef IPOD /* iPod doesn't support threading at all */ #define CANT_THREAD_EVENTS #endif -#ifdef __MACOS__ /* MacOS 7/8 don't support preemptive multi-tasking */ +#ifdef __MACOS__ /* MacOS 7/8 don't support preemptive multi-tasking */ #define CANT_THREAD_EVENTS #endif -#ifdef __OS2__ /* The OS/2 event loop runs in a separate thread */ +#ifdef __OS2__ /* The OS/2 event loop runs in a separate thread */ #define MUST_THREAD_EVENTS #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_expose.c b/src/events/SDL_windowevents.c similarity index 57% rename from src/events/SDL_expose.c rename to src/events/SDL_windowevents.c index d325ea112..1e80b8804 100644 --- a/src/events/SDL_expose.c +++ b/src/events/SDL_windowevents.c @@ -21,31 +21,32 @@ */ #include "SDL_config.h" -/* Refresh event handling code for SDL */ +/* Window event handling code for SDL */ #include "SDL_events.h" #include "SDL_events_c.h" - -/* This is global for SDL_eventloop.c */ -int SDL_PrivateExpose(void) +int +SDL_PrivateWindowEvent (SDL_WindowID windowID, Uint8 windowevent, int data1, + int data2) { - int posted; - SDL_Event events[32]; - - /* Pull out all old refresh events */ - SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]), - SDL_GETEVENT, SDL_VIDEOEXPOSEMASK); - - /* Post the event, if desired */ - posted = 0; - if ( SDL_ProcessEvents[SDL_VIDEOEXPOSE] == SDL_ENABLE ) { - SDL_Event event; - event.type = SDL_VIDEOEXPOSE; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } - return(posted); + int posted; + + /* Post the event, if desired */ + posted = 0; + if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) { + SDL_Event event; + event.type = SDL_WINDOWEVENT; + event.window.event = windowevent; + event.window.data1 = data1; + event.window.data2 = data2; + event.window.windowID = windowID; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } + return (posted); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index add218fd2..7ea78ca69 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -43,275 +43,307 @@ #define INVALID_SET_FILE_POINTER 0xFFFFFFFF #endif -static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, const char *mode) +static int SDLCALL +win32_file_open (SDL_RWops * context, const char *filename, const char *mode) { #ifndef _WIN32_WCE - UINT old_error_mode; + UINT old_error_mode; #endif - HANDLE h; - DWORD r_right, w_right; - DWORD must_exist, truncate; - int a_mode; - - if (!context) - return -1; - - context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */ - - /* "r" = reading, file must exist */ - /* "w" = writing, truncate existing, file may not exist */ - /* "r+"= reading or writing, file must exist */ - /* "a" = writing, append file may not exist */ - /* "a+"= append + read, file may not exist */ - /* "w+" = read, write, truncate. file may not exist */ - - must_exist = ( SDL_strchr(mode,'r') != NULL ) ? OPEN_EXISTING : 0; - truncate = ( SDL_strchr(mode,'w') != NULL ) ? CREATE_ALWAYS : 0; - r_right = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0; - a_mode = ( SDL_strchr(mode,'a') != NULL ) ? OPEN_ALWAYS : 0; - w_right = ( a_mode || SDL_strchr(mode,'+') || truncate ) ? GENERIC_WRITE : 0; - - if (!r_right && !w_right) /* inconsistent mode */ - return -1; /* failed (invalid call)*/ + HANDLE h; + DWORD r_right, w_right; + DWORD must_exist, truncate; + int a_mode; + + if (!context) + return -1; + + context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */ + + /* "r" = reading, file must exist */ + /* "w" = writing, truncate existing, file may not exist */ + /* "r+"= reading or writing, file must exist */ + /* "a" = writing, append file may not exist */ + /* "a+"= append + read, file may not exist */ + /* "w+" = read, write, truncate. file may not exist */ + + must_exist = (SDL_strchr (mode, 'r') != NULL) ? OPEN_EXISTING : 0; + truncate = (SDL_strchr (mode, 'w') != NULL) ? CREATE_ALWAYS : 0; + r_right = (SDL_strchr (mode, '+') != NULL + || must_exist) ? GENERIC_READ : 0; + a_mode = (SDL_strchr (mode, 'a') != NULL) ? OPEN_ALWAYS : 0; + w_right = (a_mode || SDL_strchr (mode, '+') + || truncate) ? GENERIC_WRITE : 0; + + if (!r_right && !w_right) /* inconsistent mode */ + return -1; /* failed (invalid call) */ #ifdef _WIN32_WCE - { - size_t size = SDL_strlen(filename)+1; - wchar_t *filenameW = SDL_stack_alloc(wchar_t, size); - - if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) { - SDL_SetError("Unable to convert filename to Unicode"); - SDL_stack_free(filenameW); - return -1; - } - h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, - NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL); - SDL_stack_free(filenameW); - } + { + size_t size = SDL_strlen (filename) + 1; + wchar_t *filenameW = SDL_stack_alloc (wchar_t, size); + + if (MultiByteToWideChar (CP_UTF8, 0, filename, -1, filenameW, size) == + 0) { + SDL_SetError ("Unable to convert filename to Unicode"); + SDL_stack_free (filenameW); + return -1; + } + h = CreateFile (filenameW, (w_right | r_right), + (w_right) ? 0 : FILE_SHARE_READ, NULL, + (must_exist | truncate | a_mode), + FILE_ATTRIBUTE_NORMAL, NULL); + SDL_stack_free (filenameW); + } #else - /* Do not open a dialog box if failure */ - old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS); + /* Do not open a dialog box if failure */ + old_error_mode = + SetErrorMode (SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); - h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, - NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL); + h = CreateFile (filename, (w_right | r_right), + (w_right) ? 0 : FILE_SHARE_READ, NULL, + (must_exist | truncate | a_mode), FILE_ATTRIBUTE_NORMAL, + NULL); - /* restore old behaviour */ - SetErrorMode(old_error_mode); + /* restore old behaviour */ + SetErrorMode (old_error_mode); #endif /* _WIN32_WCE */ - if (h==INVALID_HANDLE_VALUE) { - SDL_SetError("Couldn't open %s",filename); - return -2; /* failed (CreateFile) */ - } - context->hidden.win32io.h = h; - context->hidden.win32io.append = a_mode; - - return 0; /* ok */ -} -static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence) -{ - DWORD win32whence; - int file_pos; - - if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) { - SDL_SetError("win32_file_seek: invalid context/file not opened"); - return -1; - } - - switch (whence) { - case RW_SEEK_SET: - win32whence = FILE_BEGIN; break; - case RW_SEEK_CUR: - win32whence = FILE_CURRENT; break; - case RW_SEEK_END: - win32whence = FILE_END; break; - default: - SDL_SetError("win32_file_seek: Unknown value for 'whence'"); - return -1; - } - - file_pos = SetFilePointer(context->hidden.win32io.h,offset,NULL,win32whence); - - if ( file_pos != INVALID_SET_FILE_POINTER ) - return file_pos; /* success */ - - SDL_Error(SDL_EFSEEK); - return -1; /* error */ -} -static int SDLCALL win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum) -{ - - int total_bytes; - DWORD byte_read,nread; - - total_bytes = size*maxnum; - - if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE || total_bytes<=0 || !size) - return 0; - - if (!ReadFile(context->hidden.win32io.h,ptr,total_bytes,&byte_read,NULL)) { - SDL_Error(SDL_EFREAD); - return 0; - } - nread = byte_read/size; - return nread; -} -static int SDLCALL win32_file_write(SDL_RWops *context, const void *ptr, int size, int num) -{ - - int total_bytes; - DWORD byte_written,nwritten; - - total_bytes = size*num; - - if (!context || context->hidden.win32io.h==INVALID_HANDLE_VALUE || total_bytes<=0 || !size) - return 0; - - /* if in append mode, we must go to the EOF before write */ - if (context->hidden.win32io.append) { - if ( SetFilePointer(context->hidden.win32io.h,0L,NULL,FILE_END) == INVALID_SET_FILE_POINTER ) { - SDL_Error(SDL_EFWRITE); - return 0; - } - } - - if (!WriteFile(context->hidden.win32io.h,ptr,total_bytes,&byte_written,NULL)) { - SDL_Error(SDL_EFWRITE); - return 0; - } - - nwritten = byte_written/size; - return nwritten; -} -static int SDLCALL win32_file_close(SDL_RWops *context) -{ - - if ( context ) { - if (context->hidden.win32io.h != INVALID_HANDLE_VALUE) { - CloseHandle(context->hidden.win32io.h); - context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* to be sure */ - } - SDL_FreeRW(context); - } - return(0); + if (h == INVALID_HANDLE_VALUE) { + SDL_SetError ("Couldn't open %s", filename); + return -2; /* failed (CreateFile) */ + } + context->hidden.win32io.h = h; + context->hidden.win32io.append = a_mode; + + return 0; /* ok */ } -#endif /* __WIN32__ */ +static int SDLCALL +win32_file_seek (SDL_RWops * context, int offset, int whence) +{ + DWORD win32whence; + int file_pos; -#ifdef HAVE_STDIO_H + if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE) { + SDL_SetError ("win32_file_seek: invalid context/file not opened"); + return -1; + } -/* Functions to read/write stdio file pointers */ + switch (whence) { + case RW_SEEK_SET: + win32whence = FILE_BEGIN; + break; + case RW_SEEK_CUR: + win32whence = FILE_CURRENT; + break; + case RW_SEEK_END: + win32whence = FILE_END; + break; + default: + SDL_SetError ("win32_file_seek: Unknown value for 'whence'"); + return -1; + } -static int SDLCALL stdio_seek(SDL_RWops *context, int offset, int whence) -{ - if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) { - return(ftell(context->hidden.stdio.fp)); - } else { - SDL_Error(SDL_EFSEEK); - return(-1); - } -} -static int SDLCALL stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum) -{ - size_t nread; + file_pos = + SetFilePointer (context->hidden.win32io.h, offset, NULL, win32whence); + + if (file_pos != INVALID_SET_FILE_POINTER) + return file_pos; /* success */ - nread = fread(ptr, size, maxnum, context->hidden.stdio.fp); - if ( nread == 0 && ferror(context->hidden.stdio.fp) ) { - SDL_Error(SDL_EFREAD); - } - return(nread); + SDL_Error (SDL_EFSEEK); + return -1; /* error */ } -static int SDLCALL stdio_write(SDL_RWops *context, const void *ptr, int size, int num) +static int SDLCALL +win32_file_read (SDL_RWops * context, void *ptr, int size, int maxnum) { - size_t nwrote; - nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp); - if ( nwrote == 0 && ferror(context->hidden.stdio.fp) ) { - SDL_Error(SDL_EFWRITE); - } - return(nwrote); + int total_bytes; + DWORD byte_read, nread; + + total_bytes = size * maxnum; + + if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE + || total_bytes <= 0 || !size) + return 0; + + if (!ReadFile + (context->hidden.win32io.h, ptr, total_bytes, &byte_read, NULL)) { + SDL_Error (SDL_EFREAD); + return 0; + } + nread = byte_read / size; + return nread; } -static int SDLCALL stdio_close(SDL_RWops *context) +static int SDLCALL +win32_file_write (SDL_RWops * context, const void *ptr, int size, int num) { - if ( context ) { - if ( context->hidden.stdio.autoclose ) { - /* WARNING: Check the return value here! */ - fclose(context->hidden.stdio.fp); - } - SDL_FreeRW(context); - } - return(0); -} -#endif /* !HAVE_STDIO_H */ -/* Functions to read/write memory pointers */ + int total_bytes; + DWORD byte_written, nwritten; -static int SDLCALL mem_seek(SDL_RWops *context, int offset, int whence) -{ - Uint8 *newpos; + total_bytes = size * num; + + if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE + || total_bytes <= 0 || !size) + return 0; + + /* if in append mode, we must go to the EOF before write */ + if (context->hidden.win32io.append) { + if (SetFilePointer (context->hidden.win32io.h, 0L, NULL, FILE_END) + == INVALID_SET_FILE_POINTER) { + SDL_Error (SDL_EFWRITE); + return 0; + } + } - switch (whence) { - case RW_SEEK_SET: - newpos = context->hidden.mem.base+offset; - break; - case RW_SEEK_CUR: - newpos = context->hidden.mem.here+offset; - break; - case RW_SEEK_END: - newpos = context->hidden.mem.stop+offset; - break; - default: - SDL_SetError("Unknown value for 'whence'"); - return(-1); - } - if ( newpos < context->hidden.mem.base ) { - newpos = context->hidden.mem.base; - } - if ( newpos > context->hidden.mem.stop ) { - newpos = context->hidden.mem.stop; - } - context->hidden.mem.here = newpos; - return(context->hidden.mem.here-context->hidden.mem.base); + if (!WriteFile + (context->hidden.win32io.h, ptr, total_bytes, &byte_written, NULL)) { + SDL_Error (SDL_EFWRITE); + return 0; + } + + nwritten = byte_written / size; + return nwritten; } -static int SDLCALL mem_read(SDL_RWops *context, void *ptr, int size, int maxnum) +static int SDLCALL +win32_file_close (SDL_RWops * context) { - size_t total_bytes; - size_t mem_available; - total_bytes = (maxnum * size); - if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != (size_t) size) ) { - return 0; - } + if (context) { + if (context->hidden.win32io.h != INVALID_HANDLE_VALUE) { + CloseHandle (context->hidden.win32io.h); + context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* to be sure */ + } + SDL_FreeRW (context); + } + return (0); +} +#endif /* __WIN32__ */ - mem_available = (context->hidden.mem.stop - context->hidden.mem.here); - if (total_bytes > mem_available) { - total_bytes = mem_available; - } +#ifdef HAVE_STDIO_H - SDL_memcpy(ptr, context->hidden.mem.here, total_bytes); - context->hidden.mem.here += total_bytes; +/* Functions to read/write stdio file pointers */ - return (total_bytes / size); +static int SDLCALL +stdio_seek (SDL_RWops * context, int offset, int whence) +{ + if (fseek (context->hidden.stdio.fp, offset, whence) == 0) { + return (ftell (context->hidden.stdio.fp)); + } else { + SDL_Error (SDL_EFSEEK); + return (-1); + } } -static int SDLCALL mem_write(SDL_RWops *context, const void *ptr, int size, int num) +static int SDLCALL +stdio_read (SDL_RWops * context, void *ptr, int size, int maxnum) { - if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) { - num = (context->hidden.mem.stop-context->hidden.mem.here)/size; - } - SDL_memcpy(context->hidden.mem.here, ptr, num*size); - context->hidden.mem.here += num*size; - return(num); + size_t nread; + + nread = fread (ptr, size, maxnum, context->hidden.stdio.fp); + if (nread == 0 && ferror (context->hidden.stdio.fp)) { + SDL_Error (SDL_EFREAD); + } + return (nread); } -static int SDLCALL mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num) +static int SDLCALL +stdio_write (SDL_RWops * context, const void *ptr, int size, int num) { - SDL_SetError("Can't write to read-only memory"); - return(-1); + size_t nwrote; + + nwrote = fwrite (ptr, size, num, context->hidden.stdio.fp); + if (nwrote == 0 && ferror (context->hidden.stdio.fp)) { + SDL_Error (SDL_EFWRITE); + } + return (nwrote); } -static int SDLCALL mem_close(SDL_RWops *context) +static int SDLCALL +stdio_close (SDL_RWops * context) { - if ( context ) { - SDL_FreeRW(context); - } - return(0); + if (context) { + if (context->hidden.stdio.autoclose) { + /* WARNING: Check the return value here! */ + fclose (context->hidden.stdio.fp); + } + SDL_FreeRW (context); + } + return (0); +} +#endif /* !HAVE_STDIO_H */ + +/* Functions to read/write memory pointers */ + +static int SDLCALL +mem_seek (SDL_RWops * context, int offset, int whence) +{ + Uint8 *newpos; + + switch (whence) { + case RW_SEEK_SET: + newpos = context->hidden.mem.base + offset; + break; + case RW_SEEK_CUR: + newpos = context->hidden.mem.here + offset; + break; + case RW_SEEK_END: + newpos = context->hidden.mem.stop + offset; + break; + default: + SDL_SetError ("Unknown value for 'whence'"); + return (-1); + } + if (newpos < context->hidden.mem.base) { + newpos = context->hidden.mem.base; + } + if (newpos > context->hidden.mem.stop) { + newpos = context->hidden.mem.stop; + } + context->hidden.mem.here = newpos; + return (context->hidden.mem.here - context->hidden.mem.base); +} +static int SDLCALL +mem_read (SDL_RWops * context, void *ptr, int size, int maxnum) +{ + size_t total_bytes; + size_t mem_available; + + total_bytes = (maxnum * size); + if ((maxnum <= 0) || (size <= 0) + || ((total_bytes / maxnum) != (size_t) size)) { + return 0; + } + + mem_available = (context->hidden.mem.stop - context->hidden.mem.here); + if (total_bytes > mem_available) { + total_bytes = mem_available; + } + + SDL_memcpy (ptr, context->hidden.mem.here, total_bytes); + context->hidden.mem.here += total_bytes; + + return (total_bytes / size); +} +static int SDLCALL +mem_write (SDL_RWops * context, const void *ptr, int size, int num) +{ + if ((context->hidden.mem.here + (num * size)) > context->hidden.mem.stop) { + num = (context->hidden.mem.stop - context->hidden.mem.here) / size; + } + SDL_memcpy (context->hidden.mem.here, ptr, num * size); + context->hidden.mem.here += num * size; + return (num); +} +static int SDLCALL +mem_writeconst (SDL_RWops * context, const void *ptr, int size, int num) +{ + SDL_SetError ("Can't write to read-only memory"); + return (-1); +} +static int SDLCALL +mem_close (SDL_RWops * context) +{ + if (context) { + SDL_FreeRW (context); + } + return (0); } @@ -322,233 +354,263 @@ static int SDLCALL mem_close(SDL_RWops *context) * translate unix-style slash-separated filename to mac-style colon-separated * name; return malloced string */ -static char *unix_to_mac(const char *file) -{ - int flen = SDL_strlen(file); - char *path = SDL_malloc(flen + 2); - const char *src = file; - char *dst = path; - if(*src == '/') { - /* really depends on filesystem layout, hope for the best */ - src++; - } else { - /* Check if this is a MacOS path to begin with */ - if(*src != ':') - *dst++ = ':'; /* relative paths begin with ':' */ - } - while(src < file + flen) { - const char *end = SDL_strchr(src, '/'); - int len; - if(!end) - end = file + flen; /* last component */ - len = end - src; - if(len == 0 || (len == 1 && src[0] == '.')) { - /* remove repeated slashes and . */ - } else { - if(len == 2 && src[0] == '.' && src[1] == '.') { - /* replace .. with the empty string */ - } else { - SDL_memcpy(dst, src, len); - dst += len; - } - if(end < file + flen) - *dst++ = ':'; - } - src = end + 1; - } - *dst++ = '\0'; - return path; +static char * +unix_to_mac (const char *file) +{ + int flen = SDL_strlen (file); + char *path = SDL_malloc (flen + 2); + const char *src = file; + char *dst = path; + if (*src == '/') { + /* really depends on filesystem layout, hope for the best */ + src++; + } else { + /* Check if this is a MacOS path to begin with */ + if (*src != ':') + *dst++ = ':'; /* relative paths begin with ':' */ + } + while (src < file + flen) { + const char *end = SDL_strchr (src, '/'); + int len; + if (!end) + end = file + flen; /* last component */ + len = end - src; + if (len == 0 || (len == 1 && src[0] == '.')) { + /* remove repeated slashes and . */ + } else { + if (len == 2 && src[0] == '.' && src[1] == '.') { + /* replace .. with the empty string */ + } else { + SDL_memcpy (dst, src, len); + dst += len; + } + if (end < file + flen) + *dst++ = ':'; + } + src = end + 1; + } + *dst++ = '\0'; + return path; } #endif /* __MACOS__ */ -SDL_RWops *SDL_RWFromFile(const char *file, const char *mode) +SDL_RWops * +SDL_RWFromFile (const char *file, const char *mode) { - SDL_RWops *rwops = NULL; + SDL_RWops *rwops = NULL; #ifdef HAVE_STDIO_H - FILE *fp = NULL; + FILE *fp = NULL; #endif - if ( !file || !*file || !mode || !*mode ) { - SDL_SetError("SDL_RWFromFile(): No file or no mode specified"); - return NULL; - } - + if (!file || !*file || !mode || !*mode) { + SDL_SetError ("SDL_RWFromFile(): No file or no mode specified"); + return NULL; + } #if defined(__WIN32__) - rwops = SDL_AllocRW(); - if (!rwops) - return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ - rwops->hidden.win32io.h = INVALID_HANDLE_VALUE; - if (win32_file_open(rwops,file,mode)) { - SDL_FreeRW(rwops); - return NULL; - } - rwops->seek = win32_file_seek; - rwops->read = win32_file_read; - rwops->write = win32_file_write; - rwops->close = win32_file_close; + rwops = SDL_AllocRW (); + if (!rwops) + return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ + rwops->hidden.win32io.h = INVALID_HANDLE_VALUE; + if (win32_file_open (rwops, file, mode)) { + SDL_FreeRW (rwops); + return NULL; + } + rwops->seek = win32_file_seek; + rwops->read = win32_file_read; + rwops->write = win32_file_write; + rwops->close = win32_file_close; #elif HAVE_STDIO_H #ifdef __MACOS__ - { - char *mpath = unix_to_mac(file); - fp = fopen(mpath, mode); - SDL_free(mpath); - } + { + char *mpath = unix_to_mac (file); + fp = fopen (mpath, mode); + SDL_free (mpath); + } #else - fp = fopen(file, mode); + fp = fopen (file, mode); #endif - if ( fp == NULL ) { - SDL_SetError("Couldn't open %s", file); - } else { - rwops = SDL_RWFromFP(fp, 1); - } + if (fp == NULL) { + SDL_SetError ("Couldn't open %s", file); + } else { + rwops = SDL_RWFromFP (fp, 1); + } #else - SDL_SetError("SDL not compiled with stdio support"); + SDL_SetError ("SDL not compiled with stdio support"); #endif /* !HAVE_STDIO_H */ - return(rwops); + return (rwops); } #ifdef HAVE_STDIO_H -SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose) -{ - SDL_RWops *rwops = NULL; - - rwops = SDL_AllocRW(); - if ( rwops != NULL ) { - rwops->seek = stdio_seek; - rwops->read = stdio_read; - rwops->write = stdio_write; - rwops->close = stdio_close; - rwops->hidden.stdio.fp = fp; - rwops->hidden.stdio.autoclose = autoclose; - } - return(rwops); +SDL_RWops * +SDL_RWFromFP (FILE * fp, int autoclose) +{ + SDL_RWops *rwops = NULL; + + rwops = SDL_AllocRW (); + if (rwops != NULL) { + rwops->seek = stdio_seek; + rwops->read = stdio_read; + rwops->write = stdio_write; + rwops->close = stdio_close; + rwops->hidden.stdio.fp = fp; + rwops->hidden.stdio.autoclose = autoclose; + } + return (rwops); } #endif /* HAVE_STDIO_H */ -SDL_RWops *SDL_RWFromMem(void *mem, int size) +SDL_RWops * +SDL_RWFromMem (void *mem, int size) { - SDL_RWops *rwops; + SDL_RWops *rwops; - rwops = SDL_AllocRW(); - if ( rwops != NULL ) { - rwops->seek = mem_seek; - rwops->read = mem_read; - rwops->write = mem_write; - rwops->close = mem_close; - rwops->hidden.mem.base = (Uint8 *)mem; - rwops->hidden.mem.here = rwops->hidden.mem.base; - rwops->hidden.mem.stop = rwops->hidden.mem.base+size; - } - return(rwops); + rwops = SDL_AllocRW (); + if (rwops != NULL) { + rwops->seek = mem_seek; + rwops->read = mem_read; + rwops->write = mem_write; + rwops->close = mem_close; + rwops->hidden.mem.base = (Uint8 *) mem; + rwops->hidden.mem.here = rwops->hidden.mem.base; + rwops->hidden.mem.stop = rwops->hidden.mem.base + size; + } + return (rwops); } -SDL_RWops *SDL_RWFromConstMem(const void *mem, int size) +SDL_RWops * +SDL_RWFromConstMem (const void *mem, int size) { - SDL_RWops *rwops; + SDL_RWops *rwops; - rwops = SDL_AllocRW(); - if ( rwops != NULL ) { - rwops->seek = mem_seek; - rwops->read = mem_read; - rwops->write = mem_writeconst; - rwops->close = mem_close; - rwops->hidden.mem.base = (Uint8 *)mem; - rwops->hidden.mem.here = rwops->hidden.mem.base; - rwops->hidden.mem.stop = rwops->hidden.mem.base+size; - } - return(rwops); + rwops = SDL_AllocRW (); + if (rwops != NULL) { + rwops->seek = mem_seek; + rwops->read = mem_read; + rwops->write = mem_writeconst; + rwops->close = mem_close; + rwops->hidden.mem.base = (Uint8 *) mem; + rwops->hidden.mem.here = rwops->hidden.mem.base; + rwops->hidden.mem.stop = rwops->hidden.mem.base + size; + } + return (rwops); } -SDL_RWops *SDL_AllocRW(void) +SDL_RWops * +SDL_AllocRW (void) { - SDL_RWops *area; + SDL_RWops *area; - area = (SDL_RWops *)SDL_malloc(sizeof *area); - if ( area == NULL ) { - SDL_OutOfMemory(); - } - return(area); + area = (SDL_RWops *) SDL_malloc (sizeof *area); + if (area == NULL) { + SDL_OutOfMemory (); + } + return (area); } -void SDL_FreeRW(SDL_RWops *area) +void +SDL_FreeRW (SDL_RWops * area) { - SDL_free(area); + SDL_free (area); } /* Functions for dynamically reading and writing endian-specific values */ -Uint16 SDL_ReadLE16 (SDL_RWops *src) +Uint16 +SDL_ReadLE16 (SDL_RWops * src) { - Uint16 value; + Uint16 value; - SDL_RWread(src, &value, (sizeof value), 1); - return(SDL_SwapLE16(value)); + SDL_RWread (src, &value, (sizeof value), 1); + return (SDL_SwapLE16 (value)); } -Uint16 SDL_ReadBE16 (SDL_RWops *src) + +Uint16 +SDL_ReadBE16 (SDL_RWops * src) { - Uint16 value; + Uint16 value; - SDL_RWread(src, &value, (sizeof value), 1); - return(SDL_SwapBE16(value)); + SDL_RWread (src, &value, (sizeof value), 1); + return (SDL_SwapBE16 (value)); } -Uint32 SDL_ReadLE32 (SDL_RWops *src) + +Uint32 +SDL_ReadLE32 (SDL_RWops * src) { - Uint32 value; + Uint32 value; - SDL_RWread(src, &value, (sizeof value), 1); - return(SDL_SwapLE32(value)); + SDL_RWread (src, &value, (sizeof value), 1); + return (SDL_SwapLE32 (value)); } -Uint32 SDL_ReadBE32 (SDL_RWops *src) + +Uint32 +SDL_ReadBE32 (SDL_RWops * src) { - Uint32 value; + Uint32 value; - SDL_RWread(src, &value, (sizeof value), 1); - return(SDL_SwapBE32(value)); + SDL_RWread (src, &value, (sizeof value), 1); + return (SDL_SwapBE32 (value)); } -Uint64 SDL_ReadLE64 (SDL_RWops *src) + +Uint64 +SDL_ReadLE64 (SDL_RWops * src) { - Uint64 value; + Uint64 value; - SDL_RWread(src, &value, (sizeof value), 1); - return(SDL_SwapLE64(value)); + SDL_RWread (src, &value, (sizeof value), 1); + return (SDL_SwapLE64 (value)); } -Uint64 SDL_ReadBE64 (SDL_RWops *src) + +Uint64 +SDL_ReadBE64 (SDL_RWops * src) { - Uint64 value; + Uint64 value; - SDL_RWread(src, &value, (sizeof value), 1); - return(SDL_SwapBE64(value)); + SDL_RWread (src, &value, (sizeof value), 1); + return (SDL_SwapBE64 (value)); } -int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value) +int +SDL_WriteLE16 (SDL_RWops * dst, Uint16 value) { - value = SDL_SwapLE16(value); - return(SDL_RWwrite(dst, &value, (sizeof value), 1)); + value = SDL_SwapLE16 (value); + return (SDL_RWwrite (dst, &value, (sizeof value), 1)); } -int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value) + +int +SDL_WriteBE16 (SDL_RWops * dst, Uint16 value) { - value = SDL_SwapBE16(value); - return(SDL_RWwrite(dst, &value, (sizeof value), 1)); + value = SDL_SwapBE16 (value); + return (SDL_RWwrite (dst, &value, (sizeof value), 1)); } -int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value) + +int +SDL_WriteLE32 (SDL_RWops * dst, Uint32 value) { - value = SDL_SwapLE32(value); - return(SDL_RWwrite(dst, &value, (sizeof value), 1)); + value = SDL_SwapLE32 (value); + return (SDL_RWwrite (dst, &value, (sizeof value), 1)); } -int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value) + +int +SDL_WriteBE32 (SDL_RWops * dst, Uint32 value) { - value = SDL_SwapBE32(value); - return(SDL_RWwrite(dst, &value, (sizeof value), 1)); + value = SDL_SwapBE32 (value); + return (SDL_RWwrite (dst, &value, (sizeof value), 1)); } -int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value) + +int +SDL_WriteLE64 (SDL_RWops * dst, Uint64 value) { - value = SDL_SwapLE64(value); - return(SDL_RWwrite(dst, &value, (sizeof value), 1)); + value = SDL_SwapLE64 (value); + return (SDL_RWwrite (dst, &value, (sizeof value), 1)); } -int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value) + +int +SDL_WriteBE64 (SDL_RWops * dst, Uint64 value) { - value = SDL_SwapBE64(value); - return(SDL_RWwrite(dst, &value, (sizeof value), 1)); + value = SDL_SwapBE64 (value); + return (SDL_RWwrite (dst, &value, (sizeof value), 1)); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/hermes/HeadMMX.h b/src/hermes/HeadMMX.h index 11cf6da5b..3e757fbd4 100644 --- a/src/hermes/HeadMMX.h +++ b/src/hermes/HeadMMX.h @@ -19,24 +19,25 @@ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void STACKCALL ConvertMMX(HermesConverterInterface *); + void STACKCALL ConvertMMX (HermesConverterInterface *); -void STACKCALL ClearMMX_32(HermesClearInterface *); -void STACKCALL ClearMMX_24(HermesClearInterface *); -void STACKCALL ClearMMX_16(HermesClearInterface *); -void STACKCALL ClearMMX_8(HermesClearInterface *); + void STACKCALL ClearMMX_32 (HermesClearInterface *); + void STACKCALL ClearMMX_24 (HermesClearInterface *); + void STACKCALL ClearMMX_16 (HermesClearInterface *); + void STACKCALL ClearMMX_8 (HermesClearInterface *); -void ConvertMMXpII32_24RGB888(); -void ConvertMMXpII32_16RGB565(); -void ConvertMMXpII32_16BGR565(); -void ConvertMMXpII32_16RGB555(); -void ConvertMMXpII32_16BGR565(); -void ConvertMMXpII32_16BGR555(); + void ConvertMMXpII32_24RGB888 (); + void ConvertMMXpII32_16RGB565 (); + void ConvertMMXpII32_16BGR565 (); + void ConvertMMXpII32_16RGB555 (); + void ConvertMMXpII32_16BGR565 (); + void ConvertMMXpII32_16BGR555 (); -void ConvertMMXp32_16RGB555(); + void ConvertMMXp32_16RGB555 (); #ifdef __cplusplus } @@ -47,29 +48,30 @@ void ConvertMMXp32_16RGB555(); /* Fix the underscore business with ELF compilers */ #if defined(__ELF__) && defined(__GNUC__) - #ifdef __cplusplus - extern "C" { - #endif +#ifdef __cplusplus +extern "C" +{ +#endif - extern void _ConvertMMX(HermesConverterInterface *); - extern void _ConvertMMXpII32_24RGB888(); - extern void _ConvertMMXpII32_16RGB565(); - extern void _ConvertMMXpII32_16BGR565(); - extern void _ConvertMMXpII32_16RGB555(); - extern void _ConvertMMXpII32_16BGR555(); + extern void _ConvertMMX (HermesConverterInterface *); + extern void _ConvertMMXpII32_24RGB888 (); + extern void _ConvertMMXpII32_16RGB565 (); + extern void _ConvertMMXpII32_16BGR565 (); + extern void _ConvertMMXpII32_16RGB555 (); + extern void _ConvertMMXpII32_16BGR555 (); - #define ConvertMMX _ConvertMMX - #define ConvertMMXpII32_24RGB888 _ConvertMMXpII32_24RGB888 - #define ConvertMMXpII32_16RGB565 _ConvertMMXpII32_16RGB565 - #define ConvertMMXpII32_16BGR565 _ConvertMMXpII32_16BGR565 - #define ConvertMMXpII32_16RGB555 _ConvertMMXpII32_16RGB555 - #define ConvertMMXpII32_16BGR555 _ConvertMMXpII32_16BGR555 +#define ConvertMMX _ConvertMMX +#define ConvertMMXpII32_24RGB888 _ConvertMMXpII32_24RGB888 +#define ConvertMMXpII32_16RGB565 _ConvertMMXpII32_16RGB565 +#define ConvertMMXpII32_16BGR565 _ConvertMMXpII32_16BGR565 +#define ConvertMMXpII32_16RGB555 _ConvertMMXpII32_16RGB555 +#define ConvertMMXpII32_16BGR555 _ConvertMMXpII32_16BGR555 - #ifdef __cplusplus - } - #endif +#ifdef __cplusplus +} +#endif -#endif /* ELF and GNUC */ +#endif /* ELF and GNUC */ @@ -92,9 +94,10 @@ void ConvertMMXp32_16RGB555(); #pragma aux ConvertMMXpII32_16BGR555 "_*" #pragma aux ConvertMMXp32_16RGB555 "_*" -#endif /* WATCOM */ +#endif /* WATCOM */ -#endif /* X86_ASSEMBLER */ +#endif /* X86_ASSEMBLER */ #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/hermes/HeadX86.h b/src/hermes/HeadX86.h index 54e0cc9d7..48af7850b 100644 --- a/src/hermes/HeadX86.h +++ b/src/hermes/HeadX86.h @@ -17,54 +17,55 @@ /* Ok, we start with normal function definitions */ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void STACKCALL ConvertX86(HermesConverterInterface *); -void STACKCALL ClearX86_32(HermesClearInterface *); -void STACKCALL ClearX86_24(HermesClearInterface *); -void STACKCALL ClearX86_16(HermesClearInterface *); -void STACKCALL ClearX86_8(HermesClearInterface *); - -int STACKCALL Hermes_X86_CPU(); - -void ConvertX86p32_32BGR888(); -void ConvertX86p32_32RGBA888(); -void ConvertX86p32_32BGRA888(); -void ConvertX86p32_24RGB888(); -void ConvertX86p32_24BGR888(); -void ConvertX86p32_16RGB565(); -void ConvertX86p32_16BGR565(); -void ConvertX86p32_16RGB555(); -void ConvertX86p32_16BGR555(); -void ConvertX86p32_8RGB332(); - -void ConvertX86p16_32RGB888(); -void ConvertX86p16_32BGR888(); -void ConvertX86p16_32RGBA888(); -void ConvertX86p16_32BGRA888(); -void ConvertX86p16_24RGB888(); -void ConvertX86p16_24BGR888(); -void ConvertX86p16_16BGR565(); -void ConvertX86p16_16RGB555(); -void ConvertX86p16_16BGR555(); -void ConvertX86p16_8RGB332(); - -void CopyX86p_4byte(); -void CopyX86p_3byte(); -void CopyX86p_2byte(); -void CopyX86p_1byte(); - -void ConvertX86pI8_32(); -void ConvertX86pI8_24(); -void ConvertX86pI8_16(); - -extern int ConvertX86p16_32RGB888_LUT_X86[512]; -extern int ConvertX86p16_32BGR888_LUT_X86[512]; -extern int ConvertX86p16_32RGBA888_LUT_X86[512]; -extern int ConvertX86p16_32BGRA888_LUT_X86[512]; - + void STACKCALL ConvertX86 (HermesConverterInterface *); + void STACKCALL ClearX86_32 (HermesClearInterface *); + void STACKCALL ClearX86_24 (HermesClearInterface *); + void STACKCALL ClearX86_16 (HermesClearInterface *); + void STACKCALL ClearX86_8 (HermesClearInterface *); + + int STACKCALL Hermes_X86_CPU (); + + void ConvertX86p32_32BGR888 (); + void ConvertX86p32_32RGBA888 (); + void ConvertX86p32_32BGRA888 (); + void ConvertX86p32_24RGB888 (); + void ConvertX86p32_24BGR888 (); + void ConvertX86p32_16RGB565 (); + void ConvertX86p32_16BGR565 (); + void ConvertX86p32_16RGB555 (); + void ConvertX86p32_16BGR555 (); + void ConvertX86p32_8RGB332 (); + + void ConvertX86p16_32RGB888 (); + void ConvertX86p16_32BGR888 (); + void ConvertX86p16_32RGBA888 (); + void ConvertX86p16_32BGRA888 (); + void ConvertX86p16_24RGB888 (); + void ConvertX86p16_24BGR888 (); + void ConvertX86p16_16BGR565 (); + void ConvertX86p16_16RGB555 (); + void ConvertX86p16_16BGR555 (); + void ConvertX86p16_8RGB332 (); + + void CopyX86p_4byte (); + void CopyX86p_3byte (); + void CopyX86p_2byte (); + void CopyX86p_1byte (); + + void ConvertX86pI8_32 (); + void ConvertX86pI8_24 (); + void ConvertX86pI8_16 (); + + extern int ConvertX86p16_32RGB888_LUT_X86[512]; + extern int ConvertX86p16_32BGR888_LUT_X86[512]; + extern int ConvertX86p16_32RGBA888_LUT_X86[512]; + extern int ConvertX86p16_32BGRA888_LUT_X86[512]; + #ifdef __cplusplus } #endif @@ -75,57 +76,58 @@ extern int ConvertX86p16_32BGRA888_LUT_X86[512]; /* Now fix up the ELF underscore problem */ #if defined(__ELF__) && defined(__GNUC__) - #ifdef __cplusplus - extern "C" { - #endif +#ifdef __cplusplus +extern "C" +{ +#endif - extern int _Hermes_X86_CPU(); + extern int _Hermes_X86_CPU (); - extern void _ConvertX86(HermesConverterInterface *); + extern void _ConvertX86 (HermesConverterInterface *); - extern void _ConvertX86p32_32BGR888(); - extern void _ConvertX86p32_32RGBA888(); - extern void _ConvertX86p32_32BGRA888(); - extern void _ConvertX86p32_24RGB888(); - extern void _ConvertX86p32_24BGR888(); - extern void _ConvertX86p32_16RGB565(); - extern void _ConvertX86p32_16BGR565(); - extern void _ConvertX86p32_16RGB555(); - extern void _ConvertX86p32_16BGR555(); - extern void _ConvertX86p32_8RGB332(); + extern void _ConvertX86p32_32BGR888 (); + extern void _ConvertX86p32_32RGBA888 (); + extern void _ConvertX86p32_32BGRA888 (); + extern void _ConvertX86p32_24RGB888 (); + extern void _ConvertX86p32_24BGR888 (); + extern void _ConvertX86p32_16RGB565 (); + extern void _ConvertX86p32_16BGR565 (); + extern void _ConvertX86p32_16RGB555 (); + extern void _ConvertX86p32_16BGR555 (); + extern void _ConvertX86p32_8RGB332 (); - extern void _ConvertX86p16_16BGR565(); - extern void _ConvertX86p16_16RGB555(); - extern void _ConvertX86p16_16BGR555(); - extern void _ConvertX86p16_8RGB332(); + extern void _ConvertX86p16_16BGR565 (); + extern void _ConvertX86p16_16RGB555 (); + extern void _ConvertX86p16_16BGR555 (); + extern void _ConvertX86p16_8RGB332 (); - #define Hermes_X86_CPU _Hermes_X86_CPU +#define Hermes_X86_CPU _Hermes_X86_CPU - #define ConvertX86 _ConvertX86 +#define ConvertX86 _ConvertX86 - #define ConvertX86p32_32BGR888 _ConvertX86p32_32BGR888 - #define ConvertX86p32_32RGBA888 _ConvertX86p32_32RGBA888 - #define ConvertX86p32_32BGRA888 _ConvertX86p32_32BGRA888 - #define ConvertX86p32_24RGB888 _ConvertX86p32_24RGB888 - #define ConvertX86p32_24BGR888 _ConvertX86p32_24BGR888 - #define ConvertX86p32_16RGB565 _ConvertX86p32_16RGB565 - #define ConvertX86p32_16BGR565 _ConvertX86p32_16BGR565 - #define ConvertX86p32_16RGB555 _ConvertX86p32_16RGB555 - #define ConvertX86p32_16BGR555 _ConvertX86p32_16BGR555 - #define ConvertX86p32_8RGB332 _ConvertX86p32_8RGB332 +#define ConvertX86p32_32BGR888 _ConvertX86p32_32BGR888 +#define ConvertX86p32_32RGBA888 _ConvertX86p32_32RGBA888 +#define ConvertX86p32_32BGRA888 _ConvertX86p32_32BGRA888 +#define ConvertX86p32_24RGB888 _ConvertX86p32_24RGB888 +#define ConvertX86p32_24BGR888 _ConvertX86p32_24BGR888 +#define ConvertX86p32_16RGB565 _ConvertX86p32_16RGB565 +#define ConvertX86p32_16BGR565 _ConvertX86p32_16BGR565 +#define ConvertX86p32_16RGB555 _ConvertX86p32_16RGB555 +#define ConvertX86p32_16BGR555 _ConvertX86p32_16BGR555 +#define ConvertX86p32_8RGB332 _ConvertX86p32_8RGB332 - #define ConvertX86p16_16BGR565 _ConvertX86p16_16BGR565 - #define ConvertX86p16_16RGB555 _ConvertX86p16_16RGB555 - #define ConvertX86p16_16BGR555 _ConvertX86p16_16BGR555 - #define ConvertX86p16_8RGB332 _ConvertX86p16_8RGB332 +#define ConvertX86p16_16BGR565 _ConvertX86p16_16BGR565 +#define ConvertX86p16_16RGB555 _ConvertX86p16_16RGB555 +#define ConvertX86p16_16BGR555 _ConvertX86p16_16BGR555 +#define ConvertX86p16_8RGB332 _ConvertX86p16_8RGB332 - #ifdef __cplusplus - } - #endif +#ifdef __cplusplus +} +#endif -#endif /* ELF & GNU */ +#endif /* ELF & GNU */ @@ -177,10 +179,11 @@ extern int ConvertX86p16_32BGRA888_LUT_X86[512]; #pragma aux ConvertX86p16_32RGBA888_LUT_X86 "_*" #pragma aux ConvertX86p16_32BGRA888_LUT_X86 "_*" -#endif /* __WATCOMC__ */ +#endif /* __WATCOMC__ */ -#endif /* X86_ASSEMBLER */ +#endif /* X86_ASSEMBLER */ -#endif +#endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 5984a3200..a5dc9f6e0 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -40,47 +40,49 @@ Uint8 SDL_numjoysticks = 0; SDL_Joystick **SDL_joysticks = NULL; static SDL_Joystick *default_joystick = NULL; -int SDL_JoystickInit(void) +int +SDL_JoystickInit (void) { - int arraylen; - int status; - - SDL_numjoysticks = 0; - status = SDL_SYS_JoystickInit(); - if ( status >= 0 ) { - arraylen = (status+1)*sizeof(*SDL_joysticks); - SDL_joysticks = (SDL_Joystick **)SDL_malloc(arraylen); - if ( SDL_joysticks == NULL ) { - SDL_numjoysticks = 0; - } else { - SDL_memset(SDL_joysticks, 0, arraylen); - SDL_numjoysticks = status; - } - status = 0; - } - default_joystick = NULL; - return(status); + int arraylen; + int status; + + SDL_numjoysticks = 0; + status = SDL_SYS_JoystickInit (); + if (status >= 0) { + arraylen = (status + 1) * sizeof (*SDL_joysticks); + SDL_joysticks = (SDL_Joystick **) SDL_malloc (arraylen); + if (SDL_joysticks == NULL) { + SDL_numjoysticks = 0; + } else { + SDL_memset (SDL_joysticks, 0, arraylen); + SDL_numjoysticks = status; + } + status = 0; + } + default_joystick = NULL; + return (status); } /* * Count the number of joysticks attached to the system */ -int SDL_NumJoysticks(void) +int +SDL_NumJoysticks (void) { - return SDL_numjoysticks; + return SDL_numjoysticks; } /* * Get the implementation dependent name of a joystick */ -const char *SDL_JoystickName(int device_index) +const char * +SDL_JoystickName (int device_index) { - if ( (device_index < 0) || (device_index >= SDL_numjoysticks) ) { - SDL_SetError("There are %d joysticks available", - SDL_numjoysticks); - return(NULL); - } - return(SDL_SYS_JoystickName(device_index)); + if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { + SDL_SetError ("There are %d joysticks available", SDL_numjoysticks); + return (NULL); + } + return (SDL_SYS_JoystickName (device_index)); } /* @@ -90,484 +92,505 @@ const char *SDL_JoystickName(int device_index) * * This function returns a joystick identifier, or NULL if an error occurred. */ -SDL_Joystick *SDL_JoystickOpen(int device_index) +SDL_Joystick * +SDL_JoystickOpen (int device_index) { - int i; - SDL_Joystick *joystick; - - if ( (device_index < 0) || (device_index >= SDL_numjoysticks) ) { - SDL_SetError("There are %d joysticks available", - SDL_numjoysticks); - return(NULL); - } - - /* If the joystick is already open, return it */ - for ( i=0; SDL_joysticks[i]; ++i ) { - if ( device_index == SDL_joysticks[i]->index ) { - joystick = SDL_joysticks[i]; - ++joystick->ref_count; - return(joystick); - } - } - - /* Create and initialize the joystick */ - joystick = (SDL_Joystick *)SDL_malloc((sizeof *joystick)); - if ( joystick != NULL ) { - SDL_memset(joystick, 0, (sizeof *joystick)); - joystick->index = device_index; - if ( SDL_SYS_JoystickOpen(joystick) < 0 ) { - SDL_free(joystick); - joystick = NULL; - } else { - if ( joystick->naxes > 0 ) { - joystick->axes = (Sint16 *)SDL_malloc - (joystick->naxes*sizeof(Sint16)); - } - if ( joystick->nhats > 0 ) { - joystick->hats = (Uint8 *)SDL_malloc - (joystick->nhats*sizeof(Uint8)); - } - if ( joystick->nballs > 0 ) { - joystick->balls = (struct balldelta *)SDL_malloc - (joystick->nballs*sizeof(*joystick->balls)); - } - if ( joystick->nbuttons > 0 ) { - joystick->buttons = (Uint8 *)SDL_malloc - (joystick->nbuttons*sizeof(Uint8)); - } - if ( ((joystick->naxes > 0) && !joystick->axes) - || ((joystick->nhats > 0) && !joystick->hats) - || ((joystick->nballs > 0) && !joystick->balls) - || ((joystick->nbuttons > 0) && !joystick->buttons)) { - SDL_OutOfMemory(); - SDL_JoystickClose(joystick); - joystick = NULL; - } - if ( joystick->axes ) { - SDL_memset(joystick->axes, 0, - joystick->naxes*sizeof(Sint16)); - } - if ( joystick->hats ) { - SDL_memset(joystick->hats, 0, - joystick->nhats*sizeof(Uint8)); - } - if ( joystick->balls ) { - SDL_memset(joystick->balls, 0, - joystick->nballs*sizeof(*joystick->balls)); - } - if ( joystick->buttons ) { - SDL_memset(joystick->buttons, 0, - joystick->nbuttons*sizeof(Uint8)); - } - } - } - if ( joystick ) { - /* Add joystick to list */ - ++joystick->ref_count; - SDL_Lock_EventThread(); - for ( i=0; SDL_joysticks[i]; ++i ) - /* Skip to next joystick */; - SDL_joysticks[i] = joystick; - SDL_Unlock_EventThread(); - } - return(joystick); + int i; + SDL_Joystick *joystick; + + if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { + SDL_SetError ("There are %d joysticks available", SDL_numjoysticks); + return (NULL); + } + + /* If the joystick is already open, return it */ + for (i = 0; SDL_joysticks[i]; ++i) { + if (device_index == SDL_joysticks[i]->index) { + joystick = SDL_joysticks[i]; + ++joystick->ref_count; + return (joystick); + } + } + + /* Create and initialize the joystick */ + joystick = (SDL_Joystick *) SDL_malloc ((sizeof *joystick)); + if (joystick != NULL) { + SDL_memset (joystick, 0, (sizeof *joystick)); + joystick->index = device_index; + if (SDL_SYS_JoystickOpen (joystick) < 0) { + SDL_free (joystick); + joystick = NULL; + } else { + if (joystick->naxes > 0) { + joystick->axes = (Sint16 *) SDL_malloc + (joystick->naxes * sizeof (Sint16)); + } + if (joystick->nhats > 0) { + joystick->hats = (Uint8 *) SDL_malloc + (joystick->nhats * sizeof (Uint8)); + } + if (joystick->nballs > 0) { + joystick->balls = (struct balldelta *) SDL_malloc + (joystick->nballs * sizeof (*joystick->balls)); + } + if (joystick->nbuttons > 0) { + joystick->buttons = (Uint8 *) SDL_malloc + (joystick->nbuttons * sizeof (Uint8)); + } + if (((joystick->naxes > 0) && !joystick->axes) + || ((joystick->nhats > 0) && !joystick->hats) + || ((joystick->nballs > 0) && !joystick->balls) + || ((joystick->nbuttons > 0) && !joystick->buttons)) { + SDL_OutOfMemory (); + SDL_JoystickClose (joystick); + joystick = NULL; + } + if (joystick->axes) { + SDL_memset (joystick->axes, 0, + joystick->naxes * sizeof (Sint16)); + } + if (joystick->hats) { + SDL_memset (joystick->hats, 0, + joystick->nhats * sizeof (Uint8)); + } + if (joystick->balls) { + SDL_memset (joystick->balls, 0, + joystick->nballs * sizeof (*joystick->balls)); + } + if (joystick->buttons) { + SDL_memset (joystick->buttons, 0, + joystick->nbuttons * sizeof (Uint8)); + } + } + } + if (joystick) { + /* Add joystick to list */ + ++joystick->ref_count; + SDL_Lock_EventThread (); + for (i = 0; SDL_joysticks[i]; ++i) + /* Skip to next joystick */ ; + SDL_joysticks[i] = joystick; + SDL_Unlock_EventThread (); + } + return (joystick); } /* * Returns 1 if the joystick has been opened, or 0 if it has not. */ -int SDL_JoystickOpened(int device_index) +int +SDL_JoystickOpened (int device_index) { - int i, opened; - - opened = 0; - for ( i=0; SDL_joysticks[i]; ++i ) { - if ( SDL_joysticks[i]->index == (Uint8)device_index ) { - opened = 1; - break; - } - } - return(opened); + int i, opened; + + opened = 0; + for (i = 0; SDL_joysticks[i]; ++i) { + if (SDL_joysticks[i]->index == (Uint8) device_index) { + opened = 1; + break; + } + } + return (opened); } -static int ValidJoystick(SDL_Joystick **joystick) +static int +ValidJoystick (SDL_Joystick ** joystick) { - int valid; - - if ( *joystick == NULL ) { - *joystick = default_joystick; - } - if ( *joystick == NULL ) { - SDL_SetError("Joystick hasn't been opened yet"); - valid = 0; - } else { - valid = 1; - } - return valid; + int valid; + + if (*joystick == NULL) { + *joystick = default_joystick; + } + if (*joystick == NULL) { + SDL_SetError ("Joystick hasn't been opened yet"); + valid = 0; + } else { + valid = 1; + } + return valid; } /* * Get the device index of an opened joystick. */ -int SDL_JoystickIndex(SDL_Joystick *joystick) +int +SDL_JoystickIndex (SDL_Joystick * joystick) { - if ( ! ValidJoystick(&joystick) ) { - return(-1); - } - return(joystick->index); + if (!ValidJoystick (&joystick)) { + return (-1); + } + return (joystick->index); } /* * Get the number of multi-dimensional axis controls on a joystick */ -int SDL_JoystickNumAxes(SDL_Joystick *joystick) +int +SDL_JoystickNumAxes (SDL_Joystick * joystick) { - if ( ! ValidJoystick(&joystick) ) { - return(-1); - } - return(joystick->naxes); + if (!ValidJoystick (&joystick)) { + return (-1); + } + return (joystick->naxes); } /* * Get the number of hats on a joystick */ -int SDL_JoystickNumHats(SDL_Joystick *joystick) +int +SDL_JoystickNumHats (SDL_Joystick * joystick) { - if ( ! ValidJoystick(&joystick) ) { - return(-1); - } - return(joystick->nhats); + if (!ValidJoystick (&joystick)) { + return (-1); + } + return (joystick->nhats); } /* * Get the number of trackballs on a joystick */ -int SDL_JoystickNumBalls(SDL_Joystick *joystick) +int +SDL_JoystickNumBalls (SDL_Joystick * joystick) { - if ( ! ValidJoystick(&joystick) ) { - return(-1); - } - return(joystick->nballs); + if (!ValidJoystick (&joystick)) { + return (-1); + } + return (joystick->nballs); } /* * Get the number of buttons on a joystick */ -int SDL_JoystickNumButtons(SDL_Joystick *joystick) +int +SDL_JoystickNumButtons (SDL_Joystick * joystick) { - if ( ! ValidJoystick(&joystick) ) { - return(-1); - } - return(joystick->nbuttons); + if (!ValidJoystick (&joystick)) { + return (-1); + } + return (joystick->nbuttons); } /* * Get the current state of an axis control on a joystick */ -Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis) +Sint16 +SDL_JoystickGetAxis (SDL_Joystick * joystick, int axis) { - Sint16 state; - - if ( ! ValidJoystick(&joystick) ) { - return(0); - } - if ( axis < joystick->naxes ) { - state = joystick->axes[axis]; - } else { - SDL_SetError("Joystick only has %d axes", joystick->naxes); - state = 0; - } - return(state); + Sint16 state; + + if (!ValidJoystick (&joystick)) { + return (0); + } + if (axis < joystick->naxes) { + state = joystick->axes[axis]; + } else { + SDL_SetError ("Joystick only has %d axes", joystick->naxes); + state = 0; + } + return (state); } /* * Get the current state of a hat on a joystick */ -Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat) +Uint8 +SDL_JoystickGetHat (SDL_Joystick * joystick, int hat) { - Uint8 state; - - if ( ! ValidJoystick(&joystick) ) { - return(0); - } - if ( hat < joystick->nhats ) { - state = joystick->hats[hat]; - } else { - SDL_SetError("Joystick only has %d hats", joystick->nhats); - state = 0; - } - return(state); + Uint8 state; + + if (!ValidJoystick (&joystick)) { + return (0); + } + if (hat < joystick->nhats) { + state = joystick->hats[hat]; + } else { + SDL_SetError ("Joystick only has %d hats", joystick->nhats); + state = 0; + } + return (state); } /* * Get the ball axis change since the last poll */ -int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy) +int +SDL_JoystickGetBall (SDL_Joystick * joystick, int ball, int *dx, int *dy) { - int retval; - - if ( ! ValidJoystick(&joystick) ) { - return(-1); - } - - retval = 0; - if ( ball < joystick->nballs ) { - if ( dx ) { - *dx = joystick->balls[ball].dx; - } - if ( dy ) { - *dy = joystick->balls[ball].dy; - } - joystick->balls[ball].dx = 0; - joystick->balls[ball].dy = 0; - } else { - SDL_SetError("Joystick only has %d balls", joystick->nballs); - retval = -1; - } - return(retval); + int retval; + + if (!ValidJoystick (&joystick)) { + return (-1); + } + + retval = 0; + if (ball < joystick->nballs) { + if (dx) { + *dx = joystick->balls[ball].dx; + } + if (dy) { + *dy = joystick->balls[ball].dy; + } + joystick->balls[ball].dx = 0; + joystick->balls[ball].dy = 0; + } else { + SDL_SetError ("Joystick only has %d balls", joystick->nballs); + retval = -1; + } + return (retval); } /* * Get the current state of a button on a joystick */ -Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button) +Uint8 +SDL_JoystickGetButton (SDL_Joystick * joystick, int button) { - Uint8 state; - - if ( ! ValidJoystick(&joystick) ) { - return(0); - } - if ( button < joystick->nbuttons ) { - state = joystick->buttons[button]; - } else { - SDL_SetError("Joystick only has %d buttons",joystick->nbuttons); - state = 0; - } - return(state); + Uint8 state; + + if (!ValidJoystick (&joystick)) { + return (0); + } + if (button < joystick->nbuttons) { + state = joystick->buttons[button]; + } else { + SDL_SetError ("Joystick only has %d buttons", joystick->nbuttons); + state = 0; + } + return (state); } /* * Close a joystick previously opened with SDL_JoystickOpen() */ -void SDL_JoystickClose(SDL_Joystick *joystick) +void +SDL_JoystickClose (SDL_Joystick * joystick) { - int i; - - if ( ! ValidJoystick(&joystick) ) { - return; - } - - /* First decrement ref count */ - if ( --joystick->ref_count > 0 ) { - return; - } - - /* Lock the event queue - prevent joystick polling */ - SDL_Lock_EventThread(); - - if ( joystick == default_joystick ) { - default_joystick = NULL; - } - SDL_SYS_JoystickClose(joystick); - - /* Remove joystick from list */ - for ( i=0; SDL_joysticks[i]; ++i ) { - if ( joystick == SDL_joysticks[i] ) { - SDL_memcpy(&SDL_joysticks[i], &SDL_joysticks[i+1], - (SDL_numjoysticks-i)*sizeof(joystick)); - break; - } - } - - /* Let the event thread keep running */ - SDL_Unlock_EventThread(); - - /* Free the data associated with this joystick */ - if ( joystick->axes ) { - SDL_free(joystick->axes); - } - if ( joystick->hats ) { - SDL_free(joystick->hats); - } - if ( joystick->balls ) { - SDL_free(joystick->balls); - } - if ( joystick->buttons ) { - SDL_free(joystick->buttons); - } - SDL_free(joystick); + int i; + + if (!ValidJoystick (&joystick)) { + return; + } + + /* First decrement ref count */ + if (--joystick->ref_count > 0) { + return; + } + + /* Lock the event queue - prevent joystick polling */ + SDL_Lock_EventThread (); + + if (joystick == default_joystick) { + default_joystick = NULL; + } + SDL_SYS_JoystickClose (joystick); + + /* Remove joystick from list */ + for (i = 0; SDL_joysticks[i]; ++i) { + if (joystick == SDL_joysticks[i]) { + SDL_memcpy (&SDL_joysticks[i], &SDL_joysticks[i + 1], + (SDL_numjoysticks - i) * sizeof (joystick)); + break; + } + } + + /* Let the event thread keep running */ + SDL_Unlock_EventThread (); + + /* Free the data associated with this joystick */ + if (joystick->axes) { + SDL_free (joystick->axes); + } + if (joystick->hats) { + SDL_free (joystick->hats); + } + if (joystick->balls) { + SDL_free (joystick->balls); + } + if (joystick->buttons) { + SDL_free (joystick->buttons); + } + SDL_free (joystick); } -void SDL_JoystickQuit(void) +void +SDL_JoystickQuit (void) { - /* Stop the event polling */ - SDL_Lock_EventThread(); - SDL_numjoysticks = 0; - SDL_Unlock_EventThread(); - - /* Quit the joystick setup */ - SDL_SYS_JoystickQuit(); - if ( SDL_joysticks ) { - SDL_free(SDL_joysticks); - SDL_joysticks = NULL; - } + /* Stop the event polling */ + SDL_Lock_EventThread (); + SDL_numjoysticks = 0; + SDL_Unlock_EventThread (); + + /* Quit the joystick setup */ + SDL_SYS_JoystickQuit (); + if (SDL_joysticks) { + SDL_free (SDL_joysticks); + SDL_joysticks = NULL; + } } /* These are global for SDL_sysjoystick.c and SDL_events.c */ -int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value) +int +SDL_PrivateJoystickAxis (SDL_Joystick * joystick, Uint8 axis, Sint16 value) { - int posted; + int posted; - /* Update internal joystick state */ - joystick->axes[axis] = value; + /* Update internal joystick state */ + joystick->axes[axis] = value; - /* Post the event, if desired */ - posted = 0; + /* Post the event, if desired */ + posted = 0; #if !SDL_EVENTS_DISABLED - if ( SDL_ProcessEvents[SDL_JOYAXISMOTION] == SDL_ENABLE ) { - SDL_Event event; - event.type = SDL_JOYAXISMOTION; - event.jaxis.which = joystick->index; - event.jaxis.axis = axis; - event.jaxis.value = value; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } + if (SDL_ProcessEvents[SDL_JOYAXISMOTION] == SDL_ENABLE) { + SDL_Event event; + event.type = SDL_JOYAXISMOTION; + event.jaxis.which = joystick->index; + event.jaxis.axis = axis; + event.jaxis.value = value; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } #endif /* !SDL_EVENTS_DISABLED */ - return(posted); + return (posted); } -int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value) +int +SDL_PrivateJoystickHat (SDL_Joystick * joystick, Uint8 hat, Uint8 value) { - int posted; + int posted; - /* Update internal joystick state */ - joystick->hats[hat] = value; + /* Update internal joystick state */ + joystick->hats[hat] = value; - /* Post the event, if desired */ - posted = 0; + /* Post the event, if desired */ + posted = 0; #if !SDL_EVENTS_DISABLED - if ( SDL_ProcessEvents[SDL_JOYHATMOTION] == SDL_ENABLE ) { - SDL_Event event; - event.jhat.type = SDL_JOYHATMOTION; - event.jhat.which = joystick->index; - event.jhat.hat = hat; - event.jhat.value = value; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } + if (SDL_ProcessEvents[SDL_JOYHATMOTION] == SDL_ENABLE) { + SDL_Event event; + event.jhat.type = SDL_JOYHATMOTION; + event.jhat.which = joystick->index; + event.jhat.hat = hat; + event.jhat.value = value; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } #endif /* !SDL_EVENTS_DISABLED */ - return(posted); + return (posted); } -int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball, - Sint16 xrel, Sint16 yrel) +int +SDL_PrivateJoystickBall (SDL_Joystick * joystick, Uint8 ball, + Sint16 xrel, Sint16 yrel) { - int posted; + int posted; - /* Update internal mouse state */ - joystick->balls[ball].dx += xrel; - joystick->balls[ball].dy += yrel; + /* Update internal mouse state */ + joystick->balls[ball].dx += xrel; + joystick->balls[ball].dy += yrel; - /* Post the event, if desired */ - posted = 0; + /* Post the event, if desired */ + posted = 0; #if !SDL_EVENTS_DISABLED - if ( SDL_ProcessEvents[SDL_JOYBALLMOTION] == SDL_ENABLE ) { - SDL_Event event; - event.jball.type = SDL_JOYBALLMOTION; - event.jball.which = joystick->index; - event.jball.ball = ball; - event.jball.xrel = xrel; - event.jball.yrel = yrel; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } + if (SDL_ProcessEvents[SDL_JOYBALLMOTION] == SDL_ENABLE) { + SDL_Event event; + event.jball.type = SDL_JOYBALLMOTION; + event.jball.which = joystick->index; + event.jball.ball = ball; + event.jball.xrel = xrel; + event.jball.yrel = yrel; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } #endif /* !SDL_EVENTS_DISABLED */ - return(posted); + return (posted); } -int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state) +int +SDL_PrivateJoystickButton (SDL_Joystick * joystick, Uint8 button, Uint8 state) { - int posted; + int posted; #if !SDL_EVENTS_DISABLED - SDL_Event event; - - switch ( state ) { - case SDL_PRESSED: - event.type = SDL_JOYBUTTONDOWN; - break; - case SDL_RELEASED: - event.type = SDL_JOYBUTTONUP; - break; - default: - /* Invalid state -- bail */ - return(0); - } + SDL_Event event; + + switch (state) { + case SDL_PRESSED: + event.type = SDL_JOYBUTTONDOWN; + break; + case SDL_RELEASED: + event.type = SDL_JOYBUTTONUP; + break; + default: + /* Invalid state -- bail */ + return (0); + } #endif /* !SDL_EVENTS_DISABLED */ - /* Update internal joystick state */ - joystick->buttons[button] = state; + /* Update internal joystick state */ + joystick->buttons[button] = state; - /* Post the event, if desired */ - posted = 0; + /* Post the event, if desired */ + posted = 0; #if !SDL_EVENTS_DISABLED - if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { - event.jbutton.which = joystick->index; - event.jbutton.button = button; - event.jbutton.state = state; - if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { - posted = 1; - SDL_PushEvent(&event); - } - } + if (SDL_ProcessEvents[event.type] == SDL_ENABLE) { + event.jbutton.which = joystick->index; + event.jbutton.button = button; + event.jbutton.state = state; + if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { + posted = 1; + SDL_PushEvent (&event); + } + } #endif /* !SDL_EVENTS_DISABLED */ - return(posted); + return (posted); } -void SDL_JoystickUpdate(void) +void +SDL_JoystickUpdate (void) { - int i; + int i; - for ( i=0; SDL_joysticks[i]; ++i ) { - SDL_SYS_JoystickUpdate(SDL_joysticks[i]); - } + for (i = 0; SDL_joysticks[i]; ++i) { + SDL_SYS_JoystickUpdate (SDL_joysticks[i]); + } } -int SDL_JoystickEventState(int state) +int +SDL_JoystickEventState (int state) { #if SDL_EVENTS_DISABLED - return SDL_IGNORE; + return SDL_IGNORE; #else - const Uint8 event_list[] = { - SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, - SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, - }; - unsigned int i; - - switch (state) { - case SDL_QUERY: - state = SDL_IGNORE; - for ( i=0; iindex)); + ULONG temp, i; + D (bug ("Opening joystick %ld\n", joystick->index)); - if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) - return -1; + if (!(joystick->hwdata = SDL_malloc (sizeof (struct joystick_hwdata)))) + return -1; /* This loop is to check if the controller is a joypad */ - for(i=0;i<20;i++) - { - temp=ReadJoyPort(joystick->index^1); // fix to invert amiga joyports - WaitTOF(); - } + for (i = 0; i < 20; i++) { + temp = ReadJoyPort (joystick->index ^ 1); // fix to invert amiga joyports + WaitTOF (); + } - if((temp&JP_TYPE_MASK)==JP_TYPE_GAMECTLR) - joystick->nbuttons=7; - else - joystick->nbuttons=3; + if ((temp & JP_TYPE_MASK) == JP_TYPE_GAMECTLR) + joystick->nbuttons = 7; + else + joystick->nbuttons = 3; - joystick->nhats=0; - joystick->nballs=0; - joystick->naxes=2; - joystick->hwdata->joystate=0L; + joystick->nhats = 0; + joystick->nballs = 0; + joystick->naxes = 2; + joystick->hwdata->joystate = 0L; - return 0; + return 0; } /* Function to update the state of a joystick - called as a device poll. @@ -143,91 +140,80 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - ULONG data; - int i; - - if(joystick->index<2) - { - data=ReadJoyPort(joystick->index); - - if(data&JP_DIRECTION_MASK) - { - if(data&JPF_JOY_DOWN) - { - if(!(joystick->hwdata->joystate&JPF_JOY_DOWN)) - SDL_PrivateJoystickAxis(joystick,0,127); - } - else if(data&JPF_JOY_UP) - { - if(!(joystick->hwdata->joystate&JPF_JOY_UP)) - SDL_PrivateJoystickAxis(joystick,0,-127); - } - else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN)) - SDL_PrivateJoystickAxis(joystick,0,0); - - if(data&JPF_JOY_LEFT) - { - if(!(joystick->hwdata->joystate&JPF_JOY_LEFT)) - SDL_PrivateJoystickAxis(joystick,1,-127); - } - else if(data&JPF_JOY_RIGHT) - { - if(!(joystick->hwdata->joystate&JPF_JOY_RIGHT)) - SDL_PrivateJoystickAxis(joystick,1,127); - } - else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT)) - SDL_PrivateJoystickAxis(joystick,1,0); - } - else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT)) - { - SDL_PrivateJoystickAxis(joystick,1,0); - } - else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN)) - { - SDL_PrivateJoystickAxis(joystick,0,0); - } - - for(i=0;inbuttons;i++) - { - if( (data&joybut[i]) ) - { - if(i==1) - data&=(~(joybut[2])); - - if(!(joystick->hwdata->joystate&joybut[i])) - SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); - } - else if(joystick->hwdata->joystate&joybut[i]) - SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); - } - - joystick->hwdata->joystate=data; - } - - return; + ULONG data; + int i; + + if (joystick->index < 2) { + data = ReadJoyPort (joystick->index); + + if (data & JP_DIRECTION_MASK) { + if (data & JPF_JOY_DOWN) { + if (!(joystick->hwdata->joystate & JPF_JOY_DOWN)) + SDL_PrivateJoystickAxis (joystick, 0, 127); + } else if (data & JPF_JOY_UP) { + if (!(joystick->hwdata->joystate & JPF_JOY_UP)) + SDL_PrivateJoystickAxis (joystick, 0, -127); + } else if (joystick->hwdata-> + joystate & (JPF_JOY_UP | JPF_JOY_DOWN)) + SDL_PrivateJoystickAxis (joystick, 0, 0); + + if (data & JPF_JOY_LEFT) { + if (!(joystick->hwdata->joystate & JPF_JOY_LEFT)) + SDL_PrivateJoystickAxis (joystick, 1, -127); + } else if (data & JPF_JOY_RIGHT) { + if (!(joystick->hwdata->joystate & JPF_JOY_RIGHT)) + SDL_PrivateJoystickAxis (joystick, 1, 127); + } else if (joystick->hwdata-> + joystate & (JPF_JOY_LEFT | JPF_JOY_RIGHT)) + SDL_PrivateJoystickAxis (joystick, 1, 0); + } else if (joystick->hwdata-> + joystate & (JPF_JOY_LEFT | JPF_JOY_RIGHT)) { + SDL_PrivateJoystickAxis (joystick, 1, 0); + } else if (joystick->hwdata->joystate & (JPF_JOY_UP | JPF_JOY_DOWN)) { + SDL_PrivateJoystickAxis (joystick, 0, 0); + } + + for (i = 0; i < joystick->nbuttons; i++) { + if ((data & joybut[i])) { + if (i == 1) + data &= (~(joybut[2])); + + if (!(joystick->hwdata->joystate & joybut[i])) + SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); + } else if (joystick->hwdata->joystate & joybut[i]) + SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); + } + + joystick->hwdata->joystate = data; + } + + return; } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - if(joystick->hwdata) - SDL_free(joystick->hwdata); - return; + if (joystick->hwdata) + SDL_free (joystick->hwdata); + return; } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - if(LowLevelBase) - { - CloseLibrary(LowLevelBase); - LowLevelBase=NULL; - SDL_numjoysticks=0; - } - return; + if (LowLevelBase) { + CloseLibrary (LowLevelBase); + LowLevelBase = NULL; + SDL_numjoysticks = 0; + } + return; } #endif /* SDL_JOYSTICK_AMIGA */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/beos/SDL_bejoystick.cc b/src/joystick/beos/SDL_bejoystick.cc index 7c52b8664..a93fa9878 100644 --- a/src/joystick/beos/SDL_bejoystick.cc +++ b/src/joystick/beos/SDL_bejoystick.cc @@ -28,7 +28,8 @@ #include #include -extern "C" { +extern "C" +{ #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" @@ -36,202 +37,205 @@ extern "C" { /* The maximum number of joysticks we'll detect */ -#define MAX_JOYSTICKS 16 +#define MAX_JOYSTICKS 16 /* A list of available joysticks */ -static char *SDL_joyport[MAX_JOYSTICKS]; -static char *SDL_joyname[MAX_JOYSTICKS]; + static char *SDL_joyport[MAX_JOYSTICKS]; + static char *SDL_joyname[MAX_JOYSTICKS]; /* The private structure used to keep track of a joystick */ -struct joystick_hwdata { - BJoystick *stick; - uint8 *new_hats; - int16 *new_axes; -}; + struct joystick_hwdata + { + BJoystick *stick; + uint8 *new_hats; + int16 *new_axes; + }; /* Function to scan the system for joysticks. * This function should set SDL_numjoysticks to the number of available * joysticks. Joystick 0 should be the system default joystick. * It should return 0, or -1 on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) -{ - BJoystick joystick; - int numjoysticks; - int i; - int32 nports; - char name[B_OS_NAME_LENGTH]; - - /* Search for attached joysticks */ - nports = joystick.CountDevices(); - numjoysticks = 0; - SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport)); - SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname)); - for ( i=0; (SDL_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i ) { - if ( joystick.GetDeviceName(i, name) == B_OK ) { - if ( joystick.Open(name) != B_ERROR ) { - BString stick_name; - joystick.GetControllerName(&stick_name); - SDL_joyport[numjoysticks] = strdup(name); - SDL_joyname[numjoysticks] = - strdup(stick_name.String()); - numjoysticks++; - joystick.Close(); - } - } - } - return(numjoysticks); -} + int SDL_SYS_JoystickInit (void) + { + BJoystick joystick; + int numjoysticks; + int i; + int32 nports; + char name[B_OS_NAME_LENGTH]; + + /* Search for attached joysticks */ + nports = joystick.CountDevices (); + numjoysticks = 0; + SDL_memset (SDL_joyport, 0, (sizeof SDL_joyport)); + SDL_memset (SDL_joyname, 0, (sizeof SDL_joyname)); + for (i = 0; (SDL_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i) + { + if (joystick.GetDeviceName (i, name) == B_OK) { + if (joystick.Open (name) != B_ERROR) { + BString stick_name; + joystick.GetControllerName (&stick_name); + SDL_joyport[numjoysticks] = strdup (name); + SDL_joyname[numjoysticks] = + strdup (stick_name.String ()); + numjoysticks++; + joystick.Close (); + } + } + } + return (numjoysticks); + } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) -{ - return SDL_joyname[index]; -} + const char *SDL_SYS_JoystickName (int index) + { + return SDL_joyname[index]; + } /* Function to open a joystick for use. The joystick to open is specified by the index field of the joystick. This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - BJoystick *stick; - - /* Create the joystick data structure */ - joystick->hwdata = (struct joystick_hwdata *) - SDL_malloc(sizeof(*joystick->hwdata)); - if ( joystick->hwdata == NULL ) { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - stick = new BJoystick; - joystick->hwdata->stick = stick; - - /* Open the requested joystick for use */ - if ( stick->Open(SDL_joyport[joystick->index]) == B_ERROR ) { - SDL_SetError("Unable to open joystick"); - SDL_SYS_JoystickClose(joystick); - return(-1); - } - - /* Set the joystick to calibrated mode */ - stick->EnableCalibration(); - - /* Get the number of buttons, hats, and axes on the joystick */ - joystick->nbuttons = stick->CountButtons(); - joystick->naxes = stick->CountAxes(); - joystick->nhats = stick->CountHats(); - - joystick->hwdata->new_axes = (int16 *) - SDL_malloc(joystick->naxes*sizeof(int16)); - joystick->hwdata->new_hats = (uint8 *) - SDL_malloc(joystick->nhats*sizeof(uint8)); - if ( ! joystick->hwdata->new_hats || ! joystick->hwdata->new_axes ) { - SDL_OutOfMemory(); - SDL_SYS_JoystickClose(joystick); - return(-1); - } - - /* We're done! */ - return(0); -} + int SDL_SYS_JoystickOpen (SDL_Joystick * joystick) + { + BJoystick *stick; + + /* Create the joystick data structure */ + joystick->hwdata = (struct joystick_hwdata *) + SDL_malloc (sizeof (*joystick->hwdata)); + if (joystick->hwdata == NULL) { + SDL_OutOfMemory (); + return (-1); + } + SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); + stick = new BJoystick; + joystick->hwdata->stick = stick; + + /* Open the requested joystick for use */ + if (stick->Open (SDL_joyport[joystick->index]) == B_ERROR) { + SDL_SetError ("Unable to open joystick"); + SDL_SYS_JoystickClose (joystick); + return (-1); + } + + /* Set the joystick to calibrated mode */ + stick->EnableCalibration (); + + /* Get the number of buttons, hats, and axes on the joystick */ + joystick->nbuttons = stick->CountButtons (); + joystick->naxes = stick->CountAxes (); + joystick->nhats = stick->CountHats (); + + joystick->hwdata->new_axes = (int16 *) + SDL_malloc (joystick->naxes * sizeof (int16)); + joystick->hwdata->new_hats = (uint8 *) + SDL_malloc (joystick->nhats * sizeof (uint8)); + if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) { + SDL_OutOfMemory (); + SDL_SYS_JoystickClose (joystick); + return (-1); + } + + /* We're done! */ + return (0); + } /* Function to update the state of a joystick - called as a device poll. * This function shouldn't update the joystick structure directly, * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - static const Uint8 hat_map[9] = { - SDL_HAT_CENTERED, - SDL_HAT_UP, - SDL_HAT_RIGHTUP, - SDL_HAT_RIGHT, - SDL_HAT_RIGHTDOWN, - SDL_HAT_DOWN, - SDL_HAT_LEFTDOWN, - SDL_HAT_LEFT, - SDL_HAT_LEFTUP - }; - const int JITTER = (32768/10); /* 10% jitter threshold (ok?) */ - - BJoystick *stick; - int i, change; - int16 *axes; - uint8 *hats; - uint32 buttons; - - /* Set up data pointers */ - stick = joystick->hwdata->stick; - axes = joystick->hwdata->new_axes; - hats = joystick->hwdata->new_hats; - - /* Get the new joystick state */ - stick->Update(); - stick->GetAxisValues(axes); - stick->GetHatValues(hats); - buttons = stick->ButtonValues(); - - /* Generate axis motion events */ - for ( i=0; inaxes; ++i ) { - change = ((int32)axes[i] - joystick->axes[i]); - if ( (change > JITTER) || (change < -JITTER) ) { - SDL_PrivateJoystickAxis(joystick, i, axes[i]); - } - } - - /* Generate hat change events */ - for ( i=0; inhats; ++i ) { - if ( hats[i] != joystick->hats[i] ) { - SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]); - } - } - - /* Generate button events */ - for ( i=0; inbuttons; ++i ) { - if ( (buttons&0x01) != joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, i, (buttons&0x01)); - } - buttons >>= 1; - } -} + void SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) + { + static const Uint8 hat_map[9] = { + SDL_HAT_CENTERED, + SDL_HAT_UP, + SDL_HAT_RIGHTUP, + SDL_HAT_RIGHT, + SDL_HAT_RIGHTDOWN, + SDL_HAT_DOWN, + SDL_HAT_LEFTDOWN, + SDL_HAT_LEFT, + SDL_HAT_LEFTUP + }; + const int JITTER = (32768 / 10); /* 10% jitter threshold (ok?) */ + + BJoystick *stick; + int i, change; + int16 *axes; + uint8 *hats; + uint32 buttons; + + /* Set up data pointers */ + stick = joystick->hwdata->stick; + axes = joystick->hwdata->new_axes; + hats = joystick->hwdata->new_hats; + + /* Get the new joystick state */ + stick->Update (); + stick->GetAxisValues (axes); + stick->GetHatValues (hats); + buttons = stick->ButtonValues (); + + /* Generate axis motion events */ + for (i = 0; i < joystick->naxes; ++i) { + change = ((int32) axes[i] - joystick->axes[i]); + if ((change > JITTER) || (change < -JITTER)) { + SDL_PrivateJoystickAxis (joystick, i, axes[i]); + } + } + + /* Generate hat change events */ + for (i = 0; i < joystick->nhats; ++i) { + if (hats[i] != joystick->hats[i]) { + SDL_PrivateJoystickHat (joystick, i, hat_map[hats[i]]); + } + } + + /* Generate button events */ + for (i = 0; i < joystick->nbuttons; ++i) { + if ((buttons & 0x01) != joystick->buttons[i]) { + SDL_PrivateJoystickButton (joystick, i, (buttons & 0x01)); + } + buttons >>= 1; + } + } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - if ( joystick->hwdata ) { - joystick->hwdata->stick->Close(); - delete joystick->hwdata->stick; - if ( joystick->hwdata->new_hats ) { - SDL_free(joystick->hwdata->new_hats); - } - if ( joystick->hwdata->new_axes ) { - SDL_free(joystick->hwdata->new_axes); - } - SDL_free(joystick->hwdata); - joystick->hwdata = NULL; - } -} + void SDL_SYS_JoystickClose (SDL_Joystick * joystick) + { + if (joystick->hwdata) { + joystick->hwdata->stick->Close (); + delete joystick->hwdata->stick; + if (joystick->hwdata->new_hats) { + SDL_free (joystick->hwdata->new_hats); + } + if (joystick->hwdata->new_axes) { + SDL_free (joystick->hwdata->new_axes); + } + SDL_free (joystick->hwdata); + joystick->hwdata = NULL; + } + } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - int i; + void SDL_SYS_JoystickQuit (void) + { + int i; - for ( i=0; SDL_joyport[i]; ++i ) { - SDL_free(SDL_joyport[i]); - } - SDL_joyport[0] = NULL; + for (i = 0; SDL_joyport[i]; ++i) { + SDL_free (SDL_joyport[i]); + } + SDL_joyport[0] = NULL; - for ( i=0; SDL_joyname[i]; ++i ) { - SDL_free(SDL_joyname[i]); - } - SDL_joyname[0] = NULL; -} + for (i = 0; SDL_joyname[i]; ++i) { + SDL_free (SDL_joyname[i]); + } + SDL_joyname[0] = NULL; + } -}; // extern "C" +}; // extern "C" #endif /* SDL_JOYSTICK_BEOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c index 0c7043aca..18a166e32 100644 --- a/src/joystick/bsd/SDL_sysjoystick.c +++ b/src/joystick/bsd/SDL_sysjoystick.c @@ -74,62 +74,69 @@ #define MAX_JOY_JOYS 2 #define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS) -struct report { - struct usb_ctl_report *buf; /* Buffer */ - size_t size; /* Buffer size */ - int rid; /* Report ID */ - enum { - SREPORT_UNINIT, - SREPORT_CLEAN, - SREPORT_DIRTY - } status; +struct report +{ + struct usb_ctl_report *buf; /* Buffer */ + size_t size; /* Buffer size */ + int rid; /* Report ID */ + enum + { + SREPORT_UNINIT, + SREPORT_CLEAN, + SREPORT_DIRTY + } status; }; -static struct { - int uhid_report; - hid_kind_t kind; - const char *name; +static struct +{ + int uhid_report; + hid_kind_t kind; + const char *name; } const repinfo[] = { - { UHID_INPUT_REPORT, hid_input, "input" }, - { UHID_OUTPUT_REPORT, hid_output, "output" }, - { UHID_FEATURE_REPORT, hid_feature, "feature" } + {UHID_INPUT_REPORT, hid_input, "input"}, + {UHID_OUTPUT_REPORT, hid_output, "output"}, + {UHID_FEATURE_REPORT, hid_feature, "feature"} }; -enum { - REPORT_INPUT = 0, - REPORT_OUTPUT = 1, - REPORT_FEATURE = 2 +enum +{ + REPORT_INPUT = 0, + REPORT_OUTPUT = 1, + REPORT_FEATURE = 2 }; -enum { - JOYAXE_X, - JOYAXE_Y, - JOYAXE_Z, - JOYAXE_SLIDER, - JOYAXE_WHEEL, - JOYAXE_RX, - JOYAXE_RY, - JOYAXE_RZ, - JOYAXE_count +enum +{ + JOYAXE_X, + JOYAXE_Y, + JOYAXE_Z, + JOYAXE_SLIDER, + JOYAXE_WHEEL, + JOYAXE_RX, + JOYAXE_RY, + JOYAXE_RZ, + JOYAXE_count }; -struct joystick_hwdata { - int fd; - char *path; - enum { - BSDJOY_UHID, /* uhid(4) */ - BSDJOY_JOY /* joy(4) */ - } type; - struct report_desc *repdesc; - struct report inreport; - int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,..*/ +struct joystick_hwdata +{ + int fd; + char *path; + enum + { + BSDJOY_UHID, /* uhid(4) */ + BSDJOY_JOY /* joy(4) */ + } type; + struct report_desc *repdesc; + struct report inreport; + int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,.. */ }; static char *joynames[MAX_JOYS]; static char *joydevnames[MAX_JOYS]; -static int report_alloc(struct report *, struct report_desc *, int); -static void report_free(struct report *); +static int report_alloc (struct report *, struct report_desc *, int); +static void report_free (struct report *); #ifdef USBHID_UCR_DATA #define REP_BUF_DATA(rep) ((rep)->buf->ucr_data) @@ -138,443 +145,456 @@ static void report_free(struct report *); #endif int -SDL_SYS_JoystickInit(void) +SDL_SYS_JoystickInit (void) { - char s[16]; - int i, fd; - - SDL_numjoysticks = 0; - - SDL_memset(joynames, 0, sizeof(joynames)); - SDL_memset(joydevnames, 0, sizeof(joydevnames)); - - for (i = 0; i < MAX_UHID_JOYS; i++) { - SDL_Joystick nj; - - SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i); - - nj.index = SDL_numjoysticks; - joynames[nj.index] = strdup(s); - - if (SDL_SYS_JoystickOpen(&nj) == 0) { - SDL_SYS_JoystickClose(&nj); - SDL_numjoysticks++; - } else { - SDL_free(joynames[nj.index]); - joynames[nj.index] = NULL; - } - } - for (i = 0; i < MAX_JOY_JOYS; i++) { - SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i); - fd = open(s, O_RDONLY); - if (fd != -1) { - joynames[SDL_numjoysticks++] = strdup(s); - close(fd); - } - } - - /* Read the default USB HID usage table. */ - hid_init(NULL); - - return (SDL_numjoysticks); + char s[16]; + int i, fd; + + SDL_numjoysticks = 0; + + SDL_memset (joynames, 0, sizeof (joynames)); + SDL_memset (joydevnames, 0, sizeof (joydevnames)); + + for (i = 0; i < MAX_UHID_JOYS; i++) { + SDL_Joystick nj; + + SDL_snprintf (s, SDL_arraysize (s), "/dev/uhid%d", i); + + nj.index = SDL_numjoysticks; + joynames[nj.index] = strdup (s); + + if (SDL_SYS_JoystickOpen (&nj) == 0) { + SDL_SYS_JoystickClose (&nj); + SDL_numjoysticks++; + } else { + SDL_free (joynames[nj.index]); + joynames[nj.index] = NULL; + } + } + for (i = 0; i < MAX_JOY_JOYS; i++) { + SDL_snprintf (s, SDL_arraysize (s), "/dev/joy%d", i); + fd = open (s, O_RDONLY); + if (fd != -1) { + joynames[SDL_numjoysticks++] = strdup (s); + close (fd); + } + } + + /* Read the default USB HID usage table. */ + hid_init (NULL); + + return (SDL_numjoysticks); } const char * -SDL_SYS_JoystickName(int index) +SDL_SYS_JoystickName (int index) { - if (joydevnames[index] != NULL) { - return (joydevnames[index]); - } - return (joynames[index]); + if (joydevnames[index] != NULL) { + return (joydevnames[index]); + } + return (joynames[index]); } static int -usage_to_joyaxe(unsigned usage) +usage_to_joyaxe (unsigned usage) { int joyaxe; switch (usage) { case HUG_X: - joyaxe = JOYAXE_X; break; + joyaxe = JOYAXE_X; + break; case HUG_Y: - joyaxe = JOYAXE_Y; break; + joyaxe = JOYAXE_Y; + break; case HUG_Z: - joyaxe = JOYAXE_Z; break; + joyaxe = JOYAXE_Z; + break; case HUG_SLIDER: - joyaxe = JOYAXE_SLIDER; break; + joyaxe = JOYAXE_SLIDER; + break; case HUG_WHEEL: - joyaxe = JOYAXE_WHEEL; break; + joyaxe = JOYAXE_WHEEL; + break; case HUG_RX: - joyaxe = JOYAXE_RX; break; + joyaxe = JOYAXE_RX; + break; case HUG_RY: - joyaxe = JOYAXE_RY; break; + joyaxe = JOYAXE_RY; + break; case HUG_RZ: - joyaxe = JOYAXE_RZ; break; + joyaxe = JOYAXE_RZ; + break; default: - joyaxe = -1; + joyaxe = -1; } - return joyaxe; + return joyaxe; } static unsigned -hatval_to_sdl(Sint32 hatval) +hatval_to_sdl (Sint32 hatval) { static const unsigned hat_dir_map[8] = { - SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN, - SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP + SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN, + SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP }; unsigned result; - if ((hatval & 7) == hatval) - result = hat_dir_map[hatval]; - else - result = SDL_HAT_CENTERED; + if ((hatval & 7) == hatval) + result = hat_dir_map[hatval]; + else + result = SDL_HAT_CENTERED; return result; } int -SDL_SYS_JoystickOpen(SDL_Joystick *joy) +SDL_SYS_JoystickOpen (SDL_Joystick * joy) { - char *path = joynames[joy->index]; - struct joystick_hwdata *hw; - struct hid_item hitem; - struct hid_data *hdata; - struct report *rep; - int fd; - int i; - - fd = open(path, O_RDONLY); - if (fd == -1) { - SDL_SetError("%s: %s", path, strerror(errno)); - return (-1); - } - - hw = (struct joystick_hwdata *)SDL_malloc(sizeof(struct joystick_hwdata)); - if (hw == NULL) { - SDL_OutOfMemory(); - close(fd); - return (-1); - } - joy->hwdata = hw; - hw->fd = fd; - hw->path = strdup(path); - if (! SDL_strncmp(path, "/dev/joy", 8)) { - hw->type = BSDJOY_JOY; - joy->naxes = 2; - joy->nbuttons = 2; - joy->nhats = 0; - joy->nballs = 0; - joydevnames[joy->index] = strdup("Gameport joystick"); - goto usbend; - } else { - hw->type = BSDJOY_UHID; - } - - { - int ax; - for (ax = 0; ax < JOYAXE_count; ax++) - hw->axis_map[ax] = -1; - } - hw->repdesc = hid_get_report_desc(fd); - if (hw->repdesc == NULL) { - SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path, - strerror(errno)); - goto usberr; - } - - rep = &hw->inreport; - if (ioctl(fd, USB_GET_REPORT_ID, &rep->rid) < 0) { - rep->rid = -1; /* XXX */ - } - if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) { - goto usberr; - } - if (rep->size <= 0) { - SDL_SetError("%s: Input report descriptor has invalid length", - hw->path); - goto usberr; - } + char *path = joynames[joy->index]; + struct joystick_hwdata *hw; + struct hid_item hitem; + struct hid_data *hdata; + struct report *rep; + int fd; + int i; + + fd = open (path, O_RDONLY); + if (fd == -1) { + SDL_SetError ("%s: %s", path, strerror (errno)); + return (-1); + } + + hw = (struct joystick_hwdata *) + SDL_malloc (sizeof (struct joystick_hwdata)); + if (hw == NULL) { + SDL_OutOfMemory (); + close (fd); + return (-1); + } + joy->hwdata = hw; + hw->fd = fd; + hw->path = strdup (path); + if (!SDL_strncmp (path, "/dev/joy", 8)) { + hw->type = BSDJOY_JOY; + joy->naxes = 2; + joy->nbuttons = 2; + joy->nhats = 0; + joy->nballs = 0; + joydevnames[joy->index] = strdup ("Gameport joystick"); + goto usbend; + } else { + hw->type = BSDJOY_UHID; + } + + { + int ax; + for (ax = 0; ax < JOYAXE_count; ax++) + hw->axis_map[ax] = -1; + } + hw->repdesc = hid_get_report_desc (fd); + if (hw->repdesc == NULL) { + SDL_SetError ("%s: USB_GET_REPORT_DESC: %s", hw->path, + strerror (errno)); + goto usberr; + } + rep = &hw->inreport; + if (ioctl (fd, USB_GET_REPORT_ID, &rep->rid) < 0) { + rep->rid = -1; /* XXX */ + } + if (report_alloc (rep, hw->repdesc, REPORT_INPUT) < 0) { + goto usberr; + } + if (rep->size <= 0) { + SDL_SetError ("%s: Input report descriptor has invalid length", + hw->path); + goto usberr; + } #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111) - hdata = hid_start_parse(hw->repdesc, 1 << hid_input, rep->rid); + hdata = hid_start_parse (hw->repdesc, 1 << hid_input, rep->rid); #else - hdata = hid_start_parse(hw->repdesc, 1 << hid_input); + hdata = hid_start_parse (hw->repdesc, 1 << hid_input); #endif - if (hdata == NULL) { - SDL_SetError("%s: Cannot start HID parser", hw->path); - goto usberr; - } - joy->naxes = 0; - joy->nbuttons = 0; - joy->nhats = 0; - joy->nballs = 0; - for (i=0; iaxis_map[i] = -1; - - while (hid_get_item(hdata, &hitem) > 0) { - char *sp; - const char *s; - - switch (hitem.kind) { - case hid_collection: - switch (HID_PAGE(hitem.usage)) { - case HUP_GENERIC_DESKTOP: - switch (HID_USAGE(hitem.usage)) { - case HUG_JOYSTICK: - case HUG_GAME_PAD: - s = hid_usage_in_page(hitem.usage); - sp = SDL_malloc(SDL_strlen(s) + 5); - SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)", s, - joy->index); - joydevnames[joy->index] = sp; - } - } - break; - case hid_input: - switch (HID_PAGE(hitem.usage)) { - case HUP_GENERIC_DESKTOP: { - unsigned usage = HID_USAGE(hitem.usage); - int joyaxe = usage_to_joyaxe(usage); - if (joyaxe >= 0) { - hw->axis_map[joyaxe] = 1; - } else if (usage == HUG_HAT_SWITCH) { - joy->nhats++; - } - break; - } - case HUP_BUTTON: - joy->nbuttons++; - break; - default: - break; - } - break; - default: - break; - } - } - hid_end_parse(hdata); - for (i=0; iaxis_map[i] > 0) - hw->axis_map[i] = joy->naxes++; - -usbend: - /* The poll blocks the event thread. */ - fcntl(fd, F_SETFL, O_NONBLOCK); - - return (0); -usberr: - close(hw->fd); - SDL_free(hw->path); - SDL_free(hw); - return (-1); + if (hdata == NULL) { + SDL_SetError ("%s: Cannot start HID parser", hw->path); + goto usberr; + } + joy->naxes = 0; + joy->nbuttons = 0; + joy->nhats = 0; + joy->nballs = 0; + for (i = 0; i < JOYAXE_count; i++) + hw->axis_map[i] = -1; + + while (hid_get_item (hdata, &hitem) > 0) { + char *sp; + const char *s; + + switch (hitem.kind) { + case hid_collection: + switch (HID_PAGE (hitem.usage)) { + case HUP_GENERIC_DESKTOP: + switch (HID_USAGE (hitem.usage)) { + case HUG_JOYSTICK: + case HUG_GAME_PAD: + s = hid_usage_in_page (hitem.usage); + sp = SDL_malloc (SDL_strlen (s) + 5); + SDL_snprintf (sp, SDL_strlen (s) + 5, "%s (%d)", + s, joy->index); + joydevnames[joy->index] = sp; + } + } + break; + case hid_input: + switch (HID_PAGE (hitem.usage)) { + case HUP_GENERIC_DESKTOP: + { + unsigned usage = HID_USAGE (hitem.usage); + int joyaxe = usage_to_joyaxe (usage); + if (joyaxe >= 0) { + hw->axis_map[joyaxe] = 1; + } else if (usage == HUG_HAT_SWITCH) { + joy->nhats++; + } + break; + } + case HUP_BUTTON: + joy->nbuttons++; + break; + default: + break; + } + break; + default: + break; + } + } + hid_end_parse (hdata); + for (i = 0; i < JOYAXE_count; i++) + if (hw->axis_map[i] > 0) + hw->axis_map[i] = joy->naxes++; + + usbend: + /* The poll blocks the event thread. */ + fcntl (fd, F_SETFL, O_NONBLOCK); + + return (0); + usberr: + close (hw->fd); + SDL_free (hw->path); + SDL_free (hw); + return (-1); } void -SDL_SYS_JoystickUpdate(SDL_Joystick *joy) +SDL_SYS_JoystickUpdate (SDL_Joystick * joy) { - struct hid_item hitem; - struct hid_data *hdata; - struct report *rep; - int nbutton, naxe = -1; - Sint32 v; + struct hid_item hitem; + struct hid_data *hdata; + struct report *rep; + int nbutton, naxe = -1; + Sint32 v; #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H - struct joystick gameport; - static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0; - - if (joy->hwdata->type == BSDJOY_JOY) { - if (read(joy->hwdata->fd, &gameport, sizeof gameport) != sizeof gameport) - return; - if (abs(x - gameport.x) > 8) { - x = gameport.x; - if (x < xmin) { - xmin = x; - } - if (x > xmax) { - xmax = x; - } - if (xmin == xmax) { - xmin--; - xmax++; - } - v = (Sint32)x; - v -= (xmax + xmin + 1)/2; - v *= 32768/((xmax - xmin + 1)/2); - SDL_PrivateJoystickAxis(joy, 0, v); - } - if (abs(y - gameport.y) > 8) { - y = gameport.y; - if (y < ymin) { - ymin = y; - } - if (y > ymax) { - ymax = y; - } - if (ymin == ymax) { - ymin--; - ymax++; - } - v = (Sint32)y; - v -= (ymax + ymin + 1)/2; - v *= 32768/((ymax - ymin + 1)/2); - SDL_PrivateJoystickAxis(joy, 1, v); - } - if (gameport.b1 != joy->buttons[0]) { - SDL_PrivateJoystickButton(joy, 0, gameport.b1); - } - if (gameport.b2 != joy->buttons[1]) { - SDL_PrivateJoystickButton(joy, 1, gameport.b2); - } - return; - } + struct joystick gameport; + static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0; + + if (joy->hwdata->type == BSDJOY_JOY) { + if (read (joy->hwdata->fd, &gameport, sizeof gameport) != + sizeof gameport) + return; + if (abs (x - gameport.x) > 8) { + x = gameport.x; + if (x < xmin) { + xmin = x; + } + if (x > xmax) { + xmax = x; + } + if (xmin == xmax) { + xmin--; + xmax++; + } + v = (Sint32) x; + v -= (xmax + xmin + 1) / 2; + v *= 32768 / ((xmax - xmin + 1) / 2); + SDL_PrivateJoystickAxis (joy, 0, v); + } + if (abs (y - gameport.y) > 8) { + y = gameport.y; + if (y < ymin) { + ymin = y; + } + if (y > ymax) { + ymax = y; + } + if (ymin == ymax) { + ymin--; + ymax++; + } + v = (Sint32) y; + v -= (ymax + ymin + 1) / 2; + v *= 32768 / ((ymax - ymin + 1) / 2); + SDL_PrivateJoystickAxis (joy, 1, v); + } + if (gameport.b1 != joy->buttons[0]) { + SDL_PrivateJoystickButton (joy, 0, gameport.b1); + } + if (gameport.b2 != joy->buttons[1]) { + SDL_PrivateJoystickButton (joy, 1, gameport.b2); + } + return; + } #endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */ - - rep = &joy->hwdata->inreport; - if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) { - return; - } + rep = &joy->hwdata->inreport; + + if (read (joy->hwdata->fd, REP_BUF_DATA (rep), rep->size) != rep->size) { + return; + } #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111) - hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid); + hdata = hid_start_parse (joy->hwdata->repdesc, 1 << hid_input, rep->rid); #else - hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input); + hdata = hid_start_parse (joy->hwdata->repdesc, 1 << hid_input); #endif - if (hdata == NULL) { - fprintf(stderr, "%s: Cannot start HID parser\n", - joy->hwdata->path); - return; - } - - for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) { - switch (hitem.kind) { - case hid_input: - switch (HID_PAGE(hitem.usage)) { - case HUP_GENERIC_DESKTOP: { - unsigned usage = HID_USAGE(hitem.usage); - int joyaxe = usage_to_joyaxe(usage); - if (joyaxe >= 0) { - naxe = joy->hwdata->axis_map[joyaxe]; - /* scaleaxe */ - v = (Sint32)hid_get_data(REP_BUF_DATA(rep), - &hitem); - v -= (hitem.logical_maximum + hitem.logical_minimum + 1)/2; - v *= 32768/((hitem.logical_maximum - hitem.logical_minimum + 1)/2); - if (v != joy->axes[naxe]) { - SDL_PrivateJoystickAxis(joy, naxe, v); - } - } else if (usage == HUG_HAT_SWITCH) { - v = (Sint32)hid_get_data(REP_BUF_DATA(rep), - &hitem); - SDL_PrivateJoystickHat(joy, 0, - hatval_to_sdl(v)-hitem.logical_minimum); - } - break; - } - case HUP_BUTTON: - v = (Sint32)hid_get_data(REP_BUF_DATA(rep), - &hitem); - if (joy->buttons[nbutton] != v) { - SDL_PrivateJoystickButton(joy, - nbutton, v); - } - nbutton++; - break; - default: - continue; - } - break; - default: - break; - } - } - hid_end_parse(hdata); - - return; + if (hdata == NULL) { + fprintf (stderr, "%s: Cannot start HID parser\n", joy->hwdata->path); + return; + } + + for (nbutton = 0; hid_get_item (hdata, &hitem) > 0;) { + switch (hitem.kind) { + case hid_input: + switch (HID_PAGE (hitem.usage)) { + case HUP_GENERIC_DESKTOP: + { + unsigned usage = HID_USAGE (hitem.usage); + int joyaxe = usage_to_joyaxe (usage); + if (joyaxe >= 0) { + naxe = joy->hwdata->axis_map[joyaxe]; + /* scaleaxe */ + v = (Sint32) hid_get_data (REP_BUF_DATA (rep), + &hitem); + v -= (hitem.logical_maximum + + hitem.logical_minimum + 1) / 2; + v *= 32768 / + ((hitem.logical_maximum - + hitem.logical_minimum + 1) / 2); + if (v != joy->axes[naxe]) { + SDL_PrivateJoystickAxis (joy, naxe, v); + } + } else if (usage == HUG_HAT_SWITCH) { + v = (Sint32) hid_get_data (REP_BUF_DATA (rep), + &hitem); + SDL_PrivateJoystickHat (joy, 0, + hatval_to_sdl (v) - + hitem.logical_minimum); + } + break; + } + case HUP_BUTTON: + v = (Sint32) hid_get_data (REP_BUF_DATA (rep), &hitem); + if (joy->buttons[nbutton] != v) { + SDL_PrivateJoystickButton (joy, nbutton, v); + } + nbutton++; + break; + default: + continue; + } + break; + default: + break; + } + } + hid_end_parse (hdata); + + return; } /* Function to close a joystick after use */ void -SDL_SYS_JoystickClose(SDL_Joystick *joy) +SDL_SYS_JoystickClose (SDL_Joystick * joy) { - if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) { - report_free(&joy->hwdata->inreport); - hid_dispose_report_desc(joy->hwdata->repdesc); - } - close(joy->hwdata->fd); - SDL_free(joy->hwdata->path); - SDL_free(joy->hwdata); - - return; + if (SDL_strncmp (joy->hwdata->path, "/dev/joy", 8)) { + report_free (&joy->hwdata->inreport); + hid_dispose_report_desc (joy->hwdata->repdesc); + } + close (joy->hwdata->fd); + SDL_free (joy->hwdata->path); + SDL_free (joy->hwdata); + + return; } void -SDL_SYS_JoystickQuit(void) +SDL_SYS_JoystickQuit (void) { - int i; + int i; - for (i = 0; i < MAX_JOYS; i++) { - if (joynames[i] != NULL) - SDL_free(joynames[i]); - if (joydevnames[i] != NULL) - SDL_free(joydevnames[i]); - } + for (i = 0; i < MAX_JOYS; i++) { + if (joynames[i] != NULL) + SDL_free (joynames[i]); + if (joydevnames[i] != NULL) + SDL_free (joydevnames[i]); + } - return; + return; } static int -report_alloc(struct report *r, struct report_desc *rd, int repind) +report_alloc (struct report *r, struct report_desc *rd, int repind) { - int len; + int len; #ifdef __DragonFly__ - len = hid_report_size(rd, r->rid, repinfo[repind].kind); + len = hid_report_size (rd, r->rid, repinfo[repind].kind); #elif __FREEBSD__ # if (__FreeBSD_version >= 460000) # if (__FreeBSD_version <= 500111) - len = hid_report_size(rd, r->rid, repinfo[repind].kind); + len = hid_report_size (rd, r->rid, repinfo[repind].kind); # else - len = hid_report_size(rd, repinfo[repind].kind, r->rid); + len = hid_report_size (rd, repinfo[repind].kind, r->rid); # endif # else - len = hid_report_size(rd, repinfo[repind].kind, &r->rid); + len = hid_report_size (rd, repinfo[repind].kind, &r->rid); # endif #else # ifdef USBHID_NEW - len = hid_report_size(rd, repinfo[repind].kind, r->rid); + len = hid_report_size (rd, repinfo[repind].kind, r->rid); # else - len = hid_report_size(rd, repinfo[repind].kind, &r->rid); + len = hid_report_size (rd, repinfo[repind].kind, &r->rid); # endif #endif - if (len < 0) { - SDL_SetError("Negative HID report size"); - return (-1); - } - r->size = len; - - if (r->size > 0) { - r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + - r->size); - if (r->buf == NULL) { - SDL_OutOfMemory(); - return (-1); - } - } else { - r->buf = NULL; - } - - r->status = SREPORT_CLEAN; - return (0); + if (len < 0) { + SDL_SetError ("Negative HID report size"); + return (-1); + } + r->size = len; + + if (r->size > 0) { + r->buf = SDL_malloc (sizeof (*r->buf) - sizeof (REP_BUF_DATA (r)) + + r->size); + if (r->buf == NULL) { + SDL_OutOfMemory (); + return (-1); + } + } else { + r->buf = NULL; + } + + r->status = SREPORT_CLEAN; + return (0); } static void -report_free(struct report *r) +report_free (struct report *r) { - if (r->buf != NULL) { - SDL_free(r->buf); - } - r->status = SREPORT_UNINIT; + if (r->buf != NULL) { + SDL_free (r->buf); + } + r->status = SREPORT_UNINIT; } #endif /* SDL_JOYSTICK_USBHID */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 022c992d4..4b1a6097c 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -42,7 +42,7 @@ #include #include #include -#include /* for NewPtrClear, DisposePtr */ +#include /* for NewPtrClear, DisposePtr */ #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" @@ -50,51 +50,51 @@ struct recElement { - IOHIDElementCookie cookie; /* unique value which identifies element, will NOT change */ - long min; /* reported min value possible */ - long max; /* reported max value possible */ + IOHIDElementCookie cookie; /* unique value which identifies element, will NOT change */ + long min; /* reported min value possible */ + long max; /* reported max value possible */ #if 0 - /* TODO: maybe should handle the following stuff somehow? */ - - long scaledMin; /* reported scaled min value possible */ - long scaledMax; /* reported scaled max value possible */ - long size; /* size in bits of data return from element */ - Boolean relative; /* are reports relative to last report (deltas) */ - Boolean wrapping; /* does element wrap around (one value higher than max is min) */ - Boolean nonLinear; /* are the values reported non-linear relative to element movement */ - Boolean preferredState; /* does element have a preferred state (such as a button) */ - Boolean nullState; /* does element have null state */ -#endif /* 0 */ - - /* runtime variables used for auto-calibration */ - long minReport; /* min returned value */ - long maxReport; /* max returned value */ - - struct recElement * pNext; /* next element in list */ + /* TODO: maybe should handle the following stuff somehow? */ + + long scaledMin; /* reported scaled min value possible */ + long scaledMax; /* reported scaled max value possible */ + long size; /* size in bits of data return from element */ + Boolean relative; /* are reports relative to last report (deltas) */ + Boolean wrapping; /* does element wrap around (one value higher than max is min) */ + Boolean nonLinear; /* are the values reported non-linear relative to element movement */ + Boolean preferredState; /* does element have a preferred state (such as a button) */ + Boolean nullState; /* does element have null state */ +#endif /* 0 */ + + /* runtime variables used for auto-calibration */ + long minReport; /* min returned value */ + long maxReport; /* max returned value */ + + struct recElement *pNext; /* next element in list */ }; typedef struct recElement recElement; struct joystick_hwdata { - IOHIDDeviceInterface ** interface; /* interface to device, NULL = no interface */ + IOHIDDeviceInterface **interface; /* interface to device, NULL = no interface */ - char product[256]; /* name of product */ - long usage; /* usage page from IOUSBHID Parser.h which defines general usage */ - long usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */ + char product[256]; /* name of product */ + long usage; /* usage page from IOUSBHID Parser.h which defines general usage */ + long usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */ - long axes; /* number of axis (calculated, not reported by device) */ - long buttons; /* number of buttons (calculated, not reported by device) */ - long hats; /* number of hat switches (calculated, not reported by device) */ - long elements; /* number of total elements (shouldbe total of above) (calculated, not reported by device) */ + long axes; /* number of axis (calculated, not reported by device) */ + long buttons; /* number of buttons (calculated, not reported by device) */ + long hats; /* number of hat switches (calculated, not reported by device) */ + long elements; /* number of total elements (shouldbe total of above) (calculated, not reported by device) */ - recElement* firstAxis; - recElement* firstButton; - recElement* firstHat; + recElement *firstAxis; + recElement *firstButton; + recElement *firstHat; - int removed; - int uncentered; + int removed; + int uncentered; - struct joystick_hwdata* pNext; /* next device */ + struct joystick_hwdata *pNext; /* next device */ }; typedef struct joystick_hwdata recDevice; @@ -103,60 +103,65 @@ typedef struct joystick_hwdata recDevice; static recDevice *gpDeviceList = NULL; -static void HIDReportErrorNum (char * strError, long numError) +static void +HIDReportErrorNum (char *strError, long numError) { - SDL_SetError(strError); + SDL_SetError (strError); } -static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice); +static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, + recDevice * pDevice); /* returns current value for element, polling element * will return 0 on error conditions which should be accounted for by application */ -static SInt32 HIDGetElementValue (recDevice *pDevice, recElement *pElement) +static SInt32 +HIDGetElementValue (recDevice * pDevice, recElement * pElement) { - IOReturn result = kIOReturnSuccess; - IOHIDEventStruct hidEvent; - hidEvent.value = 0; - - if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) - { - result = (*(pDevice->interface))->getElementValue(pDevice->interface, pElement->cookie, &hidEvent); - if (kIOReturnSuccess == result) - { - /* record min and max for auto calibration */ - if (hidEvent.value < pElement->minReport) - pElement->minReport = hidEvent.value; - if (hidEvent.value > pElement->maxReport) - pElement->maxReport = hidEvent.value; - } - } - - /* auto user scale */ - return hidEvent.value; + IOReturn result = kIOReturnSuccess; + IOHIDEventStruct hidEvent; + hidEvent.value = 0; + + if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) { + result = + (*(pDevice->interface))->getElementValue (pDevice->interface, + pElement->cookie, + &hidEvent); + if (kIOReturnSuccess == result) { + /* record min and max for auto calibration */ + if (hidEvent.value < pElement->minReport) + pElement->minReport = hidEvent.value; + if (hidEvent.value > pElement->maxReport) + pElement->maxReport = hidEvent.value; + } + } + + /* auto user scale */ + return hidEvent.value; } -static SInt32 HIDScaledCalibratedValue (recDevice *pDevice, recElement *pElement, long min, long max) +static SInt32 +HIDScaledCalibratedValue (recDevice * pDevice, recElement * pElement, + long min, long max) { - float deviceScale = max - min; - float readScale = pElement->maxReport - pElement->minReport; - SInt32 value = HIDGetElementValue(pDevice, pElement); - if (readScale == 0) - return value; /* no scaling at all */ - else - return ((value - pElement->minReport) * deviceScale / readScale) + min; + float deviceScale = max - min; + float readScale = pElement->maxReport - pElement->minReport; + SInt32 value = HIDGetElementValue (pDevice, pElement); + if (readScale == 0) + return value; /* no scaling at all */ + else + return ((value - pElement->minReport) * deviceScale / readScale) + + min; } -static void HIDRemovalCallback(void * target, - IOReturn result, - void * refcon, - void * sender) +static void +HIDRemovalCallback (void *target, IOReturn result, void *refcon, void *sender) { - recDevice *device = (recDevice *) refcon; - device->removed = 1; - device->uncentered = 1; + recDevice *device = (recDevice *) refcon; + device->removed = 1; + device->uncentered = 1; } @@ -165,39 +170,50 @@ static void HIDRemovalCallback(void * target, * Note: appliction now owns the device and must close and release it prior to exiting */ -static IOReturn HIDCreateOpenDeviceInterface (io_object_t hidDevice, recDevice *pDevice) +static IOReturn +HIDCreateOpenDeviceInterface (io_object_t hidDevice, recDevice * pDevice) { - IOReturn result = kIOReturnSuccess; - HRESULT plugInResult = S_OK; - SInt32 score = 0; - IOCFPlugInInterface ** ppPlugInInterface = NULL; - - if (NULL == pDevice->interface) - { - result = IOCreatePlugInInterfaceForService (hidDevice, kIOHIDDeviceUserClientTypeID, - kIOCFPlugInInterfaceID, &ppPlugInInterface, &score); - if (kIOReturnSuccess == result) - { - /* Call a method of the intermediate plug-in to create the device interface */ - plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface, - CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void *) &(pDevice->interface)); - if (S_OK != plugInResult) - HIDReportErrorNum ("CouldnÕt query HID class device interface from plugInInterface", plugInResult); - (*ppPlugInInterface)->Release (ppPlugInInterface); - } - else - HIDReportErrorNum ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.", result); - } - if (NULL != pDevice->interface) - { - result = (*(pDevice->interface))->open (pDevice->interface, 0); - if (kIOReturnSuccess != result) - HIDReportErrorNum ("Failed to open pDevice->interface via open.", result); - else - (*(pDevice->interface))->setRemovalCallback (pDevice->interface, HIDRemovalCallback, pDevice, pDevice); - - } - return result; + IOReturn result = kIOReturnSuccess; + HRESULT plugInResult = S_OK; + SInt32 score = 0; + IOCFPlugInInterface **ppPlugInInterface = NULL; + + if (NULL == pDevice->interface) { + result = + IOCreatePlugInInterfaceForService (hidDevice, + kIOHIDDeviceUserClientTypeID, + kIOCFPlugInInterfaceID, + &ppPlugInInterface, &score); + if (kIOReturnSuccess == result) { + /* Call a method of the intermediate plug-in to create the device interface */ + plugInResult = + (*ppPlugInInterface)->QueryInterface (ppPlugInInterface, + CFUUIDGetUUIDBytes + (kIOHIDDeviceInterfaceID), + (void *) &(pDevice-> + interface)); + if (S_OK != plugInResult) + HIDReportErrorNum + ("CouldnÕt query HID class device interface from plugInInterface", + plugInResult); + (*ppPlugInInterface)->Release (ppPlugInInterface); + } else + HIDReportErrorNum + ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.", + result); + } + if (NULL != pDevice->interface) { + result = (*(pDevice->interface))->open (pDevice->interface, 0); + if (kIOReturnSuccess != result) + HIDReportErrorNum + ("Failed to open pDevice->interface via open.", result); + else + (*(pDevice->interface))->setRemovalCallback (pDevice->interface, + HIDRemovalCallback, + pDevice, pDevice); + + } + return result; } /* Closes and releases interface to device, should be done prior to exting application @@ -206,47 +222,49 @@ static IOReturn HIDCreateOpenDeviceInterface (io_object_t hidDevice, recDevice * * (device may have to be plug and re-plugged in different location to get it working again without a restart) */ -static IOReturn HIDCloseReleaseInterface (recDevice *pDevice) +static IOReturn +HIDCloseReleaseInterface (recDevice * pDevice) { - IOReturn result = kIOReturnSuccess; - - if ((NULL != pDevice) && (NULL != pDevice->interface)) - { - /* close the interface */ - result = (*(pDevice->interface))->close (pDevice->interface); - if (kIOReturnNotOpen == result) - { - /* do nothing as device was not opened, thus can't be closed */ - } - else if (kIOReturnSuccess != result) - HIDReportErrorNum ("Failed to close IOHIDDeviceInterface.", result); - /* release the interface */ - result = (*(pDevice->interface))->Release (pDevice->interface); - if (kIOReturnSuccess != result) - HIDReportErrorNum ("Failed to release IOHIDDeviceInterface.", result); - pDevice->interface = NULL; - } - return result; + IOReturn result = kIOReturnSuccess; + + if ((NULL != pDevice) && (NULL != pDevice->interface)) { + /* close the interface */ + result = (*(pDevice->interface))->close (pDevice->interface); + if (kIOReturnNotOpen == result) { + /* do nothing as device was not opened, thus can't be closed */ + } else if (kIOReturnSuccess != result) + HIDReportErrorNum ("Failed to close IOHIDDeviceInterface.", + result); + /* release the interface */ + result = (*(pDevice->interface))->Release (pDevice->interface); + if (kIOReturnSuccess != result) + HIDReportErrorNum ("Failed to release IOHIDDeviceInterface.", + result); + pDevice->interface = NULL; + } + return result; } /* extracts actual specific element information from each element CF dictionary entry */ -static void HIDGetElementInfo (CFTypeRef refElement, recElement *pElement) +static void +HIDGetElementInfo (CFTypeRef refElement, recElement * pElement) { - long number; - CFTypeRef refType; - - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementCookieKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->cookie = (IOHIDElementCookie) number; - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMinKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->min = number; - pElement->maxReport = pElement->min; - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMaxKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->max = number; - pElement->minReport = pElement->max; + long number; + CFTypeRef refType; + + refType = + CFDictionaryGetValue (refElement, CFSTR (kIOHIDElementCookieKey)); + if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) + pElement->cookie = (IOHIDElementCookie) number; + refType = CFDictionaryGetValue (refElement, CFSTR (kIOHIDElementMinKey)); + if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) + pElement->min = number; + pElement->maxReport = pElement->min; + refType = CFDictionaryGetValue (refElement, CFSTR (kIOHIDElementMaxKey)); + if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) + pElement->max = number; + pElement->minReport = pElement->max; /* TODO: maybe should handle the following stuff somehow? @@ -275,292 +293,323 @@ static void HIDGetElementInfo (CFTypeRef refElement, recElement *pElement) if (refType) pElement->nullState = CFBooleanGetValue (refType); */ -} +} /* examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements * if element of interest allocate storage, add to list and retrieve element specific info * if collection then pass on to deconstruction collection into additional individual elements */ -static void HIDAddElement (CFTypeRef refElement, recDevice* pDevice) +static void +HIDAddElement (CFTypeRef refElement, recDevice * pDevice) { - recElement* element = NULL; - recElement** headElement = NULL; - long elementType, usagePage, usage; - CFTypeRef refElementType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementTypeKey)); - CFTypeRef refUsagePage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsagePageKey)); - CFTypeRef refUsage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsageKey)); - - - if ((refElementType) && (CFNumberGetValue (refElementType, kCFNumberLongType, &elementType))) - { - /* look at types of interest */ - if ((elementType == kIOHIDElementTypeInput_Misc) || (elementType == kIOHIDElementTypeInput_Button) || - (elementType == kIOHIDElementTypeInput_Axis)) - { - if (refUsagePage && CFNumberGetValue (refUsagePage, kCFNumberLongType, &usagePage) && - refUsage && CFNumberGetValue (refUsage, kCFNumberLongType, &usage)) - { - switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */ - { - case kHIDPage_GenericDesktop: - { - switch (usage) /* look at usage to determine function */ - { - case kHIDUsage_GD_X: - case kHIDUsage_GD_Y: - case kHIDUsage_GD_Z: - case kHIDUsage_GD_Rx: - case kHIDUsage_GD_Ry: - case kHIDUsage_GD_Rz: - case kHIDUsage_GD_Slider: - case kHIDUsage_GD_Dial: - case kHIDUsage_GD_Wheel: - element = (recElement *) NewPtrClear (sizeof (recElement)); - if (element) - { - pDevice->axes++; - headElement = &(pDevice->firstAxis); - } - break; - case kHIDUsage_GD_Hatswitch: - element = (recElement *) NewPtrClear (sizeof (recElement)); - if (element) - { - pDevice->hats++; - headElement = &(pDevice->firstHat); - } - break; - } - } - break; - case kHIDPage_Button: - element = (recElement *) NewPtrClear (sizeof (recElement)); - if (element) - { - pDevice->buttons++; - headElement = &(pDevice->firstButton); - } - break; - default: - break; - } - } - } - else if (kIOHIDElementTypeCollection == elementType) - HIDGetCollectionElements ((CFMutableDictionaryRef) refElement, pDevice); - } - - if (element && headElement) /* add to list */ - { - pDevice->elements++; - if (NULL == *headElement) - *headElement = element; - else - { - recElement *elementPrevious, *elementCurrent; - elementCurrent = *headElement; - while (elementCurrent) - { - elementPrevious = elementCurrent; - elementCurrent = elementPrevious->pNext; - } - elementPrevious->pNext = element; - } - element->pNext = NULL; - HIDGetElementInfo (refElement, element); - } + recElement *element = NULL; + recElement **headElement = NULL; + long elementType, usagePage, usage; + CFTypeRef refElementType = + CFDictionaryGetValue (refElement, CFSTR (kIOHIDElementTypeKey)); + CFTypeRef refUsagePage = + CFDictionaryGetValue (refElement, CFSTR (kIOHIDElementUsagePageKey)); + CFTypeRef refUsage = + CFDictionaryGetValue (refElement, CFSTR (kIOHIDElementUsageKey)); + + + if ((refElementType) + && + (CFNumberGetValue (refElementType, kCFNumberLongType, &elementType))) + { + /* look at types of interest */ + if ((elementType == kIOHIDElementTypeInput_Misc) + || (elementType == kIOHIDElementTypeInput_Button) + || (elementType == kIOHIDElementTypeInput_Axis)) { + if (refUsagePage + && CFNumberGetValue (refUsagePage, kCFNumberLongType, + &usagePage) && refUsage + && CFNumberGetValue (refUsage, kCFNumberLongType, &usage)) { + switch (usagePage) { /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */ + case kHIDPage_GenericDesktop: + { + switch (usage) { /* look at usage to determine function */ + case kHIDUsage_GD_X: + case kHIDUsage_GD_Y: + case kHIDUsage_GD_Z: + case kHIDUsage_GD_Rx: + case kHIDUsage_GD_Ry: + case kHIDUsage_GD_Rz: + case kHIDUsage_GD_Slider: + case kHIDUsage_GD_Dial: + case kHIDUsage_GD_Wheel: + element = (recElement *) + NewPtrClear (sizeof (recElement)); + if (element) { + pDevice->axes++; + headElement = &(pDevice->firstAxis); + } + break; + case kHIDUsage_GD_Hatswitch: + element = (recElement *) + NewPtrClear (sizeof (recElement)); + if (element) { + pDevice->hats++; + headElement = &(pDevice->firstHat); + } + break; + } + } + break; + case kHIDPage_Button: + element = (recElement *) + NewPtrClear (sizeof (recElement)); + if (element) { + pDevice->buttons++; + headElement = &(pDevice->firstButton); + } + break; + default: + break; + } + } + } else if (kIOHIDElementTypeCollection == elementType) + HIDGetCollectionElements ((CFMutableDictionaryRef) refElement, + pDevice); + } + + if (element && headElement) { /* add to list */ + pDevice->elements++; + if (NULL == *headElement) + *headElement = element; + else { + recElement *elementPrevious, *elementCurrent; + elementCurrent = *headElement; + while (elementCurrent) { + elementPrevious = elementCurrent; + elementCurrent = elementPrevious->pNext; + } + elementPrevious->pNext = element; + } + element->pNext = NULL; + HIDGetElementInfo (refElement, element); + } } /* collects information from each array member in device element list (each array memeber = element) */ -static void HIDGetElementsCFArrayHandler (const void * value, void * parameter) +static void +HIDGetElementsCFArrayHandler (const void *value, void *parameter) { - if (CFGetTypeID (value) == CFDictionaryGetTypeID ()) - HIDAddElement ((CFTypeRef) value, (recDevice *) parameter); + if (CFGetTypeID (value) == CFDictionaryGetTypeID ()) + HIDAddElement ((CFTypeRef) value, (recDevice *) parameter); } /* handles retrieval of element information from arrays of elements in device IO registry information */ -static void HIDGetElements (CFTypeRef refElementCurrent, recDevice *pDevice) +static void +HIDGetElements (CFTypeRef refElementCurrent, recDevice * pDevice) { - CFTypeID type = CFGetTypeID (refElementCurrent); - if (type == CFArrayGetTypeID()) /* if element is an array */ - { - CFRange range = {0, CFArrayGetCount (refElementCurrent)}; - /* CountElementsCFArrayHandler called for each array member */ - CFArrayApplyFunction (refElementCurrent, range, HIDGetElementsCFArrayHandler, pDevice); - } -} + CFTypeID type = CFGetTypeID (refElementCurrent); + if (type == CFArrayGetTypeID ()) { /* if element is an array */ + CFRange range = { 0, CFArrayGetCount (refElementCurrent) }; + /* CountElementsCFArrayHandler called for each array member */ + CFArrayApplyFunction (refElementCurrent, range, + HIDGetElementsCFArrayHandler, pDevice); + } +} /* handles extracting element information from element collection CF types * used from top level element decoding and hierarchy deconstruction to flatten device element list */ -static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice) +static void +HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, + recDevice * pDevice) { - CFTypeRef refElementTop = CFDictionaryGetValue (deviceProperties, CFSTR(kIOHIDElementKey)); - if (refElementTop) - HIDGetElements (refElementTop, pDevice); + CFTypeRef refElementTop = + CFDictionaryGetValue (deviceProperties, CFSTR (kIOHIDElementKey)); + if (refElementTop) + HIDGetElements (refElementTop, pDevice); } /* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */ -static void HIDTopLevelElementHandler (const void * value, void * parameter) +static void +HIDTopLevelElementHandler (const void *value, void *parameter) { - CFTypeRef refCF = 0; - if (CFGetTypeID (value) != CFDictionaryGetTypeID ()) - return; - refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsagePageKey)); - if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage."); - refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsageKey)); - if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); + CFTypeRef refCF = 0; + if (CFGetTypeID (value) != CFDictionaryGetTypeID ()) + return; + refCF = CFDictionaryGetValue (value, CFSTR (kIOHIDElementUsagePageKey)); + if (!CFNumberGetValue + (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage)) + SDL_SetError + ("CFNumberGetValue error retrieving pDevice->usagePage."); + refCF = CFDictionaryGetValue (value, CFSTR (kIOHIDElementUsageKey)); + if (!CFNumberGetValue + (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage)) + SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); } /* extracts device info from CF dictionary records in IO registry */ -static void HIDGetDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, recDevice *pDevice) +static void +HIDGetDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, + recDevice * pDevice) { - CFMutableDictionaryRef usbProperties = 0; - io_registry_entry_t parent1, parent2; - - /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also - * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties - */ - if ((KERN_SUCCESS == IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) && - (KERN_SUCCESS == IORegistryEntryGetParentEntry (parent1, kIOServicePlane, &parent2)) && - (KERN_SUCCESS == IORegistryEntryCreateCFProperties (parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) - { - if (usbProperties) - { - CFTypeRef refCF = 0; - /* get device info - * try hid dictionary first, if fail then go to usb dictionary - */ - - - /* get product name */ - refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductKey)); - if (!refCF) - refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Product Name")); - if (refCF) - { - if (!CFStringGetCString (refCF, pDevice->product, 256, CFStringGetSystemEncoding ())) - SDL_SetError ("CFStringGetCString error retrieving pDevice->product."); - } - - /* get usage page and usage */ - refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); - if (refCF) - { - if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage."); - refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); - if (refCF) - if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); - } - - if (NULL == refCF) /* get top level element HID usage page or usage */ - { - /* use top level element instead */ - CFTypeRef refCFTopElement = 0; - refCFTopElement = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); - { - /* refCFTopElement points to an array of element dictionaries */ - CFRange range = {0, CFArrayGetCount (refCFTopElement)}; - CFArrayApplyFunction (refCFTopElement, range, HIDTopLevelElementHandler, pDevice); - } - } - - CFRelease (usbProperties); - } - else - SDL_SetError ("IORegistryEntryCreateCFProperties failed to create usbProperties."); - - if (kIOReturnSuccess != IOObjectRelease (parent2)) - SDL_SetError ("IOObjectRelease error with parent2."); - if (kIOReturnSuccess != IOObjectRelease (parent1)) - SDL_SetError ("IOObjectRelease error with parent1."); - } + CFMutableDictionaryRef usbProperties = 0; + io_registry_entry_t parent1, parent2; + + /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also + * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties + */ + if ((KERN_SUCCESS == + IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) + && (KERN_SUCCESS == + IORegistryEntryGetParentEntry (parent1, kIOServicePlane, + &parent2)) + && (KERN_SUCCESS == + IORegistryEntryCreateCFProperties (parent2, &usbProperties, + kCFAllocatorDefault, + kNilOptions))) { + if (usbProperties) { + CFTypeRef refCF = 0; + /* get device info + * try hid dictionary first, if fail then go to usb dictionary + */ + + + /* get product name */ + refCF = + CFDictionaryGetValue (hidProperties, + CFSTR (kIOHIDProductKey)); + if (!refCF) + refCF = + CFDictionaryGetValue (usbProperties, + CFSTR ("USB Product Name")); + if (refCF) { + if (!CFStringGetCString + (refCF, pDevice->product, 256, + CFStringGetSystemEncoding ())) + SDL_SetError + ("CFStringGetCString error retrieving pDevice->product."); + } + + /* get usage page and usage */ + refCF = + CFDictionaryGetValue (hidProperties, + CFSTR (kIOHIDPrimaryUsagePageKey)); + if (refCF) { + if (!CFNumberGetValue + (refCF, kCFNumberLongType, &pDevice->usagePage)) + SDL_SetError + ("CFNumberGetValue error retrieving pDevice->usagePage."); + refCF = + CFDictionaryGetValue (hidProperties, + CFSTR (kIOHIDPrimaryUsageKey)); + if (refCF) + if (!CFNumberGetValue + (refCF, kCFNumberLongType, &pDevice->usage)) + SDL_SetError + ("CFNumberGetValue error retrieving pDevice->usage."); + } + + if (NULL == refCF) { /* get top level element HID usage page or usage */ + /* use top level element instead */ + CFTypeRef refCFTopElement = 0; + refCFTopElement = + CFDictionaryGetValue (hidProperties, + CFSTR (kIOHIDElementKey)); + { + /* refCFTopElement points to an array of element dictionaries */ + CFRange range = { 0, CFArrayGetCount (refCFTopElement) }; + CFArrayApplyFunction (refCFTopElement, range, + HIDTopLevelElementHandler, pDevice); + } + } + + CFRelease (usbProperties); + } else + SDL_SetError + ("IORegistryEntryCreateCFProperties failed to create usbProperties."); + + if (kIOReturnSuccess != IOObjectRelease (parent2)) + SDL_SetError ("IOObjectRelease error with parent2."); + if (kIOReturnSuccess != IOObjectRelease (parent1)) + SDL_SetError ("IOObjectRelease error with parent1."); + } } -static recDevice *HIDBuildDevice (io_object_t hidDevice) +static recDevice * +HIDBuildDevice (io_object_t hidDevice) { - recDevice *pDevice = (recDevice *) NewPtrClear (sizeof (recDevice)); - if (pDevice) - { - /* get dictionary for HID properties */ - CFMutableDictionaryRef hidProperties = 0; - kern_return_t result = IORegistryEntryCreateCFProperties (hidDevice, &hidProperties, kCFAllocatorDefault, kNilOptions); - if ((result == KERN_SUCCESS) && hidProperties) - { - /* create device interface */ - result = HIDCreateOpenDeviceInterface (hidDevice, pDevice); - if (kIOReturnSuccess == result) - { - HIDGetDeviceInfo (hidDevice, hidProperties, pDevice); /* hidDevice used to find parents in registry tree */ - HIDGetCollectionElements (hidProperties, pDevice); - } - else - { - DisposePtr((Ptr)pDevice); - pDevice = NULL; - } - CFRelease (hidProperties); - } - else - { - DisposePtr((Ptr)pDevice); - pDevice = NULL; - } - } - return pDevice; + recDevice *pDevice = (recDevice *) NewPtrClear (sizeof (recDevice)); + if (pDevice) { + /* get dictionary for HID properties */ + CFMutableDictionaryRef hidProperties = 0; + kern_return_t result = + IORegistryEntryCreateCFProperties (hidDevice, &hidProperties, + kCFAllocatorDefault, + kNilOptions); + if ((result == KERN_SUCCESS) && hidProperties) { + /* create device interface */ + result = HIDCreateOpenDeviceInterface (hidDevice, pDevice); + if (kIOReturnSuccess == result) { + HIDGetDeviceInfo (hidDevice, hidProperties, pDevice); /* hidDevice used to find parents in registry tree */ + HIDGetCollectionElements (hidProperties, pDevice); + } else { + DisposePtr ((Ptr) pDevice); + pDevice = NULL; + } + CFRelease (hidProperties); + } else { + DisposePtr ((Ptr) pDevice); + pDevice = NULL; + } + } + return pDevice; } /* disposes of the element list associated with a device and the memory associated with the list */ -static void HIDDisposeElementList (recElement **elementList) +static void +HIDDisposeElementList (recElement ** elementList) { - recElement *pElement = *elementList; - while (pElement) - { - recElement *pElementNext = pElement->pNext; - DisposePtr ((Ptr) pElement); - pElement = pElementNext; - } - *elementList = NULL; + recElement *pElement = *elementList; + while (pElement) { + recElement *pElementNext = pElement->pNext; + DisposePtr ((Ptr) pElement); + pElement = pElementNext; + } + *elementList = NULL; } /* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL * all your device no longer belong to us... (i.e., you do not 'own' the device anymore) */ -static recDevice *HIDDisposeDevice (recDevice **ppDevice) +static recDevice * +HIDDisposeDevice (recDevice ** ppDevice) { - kern_return_t result = KERN_SUCCESS; - recDevice *pDeviceNext = NULL; - if (*ppDevice) - { - /* save next device prior to disposing of this device */ - pDeviceNext = (*ppDevice)->pNext; - - /* free element lists */ - HIDDisposeElementList (&(*ppDevice)->firstAxis); - HIDDisposeElementList (&(*ppDevice)->firstButton); - HIDDisposeElementList (&(*ppDevice)->firstHat); - - result = HIDCloseReleaseInterface (*ppDevice); /* function sanity checks interface value (now application does not own device) */ - if (kIOReturnSuccess != result) - HIDReportErrorNum ("HIDCloseReleaseInterface failed when trying to dipose device.", result); - DisposePtr ((Ptr)*ppDevice); - *ppDevice = NULL; - } - return pDeviceNext; + kern_return_t result = KERN_SUCCESS; + recDevice *pDeviceNext = NULL; + if (*ppDevice) { + /* save next device prior to disposing of this device */ + pDeviceNext = (*ppDevice)->pNext; + + /* free element lists */ + HIDDisposeElementList (&(*ppDevice)->firstAxis); + HIDDisposeElementList (&(*ppDevice)->firstButton); + HIDDisposeElementList (&(*ppDevice)->firstHat); + + result = HIDCloseReleaseInterface (*ppDevice); /* function sanity checks interface value (now application does not own device) */ + if (kIOReturnSuccess != result) + HIDReportErrorNum + ("HIDCloseReleaseInterface failed when trying to dipose device.", + result); + DisposePtr ((Ptr) * ppDevice); + *ppDevice = NULL; + } + return pDeviceNext; } @@ -569,126 +618,122 @@ static recDevice *HIDDisposeDevice (recDevice **ppDevice) * This function should return the number of available joysticks, or -1 * on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - IOReturn result = kIOReturnSuccess; - mach_port_t masterPort = 0; - io_iterator_t hidObjectIterator = 0; - CFMutableDictionaryRef hidMatchDictionary = NULL; - recDevice *device, *lastDevice; - io_object_t ioHIDDeviceObject = 0; - - SDL_numjoysticks = 0; - - if (gpDeviceList) - { - SDL_SetError("Joystick: Device list already inited."); - return -1; - } - - result = IOMasterPort (bootstrap_port, &masterPort); - if (kIOReturnSuccess != result) - { - SDL_SetError("Joystick: IOMasterPort error with bootstrap_port."); - return -1; - } - - /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */ - hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey); - if (hidMatchDictionary) - { - /* Add key for device type (joystick, in this case) to refine the matching dictionary. */ - - /* NOTE: we now perform this filtering later - UInt32 usagePage = kHIDPage_GenericDesktop; - UInt32 usage = kHIDUsage_GD_Joystick; - CFNumberRef refUsage = NULL, refUsagePage = NULL; - - refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage); - CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage); - refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage); - CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage); - */ - } - else - { - SDL_SetError("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching."); - return -1; - } - - /*/ Now search I/O Registry for matching devices. */ - result = IOServiceGetMatchingServices (masterPort, hidMatchDictionary, &hidObjectIterator); - /* Check for errors */ - if (kIOReturnSuccess != result) - { - SDL_SetError("Joystick: Couldn't create a HID object iterator."); - return -1; - } - if (!hidObjectIterator) /* there are no joysticks */ - { - gpDeviceList = NULL; - SDL_numjoysticks = 0; - return 0; - } - /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */ - - /* build flat linked list of devices from device iterator */ - - gpDeviceList = lastDevice = NULL; - - while ((ioHIDDeviceObject = IOIteratorNext (hidObjectIterator))) - { - /* build a device record */ - device = HIDBuildDevice (ioHIDDeviceObject); - if (!device) - continue; - - /* dump device object, it is no longer needed */ - result = IOObjectRelease (ioHIDDeviceObject); + IOReturn result = kIOReturnSuccess; + mach_port_t masterPort = 0; + io_iterator_t hidObjectIterator = 0; + CFMutableDictionaryRef hidMatchDictionary = NULL; + recDevice *device, *lastDevice; + io_object_t ioHIDDeviceObject = 0; + + SDL_numjoysticks = 0; + + if (gpDeviceList) { + SDL_SetError ("Joystick: Device list already inited."); + return -1; + } + + result = IOMasterPort (bootstrap_port, &masterPort); + if (kIOReturnSuccess != result) { + SDL_SetError ("Joystick: IOMasterPort error with bootstrap_port."); + return -1; + } + + /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */ + hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey); + if (hidMatchDictionary) { + /* Add key for device type (joystick, in this case) to refine the matching dictionary. */ + + /* NOTE: we now perform this filtering later + UInt32 usagePage = kHIDPage_GenericDesktop; + UInt32 usage = kHIDUsage_GD_Joystick; + CFNumberRef refUsage = NULL, refUsagePage = NULL; + + refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage); + CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage); + refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage); + CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage); + */ + } else { + SDL_SetError + ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching."); + return -1; + } + + /*/ Now search I/O Registry for matching devices. */ + result = + IOServiceGetMatchingServices (masterPort, hidMatchDictionary, + &hidObjectIterator); + /* Check for errors */ + if (kIOReturnSuccess != result) { + SDL_SetError ("Joystick: Couldn't create a HID object iterator."); + return -1; + } + if (!hidObjectIterator) { /* there are no joysticks */ + gpDeviceList = NULL; + SDL_numjoysticks = 0; + return 0; + } + /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */ + + /* build flat linked list of devices from device iterator */ + + gpDeviceList = lastDevice = NULL; + + while ((ioHIDDeviceObject = IOIteratorNext (hidObjectIterator))) { + /* build a device record */ + device = HIDBuildDevice (ioHIDDeviceObject); + if (!device) + continue; + + /* dump device object, it is no longer needed */ + result = IOObjectRelease (ioHIDDeviceObject); /* if (KERN_SUCCESS != result) HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result); */ - /* Filter device list to non-keyboard/mouse stuff */ - if ( (device->usagePage != kHIDPage_GenericDesktop) || - ((device->usage != kHIDUsage_GD_Joystick && - device->usage != kHIDUsage_GD_GamePad)) ) { - - /* release memory for the device */ - HIDDisposeDevice (&device); - DisposePtr((Ptr)device); - continue; - } - - /* Add device to the end of the list */ - if (lastDevice) - lastDevice->pNext = device; - else - gpDeviceList = device; - lastDevice = device; - } - result = IOObjectRelease (hidObjectIterator); /* release the iterator */ - - /* Count the total number of devices we found */ - device = gpDeviceList; - while (device) - { - SDL_numjoysticks++; - device = device->pNext; - } - - return SDL_numjoysticks; + /* Filter device list to non-keyboard/mouse stuff */ + if ((device->usagePage != kHIDPage_GenericDesktop) || + ((device->usage != kHIDUsage_GD_Joystick && + device->usage != kHIDUsage_GD_GamePad))) { + + /* release memory for the device */ + HIDDisposeDevice (&device); + DisposePtr ((Ptr) device); + continue; + } + + /* Add device to the end of the list */ + if (lastDevice) + lastDevice->pNext = device; + else + gpDeviceList = device; + lastDevice = device; + } + result = IOObjectRelease (hidObjectIterator); /* release the iterator */ + + /* Count the total number of devices we found */ + device = gpDeviceList; + while (device) { + SDL_numjoysticks++; + device = device->pNext; + } + + return SDL_numjoysticks; } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { - recDevice *device = gpDeviceList; - - for (; index > 0; index--) - device = device->pNext; + recDevice *device = gpDeviceList; - return device->product; + for (; index > 0; index--) + device = device->pNext; + + return device->product; } /* Function to open a joystick for use. @@ -696,23 +741,24 @@ const char *SDL_SYS_JoystickName(int index) * This should fill the nbuttons and naxes fields of the joystick structure. * It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - recDevice *device = gpDeviceList; - int index; - - for (index = joystick->index; index > 0; index--) - device = device->pNext; + recDevice *device = gpDeviceList; + int index; + + for (index = joystick->index; index > 0; index--) + device = device->pNext; - joystick->hwdata = device; - joystick->name = device->product; + joystick->hwdata = device; + joystick->name = device->product; - joystick->naxes = device->axes; - joystick->nhats = device->hats; - joystick->nballs = 0; - joystick->nbuttons = device->buttons; + joystick->naxes = device->axes; + joystick->nhats = device->hats; + joystick->nballs = 0; + joystick->nbuttons = device->buttons; - return 0; + return 0; } /* Function to update the state of a joystick - called as a device poll. @@ -720,123 +766,121 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - recDevice *device = joystick->hwdata; - recElement *element; - SInt32 value; - int i; - - if (device->removed) /* device was unplugged; ignore it. */ - { - if (device->uncentered) - { - device->uncentered = 0; - - /* Tell the app that everything is centered/unpressed... */ - for (i = 0; i < device->axes; i++) - SDL_PrivateJoystickAxis(joystick, i, 0); - - for (i = 0; i < device->buttons; i++) - SDL_PrivateJoystickButton(joystick, i, 0); - - for (i = 0; i < device->hats; i++) - SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED); - } - - return; - } - - element = device->firstAxis; - i = 0; - while (element) - { - value = HIDScaledCalibratedValue(device, element, -32768, 32767); - if ( value != joystick->axes[i] ) - SDL_PrivateJoystickAxis(joystick, i, value); - element = element->pNext; - ++i; - } - - element = device->firstButton; - i = 0; - while (element) - { - value = HIDGetElementValue(device, element); - if (value > 1) /* handle pressure-sensitive buttons */ + recDevice *device = joystick->hwdata; + recElement *element; + SInt32 value; + int i; + + if (device->removed) { /* device was unplugged; ignore it. */ + if (device->uncentered) { + device->uncentered = 0; + + /* Tell the app that everything is centered/unpressed... */ + for (i = 0; i < device->axes; i++) + SDL_PrivateJoystickAxis (joystick, i, 0); + + for (i = 0; i < device->buttons; i++) + SDL_PrivateJoystickButton (joystick, i, 0); + + for (i = 0; i < device->hats; i++) + SDL_PrivateJoystickHat (joystick, i, SDL_HAT_CENTERED); + } + + return; + } + + element = device->firstAxis; + i = 0; + while (element) { + value = HIDScaledCalibratedValue (device, element, -32768, 32767); + if (value != joystick->axes[i]) + SDL_PrivateJoystickAxis (joystick, i, value); + element = element->pNext; + ++i; + } + + element = device->firstButton; + i = 0; + while (element) { + value = HIDGetElementValue (device, element); + if (value > 1) /* handle pressure-sensitive buttons */ value = 1; - if ( value != joystick->buttons[i] ) - SDL_PrivateJoystickButton(joystick, i, value); - element = element->pNext; - ++i; - } - - element = device->firstHat; - i = 0; - while (element) - { - Uint8 pos = 0; - - value = HIDGetElementValue(device, element); - if (element->max == 3) /* 4 position hatswitch - scale up value */ - value *= 2; - else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */ - value = -1; - switch(value) - { - case 0: - pos = SDL_HAT_UP; - break; - case 1: - pos = SDL_HAT_RIGHTUP; - break; - case 2: - pos = SDL_HAT_RIGHT; - break; - case 3: - pos = SDL_HAT_RIGHTDOWN; - break; - case 4: - pos = SDL_HAT_DOWN; - break; - case 5: - pos = SDL_HAT_LEFTDOWN; - break; - case 6: - pos = SDL_HAT_LEFT; - break; - case 7: - pos = SDL_HAT_LEFTUP; - break; - default: - /* Every other value is mapped to center. We do that because some - * joysticks use 8 and some 15 for this value, and apparently - * there are even more variants out there - so we try to be generous. - */ - pos = SDL_HAT_CENTERED; - break; - } - if ( pos != joystick->hats[i] ) - SDL_PrivateJoystickHat(joystick, i, pos); - element = element->pNext; - ++i; - } - - return; + if (value != joystick->buttons[i]) + SDL_PrivateJoystickButton (joystick, i, value); + element = element->pNext; + ++i; + } + + element = device->firstHat; + i = 0; + while (element) { + Uint8 pos = 0; + + value = HIDGetElementValue (device, element); + if (element->max == 3) /* 4 position hatswitch - scale up value */ + value *= 2; + else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */ + value = -1; + switch (value) { + case 0: + pos = SDL_HAT_UP; + break; + case 1: + pos = SDL_HAT_RIGHTUP; + break; + case 2: + pos = SDL_HAT_RIGHT; + break; + case 3: + pos = SDL_HAT_RIGHTDOWN; + break; + case 4: + pos = SDL_HAT_DOWN; + break; + case 5: + pos = SDL_HAT_LEFTDOWN; + break; + case 6: + pos = SDL_HAT_LEFT; + break; + case 7: + pos = SDL_HAT_LEFTUP; + break; + default: + /* Every other value is mapped to center. We do that because some + * joysticks use 8 and some 15 for this value, and apparently + * there are even more variants out there - so we try to be generous. + */ + pos = SDL_HAT_CENTERED; + break; + } + if (pos != joystick->hats[i]) + SDL_PrivateJoystickHat (joystick, i, pos); + element = element->pNext; + ++i; + } + + return; } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - /* Should we do anything here? */ - return; + /* Should we do anything here? */ + return; } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - while (NULL != gpDeviceList) - gpDeviceList = HIDDisposeDevice (&gpDeviceList); + while (NULL != gpDeviceList) + gpDeviceList = HIDDisposeDevice (&gpDeviceList); } #endif /* SDL_JOYSTICK_IOKIT */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/dc/SDL_sysjoystick.c b/src/joystick/dc/SDL_sysjoystick.c index ac7247334..9ac9df14f 100644 --- a/src/joystick/dc/SDL_sysjoystick.c +++ b/src/joystick/dc/SDL_sysjoystick.c @@ -31,21 +31,21 @@ #include #include -#define MAX_JOYSTICKS 8 /* only 2 are supported in the multimedia API */ -#define MAX_AXES 6 /* each joystick can have up to 6 axes */ -#define MAX_BUTTONS 8 /* and 8 buttons */ +#define MAX_JOYSTICKS 8 /* only 2 are supported in the multimedia API */ +#define MAX_AXES 6 /* each joystick can have up to 6 axes */ +#define MAX_BUTTONS 8 /* and 8 buttons */ #define MAX_HATS 2 #define JOYNAMELEN 8 /* array to hold joystick ID values */ -static uint8 SYS_Joystick_addr[MAX_JOYSTICKS]; +static uint8 SYS_Joystick_addr[MAX_JOYSTICKS]; /* The private structure used to keep track of a joystick */ struct joystick_hwdata { - cont_cond_t prev_cond; - int prev_buttons; + cont_cond_t prev_cond; + int prev_buttons; }; /* Function to scan the system for joysticks. @@ -53,31 +53,35 @@ struct joystick_hwdata * joysticks. Joystick 0 should be the system default joystick. * It should return 0, or -1 on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - int numdevs; + int numdevs; - int p,u; + int p, u; - numdevs = 0; - for(p=0;pinfo.product_name; + maple_device_t *dev; + if (maple_compat_resolve + (SYS_Joystick_addr[index], &dev, MAPLE_FUNC_CONTROLLER) != 0) + return NULL; + return dev->info.product_name; } /* Function to open a joystick for use. @@ -85,22 +89,23 @@ const char *SDL_SYS_JoystickName(int index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - /* allocate memory for system specific hardware data */ - joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - - /* fill nbuttons, naxes, and nhats fields */ - joystick->nbuttons = MAX_BUTTONS; - joystick->naxes = MAX_AXES; - joystick->nhats = MAX_HATS; - return(0); + /* allocate memory for system specific hardware data */ + joystick->hwdata = + (struct joystick_hwdata *) SDL_malloc (sizeof (*joystick->hwdata)); + if (joystick->hwdata == NULL) { + SDL_OutOfMemory (); + return (-1); + } + SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); + + /* fill nbuttons, naxes, and nhats fields */ + joystick->nbuttons = MAX_BUTTONS; + joystick->naxes = MAX_AXES; + joystick->nhats = MAX_HATS; + return (0); } @@ -110,84 +115,102 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { -const int sdl_buttons[] = { - CONT_C, - CONT_B, - CONT_A, - CONT_START, - CONT_Z, - CONT_Y, - CONT_X, - CONT_D -}; - - uint8 addr; - cont_cond_t cond,*prev_cond; - int buttons,prev_buttons,i,changed; - - addr = SYS_Joystick_addr[joystick->index]; - if (cont_get_cond(addr,&cond)<0) return; - - buttons = cond.buttons; - prev_buttons = joystick->hwdata->prev_buttons; - changed = buttons^prev_buttons; - - if ((changed)&(CONT_DPAD_UP|CONT_DPAD_DOWN|CONT_DPAD_LEFT|CONT_DPAD_RIGHT)) { - int hat = SDL_HAT_CENTERED; - if (buttons&CONT_DPAD_UP) hat|=SDL_HAT_UP; - if (buttons&CONT_DPAD_DOWN) hat|=SDL_HAT_DOWN; - if (buttons&CONT_DPAD_LEFT) hat|=SDL_HAT_LEFT; - if (buttons&CONT_DPAD_RIGHT) hat|=SDL_HAT_RIGHT; - SDL_PrivateJoystickHat(joystick, 0, hat); - } - if ((changed)&(CONT_DPAD2_UP|CONT_DPAD2_DOWN|CONT_DPAD2_LEFT|CONT_DPAD2_RIGHT)) { - int hat = SDL_HAT_CENTERED; - if (buttons&CONT_DPAD2_UP) hat|=SDL_HAT_UP; - if (buttons&CONT_DPAD2_DOWN) hat|=SDL_HAT_DOWN; - if (buttons&CONT_DPAD2_LEFT) hat|=SDL_HAT_LEFT; - if (buttons&CONT_DPAD2_RIGHT) hat|=SDL_HAT_RIGHT; - SDL_PrivateJoystickHat(joystick, 1, hat); - } - - for(i=0;ihwdata->prev_cond; - if (cond.joyx!=prev_cond->joyx) - SDL_PrivateJoystickAxis(joystick, 0, cond.joyx-128); - if (cond.joyy!=prev_cond->joyy) - SDL_PrivateJoystickAxis(joystick, 1, cond.joyy-128); - if (cond.rtrig!=prev_cond->rtrig) - SDL_PrivateJoystickAxis(joystick, 2, cond.rtrig); - if (cond.ltrig!=prev_cond->ltrig) - SDL_PrivateJoystickAxis(joystick, 3, cond.ltrig); - if (cond.joy2x!=prev_cond->joy2x) - SDL_PrivateJoystickAxis(joystick, 4, cond.joy2x-128); - if (cond.joy2y!=prev_cond->joy2y) - SDL_PrivateJoystickAxis(joystick, 5, cond.joy2y-128); - - joystick->hwdata->prev_buttons = buttons; - joystick->hwdata->prev_cond = cond; + const int sdl_buttons[] = { + CONT_C, + CONT_B, + CONT_A, + CONT_START, + CONT_Z, + CONT_Y, + CONT_X, + CONT_D + }; + + uint8 addr; + cont_cond_t cond, *prev_cond; + int buttons, prev_buttons, i, changed; + + addr = SYS_Joystick_addr[joystick->index]; + if (cont_get_cond (addr, &cond) < 0) + return; + + buttons = cond.buttons; + prev_buttons = joystick->hwdata->prev_buttons; + changed = buttons ^ prev_buttons; + + if ((changed) & + (CONT_DPAD_UP | CONT_DPAD_DOWN | CONT_DPAD_LEFT | CONT_DPAD_RIGHT)) { + int hat = SDL_HAT_CENTERED; + if (buttons & CONT_DPAD_UP) + hat |= SDL_HAT_UP; + if (buttons & CONT_DPAD_DOWN) + hat |= SDL_HAT_DOWN; + if (buttons & CONT_DPAD_LEFT) + hat |= SDL_HAT_LEFT; + if (buttons & CONT_DPAD_RIGHT) + hat |= SDL_HAT_RIGHT; + SDL_PrivateJoystickHat (joystick, 0, hat); + } + if ((changed) & + (CONT_DPAD2_UP | CONT_DPAD2_DOWN | CONT_DPAD2_LEFT | + CONT_DPAD2_RIGHT)) { + int hat = SDL_HAT_CENTERED; + if (buttons & CONT_DPAD2_UP) + hat |= SDL_HAT_UP; + if (buttons & CONT_DPAD2_DOWN) + hat |= SDL_HAT_DOWN; + if (buttons & CONT_DPAD2_LEFT) + hat |= SDL_HAT_LEFT; + if (buttons & CONT_DPAD2_RIGHT) + hat |= SDL_HAT_RIGHT; + SDL_PrivateJoystickHat (joystick, 1, hat); + } + + for (i = 0; i < sizeof (sdl_buttons) / sizeof (sdl_buttons[0]); i++) { + if (changed & sdl_buttons[i]) { + SDL_PrivateJoystickButton (joystick, i, + (buttons & sdl_buttons[i]) ? + SDL_PRESSED : SDL_RELEASED); + } + } + + prev_cond = &joystick->hwdata->prev_cond; + if (cond.joyx != prev_cond->joyx) + SDL_PrivateJoystickAxis (joystick, 0, cond.joyx - 128); + if (cond.joyy != prev_cond->joyy) + SDL_PrivateJoystickAxis (joystick, 1, cond.joyy - 128); + if (cond.rtrig != prev_cond->rtrig) + SDL_PrivateJoystickAxis (joystick, 2, cond.rtrig); + if (cond.ltrig != prev_cond->ltrig) + SDL_PrivateJoystickAxis (joystick, 3, cond.ltrig); + if (cond.joy2x != prev_cond->joy2x) + SDL_PrivateJoystickAxis (joystick, 4, cond.joy2x - 128); + if (cond.joy2y != prev_cond->joy2y) + SDL_PrivateJoystickAxis (joystick, 5, cond.joy2y - 128); + + joystick->hwdata->prev_buttons = buttons; + joystick->hwdata->prev_cond = cond; } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - if (joystick->hwdata != NULL) { - /* free system specific hardware data */ - SDL_free(joystick->hwdata); - } + if (joystick->hwdata != NULL) { + /* free system specific hardware data */ + SDL_free (joystick->hwdata); + } } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - return; + return; } #endif /* SDL_JOYSTICK_DC */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/dummy/SDL_sysjoystick.c b/src/joystick/dummy/SDL_sysjoystick.c index f3209a2c3..87f644ba1 100644 --- a/src/joystick/dummy/SDL_sysjoystick.c +++ b/src/joystick/dummy/SDL_sysjoystick.c @@ -34,17 +34,19 @@ * joysticks. Joystick 0 should be the system default joystick. * It should return 0, or -1 on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - SDL_numjoysticks = 0; - return(0); + SDL_numjoysticks = 0; + return (0); } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { - SDL_SetError("Logic error: No joysticks available"); - return(NULL); + SDL_SetError ("Logic error: No joysticks available"); + return (NULL); } /* Function to open a joystick for use. @@ -52,10 +54,11 @@ const char *SDL_SYS_JoystickName(int index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - SDL_SetError("Logic error: No joysticks available"); - return(-1); + SDL_SetError ("Logic error: No joysticks available"); + return (-1); } /* Function to update the state of a joystick - called as a device poll. @@ -63,21 +66,25 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - return; + return; } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - return; + return; } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - return; + return; } #endif /* SDL_JOYSTICK_DUMMY || SDL_JOYSTICK_DISABLED */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 37cf4efe0..8b2072fe8 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -29,7 +29,7 @@ #include #include #include -#include /* For the definition of PATH_MAX */ +#include /* For the definition of PATH_MAX */ #include #if SDL_INPUT_LINUXEV #include @@ -40,22 +40,25 @@ #include "../SDL_joystick_c.h" /* Special joystick configurations */ -static struct { - const char *name; - int naxes; - int nhats; - int nballs; +static struct +{ + const char *name; + int naxes; + int nhats; + int nballs; } special_joysticks[] = { - { "MadCatz Panther XL", 3, 2, 1 }, /* We don't handle rudder (axis 8) */ - { "SideWinder Precision Pro", 4, 1, 0 }, - { "SideWinder 3D Pro", 4, 1, 0 }, - { "Microsoft SideWinder 3D Pro", 4, 1, 0 }, - { "Microsoft SideWinder Dual Strike USB version 1.0", 2, 1, 0 }, - { "WingMan Interceptor", 3, 3, 0 }, - { "WingMan Extreme Digital 3D", 4, 1, 0 }, - { "Microsoft SideWinder Precision 2 Joystick", 4, 1, 0 }, - { "Logitech Inc. WingMan Extreme Digital 3D", 4, 1, 0 }, - { "Saitek Saitek X45", 6, 1, 0 } + { + "MadCatz Panther XL", 3, 2, 1}, /* We don't handle rudder (axis 8) */ + { + "SideWinder Precision Pro", 4, 1, 0}, { + "SideWinder 3D Pro", 4, 1, 0}, { + "Microsoft SideWinder 3D Pro", 4, 1, 0}, { + "Microsoft SideWinder Dual Strike USB version 1.0", 2, 1, 0}, { + "WingMan Interceptor", 3, 3, 0}, { + "WingMan Extreme Digital 3D", 4, 1, 0}, { + "Microsoft SideWinder Precision 2 Joystick", 4, 1, 0}, { + "Logitech Inc. WingMan Extreme Digital 3D", 4, 1, 0}, { + "Saitek Saitek X45", 6, 1, 0} }; #ifndef NO_LOGICAL_JOYSTICKS @@ -71,9 +74,10 @@ static struct { -id */ -struct joystick_logical_mapping { - int njoy; - int nthing; +struct joystick_logical_mapping +{ + int njoy; + int nthing; }; /* @@ -84,69 +88,80 @@ struct joystick_logical_mapping { */ static struct joystick_logical_mapping mp88xx_1_logical_axismap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5} + {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5} }; static struct joystick_logical_mapping mp88xx_1_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11} + {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, + {0, 9}, {0, 10}, {0, 11} }; static struct joystick_logical_mapping mp88xx_2_logical_axismap[] = { - {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, - {1,2},{1,3},{0,4},{0,5},{1,4},{1,5} + {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {0, 3}, + {1, 2}, {1, 3}, {0, 4}, {0, 5}, {1, 4}, {1, 5} }; static struct joystick_logical_mapping mp88xx_2_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, - {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11} + {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, + {0, 9}, {0, 10}, {0, 11}, + {1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, + {1, 9}, {1, 10}, {1, 11} }; static struct joystick_logical_mapping mp88xx_3_logical_axismap[] = { - {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, - {1,2},{1,3},{2,0},{2,1},{2,2},{2,3}, - {0,4},{0,5},{1,4},{1,5},{2,4},{2,5} + {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {0, 3}, + {1, 2}, {1, 3}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, + {0, 4}, {0, 5}, {1, 4}, {1, 5}, {2, 4}, {2, 5} }; static struct joystick_logical_mapping mp88xx_3_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, - {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}, - {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11} + {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, + {0, 9}, {0, 10}, {0, 11}, + {1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, + {1, 9}, {1, 10}, {1, 11}, + {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8}, + {2, 9}, {2, 10}, {2, 11} }; static struct joystick_logical_mapping mp88xx_4_logical_axismap[] = { - {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, - {1,2},{1,3},{2,0},{2,1},{2,2},{2,3}, - {3,0},{3,1},{3,2},{3,3},{0,4},{0,5}, - {1,4},{1,5},{2,4},{2,5},{3,4},{3,5} + {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {0, 3}, + {1, 2}, {1, 3}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, + {3, 0}, {3, 1}, {3, 2}, {3, 3}, {0, 4}, {0, 5}, + {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} }; static struct joystick_logical_mapping mp88xx_4_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, - {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}, - {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11}, - {3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8},{3,9},{3,10},{3,11} + {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, + {0, 9}, {0, 10}, {0, 11}, + {1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, + {1, 9}, {1, 10}, {1, 11}, + {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8}, + {2, 9}, {2, 10}, {2, 11}, + {3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8}, + {3, 9}, {3, 10}, {3, 11} }; -struct joystick_logical_layout { - int naxes; - int nhats; - int nballs; - int nbuttons; +struct joystick_logical_layout +{ + int naxes; + int nhats; + int nballs; + int nbuttons; }; static struct joystick_logical_layout mp88xx_1_logical_layout[] = { - {6, 0, 0, 12} + {6, 0, 0, 12} }; static struct joystick_logical_layout mp88xx_2_logical_layout[] = { - {6, 0, 0, 12}, - {6, 0, 0, 12} + {6, 0, 0, 12}, + {6, 0, 0, 12} }; static struct joystick_logical_layout mp88xx_3_logical_layout[] = { - {6, 0, 0, 12}, - {6, 0, 0, 12}, - {6, 0, 0, 12} + {6, 0, 0, 12}, + {6, 0, 0, 12}, + {6, 0, 0, 12} }; static struct joystick_logical_layout mp88xx_4_logical_layout[] = { - {6, 0, 0, 12}, - {6, 0, 0, 12}, - {6, 0, 0, 12}, - {6, 0, 0, 12} + {6, 0, 0, 12}, + {6, 0, 0, 12}, + {6, 0, 0, 12}, + {6, 0, 0, 12} }; /* @@ -162,78 +177,73 @@ static struct joystick_logical_layout mp88xx_4_logical_layout[] = { axes, hats, balls, buttons arrays that map a physical thingy to a logical thingy */ -struct joystick_logicalmap { - const char *name; - int nbuttons; - int njoys; - struct joystick_logical_layout *layout; - struct joystick_logical_mapping *axismap; - struct joystick_logical_mapping *hatmap; - struct joystick_logical_mapping *ballmap; - struct joystick_logical_mapping *buttonmap; +struct joystick_logicalmap +{ + const char *name; + int nbuttons; + int njoys; + struct joystick_logical_layout *layout; + struct joystick_logical_mapping *axismap; + struct joystick_logical_mapping *hatmap; + struct joystick_logical_mapping *ballmap; + struct joystick_logical_mapping *buttonmap; }; static struct joystick_logicalmap joystick_logicalmap[] = { - { - "WiseGroup.,Ltd MP-8866 Dual USB Joypad", - 12, - 1, - mp88xx_1_logical_layout, - mp88xx_1_logical_axismap, - NULL, - NULL, - mp88xx_1_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8866 Dual USB Joypad", - 24, - 2, - mp88xx_2_logical_layout, - mp88xx_2_logical_axismap, - NULL, - NULL, - mp88xx_2_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 12, - 1, - mp88xx_1_logical_layout, - mp88xx_1_logical_axismap, - NULL, - NULL, - mp88xx_1_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 24, - 2, - mp88xx_2_logical_layout, - mp88xx_2_logical_axismap, - NULL, - NULL, - mp88xx_2_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 36, - 3, - mp88xx_3_logical_layout, - mp88xx_3_logical_axismap, - NULL, - NULL, - mp88xx_3_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 48, - 4, - mp88xx_4_logical_layout, - mp88xx_4_logical_axismap, - NULL, - NULL, - mp88xx_4_logical_buttonmap - } + { + "WiseGroup.,Ltd MP-8866 Dual USB Joypad", + 12, + 1, + mp88xx_1_logical_layout, + mp88xx_1_logical_axismap, + NULL, + NULL, + mp88xx_1_logical_buttonmap}, + { + "WiseGroup.,Ltd MP-8866 Dual USB Joypad", + 24, + 2, + mp88xx_2_logical_layout, + mp88xx_2_logical_axismap, + NULL, + NULL, + mp88xx_2_logical_buttonmap}, + { + "WiseGroup.,Ltd MP-8800 Quad USB Joypad", + 12, + 1, + mp88xx_1_logical_layout, + mp88xx_1_logical_axismap, + NULL, + NULL, + mp88xx_1_logical_buttonmap}, + { + "WiseGroup.,Ltd MP-8800 Quad USB Joypad", + 24, + 2, + mp88xx_2_logical_layout, + mp88xx_2_logical_axismap, + NULL, + NULL, + mp88xx_2_logical_buttonmap}, + { + "WiseGroup.,Ltd MP-8800 Quad USB Joypad", + 36, + 3, + mp88xx_3_logical_layout, + mp88xx_3_logical_axismap, + NULL, + NULL, + mp88xx_3_logical_buttonmap}, + { + "WiseGroup.,Ltd MP-8800 Quad USB Joypad", + 48, + 4, + mp88xx_4_logical_layout, + mp88xx_4_logical_axismap, + NULL, + NULL, + mp88xx_4_logical_buttonmap} }; /* find the head of a linked list, given a point in it @@ -256,114 +266,120 @@ static struct joystick_logicalmap joystick_logicalmap[] = { /* A list of available joysticks */ static struct { - char* fname; + char *fname; #ifndef NO_LOGICAL_JOYSTICKS - SDL_Joystick* joy; - struct joystick_logicalmap* map; - int prev; - int next; - int logicalno; -#endif /* USE_LOGICAL_JOYSTICKS */ + SDL_Joystick *joy; + struct joystick_logicalmap *map; + int prev; + int next; + int logicalno; +#endif /* USE_LOGICAL_JOYSTICKS */ } SDL_joylist[MAX_JOYSTICKS]; /* The private structure used to keep track of a joystick */ -struct joystick_hwdata { - int fd; - /* The current linux joystick driver maps hats to two axes */ - struct hwdata_hat { - int axis[2]; - } *hats; - /* The current linux joystick driver maps balls to two axes */ - struct hwdata_ball { - int axis[2]; - } *balls; - - /* Support for the Linux 2.4 unified input interface */ +struct joystick_hwdata +{ + int fd; + /* The current linux joystick driver maps hats to two axes */ + struct hwdata_hat + { + int axis[2]; + } *hats; + /* The current linux joystick driver maps balls to two axes */ + struct hwdata_ball + { + int axis[2]; + } *balls; + + /* Support for the Linux 2.4 unified input interface */ #if SDL_INPUT_LINUXEV - SDL_bool is_hid; - Uint8 key_map[KEY_MAX-BTN_MISC]; - Uint8 abs_map[ABS_MAX]; - struct axis_correct { - int used; - int coef[3]; - } abs_correct[ABS_MAX]; + SDL_bool is_hid; + Uint8 key_map[KEY_MAX - BTN_MISC]; + Uint8 abs_map[ABS_MAX]; + struct axis_correct + { + int used; + int coef[3]; + } abs_correct[ABS_MAX]; #endif }; #ifndef NO_LOGICAL_JOYSTICKS -static int CountLogicalJoysticks(int max) +static int +CountLogicalJoysticks (int max) { - register int i, j, k, ret, prev; - const char* name; - int nbuttons, fd; - unsigned char n; - - ret = 0; - - for(i = 0; i < max; i++) { - name = SDL_SYS_JoystickName(i); - - fd = open(SDL_joylist[i].fname, O_RDONLY, 0); - if ( fd >= 0 ) { - if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { - nbuttons = -1; - } else { - nbuttons = n; - } - close(fd); - } - else { - nbuttons=-1; - } - - if (name) { - for(j = 0; j < SDL_arraysize(joystick_logicalmap); j++) { - if (!SDL_strcmp(name, joystick_logicalmap[j].name) && (nbuttons==-1 || nbuttons==joystick_logicalmap[j].nbuttons)) { - prev = i; - SDL_joylist[prev].map = &(joystick_logicalmap[j]); - - for(k = 1; k < joystick_logicalmap[j].njoys; k++) { - SDL_joylist[prev].next = max + ret; - SDL_joylist[max+ret].prev = prev; - - prev = max + ret; - SDL_joylist[prev].logicalno = k; - SDL_joylist[prev].map = &(joystick_logicalmap[j]); - ret++; - } - - break; + register int i, j, k, ret, prev; + const char *name; + int nbuttons, fd; + unsigned char n; + + ret = 0; + + for (i = 0; i < max; i++) { + name = SDL_SYS_JoystickName (i); + + fd = open (SDL_joylist[i].fname, O_RDONLY, 0); + if (fd >= 0) { + if (ioctl (fd, JSIOCGBUTTONS, &n) < 0) { + nbuttons = -1; + } else { + nbuttons = n; + } + close (fd); + } else { + nbuttons = -1; + } + + if (name) { + for (j = 0; j < SDL_arraysize (joystick_logicalmap); j++) { + if (!SDL_strcmp (name, joystick_logicalmap[j].name) + && (nbuttons == -1 + || nbuttons == joystick_logicalmap[j].nbuttons)) { + prev = i; + SDL_joylist[prev].map = &(joystick_logicalmap[j]); + + for (k = 1; k < joystick_logicalmap[j].njoys; k++) { + SDL_joylist[prev].next = max + ret; + SDL_joylist[max + ret].prev = prev; + + prev = max + ret; + SDL_joylist[prev].logicalno = k; + SDL_joylist[prev].map = &(joystick_logicalmap[j]); + ret++; + } + + break; + } } - } - } - } + } + } - return ret; + return ret; } -static void LogicalSuffix(int logicalno, char* namebuf, int len) +static void +LogicalSuffix (int logicalno, char *namebuf, int len) { - register int slen; - const static char suffixs[] = - "01020304050607080910111213141516171819" - "20212223242526272829303132"; - const char* suffix; - slen = SDL_strlen(namebuf); - suffix = NULL; - - if (logicalno*2> 5])) != 0) -static int EV_IsJoystick(int fd) +static int +EV_IsJoystick (int fd) { - unsigned long evbit[40]; - unsigned long keybit[40]; - unsigned long absbit[40]; - - if ( (ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) || - (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || - (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0) ) { - return(0); - } - if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) && - test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit) && - (test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit) || test_bit(BTN_1, keybit)))) return 0; - return(1); + unsigned long evbit[40]; + unsigned long keybit[40]; + unsigned long absbit[40]; + + if ((ioctl (fd, EVIOCGBIT (0, sizeof (evbit)), evbit) < 0) || + (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (keybit)), keybit) < 0) || + (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (absbit)), absbit) < 0)) { + return (0); + } + if (!(test_bit (EV_KEY, evbit) && test_bit (EV_ABS, evbit) && + test_bit (ABS_X, absbit) && test_bit (ABS_Y, absbit) && + (test_bit (BTN_TRIGGER, keybit) || test_bit (BTN_A, keybit) + || test_bit (BTN_1, keybit)))) + return 0; + return (1); } #endif /* SDL_INPUT_LINUXEV */ /* Function to scan the system for joysticks */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - /* The base path of the joystick devices */ - const char *joydev_pattern[] = { + /* The base path of the joystick devices */ + const char *joydev_pattern[] = { #if SDL_INPUT_LINUXEV - "/dev/input/event%d", + "/dev/input/event%d", #endif - "/dev/input/js%d", - "/dev/js%d" - }; - int numjoysticks; - int i, j; - int fd; - char path[PATH_MAX]; - dev_t dev_nums[MAX_JOYSTICKS]; /* major/minor device numbers */ - struct stat sb; - int n, duplicate; - - numjoysticks = 0; - - /* First see if the user specified a joystick to use */ - if ( SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL ) { - SDL_strlcpy(path, SDL_getenv("SDL_JOYSTICK_DEVICE"), sizeof(path)); - if ( stat(path, &sb) == 0 ) { - fd = open(path, O_RDONLY, 0); - if ( fd >= 0 ) { - /* Assume the user knows what they're doing. */ - SDL_joylist[numjoysticks].fname = SDL_strdup(path); - if ( SDL_joylist[numjoysticks].fname ) { - dev_nums[numjoysticks] = sb.st_rdev; - ++numjoysticks; - } - close(fd); - } - } - } - - for ( i=0; i= 0) { + /* Assume the user knows what they're doing. */ + SDL_joylist[numjoysticks].fname = SDL_strdup (path); + if (SDL_joylist[numjoysticks].fname) { + dev_nums[numjoysticks] = sb.st_rdev; + ++numjoysticks; + } + close (fd); + } + } + } + + for (i = 0; i < SDL_arraysize (joydev_pattern); ++i) { + for (j = 0; j < MAX_JOYSTICKS; ++j) { + SDL_snprintf (path, SDL_arraysize (path), joydev_pattern[i], j); + + /* rcg06302000 replaced access(F_OK) call with stat(). + * stat() will fail if the file doesn't exist, so it's + * equivalent behaviour. + */ + if (stat (path, &sb) == 0) { + /* Check to make sure it's not already in list. + * This happens when we see a stick via symlink. + */ + duplicate = 0; + for (n = 0; (n < numjoysticks) && !duplicate; ++n) { + if (sb.st_rdev == dev_nums[n]) { + duplicate = 1; + } + } + if (duplicate) { + continue; + } + + fd = open (path, O_RDONLY, 0); + if (fd < 0) { + continue; + } #if SDL_INPUT_LINUXEV #ifdef DEBUG_INPUT_EVENTS - printf("Checking %s\n", path); + printf ("Checking %s\n", path); #endif - if ( (i == 0) && ! EV_IsJoystick(fd) ) { - close(fd); - continue; - } + if ((i == 0) && !EV_IsJoystick (fd)) { + close (fd); + continue; + } #endif - close(fd); - - /* We're fine, add this joystick */ - SDL_joylist[numjoysticks].fname = SDL_strdup(path); - if ( SDL_joylist[numjoysticks].fname ) { - dev_nums[numjoysticks] = sb.st_rdev; - ++numjoysticks; - } - } else - break; - } + close (fd); + + /* We're fine, add this joystick */ + SDL_joylist[numjoysticks].fname = SDL_strdup (path); + if (SDL_joylist[numjoysticks].fname) { + dev_nums[numjoysticks] = sb.st_rdev; + ++numjoysticks; + } + } else + break; + } #if SDL_INPUT_LINUXEV - /* This is a special case... - If the event devices are valid then the joystick devices - will be duplicates but without extra information about their - hats or balls. Unfortunately, the event devices can't - currently be calibrated, so it's a win-lose situation. - So : /dev/input/eventX = /dev/input/jsY = /dev/jsY - */ - if ( (i == 0) && (numjoysticks > 0) ) - break; + /* This is a special case... + If the event devices are valid then the joystick devices + will be duplicates but without extra information about their + hats or balls. Unfortunately, the event devices can't + currently be calibrated, so it's a win-lose situation. + So : /dev/input/eventX = /dev/input/jsY = /dev/jsY + */ + if ((i == 0) && (numjoysticks > 0)) + break; #endif - } + } #ifndef NO_LOGICAL_JOYSTICKS - numjoysticks += CountLogicalJoysticks(numjoysticks); + numjoysticks += CountLogicalJoysticks (numjoysticks); #endif - return(numjoysticks); + return (numjoysticks); } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { - int fd; - static char namebuf[128]; - char *name; - SDL_logical_joydecl(int oindex = index); + int fd; + static char namebuf[128]; + char *name; + SDL_logical_joydecl (int oindex = index); #ifndef NO_LOGICAL_JOYSTICKS - SDL_joylist_head(index, index); + SDL_joylist_head (index, index); #endif - name = NULL; - fd = open(SDL_joylist[index].fname, O_RDONLY, 0); - if ( fd >= 0 ) { - if ( + name = NULL; + fd = open (SDL_joylist[index].fname, O_RDONLY, 0); + if (fd >= 0) { + if ( #if SDL_INPUT_LINUXEV - (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) && + (ioctl (fd, EVIOCGNAME (sizeof (namebuf)), namebuf) <= 0) && #endif - (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0) ) { - name = SDL_joylist[index].fname; - } else { - name = namebuf; - } - close(fd); + (ioctl (fd, JSIOCGNAME (sizeof (namebuf)), namebuf) <= 0)) { + name = SDL_joylist[index].fname; + } else { + name = namebuf; + } + close (fd); #ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next || index!=oindex) - { - LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128); - } + if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next + || index != oindex) { + LogicalSuffix (SDL_joylist[oindex].logicalno, namebuf, 128); + } #endif - } - return name; + } + return name; } -static int allocate_hatdata(SDL_Joystick *joystick) +static int +allocate_hatdata (SDL_Joystick * joystick) { - int i; - - joystick->hwdata->hats = (struct hwdata_hat *)SDL_malloc( - joystick->nhats * sizeof(struct hwdata_hat)); - if ( joystick->hwdata->hats == NULL ) { - return(-1); - } - for ( i=0; inhats; ++i ) { - joystick->hwdata->hats[i].axis[0] = 1; - joystick->hwdata->hats[i].axis[1] = 1; - } - return(0); + int i; + + joystick->hwdata->hats = + (struct hwdata_hat *) SDL_malloc (joystick->nhats * + sizeof (struct hwdata_hat)); + if (joystick->hwdata->hats == NULL) { + return (-1); + } + for (i = 0; i < joystick->nhats; ++i) { + joystick->hwdata->hats[i].axis[0] = 1; + joystick->hwdata->hats[i].axis[1] = 1; + } + return (0); } -static int allocate_balldata(SDL_Joystick *joystick) +static int +allocate_balldata (SDL_Joystick * joystick) { - int i; - - joystick->hwdata->balls = (struct hwdata_ball *)SDL_malloc( - joystick->nballs * sizeof(struct hwdata_ball)); - if ( joystick->hwdata->balls == NULL ) { - return(-1); - } - for ( i=0; inballs; ++i ) { - joystick->hwdata->balls[i].axis[0] = 0; - joystick->hwdata->balls[i].axis[1] = 0; - } - return(0); + int i; + + joystick->hwdata->balls = + (struct hwdata_ball *) SDL_malloc (joystick->nballs * + sizeof (struct hwdata_ball)); + if (joystick->hwdata->balls == NULL) { + return (-1); + } + for (i = 0; i < joystick->nballs; ++i) { + joystick->hwdata->balls[i].axis[0] = 0; + joystick->hwdata->balls[i].axis[1] = 0; + } + return (0); } -static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd) +static SDL_bool +JS_ConfigJoystick (SDL_Joystick * joystick, int fd) { - SDL_bool handled; - unsigned char n; - int old_axes, tmp_naxes, tmp_nhats, tmp_nballs; - const char *name; - char *env, env_name[128]; - int i; - - handled = SDL_FALSE; - - /* Default joystick device settings */ - if ( ioctl(fd, JSIOCGAXES, &n) < 0 ) { - joystick->naxes = 2; - } else { - joystick->naxes = n; - } - if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { - joystick->nbuttons = 2; - } else { - joystick->nbuttons = n; - } - - name = SDL_SYS_JoystickName(joystick->index); - old_axes = joystick->naxes; - - /* Generic analog joystick support */ - if ( SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat") ) { - if ( SDL_sscanf(name,"Analog %d-axis %*d-button %d-hat", - &tmp_naxes, &tmp_nhats) == 2 ) { - - joystick->naxes = tmp_naxes; - joystick->nhats = tmp_nhats; - - handled = SDL_TRUE; - } - } - - /* Special joystick support */ - for ( i=0; i < SDL_arraysize(special_joysticks); ++i ) { - if ( SDL_strcmp(name, special_joysticks[i].name) == 0 ) { - - joystick->naxes = special_joysticks[i].naxes; - joystick->nhats = special_joysticks[i].nhats; - joystick->nballs = special_joysticks[i].nballs; - - handled = SDL_TRUE; - break; - } - } - - /* User environment joystick support */ - if ( (env = SDL_getenv("SDL_LINUX_JOYSTICK")) ) { - *env_name = '\0'; - if ( *env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1 ) - env += SDL_strlen(env_name)+2; - else if ( SDL_sscanf(env, "%s", env_name) == 1 ) - env += SDL_strlen(env_name); - - if ( SDL_strcmp(name, env_name) == 0 ) { - - if ( SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats, - &tmp_nballs) == 3 ) { - - joystick->naxes = tmp_naxes; - joystick->nhats = tmp_nhats; - joystick->nballs = tmp_nballs; - - handled = SDL_TRUE; - } - } - } - - /* Remap hats and balls */ - if (handled) { - if ( joystick->nhats > 0 ) { - if ( allocate_hatdata(joystick) < 0 ) { - joystick->nhats = 0; - } - } - if ( joystick->nballs > 0 ) { - if ( allocate_balldata(joystick) < 0 ) { - joystick->nballs = 0; - } - } - } - - return(handled); + SDL_bool handled; + unsigned char n; + int old_axes, tmp_naxes, tmp_nhats, tmp_nballs; + const char *name; + char *env, env_name[128]; + int i; + + handled = SDL_FALSE; + + /* Default joystick device settings */ + if (ioctl (fd, JSIOCGAXES, &n) < 0) { + joystick->naxes = 2; + } else { + joystick->naxes = n; + } + if (ioctl (fd, JSIOCGBUTTONS, &n) < 0) { + joystick->nbuttons = 2; + } else { + joystick->nbuttons = n; + } + + name = SDL_SYS_JoystickName (joystick->index); + old_axes = joystick->naxes; + + /* Generic analog joystick support */ + if (SDL_strstr (name, "Analog") == name && SDL_strstr (name, "-hat")) { + if (SDL_sscanf (name, "Analog %d-axis %*d-button %d-hat", + &tmp_naxes, &tmp_nhats) == 2) { + + joystick->naxes = tmp_naxes; + joystick->nhats = tmp_nhats; + + handled = SDL_TRUE; + } + } + + /* Special joystick support */ + for (i = 0; i < SDL_arraysize (special_joysticks); ++i) { + if (SDL_strcmp (name, special_joysticks[i].name) == 0) { + + joystick->naxes = special_joysticks[i].naxes; + joystick->nhats = special_joysticks[i].nhats; + joystick->nballs = special_joysticks[i].nballs; + + handled = SDL_TRUE; + break; + } + } + + /* User environment joystick support */ + if ((env = SDL_getenv ("SDL_LINUX_JOYSTICK"))) { + *env_name = '\0'; + if (*env == '\'' && SDL_sscanf (env, "'%[^']s'", env_name) == 1) + env += SDL_strlen (env_name) + 2; + else if (SDL_sscanf (env, "%s", env_name) == 1) + env += SDL_strlen (env_name); + + if (SDL_strcmp (name, env_name) == 0) { + + if (SDL_sscanf (env, "%d %d %d", &tmp_naxes, &tmp_nhats, + &tmp_nballs) == 3) { + + joystick->naxes = tmp_naxes; + joystick->nhats = tmp_nhats; + joystick->nballs = tmp_nballs; + + handled = SDL_TRUE; + } + } + } + + /* Remap hats and balls */ + if (handled) { + if (joystick->nhats > 0) { + if (allocate_hatdata (joystick) < 0) { + joystick->nhats = 0; + } + } + if (joystick->nballs > 0) { + if (allocate_balldata (joystick) < 0) { + joystick->nballs = 0; + } + } + } + + return (handled); } #if SDL_INPUT_LINUXEV -static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd) +static SDL_bool +EV_ConfigJoystick (SDL_Joystick * joystick, int fd) { - int i, t; - unsigned long keybit[40]; - unsigned long absbit[40]; - unsigned long relbit[40]; - - /* See if this device uses the new unified event API */ - if ( (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) && - (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) && - (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0) ) { - joystick->hwdata->is_hid = SDL_TRUE; - - /* Get the number of buttons, axes, and other thingamajigs */ - for ( i=BTN_JOYSTICK; i < KEY_MAX; ++i ) { - if ( test_bit(i, keybit) ) { + int i, t; + unsigned long keybit[40]; + unsigned long absbit[40]; + unsigned long relbit[40]; + + /* See if this device uses the new unified event API */ + if ((ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (keybit)), keybit) >= 0) && + (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (absbit)), absbit) >= 0) && + (ioctl (fd, EVIOCGBIT (EV_REL, sizeof (relbit)), relbit) >= 0)) { + joystick->hwdata->is_hid = SDL_TRUE; + + /* Get the number of buttons, axes, and other thingamajigs */ + for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) { + if (test_bit (i, keybit)) { #ifdef DEBUG_INPUT_EVENTS - printf("Joystick has button: 0x%x\n", i); + printf ("Joystick has button: 0x%x\n", i); #endif - joystick->hwdata->key_map[i-BTN_MISC] = - joystick->nbuttons; - ++joystick->nbuttons; - } - } - for ( i=BTN_MISC; i < BTN_JOYSTICK; ++i ) { - if ( test_bit(i, keybit) ) { + joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons; + ++joystick->nbuttons; + } + } + for (i = BTN_MISC; i < BTN_JOYSTICK; ++i) { + if (test_bit (i, keybit)) { #ifdef DEBUG_INPUT_EVENTS - printf("Joystick has button: 0x%x\n", i); + printf ("Joystick has button: 0x%x\n", i); #endif - joystick->hwdata->key_map[i-BTN_MISC] = - joystick->nbuttons; - ++joystick->nbuttons; - } - } - for ( i=0; ihwdata->key_map[i - BTN_MISC] = joystick->nbuttons; + ++joystick->nbuttons; + } + } + for (i = 0; i < ABS_MAX; ++i) { + /* Skip hats */ + if (i == ABS_HAT0X) { + i = ABS_HAT3Y; + continue; + } + if (test_bit (i, absbit)) { + int values[5]; + + if (ioctl (fd, EVIOCGABS (i), values) < 0) + continue; #ifdef DEBUG_INPUT_EVENTS - printf("Joystick has absolute axis: %x\n", i); - printf("Values = { %d, %d, %d, %d, %d }\n", - values[0], values[1], - values[2], values[3], values[4]); + printf ("Joystick has absolute axis: %x\n", i); + printf ("Values = { %d, %d, %d, %d, %d }\n", + values[0], values[1], + values[2], values[3], values[4]); #endif /* DEBUG_INPUT_EVENTS */ - joystick->hwdata->abs_map[i] = joystick->naxes; - if ( values[1] == values[2] ) { - joystick->hwdata->abs_correct[i].used = 0; - } else { - joystick->hwdata->abs_correct[i].used = 1; - joystick->hwdata->abs_correct[i].coef[0] = - (values[2] + values[1]) / 2 - values[4]; - joystick->hwdata->abs_correct[i].coef[1] = - (values[2] + values[1]) / 2 + values[4]; - t = ((values[2] - values[1]) / 2 - 2 * values[4]); - if ( t != 0 ) { - joystick->hwdata->abs_correct[i].coef[2] = (1 << 29) / t; - } else { - joystick->hwdata->abs_correct[i].coef[2] = 0; - } - } - ++joystick->naxes; - } - } - for ( i=ABS_HAT0X; i <= ABS_HAT3Y; i += 2 ) { - if ( test_bit(i, absbit) || test_bit(i+1, absbit) ) { + joystick->hwdata->abs_map[i] = joystick->naxes; + if (values[1] == values[2]) { + joystick->hwdata->abs_correct[i].used = 0; + } else { + joystick->hwdata->abs_correct[i].used = 1; + joystick->hwdata->abs_correct[i].coef[0] = + (values[2] + values[1]) / 2 - values[4]; + joystick->hwdata->abs_correct[i].coef[1] = + (values[2] + values[1]) / 2 + values[4]; + t = ((values[2] - values[1]) / 2 - 2 * values[4]); + if (t != 0) { + joystick->hwdata->abs_correct[i].coef[2] = + (1 << 29) / t; + } else { + joystick->hwdata->abs_correct[i].coef[2] = 0; + } + } + ++joystick->naxes; + } + } + for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) { + if (test_bit (i, absbit) || test_bit (i + 1, absbit)) { #ifdef DEBUG_INPUT_EVENTS - printf("Joystick has hat %d\n",(i-ABS_HAT0X)/2); + printf ("Joystick has hat %d\n", (i - ABS_HAT0X) / 2); #endif - ++joystick->nhats; - } - } - if ( test_bit(REL_X, relbit) || test_bit(REL_Y, relbit) ) { - ++joystick->nballs; - } - - /* Allocate data to keep track of these thingamajigs */ - if ( joystick->nhats > 0 ) { - if ( allocate_hatdata(joystick) < 0 ) { - joystick->nhats = 0; - } - } - if ( joystick->nballs > 0 ) { - if ( allocate_balldata(joystick) < 0 ) { - joystick->nballs = 0; - } - } - } - return(joystick->hwdata->is_hid); + ++joystick->nhats; + } + } + if (test_bit (REL_X, relbit) || test_bit (REL_Y, relbit)) { + ++joystick->nballs; + } + + /* Allocate data to keep track of these thingamajigs */ + if (joystick->nhats > 0) { + if (allocate_hatdata (joystick) < 0) { + joystick->nhats = 0; + } + } + if (joystick->nballs > 0) { + if (allocate_balldata (joystick) < 0) { + joystick->nballs = 0; + } + } + } + return (joystick->hwdata->is_hid); } #endif /* SDL_INPUT_LINUXEV */ #ifndef NO_LOGICAL_JOYSTICKS -static void ConfigLogicalJoystick(SDL_Joystick *joystick) +static void +ConfigLogicalJoystick (SDL_Joystick * joystick) { - struct joystick_logical_layout* layout; - - layout = SDL_joylist[joystick->index].map->layout + - SDL_joylist[joystick->index].logicalno; - - joystick->nbuttons = layout->nbuttons; - joystick->nhats = layout->nhats; - joystick->naxes = layout->naxes; - joystick->nballs = layout->nballs; + struct joystick_logical_layout *layout; + + layout = SDL_joylist[joystick->index].map->layout + + SDL_joylist[joystick->index].logicalno; + + joystick->nbuttons = layout->nbuttons; + joystick->nhats = layout->nhats; + joystick->naxes = layout->naxes; + joystick->nballs = layout->nballs; } #endif @@ -775,192 +802,193 @@ static void ConfigLogicalJoystick(SDL_Joystick *joystick) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - int fd; - SDL_logical_joydecl(int realindex); - SDL_logical_joydecl(SDL_Joystick *realjoy = NULL); + int fd; + SDL_logical_joydecl (int realindex); + SDL_logical_joydecl (SDL_Joystick * realjoy = NULL); - /* Open the joystick and set the joystick file descriptor */ + /* Open the joystick and set the joystick file descriptor */ #ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(realindex, joystick->index); - realjoy = SDL_JoystickOpen(realindex); + if (SDL_joylist[joystick->index].fname == NULL) { + SDL_joylist_head (realindex, joystick->index); + realjoy = SDL_JoystickOpen (realindex); - if (realjoy == NULL) - return(-1); - - fd = realjoy->hwdata->fd; + if (realjoy == NULL) + return (-1); + + fd = realjoy->hwdata->fd; - } else { - fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); - } - SDL_joylist[joystick->index].joy = joystick; + } else { + fd = open (SDL_joylist[joystick->index].fname, O_RDONLY, 0); + } + SDL_joylist[joystick->index].joy = joystick; #else - fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); + fd = open (SDL_joylist[joystick->index].fname, O_RDONLY, 0); #endif - if ( fd < 0 ) { - SDL_SetError("Unable to open %s\n", - SDL_joylist[joystick->index]); - return(-1); - } - joystick->hwdata = (struct joystick_hwdata *) - SDL_malloc(sizeof(*joystick->hwdata)); - if ( joystick->hwdata == NULL ) { - SDL_OutOfMemory(); - close(fd); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - joystick->hwdata->fd = fd; - - /* Set the joystick to non-blocking read mode */ - fcntl(fd, F_SETFL, O_NONBLOCK); - - /* Get the number of buttons and axes on the joystick */ + if (fd < 0) { + SDL_SetError ("Unable to open %s\n", SDL_joylist[joystick->index]); + return (-1); + } + joystick->hwdata = (struct joystick_hwdata *) + SDL_malloc (sizeof (*joystick->hwdata)); + if (joystick->hwdata == NULL) { + SDL_OutOfMemory (); + close (fd); + return (-1); + } + SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); + joystick->hwdata->fd = fd; + + /* Set the joystick to non-blocking read mode */ + fcntl (fd, F_SETFL, O_NONBLOCK); + + /* Get the number of buttons and axes on the joystick */ #ifndef NO_LOGICAL_JOYSTICKS - if (realjoy) - ConfigLogicalJoystick(joystick); - else + if (realjoy) + ConfigLogicalJoystick (joystick); + else #endif #if SDL_INPUT_LINUXEV - if ( ! EV_ConfigJoystick(joystick, fd) ) + if (!EV_ConfigJoystick (joystick, fd)) #endif - JS_ConfigJoystick(joystick, fd); + JS_ConfigJoystick (joystick, fd); - return(0); + return (0); } #ifndef NO_LOGICAL_JOYSTICKS -static SDL_Joystick* FindLogicalJoystick( - SDL_Joystick *joystick, struct joystick_logical_mapping* v) +static SDL_Joystick * +FindLogicalJoystick (SDL_Joystick * joystick, + struct joystick_logical_mapping *v) { - SDL_Joystick *logicaljoy; - register int i; + SDL_Joystick *logicaljoy; + register int i; - i = joystick->index; - logicaljoy = NULL; + i = joystick->index; + logicaljoy = NULL; - /* get the fake joystick that will receive the event - */ - for(;;) { + /* get the fake joystick that will receive the event + */ + for (;;) { - if (SDL_joylist[i].logicalno == v->njoy) { - logicaljoy = SDL_joylist[i].joy; - break; - } + if (SDL_joylist[i].logicalno == v->njoy) { + logicaljoy = SDL_joylist[i].joy; + break; + } - if (SDL_joylist[i].next == 0) - break; + if (SDL_joylist[i].next == 0) + break; - i = SDL_joylist[i].next; + i = SDL_joylist[i].next; - } + } - return logicaljoy; + return logicaljoy; } -static int LogicalJoystickButton( - SDL_Joystick *joystick, Uint8 button, Uint8 state){ - struct joystick_logical_mapping* buttons; - SDL_Joystick *logicaljoy = NULL; +static int +LogicalJoystickButton (SDL_Joystick * joystick, Uint8 button, Uint8 state) +{ + struct joystick_logical_mapping *buttons; + SDL_Joystick *logicaljoy = NULL; - /* if there's no map then this is just a regular joystick - */ - if (SDL_joylist[joystick->index].map == NULL) - return 0; + /* if there's no map then this is just a regular joystick + */ + if (SDL_joylist[joystick->index].map == NULL) + return 0; - /* get the logical joystick that will receive the event - */ - buttons = SDL_joylist[joystick->index].map->buttonmap+button; - logicaljoy = FindLogicalJoystick(joystick, buttons); + /* get the logical joystick that will receive the event + */ + buttons = SDL_joylist[joystick->index].map->buttonmap + button; + logicaljoy = FindLogicalJoystick (joystick, buttons); - if (logicaljoy == NULL) - return 1; + if (logicaljoy == NULL) + return 1; - SDL_PrivateJoystickButton(logicaljoy, buttons->nthing, state); + SDL_PrivateJoystickButton (logicaljoy, buttons->nthing, state); - return 1; + return 1; } -static int LogicalJoystickAxis( - SDL_Joystick *joystick, Uint8 axis, Sint16 value) +static int +LogicalJoystickAxis (SDL_Joystick * joystick, Uint8 axis, Sint16 value) { - struct joystick_logical_mapping* axes; - SDL_Joystick *logicaljoy = NULL; + struct joystick_logical_mapping *axes; + SDL_Joystick *logicaljoy = NULL; - /* if there's no map then this is just a regular joystick - */ - if (SDL_joylist[joystick->index].map == NULL) - return 0; + /* if there's no map then this is just a regular joystick + */ + if (SDL_joylist[joystick->index].map == NULL) + return 0; - /* get the logical joystick that will receive the event - */ - axes = SDL_joylist[joystick->index].map->axismap+axis; - logicaljoy = FindLogicalJoystick(joystick, axes); + /* get the logical joystick that will receive the event + */ + axes = SDL_joylist[joystick->index].map->axismap + axis; + logicaljoy = FindLogicalJoystick (joystick, axes); - if (logicaljoy == NULL) - return 1; + if (logicaljoy == NULL) + return 1; - SDL_PrivateJoystickAxis(logicaljoy, axes->nthing, value); + SDL_PrivateJoystickAxis (logicaljoy, axes->nthing, value); - return 1; + return 1; } #endif /* USE_LOGICAL_JOYSTICKS */ -static __inline__ -void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value) +static __inline__ void +HandleHat (SDL_Joystick * stick, Uint8 hat, int axis, int value) { - struct hwdata_hat *the_hat; - const Uint8 position_map[3][3] = { - { SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP }, - { SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT }, - { SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN } - }; - SDL_logical_joydecl(SDL_Joystick *logicaljoy = NULL); - SDL_logical_joydecl(struct joystick_logical_mapping* hats = NULL); - - the_hat = &stick->hwdata->hats[hat]; - if ( value < 0 ) { - value = 0; - } else - if ( value == 0 ) { - value = 1; - } else - if ( value > 0 ) { - value = 2; - } - if ( value != the_hat->axis[axis] ) { - the_hat->axis[axis] = value; + struct hwdata_hat *the_hat; + const Uint8 position_map[3][3] = { + {SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP}, + {SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT}, + {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN} + }; + SDL_logical_joydecl (SDL_Joystick * logicaljoy = NULL); + SDL_logical_joydecl (struct joystick_logical_mapping *hats = NULL); + + the_hat = &stick->hwdata->hats[hat]; + if (value < 0) { + value = 0; + } else if (value == 0) { + value = 1; + } else if (value > 0) { + value = 2; + } + if (value != the_hat->axis[axis]) { + the_hat->axis[axis] = value; #ifndef NO_LOGICAL_JOYSTICKS - /* if there's no map then this is just a regular joystick - */ - if (SDL_joylist[stick->index].map != NULL) { - - /* get the fake joystick that will receive the event - */ - hats = SDL_joylist[stick->index].map->hatmap+hat; - logicaljoy = FindLogicalJoystick(stick, hats); - } - - if (logicaljoy) { - stick = logicaljoy; - hat = hats->nthing; - } + /* if there's no map then this is just a regular joystick + */ + if (SDL_joylist[stick->index].map != NULL) { + + /* get the fake joystick that will receive the event + */ + hats = SDL_joylist[stick->index].map->hatmap + hat; + logicaljoy = FindLogicalJoystick (stick, hats); + } + + if (logicaljoy) { + stick = logicaljoy; + hat = hats->nthing; + } #endif /* USE_LOGICAL_JOYSTICKS */ - SDL_PrivateJoystickHat(stick, hat, - position_map[the_hat->axis[1]][the_hat->axis[0]]); - } + SDL_PrivateJoystickHat (stick, hat, + position_map[the_hat->axis[1]][the_hat-> + axis[0]]); + } } -static __inline__ -void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value) +static __inline__ void +HandleBall (SDL_Joystick * stick, Uint8 ball, int axis, int value) { - stick->hwdata->balls[ball].axis[axis] += value; + stick->hwdata->balls[ball].axis[axis] += value; } /* Function to update the state of a joystick - called as a device poll. @@ -968,231 +996,246 @@ void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value) * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -static __inline__ void JS_HandleEvents(SDL_Joystick *joystick) +static __inline__ void +JS_HandleEvents (SDL_Joystick * joystick) { - struct js_event events[32]; - int i, len; - Uint8 other_axis; + struct js_event events[32]; + int i, len; + Uint8 other_axis; #ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(i, joystick->index); - JS_HandleEvents(SDL_joylist[i].joy); - return; - } + if (SDL_joylist[joystick->index].fname == NULL) { + SDL_joylist_head (i, joystick->index); + JS_HandleEvents (SDL_joylist[i].joy); + return; + } #endif - while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { - len /= sizeof(events[0]); - for ( i=0; inaxes ) { + while ((len = read (joystick->hwdata->fd, events, (sizeof events))) > 0) { + len /= sizeof (events[0]); + for (i = 0; i < len; ++i) { + switch (events[i].type & ~JS_EVENT_INIT) { + case JS_EVENT_AXIS: + if (events[i].number < joystick->naxes) { #ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickAxis(joystick, - events[i].number, events[i].value)) + if (!LogicalJoystickAxis (joystick, + events[i].number, + events[i].value)) #endif - SDL_PrivateJoystickAxis(joystick, - events[i].number, events[i].value); - break; - } - events[i].number -= joystick->naxes; - other_axis = (events[i].number / 2); - if ( other_axis < joystick->nhats ) { - HandleHat(joystick, other_axis, - events[i].number%2, - events[i].value); - break; - } - events[i].number -= joystick->nhats*2; - other_axis = (events[i].number / 2); - if ( other_axis < joystick->nballs ) { - HandleBall(joystick, other_axis, - events[i].number%2, - events[i].value); - break; - } - break; - case JS_EVENT_BUTTON: + SDL_PrivateJoystickAxis (joystick, + events[i].number, + events[i].value); + break; + } + events[i].number -= joystick->naxes; + other_axis = (events[i].number / 2); + if (other_axis < joystick->nhats) { + HandleHat (joystick, other_axis, + events[i].number % 2, events[i].value); + break; + } + events[i].number -= joystick->nhats * 2; + other_axis = (events[i].number / 2); + if (other_axis < joystick->nballs) { + HandleBall (joystick, other_axis, + events[i].number % 2, events[i].value); + break; + } + break; + case JS_EVENT_BUTTON: #ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickButton(joystick, - events[i].number, events[i].value)) + if (!LogicalJoystickButton (joystick, + events[i].number, + events[i].value)) #endif - SDL_PrivateJoystickButton(joystick, - events[i].number, events[i].value); - break; - default: - /* ?? */ - break; - } - } - } + SDL_PrivateJoystickButton (joystick, + events[i].number, + events[i].value); + break; + default: + /* ?? */ + break; + } + } + } } + #if SDL_INPUT_LINUXEV -static __inline__ int EV_AxisCorrect(SDL_Joystick *joystick, int which, int value) +static __inline__ int +EV_AxisCorrect (SDL_Joystick * joystick, int which, int value) { - struct axis_correct *correct; - - correct = &joystick->hwdata->abs_correct[which]; - if ( correct->used ) { - if ( value > correct->coef[0] ) { - if ( value < correct->coef[1] ) { - return 0; - } - value -= correct->coef[1]; - } else { - value -= correct->coef[0]; - } - value *= correct->coef[2]; - value >>= 14; - } - - /* Clamp and return */ - if ( value < -32768 ) return -32768; - if ( value > 32767 ) return 32767; - - return value; + struct axis_correct *correct; + + correct = &joystick->hwdata->abs_correct[which]; + if (correct->used) { + if (value > correct->coef[0]) { + if (value < correct->coef[1]) { + return 0; + } + value -= correct->coef[1]; + } else { + value -= correct->coef[0]; + } + value *= correct->coef[2]; + value >>= 14; + } + + /* Clamp and return */ + if (value < -32768) + return -32768; + if (value > 32767) + return 32767; + + return value; } -static __inline__ void EV_HandleEvents(SDL_Joystick *joystick) +static __inline__ void +EV_HandleEvents (SDL_Joystick * joystick) { - struct input_event events[32]; - int i, len; - int code; + struct input_event events[32]; + int i, len; + int code; #ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(i, joystick->index); - return EV_HandleEvents(SDL_joylist[i].joy); - } + if (SDL_joylist[joystick->index].fname == NULL) { + SDL_joylist_head (i, joystick->index); + return EV_HandleEvents (SDL_joylist[i].joy); + } #endif - while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { - len /= sizeof(events[0]); - for ( i=0; i= BTN_MISC ) { - code -= BTN_MISC; + while ((len = read (joystick->hwdata->fd, events, (sizeof events))) > 0) { + len /= sizeof (events[0]); + for (i = 0; i < len; ++i) { + code = events[i].code; + switch (events[i].type) { + case EV_KEY: + if (code >= BTN_MISC) { + code -= BTN_MISC; #ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickButton(joystick, - joystick->hwdata->key_map[code], - events[i].value)) + if (!LogicalJoystickButton (joystick, + joystick->hwdata-> + key_map[code], + events[i].value)) #endif - SDL_PrivateJoystickButton(joystick, - joystick->hwdata->key_map[code], - events[i].value); - } - break; - case EV_ABS: - switch (code) { - case ABS_HAT0X: - case ABS_HAT0Y: - case ABS_HAT1X: - case ABS_HAT1Y: - case ABS_HAT2X: - case ABS_HAT2Y: - case ABS_HAT3X: - case ABS_HAT3Y: - code -= ABS_HAT0X; - HandleHat(joystick, code/2, code%2, - events[i].value); - break; - default: - events[i].value = EV_AxisCorrect(joystick, code, events[i].value); + SDL_PrivateJoystickButton (joystick, + joystick->hwdata-> + key_map[code], + events[i].value); + } + break; + case EV_ABS: + switch (code) { + case ABS_HAT0X: + case ABS_HAT0Y: + case ABS_HAT1X: + case ABS_HAT1Y: + case ABS_HAT2X: + case ABS_HAT2Y: + case ABS_HAT3X: + case ABS_HAT3Y: + code -= ABS_HAT0X; + HandleHat (joystick, code / 2, code % 2, events[i].value); + break; + default: + events[i].value = + EV_AxisCorrect (joystick, code, events[i].value); #ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickAxis(joystick, - joystick->hwdata->abs_map[code], - events[i].value)) + if (!LogicalJoystickAxis (joystick, + joystick->hwdata-> + abs_map[code], events[i].value)) #endif - SDL_PrivateJoystickAxis(joystick, - joystick->hwdata->abs_map[code], - events[i].value); - break; - } - break; - case EV_REL: - switch (code) { - case REL_X: - case REL_Y: - code -= REL_X; - HandleBall(joystick, code/2, code%2, - events[i].value); - break; - default: - break; - } - break; - default: - break; - } - } - } + SDL_PrivateJoystickAxis (joystick, + joystick->hwdata-> + abs_map[code], + events[i].value); + break; + } + break; + case EV_REL: + switch (code) { + case REL_X: + case REL_Y: + code -= REL_X; + HandleBall (joystick, code / 2, code % 2, + events[i].value); + break; + default: + break; + } + break; + default: + break; + } + } + } } #endif /* SDL_INPUT_LINUXEV */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - int i; - + int i; + #if SDL_INPUT_LINUXEV - if ( joystick->hwdata->is_hid ) - EV_HandleEvents(joystick); - else + if (joystick->hwdata->is_hid) + EV_HandleEvents (joystick); + else #endif - JS_HandleEvents(joystick); - - /* Deliver ball motion updates */ - for ( i=0; inballs; ++i ) { - int xrel, yrel; - - xrel = joystick->hwdata->balls[i].axis[0]; - yrel = joystick->hwdata->balls[i].axis[1]; - if ( xrel || yrel ) { - joystick->hwdata->balls[i].axis[0] = 0; - joystick->hwdata->balls[i].axis[1] = 0; - SDL_PrivateJoystickBall(joystick, (Uint8)i, xrel, yrel); - } - } + JS_HandleEvents (joystick); + + /* Deliver ball motion updates */ + for (i = 0; i < joystick->nballs; ++i) { + int xrel, yrel; + + xrel = joystick->hwdata->balls[i].axis[0]; + yrel = joystick->hwdata->balls[i].axis[1]; + if (xrel || yrel) { + joystick->hwdata->balls[i].axis[0] = 0; + joystick->hwdata->balls[i].axis[1] = 0; + SDL_PrivateJoystickBall (joystick, (Uint8) i, xrel, yrel); + } + } } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { #ifndef NO_LOGICAL_JOYSTICKS - register int i; - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(i, joystick->index); - SDL_JoystickClose(SDL_joylist[i].joy); - } + register int i; + if (SDL_joylist[joystick->index].fname == NULL) { + SDL_joylist_head (i, joystick->index); + SDL_JoystickClose (SDL_joylist[i].joy); + } #endif - if ( joystick->hwdata ) { + if (joystick->hwdata) { #ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname != NULL) + if (SDL_joylist[joystick->index].fname != NULL) #endif - close(joystick->hwdata->fd); - if ( joystick->hwdata->hats ) { - SDL_free(joystick->hwdata->hats); - } - if ( joystick->hwdata->balls ) { - SDL_free(joystick->hwdata->balls); - } - SDL_free(joystick->hwdata); - joystick->hwdata = NULL; - } + close (joystick->hwdata->fd); + if (joystick->hwdata->hats) { + SDL_free (joystick->hwdata->hats); + } + if (joystick->hwdata->balls) { + SDL_free (joystick->hwdata->balls); + } + SDL_free (joystick->hwdata); + joystick->hwdata = NULL; + } } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - int i; + int i; - for ( i=0; SDL_joylist[i].fname; ++i ) { - SDL_free(SDL_joylist[i].fname); - } - SDL_joylist[0].fname = NULL; + for (i = 0; SDL_joylist[i].fname; ++i) { + SDL_free (SDL_joylist[i].fname); + } + SDL_joylist[0].fname = NULL; } #endif /* SDL_JOYSTICK_LINUX */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/macos/SDL_sysjoystick.c b/src/joystick/macos/SDL_sysjoystick.c index 25609b30a..5cb97e265 100644 --- a/src/joystick/macos/SDL_sysjoystick.c +++ b/src/joystick/macos/SDL_sysjoystick.c @@ -37,25 +37,25 @@ /* The max number of joysticks we will detect */ -#define MAX_JOYSTICKS 16 +#define MAX_JOYSTICKS 16 /* Limit ourselves to 32 elements per device */ -#define kMaxReferences 32 +#define kMaxReferences 32 #define ISpSymmetricAxisToFloat(axis) ((((float) axis) - kISpAxisMiddle) / (kISpAxisMaximum-kISpAxisMiddle)) #define ISpAsymmetricAxisToFloat(axis) (((float) axis) / (kISpAxisMaximum)) -static ISpDeviceReference SYS_Joysticks[MAX_JOYSTICKS]; -static ISpElementListReference SYS_Elements[MAX_JOYSTICKS]; -static ISpDeviceDefinition SYS_DevDef[MAX_JOYSTICKS]; +static ISpDeviceReference SYS_Joysticks[MAX_JOYSTICKS]; +static ISpElementListReference SYS_Elements[MAX_JOYSTICKS]; +static ISpDeviceDefinition SYS_DevDef[MAX_JOYSTICKS]; -struct joystick_hwdata +struct joystick_hwdata { char name[64]; /* Uint8 id;*/ ISpElementReference refs[kMaxReferences]; /* gonna need some sort of mapping info */ -}; +}; /* Function to scan the system for joysticks. @@ -63,81 +63,77 @@ struct joystick_hwdata * This function should return the number of available joysticks, or -1 * on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { static ISpDeviceClass classes[4] = { kISpDeviceClass_Joystick, - #if kISpDeviceClass_Gamepad +#if kISpDeviceClass_Gamepad kISpDeviceClass_Gamepad, - #endif +#endif kISpDeviceClass_Wheel, 0 }; - OSErr err; - int i; - UInt32 count, numJoysticks; + OSErr err; + int i; + UInt32 count, numJoysticks; - if ( (Ptr)0 == (Ptr)ISpStartup ) { - SDL_SetError("InputSprocket not installed"); - return -1; // InputSprocket not installed + if ((Ptr) 0 == (Ptr) ISpStartup) { + SDL_SetError ("InputSprocket not installed"); + return -1; // InputSprocket not installed } - if( (Ptr)0 == (Ptr)ISpGetVersion ) { - SDL_SetError("InputSprocket not version 1.1 or newer"); - return -1; // old version of ISp (not at least 1.1) + if ((Ptr) 0 == (Ptr) ISpGetVersion) { + SDL_SetError ("InputSprocket not version 1.1 or newer"); + return -1; // old version of ISp (not at least 1.1) } - ISpStartup(); + ISpStartup (); /* Get all the joysticks */ numJoysticks = 0; - for ( i=0; classes[i]; ++i ) { + for (i = 0; classes[i]; ++i) { count = 0; - err = ISpDevices_ExtractByClass( - classes[i], - MAX_JOYSTICKS-numJoysticks, - &count, - &SYS_Joysticks[numJoysticks]); + err = ISpDevices_ExtractByClass (classes[i], + MAX_JOYSTICKS - numJoysticks, + &count, + &SYS_Joysticks[numJoysticks]); numJoysticks += count; } - for(i = 0; i < numJoysticks; i++) - { - ISpDevice_GetDefinition( - SYS_Joysticks[i], sizeof(ISpDeviceDefinition), - &SYS_DevDef[i]); - - err = ISpElementList_New( - 0, NULL, - &SYS_Elements[i], 0); - + for (i = 0; i < numJoysticks; i++) { + ISpDevice_GetDefinition (SYS_Joysticks[i], + sizeof (ISpDeviceDefinition), + &SYS_DevDef[i]); + + err = ISpElementList_New (0, NULL, &SYS_Elements[i], 0); + if (err) { - SDL_OutOfMemory(); + SDL_OutOfMemory (); return -1; } - ISpDevice_GetElementList( - SYS_Joysticks[i], - &SYS_Elements[i]); + ISpDevice_GetElementList (SYS_Joysticks[i], &SYS_Elements[i]); } - ISpDevices_Deactivate(numJoysticks, SYS_Joysticks); + ISpDevices_Deactivate (numJoysticks, SYS_Joysticks); return numJoysticks; } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { static char name[64]; int len; /* convert pascal string to c-string */ len = SYS_DevDef[index].deviceName[0]; - if ( len >= sizeof(name) ) { - len = (sizeof(name) - 1); + if (len >= sizeof (name)) { + len = (sizeof (name) - 1); } - SDL_memcpy(name, &SYS_DevDef[index].deviceName[1], len); + SDL_memcpy (name, &SYS_DevDef[index].deviceName[1], len); name[len] = '\0'; return name; @@ -148,11 +144,12 @@ const char *SDL_SYS_JoystickName(int index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - int index; - UInt32 count, gotCount, count2; - long numAxis, numButtons, numHats, numBalls; + int index; + UInt32 count, gotCount, count2; + long numAxis, numButtons, numHats, numBalls; count = kMaxReferences; count2 = 0; @@ -161,44 +158,40 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) index = joystick->index; /* allocate memory for system specific hardware data */ - joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); + joystick->hwdata = + (struct joystick_hwdata *) SDL_malloc (sizeof (*joystick->hwdata)); + if (joystick->hwdata == NULL) { + SDL_OutOfMemory (); + return (-1); } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - SDL_strlcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index), SDL_arraysize(joystick->hwdata->name)); + SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); + SDL_strlcpy (joystick->hwdata->name, SDL_SYS_JoystickName (index), + SDL_arraysize (joystick->hwdata->name)); joystick->name = joystick->hwdata->name; - ISpElementList_ExtractByKind( - SYS_Elements[index], - kISpElementKind_Axis, - count, - &gotCount, - joystick->hwdata->refs); + ISpElementList_ExtractByKind (SYS_Elements[index], + kISpElementKind_Axis, + count, &gotCount, joystick->hwdata->refs); numAxis = gotCount; count -= gotCount; count2 += gotCount; - ISpElementList_ExtractByKind( - SYS_Elements[index], - kISpElementKind_DPad, - count, - &gotCount, - &(joystick->hwdata->refs[count2])); + ISpElementList_ExtractByKind (SYS_Elements[index], + kISpElementKind_DPad, + count, + &gotCount, + &(joystick->hwdata->refs[count2])); numHats = gotCount; count -= gotCount; count2 += gotCount; - ISpElementList_ExtractByKind( - SYS_Elements[index], - kISpElementKind_Button, - count, - &gotCount, - &(joystick->hwdata->refs[count2])); + ISpElementList_ExtractByKind (SYS_Elements[index], + kISpElementKind_Button, + count, + &gotCount, + &(joystick->hwdata->refs[count2])); numButtons = gotCount; count -= gotCount; @@ -209,9 +202,7 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) joystick->nballs = numBalls; joystick->nbuttons = numButtons; - ISpDevices_Activate( - 1, - &SYS_Joysticks[index]); + ISpDevices_Activate (1, &SYS_Joysticks[index]); return 0; } @@ -221,100 +212,92 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - int i, j; - ISpAxisData a; - ISpDPadData b; + int i, j; + ISpAxisData a; + ISpDPadData b; //ISpDeltaData c; - ISpButtonData d; + ISpButtonData d; - for(i = 0, j = 0; i < joystick->naxes; i++, j++) - { + for (i = 0, j = 0; i < joystick->naxes; i++, j++) { Sint16 value; - ISpElement_GetSimpleState( - joystick->hwdata->refs[j], - &a); - value = (ISpSymmetricAxisToFloat(a)* 32767.0); - if ( value != joystick->axes[i] ) { - SDL_PrivateJoystickAxis(joystick, i, value); + ISpElement_GetSimpleState (joystick->hwdata->refs[j], &a); + value = (ISpSymmetricAxisToFloat (a) * 32767.0); + if (value != joystick->axes[i]) { + SDL_PrivateJoystickAxis (joystick, i, value); } } - for(i = 0; i < joystick->nhats; i++, j++) - { + for (i = 0; i < joystick->nhats; i++, j++) { Uint8 pos; - ISpElement_GetSimpleState( - joystick->hwdata->refs[j], - &b); - switch(b) { - case kISpPadIdle: - pos = SDL_HAT_CENTERED; - break; - case kISpPadLeft: - pos = SDL_HAT_LEFT; - break; - case kISpPadUpLeft: - pos = SDL_HAT_LEFTUP; - break; - case kISpPadUp: - pos = SDL_HAT_UP; - break; - case kISpPadUpRight: - pos = SDL_HAT_RIGHTUP; - break; - case kISpPadRight: - pos = SDL_HAT_RIGHT; - break; - case kISpPadDownRight: - pos = SDL_HAT_RIGHTDOWN; - break; - case kISpPadDown: - pos = SDL_HAT_DOWN; - break; - case kISpPadDownLeft: - pos = SDL_HAT_LEFTDOWN; - break; + ISpElement_GetSimpleState (joystick->hwdata->refs[j], &b); + switch (b) { + case kISpPadIdle: + pos = SDL_HAT_CENTERED; + break; + case kISpPadLeft: + pos = SDL_HAT_LEFT; + break; + case kISpPadUpLeft: + pos = SDL_HAT_LEFTUP; + break; + case kISpPadUp: + pos = SDL_HAT_UP; + break; + case kISpPadUpRight: + pos = SDL_HAT_RIGHTUP; + break; + case kISpPadRight: + pos = SDL_HAT_RIGHT; + break; + case kISpPadDownRight: + pos = SDL_HAT_RIGHTDOWN; + break; + case kISpPadDown: + pos = SDL_HAT_DOWN; + break; + case kISpPadDownLeft: + pos = SDL_HAT_LEFTDOWN; + break; } - if ( pos != joystick->hats[i] ) { - SDL_PrivateJoystickHat(joystick, i, pos); + if (pos != joystick->hats[i]) { + SDL_PrivateJoystickHat (joystick, i, pos); } } - for(i = 0; i < joystick->nballs; i++, j++) - { + for (i = 0; i < joystick->nballs; i++, j++) { /* ignore balls right now */ } - for(i = 0; i < joystick->nbuttons; i++, j++) - { - ISpElement_GetSimpleState( - joystick->hwdata->refs[j], - &d); - if ( d != joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, i, d); + for (i = 0; i < joystick->nbuttons; i++, j++) { + ISpElement_GetSimpleState (joystick->hwdata->refs[j], &d); + if (d != joystick->buttons[i]) { + SDL_PrivateJoystickButton (joystick, i, d); } } } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { int index; index = joystick->index; - ISpDevices_Deactivate( - 1, - &SYS_Joysticks[index]); + ISpDevices_Deactivate (1, &SYS_Joysticks[index]); } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - ISpShutdown(); + ISpShutdown (); } #endif /* SDL_JOYSTICK_MACOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/mint/SDL_sysjoystick.c b/src/joystick/mint/SDL_sysjoystick.c index 0a129fe81..8ef9c4771 100644 --- a/src/joystick/mint/SDL_sysjoystick.c +++ b/src/joystick/mint/SDL_sysjoystick.c @@ -52,32 +52,34 @@ 2 joysticks on parallel port */ -enum { - IKBD_JOY1=0, - XBIOS_JOY1, - PORTA_PAD, - PORTB_PAD, - PORTA_JOY0, - PORTA_JOY1, - PORTB_JOY0, - PORTB_JOY1, - PORTA_LP, - PORTA_ANPAD, - PORTB_ANPAD, +enum +{ + IKBD_JOY1 = 0, + XBIOS_JOY1, + PORTA_PAD, + PORTB_PAD, + PORTA_JOY0, + PORTA_JOY1, + PORTB_JOY0, + PORTB_JOY1, + PORTA_LP, + PORTA_ANPAD, + PORTB_ANPAD, #if 0 - PARA_JOY0, - PARA_JOY1, + PARA_JOY0, + PARA_JOY1, #endif - MAX_JOYSTICKS + MAX_JOYSTICKS }; -enum { - MCH_ST=0, - MCH_STE, - MCH_TT, - MCH_F30, - MCH_CLONE, - MCH_ARANYM +enum +{ + MCH_ST = 0, + MCH_STE, + MCH_TT, + MCH_F30, + MCH_CLONE, + MCH_ARANYM }; /* Joypad buttons @@ -86,13 +88,14 @@ enum { * X,Y,Z are connected to 7,8,9 */ -enum { - JP_UP=0, JP_DOWN, JP_LEFT, JP_RIGHT, - JP_KPMULT, JP_KP7, JP_KP4, JP_KP1, - JP_KP0, JP_KP8, JP_KP5, JP_KP2, - JP_KPNUM, JP_KP9, JP_KP6, JP_KP3, - JP_PAUSE, JP_FIRE0, JP_UNDEF0, JP_FIRE1, - JP_UNDEF1, JP_FIRE2, JP_UNDEF2, JP_OPTION +enum +{ + JP_UP = 0, JP_DOWN, JP_LEFT, JP_RIGHT, + JP_KPMULT, JP_KP7, JP_KP4, JP_KP1, + JP_KP0, JP_KP8, JP_KP5, JP_KP2, + JP_KPNUM, JP_KP9, JP_KP6, JP_KP3, + JP_PAUSE, JP_FIRE0, JP_UNDEF0, JP_FIRE1, + JP_UNDEF1, JP_FIRE2, JP_UNDEF2, JP_OPTION }; #define JP_NUM_BUTTONS 17 @@ -105,41 +108,42 @@ enum { /*--- Types ---*/ -typedef struct { - SDL_bool enabled; - unsigned char *name; - Uint32 prevstate; +typedef struct +{ + SDL_bool enabled; + unsigned char *name; + Uint32 prevstate; } atarijoy_t; /*--- Variables ---*/ -static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={ - {SDL_FALSE,"IKBD joystick port 1",0}, - {SDL_FALSE,"Xbios joystick port 1",0}, - {SDL_FALSE,"Joypad port A",0}, - {SDL_FALSE,"Joypad port B",0}, - {SDL_FALSE,"Joystick 0 port A",0}, - {SDL_FALSE,"Joystick 1 port A",0}, - {SDL_FALSE,"Joystick 0 port B",0}, - {SDL_FALSE,"Joystick 1 port B",0}, - {SDL_FALSE,"Lightpen port A",0}, - {SDL_FALSE,"Analog paddle port A",0}, - {SDL_FALSE,"Analog paddle port B",0} +static atarijoy_t atarijoysticks[MAX_JOYSTICKS] = { + {SDL_FALSE, "IKBD joystick port 1", 0}, + {SDL_FALSE, "Xbios joystick port 1", 0}, + {SDL_FALSE, "Joypad port A", 0}, + {SDL_FALSE, "Joypad port B", 0}, + {SDL_FALSE, "Joystick 0 port A", 0}, + {SDL_FALSE, "Joystick 1 port A", 0}, + {SDL_FALSE, "Joystick 0 port B", 0}, + {SDL_FALSE, "Joystick 1 port B", 0}, + {SDL_FALSE, "Lightpen port A", 0}, + {SDL_FALSE, "Analog paddle port A", 0}, + {SDL_FALSE, "Analog paddle port B", 0} #if 0 - ,{SDL_FALSE,"Joystick 0 parallel port",0}, - {SDL_FALSE,"Joystick 1 parallel port",0} + , {SDL_FALSE, "Joystick 0 parallel port", 0}, + {SDL_FALSE, "Joystick 1 parallel port", 0} #endif }; -static const int jp_buttons[JP_NUM_BUTTONS]={ - JP_FIRE0, JP_FIRE1, JP_FIRE2, JP_PAUSE, - JP_OPTION, JP_KPMULT, JP_KPNUM, JP_KP0, - JP_KP1, JP_KP2, JP_KP3, JP_KP4, - JP_KP5, JP_KP6, JP_KP7, JP_KP8, - JP_KP9 +static const int jp_buttons[JP_NUM_BUTTONS] = { + JP_FIRE0, JP_FIRE1, JP_FIRE2, JP_PAUSE, + JP_OPTION, JP_KPMULT, JP_KPNUM, JP_KP0, + JP_KP1, JP_KP2, JP_KP3, JP_KP4, + JP_KP5, JP_KP6, JP_KP7, JP_KP8, + JP_KP9 }; -static SDL_bool joypad_ports_enabled=SDL_FALSE; +static SDL_bool joypad_ports_enabled = SDL_FALSE; /* Updated joypad ports */ static Uint16 jp_paddles[4]; @@ -150,17 +154,18 @@ static Uint32 jp_joypads[2]; /*--- Functions prototypes ---*/ -static int GetEnabledAtariJoystick(int index); -static void UpdateJoypads(void); +static int GetEnabledAtariJoystick (int index); +static void UpdateJoypads (void); /*--- Functions ---*/ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - int i; - unsigned long cookie_mch; - const char *envr=SDL_getenv("SDL_JOYSTICK_ATARI"); - + int i; + unsigned long cookie_mch; + const char *envr = SDL_getenv ("SDL_JOYSTICK_ATARI"); + #define TEST_JOY_ENABLED(env,idstring,num) \ if (SDL_strstr(env,idstring"-off")) { \ atarijoysticks[num].enabled=SDL_FALSE; \ @@ -169,465 +174,499 @@ int SDL_SYS_JoystickInit(void) atarijoysticks[num].enabled=SDL_TRUE; \ } - /* Cookie _MCH present ? if not, assume ST machine */ - if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) { - cookie_mch = MCH_ST << 16; - } - - /* Enable some default joysticks */ - if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || - (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || - (cookie_mch == MCH_ARANYM<<16)) { - atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0); - } - if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { - atarijoysticks[PORTA_PAD].enabled=SDL_TRUE; - atarijoysticks[PORTB_PAD].enabled=SDL_TRUE; - } - if (!atarijoysticks[IKBD_JOY1].enabled) { - atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0); - } - - /* Read environment for joysticks to enable */ - if (envr) { - /* IKBD on any Atari, maybe clones */ - if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || - (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || - (cookie_mch == MCH_ARANYM<<16)) { - if (SDL_AtariIkbd_enabled!=0) { - TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1); - } - } - /* Joypads ports only on STE and Falcon */ - if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { - TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD); - if (!atarijoysticks[PORTA_PAD].enabled) { - TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0); - TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1); - if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) { - TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP); - if (!atarijoysticks[PORTA_LP].enabled) { - TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD); - } - } - } - - TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD); - if (!atarijoysticks[PORTB_PAD].enabled) { - TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0); - TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1); - if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) { - TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD); - } - } - } - - if (!atarijoysticks[IKBD_JOY1].enabled) { - if (SDL_AtariXbios_enabled!=0) { - TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1); - } - } + /* Cookie _MCH present ? if not, assume ST machine */ + if (Getcookie (C__MCH, &cookie_mch) != C_FOUND) { + cookie_mch = MCH_ST << 16; + } + + /* Enable some default joysticks */ + if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) || + (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16) || + (cookie_mch == MCH_ARANYM << 16)) { + atarijoysticks[IKBD_JOY1].enabled = (SDL_AtariIkbd_enabled != 0); + } + if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) { + atarijoysticks[PORTA_PAD].enabled = SDL_TRUE; + atarijoysticks[PORTB_PAD].enabled = SDL_TRUE; + } + if (!atarijoysticks[IKBD_JOY1].enabled) { + atarijoysticks[XBIOS_JOY1].enabled = (SDL_AtariXbios_enabled != 0); + } + + /* Read environment for joysticks to enable */ + if (envr) { + /* IKBD on any Atari, maybe clones */ + if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) + || (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16) + || (cookie_mch == MCH_ARANYM << 16)) { + if (SDL_AtariIkbd_enabled != 0) { + TEST_JOY_ENABLED (envr, "ikbd-joy1", IKBD_JOY1); + } + } + /* Joypads ports only on STE and Falcon */ + if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) { + TEST_JOY_ENABLED (envr, "porta-pad", PORTA_PAD); + if (!atarijoysticks[PORTA_PAD].enabled) { + TEST_JOY_ENABLED (envr, "porta-joy0", PORTA_JOY0); + TEST_JOY_ENABLED (envr, "porta-joy1", PORTA_JOY1); + if (!(atarijoysticks[PORTA_JOY0].enabled) + && !(atarijoysticks[PORTA_JOY1].enabled)) { + TEST_JOY_ENABLED (envr, "porta-lp", PORTA_LP); + if (!atarijoysticks[PORTA_LP].enabled) { + TEST_JOY_ENABLED (envr, "porta-anpad", PORTA_ANPAD); + } + } + } + + TEST_JOY_ENABLED (envr, "portb-pad", PORTB_PAD); + if (!atarijoysticks[PORTB_PAD].enabled) { + TEST_JOY_ENABLED (envr, "portb-joy0", PORTB_JOY0); + TEST_JOY_ENABLED (envr, "portb-joy1", PORTB_JOY1); + if (!(atarijoysticks[PORTB_JOY0].enabled) + && !(atarijoysticks[PORTB_JOY1].enabled)) { + TEST_JOY_ENABLED (envr, "portb-anpad", PORTB_ANPAD); + } + } + } + + if (!atarijoysticks[IKBD_JOY1].enabled) { + if (SDL_AtariXbios_enabled != 0) { + TEST_JOY_ENABLED (envr, "xbios-joy1", XBIOS_JOY1); + } + } #if 0 - /* Parallel port on any Atari, maybe clones */ - if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || - (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) { - TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0); - TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1); - } + /* Parallel port on any Atari, maybe clones */ + if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) + || (cookie_mch == MCH_TT << 16) + || (cookie_mch == MCH_F30 << 16)) { + TEST_JOY_ENABLED (envr, "para-joy0", PARA_JOY0); + TEST_JOY_ENABLED (envr, "para-joy1", PARA_JOY1); + } #endif - } - - /* Need to update joypad ports ? */ - joypad_ports_enabled=SDL_FALSE; - for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) { - if (atarijoysticks[i].enabled) { - joypad_ports_enabled=SDL_TRUE; - break; - } - } - - SDL_numjoysticks = 0; - for (i=0;iindex); - if (numjoystick==-1) - return -1; - - joystick->naxes=0; - joystick->nhats=0; - joystick->nballs=0; - - switch(numjoystick) { - case PORTA_PAD: - case PORTB_PAD: - joystick->nhats=1; - joystick->nbuttons=JP_NUM_BUTTONS; - break; - case PORTA_LP: - case PORTA_ANPAD: - case PORTB_ANPAD: - joystick->naxes=2; - joystick->nbuttons=2; - break; - default: - joystick->nhats=1; - joystick->nbuttons=1; - break; - } - - return(0); + int numjoystick; + + numjoystick = GetEnabledAtariJoystick (joystick->index); + if (numjoystick == -1) + return -1; + + joystick->naxes = 0; + joystick->nhats = 0; + joystick->nballs = 0; + + switch (numjoystick) { + case PORTA_PAD: + case PORTB_PAD: + joystick->nhats = 1; + joystick->nbuttons = JP_NUM_BUTTONS; + break; + case PORTA_LP: + case PORTA_ANPAD: + case PORTB_ANPAD: + joystick->naxes = 2; + joystick->nbuttons = 2; + break; + default: + joystick->nhats = 1; + joystick->nbuttons = 1; + break; + } + + return (0); } -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - int numjoystick; - Uint8 hatstate; - Uint32 curstate,prevstate; - - numjoystick=GetEnabledAtariJoystick(joystick->index); - if (numjoystick==-1) - return; - - prevstate = atarijoysticks[numjoystick].prevstate; - - if (joypad_ports_enabled) { - Supexec(UpdateJoypads); - } - - switch (numjoystick) { - case IKBD_JOY1: - case XBIOS_JOY1: - { - curstate = 0; - - if (numjoystick==IKBD_JOY1) { - curstate = SDL_AtariIkbd_joystick & 0xff; - } - if (numjoystick==XBIOS_JOY1) { - curstate = SDL_AtariXbios_joystick & 0xff; - } - - if (curstate != prevstate) { - hatstate = SDL_HAT_CENTERED; - if (curstate & IKBD_JOY_LEFT) { - hatstate |= SDL_HAT_LEFT; - } - if (curstate & IKBD_JOY_RIGHT) { - hatstate |= SDL_HAT_RIGHT; - } - if (curstate & IKBD_JOY_UP) { - hatstate |= SDL_HAT_UP; - } - if (curstate & IKBD_JOY_DOWN) { - hatstate |= SDL_HAT_DOWN; - } - SDL_PrivateJoystickHat(joystick, 0, hatstate); - - /* Button */ - if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); - } - if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED); - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; - case PORTA_PAD: - case PORTB_PAD: - { - int numjoypad,i; - - numjoypad=0; - if (numjoystick==PORTB_PAD) numjoypad=1; - - curstate=jp_joypads[numjoypad]; - if (curstate!=prevstate) { - hatstate = SDL_HAT_CENTERED; - if (curstate & (1<>dir_shift) & 15; - curstate |= ((jp_fires>>fire_shift) & 1)<<4; - - if (curstate != prevstate) { - hatstate = SDL_HAT_CENTERED; - if (curstate & PORT_JS_LEFT) { - hatstate |= SDL_HAT_LEFT; - } - if (curstate & PORT_JS_RIGHT) { - hatstate |= SDL_HAT_RIGHT; - } - if (curstate & PORT_JS_UP) { - hatstate |= SDL_HAT_UP; - } - if (curstate & PORT_JS_DOWN) { - hatstate |= SDL_HAT_DOWN; - } - SDL_PrivateJoystickHat(joystick, 0, hatstate); - - /* Button */ - if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); - } - if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED); - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; - case PORTA_LP: - { - int i; - - curstate = jp_lightpens[0]>>1; - curstate |= (jp_lightpens[1]>>1)<<15; - curstate |= (jp_fires & 3)<<30; - - if (curstate != prevstate) { - /* X axis */ - SDL_PrivateJoystickAxis(joystick,0,jp_lightpens[0] ^ 0x8000); - /* Y axis */ - SDL_PrivateJoystickAxis(joystick,1,jp_lightpens[1] ^ 0x8000); - /* Buttons */ - for (i=0;i<2;i++) { - int button; - - button=1<<(30+i); - - if ((curstate & button) && !(prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); - } - if (!(curstate & button) && (prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); - } - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; - case PORTA_ANPAD: - case PORTB_ANPAD: - { - int numpaddle, i; - - numpaddle=0<<1; - if (numjoystick==PORTB_ANPAD) numpaddle=1<<1; - - curstate = jp_paddles[numpaddle]>>1; - curstate |= (jp_paddles[numpaddle+1]>>1)<<15; - curstate |= ((jp_fires>>numpaddle) & 3)<<30; - - if (curstate != prevstate) { - /* X axis */ - SDL_PrivateJoystickAxis(joystick,0,jp_paddles[numpaddle] ^ 0x8000); - /* Y axis */ - SDL_PrivateJoystickAxis(joystick,1,jp_paddles[numpaddle+1] ^ 0x8000); - /* Buttons */ - for (i=0;i<2;i++) { - int button; - - button=1<<(30+i); - - if ((curstate & button) && !(prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); - } - if (!(curstate & button) && (prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); - } - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; + int numjoystick; + Uint8 hatstate; + Uint32 curstate, prevstate; + + numjoystick = GetEnabledAtariJoystick (joystick->index); + if (numjoystick == -1) + return; + + prevstate = atarijoysticks[numjoystick].prevstate; + + if (joypad_ports_enabled) { + Supexec (UpdateJoypads); + } + + switch (numjoystick) { + case IKBD_JOY1: + case XBIOS_JOY1: + { + curstate = 0; + + if (numjoystick == IKBD_JOY1) { + curstate = SDL_AtariIkbd_joystick & 0xff; + } + if (numjoystick == XBIOS_JOY1) { + curstate = SDL_AtariXbios_joystick & 0xff; + } + + if (curstate != prevstate) { + hatstate = SDL_HAT_CENTERED; + if (curstate & IKBD_JOY_LEFT) { + hatstate |= SDL_HAT_LEFT; + } + if (curstate & IKBD_JOY_RIGHT) { + hatstate |= SDL_HAT_RIGHT; + } + if (curstate & IKBD_JOY_UP) { + hatstate |= SDL_HAT_UP; + } + if (curstate & IKBD_JOY_DOWN) { + hatstate |= SDL_HAT_DOWN; + } + SDL_PrivateJoystickHat (joystick, 0, hatstate); + + /* Button */ + if ((curstate & IKBD_JOY_FIRE) + && !(prevstate & IKBD_JOY_FIRE)) { + SDL_PrivateJoystickButton (joystick, 0, SDL_PRESSED); + } + if (!(curstate & IKBD_JOY_FIRE) + && (prevstate & IKBD_JOY_FIRE)) { + SDL_PrivateJoystickButton (joystick, 0, SDL_RELEASED); + } + } + atarijoysticks[numjoystick].prevstate = curstate; + } + break; + case PORTA_PAD: + case PORTB_PAD: + { + int numjoypad, i; + + numjoypad = 0; + if (numjoystick == PORTB_PAD) + numjoypad = 1; + + curstate = jp_joypads[numjoypad]; + if (curstate != prevstate) { + hatstate = SDL_HAT_CENTERED; + if (curstate & (1 << JP_LEFT)) { + hatstate |= SDL_HAT_LEFT; + } + if (curstate & (1 << JP_RIGHT)) { + hatstate |= SDL_HAT_RIGHT; + } + if (curstate & (1 << JP_UP)) { + hatstate |= SDL_HAT_UP; + } + if (curstate & (1 << JP_DOWN)) { + hatstate |= SDL_HAT_DOWN; + } + SDL_PrivateJoystickHat (joystick, 0, hatstate); + + /* Buttons */ + for (i = 0; i < JP_NUM_BUTTONS; i++) { + int button; + + button = 1 << jp_buttons[i]; + + if ((curstate & button) && !(prevstate & button)) { + SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); + } + if (!(curstate & button) && (prevstate & button)) { + SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); + } + } + } + atarijoysticks[numjoystick].prevstate = curstate; + } + break; + case PORTA_JOY0: + case PORTA_JOY1: + case PORTB_JOY0: + case PORTB_JOY1: + { + int fire_shift = 0, dir_shift = 0; + + if (numjoystick == PORTA_JOY0) { + fire_shift = 0; + dir_shift = 0; + } + if (numjoystick == PORTA_JOY1) { + fire_shift = 1; + dir_shift = 4; + } + if (numjoystick == PORTB_JOY0) { + fire_shift = 2; + dir_shift = 8; + } + if (numjoystick == PORTB_JOY1) { + fire_shift = 3; + dir_shift = 12; + } + + curstate = (jp_directions >> dir_shift) & 15; + curstate |= ((jp_fires >> fire_shift) & 1) << 4; + + if (curstate != prevstate) { + hatstate = SDL_HAT_CENTERED; + if (curstate & PORT_JS_LEFT) { + hatstate |= SDL_HAT_LEFT; + } + if (curstate & PORT_JS_RIGHT) { + hatstate |= SDL_HAT_RIGHT; + } + if (curstate & PORT_JS_UP) { + hatstate |= SDL_HAT_UP; + } + if (curstate & PORT_JS_DOWN) { + hatstate |= SDL_HAT_DOWN; + } + SDL_PrivateJoystickHat (joystick, 0, hatstate); + + /* Button */ + if ((curstate & PORT_JS_FIRE) + && !(prevstate & PORT_JS_FIRE)) { + SDL_PrivateJoystickButton (joystick, 0, SDL_PRESSED); + } + if (!(curstate & PORT_JS_FIRE) + && (prevstate & PORT_JS_FIRE)) { + SDL_PrivateJoystickButton (joystick, 0, SDL_RELEASED); + } + } + atarijoysticks[numjoystick].prevstate = curstate; + } + break; + case PORTA_LP: + { + int i; + + curstate = jp_lightpens[0] >> 1; + curstate |= (jp_lightpens[1] >> 1) << 15; + curstate |= (jp_fires & 3) << 30; + + if (curstate != prevstate) { + /* X axis */ + SDL_PrivateJoystickAxis (joystick, 0, + jp_lightpens[0] ^ 0x8000); + /* Y axis */ + SDL_PrivateJoystickAxis (joystick, 1, + jp_lightpens[1] ^ 0x8000); + /* Buttons */ + for (i = 0; i < 2; i++) { + int button; + + button = 1 << (30 + i); + + if ((curstate & button) && !(prevstate & button)) { + SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); + } + if (!(curstate & button) && (prevstate & button)) { + SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); + } + } + } + atarijoysticks[numjoystick].prevstate = curstate; + } + break; + case PORTA_ANPAD: + case PORTB_ANPAD: + { + int numpaddle, i; + + numpaddle = 0 << 1; + if (numjoystick == PORTB_ANPAD) + numpaddle = 1 << 1; + + curstate = jp_paddles[numpaddle] >> 1; + curstate |= (jp_paddles[numpaddle + 1] >> 1) << 15; + curstate |= ((jp_fires >> numpaddle) & 3) << 30; + + if (curstate != prevstate) { + /* X axis */ + SDL_PrivateJoystickAxis (joystick, 0, + jp_paddles[numpaddle] ^ 0x8000); + /* Y axis */ + SDL_PrivateJoystickAxis (joystick, 1, + jp_paddles[numpaddle + 1] ^ 0x8000); + /* Buttons */ + for (i = 0; i < 2; i++) { + int button; + + button = 1 << (30 + i); + + if ((curstate & button) && !(prevstate & button)) { + SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); + } + if (!(curstate & button) && (prevstate & button)) { + SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); + } + } + } + atarijoysticks[numjoystick].prevstate = curstate; + } + break; #if 0 - case PARA_JOY0: - case PARA_JOY1: - break; + case PARA_JOY0: + case PARA_JOY1: + break; #endif - }; + }; - return; + return; } -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - return; + return; } -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - SDL_numjoysticks=0; - return; + SDL_numjoysticks = 0; + return; } /*--- Joypad I/O read/write interface ---*/ #define JOYPAD_IO_BASE (0xffff9200) -struct JOYPAD_IO_S { - Uint16 fires; - Uint16 directions; - Uint16 dummy1[6]; - Uint16 paddles[4]; - Uint16 dummy2[4]; - Uint16 lightpens[2]; +struct JOYPAD_IO_S +{ + Uint16 fires; + Uint16 directions; + Uint16 dummy1[6]; + Uint16 paddles[4]; + Uint16 dummy2[4]; + Uint16 lightpens[2]; }; #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE)) -static void UpdateJoypads(void) +static void +UpdateJoypads (void) { - Uint16 tmp; - - /*--- This function is called in supervisor mode ---*/ - - /* Update joysticks */ - jp_fires = (~(JOYPAD_IO.fires)) & 15; - jp_directions = (~(JOYPAD_IO.directions)); - - /* Update lightpen */ - tmp = JOYPAD_IO.lightpens[0] & 1023; - jp_lightpens[0] = (tmp<<6) | (tmp>>4); - tmp = JOYPAD_IO.lightpens[1] & 1023; - jp_lightpens[1] = (tmp<<6) | (tmp>>4); - - /* Update paddles */ - tmp = (JOYPAD_IO.paddles[0] & 255); - jp_paddles[0] = (tmp<<8) | tmp; - tmp = (JOYPAD_IO.paddles[1] & 255); - jp_paddles[1] = (tmp<<8) | tmp; - tmp = (JOYPAD_IO.paddles[2] & 255); - jp_paddles[2] = (tmp<<8) | tmp; - tmp = (JOYPAD_IO.paddles[3] & 255); - jp_paddles[3] = (tmp<<8) | tmp; - - /* Update joypad 0 */ - JOYPAD_IO.directions=0xfffe; - jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16); - JOYPAD_IO.directions=0xfffe; - jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15; - - JOYPAD_IO.directions=0xfffd; - jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2); - JOYPAD_IO.directions=0xfffd; - jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4; - - JOYPAD_IO.directions=0xfffb; - jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4); - JOYPAD_IO.directions=0xfffb; - jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8; - - JOYPAD_IO.directions=0xfff7; - jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6); - JOYPAD_IO.directions=0xfff7; - jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12; - - /* Update joypad 1 */ - JOYPAD_IO.directions=0xffef; - jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2); - JOYPAD_IO.directions=0xffef; - jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15; - - JOYPAD_IO.directions=0xffdf; - jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16); - JOYPAD_IO.directions=0xffdf; - jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4; - - JOYPAD_IO.directions=0xffbf; - jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2); - JOYPAD_IO.directions=0xffbf; - jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8; - - JOYPAD_IO.directions=0xff7f; - jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4); - JOYPAD_IO.directions=0xff7f; - jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12; + Uint16 tmp; + + /*--- This function is called in supervisor mode ---*/ + + /* Update joysticks */ + jp_fires = (~(JOYPAD_IO.fires)) & 15; + jp_directions = (~(JOYPAD_IO.directions)); + + /* Update lightpen */ + tmp = JOYPAD_IO.lightpens[0] & 1023; + jp_lightpens[0] = (tmp << 6) | (tmp >> 4); + tmp = JOYPAD_IO.lightpens[1] & 1023; + jp_lightpens[1] = (tmp << 6) | (tmp >> 4); + + /* Update paddles */ + tmp = (JOYPAD_IO.paddles[0] & 255); + jp_paddles[0] = (tmp << 8) | tmp; + tmp = (JOYPAD_IO.paddles[1] & 255); + jp_paddles[1] = (tmp << 8) | tmp; + tmp = (JOYPAD_IO.paddles[2] & 255); + jp_paddles[2] = (tmp << 8) | tmp; + tmp = (JOYPAD_IO.paddles[3] & 255); + jp_paddles[3] = (tmp << 8) | tmp; + + /* Update joypad 0 */ + JOYPAD_IO.directions = 0xfffe; + jp_joypads[0] = ((~(JOYPAD_IO.fires)) & 3) << (16); + JOYPAD_IO.directions = 0xfffe; + jp_joypads[0] |= ((~(JOYPAD_IO.directions)) >> 8) & 15; + + JOYPAD_IO.directions = 0xfffd; + jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 2); + JOYPAD_IO.directions = 0xfffd; + jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 4; + + JOYPAD_IO.directions = 0xfffb; + jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 4); + JOYPAD_IO.directions = 0xfffb; + jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 8; + + JOYPAD_IO.directions = 0xfff7; + jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 6); + JOYPAD_IO.directions = 0xfff7; + jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 12; + + /* Update joypad 1 */ + JOYPAD_IO.directions = 0xffef; + jp_joypads[1] = ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 - 2); + JOYPAD_IO.directions = 0xffef; + jp_joypads[1] |= ((~(JOYPAD_IO.directions)) >> 12) & 15; + + JOYPAD_IO.directions = 0xffdf; + jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16); + JOYPAD_IO.directions = 0xffdf; + jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 4; + + JOYPAD_IO.directions = 0xffbf; + jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 2); + JOYPAD_IO.directions = 0xffbf; + jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 8; + + JOYPAD_IO.directions = 0xff7f; + jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 4); + JOYPAD_IO.directions = 0xff7f; + jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 12; } #endif /* SDL_JOYSTICK_MINT */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/os2/SDL_sysjoystick.c b/src/joystick/os2/SDL_sysjoystick.c index 15dca4eb7..dd8dc699d 100644 --- a/src/joystick/os2/SDL_sysjoystick.c +++ b/src/joystick/os2/SDL_sysjoystick.c @@ -38,15 +38,15 @@ #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" -HFILE hJoyPort = NULL; /* Joystick GAME$ Port Address */ -#define MAX_JOYSTICKS 2 /* Maximum of two joysticks */ -#define MAX_AXES 4 /* each joystick can have up to 4 axes */ -#define MAX_BUTTONS 8 /* 8 buttons */ -#define MAX_HATS 0 /* 0 hats - OS/2 doesn't support it */ -#define MAX_BALLS 0 /* and 0 balls - OS/2 doesn't support it */ -#define AXIS_MIN -32768 /* minimum value for axes coordinate */ -#define AXIS_MAX 32767 /* maximum value for axes coordinate */ -#define MAX_JOYNAME 128 /* Joystick name may have 128 characters */ +HFILE hJoyPort = NULL; /* Joystick GAME$ Port Address */ +#define MAX_JOYSTICKS 2 /* Maximum of two joysticks */ +#define MAX_AXES 4 /* each joystick can have up to 4 axes */ +#define MAX_BUTTONS 8 /* 8 buttons */ +#define MAX_HATS 0 /* 0 hats - OS/2 doesn't support it */ +#define MAX_BALLS 0 /* and 0 balls - OS/2 doesn't support it */ +#define AXIS_MIN -32768 /* minimum value for axes coordinate */ +#define AXIS_MAX 32767 /* maximum value for axes coordinate */ +#define MAX_JOYNAME 128 /* Joystick name may have 128 characters */ /* limit axes to 256 possible positions to filter out noise */ #define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256) /* Calc Button Flag for buttons A to D */ @@ -55,16 +55,16 @@ HFILE hJoyPort = NULL; /* Joystick GAME$ Port Address */ /* Joystick data... hold information about detected devices */ typedef struct SYS_JoyData_s { -Sint8 id; // Device ID -char szDeviceName[MAX_JOYNAME]; // Device Name -char axes; // Number of axes -char buttons; // Number of buttons -char hats; // Number of buttons -char balls; // Number of buttons -int axes_min[MAX_AXES]; // minimum callibration value for axes -int axes_med[MAX_AXES]; // medium callibration value for axes -int axes_max[MAX_AXES]; // maximum callibration value for axes -int buttoncalc[4]; // Used for buttons 5, 6, 7 and 8. + Sint8 id; // Device ID + char szDeviceName[MAX_JOYNAME]; // Device Name + char axes; // Number of axes + char buttons; // Number of buttons + char hats; // Number of buttons + char balls; // Number of buttons + int axes_min[MAX_AXES]; // minimum callibration value for axes + int axes_med[MAX_AXES]; // medium callibration value for axes + int axes_max[MAX_AXES]; // maximum callibration value for axes + int buttoncalc[4]; // Used for buttons 5, 6, 7 and 8. } SYS_JoyData_t, *SYS_JoyData_p; SYS_JoyData_t SYS_JoyData[MAX_JOYSTICKS]; @@ -73,30 +73,30 @@ SYS_JoyData_t SYS_JoyData[MAX_JOYSTICKS]; /* Structure used to convert data from OS/2 driver format to SDL format */ struct joystick_hwdata { -Sint8 id; -struct _transaxes - { - int offset; /* Center Offset */ - float scale1; /* Center to left/up Scale */ - float scale2; /* Center to right/down Scale */ - } transaxes[MAX_AXES]; + Sint8 id; + struct _transaxes + { + int offset; /* Center Offset */ + float scale1; /* Center to left/up Scale */ + float scale2; /* Center to right/down Scale */ + } transaxes[MAX_AXES]; }; /* Structure used to get values from Joystick Environment Variable */ struct _joycfg { -char name[MAX_JOYNAME]; -unsigned int axes; -unsigned int buttons; -unsigned int hats; -unsigned int balls; + char name[MAX_JOYNAME]; + unsigned int axes; + unsigned int buttons; + unsigned int hats; + unsigned int balls; }; /* OS/2 Implementation Function Prototypes */ -APIRET joyPortOpen(HFILE * hGame); -void joyPortClose(HFILE * hGame); -int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars); -int joyGetEnv(struct _joycfg * joydata); +APIRET joyPortOpen (HFILE * hGame); +void joyPortClose (HFILE * hGame); +int joyGetData (char *joyenv, char *name, char stopchar, size_t maxchars); +int joyGetEnv (struct _joycfg *joydata); @@ -106,214 +106,228 @@ int joyGetEnv(struct _joycfg * joydata); /* joysticks. Joystick 0 should be the system default joystick. */ /* It should return 0, or -1 on an unrecoverable fatal error. */ /************************************************************************/ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { -APIRET rc; /* Generic OS/2 return code */ -GAME_PORT_STRUCT stJoyStatus; /* Joystick Status Structure */ -GAME_PARM_STRUCT stGameParms; /* Joystick Parameter Structure */ -GAME_CALIB_STRUCT stGameCalib; /* Calibration Struct */ -ULONG ulDataLen; /* Size of data */ -ULONG ulLastTick; /* Tick Counter for timing operations */ -Uint8 maxdevs; /* Maximum number of devices */ -Uint8 numdevs; /* Number of present devices */ -Uint8 maxbut; /* Maximum number of buttons... */ -Uint8 i; /* Temporary Count Vars */ -Uint8 ucNewJoystickMask; /* Mask for Joystick Detection */ -struct _joycfg joycfg; /* Joy Configuration from envvar */ + APIRET rc; /* Generic OS/2 return code */ + GAME_PORT_STRUCT stJoyStatus; /* Joystick Status Structure */ + GAME_PARM_STRUCT stGameParms; /* Joystick Parameter Structure */ + GAME_CALIB_STRUCT stGameCalib; /* Calibration Struct */ + ULONG ulDataLen; /* Size of data */ + ULONG ulLastTick; /* Tick Counter for timing operations */ + Uint8 maxdevs; /* Maximum number of devices */ + Uint8 numdevs; /* Number of present devices */ + Uint8 maxbut; /* Maximum number of buttons... */ + Uint8 i; /* Temporary Count Vars */ + Uint8 ucNewJoystickMask; /* Mask for Joystick Detection */ + struct _joycfg joycfg; /* Joy Configuration from envvar */ /* Get Max Number of Devices */ -rc = joyPortOpen(&hJoyPort); /* Open GAME$ port */ -if (rc != 0) return 0; /* Cannot open... report no joystick */ -ulDataLen = sizeof(stGameParms); -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_PARMS, - NULL, 0, NULL, &stGameParms, ulDataLen, &ulDataLen); /* Ask device info */ -if (rc != 0) - { - joyPortClose(&hJoyPort); - SDL_SetError("Could not read joystick port."); - return -1; - } -if (stGameParms.useA != 0) maxdevs++; -if (stGameParms.useB != 0) maxdevs++; -if ( maxdevs > MAX_JOYSTICKS ) maxdevs = MAX_JOYSTICKS; + rc = joyPortOpen (&hJoyPort); /* Open GAME$ port */ + if (rc != 0) + return 0; /* Cannot open... report no joystick */ + ulDataLen = sizeof (stGameParms); + rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_GET_PARMS, NULL, 0, NULL, &stGameParms, ulDataLen, &ulDataLen); /* Ask device info */ + if (rc != 0) { + joyPortClose (&hJoyPort); + SDL_SetError ("Could not read joystick port."); + return -1; + } + if (stGameParms.useA != 0) + maxdevs++; + if (stGameParms.useB != 0) + maxdevs++; + if (maxdevs > MAX_JOYSTICKS) + maxdevs = MAX_JOYSTICKS; /* Defines min/max axes values (callibration) */ -ulDataLen = sizeof(stGameCalib); -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_CALIB, - NULL, 0, NULL, &stGameCalib, ulDataLen, &ulDataLen); -if (rc != 0) - { - joyPortClose(&hJoyPort); - SDL_SetError("Could not read callibration data."); - return -1; - } + ulDataLen = sizeof (stGameCalib); + rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_GET_CALIB, + NULL, 0, NULL, &stGameCalib, ulDataLen, &ulDataLen); + if (rc != 0) { + joyPortClose (&hJoyPort); + SDL_SetError ("Could not read callibration data."); + return -1; + } /* Determine how many joysticks are active */ -numdevs = 0; /* Points no device */ -ucNewJoystickMask = 0x0F; /* read all 4 joystick axis */ -ulDataLen = sizeof(ucNewJoystickMask); -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_RESET, - &ucNewJoystickMask, ulDataLen, &ulDataLen, NULL, 0, NULL); -if (rc == 0) - { - ulDataLen = sizeof(stJoyStatus); - rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET, - NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen); - if (rc != 0) - { - joyPortClose(&hJoyPort); - SDL_SetError("Could not call joystick port."); - return -1; - } - ulLastTick = stJoyStatus.ulJs_Ticks; - while (stJoyStatus.ulJs_Ticks == ulLastTick) - { - rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET, - NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen); - } - if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) numdevs++; - if (((stJoyStatus.ucJs_JoyStickMask >> 2) & 0x03) > 0) numdevs++; - } - -if (numdevs>maxdevs) numdevs=maxdevs; + numdevs = 0; /* Points no device */ + ucNewJoystickMask = 0x0F; /* read all 4 joystick axis */ + ulDataLen = sizeof (ucNewJoystickMask); + rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_PORT_RESET, + &ucNewJoystickMask, ulDataLen, &ulDataLen, NULL, 0, + NULL); + if (rc == 0) { + ulDataLen = sizeof (stJoyStatus); + rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET, + NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen); + if (rc != 0) { + joyPortClose (&hJoyPort); + SDL_SetError ("Could not call joystick port."); + return -1; + } + ulLastTick = stJoyStatus.ulJs_Ticks; + while (stJoyStatus.ulJs_Ticks == ulLastTick) { + rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET, + NULL, 0, NULL, &stJoyStatus, ulDataLen, + &ulDataLen); + } + if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) + numdevs++; + if (((stJoyStatus.ucJs_JoyStickMask >> 2) & 0x03) > 0) + numdevs++; + } + + if (numdevs > maxdevs) + numdevs = maxdevs; /* If *any* joystick was detected... Let's configure SDL for them */ -if (numdevs > 0) - { - /* Verify if it is a "user defined" joystick */ - if (joyGetEnv(&joycfg)) - { - GAME_3POS_STRUCT * axis[4]; - axis[0] = &stGameCalib.Ax; - axis[1] = &stGameCalib.Ay; - axis[2] = &stGameCalib.Bx; - axis[3] = &stGameCalib.By; - /* Say it has one device only (user defined is always one device only) */ - numdevs = 1; - /* Define Device 0 as... */ - SYS_JoyData[0].id=0; - /* Define Number of Axes... up to 4 */ - if (joycfg.axes>MAX_AXES) joycfg.axes = MAX_AXES; - SYS_JoyData[0].axes = joycfg.axes; - /* Define number of buttons... 8 if 2 axes, 6 if 3 axes and 4 if 4 axes */ - maxbut = MAX_BUTTONS; - if (joycfg.axes>2) maxbut-=((joycfg.axes-2)<<1); /* MAX_BUTTONS - 2*(axes-2) */ - if (joycfg.buttons > maxbut) joycfg.buttons = maxbut; - SYS_JoyData[0].buttons = joycfg.buttons; - /* Define number of hats */ - if (joycfg.hats > MAX_HATS) joycfg.hats = MAX_HATS; - SYS_JoyData[0].hats = joycfg.hats; - /* Define number of balls */ - if (joycfg.balls > MAX_BALLS) joycfg.balls = MAX_BALLS; - SYS_JoyData[0].balls = joycfg.balls; - /* Initialize Axes Callibration Values */ - for (i=0; ilower; - SYS_JoyData[0].axes_med[i] = axis[i]->centre; - SYS_JoyData[0].axes_max[i] = axis[i]->upper; - } - /* Initialize Buttons 5 to 8 structures */ - if (joycfg.buttons>=5) SYS_JoyData[0].buttoncalc[0]=((axis[2]->lower+axis[3]->centre)>>1); - if (joycfg.buttons>=6) SYS_JoyData[0].buttoncalc[1]=((axis[3]->lower+axis[3]->centre)>>1); - if (joycfg.buttons>=7) SYS_JoyData[0].buttoncalc[2]=((axis[2]->upper+axis[3]->centre)>>1); - if (joycfg.buttons>=8) SYS_JoyData[0].buttoncalc[3]=((axis[3]->upper+axis[3]->centre)>>1); - /* Intialize Joystick Name */ - SDL_strlcpy (SYS_JoyData[0].szDeviceName,joycfg.name, SDL_arraysize(SYS_JoyData[0].szDeviceName)); - } - /* Default Init ... autoconfig */ - else - { - /* if two devices were detected... configure as Joy1 4 axis and Joy2 2 axis */ - if (numdevs==2) - { - /* Define Device 0 as 4 axes, 4 buttons */ - SYS_JoyData[0].id=0; - SYS_JoyData[0].axes = 4; - SYS_JoyData[0].buttons = 4; - SYS_JoyData[0].hats = 0; - SYS_JoyData[0].balls = 0; - SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower; - SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre; - SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper; - SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower; - SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre; - SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper; - SYS_JoyData[0].axes_min[2] = stGameCalib.Bx.lower; - SYS_JoyData[0].axes_med[2] = stGameCalib.Bx.centre; - SYS_JoyData[0].axes_max[2] = stGameCalib.Bx.upper; - SYS_JoyData[0].axes_min[3] = stGameCalib.By.lower; - SYS_JoyData[0].axes_med[3] = stGameCalib.By.centre; - SYS_JoyData[0].axes_max[3] = stGameCalib.By.upper; - /* Define Device 1 as 2 axes, 2 buttons */ - SYS_JoyData[1].id=1; - SYS_JoyData[1].axes = 2; - SYS_JoyData[1].buttons = 2; - SYS_JoyData[1].hats = 0; - SYS_JoyData[1].balls = 0; - SYS_JoyData[1].axes_min[0] = stGameCalib.Bx.lower; - SYS_JoyData[1].axes_med[0] = stGameCalib.Bx.centre; - SYS_JoyData[1].axes_max[0] = stGameCalib.Bx.upper; - SYS_JoyData[1].axes_min[1] = stGameCalib.By.lower; - SYS_JoyData[1].axes_med[1] = stGameCalib.By.centre; - SYS_JoyData[1].axes_max[1] = stGameCalib.By.upper; - } - /* One joystick only? */ - else - { - /* If it is joystick A... */ - if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) - { - /* Define Device 0 as 2 axes, 4 buttons */ - SYS_JoyData[0].id=0; - SYS_JoyData[0].axes = 2; - SYS_JoyData[0].buttons = 4; - SYS_JoyData[0].hats = 0; - SYS_JoyData[0].balls = 0; - SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower; - SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre; - SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper; - SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower; - SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre; - SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper; - } - /* If not, it is joystick B */ - else - { - /* Define Device 1 as 2 axes, 2 buttons */ - SYS_JoyData[0].id=1; - SYS_JoyData[0].axes = 2; - SYS_JoyData[0].buttons = 2; - SYS_JoyData[0].hats = 0; - SYS_JoyData[0].balls = 0; - SYS_JoyData[0].axes_min[0] = stGameCalib.Bx.lower; - SYS_JoyData[0].axes_med[0] = stGameCalib.Bx.centre; - SYS_JoyData[0].axes_max[0] = stGameCalib.Bx.upper; - SYS_JoyData[0].axes_min[1] = stGameCalib.By.lower; - SYS_JoyData[0].axes_med[1] = stGameCalib.By.centre; - SYS_JoyData[0].axes_max[1] = stGameCalib.By.upper; - } - } - /* Hack to define Joystick Port Names */ - if ( numdevs > maxdevs ) numdevs = maxdevs; - for (i=0; i 0) { + /* Verify if it is a "user defined" joystick */ + if (joyGetEnv (&joycfg)) { + GAME_3POS_STRUCT *axis[4]; + axis[0] = &stGameCalib.Ax; + axis[1] = &stGameCalib.Ay; + axis[2] = &stGameCalib.Bx; + axis[3] = &stGameCalib.By; + /* Say it has one device only (user defined is always one device only) */ + numdevs = 1; + /* Define Device 0 as... */ + SYS_JoyData[0].id = 0; + /* Define Number of Axes... up to 4 */ + if (joycfg.axes > MAX_AXES) + joycfg.axes = MAX_AXES; + SYS_JoyData[0].axes = joycfg.axes; + /* Define number of buttons... 8 if 2 axes, 6 if 3 axes and 4 if 4 axes */ + maxbut = MAX_BUTTONS; + if (joycfg.axes > 2) + maxbut -= ((joycfg.axes - 2) << 1); /* MAX_BUTTONS - 2*(axes-2) */ + if (joycfg.buttons > maxbut) + joycfg.buttons = maxbut; + SYS_JoyData[0].buttons = joycfg.buttons; + /* Define number of hats */ + if (joycfg.hats > MAX_HATS) + joycfg.hats = MAX_HATS; + SYS_JoyData[0].hats = joycfg.hats; + /* Define number of balls */ + if (joycfg.balls > MAX_BALLS) + joycfg.balls = MAX_BALLS; + SYS_JoyData[0].balls = joycfg.balls; + /* Initialize Axes Callibration Values */ + for (i = 0; i < joycfg.axes; i++) { + SYS_JoyData[0].axes_min[i] = axis[i]->lower; + SYS_JoyData[0].axes_med[i] = axis[i]->centre; + SYS_JoyData[0].axes_max[i] = axis[i]->upper; + } + /* Initialize Buttons 5 to 8 structures */ + if (joycfg.buttons >= 5) + SYS_JoyData[0].buttoncalc[0] = + ((axis[2]->lower + axis[3]->centre) >> 1); + if (joycfg.buttons >= 6) + SYS_JoyData[0].buttoncalc[1] = + ((axis[3]->lower + axis[3]->centre) >> 1); + if (joycfg.buttons >= 7) + SYS_JoyData[0].buttoncalc[2] = + ((axis[2]->upper + axis[3]->centre) >> 1); + if (joycfg.buttons >= 8) + SYS_JoyData[0].buttoncalc[3] = + ((axis[3]->upper + axis[3]->centre) >> 1); + /* Intialize Joystick Name */ + SDL_strlcpy (SYS_JoyData[0].szDeviceName, joycfg.name, + SDL_arraysize (SYS_JoyData[0].szDeviceName)); + } + /* Default Init ... autoconfig */ + else { + /* if two devices were detected... configure as Joy1 4 axis and Joy2 2 axis */ + if (numdevs == 2) { + /* Define Device 0 as 4 axes, 4 buttons */ + SYS_JoyData[0].id = 0; + SYS_JoyData[0].axes = 4; + SYS_JoyData[0].buttons = 4; + SYS_JoyData[0].hats = 0; + SYS_JoyData[0].balls = 0; + SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower; + SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre; + SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper; + SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower; + SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre; + SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper; + SYS_JoyData[0].axes_min[2] = stGameCalib.Bx.lower; + SYS_JoyData[0].axes_med[2] = stGameCalib.Bx.centre; + SYS_JoyData[0].axes_max[2] = stGameCalib.Bx.upper; + SYS_JoyData[0].axes_min[3] = stGameCalib.By.lower; + SYS_JoyData[0].axes_med[3] = stGameCalib.By.centre; + SYS_JoyData[0].axes_max[3] = stGameCalib.By.upper; + /* Define Device 1 as 2 axes, 2 buttons */ + SYS_JoyData[1].id = 1; + SYS_JoyData[1].axes = 2; + SYS_JoyData[1].buttons = 2; + SYS_JoyData[1].hats = 0; + SYS_JoyData[1].balls = 0; + SYS_JoyData[1].axes_min[0] = stGameCalib.Bx.lower; + SYS_JoyData[1].axes_med[0] = stGameCalib.Bx.centre; + SYS_JoyData[1].axes_max[0] = stGameCalib.Bx.upper; + SYS_JoyData[1].axes_min[1] = stGameCalib.By.lower; + SYS_JoyData[1].axes_med[1] = stGameCalib.By.centre; + SYS_JoyData[1].axes_max[1] = stGameCalib.By.upper; + } + /* One joystick only? */ + else { + /* If it is joystick A... */ + if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) { + /* Define Device 0 as 2 axes, 4 buttons */ + SYS_JoyData[0].id = 0; + SYS_JoyData[0].axes = 2; + SYS_JoyData[0].buttons = 4; + SYS_JoyData[0].hats = 0; + SYS_JoyData[0].balls = 0; + SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower; + SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre; + SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper; + SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower; + SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre; + SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper; + } + /* If not, it is joystick B */ + else { + /* Define Device 1 as 2 axes, 2 buttons */ + SYS_JoyData[0].id = 1; + SYS_JoyData[0].axes = 2; + SYS_JoyData[0].buttons = 2; + SYS_JoyData[0].hats = 0; + SYS_JoyData[0].balls = 0; + SYS_JoyData[0].axes_min[0] = stGameCalib.Bx.lower; + SYS_JoyData[0].axes_med[0] = stGameCalib.Bx.centre; + SYS_JoyData[0].axes_max[0] = stGameCalib.Bx.upper; + SYS_JoyData[0].axes_min[1] = stGameCalib.By.lower; + SYS_JoyData[0].axes_med[1] = stGameCalib.By.centre; + SYS_JoyData[0].axes_max[1] = stGameCalib.By.upper; } - } + } + /* Hack to define Joystick Port Names */ + if (numdevs > maxdevs) + numdevs = maxdevs; + for (i = 0; i < numdevs; i++) + SDL_snprintf (SYS_JoyData[i].szDeviceName, + SDL_arraysize (SYS_JoyData[i].szDeviceName), + "Default Joystick %c", 'A' + SYS_JoyData[i].id); + + } + } /* Return the number of devices found */ -return(numdevs); + return (numdevs); } /***********************************************************/ /* Function to get the device-dependent name of a joystick */ /***********************************************************/ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { /* No need to verify if device exists, already done in upper layer */ -return(SYS_JoyData[index].szDeviceName); + return (SYS_JoyData[index].szDeviceName); } @@ -324,51 +338,51 @@ return(SYS_JoyData[index].szDeviceName); /* This should fill the nbuttons and naxes fields of the joystick structure. */ /* It returns 0, or -1 if there is an error. */ /******************************************************************************/ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { -int index; /* Index shortcut for index in joystick structure */ -int i; /* Generic Counter */ + int index; /* Index shortcut for index in joystick structure */ + int i; /* Generic Counter */ /* allocate memory for system specific hardware data */ -joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); -if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); - } + joystick->hwdata = + (struct joystick_hwdata *) SDL_malloc (sizeof (*joystick->hwdata)); + if (joystick->hwdata == NULL) { + SDL_OutOfMemory (); + return (-1); + } /* Reset Hardware Data */ -SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); + SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); /* ShortCut Pointer */ -index = joystick->index; + index = joystick->index; /* Define offsets and scales for all axes */ -joystick->hwdata->id = SYS_JoyData[index].id; -for ( i = 0; i < MAX_AXES; ++i ) - { - if ( (i<2) || i < SYS_JoyData[index].axes ) - { - joystick->hwdata->transaxes[i].offset = ((AXIS_MAX + AXIS_MIN)>>1) - SYS_JoyData[index].axes_med[i]; - //joystick->hwdata->transaxes[i].scale = (float)((AXIS_MAX - AXIS_MIN)/(SYS_JoyData[index].axes_max[i]-SYS_JoyData[index].axes_min[i])); - joystick->hwdata->transaxes[i].scale1 = (float)abs((AXIS_MIN/SYS_JoyData[index].axes_min[i])); - joystick->hwdata->transaxes[i].scale2 = (float)abs((AXIS_MAX/SYS_JoyData[index].axes_max[i])); - } - else - { - joystick->hwdata->transaxes[i].offset = 0; - //joystick->hwdata->transaxes[i].scale = 1.0; /* Just in case */ - joystick->hwdata->transaxes[i].scale1 = 1.0; /* Just in case */ - joystick->hwdata->transaxes[i].scale2 = 1.0; /* Just in case */ - } - } + joystick->hwdata->id = SYS_JoyData[index].id; + for (i = 0; i < MAX_AXES; ++i) { + if ((i < 2) || i < SYS_JoyData[index].axes) { + joystick->hwdata->transaxes[i].offset = + ((AXIS_MAX + AXIS_MIN) >> 1) - SYS_JoyData[index].axes_med[i]; + //joystick->hwdata->transaxes[i].scale = (float)((AXIS_MAX - AXIS_MIN)/(SYS_JoyData[index].axes_max[i]-SYS_JoyData[index].axes_min[i])); + joystick->hwdata->transaxes[i].scale1 = + (float) abs ((AXIS_MIN / SYS_JoyData[index].axes_min[i])); + joystick->hwdata->transaxes[i].scale2 = + (float) abs ((AXIS_MAX / SYS_JoyData[index].axes_max[i])); + } else { + joystick->hwdata->transaxes[i].offset = 0; + //joystick->hwdata->transaxes[i].scale = 1.0; /* Just in case */ + joystick->hwdata->transaxes[i].scale1 = 1.0; /* Just in case */ + joystick->hwdata->transaxes[i].scale2 = 1.0; /* Just in case */ + } + } /* fill nbuttons, naxes, and nhats fields */ -joystick->nbuttons = SYS_JoyData[index].buttons; -joystick->naxes = SYS_JoyData[index].axes; + joystick->nbuttons = SYS_JoyData[index].buttons; + joystick->naxes = SYS_JoyData[index].axes; /* joystick->nhats = SYS_JoyData[index].hats; */ -joystick->nhats = 0; /* No support for hats at this time */ + joystick->nhats = 0; /* No support for hats at this time */ /* joystick->nballs = SYS_JoyData[index].balls; */ -joystick->nballs = 0; /* No support for balls at this time */ -return 0; + joystick->nballs = 0; /* No support for balls at this time */ + return 0; } @@ -379,131 +393,132 @@ return 0; /* but instead should call SDL_PrivateJoystick*() to deliver events */ /* and update joystick device state. */ /***************************************************************************/ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { -APIRET rc; /* Generic OS/2 return code */ -int index; /* index shortcurt to joystick index */ -int i; /* Generic counter */ -int normbut; /* Number of buttons reported by joystick */ -int corr; /* Correction for button names */ -Sint16 value, change; /* Values used to update axis values */ -struct _transaxes *transaxes; /* Shortcut for Correction structure */ -Uint32 pos[MAX_AXES]; /* Vector to inform the Axis status */ -ULONG ulDataLen; /* Size of data */ -GAME_STATUS_STRUCT stGameStatus; /* Joystick Status Structure */ - -ulDataLen = sizeof(stGameStatus); -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_STATUS, - NULL, 0, NULL, &stGameStatus, ulDataLen, &ulDataLen); -if (rc != 0) - { - SDL_SetError("Could not read joystick status."); - return; /* Could not read data */ - } + APIRET rc; /* Generic OS/2 return code */ + int index; /* index shortcurt to joystick index */ + int i; /* Generic counter */ + int normbut; /* Number of buttons reported by joystick */ + int corr; /* Correction for button names */ + Sint16 value, change; /* Values used to update axis values */ + struct _transaxes *transaxes; /* Shortcut for Correction structure */ + Uint32 pos[MAX_AXES]; /* Vector to inform the Axis status */ + ULONG ulDataLen; /* Size of data */ + GAME_STATUS_STRUCT stGameStatus; /* Joystick Status Structure */ + + ulDataLen = sizeof (stGameStatus); + rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_GET_STATUS, + NULL, 0, NULL, &stGameStatus, ulDataLen, &ulDataLen); + if (rc != 0) { + SDL_SetError ("Could not read joystick status."); + return; /* Could not read data */ + } /* Shortcut pointer */ -index = joystick->index; + index = joystick->index; /* joystick motion events */ -if (SYS_JoyData[index].id == 0) - { - pos[0] = stGameStatus.curdata.A.x; - pos[1] = stGameStatus.curdata.A.y; - if (SYS_JoyData[index].axes >= 3) pos[2] = stGameStatus.curdata.B.x; - else pos[2]=0; - if (SYS_JoyData[index].axes >= 4) pos[3] = stGameStatus.curdata.B.y; - else pos[3]=0; - pos[4]=0; /* OS/2 basic drivers do not support more than 4 axes joysticks */ - pos[5]=0; - } -else if (SYS_JoyData[index].id == 1) - { - pos[0] = stGameStatus.curdata.B.x; - pos[1] = stGameStatus.curdata.B.y; - pos[2]=0; - pos[3]=0; - pos[4]=0; - pos[5]=0; - } + if (SYS_JoyData[index].id == 0) { + pos[0] = stGameStatus.curdata.A.x; + pos[1] = stGameStatus.curdata.A.y; + if (SYS_JoyData[index].axes >= 3) + pos[2] = stGameStatus.curdata.B.x; + else + pos[2] = 0; + if (SYS_JoyData[index].axes >= 4) + pos[3] = stGameStatus.curdata.B.y; + else + pos[3] = 0; + pos[4] = 0; /* OS/2 basic drivers do not support more than 4 axes joysticks */ + pos[5] = 0; + } else if (SYS_JoyData[index].id == 1) { + pos[0] = stGameStatus.curdata.B.x; + pos[1] = stGameStatus.curdata.B.y; + pos[2] = 0; + pos[3] = 0; + pos[4] = 0; + pos[5] = 0; + } /* Corrects the movements using the callibration */ -transaxes = joystick->hwdata->transaxes; -for (i = 0; i < joystick->naxes; i++) - { - value = pos[i] + transaxes[i].offset; - if (value<0) - { - value*=transaxes[i].scale1; - if (value>0) value = AXIS_MIN; - } - else - { - value*=transaxes[i].scale2; - if (value<0) value = AXIS_MAX; - } - change = (value - joystick->axes[i]); - if ( (change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD) ) - { - SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)value); - } - } + transaxes = joystick->hwdata->transaxes; + for (i = 0; i < joystick->naxes; i++) { + value = pos[i] + transaxes[i].offset; + if (value < 0) { + value *= transaxes[i].scale1; + if (value > 0) + value = AXIS_MIN; + } else { + value *= transaxes[i].scale2; + if (value < 0) + value = AXIS_MAX; + } + change = (value - joystick->axes[i]); + if ((change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD)) { + SDL_PrivateJoystickAxis (joystick, (Uint8) i, (Sint16) value); + } + } /* joystick button A to D events */ -if (SYS_JoyData[index].id == 1) corr = 2; -else corr = 0; -normbut=4; /* Number of normal buttons */ -if (joystick->nbuttonsnbuttons; -for ( i = corr; (i-corr) < normbut; ++i ) - { - /* - Button A: 1110 0000 - Button B: 1101 0000 - Button C: 1011 0000 - Button D: 0111 0000 - */ - if ( (~stGameStatus.curdata.butMask)>>4 & JOY_BUTTON_FLAG(i) ) - { - if ( ! joystick->buttons[i-corr] ) - { - SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_PRESSED); - } - } - else - { - if ( joystick->buttons[i-corr] ) - { - SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_RELEASED); - } - } - } + if (SYS_JoyData[index].id == 1) + corr = 2; + else + corr = 0; + normbut = 4; /* Number of normal buttons */ + if (joystick->nbuttons < normbut) + normbut = joystick->nbuttons; + for (i = corr; (i - corr) < normbut; ++i) { + /* + Button A: 1110 0000 + Button B: 1101 0000 + Button C: 1011 0000 + Button D: 0111 0000 + */ + if ((~stGameStatus.curdata.butMask) >> 4 & JOY_BUTTON_FLAG (i)) { + if (!joystick->buttons[i - corr]) { + SDL_PrivateJoystickButton (joystick, (Uint8) (i - corr), + SDL_PRESSED); + } + } else { + if (joystick->buttons[i - corr]) { + SDL_PrivateJoystickButton (joystick, (Uint8) (i - corr), + SDL_RELEASED); + } + } + } /* Joystick button E to H buttons */ - /* - Button E: Axis 2 X Left - Button F: Axis 2 Y Up - Button G: Axis 2 X Right - Button H: Axis 2 Y Down - */ -if (joystick->nbuttons>=5) - { - if (stGameStatus.curdata.B.x < SYS_JoyData[index].buttoncalc[0]) SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_PRESSED); - else SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_RELEASED); - } -if (joystick->nbuttons>=6) - { - if (stGameStatus.curdata.B.y < SYS_JoyData[index].buttoncalc[1]) SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_PRESSED); - else SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_RELEASED); - } -if (joystick->nbuttons>=7) - { - if (stGameStatus.curdata.B.x > SYS_JoyData[index].buttoncalc[2]) SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_PRESSED); - else SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_RELEASED); - } -if (joystick->nbuttons>=8) - { - if (stGameStatus.curdata.B.y > SYS_JoyData[index].buttoncalc[3]) SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_PRESSED); - else SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_RELEASED); - } + /* + Button E: Axis 2 X Left + Button F: Axis 2 Y Up + Button G: Axis 2 X Right + Button H: Axis 2 Y Down + */ + if (joystick->nbuttons >= 5) { + if (stGameStatus.curdata.B.x < SYS_JoyData[index].buttoncalc[0]) + SDL_PrivateJoystickButton (joystick, (Uint8) 4, SDL_PRESSED); + else + SDL_PrivateJoystickButton (joystick, (Uint8) 4, SDL_RELEASED); + } + if (joystick->nbuttons >= 6) { + if (stGameStatus.curdata.B.y < SYS_JoyData[index].buttoncalc[1]) + SDL_PrivateJoystickButton (joystick, (Uint8) 5, SDL_PRESSED); + else + SDL_PrivateJoystickButton (joystick, (Uint8) 5, SDL_RELEASED); + } + if (joystick->nbuttons >= 7) { + if (stGameStatus.curdata.B.x > SYS_JoyData[index].buttoncalc[2]) + SDL_PrivateJoystickButton (joystick, (Uint8) 6, SDL_PRESSED); + else + SDL_PrivateJoystickButton (joystick, (Uint8) 6, SDL_RELEASED); + } + if (joystick->nbuttons >= 8) { + if (stGameStatus.curdata.B.y > SYS_JoyData[index].buttoncalc[3]) + SDL_PrivateJoystickButton (joystick, (Uint8) 7, SDL_PRESSED); + else + SDL_PrivateJoystickButton (joystick, (Uint8) 7, SDL_RELEASED); + } /* joystick hat events */ /* Not Supported under OS/2 */ @@ -516,13 +531,13 @@ if (joystick->nbuttons>=8) /******************************************/ /* Function to close a joystick after use */ /******************************************/ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { -if (joystick->hwdata != NULL) - { - /* free system specific hardware data */ - SDL_free(joystick->hwdata); - } + if (joystick->hwdata != NULL) { + /* free system specific hardware data */ + SDL_free (joystick->hwdata); + } } @@ -530,9 +545,10 @@ if (joystick->hwdata != NULL) /********************************************************************/ /* Function to perform any system-specific joystick related cleanup */ /********************************************************************/ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { -joyPortClose(&hJoyPort); + joyPortClose (&hJoyPort); } @@ -547,42 +563,43 @@ joyPortClose(&hJoyPort); /*****************************************/ /* Open Joystick Port, if not opened yet */ /*****************************************/ -APIRET joyPortOpen(HFILE * hGame) +APIRET +joyPortOpen (HFILE * hGame) { -APIRET rc; /* Generic Return Code */ -ULONG ulAction; /* ? */ -ULONG ulVersion; /* Version of joystick driver */ -ULONG ulDataLen; /* Size of version data */ + APIRET rc; /* Generic Return Code */ + ULONG ulAction; /* ? */ + ULONG ulVersion; /* Version of joystick driver */ + ULONG ulDataLen; /* Size of version data */ /* Verifies if joyport is not already open... */ -if (*hGame != NULL) return 0; + if (*hGame != NULL) + return 0; /* Open GAME$ for read */ -rc = DosOpen((PSZ)GAMEPDDNAME, hGame, &ulAction, 0, FILE_READONLY, - FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL); -if (rc != 0) - { - SDL_SetError("Could not open Joystick Port."); - return -1; - } - + rc = DosOpen ((PSZ) GAMEPDDNAME, hGame, &ulAction, 0, FILE_READONLY, + FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, + NULL); + if (rc != 0) { + SDL_SetError ("Could not open Joystick Port."); + return -1; + } + /* Get Joystick Driver Version... must be 2.0 or higher */ -ulVersion = 0; -ulDataLen = sizeof(ulVersion); -rc = DosDevIOCtl( *hGame, IOCTL_CAT_USER, GAME_GET_VERSION, - NULL, 0, NULL, &ulVersion, ulDataLen, &ulDataLen); -if (rc != 0) - { - joyPortClose(hGame); - SDL_SetError("Could not get Joystick Driver version."); - return -1; - } -if (ulVersion < GAME_VERSION) - { - joyPortClose(hGame); - SDL_SetError("Driver too old. At least IBM driver version 2.0 required."); - return -1; - } -return 0; + ulVersion = 0; + ulDataLen = sizeof (ulVersion); + rc = DosDevIOCtl (*hGame, IOCTL_CAT_USER, GAME_GET_VERSION, + NULL, 0, NULL, &ulVersion, ulDataLen, &ulDataLen); + if (rc != 0) { + joyPortClose (hGame); + SDL_SetError ("Could not get Joystick Driver version."); + return -1; + } + if (ulVersion < GAME_VERSION) { + joyPortClose (hGame); + SDL_SetError + ("Driver too old. At least IBM driver version 2.0 required."); + return -1; + } + return 0; } @@ -590,10 +607,12 @@ return 0; /****************************/ /* Close JoyPort, if opened */ /****************************/ -void joyPortClose(HFILE * hGame) +void +joyPortClose (HFILE * hGame) { -if (*hGame != NULL) DosClose(*hGame); -*hGame = NULL; + if (*hGame != NULL) + DosClose (*hGame); + *hGame = NULL; } @@ -601,37 +620,52 @@ if (*hGame != NULL) DosClose(*hGame); /***************************/ /* Get SDL Joystick EnvVar */ /***************************/ -int joyGetEnv(struct _joycfg * joydata) +int +joyGetEnv (struct _joycfg *joydata) { -char *joyenv; /* Pointer to tested character */ -char tempnumber[5]; /* Temporary place to put numeric texts */ + char *joyenv; /* Pointer to tested character */ + char tempnumber[5]; /* Temporary place to put numeric texts */ -joyenv = SDL_getenv("SDL_OS2_JOYSTICK"); -if (joyenv == NULL) return 0; + joyenv = SDL_getenv ("SDL_OS2_JOYSTICK"); + if (joyenv == NULL) + return 0; /* Joystick Environment is defined! */ -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */ + while (*joyenv == ' ' && *joyenv != 0) + joyenv++; /* jump spaces... */ /* If the string name starts with '... get if fully */ -if (*joyenv=='\'') joyenv+=joyGetData(++joyenv,joydata->name,'\'',sizeof(joydata->name)); + if (*joyenv == '\'') + joyenv += + joyGetData (++joyenv, joydata->name, '\'', + sizeof (joydata->name)); /* If not, get it until the next space */ -else if (*joyenv=='\"') joyenv+=joyGetData(++joyenv,joydata->name,'\"',sizeof(joydata->name)); -else joyenv+=joyGetData(joyenv,joydata->name,' ',sizeof(joydata->name)); + else if (*joyenv == '\"') + joyenv += + joyGetData (++joyenv, joydata->name, '\"', + sizeof (joydata->name)); + else + joyenv += + joyGetData (joyenv, joydata->name, ' ', sizeof (joydata->name)); /* Now get the number of axes */ -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */ -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber)); -joydata->axes = atoi(tempnumber); + while (*joyenv == ' ' && *joyenv != 0) + joyenv++; /* jump spaces... */ + joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); + joydata->axes = atoi (tempnumber); /* Now get the number of buttons */ -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */ -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber)); -joydata->buttons = atoi(tempnumber); + while (*joyenv == ' ' && *joyenv != 0) + joyenv++; /* jump spaces... */ + joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); + joydata->buttons = atoi (tempnumber); /* Now get the number of hats */ -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */ -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber)); -joydata->hats = atoi(tempnumber); + while (*joyenv == ' ' && *joyenv != 0) + joyenv++; /* jump spaces... */ + joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); + joydata->hats = atoi (tempnumber); /* Now get the number of balls */ -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */ -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber)); -joydata->balls = atoi(tempnumber); -return 1; + while (*joyenv == ' ' && *joyenv != 0) + joyenv++; /* jump spaces... */ + joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); + joydata->balls = atoi (tempnumber); + return 1; } @@ -640,29 +674,28 @@ return 1; /* Get a text from in the string starting in joyenv until it finds */ /* the stopchar or maxchars is reached. The result is placed in name. */ /************************************************************************/ -int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars) +int +joyGetData (char *joyenv, char *name, char stopchar, size_t maxchars) { -char *nameptr; /* Pointer to the selected character */ -int chcnt=0; /* Count how many characters where copied */ - -nameptr=name; -while (*joyenv!=stopchar && *joyenv!=0) - { - if (nameptr<(name+(maxchars-1))) - { - *nameptr = *joyenv; /* Only copy if smaller than maximum */ - nameptr++; - } - chcnt++; - joyenv++; - } -if (*joyenv==stopchar) - { - joyenv++; /* Jump stopchar */ - chcnt++; - } -*nameptr = 0; /* Mark last byte */ -return chcnt; + char *nameptr; /* Pointer to the selected character */ + int chcnt = 0; /* Count how many characters where copied */ + + nameptr = name; + while (*joyenv != stopchar && *joyenv != 0) { + if (nameptr < (name + (maxchars - 1))) { + *nameptr = *joyenv; /* Only copy if smaller than maximum */ + nameptr++; + } + chcnt++; + joyenv++; + } + if (*joyenv == stopchar) { + joyenv++; /* Jump stopchar */ + chcnt++; + } + *nameptr = 0; /* Mark last byte */ + return chcnt; } #endif /* SDL_JOYSTICK_OS2 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/os2/joyos2.h b/src/joystick/os2/joyos2.h index 29800106e..0ceace1bc 100644 --- a/src/joystick/os2/joyos2.h +++ b/src/joystick/os2/joyos2.h @@ -13,27 +13,28 @@ #define JOYOS2_H /****** GAMEPORT.SYS joystick definitions, start *****************************/ -#define GAME_VERSION 0x20 /* 2.0 First IBM version */ +#define GAME_VERSION 0x20 /* 2.0 First IBM version */ #define GAMEPDDNAME "GAME$ " #define IOCTL_CAT_USER 0x80 -#define GAME_PORT_GET 0x20 /* read GAMEPORT.SYS values */ -#define GAME_PORT_RESET 0x60 /* reset joystick mask with given value */ - -#pragma pack(1) /* pack structure size is 1 byte */ -typedef struct { /* GAMEPORT.SYS structure */ - USHORT usJs_AxCnt; /* Joystick_A X position */ - USHORT usJs_AyCnt; /* Joystick_A Y position */ - USHORT usJs_BxCnt; /* Joystick_B X position */ - USHORT usJs_ByCnt; /* Joystick_B Y position */ - USHORT usJs_ButtonA1Cnt; /* button A1 press count */ - USHORT usJs_ButtonA2Cnt; /* button A2 press count */ - USHORT usJs_ButtonB1Cnt; /* button B1 press count */ - USHORT usJs_ButtonB2Cnt; /* button B2 press count */ - UCHAR ucJs_JoyStickMask; /* mask of connected joystick pots */ - UCHAR ucJs_ButtonStatus; /* bits of switches down */ - ULONG ulJs_Ticks; /* joystick clock ticks */ +#define GAME_PORT_GET 0x20 /* read GAMEPORT.SYS values */ +#define GAME_PORT_RESET 0x60 /* reset joystick mask with given value */ + +#pragma pack(1) /* pack structure size is 1 byte */ +typedef struct +{ /* GAMEPORT.SYS structure */ + USHORT usJs_AxCnt; /* Joystick_A X position */ + USHORT usJs_AyCnt; /* Joystick_A Y position */ + USHORT usJs_BxCnt; /* Joystick_B X position */ + USHORT usJs_ByCnt; /* Joystick_B Y position */ + USHORT usJs_ButtonA1Cnt; /* button A1 press count */ + USHORT usJs_ButtonA2Cnt; /* button A2 press count */ + USHORT usJs_ButtonB1Cnt; /* button B1 press count */ + USHORT usJs_ButtonB2Cnt; /* button B2 press count */ + UCHAR ucJs_JoyStickMask; /* mask of connected joystick pots */ + UCHAR ucJs_ButtonStatus; /* bits of switches down */ + ULONG ulJs_Ticks; /* joystick clock ticks */ } GAME_PORT_STRUCT; -#pragma pack() /*reset to normal pack size */ +#pragma pack() /*reset to normal pack size */ /****** GAMEPORT.SYS joystick definitions, end *******************************/ @@ -70,31 +71,31 @@ typedef struct { /* GAMEPORT.SYS structure */ /****************************************************************************/ // 1-D position struct used for each axis -typedef SHORT GAME_POS; /* some data formats require signed values */ +typedef SHORT GAME_POS; /* some data formats require signed values */ // simple 2-D position for each joystick typedef struct { - GAME_POS x; - GAME_POS y; + GAME_POS x; + GAME_POS y; } GAME_2DPOS_STRUCT; // struct defining the instantaneous state of both sticks and all buttons typedef struct { - GAME_2DPOS_STRUCT A; - GAME_2DPOS_STRUCT B; - USHORT butMask; + GAME_2DPOS_STRUCT A; + GAME_2DPOS_STRUCT B; + USHORT butMask; } GAME_DATA_STRUCT; // struct to be used for calibration and digital response on each axis typedef struct { - GAME_POS lower; - GAME_POS centre; - GAME_POS upper; + GAME_POS lower; + GAME_POS centre; + GAME_POS upper; } GAME_3POS_STRUCT; /****************************************************************************/ @@ -104,11 +105,11 @@ GAME_3POS_STRUCT; // current data for all sticks as well as button counts since last read typedef struct { - GAME_DATA_STRUCT curdata; - USHORT b1cnt; - USHORT b2cnt; - USHORT b3cnt; - USHORT b4cnt; + GAME_DATA_STRUCT curdata; + USHORT b1cnt; + USHORT b2cnt; + USHORT b3cnt; + USHORT b4cnt; } GAME_STATUS_STRUCT; /****************************************************************************/ @@ -135,14 +136,14 @@ GAME_STATUS_STRUCT; // parameters defining the operation of the driver typedef struct { - USHORT useA; /* new bitmasks: see above */ - USHORT useB; - USHORT mode; /* see consts above */ - USHORT format; /* see consts above */ - USHORT sampDiv; /* samp freq = 32 / n */ - USHORT scale; /* scaling factor */ - USHORT res1; /* must be 0 */ - USHORT res2; /* must be 0 */ + USHORT useA; /* new bitmasks: see above */ + USHORT useB; + USHORT mode; /* see consts above */ + USHORT format; /* see consts above */ + USHORT sampDiv; /* samp freq = 32 / n */ + USHORT scale; /* scaling factor */ + USHORT res1; /* must be 0 */ + USHORT res2; /* must be 0 */ } GAME_PARM_STRUCT; /****************************************************************************/ @@ -154,10 +155,10 @@ GAME_PARM_STRUCT; // - lower limit on value to be considered in upper range typedef struct { - GAME_3POS_STRUCT Ax; - GAME_3POS_STRUCT Ay; - GAME_3POS_STRUCT Bx; - GAME_3POS_STRUCT By; + GAME_3POS_STRUCT Ax; + GAME_3POS_STRUCT Ay; + GAME_3POS_STRUCT Bx; + GAME_3POS_STRUCT By; } GAME_CALIB_STRUCT; /****************************************************************************/ @@ -166,12 +167,13 @@ GAME_CALIB_STRUCT; // struct defining the digital response values for all axes typedef struct { - GAME_3POS_STRUCT Ax; - GAME_3POS_STRUCT Ay; - GAME_3POS_STRUCT Bx; - GAME_3POS_STRUCT By; + GAME_3POS_STRUCT Ax; + GAME_3POS_STRUCT Ay; + GAME_3POS_STRUCT Bx; + GAME_3POS_STRUCT By; } GAME_DIGSET_STRUCT; /****************************************************************************/ #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/riscos/SDL_sysjoystick.c b/src/joystick/riscos/SDL_sysjoystick.c index ed8ac91cb..c15bd2623 100644 --- a/src/joystick/riscos/SDL_sysjoystick.c +++ b/src/joystick/riscos/SDL_sysjoystick.c @@ -41,9 +41,9 @@ #define JOYSTICK_READ 0x43F40 -struct joystick_hwdata +struct joystick_hwdata { - int joystate; + int joystate; }; @@ -52,32 +52,32 @@ struct joystick_hwdata * joysticks. Joystick 0 should be the system default joystick. * It should return number of joysticks, or -1 on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - _kernel_swi_regs regs; - - /* Try to read joystick 0 */ - regs.r[0] = 0; - if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) - { - /* Switch works so assume we've got a joystick */ - return 1; - } - /* Switch fails so it looks like there's no joystick here */ - - return(0); + _kernel_swi_regs regs; + + /* Try to read joystick 0 */ + regs.r[0] = 0; + if (_kernel_swi (JOYSTICK_READ, ®s, ®s) == NULL) { + /* Switch works so assume we've got a joystick */ + return 1; + } + /* Switch fails so it looks like there's no joystick here */ + + return (0); } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { - if (index == 0) - { - return "RISC OS Joystick 0"; - } + if (index == 0) { + return "RISC OS Joystick 0"; + } - SDL_SetError("No joystick available with that index"); - return(NULL); + SDL_SetError ("No joystick available with that index"); + return (NULL); } /* Function to open a joystick for use. @@ -85,24 +85,25 @@ const char *SDL_SYS_JoystickName(int index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - _kernel_swi_regs regs; + _kernel_swi_regs regs; - if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) - return -1; + if (!(joystick->hwdata = SDL_malloc (sizeof (struct joystick_hwdata)))) + return -1; - regs.r[0] = joystick->index; + regs.r[0] = joystick->index; - /* Don't know how to get exact count of buttons so assume max of 4 for now */ - joystick->nbuttons=4; + /* Don't know how to get exact count of buttons so assume max of 4 for now */ + joystick->nbuttons = 4; - joystick->nhats=0; - joystick->nballs=0; - joystick->naxes=2; - joystick->hwdata->joystate=0; + joystick->nhats = 0; + joystick->nballs = 0; + joystick->naxes = 2; + joystick->hwdata->joystate = 0; - return 0; + return 0; } @@ -111,66 +112,69 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - _kernel_swi_regs regs; - regs.r[0] = joystick->index; - - if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) - { - int newstate = regs.r[0]; - int oldstate = joystick->hwdata->joystate; - if (newstate != oldstate) - { - if ((newstate & 0xFF) != (oldstate & 0xFF)) - { - int y = regs.r[0] & 0xFF; - /* Convert to signed values */ - if (y >= 128) y -= 256; - SDL_PrivateJoystickAxis(joystick,1,-y * 256); /* Up and down opposite to result in SDL */ - } - if ((newstate & 0xFF00) != (oldstate & 0xFF00)) - { - int x = (regs.r[0] & 0xFF00) >> 8; - if (x >= 128) x -= 256; - SDL_PrivateJoystickAxis(joystick,0,x * 256); - } - - if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) - { - int buttons = (regs.r[0] & 0xFF0000) >> 16; - int oldbuttons = (oldstate & 0xFF0000) >> 16; - int i; - for (i = 0; i < joystick->nbuttons; i++) - { - if ((buttons & (1<hwdata->joystate = newstate; - } - } - - return; + _kernel_swi_regs regs; + regs.r[0] = joystick->index; + + if (_kernel_swi (JOYSTICK_READ, ®s, ®s) == NULL) { + int newstate = regs.r[0]; + int oldstate = joystick->hwdata->joystate; + if (newstate != oldstate) { + if ((newstate & 0xFF) != (oldstate & 0xFF)) { + int y = regs.r[0] & 0xFF; + /* Convert to signed values */ + if (y >= 128) + y -= 256; + SDL_PrivateJoystickAxis (joystick, 1, -y * 256); /* Up and down opposite to result in SDL */ + } + if ((newstate & 0xFF00) != (oldstate & 0xFF00)) { + int x = (regs.r[0] & 0xFF00) >> 8; + if (x >= 128) + x -= 256; + SDL_PrivateJoystickAxis (joystick, 0, x * 256); + } + + if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) { + int buttons = (regs.r[0] & 0xFF0000) >> 16; + int oldbuttons = (oldstate & 0xFF0000) >> 16; + int i; + for (i = 0; i < joystick->nbuttons; i++) { + if ((buttons & (1 << i)) != (oldbuttons & (1 << i))) { + if (buttons & (1 << i)) + SDL_PrivateJoystickButton (joystick, i, + SDL_PRESSED); + else + SDL_PrivateJoystickButton (joystick, i, + SDL_RELEASED); + } + } + } + joystick->hwdata->joystate = newstate; + } + } + + return; } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - if(joystick->hwdata) - SDL_free(joystick->hwdata); - return; + if (joystick->hwdata) + SDL_free (joystick->hwdata); + return; } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - SDL_numjoysticks=0; + SDL_numjoysticks = 0; - return; + return; } #endif /* SDL_JOYSTICK_RISCOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/win32/SDL_dxjoystick.c b/src/joystick/win32/SDL_dxjoystick.c index 2e179065b..e931540d2 100644 --- a/src/joystick/win32/SDL_dxjoystick.c +++ b/src/joystick/win32/SDL_dxjoystick.c @@ -45,162 +45,171 @@ #define DIRECTINPUT_VERSION 0x0500 #include -#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */ +#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */ extern HINSTANCE SDL_Instance; -extern int DX5_Load(); -extern void DX5_Unload(); -extern HRESULT (WINAPI *DInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT *ppDI, LPUNKNOWN punkOuter); +extern int DX5_Load (); +extern void DX5_Unload (); +extern HRESULT (WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, + LPDIRECTINPUT * ppDI, + LPUNKNOWN punkOuter); static LPDIRECTINPUT dinput = NULL; #define MAX_JOYSTICKS 8 -#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */ +#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */ #define AXIS_MIN -32768 /* minimum value for axis coordinate */ #define AXIS_MAX 32767 /* maximum value for axis coordinate */ -#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */ +#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */ -typedef enum Type { BUTTON, AXIS, HAT } Type; +typedef enum Type +{ BUTTON, AXIS, HAT } Type; /* array to hold joystick ID values */ static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS]; -static int SYS_NumJoysticks; +static int SYS_NumJoysticks; extern HWND SDL_Window; typedef struct input_t { - /* DirectInput offset for this input type: */ - DWORD ofs; + /* DirectInput offset for this input type: */ + DWORD ofs; - /* Button, axis or hat: */ - Type type; + /* Button, axis or hat: */ + Type type; - /* SDL input offset: */ - Uint8 num; + /* SDL input offset: */ + Uint8 num; } input_t; /* The private structure used to keep track of a joystick */ struct joystick_hwdata { - LPDIRECTINPUTDEVICE2 InputDevice; - int buffered; + LPDIRECTINPUTDEVICE2 InputDevice; + int buffered; - input_t Inputs[MAX_INPUTS]; - int NumInputs; + input_t Inputs[MAX_INPUTS]; + int NumInputs; }; /* Convert a DirectInput return code to a text message */ -static void SetDIerror(char *function, int code) +static void +SetDIerror (char *function, int code) { - static char *error; - static char errbuf[1024]; - - errbuf[0] = 0; - switch (code) { - case DIERR_GENERIC: - error = "Undefined error!"; - break; - case DIERR_OLDDIRECTINPUTVERSION: - error = "Your version of DirectInput needs upgrading"; - break; - case DIERR_INVALIDPARAM: - error = "Invalid parameters"; - break; - case DIERR_OUTOFMEMORY: - error = "Out of memory"; - break; - case DIERR_DEVICENOTREG: - error = "Device not registered"; - break; - case DIERR_NOINTERFACE: - error = "Interface not supported"; - break; - case DIERR_NOTINITIALIZED: - error = "Device not initialized"; - break; - default: - sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x", - function, code); - break; - } - if ( ! errbuf[0] ) { - sprintf(errbuf, "%s: %s", function, error); - } - SDL_SetError("%s", errbuf); - return; + static char *error; + static char errbuf[1024]; + + errbuf[0] = 0; + switch (code) { + case DIERR_GENERIC: + error = "Undefined error!"; + break; + case DIERR_OLDDIRECTINPUTVERSION: + error = "Your version of DirectInput needs upgrading"; + break; + case DIERR_INVALIDPARAM: + error = "Invalid parameters"; + break; + case DIERR_OUTOFMEMORY: + error = "Out of memory"; + break; + case DIERR_DEVICENOTREG: + error = "Device not registered"; + break; + case DIERR_NOINTERFACE: + error = "Interface not supported"; + break; + case DIERR_NOTINITIALIZED: + error = "Device not initialized"; + break; + default: + sprintf (errbuf, "%s: Unknown DirectInput error: 0x%x", + function, code); + break; + } + if (!errbuf[0]) { + sprintf (errbuf, "%s: %s", function, error); + } + SDL_SetError ("%s", errbuf); + return; } -BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, - VOID* pContext ) +BOOL CALLBACK +EnumJoysticksCallback (const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) { - memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance, sizeof(DIDEVICEINSTANCE)); - SYS_NumJoysticks++; + memcpy (&SYS_Joystick[SYS_NumJoysticks], pdidInstance, + sizeof (DIDEVICEINSTANCE)); + SYS_NumJoysticks++; - if( SYS_NumJoysticks >= MAX_JOYSTICKS ) - return DIENUM_STOP; + if (SYS_NumJoysticks >= MAX_JOYSTICKS) + return DIENUM_STOP; - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } -static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, - LPVOID pvRef) +static BOOL CALLBACK +DIJoystick_EnumDevObjectsProc (LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef) { - SDL_Joystick *joystick = (SDL_Joystick*)pvRef; - HRESULT result; - input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs]; - const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS; - if(!(dev->dwType & SupportedMask)) - return DIENUM_CONTINUE; /* unsupported */ - - in->ofs = dev->dwOfs; - - if(dev->dwType & DIDFT_BUTTON) { - in->type = BUTTON; - in->num = joystick->nbuttons; - joystick->nbuttons++; - } else if(dev->dwType & DIDFT_POV) { - in->type = HAT; - in->num = joystick->nhats; - joystick->nhats++; - } else { /* dev->dwType & DIDFT_AXIS */ - DIPROPRANGE diprg; - DIPROPDWORD dilong; - - in->type = AXIS; - in->num = joystick->naxes; - - diprg.diph.dwSize = sizeof(diprg); - diprg.diph.dwHeaderSize = sizeof(diprg.diph); - diprg.diph.dwObj = dev->dwOfs; - diprg.diph.dwHow = DIPH_BYOFFSET; - diprg.lMin = AXIS_MIN; - diprg.lMax = AXIS_MAX; - - result = IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice, DIPROP_RANGE, &diprg.diph); - if ( result != DI_OK ) - return DIENUM_CONTINUE; /* don't use this axis */ - - /* Set dead zone to 0. */ - dilong.diph.dwSize = sizeof(dilong); - dilong.diph.dwHeaderSize = sizeof(dilong.diph); - dilong.diph.dwObj = dev->dwOfs; - dilong.diph.dwHow = DIPH_BYOFFSET; - dilong.dwData = 0; - result = IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice, DIPROP_DEADZONE, &dilong.diph); - if ( result != DI_OK ) - return DIENUM_CONTINUE; /* don't use this axis */ - - joystick->naxes++; - } - - joystick->hwdata->NumInputs++; - - if(joystick->hwdata->NumInputs == MAX_INPUTS) - return DIENUM_STOP; /* too many */ - - return DIENUM_CONTINUE; + SDL_Joystick *joystick = (SDL_Joystick *) pvRef; + HRESULT result; + input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs]; + const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS; + if (!(dev->dwType & SupportedMask)) + return DIENUM_CONTINUE; /* unsupported */ + + in->ofs = dev->dwOfs; + + if (dev->dwType & DIDFT_BUTTON) { + in->type = BUTTON; + in->num = joystick->nbuttons; + joystick->nbuttons++; + } else if (dev->dwType & DIDFT_POV) { + in->type = HAT; + in->num = joystick->nhats; + joystick->nhats++; + } else { /* dev->dwType & DIDFT_AXIS */ + DIPROPRANGE diprg; + DIPROPDWORD dilong; + + in->type = AXIS; + in->num = joystick->naxes; + + diprg.diph.dwSize = sizeof (diprg); + diprg.diph.dwHeaderSize = sizeof (diprg.diph); + diprg.diph.dwObj = dev->dwOfs; + diprg.diph.dwHow = DIPH_BYOFFSET; + diprg.lMin = AXIS_MIN; + diprg.lMax = AXIS_MAX; + + result = + IDirectInputDevice2_SetProperty (joystick->hwdata->InputDevice, + DIPROP_RANGE, &diprg.diph); + if (result != DI_OK) + return DIENUM_CONTINUE; /* don't use this axis */ + + /* Set dead zone to 0. */ + dilong.diph.dwSize = sizeof (dilong); + dilong.diph.dwHeaderSize = sizeof (dilong.diph); + dilong.diph.dwObj = dev->dwOfs; + dilong.diph.dwHow = DIPH_BYOFFSET; + dilong.dwData = 0; + result = + IDirectInputDevice2_SetProperty (joystick->hwdata->InputDevice, + DIPROP_DEADZONE, &dilong.diph); + if (result != DI_OK) + return DIENUM_CONTINUE; /* don't use this axis */ + + joystick->naxes++; + } + + joystick->hwdata->NumInputs++; + + if (joystick->hwdata->NumInputs == MAX_INPUTS) + return DIENUM_STOP; /* too many */ + + return DIENUM_CONTINUE; } /* Function to scan the system for joysticks. @@ -208,39 +217,39 @@ static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev * joysticks. Joystick 0 should be the system default joystick. * It should return 0, or -1 on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - HRESULT result; - - SYS_NumJoysticks = 0; - - /* Create the DirectInput object */ - if ( DX5_Load() < 0 ) { - SDL_SetError("Couldn't load DirectInput"); - return(-1); - } - result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, - &dinput, NULL); - if ( result != DI_OK ) { - DX5_Unload(); - SetDIerror("DirectInputCreate", result); - return(-1); - } - - result = IDirectInput_EnumDevices(dinput, - DIDEVTYPE_JOYSTICK, - EnumJoysticksCallback, - NULL, - DIEDFL_ATTACHEDONLY ); - - return SYS_NumJoysticks; + HRESULT result; + + SYS_NumJoysticks = 0; + + /* Create the DirectInput object */ + if (DX5_Load () < 0) { + SDL_SetError ("Couldn't load DirectInput"); + return (-1); + } + result = DInputCreate (SDL_Instance, DIRECTINPUT_VERSION, &dinput, NULL); + if (result != DI_OK) { + DX5_Unload (); + SetDIerror ("DirectInputCreate", result); + return (-1); + } + + result = IDirectInput_EnumDevices (dinput, + DIDEVTYPE_JOYSTICK, + EnumJoysticksCallback, + NULL, DIEDFL_ATTACHEDONLY); + + return SYS_NumJoysticks; } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { - /***-> test for invalid index ? */ - return(SYS_Joystick[index].tszProductName); + /***-> test for invalid index ? */ + return (SYS_Joystick[index].tszProductName); } /* Function to open a joystick for use. @@ -248,127 +257,143 @@ const char *SDL_SYS_JoystickName(int index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - HRESULT result; - LPDIRECTINPUTDEVICE device; - - /* allocate memory for system specific hardware data */ - joystick->hwdata = (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); - } - memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - joystick->hwdata->buffered = 1; - - result = IDirectInput_CreateDevice(dinput, &SYS_Joystick[joystick->index].guidInstance, - &device, NULL); - if ( result != DI_OK ) { - SetDIerror("DirectInput::CreateDevice", result); - return(-1); - } - - result = IDirectInputDevice_QueryInterface(device, - &IID_IDirectInputDevice2, (LPVOID *)&joystick->hwdata->InputDevice); - IDirectInputDevice_Release(device); - if ( result != DI_OK ) { - SetDIerror("DirectInputDevice::QueryInterface", result); - return(-1); - } - - result = IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->InputDevice, SDL_Window, - DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); - if ( result != DI_OK ) { - SetDIerror("DirectInputDevice::SetCooperativeLevel", result); - return(-1); - } - - result = IDirectInputDevice2_SetDataFormat(joystick->hwdata->InputDevice, &c_dfDIJoystick); - if ( result != DI_OK ) { - SetDIerror("DirectInputDevice::SetDataFormat", result); - return(-1); - } - - IDirectInputDevice2_EnumObjects(joystick->hwdata->InputDevice, - DIJoystick_EnumDevObjectsProc, - joystick, - DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); - - { - DIPROPDWORD dipdw; - memset(&dipdw, 0, sizeof(dipdw)); - dipdw.diph.dwSize = sizeof(dipdw); - dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = INPUT_QSIZE; - result = IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice, - DIPROP_BUFFERSIZE, &dipdw.diph); - - if ( result == DI_POLLEDDEVICE ) - { - /* This device doesn't support buffering, so we're forced - * to use less reliable polling. */ - joystick->hwdata->buffered = 0; - } else if ( result != DI_OK ) { - SetDIerror("DirectInputDevice::SetProperty", result); - return(-1); - } - } - - return(0); + HRESULT result; + LPDIRECTINPUTDEVICE device; + + /* allocate memory for system specific hardware data */ + joystick->hwdata = + (struct joystick_hwdata *) malloc (sizeof (*joystick->hwdata)); + if (joystick->hwdata == NULL) { + SDL_OutOfMemory (); + return (-1); + } + memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); + joystick->hwdata->buffered = 1; + + result = + IDirectInput_CreateDevice (dinput, + &SYS_Joystick[joystick->index]. + guidInstance, &device, NULL); + if (result != DI_OK) { + SetDIerror ("DirectInput::CreateDevice", result); + return (-1); + } + + result = IDirectInputDevice_QueryInterface (device, + &IID_IDirectInputDevice2, + (LPVOID *) & joystick-> + hwdata->InputDevice); + IDirectInputDevice_Release (device); + if (result != DI_OK) { + SetDIerror ("DirectInputDevice::QueryInterface", result); + return (-1); + } + + result = + IDirectInputDevice2_SetCooperativeLevel (joystick->hwdata-> + InputDevice, SDL_Window, + DISCL_NONEXCLUSIVE | + DISCL_BACKGROUND); + if (result != DI_OK) { + SetDIerror ("DirectInputDevice::SetCooperativeLevel", result); + return (-1); + } + + result = + IDirectInputDevice2_SetDataFormat (joystick->hwdata->InputDevice, + &c_dfDIJoystick); + if (result != DI_OK) { + SetDIerror ("DirectInputDevice::SetDataFormat", result); + return (-1); + } + + IDirectInputDevice2_EnumObjects (joystick->hwdata->InputDevice, + DIJoystick_EnumDevObjectsProc, + joystick, + DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); + + { + DIPROPDWORD dipdw; + memset (&dipdw, 0, sizeof (dipdw)); + dipdw.diph.dwSize = sizeof (dipdw); + dipdw.diph.dwHeaderSize = sizeof (dipdw.diph); + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = INPUT_QSIZE; + result = + IDirectInputDevice2_SetProperty (joystick->hwdata->InputDevice, + DIPROP_BUFFERSIZE, &dipdw.diph); + + if (result == DI_POLLEDDEVICE) { + /* This device doesn't support buffering, so we're forced + * to use less reliable polling. */ + joystick->hwdata->buffered = 0; + } else if (result != DI_OK) { + SetDIerror ("DirectInputDevice::SetProperty", result); + return (-1); + } + } + + return (0); } -static Uint8 TranslatePOV(DWORD value) +static Uint8 +TranslatePOV (DWORD value) { - const int HAT_VALS[] = { - SDL_HAT_UP, - SDL_HAT_UP | SDL_HAT_RIGHT, - SDL_HAT_RIGHT, - SDL_HAT_DOWN | SDL_HAT_RIGHT, - SDL_HAT_DOWN, - SDL_HAT_DOWN | SDL_HAT_LEFT, - SDL_HAT_LEFT, - SDL_HAT_UP | SDL_HAT_LEFT - }; - - if(LOWORD(value) == 0xFFFF) - return SDL_HAT_CENTERED; - - /* Round the value up: */ - value += 4500 / 2; - value %= 36000; - value /= 4500; - - if(value >= 8) - return SDL_HAT_CENTERED; /* shouldn't happen */ - - return HAT_VALS[value]; + const int HAT_VALS[] = { + SDL_HAT_UP, + SDL_HAT_UP | SDL_HAT_RIGHT, + SDL_HAT_RIGHT, + SDL_HAT_DOWN | SDL_HAT_RIGHT, + SDL_HAT_DOWN, + SDL_HAT_DOWN | SDL_HAT_LEFT, + SDL_HAT_LEFT, + SDL_HAT_UP | SDL_HAT_LEFT + }; + + if (LOWORD (value) == 0xFFFF) + return SDL_HAT_CENTERED; + + /* Round the value up: */ + value += 4500 / 2; + value %= 36000; + value /= 4500; + + if (value >= 8) + return SDL_HAT_CENTERED; /* shouldn't happen */ + + return HAT_VALS[value]; } /* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to * do it. */ -static int SDL_PrivateJoystickAxis_Int(SDL_Joystick *joystick, Uint8 axis, Sint16 value) +static int +SDL_PrivateJoystickAxis_Int (SDL_Joystick * joystick, Uint8 axis, + Sint16 value) { - if(joystick->axes[axis] != value) - return SDL_PrivateJoystickAxis(joystick, axis, value); - return 0; + if (joystick->axes[axis] != value) + return SDL_PrivateJoystickAxis (joystick, axis, value); + return 0; } -static int SDL_PrivateJoystickHat_Int(SDL_Joystick *joystick, Uint8 hat, Uint8 value) +static int +SDL_PrivateJoystickHat_Int (SDL_Joystick * joystick, Uint8 hat, Uint8 value) { - if(joystick->hats[hat] != value) - return SDL_PrivateJoystickHat(joystick, hat, value); - return 0; + if (joystick->hats[hat] != value) + return SDL_PrivateJoystickHat (joystick, hat, value); + return 0; } -static int SDL_PrivateJoystickButton_Int(SDL_Joystick *joystick, Uint8 button, Uint8 state) +static int +SDL_PrivateJoystickButton_Int (SDL_Joystick * joystick, Uint8 button, + Uint8 state) { - if(joystick->buttons[button] != state) - return SDL_PrivateJoystickButton(joystick, button, state); - return 0; + if (joystick->buttons[button] != state) + return SDL_PrivateJoystickButton (joystick, button, state); + return 0; } /* Function to update the state of a joystick - called as a device poll. @@ -376,138 +401,180 @@ static int SDL_PrivateJoystickButton_Int(SDL_Joystick *joystick, Uint8 button, U * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate_Polled(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate_Polled (SDL_Joystick * joystick) { - DIJOYSTATE state; - HRESULT result; - int i; - - result = IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice, sizeof(state), &state); - if ( result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED ) { - IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice); - result = IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice, sizeof(state), &state); - } - - /* Set each known axis, button and POV. */ - for(i = 0; i < joystick->hwdata->NumInputs; ++i) - { - const input_t *in = &joystick->hwdata->Inputs[i]; - - switch(in->type) - { - case AXIS: - switch(in->ofs) - { - case DIJOFS_X: SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.lX); break; - case DIJOFS_Y: SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.lY); break; - case DIJOFS_Z: SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.lZ); break; - case DIJOFS_RX: SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.lRx); break; - case DIJOFS_RY: SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.lRy); break; - case DIJOFS_RZ: SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.lRz); break; - case DIJOFS_SLIDER(0): SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.rglSlider[0]); break; - case DIJOFS_SLIDER(1): SDL_PrivateJoystickAxis_Int(joystick, in->num, (Sint16)state.rglSlider[0]); break; - } - - break; - - case BUTTON: - SDL_PrivateJoystickButton_Int(joystick, in->num, (Uint8) (state.rgbButtons[in->ofs - DIJOFS_BUTTON0]?SDL_PRESSED:SDL_RELEASED)); - break; - case HAT: - { - Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]); - SDL_PrivateJoystickHat_Int(joystick, in->num, pos); - break; - } - } - } + DIJOYSTATE state; + HRESULT result; + int i; + + result = + IDirectInputDevice2_GetDeviceState (joystick->hwdata->InputDevice, + sizeof (state), &state); + if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { + IDirectInputDevice2_Acquire (joystick->hwdata->InputDevice); + result = + IDirectInputDevice2_GetDeviceState (joystick->hwdata-> + InputDevice, sizeof (state), + &state); + } + + /* Set each known axis, button and POV. */ + for (i = 0; i < joystick->hwdata->NumInputs; ++i) { + const input_t *in = &joystick->hwdata->Inputs[i]; + + switch (in->type) { + case AXIS: + switch (in->ofs) { + case DIJOFS_X: + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.lX); + break; + case DIJOFS_Y: + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.lY); + break; + case DIJOFS_Z: + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.lZ); + break; + case DIJOFS_RX: + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.lRx); + break; + case DIJOFS_RY: + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.lRy); + break; + case DIJOFS_RZ: + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.lRz); + break; + case DIJOFS_SLIDER (0): + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.rglSlider[0]); + break; + case DIJOFS_SLIDER (1): + SDL_PrivateJoystickAxis_Int (joystick, in->num, + (Sint16) state.rglSlider[0]); + break; + } + + break; + + case BUTTON: + SDL_PrivateJoystickButton_Int (joystick, in->num, + (Uint8) (state. + rgbButtons[in->ofs - + DIJOFS_BUTTON0] + ? SDL_PRESSED : + SDL_RELEASED)); + break; + case HAT: + { + Uint8 pos = + TranslatePOV (state.rgdwPOV[in->ofs - DIJOFS_POV (0)]); + SDL_PrivateJoystickHat_Int (joystick, in->num, pos); + break; + } + } + } } -void SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate_Buffered (SDL_Joystick * joystick) { - int i; - HRESULT result; - DWORD numevents; - DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; - - numevents = INPUT_QSIZE; - result = IDirectInputDevice2_GetDeviceData( - joystick->hwdata->InputDevice, sizeof(DIDEVICEOBJECTDATA), - evtbuf, &numevents, 0); - if ( result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED ) { - IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice); - result = IDirectInputDevice2_GetDeviceData( - joystick->hwdata->InputDevice, sizeof(DIDEVICEOBJECTDATA), - evtbuf, &numevents, 0); - } - - /* Handle the events */ - if ( result != DI_OK ) - return; - - for(i = 0; i < (int) numevents; ++i) - { - int j; - - for(j = 0; j < joystick->hwdata->NumInputs; ++j) - { - const input_t *in = &joystick->hwdata->Inputs[j]; - - if(evtbuf[i].dwOfs != in->ofs) - continue; - - switch(in->type) - { - case AXIS: - SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)evtbuf[i].dwData); - break; - case BUTTON: - SDL_PrivateJoystickButton(joystick, in->num, (Uint8) (evtbuf[i].dwData?SDL_PRESSED:SDL_RELEASED)); - break; - case HAT: - { - Uint8 pos = TranslatePOV(evtbuf[i].dwData); - SDL_PrivateJoystickHat(joystick, in->num, pos); - } - } - } - } + int i; + HRESULT result; + DWORD numevents; + DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; + + numevents = INPUT_QSIZE; + result = + IDirectInputDevice2_GetDeviceData (joystick->hwdata->InputDevice, + sizeof (DIDEVICEOBJECTDATA), + evtbuf, &numevents, 0); + if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { + IDirectInputDevice2_Acquire (joystick->hwdata->InputDevice); + result = + IDirectInputDevice2_GetDeviceData (joystick->hwdata-> + InputDevice, + sizeof (DIDEVICEOBJECTDATA), + evtbuf, &numevents, 0); + } + + /* Handle the events */ + if (result != DI_OK) + return; + + for (i = 0; i < (int) numevents; ++i) { + int j; + + for (j = 0; j < joystick->hwdata->NumInputs; ++j) { + const input_t *in = &joystick->hwdata->Inputs[j]; + + if (evtbuf[i].dwOfs != in->ofs) + continue; + + switch (in->type) { + case AXIS: + SDL_PrivateJoystickAxis (joystick, in->num, + (Sint16) evtbuf[i].dwData); + break; + case BUTTON: + SDL_PrivateJoystickButton (joystick, in->num, + (Uint8) (evtbuf[i]. + dwData ? SDL_PRESSED + : SDL_RELEASED)); + break; + case HAT: + { + Uint8 pos = TranslatePOV (evtbuf[i].dwData); + SDL_PrivateJoystickHat (joystick, in->num, pos); + } + } + } + } } -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - HRESULT result; - - result = IDirectInputDevice2_Poll(joystick->hwdata->InputDevice); - if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { - IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice); - IDirectInputDevice2_Poll(joystick->hwdata->InputDevice); - } - - if(joystick->hwdata->buffered) - SDL_SYS_JoystickUpdate_Buffered(joystick); - else - SDL_SYS_JoystickUpdate_Polled(joystick); + HRESULT result; + + result = IDirectInputDevice2_Poll (joystick->hwdata->InputDevice); + if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { + IDirectInputDevice2_Acquire (joystick->hwdata->InputDevice); + IDirectInputDevice2_Poll (joystick->hwdata->InputDevice); + } + + if (joystick->hwdata->buffered) + SDL_SYS_JoystickUpdate_Buffered (joystick); + else + SDL_SYS_JoystickUpdate_Polled (joystick); } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - IDirectInputDevice2_Unacquire(joystick->hwdata->InputDevice); - IDirectInputDevice2_Release(joystick->hwdata->InputDevice); + IDirectInputDevice2_Unacquire (joystick->hwdata->InputDevice); + IDirectInputDevice2_Release (joystick->hwdata->InputDevice); - if (joystick->hwdata != NULL) { - /* free system specific hardware data */ - free(joystick->hwdata); - } + if (joystick->hwdata != NULL) { + /* free system specific hardware data */ + free (joystick->hwdata); + } } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - IDirectInput_Release(dinput); - dinput = NULL; - DX5_Unload(); + IDirectInput_Release (dinput); + dinput = NULL; + DX5_Unload (); } #endif /* SDL_JOYSTICK_DINPUT */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/win32/SDL_mmjoystick.c b/src/joystick/win32/SDL_mmjoystick.c index 2523bbec4..3cb6dd37e 100644 --- a/src/joystick/win32/SDL_mmjoystick.c +++ b/src/joystick/win32/SDL_mmjoystick.c @@ -36,8 +36,8 @@ #include "../SDL_joystick_c.h" #define MAX_JOYSTICKS 16 -#define MAX_AXES 6 /* each joystick can have up to 6 axes */ -#define MAX_BUTTONS 32 /* and 32 buttons */ +#define MAX_AXES 6 /* each joystick can have up to 6 axes */ +#define MAX_BUTTONS 32 /* and 32 buttons */ #define AXIS_MIN -32768 /* minimum value for axis coordinate */ #define AXIS_MAX 32767 /* maximum value for axis coordinate */ /* limit axis to 256 possible positions to filter out noise */ @@ -46,98 +46,93 @@ /* array to hold joystick ID values */ -static UINT SYS_JoystickID[MAX_JOYSTICKS]; -static JOYCAPS SYS_Joystick[MAX_JOYSTICKS]; -static char *SYS_JoystickName[MAX_JOYSTICKS]; +static UINT SYS_JoystickID[MAX_JOYSTICKS]; +static JOYCAPS SYS_Joystick[MAX_JOYSTICKS]; +static char *SYS_JoystickName[MAX_JOYSTICKS]; /* The private structure used to keep track of a joystick */ struct joystick_hwdata { - /* joystick ID */ - UINT id; - - /* values used to translate device-specific coordinates into - SDL-standard ranges */ - struct _transaxis { - int offset; - float scale; - } transaxis[6]; + /* joystick ID */ + UINT id; + + /* values used to translate device-specific coordinates into + SDL-standard ranges */ + struct _transaxis + { + int offset; + float scale; + } transaxis[6]; }; /* Convert a win32 Multimedia API return code to a text message */ -static void SetMMerror(char *function, int code); +static void SetMMerror (char *function, int code); -static char *GetJoystickName(int index, const char *szRegKey) +static char * +GetJoystickName (int index, const char *szRegKey) { - /* added 7/24/2004 by Eckhard Stolberg */ - /* - see if there is a joystick for the current - index (1-16) listed in the registry - */ - char *name = NULL; - HKEY hKey; - DWORD regsize; - LONG regresult; - unsigned char regkey[256]; - unsigned char regvalue[256]; - unsigned char regname[256]; - - SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s", - REGSTR_PATH_JOYCONFIG, - szRegKey, - REGSTR_KEY_JOYCURR); - regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, - (LPTSTR) ®key, 0, KEY_READ, &hKey); - if (regresult == ERROR_SUCCESS) - { - /* - find the registry key name for the - joystick's properties - */ - regsize = sizeof(regname); - SDL_snprintf((char *) regvalue, SDL_arraysize(regvalue), - "Joystick%d%s", index+1, - REGSTR_VAL_JOYOEMNAME); - regresult = RegQueryValueExA(hKey, - (char *) regvalue, 0, 0, (LPBYTE) ®name, - (LPDWORD) ®size); - RegCloseKey(hKey); - if (regresult == ERROR_SUCCESS) - { - /* open that registry key */ - SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s", - REGSTR_PATH_JOYOEM, regname); - regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, - (char *) regkey, 0, KEY_READ, &hKey); - if (regresult == ERROR_SUCCESS) - { - /* find the size for the OEM name text */ - regsize = sizeof(regvalue); - regresult = - RegQueryValueExA(hKey, - REGSTR_VAL_JOYOEMNAME, - 0, 0, NULL, - (LPDWORD) ®size); - if (regresult == ERROR_SUCCESS) - { - /* - allocate enough memory - for the OEM name text ... - */ - name = (char *) SDL_malloc(regsize); - /* ... and read it from the registry */ - regresult = - RegQueryValueExA(hKey, - REGSTR_VAL_JOYOEMNAME, 0, 0, - (LPBYTE) name, - (LPDWORD) ®size); - RegCloseKey(hKey); - } - } - } - } - return(name); + /* added 7/24/2004 by Eckhard Stolberg */ + /* + see if there is a joystick for the current + index (1-16) listed in the registry + */ + char *name = NULL; + HKEY hKey; + DWORD regsize; + LONG regresult; + unsigned char regkey[256]; + unsigned char regvalue[256]; + unsigned char regname[256]; + + SDL_snprintf ((char *) regkey, SDL_arraysize (regkey), "%s\\%s\\%s", + REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR); + regresult = RegOpenKeyExA (HKEY_LOCAL_MACHINE, + (LPTSTR) & regkey, 0, KEY_READ, &hKey); + if (regresult == ERROR_SUCCESS) { + /* + find the registry key name for the + joystick's properties + */ + regsize = sizeof (regname); + SDL_snprintf ((char *) regvalue, SDL_arraysize (regvalue), + "Joystick%d%s", index + 1, REGSTR_VAL_JOYOEMNAME); + regresult = RegQueryValueExA (hKey, + (char *) regvalue, 0, 0, + (LPBYTE) & regname, + (LPDWORD) & regsize); + RegCloseKey (hKey); + if (regresult == ERROR_SUCCESS) { + /* open that registry key */ + SDL_snprintf ((char *) regkey, SDL_arraysize (regkey), + "%s\\%s", REGSTR_PATH_JOYOEM, regname); + regresult = + RegOpenKeyExA (HKEY_LOCAL_MACHINE, (char *) regkey, 0, + KEY_READ, &hKey); + if (regresult == ERROR_SUCCESS) { + /* find the size for the OEM name text */ + regsize = sizeof (regvalue); + regresult = + RegQueryValueExA (hKey, + REGSTR_VAL_JOYOEMNAME, + 0, 0, NULL, (LPDWORD) & regsize); + if (regresult == ERROR_SUCCESS) { + /* + allocate enough memory + for the OEM name text ... + */ + name = (char *) SDL_malloc (regsize); + /* ... and read it from the registry */ + regresult = + RegQueryValueExA (hKey, + REGSTR_VAL_JOYOEMNAME, 0, 0, + (LPBYTE) name, (LPDWORD) & regsize); + RegCloseKey (hKey); + } + } + } + } + return (name); } /* Function to scan the system for joysticks. @@ -145,50 +140,53 @@ static char *GetJoystickName(int index, const char *szRegKey) * joysticks. Joystick 0 should be the system default joystick. * It should return 0, or -1 on an unrecoverable fatal error. */ -int SDL_SYS_JoystickInit(void) +int +SDL_SYS_JoystickInit (void) { - int i; - int maxdevs; - int numdevs; - JOYINFOEX joyinfo; - JOYCAPS joycaps; - MMRESULT result; - - /* Reset the joystick ID & name mapping tables */ - for ( i = 0; i < MAX_JOYSTICKS; ++i ) { - SYS_JoystickID[i] = 0; - SYS_JoystickName[i] = NULL; - } - - /* Loop over all potential joystick devices */ - numdevs = 0; - maxdevs = joyGetNumDevs(); - for ( i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i ) { - - joyinfo.dwSize = sizeof(joyinfo); - joyinfo.dwFlags = JOY_RETURNALL; - result = joyGetPosEx(SYS_JoystickID[i], &joyinfo); - if ( result == JOYERR_NOERROR ) { - result = joyGetDevCaps(i, &joycaps, sizeof(joycaps)); - if ( result == JOYERR_NOERROR ) { - SYS_JoystickID[numdevs] = i; - SYS_Joystick[numdevs] = joycaps; - SYS_JoystickName[numdevs] = GetJoystickName(i, joycaps.szRegKey); - numdevs++; - } - } - } - return(numdevs); + int i; + int maxdevs; + int numdevs; + JOYINFOEX joyinfo; + JOYCAPS joycaps; + MMRESULT result; + + /* Reset the joystick ID & name mapping tables */ + for (i = 0; i < MAX_JOYSTICKS; ++i) { + SYS_JoystickID[i] = 0; + SYS_JoystickName[i] = NULL; + } + + /* Loop over all potential joystick devices */ + numdevs = 0; + maxdevs = joyGetNumDevs (); + for (i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i) { + + joyinfo.dwSize = sizeof (joyinfo); + joyinfo.dwFlags = JOY_RETURNALL; + result = joyGetPosEx (SYS_JoystickID[i], &joyinfo); + if (result == JOYERR_NOERROR) { + result = joyGetDevCaps (i, &joycaps, sizeof (joycaps)); + if (result == JOYERR_NOERROR) { + SYS_JoystickID[numdevs] = i; + SYS_Joystick[numdevs] = joycaps; + SYS_JoystickName[numdevs] = + GetJoystickName (i, joycaps.szRegKey); + numdevs++; + } + } + } + return (numdevs); } /* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) +const char * +SDL_SYS_JoystickName (int index) { - if ( SYS_JoystickName[index] != NULL ) { - return(SYS_JoystickName[index]); - } else { - return(SYS_Joystick[index].szPname); - } + if (SYS_JoystickName[index] != NULL) { + return (SYS_JoystickName[index]); + } else { + return (SYS_Joystick[index].szPname); + } } /* Function to open a joystick for use. @@ -196,83 +194,84 @@ const char *SDL_SYS_JoystickName(int index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +int +SDL_SYS_JoystickOpen (SDL_Joystick * joystick) { - int index, i; - int caps_flags[MAX_AXES-2] = - { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV }; - int axis_min[MAX_AXES], axis_max[MAX_AXES]; - - - /* shortcut */ - index = joystick->index; - axis_min[0] = SYS_Joystick[index].wXmin; - axis_max[0] = SYS_Joystick[index].wXmax; - axis_min[1] = SYS_Joystick[index].wYmin; - axis_max[1] = SYS_Joystick[index].wYmax; - axis_min[2] = SYS_Joystick[index].wZmin; - axis_max[2] = SYS_Joystick[index].wZmax; - axis_min[3] = SYS_Joystick[index].wRmin; - axis_max[3] = SYS_Joystick[index].wRmax; - axis_min[4] = SYS_Joystick[index].wUmin; - axis_max[4] = SYS_Joystick[index].wUmax; - axis_min[5] = SYS_Joystick[index].wVmin; - axis_max[5] = SYS_Joystick[index].wVmax; - - /* allocate memory for system specific hardware data */ - joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - - /* set hardware data */ - joystick->hwdata->id = SYS_JoystickID[index]; - for ( i = 0; i < MAX_AXES; ++i ) { - if ( (i<2) || (SYS_Joystick[index].wCaps & caps_flags[i-2]) ) { - joystick->hwdata->transaxis[i].offset = - AXIS_MIN - axis_min[i]; - joystick->hwdata->transaxis[i].scale = - (float)(AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]); - } else { - joystick->hwdata->transaxis[i].offset = 0; - joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */ - } - } - - /* fill nbuttons, naxes, and nhats fields */ - joystick->nbuttons = SYS_Joystick[index].wNumButtons; - joystick->naxes = SYS_Joystick[index].wNumAxes; - if ( SYS_Joystick[index].wCaps & JOYCAPS_HASPOV ) { - joystick->nhats = 1; - } else { - joystick->nhats = 0; - } - return(0); + int index, i; + int caps_flags[MAX_AXES - 2] = + { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV }; + int axis_min[MAX_AXES], axis_max[MAX_AXES]; + + + /* shortcut */ + index = joystick->index; + axis_min[0] = SYS_Joystick[index].wXmin; + axis_max[0] = SYS_Joystick[index].wXmax; + axis_min[1] = SYS_Joystick[index].wYmin; + axis_max[1] = SYS_Joystick[index].wYmax; + axis_min[2] = SYS_Joystick[index].wZmin; + axis_max[2] = SYS_Joystick[index].wZmax; + axis_min[3] = SYS_Joystick[index].wRmin; + axis_max[3] = SYS_Joystick[index].wRmax; + axis_min[4] = SYS_Joystick[index].wUmin; + axis_max[4] = SYS_Joystick[index].wUmax; + axis_min[5] = SYS_Joystick[index].wVmin; + axis_max[5] = SYS_Joystick[index].wVmax; + + /* allocate memory for system specific hardware data */ + joystick->hwdata = + (struct joystick_hwdata *) SDL_malloc (sizeof (*joystick->hwdata)); + if (joystick->hwdata == NULL) { + SDL_OutOfMemory (); + return (-1); + } + SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); + + /* set hardware data */ + joystick->hwdata->id = SYS_JoystickID[index]; + for (i = 0; i < MAX_AXES; ++i) { + if ((i < 2) || (SYS_Joystick[index].wCaps & caps_flags[i - 2])) { + joystick->hwdata->transaxis[i].offset = AXIS_MIN - axis_min[i]; + joystick->hwdata->transaxis[i].scale = + (float) (AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]); + } else { + joystick->hwdata->transaxis[i].offset = 0; + joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */ + } + } + + /* fill nbuttons, naxes, and nhats fields */ + joystick->nbuttons = SYS_Joystick[index].wNumButtons; + joystick->naxes = SYS_Joystick[index].wNumAxes; + if (SYS_Joystick[index].wCaps & JOYCAPS_HASPOV) { + joystick->nhats = 1; + } else { + joystick->nhats = 0; + } + return (0); } -static Uint8 TranslatePOV(DWORD value) +static Uint8 +TranslatePOV (DWORD value) { - Uint8 pos; - - pos = SDL_HAT_CENTERED; - if ( value != JOY_POVCENTERED ) { - if ( (value > JOY_POVLEFT) || (value < JOY_POVRIGHT) ) { - pos |= SDL_HAT_UP; - } - if ( (value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD) ) { - pos |= SDL_HAT_RIGHT; - } - if ( (value > JOY_POVRIGHT) && (value < JOY_POVLEFT) ) { - pos |= SDL_HAT_DOWN; - } - if ( value > JOY_POVBACKWARD ) { - pos |= SDL_HAT_LEFT; - } - } - return(pos); + Uint8 pos; + + pos = SDL_HAT_CENTERED; + if (value != JOY_POVCENTERED) { + if ((value > JOY_POVLEFT) || (value < JOY_POVRIGHT)) { + pos |= SDL_HAT_UP; + } + if ((value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD)) { + pos |= SDL_HAT_RIGHT; + } + if ((value > JOY_POVRIGHT) && (value < JOY_POVLEFT)) { + pos |= SDL_HAT_DOWN; + } + if (value > JOY_POVBACKWARD) { + pos |= SDL_HAT_LEFT; + } + } + return (pos); } /* Function to update the state of a joystick - called as a device poll. @@ -280,135 +279,146 @@ static Uint8 TranslatePOV(DWORD value) * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +void +SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) { - MMRESULT result; - int i; - DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, - JOY_RETURNR, JOY_RETURNU, JOY_RETURNV }; - DWORD pos[MAX_AXES]; - struct _transaxis *transaxis; - int value, change; - JOYINFOEX joyinfo; - - joyinfo.dwSize = sizeof(joyinfo); - joyinfo.dwFlags = JOY_RETURNALL|JOY_RETURNPOVCTS; - if ( ! joystick->hats ) { - joyinfo.dwFlags &= ~(JOY_RETURNPOV|JOY_RETURNPOVCTS); - } - result = joyGetPosEx(joystick->hwdata->id, &joyinfo); - if ( result != JOYERR_NOERROR ) { - SetMMerror("joyGetPosEx", result); - return; - } - - /* joystick motion events */ - pos[0] = joyinfo.dwXpos; - pos[1] = joyinfo.dwYpos; - pos[2] = joyinfo.dwZpos; - pos[3] = joyinfo.dwRpos; - pos[4] = joyinfo.dwUpos; - pos[5] = joyinfo.dwVpos; - - transaxis = joystick->hwdata->transaxis; - for (i = 0; i < joystick->naxes; i++) { - if (joyinfo.dwFlags & flags[i]) { - value = (int)(((float)pos[i] + transaxis[i].offset) * transaxis[i].scale); - change = (value - joystick->axes[i]); - if ( (change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD) ) { - SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)value); - } - } - } - - /* joystick button events */ - if ( joyinfo.dwFlags & JOY_RETURNBUTTONS ) { - for ( i = 0; i < joystick->nbuttons; ++i ) { - if ( joyinfo.dwButtons & JOY_BUTTON_FLAG(i) ) { - if ( ! joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_PRESSED); - } - } else { - if ( joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_RELEASED); - } - } - } - } - - /* joystick hat events */ - if ( joyinfo.dwFlags & JOY_RETURNPOV ) { - Uint8 pos; - - pos = TranslatePOV(joyinfo.dwPOV); - if ( pos != joystick->hats[0] ) { - SDL_PrivateJoystickHat(joystick, 0, pos); - } - } + MMRESULT result; + int i; + DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, + JOY_RETURNR, JOY_RETURNU, JOY_RETURNV + }; + DWORD pos[MAX_AXES]; + struct _transaxis *transaxis; + int value, change; + JOYINFOEX joyinfo; + + joyinfo.dwSize = sizeof (joyinfo); + joyinfo.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS; + if (!joystick->hats) { + joyinfo.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS); + } + result = joyGetPosEx (joystick->hwdata->id, &joyinfo); + if (result != JOYERR_NOERROR) { + SetMMerror ("joyGetPosEx", result); + return; + } + + /* joystick motion events */ + pos[0] = joyinfo.dwXpos; + pos[1] = joyinfo.dwYpos; + pos[2] = joyinfo.dwZpos; + pos[3] = joyinfo.dwRpos; + pos[4] = joyinfo.dwUpos; + pos[5] = joyinfo.dwVpos; + + transaxis = joystick->hwdata->transaxis; + for (i = 0; i < joystick->naxes; i++) { + if (joyinfo.dwFlags & flags[i]) { + value = + (int) (((float) pos[i] + + transaxis[i].offset) * transaxis[i].scale); + change = (value - joystick->axes[i]); + if ((change < -JOY_AXIS_THRESHOLD) + || (change > JOY_AXIS_THRESHOLD)) { + SDL_PrivateJoystickAxis (joystick, (Uint8) i, (Sint16) value); + } + } + } + + /* joystick button events */ + if (joyinfo.dwFlags & JOY_RETURNBUTTONS) { + for (i = 0; i < joystick->nbuttons; ++i) { + if (joyinfo.dwButtons & JOY_BUTTON_FLAG (i)) { + if (!joystick->buttons[i]) { + SDL_PrivateJoystickButton (joystick, (Uint8) i, + SDL_PRESSED); + } + } else { + if (joystick->buttons[i]) { + SDL_PrivateJoystickButton (joystick, (Uint8) i, + SDL_RELEASED); + } + } + } + } + + /* joystick hat events */ + if (joyinfo.dwFlags & JOY_RETURNPOV) { + Uint8 pos; + + pos = TranslatePOV (joyinfo.dwPOV); + if (pos != joystick->hats[0]) { + SDL_PrivateJoystickHat (joystick, 0, pos); + } + } } /* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +void +SDL_SYS_JoystickClose (SDL_Joystick * joystick) { - if (joystick->hwdata != NULL) { - /* free system specific hardware data */ - SDL_free(joystick->hwdata); - } + if (joystick->hwdata != NULL) { + /* free system specific hardware data */ + SDL_free (joystick->hwdata); + } } /* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) +void +SDL_SYS_JoystickQuit (void) { - int i; - for (i = 0; i < MAX_JOYSTICKS; i++) { - if ( SYS_JoystickName[i] != NULL ) { - SDL_free(SYS_JoystickName[i]); - } - } + int i; + for (i = 0; i < MAX_JOYSTICKS; i++) { + if (SYS_JoystickName[i] != NULL) { + SDL_free (SYS_JoystickName[i]); + } + } } /* implementation functions */ -void SetMMerror(char *function, int code) +void +SetMMerror (char *function, int code) { - static char *error; - static char errbuf[1024]; - - errbuf[0] = 0; - switch (code) - { - case MMSYSERR_NODRIVER: - error = "Joystick driver not present"; - break; - - case MMSYSERR_INVALPARAM: - case JOYERR_PARMS: - error = "Invalid parameter(s)"; - break; - - case MMSYSERR_BADDEVICEID: - error = "Bad device ID"; - break; - - case JOYERR_UNPLUGGED: - error = "Joystick not attached"; - break; - - case JOYERR_NOCANDO: - error = "Can't capture joystick input"; - break; - - default: - SDL_snprintf(errbuf, SDL_arraysize(errbuf), - "%s: Unknown Multimedia system error: 0x%x", - function, code); - break; - } - - if ( ! errbuf[0] ) { - SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); - } - SDL_SetError("%s", errbuf); + static char *error; + static char errbuf[1024]; + + errbuf[0] = 0; + switch (code) { + case MMSYSERR_NODRIVER: + error = "Joystick driver not present"; + break; + + case MMSYSERR_INVALPARAM: + case JOYERR_PARMS: + error = "Invalid parameter(s)"; + break; + + case MMSYSERR_BADDEVICEID: + error = "Bad device ID"; + break; + + case JOYERR_UNPLUGGED: + error = "Joystick not attached"; + break; + + case JOYERR_NOCANDO: + error = "Can't capture joystick input"; + break; + + default: + SDL_snprintf (errbuf, SDL_arraysize (errbuf), + "%s: Unknown Multimedia system error: 0x%x", + function, code); + break; + } + + if (!errbuf[0]) { + SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: %s", function, + error); + } + SDL_SetError ("%s", errbuf); } #endif /* SDL_JOYSTICK_WINMM */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/beos/SDL_sysloadso.c b/src/loadso/beos/SDL_sysloadso.c index cf14c0b32..fdc6eefb0 100644 --- a/src/loadso/beos/SDL_sysloadso.c +++ b/src/loadso/beos/SDL_sysloadso.c @@ -31,46 +31,50 @@ #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { - void *handle = NULL; - const char *loaderror = "Unknown error"; - image_id library_id = load_add_on(sofile); - if ( library_id == B_ERROR ) { - loaderror = "BeOS error"; - } else { - handle = (void *)(library_id); - } + void *handle = NULL; + const char *loaderror = "Unknown error"; + image_id library_id = load_add_on (sofile); + if (library_id == B_ERROR) { + loaderror = "BeOS error"; + } else { + handle = (void *) (library_id); + } - if ( handle == NULL ) { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return(handle); + if (handle == NULL) { + SDL_SetError ("Failed loading %s: %s", sofile, loaderror); + } + return (handle); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { - void *symbol = NULL; - const char *loaderror = "Unknown error"; - image_id library_id = (image_id)handle; - if ( get_image_symbol(library_id, - name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) { - loaderror = "Symbol not found"; - } + void *symbol = NULL; + const char *loaderror = "Unknown error"; + image_id library_id = (image_id) handle; + if (get_image_symbol (library_id, + name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR) { + loaderror = "Symbol not found"; + } - if ( symbol == NULL ) { - SDL_SetError("Failed loading %s: %s", name, loaderror); - } - return(symbol); + if (symbol == NULL) { + SDL_SetError ("Failed loading %s: %s", name, loaderror); + } + return (symbol); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { - image_id library_id; - if ( handle != NULL ) { - library_id = (image_id)handle; - unload_add_on(library_id); - } + image_id library_id; + if (handle != NULL) { + library_id = (image_id) handle; + unload_add_on (library_id); + } } #endif /* SDL_LOADSO_BEOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/dlopen/SDL_sysloadso.c b/src/loadso/dlopen/SDL_sysloadso.c index ebd595500..9dc84a2ac 100644 --- a/src/loadso/dlopen/SDL_sysloadso.c +++ b/src/loadso/dlopen/SDL_sysloadso.c @@ -31,38 +31,43 @@ #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { - void *handle = dlopen(sofile, RTLD_NOW); - const char *loaderror = (char *)dlerror(); - if ( handle == NULL ) { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return(handle); + void *handle = dlopen (sofile, RTLD_NOW); + const char *loaderror = (char *) dlerror (); + if (handle == NULL) { + SDL_SetError ("Failed loading %s: %s", sofile, loaderror); + } + return (handle); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { - void *symbol = dlsym(handle, name); - if ( symbol == NULL ) { - size_t len = 1+SDL_strlen(name)+1; - char *_name = SDL_stack_alloc(char, len); - _name[0] = '_'; - SDL_strlcpy(&_name[1], name, len); - symbol = dlsym(handle, name); - SDL_stack_free(_name); - if ( symbol == NULL ) { - SDL_SetError("Failed loading %s: %s", name, (const char *)dlerror()); - } - } - return(symbol); + void *symbol = dlsym (handle, name); + if (symbol == NULL) { + size_t len = 1 + SDL_strlen (name) + 1; + char *_name = SDL_stack_alloc (char, len); + _name[0] = '_'; + SDL_strlcpy (&_name[1], name, len); + symbol = dlsym (handle, name); + SDL_stack_free (_name); + if (symbol == NULL) { + SDL_SetError ("Failed loading %s: %s", name, + (const char *) dlerror ()); + } + } + return (symbol); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { - if ( handle != NULL ) { - dlclose(handle); - } + if (handle != NULL) { + dlclose (handle); + } } #endif /* SDL_LOADSO_DLOPEN */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/dummy/SDL_sysloadso.c b/src/loadso/dummy/SDL_sysloadso.c index 6cd16b9a4..620505522 100644 --- a/src/loadso/dummy/SDL_sysloadso.c +++ b/src/loadso/dummy/SDL_sysloadso.c @@ -28,23 +28,27 @@ #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { - const char *loaderror = "SDL_LoadObject() not implemented"; - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - return(NULL); + const char *loaderror = "SDL_LoadObject() not implemented"; + SDL_SetError ("Failed loading %s: %s", sofile, loaderror); + return (NULL); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { - const char *loaderror = "SDL_LoadFunction() not implemented"; - SDL_SetError("Failed loading %s: %s", name, loaderror); - return(NULL); + const char *loaderror = "SDL_LoadFunction() not implemented"; + SDL_SetError ("Failed loading %s: %s", name, loaderror); + return (NULL); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { /* no-op. */ } #endif /* SDL_LOADSO_DUMMY || SDL_LOADSO_DISABLED */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/macos/SDL_sysloadso.c b/src/loadso/macos/SDL_sysloadso.c index 9a6df1d32..2e5e5de70 100644 --- a/src/loadso/macos/SDL_sysloadso.c +++ b/src/loadso/macos/SDL_sysloadso.c @@ -35,72 +35,76 @@ #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { - void *handle = NULL; - const char *loaderror = NULL; - CFragConnectionID library_id; - Ptr mainAddr; - Str255 errName; - OSErr error; - char psofile[512]; + void *handle = NULL; + const char *loaderror = NULL; + CFragConnectionID library_id; + Ptr mainAddr; + Str255 errName; + OSErr error; + char psofile[512]; - SDL_strlcpy(psofile, sofile, SDL_arraysize(psofile)); - error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch, - kLoadCFrag, &library_id, &mainAddr, errName); - switch (error) { - case noErr: - loaderror = NULL; - break; - case cfragNoLibraryErr: - loaderror = "Library not found"; - break; - case cfragUnresolvedErr: - loaderror = "Unabled to resolve symbols"; - break; - case cfragNoPrivateMemErr: - case cfragNoClientMemErr: - loaderror = "Out of memory"; - break; - default: - loaderror = "Unknown Code Fragment Manager error"; - break; - } - if ( loaderror == NULL ) { - handle = (void *)(library_id); - } else { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return(handle); + SDL_strlcpy (psofile, sofile, SDL_arraysize (psofile)); + error = GetSharedLibrary (C2PStr (psofile), kCompiledCFragArch, + kLoadCFrag, &library_id, &mainAddr, errName); + switch (error) { + case noErr: + loaderror = NULL; + break; + case cfragNoLibraryErr: + loaderror = "Library not found"; + break; + case cfragUnresolvedErr: + loaderror = "Unabled to resolve symbols"; + break; + case cfragNoPrivateMemErr: + case cfragNoClientMemErr: + loaderror = "Out of memory"; + break; + default: + loaderror = "Unknown Code Fragment Manager error"; + break; + } + if (loaderror == NULL) { + handle = (void *) (library_id); + } else { + SDL_SetError ("Failed loading %s: %s", sofile, loaderror); + } + return (handle); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { - void *symbol = NULL; - const char *loaderror = NULL; - CFragSymbolClass class; - CFragConnectionID library_id = (CFragConnectionID)handle; - char pname[512]; + void *symbol = NULL; + const char *loaderror = NULL; + CFragSymbolClass class; + CFragConnectionID library_id = (CFragConnectionID) handle; + char pname[512]; - SDL_strlcpy(pname, name, SDL_arraysize(pname)); - if ( FindSymbol(library_id, C2PStr(pname), - (char **)&symbol, &class) != noErr ) { - loaderror = "Symbol not found"; - } + SDL_strlcpy (pname, name, SDL_arraysize (pname)); + if (FindSymbol (library_id, C2PStr (pname), + (char **) &symbol, &class) != noErr) { + loaderror = "Symbol not found"; + } - if ( symbol == NULL ) { - SDL_SetError("Failed loading %s: %s", name, loaderror); - } - return(symbol); + if (symbol == NULL) { + SDL_SetError ("Failed loading %s: %s", name, loaderror); + } + return (symbol); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { - CFragConnectionID library_id; - if ( handle != NULL ) { - library_id = (CFragConnectionID)handle; - CloseConnection(&library_id); - } + CFragConnectionID library_id; + if (handle != NULL) { + library_id = (CFragConnectionID) handle; + CloseConnection (&library_id); + } } #endif /* SDL_LOADSO_MACOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/macosx/SDL_dlcompat.c b/src/loadso/macosx/SDL_dlcompat.c index 8628dd105..c8387634a 100644 --- a/src/loadso/macosx/SDL_dlcompat.c +++ b/src/loadso/macosx/SDL_dlcompat.c @@ -85,7 +85,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /*include "dlfcn.h"*/ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #if defined (__GNUC__) && __GNUC__ > 3 @@ -99,21 +100,24 @@ extern "C" { /* * Structure filled in by dladdr(). */ -typedef struct SDL_OSX_dl_info { - const char *dli_fname; /* Pathname of shared object */ - void *dli_fbase; /* Base address of shared object */ - const char *dli_sname; /* Name of nearest symbol */ - void *dli_saddr; /* Address of nearest symbol */ -} SDL_OSX_Dl_info; - -static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict); -#endif /* ! _POSIX_SOURCE */ -#endif /* 0 */ - -static int SDL_OSX_dlclose(void * handle); -static const char * SDL_OSX_dlerror(void); -static void * SDL_OSX_dlopen(const char *path, int mode); -static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol); + typedef struct SDL_OSX_dl_info + { + const char *dli_fname; /* Pathname of shared object */ + void *dli_fbase; /* Base address of shared object */ + const char *dli_sname; /* Name of nearest symbol */ + void *dli_saddr; /* Address of nearest symbol */ + } SDL_OSX_Dl_info; + + static int SDL_OSX_dladdr (const void *dl_restrict, + SDL_OSX_Dl_info * dl_restrict); +#endif /* ! _POSIX_SOURCE */ +#endif /* 0 */ + + static int SDL_OSX_dlclose (void *handle); + static const char *SDL_OSX_dlerror (void); + static void *SDL_OSX_dlopen (const char *path, int mode); + static void *SDL_OSX_dlsym (void *dl_restrict handle, + const char *dl_restrict symbol); #define RTLD_LAZY 0x1 #define RTLD_NOW 0x2 @@ -127,9 +131,9 @@ static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict /* * Special handle arguments for SDL_OSX_dlsym(). */ -#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */ -#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ -#endif /* ! _POSIX_SOURCE */ +#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */ +#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ +#endif /* ! _POSIX_SOURCE */ #ifdef __cplusplus } @@ -162,10 +166,13 @@ static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict #define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4 #endif /* These symbols will be looked for in dyld */ -static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0; -static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0; -static NSSymbol(*dyld_NSLookupSymbolInImage) - (const struct mach_header *, const char *, unsigned long) = 0; +static const struct mach_header *(*dyld_NSAddImage) (const char *, + unsigned long) = 0; +static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, + const char *) = 0; +static NSSymbol (*dyld_NSLookupSymbolInImage) (const struct mach_header *, + const char *, unsigned long) = + 0; /* Define this to make dlcompat reuse data block. This way in theory we save * a little bit of overhead. However we then couldn't correctly catch excess @@ -194,9 +201,9 @@ static pthread_key_t dlerror_key; struct dlthread { - int lockcnt; - unsigned char errset; - char errstr[ERR_STR_LEN]; + int lockcnt; + unsigned char errset; + char errstr[ERR_STR_LEN]; }; /* This is our central data structure. Whenever a module is loaded via @@ -204,18 +211,19 @@ struct dlthread */ struct dlstatus { - struct dlstatus *next; /* pointer to next element in the linked list */ - NSModule module; - const struct mach_header *lib; - int refs; /* reference count */ - int mode; /* mode in which this module was loaded */ - dev_t device; - ino_t inode; - int flags; /* Any internal flags we may need */ + struct dlstatus *next; /* pointer to next element in the linked list */ + NSModule module; + const struct mach_header *lib; + int refs; /* reference count */ + int mode; /* mode in which this module was loaded */ + dev_t device; + ino_t inode; + int flags; /* Any internal flags we may need */ }; /* Head node of the dlstatus list */ -static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 }; +static struct dlstatus mainStatus = + { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 }; static struct dlstatus *stqueue = &mainStatus; @@ -224,131 +232,136 @@ static struct dlstatus *stqueue = &mainStatus; /* static int err_filled = 0; */ /* Prototypes to internal functions */ -static void debug(const char *fmt, ...); -static void error(const char *str, ...); -static const char *safegetenv(const char *s); -static const char *searchList(void); -static const char *getSearchPath(int i); -static const char *getFullPath(int i, const char *file); -static const struct stat *findFile(const char *file, const char **fullPath); -static int isValidStatus(struct dlstatus *status); -static inline int isFlagSet(int mode, int flag); -static struct dlstatus *lookupStatus(const struct stat *sbuf); -static void insertStatus(struct dlstatus *dls, const struct stat *sbuf); -static int promoteLocalToGlobal(struct dlstatus *dls); -static void *reference(struct dlstatus *dls, int mode); -static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError); -static struct dlstatus *allocStatus(void); -static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode); -static NSSymbol search_linked_libs(const struct mach_header *mh, const char *symbol); -static const char *get_lib_name(const struct mach_header *mh); -static const struct mach_header *get_mach_header_from_NSModule(NSModule mod); -static void dlcompat_init_func(void); -static inline void dlcompat_init_check(void); -static inline void dolock(void); -static inline void dounlock(void); -static void dlerrorfree(void *data); -static void resetdlerror(void); -static const struct mach_header *my_find_image(const char *name); -static const struct mach_header *image_for_address(const void *address); -static inline char *dyld_error_str(void); +static void debug (const char *fmt, ...); +static void error (const char *str, ...); +static const char *safegetenv (const char *s); +static const char *searchList (void); +static const char *getSearchPath (int i); +static const char *getFullPath (int i, const char *file); +static const struct stat *findFile (const char *file, const char **fullPath); +static int isValidStatus (struct dlstatus *status); +static inline int isFlagSet (int mode, int flag); +static struct dlstatus *lookupStatus (const struct stat *sbuf); +static void insertStatus (struct dlstatus *dls, const struct stat *sbuf); +static int promoteLocalToGlobal (struct dlstatus *dls); +static void *reference (struct dlstatus *dls, int mode); +static void *dlsymIntern (struct dlstatus *dls, const char *symbol, + int canSetError); +static struct dlstatus *allocStatus (void); +static struct dlstatus *loadModule (const char *path, const struct stat *sbuf, + int mode); +static NSSymbol search_linked_libs (const struct mach_header *mh, + const char *symbol); +static const char *get_lib_name (const struct mach_header *mh); +static const struct mach_header *get_mach_header_from_NSModule (NSModule mod); +static void dlcompat_init_func (void); +static inline void dlcompat_init_check (void); +static inline void dolock (void); +static inline void dounlock (void); +static void dlerrorfree (void *data); +static void resetdlerror (void); +static const struct mach_header *my_find_image (const char *name); +static const struct mach_header *image_for_address (const void *address); +static inline char *dyld_error_str (void); #if FINK_BUILD /* Two Global Functions */ -static void *dlsym_prepend_underscore(void *handle, const char *symbol); -static void *dlsym_auto_underscore(void *handle, const char *symbol); +static void *dlsym_prepend_underscore (void *handle, const char *symbol); +static void *dlsym_auto_underscore (void *handle, const char *symbol); /* And their _intern counterparts */ -static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol); -static void *dlsym_auto_underscore_intern(void *handle, const char *symbol); +static void *dlsym_prepend_underscore_intern (void *handle, + const char *symbol); +static void *dlsym_auto_underscore_intern (void *handle, const char *symbol); #endif /* Functions */ -static void debug(const char *fmt, ...) +static void +debug (const char *fmt, ...) { #if DEBUG > 1 - va_list arg; - va_start(arg, fmt); - fprintf(stderr, "DLDEBUG: "); - vfprintf(stderr, fmt, arg); - fprintf(stderr, "\n"); - fflush(stderr); - va_end(arg); + va_list arg; + va_start (arg, fmt); + fprintf (stderr, "DLDEBUG: "); + vfprintf (stderr, fmt, arg); + fprintf (stderr, "\n"); + fflush (stderr); + va_end (arg); #endif } -static void error(const char *str, ...) +static void +error (const char *str, ...) { - va_list arg; - struct dlthread *tss; - char * err_str; - va_start(arg, str); - tss = pthread_getspecific(dlerror_key); - err_str = tss->errstr; - SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN); - vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg); - va_end(arg); - debug("ERROR: %s\n", err_str); - tss->errset = 1; + va_list arg; + struct dlthread *tss; + char *err_str; + va_start (arg, str); + tss = pthread_getspecific (dlerror_key); + err_str = tss->errstr; + SDL_strlcpy (err_str, "dlcompat: ", ERR_STR_LEN); + vsnprintf (err_str + 10, ERR_STR_LEN - 10, str, arg); + va_end (arg); + debug ("ERROR: %s\n", err_str); + tss->errset = 1; } -static void warning(const char *str) +static void +warning (const char *str) { #if DEBUG > 0 - fprintf(stderr, "WARNING: dlcompat: %s\n", str); + fprintf (stderr, "WARNING: dlcompat: %s\n", str); #endif } -static const char *safegetenv(const char *s) +static const char * +safegetenv (const char *s) { - const char *ss = SDL_getenv(s); - return ss ? ss : ""; + const char *ss = SDL_getenv (s); + return ss ? ss : ""; } /* because this is only used for debugging and error reporting functions, we * don't really care about how elegant it is... it could use the load * commands to find the install name of the library, but... */ -static const char *get_lib_name(const struct mach_header *mh) +static const char * +get_lib_name (const struct mach_header *mh) { - unsigned long count = _dyld_image_count(); - unsigned long i; - const char *val = NULL; - if (mh) - { - for (i = 0; i < count; i++) - { - if (mh == _dyld_get_image_header(i)) - { - val = _dyld_get_image_name(i); - break; - } - } - } - return val; + unsigned long count = _dyld_image_count (); + unsigned long i; + const char *val = NULL; + if (mh) { + for (i = 0; i < count; i++) { + if (mh == _dyld_get_image_header (i)) { + val = _dyld_get_image_name (i); + break; + } + } + } + return val; } /* Returns the mach_header for the module bu going through all the loaded images * and finding the one with the same name as the module. There really ought to be * an api for doing this, would be faster, but there isn't one right now */ -static const struct mach_header *get_mach_header_from_NSModule(NSModule mod) +static const struct mach_header * +get_mach_header_from_NSModule (NSModule mod) { - const char *mod_name = NSNameOfModule(mod); - const struct mach_header *mh = NULL; - unsigned long count = _dyld_image_count(); - unsigned long i; - debug("Module name: %s", mod_name); - for (i = 0; i < count; i++) - { - if (!SDL_strcmp(mod_name, _dyld_get_image_name(i))) - { - mh = _dyld_get_image_header(i); - break; - } - } - return mh; + const char *mod_name = NSNameOfModule (mod); + const struct mach_header *mh = NULL; + unsigned long count = _dyld_image_count (); + unsigned long i; + debug ("Module name: %s", mod_name); + for (i = 0; i < count; i++) { + if (!SDL_strcmp (mod_name, _dyld_get_image_name (i))) { + mh = _dyld_get_image_header (i); + break; + } + } + return mh; } @@ -360,225 +373,226 @@ static const struct mach_header *get_mach_header_from_NSModule(NSModule mod) * into one big string, which we then can easily parse. * Splitting this string into the actual path list is done by getSearchPath() */ -static const char *searchList() +static const char * +searchList () { - size_t buf_size; - static char *buf=NULL; - const char *ldlp = safegetenv("LD_LIBRARY_PATH"); - const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH"); - const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH"); - if (!stdpath) - stdpath = "/usr/local/lib:/lib:/usr/lib"; - if (!buf) - { - buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4; - buf = SDL_malloc(buf_size); - SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""), - stdpath, '\0'); - } - return buf; + size_t buf_size; + static char *buf = NULL; + const char *ldlp = safegetenv ("LD_LIBRARY_PATH"); + const char *dyldlp = safegetenv ("DYLD_LIBRARY_PATH"); + const char *stdpath = SDL_getenv ("DYLD_FALLBACK_LIBRARY_PATH"); + if (!stdpath) + stdpath = "/usr/local/lib:/lib:/usr/lib"; + if (!buf) { + buf_size = + SDL_strlen (ldlp) + SDL_strlen (dyldlp) + SDL_strlen (stdpath) + + 4; + buf = SDL_malloc (buf_size); + SDL_snprintf (buf, buf_size, "%s%s%s%s%s%c", dyldlp, + (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""), + stdpath, '\0'); + } + return buf; } /* Returns the ith search path from the list as computed by searchList() */ -static const char *getSearchPath(int i) +static const char * +getSearchPath (int i) { - static const char *list = 0; - static char **path = (char **)0; - static int end = 0; - static int numsize = MAX_SEARCH_PATHS; - static char **tmp; - /* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */ - if (i == -1) - { - return (const char*)path; - } - if (!path) - { - path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **)); - } - if (!list && !end) - list = searchList(); - if (i >= (numsize)) - { - debug("Increasing size for long PATH"); - tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **)); - if (tmp) - { - SDL_memcpy(tmp, path, sizeof(char **) * numsize); - SDL_free(path); - path = tmp; - numsize += MAX_SEARCH_PATHS; - } - else - { - return 0; - } - } - - while (!path[i] && !end) - { - path[i] = strsep((char **)&list, ":"); - - if (path[i][0] == 0) - path[i] = 0; - end = (list == 0); - } - return path[i]; + static const char *list = 0; + static char **path = (char **) 0; + static int end = 0; + static int numsize = MAX_SEARCH_PATHS; + static char **tmp; + /* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */ + if (i == -1) { + return (const char *) path; + } + if (!path) { + path = (char **) SDL_calloc (MAX_SEARCH_PATHS, sizeof (char **)); + } + if (!list && !end) + list = searchList (); + if (i >= (numsize)) { + debug ("Increasing size for long PATH"); + tmp = + (char **) SDL_calloc ((MAX_SEARCH_PATHS + numsize), + sizeof (char **)); + if (tmp) { + SDL_memcpy (tmp, path, sizeof (char **) * numsize); + SDL_free (path); + path = tmp; + numsize += MAX_SEARCH_PATHS; + } else { + return 0; + } + } + + while (!path[i] && !end) { + path[i] = strsep ((char **) &list, ":"); + + if (path[i][0] == 0) + path[i] = 0; + end = (list == 0); + } + return path[i]; } -static const char *getFullPath(int i, const char *file) +static const char * +getFullPath (int i, const char *file) { - static char buf[PATH_MAX]; - const char *path = getSearchPath(i); - if (path) - { - SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file); - } - return path ? buf : 0; + static char buf[PATH_MAX]; + const char *path = getSearchPath (i); + if (path) { + SDL_snprintf (buf, PATH_MAX, "%s/%s", path, file); + } + return path ? buf : 0; } /* Given a file name, try to determine the full path for that file. Starts * its search in the current directory, and then tries all paths in the * search list in the order they are specified there. */ -static const struct stat *findFile(const char *file, const char **fullPath) +static const struct stat * +findFile (const char *file, const char **fullPath) { - int i = 0; - static struct stat sbuf; - char *fileName; - debug("finding file %s", file); - *fullPath = file; - if (0 == stat(file, &sbuf)) - return &sbuf; - if (SDL_strchr(file, '/')) - return 0; /* If the path had a / we don't look in env var places */ - fileName = NULL; - if (!fileName) - fileName = (char *)file; - while ((*fullPath = getFullPath(i++, fileName))) - { - if (0 == stat(*fullPath, &sbuf)) - return &sbuf; - } - ; - return 0; + int i = 0; + static struct stat sbuf; + char *fileName; + debug ("finding file %s", file); + *fullPath = file; + if (0 == stat (file, &sbuf)) + return &sbuf; + if (SDL_strchr (file, '/')) + return 0; /* If the path had a / we don't look in env var places */ + fileName = NULL; + if (!fileName) + fileName = (char *) file; + while ((*fullPath = getFullPath (i++, fileName))) { + if (0 == stat (*fullPath, &sbuf)) + return &sbuf; + } + ; + return 0; } /* Determine whether a given dlstatus is valid or not */ -static int isValidStatus(struct dlstatus *status) +static int +isValidStatus (struct dlstatus *status) { - /* Walk the list to verify status is contained in it */ - struct dlstatus *dls = stqueue; - while (dls && status != dls) - dls = dls->next; - if (dls == 0) - error("invalid handle"); - else if ((dls->module == 0) || (dls->refs == 0)) - error("handle to closed library"); - else - return TRUE; - return FALSE; + /* Walk the list to verify status is contained in it */ + struct dlstatus *dls = stqueue; + while (dls && status != dls) + dls = dls->next; + if (dls == 0) + error ("invalid handle"); + else if ((dls->module == 0) || (dls->refs == 0)) + error ("handle to closed library"); + else + return TRUE; + return FALSE; } -static inline int isFlagSet(int mode, int flag) +static inline int +isFlagSet (int mode, int flag) { - return (mode & flag) == flag; + return (mode & flag) == flag; } -static struct dlstatus *lookupStatus(const struct stat *sbuf) +static struct dlstatus * +lookupStatus (const struct stat *sbuf) { - struct dlstatus *dls = stqueue; - debug("looking for status"); - while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0 - || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode)) - dls = dls->next; - return dls; + struct dlstatus *dls = stqueue; + debug ("looking for status"); + while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0 + || sbuf->st_dev != dls->device + || sbuf->st_ino != dls->inode)) + dls = dls->next; + return dls; } -static void insertStatus(struct dlstatus *dls, const struct stat *sbuf) +static void +insertStatus (struct dlstatus *dls, const struct stat *sbuf) { - debug("inserting status"); - dls->inode = sbuf->st_ino; - dls->device = sbuf->st_dev; - dls->refs = 0; - dls->mode = 0; - if ((dls->flags & DL_IN_LIST) == 0) - { - dls->next = stqueue; - stqueue = dls; - dls->flags |= DL_IN_LIST; - } + debug ("inserting status"); + dls->inode = sbuf->st_ino; + dls->device = sbuf->st_dev; + dls->refs = 0; + dls->mode = 0; + if ((dls->flags & DL_IN_LIST) == 0) { + dls->next = stqueue; + stqueue = dls; + dls->flags |= DL_IN_LIST; + } } -static struct dlstatus *allocStatus() +static struct dlstatus * +allocStatus () { - struct dlstatus *dls; + struct dlstatus *dls; #ifdef REUSE_STATUS - dls = stqueue; - while (dls && dls->module) - dls = dls->next; - if (!dls) + dls = stqueue; + while (dls && dls->module) + dls = dls->next; + if (!dls) #endif - dls = SDL_calloc(sizeof(*dls),1); - return dls; + dls = SDL_calloc (sizeof (*dls), 1); + return dls; } -static int promoteLocalToGlobal(struct dlstatus *dls) +static int +promoteLocalToGlobal (struct dlstatus *dls) { - static int (*p) (NSModule module) = 0; - debug("promoting"); - if (!p) - _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (void **)&p); - return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module)); + static int (*p) (NSModule module) = 0; + debug ("promoting"); + if (!p) + _dyld_func_lookup ("__dyld_NSMakePrivateModulePublic", (void **) &p); + return (dls->module == MAGIC_DYLIB_MOD) || (p && p (dls->module)); } -static void *reference(struct dlstatus *dls, int mode) +static void * +reference (struct dlstatus *dls, int mode) { - if (dls) - { - if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL)) - { - warning("trying to open a .dylib with RTLD_LOCAL"); - error("unable to open a .dylib with RTLD_LOCAL"); - return NULL; - } - if (isFlagSet(mode, RTLD_GLOBAL) && - !isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls)) - { - error("unable to promote local module to global"); - return NULL; - } - dls->mode |= mode; - dls->refs++; - } - else - debug("reference called with NULL argument"); - - return dls; + if (dls) { + if (dls->module == MAGIC_DYLIB_MOD && isFlagSet (mode, RTLD_LOCAL)) { + warning ("trying to open a .dylib with RTLD_LOCAL"); + error ("unable to open a .dylib with RTLD_LOCAL"); + return NULL; + } + if (isFlagSet (mode, RTLD_GLOBAL) && + !isFlagSet (dls->mode, RTLD_GLOBAL) + && !promoteLocalToGlobal (dls)) { + error ("unable to promote local module to global"); + return NULL; + } + dls->mode |= mode; + dls->refs++; + } else + debug ("reference called with NULL argument"); + + return dls; } -static const struct mach_header *my_find_image(const char *name) +static const struct mach_header * +my_find_image (const char *name) { - const struct mach_header *mh = 0; - const char *id = NULL; - int i = _dyld_image_count(); - int j; - mh = (struct mach_header *) - dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED | - NSADDIMAGE_OPTION_RETURN_ON_ERROR); - if (!mh) - { - for (j = 0; j < i; j++) - { - id = _dyld_get_image_name(j); - if (!SDL_strcmp(id, name)) - { - mh = _dyld_get_image_header(j); - break; - } - } - } - return mh; + const struct mach_header *mh = 0; + const char *id = NULL; + int i = _dyld_image_count (); + int j; + mh = (struct mach_header *) + dyld_NSAddImage (name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED | + NSADDIMAGE_OPTION_RETURN_ON_ERROR); + if (!mh) { + for (j = 0; j < i; j++) { + id = _dyld_get_image_name (j); + if (!SDL_strcmp (id, name)) { + mh = _dyld_get_image_header (j); + break; + } + } + } + return mh; } /* @@ -587,468 +601,440 @@ static const struct mach_header *my_find_image(const char *name) * bother adding the extra dependencies, if the symbols are neither in the loaded image nor * any of it's direct dependencies, then it probably isn't there. */ -static NSSymbol search_linked_libs(const struct mach_header * mh, const char *symbol) +static NSSymbol +search_linked_libs (const struct mach_header *mh, const char *symbol) { - unsigned int n; - struct load_command *lc = 0; - struct mach_header *wh; - NSSymbol nssym = 0; - if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage) - { - lc = (struct load_command *)((char *)mh + sizeof(struct mach_header)); - for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) - { - if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) - { - if ((wh = (struct mach_header *) - my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset + - (char *)lc)))) - { - if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol)) - { - nssym = dyld_NSLookupSymbolInImage(wh, - symbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | - NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - break; - } - } - } - } - if ((!nssym) && NSIsSymbolNameDefined(symbol)) - { - /* I've never seen this debug message...*/ - debug("Symbol \"%s\" is defined but was not found", symbol); - } - } - return nssym; + unsigned int n; + struct load_command *lc = 0; + struct mach_header *wh; + NSSymbol nssym = 0; + if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage + && dyld_NSLookupSymbolInImage) { + lc = (struct load_command *) ((char *) mh + + sizeof (struct mach_header)); + for (n = 0; n < mh->ncmds; + n++, lc = (struct load_command *) ((char *) lc + lc->cmdsize)) { + if ((LC_LOAD_DYLIB == lc->cmd) + || (LC_LOAD_WEAK_DYLIB == lc->cmd)) { + if ((wh = (struct mach_header *) + my_find_image ((char + *) (((struct dylib_command *) lc)-> + dylib.name.offset + (char *) lc)))) { + if (dyld_NSIsSymbolNameDefinedInImage (wh, symbol)) { + nssym = dyld_NSLookupSymbolInImage (wh, + symbol, + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND + | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + break; + } + } + } + } + if ((!nssym) && NSIsSymbolNameDefined (symbol)) { + /* I've never seen this debug message... */ + debug ("Symbol \"%s\" is defined but was not found", symbol); + } + } + return nssym; } /* Up to the caller to SDL_free() returned string */ -static inline char *dyld_error_str() +static inline char * +dyld_error_str () { - NSLinkEditErrors dylder; - int dylderno; - const char *dylderrstr; - const char *dyldfile; - char* retStr = NULL; - NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr); - if (dylderrstr && *dylderrstr) - { - retStr = SDL_strdup(dylderrstr); - } - return retStr; + NSLinkEditErrors dylder; + int dylderno; + const char *dylderrstr; + const char *dyldfile; + char *retStr = NULL; + NSLinkEditError (&dylder, &dylderno, &dyldfile, &dylderrstr); + if (dylderrstr && *dylderrstr) { + retStr = SDL_strdup (dylderrstr); + } + return retStr; } -static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError) +static void * +dlsymIntern (struct dlstatus *dls, const char *symbol, int canSetError) { - NSSymbol nssym = 0; -#ifdef __GCC__ - void *caller = __builtin_return_address(1); /* Be *very* careful about inlining */ + NSSymbol nssym = 0; +#ifdef __GCC__ + void *caller = __builtin_return_address (1); /* Be *very* careful about inlining */ #else - void *caller = NULL; + void *caller = NULL; #endif - const struct mach_header *caller_mh = 0; - char *savedErrorStr = NULL; - resetdlerror(); + const struct mach_header *caller_mh = 0; + char *savedErrorStr = NULL; + resetdlerror (); #ifndef RTLD_SELF #define RTLD_SELF ((void *) -3) #endif - if (NULL == dls) - dls = RTLD_SELF; - if ((RTLD_NEXT == dls) || (RTLD_SELF == dls)) - { - if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller) - { - caller_mh = image_for_address(caller); - if (RTLD_SELF == dls) - { - /* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE - * But it appears to work anyway, and looking at the code in dyld_libfuncs.c - * this is acceptable. - */ - if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol)) - { - nssym = dyld_NSLookupSymbolInImage(caller_mh, - symbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | - NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - } - } - if (!nssym) - { - if (RTLD_SELF == dls) - savedErrorStr = dyld_error_str(); - nssym = search_linked_libs(caller_mh, symbol); - } - } - else - { - if (canSetError) - error("RTLD_SELF and RTLD_NEXT are not supported"); - return NULL; - } - } - if (!nssym) - { - - if (RTLD_DEFAULT == dls) - { - dls = &mainStatus; - } - if (!isValidStatus(dls)) - return NULL; - - if (dls->module != MAGIC_DYLIB_MOD) - { - nssym = NSLookupSymbolInModule(dls->module, symbol); - if (!nssym && NSIsSymbolNameDefined(symbol)) - { - debug("Searching dependencies"); - savedErrorStr = dyld_error_str(); - nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol); - } - } - else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage) - { - if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol)) - { - nssym = dyld_NSLookupSymbolInImage(dls->lib, - symbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | - NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - } - else if (NSIsSymbolNameDefined(symbol)) - { - debug("Searching dependencies"); - savedErrorStr = dyld_error_str(); - nssym = search_linked_libs(dls->lib, symbol); - } - } - else if (dls->module == MAGIC_DYLIB_MOD) - { - /* Global context, use NSLookupAndBindSymbol */ - if (NSIsSymbolNameDefined(symbol)) - { - /* There doesn't seem to be a return on error option for this call??? - this is potentially broken, if binding fails, it will improperly - exit the application. */ - nssym = NSLookupAndBindSymbol(symbol); - } - else - { - if (savedErrorStr) - SDL_free(savedErrorStr); - savedErrorStr = SDL_malloc(256); - SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol); - } - } - } - /* Error reporting */ - if (!nssym) - { - if (!savedErrorStr || !SDL_strlen(savedErrorStr)) - { - if (savedErrorStr) - SDL_free(savedErrorStr); - savedErrorStr = SDL_malloc(256); - SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol); - } - if (canSetError) - { - error(savedErrorStr); - } - else - { - debug(savedErrorStr); - } - if (savedErrorStr) - SDL_free(savedErrorStr); - return NULL; - } - return NSAddressOfSymbol(nssym); + if (NULL == dls) + dls = RTLD_SELF; + if ((RTLD_NEXT == dls) || (RTLD_SELF == dls)) { + if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage + && caller) { + caller_mh = image_for_address (caller); + if (RTLD_SELF == dls) { + /* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE + * But it appears to work anyway, and looking at the code in dyld_libfuncs.c + * this is acceptable. + */ + if (dyld_NSIsSymbolNameDefinedInImage (caller_mh, symbol)) { + nssym = dyld_NSLookupSymbolInImage (caller_mh, + symbol, + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND + | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + } + } + if (!nssym) { + if (RTLD_SELF == dls) + savedErrorStr = dyld_error_str (); + nssym = search_linked_libs (caller_mh, symbol); + } + } else { + if (canSetError) + error ("RTLD_SELF and RTLD_NEXT are not supported"); + return NULL; + } + } + if (!nssym) { + + if (RTLD_DEFAULT == dls) { + dls = &mainStatus; + } + if (!isValidStatus (dls)) + return NULL; + + if (dls->module != MAGIC_DYLIB_MOD) { + nssym = NSLookupSymbolInModule (dls->module, symbol); + if (!nssym && NSIsSymbolNameDefined (symbol)) { + debug ("Searching dependencies"); + savedErrorStr = dyld_error_str (); + nssym = + search_linked_libs (get_mach_header_from_NSModule + (dls->module), symbol); + } + } else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage + && dyld_NSLookupSymbolInImage) { + if (dyld_NSIsSymbolNameDefinedInImage (dls->lib, symbol)) { + nssym = dyld_NSLookupSymbolInImage (dls->lib, + symbol, + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND + | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + } else if (NSIsSymbolNameDefined (symbol)) { + debug ("Searching dependencies"); + savedErrorStr = dyld_error_str (); + nssym = search_linked_libs (dls->lib, symbol); + } + } else if (dls->module == MAGIC_DYLIB_MOD) { + /* Global context, use NSLookupAndBindSymbol */ + if (NSIsSymbolNameDefined (symbol)) { + /* There doesn't seem to be a return on error option for this call??? + this is potentially broken, if binding fails, it will improperly + exit the application. */ + nssym = NSLookupAndBindSymbol (symbol); + } else { + if (savedErrorStr) + SDL_free (savedErrorStr); + savedErrorStr = SDL_malloc (256); + SDL_snprintf (savedErrorStr, 256, + "Symbol \"%s\" not in global context", symbol); + } + } + } + /* Error reporting */ + if (!nssym) { + if (!savedErrorStr || !SDL_strlen (savedErrorStr)) { + if (savedErrorStr) + SDL_free (savedErrorStr); + savedErrorStr = SDL_malloc (256); + SDL_snprintf (savedErrorStr, 256, "Symbol \"%s\" not found", + symbol); + } + if (canSetError) { + error (savedErrorStr); + } else { + debug (savedErrorStr); + } + if (savedErrorStr) + SDL_free (savedErrorStr); + return NULL; + } + return NSAddressOfSymbol (nssym); } -static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode) +static struct dlstatus * +loadModule (const char *path, const struct stat *sbuf, int mode) { - NSObjectFileImage ofi = 0; - NSObjectFileImageReturnCode ofirc; - struct dlstatus *dls; - NSLinkEditErrors ler; - int lerno; - const char *errstr; - const char *file; - void (*init) (void); - - ofirc = NSCreateObjectFileImageFromFile(path, &ofi); - switch (ofirc) - { - case NSObjectFileImageSuccess: - break; - case NSObjectFileImageInappropriateFile: - if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage) - { - if (isFlagSet(mode, RTLD_LOCAL)) - { - warning("trying to open a .dylib with RTLD_LOCAL"); - error("unable to open this file with RTLD_LOCAL"); - return NULL; - } - } - else - { - error("opening this file is unsupported on this system"); - return NULL; - } - break; - case NSObjectFileImageFailure: - error("object file setup failure"); - return NULL; - case NSObjectFileImageArch: - error("no object for this architecture"); - return NULL; - case NSObjectFileImageFormat: - error("bad object file format"); - return NULL; - case NSObjectFileImageAccess: - error("can't read object file"); - return NULL; - default: - error("unknown error from NSCreateObjectFileImageFromFile()"); - return NULL; - } - dls = lookupStatus(sbuf); - if (!dls) - { - dls = allocStatus(); - } - if (!dls) - { - error("unable to allocate memory"); - return NULL; - } - // dls->lib = 0; - if (ofirc == NSObjectFileImageInappropriateFile) - { - if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR))) - { - debug("Dynamic lib loaded at %ld", dls->lib); - ofi = MAGIC_DYLIB_OFI; - dls->module = MAGIC_DYLIB_MOD; - ofirc = NSObjectFileImageSuccess; - /* Although it is possible with a bit of work to modify this so it works and - functions with RTLD_NOW, I don't deem it necessary at the moment */ - } - if (!(dls->module)) - { - NSLinkEditError(&ler, &lerno, &file, &errstr); - if (!errstr || (!SDL_strlen(errstr))) - error("Can't open this file type"); - else - error(errstr); - if ((dls->flags & DL_IN_LIST) == 0) - { - SDL_free(dls); - } - return NULL; - } - } - else - { - dls->module = NSLinkModule(ofi, path, - NSLINKMODULE_OPTION_RETURN_ON_ERROR | - NSLINKMODULE_OPTION_PRIVATE | - (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0)); - NSDestroyObjectFileImage(ofi); - if (dls->module) - { - dls->lib = get_mach_header_from_NSModule(dls->module); - } - } - if (!dls->module) - { - NSLinkEditError(&ler, &lerno, &file, &errstr); - if ((dls->flags & DL_IN_LIST) == 0) - { - SDL_free(dls); - } - error(errstr); - return NULL; - } - - insertStatus(dls, sbuf); - dls = reference(dls, mode); - if ((init = dlsymIntern(dls, "__init", 0))) - { - debug("calling _init()"); - init(); - } - return dls; + NSObjectFileImage ofi = 0; + NSObjectFileImageReturnCode ofirc; + struct dlstatus *dls; + NSLinkEditErrors ler; + int lerno; + const char *errstr; + const char *file; + void (*init) (void); + + ofirc = NSCreateObjectFileImageFromFile (path, &ofi); + switch (ofirc) { + case NSObjectFileImageSuccess: + break; + case NSObjectFileImageInappropriateFile: + if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage + && dyld_NSLookupSymbolInImage) { + if (isFlagSet (mode, RTLD_LOCAL)) { + warning ("trying to open a .dylib with RTLD_LOCAL"); + error ("unable to open this file with RTLD_LOCAL"); + return NULL; + } + } else { + error ("opening this file is unsupported on this system"); + return NULL; + } + break; + case NSObjectFileImageFailure: + error ("object file setup failure"); + return NULL; + case NSObjectFileImageArch: + error ("no object for this architecture"); + return NULL; + case NSObjectFileImageFormat: + error ("bad object file format"); + return NULL; + case NSObjectFileImageAccess: + error ("can't read object file"); + return NULL; + default: + error ("unknown error from NSCreateObjectFileImageFromFile()"); + return NULL; + } + dls = lookupStatus (sbuf); + if (!dls) { + dls = allocStatus (); + } + if (!dls) { + error ("unable to allocate memory"); + return NULL; + } + // dls->lib = 0; + if (ofirc == NSObjectFileImageInappropriateFile) { + if ((dls->lib = + dyld_NSAddImage (path, NSADDIMAGE_OPTION_RETURN_ON_ERROR))) { + debug ("Dynamic lib loaded at %ld", dls->lib); + ofi = MAGIC_DYLIB_OFI; + dls->module = MAGIC_DYLIB_MOD; + ofirc = NSObjectFileImageSuccess; + /* Although it is possible with a bit of work to modify this so it works and + functions with RTLD_NOW, I don't deem it necessary at the moment */ + } + if (!(dls->module)) { + NSLinkEditError (&ler, &lerno, &file, &errstr); + if (!errstr || (!SDL_strlen (errstr))) + error ("Can't open this file type"); + else + error (errstr); + if ((dls->flags & DL_IN_LIST) == 0) { + SDL_free (dls); + } + return NULL; + } + } else { + dls->module = NSLinkModule (ofi, path, + NSLINKMODULE_OPTION_RETURN_ON_ERROR | + NSLINKMODULE_OPTION_PRIVATE | + (isFlagSet (mode, RTLD_NOW) ? + NSLINKMODULE_OPTION_BINDNOW : 0)); + NSDestroyObjectFileImage (ofi); + if (dls->module) { + dls->lib = get_mach_header_from_NSModule (dls->module); + } + } + if (!dls->module) { + NSLinkEditError (&ler, &lerno, &file, &errstr); + if ((dls->flags & DL_IN_LIST) == 0) { + SDL_free (dls); + } + error (errstr); + return NULL; + } + + insertStatus (dls, sbuf); + dls = reference (dls, mode); + if ((init = dlsymIntern (dls, "__init", 0))) { + debug ("calling _init()"); + init (); + } + return dls; } -inline static void dlcompat_init_check(void) +inline static void +dlcompat_init_check (void) { - static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER; - static int init_done = 0; - - pthread_mutex_lock(&l); - if (!init_done) { - dlcompat_init_func(); - init_done = 1; - } - pthread_mutex_unlock(&l); + static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER; + static int init_done = 0; + + pthread_mutex_lock (&l); + if (!init_done) { + dlcompat_init_func (); + init_done = 1; + } + pthread_mutex_unlock (&l); } -static void dlcompat_init_func(void) +static void +dlcompat_init_func (void) { - _dyld_func_lookup("__dyld_NSAddImage", (void **)&dyld_NSAddImage); - _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage", - (void **)&dyld_NSIsSymbolNameDefinedInImage); - _dyld_func_lookup("__dyld_NSLookupSymbolInImage", (void **)&dyld_NSLookupSymbolInImage); - if (pthread_mutex_init(&dlcompat_mutex, NULL)) - exit(1); - if (pthread_key_create(&dlerror_key, &dlerrorfree)) - exit(1); + _dyld_func_lookup ("__dyld_NSAddImage", (void **) &dyld_NSAddImage); + _dyld_func_lookup ("__dyld_NSIsSymbolNameDefinedInImage", + (void **) &dyld_NSIsSymbolNameDefinedInImage); + _dyld_func_lookup ("__dyld_NSLookupSymbolInImage", + (void **) &dyld_NSLookupSymbolInImage); + if (pthread_mutex_init (&dlcompat_mutex, NULL)) + exit (1); + if (pthread_key_create (&dlerror_key, &dlerrorfree)) + exit (1); } -static void resetdlerror() +static void +resetdlerror () { - struct dlthread *tss; - tss = pthread_getspecific(dlerror_key); - tss->errset = 0; + struct dlthread *tss; + tss = pthread_getspecific (dlerror_key); + tss->errset = 0; } -static void dlerrorfree(void *data) +static void +dlerrorfree (void *data) { - SDL_free(data); + SDL_free (data); } /* We kind of want a recursive lock here, but meet a little trouble * because they are not available pre OS X 10.2, so we fake it * using thread specific storage to keep a lock count - */ -static inline void dolock(void) + */ +static inline void +dolock (void) { - int err = 0; - struct dlthread *tss; - dlcompat_init_check(); - tss = pthread_getspecific(dlerror_key); - if (!tss) - { - tss = SDL_malloc(sizeof(struct dlthread)); - tss->lockcnt = 0; - tss->errset = 0; - if (pthread_setspecific(dlerror_key, tss)) - { - fprintf(stderr,"dlcompat: pthread_setspecific failed\n"); - exit(1); - } - } - if (!tss->lockcnt) - err = pthread_mutex_lock(&dlcompat_mutex); - tss->lockcnt = tss->lockcnt +1; - if (err) - exit(err); + int err = 0; + struct dlthread *tss; + dlcompat_init_check (); + tss = pthread_getspecific (dlerror_key); + if (!tss) { + tss = SDL_malloc (sizeof (struct dlthread)); + tss->lockcnt = 0; + tss->errset = 0; + if (pthread_setspecific (dlerror_key, tss)) { + fprintf (stderr, "dlcompat: pthread_setspecific failed\n"); + exit (1); + } + } + if (!tss->lockcnt) + err = pthread_mutex_lock (&dlcompat_mutex); + tss->lockcnt = tss->lockcnt + 1; + if (err) + exit (err); } -static inline void dounlock(void) +static inline void +dounlock (void) { - int err = 0; - struct dlthread *tss; - tss = pthread_getspecific(dlerror_key); - tss->lockcnt = tss->lockcnt -1; - if (!tss->lockcnt) - err = pthread_mutex_unlock(&dlcompat_mutex); - if (err) - exit(err); + int err = 0; + struct dlthread *tss; + tss = pthread_getspecific (dlerror_key); + tss->lockcnt = tss->lockcnt - 1; + if (!tss->lockcnt) + err = pthread_mutex_unlock (&dlcompat_mutex); + if (err) + exit (err); } -static void *SDL_OSX_dlopen(const char *path, int mode) +static void * +SDL_OSX_dlopen (const char *path, int mode) { - const struct stat *sbuf; - struct dlstatus *dls; - const char *fullPath; - - dolock(); - resetdlerror(); - if (!path) - { - dls = &mainStatus; - goto dlopenok; - } - if (!(sbuf = findFile(path, &fullPath))) - { - error("file \"%s\" not found", path); - goto dlopenerror; - } - /* Now checks that it hasn't been closed already */ - if ((dls = lookupStatus(sbuf)) && (dls->refs > 0)) - { - /* debug("status found"); */ - dls = reference(dls, mode); - goto dlopenok; - } + const struct stat *sbuf; + struct dlstatus *dls; + const char *fullPath; + + dolock (); + resetdlerror (); + if (!path) { + dls = &mainStatus; + goto dlopenok; + } + if (!(sbuf = findFile (path, &fullPath))) { + error ("file \"%s\" not found", path); + goto dlopenerror; + } + /* Now checks that it hasn't been closed already */ + if ((dls = lookupStatus (sbuf)) && (dls->refs > 0)) { + /* debug("status found"); */ + dls = reference (dls, mode); + goto dlopenok; + } #ifdef RTLD_NOLOAD - if (isFlagSet(mode, RTLD_NOLOAD)) - { - error("no existing handle and RTLD_NOLOAD specified"); - goto dlopenerror; - } + if (isFlagSet (mode, RTLD_NOLOAD)) { + error ("no existing handle and RTLD_NOLOAD specified"); + goto dlopenerror; + } #endif - if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW)) - { - error("how can I load something both RTLD_LAZY and RTLD_NOW?"); - goto dlopenerror; - } - dls = loadModule(fullPath, sbuf, mode); - + if (isFlagSet (mode, RTLD_LAZY) && isFlagSet (mode, RTLD_NOW)) { + error ("how can I load something both RTLD_LAZY and RTLD_NOW?"); + goto dlopenerror; + } + dls = loadModule (fullPath, sbuf, mode); + dlopenok: - dounlock(); - return (void *)dls; + dounlock (); + return (void *) dls; dlopenerror: - dounlock(); - return NULL; + dounlock (); + return NULL; } #if !FINK_BUILD -static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol) +static void * +SDL_OSX_dlsym (void *dl_restrict handle, const char *dl_restrict symbol) { - int sym_len = SDL_strlen(symbol); - void *value = NULL; - char *malloc_sym = NULL; - dolock(); - malloc_sym = SDL_malloc(sym_len + 2); - if (malloc_sym) - { - SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol); - value = dlsymIntern(handle, malloc_sym, 1); - SDL_free(malloc_sym); - } - else - { - error("Unable to allocate memory"); - goto dlsymerror; - } - dounlock(); - return value; + int sym_len = SDL_strlen (symbol); + void *value = NULL; + char *malloc_sym = NULL; + dolock (); + malloc_sym = SDL_malloc (sym_len + 2); + if (malloc_sym) { + SDL_snprintf (malloc_sym, sym_len + 2, "_%s", symbol); + value = dlsymIntern (handle, malloc_sym, 1); + SDL_free (malloc_sym); + } else { + error ("Unable to allocate memory"); + goto dlsymerror; + } + dounlock (); + return value; dlsymerror: - dounlock(); - return NULL; + dounlock (); + return NULL; } #endif #if FINK_BUILD -static void *dlsym_prepend_underscore(void *handle, const char *symbol) +static void * +dlsym_prepend_underscore (void *handle, const char *symbol) { - void *answer; - dolock(); - answer = dlsym_prepend_underscore_intern(handle, symbol); - dounlock(); - return answer; + void *answer; + dolock (); + answer = dlsym_prepend_underscore_intern (handle, symbol); + dounlock (); + return answer; } -static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol) +static void * +dlsym_prepend_underscore_intern (void *handle, const char *symbol) { /* * A quick and easy way for porting packages which call dlsym(handle,"sym") @@ -1059,272 +1045,268 @@ static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol) * the underscore always, or not at all. These global functions need to go away * for opendarwin. */ - int sym_len = SDL_strlen(symbol); - void *value = NULL; - char *malloc_sym = NULL; - malloc_sym = SDL_malloc(sym_len + 2); - if (malloc_sym) - { - SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol); - value = dlsymIntern(handle, malloc_sym, 1); - SDL_free(malloc_sym); - } - else - { - error("Unable to allocate memory"); - } - return value; + int sym_len = SDL_strlen (symbol); + void *value = NULL; + char *malloc_sym = NULL; + malloc_sym = SDL_malloc (sym_len + 2); + if (malloc_sym) { + SDL_snprintf (malloc_sym, sym_len + 2, "_%s", symbol); + value = dlsymIntern (handle, malloc_sym, 1); + SDL_free (malloc_sym); + } else { + error ("Unable to allocate memory"); + } + return value; } -static void *dlsym_auto_underscore(void *handle, const char *symbol) +static void * +dlsym_auto_underscore (void *handle, const char *symbol) { - void *answer; - dolock(); - answer = dlsym_auto_underscore_intern(handle, symbol); - dounlock(); - return answer; + void *answer; + dolock (); + answer = dlsym_auto_underscore_intern (handle, symbol); + dounlock (); + return answer; } -static void *dlsym_auto_underscore_intern(void *handle, const char *symbol) +static void * +dlsym_auto_underscore_intern (void *handle, const char *symbol) { - struct dlstatus *dls = handle; - void *addr = 0; - addr = dlsymIntern(dls, symbol, 0); - if (!addr) - addr = dlsym_prepend_underscore_intern(handle, symbol); - return addr; + struct dlstatus *dls = handle; + void *addr = 0; + addr = dlsymIntern (dls, symbol, 0); + if (!addr) + addr = dlsym_prepend_underscore_intern (handle, symbol); + return addr; } -static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol) +static void * +SDL_OSX_dlsym (void *dl_restrict handle, const char *dl_restrict symbol) { - struct dlstatus *dls = handle; - void *addr = 0; - dolock(); - addr = dlsymIntern(dls, symbol, 1); - dounlock(); - return addr; + struct dlstatus *dls = handle; + void *addr = 0; + dolock (); + addr = dlsymIntern (dls, symbol, 1); + dounlock (); + return addr; } #endif -static int SDL_OSX_dlclose(void *handle) +static int +SDL_OSX_dlclose (void *handle) { - struct dlstatus *dls = handle; - dolock(); - resetdlerror(); - if (!isValidStatus(dls)) - { - goto dlcloseerror; - } - if (dls->module == MAGIC_DYLIB_MOD) - { - const char *name; - if (!dls->lib) - { - name = "global context"; - } - else - { - name = get_lib_name(dls->lib); - } - warning("trying to close a .dylib!"); - error("Not closing \"%s\" - dynamic libraries cannot be closed", name); - goto dlcloseerror; - } - if (!dls->module) - { - error("module already closed"); - goto dlcloseerror; - } - - if (dls->refs == 1) - { - unsigned long options = 0; - void (*fini) (void); - if ((fini = dlsymIntern(dls, "__fini", 0))) - { - debug("calling _fini()"); - fini(); - } - options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; + struct dlstatus *dls = handle; + dolock (); + resetdlerror (); + if (!isValidStatus (dls)) { + goto dlcloseerror; + } + if (dls->module == MAGIC_DYLIB_MOD) { + const char *name; + if (!dls->lib) { + name = "global context"; + } else { + name = get_lib_name (dls->lib); + } + warning ("trying to close a .dylib!"); + error ("Not closing \"%s\" - dynamic libraries cannot be closed", + name); + goto dlcloseerror; + } + if (!dls->module) { + error ("module already closed"); + goto dlcloseerror; + } + + if (dls->refs == 1) { + unsigned long options = 0; + void (*fini) (void); + if ((fini = dlsymIntern (dls, "__fini", 0))) { + debug ("calling _fini()"); + fini (); + } + options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; #ifdef RTLD_NODELETE - if (isFlagSet(dls->mode, RTLD_NODELETE)) - options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; + if (isFlagSet (dls->mode, RTLD_NODELETE)) + options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; #endif - if (!NSUnLinkModule(dls->module, options)) - { - error("unable to unlink module"); - goto dlcloseerror; - } - dls->refs--; - dls->module = 0; - /* Note: the dlstatus struct dls is neither removed from the list - * nor is the memory it occupies freed. This shouldn't pose a - * problem in mostly all cases, though. - */ - } - dounlock(); - return 0; + if (!NSUnLinkModule (dls->module, options)) { + error ("unable to unlink module"); + goto dlcloseerror; + } + dls->refs--; + dls->module = 0; + /* Note: the dlstatus struct dls is neither removed from the list + * nor is the memory it occupies freed. This shouldn't pose a + * problem in mostly all cases, though. + */ + } + dounlock (); + return 0; dlcloseerror: - dounlock(); - return 1; + dounlock (); + return 1; } -static const char *SDL_OSX_dlerror(void) +static const char * +SDL_OSX_dlerror (void) { - struct dlthread *tss; - const char * err_str = NULL; - dlcompat_init_check(); - tss = pthread_getspecific(dlerror_key); - if (tss != NULL && tss->errset != 0) { - tss->errset = 0; - err_str = tss->errstr; - } - return (err_str); + struct dlthread *tss; + const char *err_str = NULL; + dlcompat_init_check (); + tss = pthread_getspecific (dlerror_key); + if (tss != NULL && tss->errset != 0) { + tss->errset = 0; + err_str = tss->errstr; + } + return (err_str); } /* Given an address, return the mach_header for the image containing it * or zero if the given address is not contained in any loaded images. */ -static const struct mach_header *image_for_address(const void *address) +static const struct mach_header * +image_for_address (const void *address) { - unsigned long i; - unsigned long j; - unsigned long count = _dyld_image_count(); - const struct mach_header *mh = 0; - struct load_command *lc = 0; - unsigned long addr = 0; - for (i = 0; i < count; i++) - { - addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i); - mh = _dyld_get_image_header(i); - if (mh) - { - lc = (struct load_command *)((char *)mh + sizeof(struct mach_header)); - for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) - { - if (LC_SEGMENT == lc->cmd && - addr >= ((struct segment_command *)lc)->vmaddr && - addr < - ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize) - { - goto image_found; - } - } - } - mh = 0; - } + unsigned long i; + unsigned long j; + unsigned long count = _dyld_image_count (); + const struct mach_header *mh = 0; + struct load_command *lc = 0; + unsigned long addr = 0; + for (i = 0; i < count; i++) { + addr = (unsigned long) address - _dyld_get_image_vmaddr_slide (i); + mh = _dyld_get_image_header (i); + if (mh) { + lc = (struct load_command *) ((char *) mh + + sizeof (struct mach_header)); + for (j = 0; j < mh->ncmds; + j++, lc = + (struct load_command *) ((char *) lc + lc->cmdsize)) { + if (LC_SEGMENT == lc->cmd && + addr >= ((struct segment_command *) lc)->vmaddr && + addr < + ((struct segment_command *) lc)->vmaddr + + ((struct segment_command *) lc)->vmsize) { + goto image_found; + } + } + } + mh = 0; + } image_found: - return mh; + return mh; } -#if 0 /* unused */ -static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info) +#if 0 /* unused */ +static int +SDL_OSX_dladdr (const void *dl_restrict p, SDL_OSX_Dl_info * dl_restrict info) { /* FIXME: USe the routine image_for_address. */ - unsigned long i; - unsigned long j; - unsigned long count = _dyld_image_count(); - struct mach_header *mh = 0; - struct load_command *lc = 0; - unsigned long addr = NULL; - unsigned long table_off = (unsigned long)0; - int found = 0; - if (!info) - return 0; - dolock(); - resetdlerror(); - info->dli_fname = 0; - info->dli_fbase = 0; - info->dli_sname = 0; - info->dli_saddr = 0; + unsigned long i; + unsigned long j; + unsigned long count = _dyld_image_count (); + struct mach_header *mh = 0; + struct load_command *lc = 0; + unsigned long addr = NULL; + unsigned long table_off = (unsigned long) 0; + int found = 0; + if (!info) + return 0; + dolock (); + resetdlerror (); + info->dli_fname = 0; + info->dli_fbase = 0; + info->dli_sname = 0; + info->dli_saddr = 0; /* Some of this was swiped from code posted by Douglas Davidson * to darwin-development AT lists DOT apple DOT com and slightly modified */ - for (i = 0; i < count; i++) - { - addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i); - mh = _dyld_get_image_header(i); - if (mh) - { - lc = (struct load_command *)((char *)mh + sizeof(struct mach_header)); - for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) - { - if (LC_SEGMENT == lc->cmd && - addr >= ((struct segment_command *)lc)->vmaddr && - addr < - ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize) - { - info->dli_fname = _dyld_get_image_name(i); - info->dli_fbase = (void *)mh; - found = 1; - break; - } - } - if (found) - break; - } - } - if (!found) - { - dounlock(); - return 0; - } - lc = (struct load_command *)((char *)mh + sizeof(struct mach_header)); - for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) - { - if (LC_SEGMENT == lc->cmd) - { - if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT")) - break; - } - } - table_off = - ((unsigned long)((struct segment_command *)lc)->vmaddr) - - ((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i); - debug("table off %x", table_off); - - lc = (struct load_command *)((char *)mh + sizeof(struct mach_header)); - for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) - { - if (LC_SYMTAB == lc->cmd) - { - - struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off); - unsigned long numsyms = ((struct symtab_command *)lc)->nsyms; - struct nlist *nearest = NULL; - unsigned long diff = 0xffffffff; - unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off); - debug("symtable %x", symtable); - for (i = 0; i < numsyms; i++) - { - /* Ignore the following kinds of Symbols */ - if ((!symtable->n_value) /* Undefined */ - || (symtable->n_type >= N_PEXT) /* Debug symbol */ - || (!(symtable->n_type & N_EXT)) /* Local Symbol */ - ) - { - symtable++; - continue; - } - if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr))) - { - diff = (unsigned long)symtable->n_value - addr; - nearest = symtable; - } - symtable++; - } - if (nearest) - { - info->dli_saddr = nearest->n_value + ((void *)p - addr); - info->dli_sname = (char *)(strtable + nearest->n_un.n_strx); - } - } - } - dounlock(); - return 1; + for (i = 0; i < count; i++) { + addr = (unsigned long) p - _dyld_get_image_vmaddr_slide (i); + mh = _dyld_get_image_header (i); + if (mh) { + lc = (struct load_command *) ((char *) mh + + sizeof (struct mach_header)); + for (j = 0; j < mh->ncmds; + j++, lc = + (struct load_command *) ((char *) lc + lc->cmdsize)) { + if (LC_SEGMENT == lc->cmd && + addr >= ((struct segment_command *) lc)->vmaddr && + addr < + ((struct segment_command *) lc)->vmaddr + + ((struct segment_command *) lc)->vmsize) { + info->dli_fname = _dyld_get_image_name (i); + info->dli_fbase = (void *) mh; + found = 1; + break; + } + } + if (found) + break; + } + } + if (!found) { + dounlock (); + return 0; + } + lc = (struct load_command *) ((char *) mh + sizeof (struct mach_header)); + for (j = 0; j < mh->ncmds; + j++, lc = (struct load_command *) ((char *) lc + lc->cmdsize)) { + if (LC_SEGMENT == lc->cmd) { + if (!SDL_strcmp + (((struct segment_command *) lc)->segname, "__LINKEDIT")) + break; + } + } + table_off = + ((unsigned long) ((struct segment_command *) lc)->vmaddr) - + ((unsigned long) ((struct segment_command *) lc)->fileoff) + + _dyld_get_image_vmaddr_slide (i); + debug ("table off %x", table_off); + + lc = (struct load_command *) ((char *) mh + sizeof (struct mach_header)); + for (j = 0; j < mh->ncmds; + j++, lc = (struct load_command *) ((char *) lc + lc->cmdsize)) { + if (LC_SYMTAB == lc->cmd) { + + struct nlist *symtable = + (struct nlist *) (((struct symtab_command *) lc)->symoff + + table_off); + unsigned long numsyms = ((struct symtab_command *) lc)->nsyms; + struct nlist *nearest = NULL; + unsigned long diff = 0xffffffff; + unsigned long strtable = + (unsigned long) (((struct symtab_command *) lc)->stroff + + table_off); + debug ("symtable %x", symtable); + for (i = 0; i < numsyms; i++) { + /* Ignore the following kinds of Symbols */ + if ((!symtable->n_value) /* Undefined */ + ||(symtable->n_type >= N_PEXT) /* Debug symbol */ + ||(!(symtable->n_type & N_EXT)) /* Local Symbol */ + ) { + symtable++; + continue; + } + if ((addr >= symtable->n_value) + && (diff >= (symtable->n_value - addr))) { + diff = (unsigned long) symtable->n_value - addr; + nearest = symtable; + } + symtable++; + } + if (nearest) { + info->dli_saddr = nearest->n_value + ((void *) p - addr); + info->dli_sname = (char *) (strtable + nearest->n_un.n_strx); + } + } + } + dounlock (); + return 1; } #endif @@ -1337,34 +1319,32 @@ static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restr * have the same representation, which is true on all platforms FreeBSD * runs on, but is not guaranteed by the C standard. */ -#if 0 -static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol) +#if 0 +static dlfunc_t +SDL_OSX_dlfunc (void *dl_restrict handle, const char *dl_restrict symbol) { - union - { - void *d; - dlfunc_t f; - } rv; - int sym_len = SDL_strlen(symbol); - char *malloc_sym = NULL; - dolock(); - malloc_sym = SDL_malloc(sym_len + 2); - if (malloc_sym) - { - SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol); - rv.d = dlsymIntern(handle, malloc_sym, 1); - SDL_free(malloc_sym); - } - else - { - error("Unable to allocate memory"); - goto dlfuncerror; - } - dounlock(); - return rv.f; + union + { + void *d; + dlfunc_t f; + } rv; + int sym_len = SDL_strlen (symbol); + char *malloc_sym = NULL; + dolock (); + malloc_sym = SDL_malloc (sym_len + 2); + if (malloc_sym) { + SDL_snprintf (malloc_sym, sym_len + 2, "_%s", symbol); + rv.d = dlsymIntern (handle, malloc_sym, 1); + SDL_free (malloc_sym); + } else { + error ("Unable to allocate memory"); + goto dlfuncerror; + } + dounlock (); + return rv.f; dlfuncerror: - dounlock(); - return NULL; + dounlock (); + return NULL; } #endif @@ -1378,30 +1358,34 @@ static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restri #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { - void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW); - const char *loaderror = SDL_OSX_dlerror(); - if ( handle == NULL ) { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return(handle); + void *handle = SDL_OSX_dlopen (sofile, RTLD_NOW); + const char *loaderror = SDL_OSX_dlerror (); + if (handle == NULL) { + SDL_SetError ("Failed loading %s: %s", sofile, loaderror); + } + return (handle); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { - void *symbol = SDL_OSX_dlsym(handle, name); - if ( symbol == NULL ) { - SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror()); - } - return(symbol); + void *symbol = SDL_OSX_dlsym (handle, name); + if (symbol == NULL) { + SDL_SetError ("Failed loading %s: %s", name, SDL_OSX_dlerror ()); + } + return (symbol); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { - if ( handle != NULL ) { - SDL_OSX_dlclose(handle); - } + if (handle != NULL) { + SDL_OSX_dlclose (handle); + } } #endif /* SDL_LOADSO_DLCOMPAT */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/mint/SDL_sysloadso.c b/src/loadso/mint/SDL_sysloadso.c index d089e1b93..65854d1a4 100644 --- a/src/loadso/mint/SDL_sysloadso.c +++ b/src/loadso/mint/SDL_sysloadso.c @@ -32,31 +32,35 @@ #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { - const char *loaderror = "Unknown error"; - void *handle = (void *)ldg_open((char *)sofile, ldg_global); - if ( handle == NULL ) { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return(handle); + const char *loaderror = "Unknown error"; + void *handle = (void *) ldg_open ((char *) sofile, ldg_global); + if (handle == NULL) { + SDL_SetError ("Failed loading %s: %s", sofile, loaderror); + } + return (handle); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { - const char *loaderror = "Unknown error"; - void *symbol = (void *)ldg_find((char *)name, (LDG *)handle); - if ( symbol == NULL ) { - SDL_SetError("Failed loading %s: %s", name, loaderror); - } - return(symbol); + const char *loaderror = "Unknown error"; + void *symbol = (void *) ldg_find ((char *) name, (LDG *) handle); + if (symbol == NULL) { + SDL_SetError ("Failed loading %s: %s", name, loaderror); + } + return (symbol); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { - if ( handle != NULL ) { - ldg_close((LDG *)handle, ldg_global); - } + if (handle != NULL) { + ldg_close ((LDG *) handle, ldg_global); + } } #endif /* SDL_LOADSO_LDG */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/os2/SDL_sysloadso.c b/src/loadso/os2/SDL_sysloadso.c index 006759103..ff847c24f 100644 --- a/src/loadso/os2/SDL_sysloadso.c +++ b/src/loadso/os2/SDL_sysloadso.c @@ -33,39 +33,44 @@ #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { HMODULE handle = NULL; char buf[512]; - APIRET ulrc = DosLoadModule(buf, sizeof (buf), (char *) sofile, &handle); + APIRET ulrc = DosLoadModule (buf, sizeof (buf), (char *) sofile, &handle); /* Generate an error message if all loads failed */ if ((ulrc != NO_ERROR) || (handle == NULL)) - SDL_SetError("Failed loading %s: %s", sofile, buf); + SDL_SetError ("Failed loading %s: %s", sofile, buf); - return((void *) handle); + return ((void *) handle); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { const char *loaderror = "Unknown error"; void *symbol = NULL; - APIRET ulrc = DosQueryProcAddr((HMODULE)handle, 0, (char *)name, &symbol); + APIRET ulrc = + DosQueryProcAddr ((HMODULE) handle, 0, (char *) name, &symbol); if (ulrc == ERROR_INVALID_HANDLE) loaderror = "Invalid module handle"; else if (ulrc == ERROR_INVALID_NAME) loaderror = "Symbol not found"; if (symbol == NULL) - SDL_SetError("Failed loading %s: %s", name, loaderror); + SDL_SetError ("Failed loading %s: %s", name, loaderror); - return(symbol); + return (symbol); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { - if ( handle != NULL ) - DosFreeModule((HMODULE) handle); + if (handle != NULL) + DosFreeModule ((HMODULE) handle); } #endif /* SDL_LOADSO_OS2 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/loadso/win32/SDL_sysloadso.c b/src/loadso/win32/SDL_sysloadso.c index 8ed7c68c4..bd1799c61 100644 --- a/src/loadso/win32/SDL_sysloadso.c +++ b/src/loadso/win32/SDL_sysloadso.c @@ -31,109 +31,116 @@ #include "SDL_loadso.h" -void *SDL_LoadObject(const char *sofile) +void * +SDL_LoadObject (const char *sofile) { - void *handle = NULL; - const char *loaderror = "Unknown error"; + void *handle = NULL; + const char *loaderror = "Unknown error"; #if defined(_WIN32_WCE) - char errbuf[512]; - - wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); - wchar_t *sofile_t = SDL_malloc((MAX_PATH+1) * sizeof(wchar_t)); - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH); - handle = (void *)LoadLibrary(sofile_t); - - /* Generate an error message if all loads failed */ - if ( handle == NULL ) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_arraysize(errbuf), NULL); - WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); - loaderror = errbuf; - } - - SDL_free(sofile_t); - SDL_free(errbuf_t); - -#else /*if defined(__WIN32__)*/ - char errbuf[512]; - - handle = (void *)LoadLibrary(sofile); - - /* Generate an error message if all loads failed */ - if ( handle == NULL ) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_arraysize(errbuf), NULL); - loaderror = errbuf; - } + char errbuf[512]; + + wchar_t *errbuf_t = SDL_malloc (512 * sizeof (wchar_t)); + wchar_t *sofile_t = SDL_malloc ((MAX_PATH + 1) * sizeof (wchar_t)); + + MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, + MAX_PATH); + handle = (void *) LoadLibrary (sofile_t); + + /* Generate an error message if all loads failed */ + if (handle == NULL) { + FormatMessage ((FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM), + NULL, GetLastError (), + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), + errbuf_t, SDL_arraysize (errbuf), NULL); + WideCharToMultiByte (CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, + NULL); + loaderror = errbuf; + } + + SDL_free (sofile_t); + SDL_free (errbuf_t); + +#else /*if defined(__WIN32__) */ + char errbuf[512]; + + handle = (void *) LoadLibrary (sofile); + + /* Generate an error message if all loads failed */ + if (handle == NULL) { + FormatMessage ((FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM), + NULL, GetLastError (), + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), + errbuf, SDL_arraysize (errbuf), NULL); + loaderror = errbuf; + } #endif - if ( handle == NULL ) { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return(handle); + if (handle == NULL) { + SDL_SetError ("Failed loading %s: %s", sofile, loaderror); + } + return (handle); } -void *SDL_LoadFunction(void *handle, const char *name) +void * +SDL_LoadFunction (void *handle, const char *name) { - void *symbol = NULL; - const char *loaderror = "Unknown error"; + void *symbol = NULL; + const char *loaderror = "Unknown error"; #if defined(_WIN32_WCE) - char errbuf[512]; - int length = SDL_strlen(name); - - wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t)); - wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length); - - symbol = (void *)GetProcAddress((HMODULE)handle, name_t); - if ( symbol == NULL ) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_arraysize(errbuf), NULL); - WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); - loaderror = errbuf; - } - - SDL_free(name_t); - SDL_free(errbuf_t); - -#else /*if defined(WIN32)*/ - char errbuf[512]; - - symbol = (void *)GetProcAddress((HMODULE)handle, name); - if ( symbol == NULL ) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_arraysize(errbuf), NULL); - loaderror = errbuf; - } + char errbuf[512]; + int length = SDL_strlen (name); + + wchar_t *name_t = SDL_malloc ((length + 1) * sizeof (wchar_t)); + wchar_t *errbuf_t = SDL_malloc (512 * sizeof (wchar_t)); + + MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length); + + symbol = (void *) GetProcAddress ((HMODULE) handle, name_t); + if (symbol == NULL) { + FormatMessage ((FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM), + NULL, GetLastError (), + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), + errbuf_t, SDL_arraysize (errbuf), NULL); + WideCharToMultiByte (CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, + NULL); + loaderror = errbuf; + } + + SDL_free (name_t); + SDL_free (errbuf_t); + +#else /*if defined(WIN32) */ + char errbuf[512]; + + symbol = (void *) GetProcAddress ((HMODULE) handle, name); + if (symbol == NULL) { + FormatMessage ((FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM), + NULL, GetLastError (), + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), + errbuf, SDL_arraysize (errbuf), NULL); + loaderror = errbuf; + } #endif - if ( symbol == NULL ) { - SDL_SetError("Failed loading %s: %s", name, loaderror); - } - return(symbol); + if (symbol == NULL) { + SDL_SetError ("Failed loading %s: %s", name, loaderror); + } + return (symbol); } -void SDL_UnloadObject(void *handle) +void +SDL_UnloadObject (void *handle) { - if ( handle != NULL ) { - FreeLibrary((HMODULE)handle); - } + if (handle != NULL) { + FreeLibrary ((HMODULE) handle); + } } #endif /* SDL_LOADSO_WIN32 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index 96268cc16..34a3cec3b 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -37,73 +37,79 @@ int SDL_BeAppActive = 0; static SDL_Thread *SDL_AppThread = NULL; -static int StartBeApp(void *unused) +static int +StartBeApp (void *unused) { - BApplication *App; + BApplication *App; - App = new BApplication("application/x-SDL-executable"); + App = new BApplication ("application/x-SDL-executable"); - App->Run(); - delete App; - return(0); + App->Run (); + delete App; + return (0); } /* Initialize the Be Application, if it's not already started */ -int SDL_InitBeApp(void) +int +SDL_InitBeApp (void) { - /* Create the BApplication that handles appserver interaction */ - if ( SDL_BeAppActive <= 0 ) { - SDL_AppThread = SDL_CreateThread(StartBeApp, NULL); - if ( SDL_AppThread == NULL ) { - SDL_SetError("Couldn't create BApplication thread"); - return(-1); - } - - /* Change working to directory to that of executable */ - app_info info; - if (B_OK == be_app->GetAppInfo(&info)) { - entry_ref ref = info.ref; - BEntry entry; - if (B_OK == entry.SetTo(&ref)) { - BPath path; - if (B_OK == path.SetTo(&entry)) { - if (B_OK == path.GetParent(&path)) { - chdir(path.Path()); - } - } - } - } - - do { - SDL_Delay(10); - } while ( (be_app == NULL) || be_app->IsLaunching() ); - - /* Mark the application active */ - SDL_BeAppActive = 0; - } - - /* Increment the application reference count */ - ++SDL_BeAppActive; - - /* The app is running, and we're ready to go */ - return(0); + /* Create the BApplication that handles appserver interaction */ + if (SDL_BeAppActive <= 0) { + SDL_AppThread = SDL_CreateThread (StartBeApp, NULL); + if (SDL_AppThread == NULL) { + SDL_SetError ("Couldn't create BApplication thread"); + return (-1); + } + + /* Change working to directory to that of executable */ + app_info info; + if (B_OK == be_app->GetAppInfo (&info)) { + entry_ref ref = info.ref; + BEntry entry; + if (B_OK == entry.SetTo (&ref)) { + BPath path; + if (B_OK == path.SetTo (&entry)) { + if (B_OK == path.GetParent (&path)) { + chdir (path.Path ()); + } + } + } + } + + do { + SDL_Delay (10); + } + while ((be_app == NULL) || be_app->IsLaunching ()); + + /* Mark the application active */ + SDL_BeAppActive = 0; + } + + /* Increment the application reference count */ + ++SDL_BeAppActive; + + /* The app is running, and we're ready to go */ + return (0); } /* Quit the Be Application, if there's nothing left to do */ -void SDL_QuitBeApp(void) +void +SDL_QuitBeApp (void) { - /* Decrement the application reference count */ - --SDL_BeAppActive; - - /* If the reference count reached zero, clean up the app */ - if ( SDL_BeAppActive == 0 ) { - if ( SDL_AppThread != NULL ) { - if ( be_app != NULL ) { /* Not tested */ - be_app->PostMessage(B_QUIT_REQUESTED); - } - SDL_WaitThread(SDL_AppThread, NULL); - SDL_AppThread = NULL; - } - /* be_app should now be NULL since be_app has quit */ - } + /* Decrement the application reference count */ + --SDL_BeAppActive; + + /* If the reference count reached zero, clean up the app */ + if (SDL_BeAppActive == 0) { + if (SDL_AppThread != NULL) { + if (be_app != NULL) { /* Not tested */ + be_app->PostMessage (B_QUIT_REQUESTED); + } + SDL_WaitThread (SDL_AppThread, NULL); + SDL_AppThread = NULL; + } + /* be_app should now be NULL since be_app has quit */ + } } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/main/beos/SDL_BeApp.h b/src/main/beos/SDL_BeApp.h index f55dc1d80..77d368844 100644 --- a/src/main/beos/SDL_BeApp.h +++ b/src/main/beos/SDL_BeApp.h @@ -24,10 +24,11 @@ /* Handle the BeApp specific portions of the application */ /* Initialize the Be Application, if it's not already started */ -extern int SDL_InitBeApp(void); +extern int SDL_InitBeApp (void); /* Quit the Be Application, if there's nothing left to do */ -extern void SDL_QuitBeApp(void); +extern void SDL_QuitBeApp (void); /* Flag to tell whether the app is active or not */ extern int SDL_BeAppActive; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/main/dummy/SDL_dummy_main.c b/src/main/dummy/SDL_dummy_main.c index da47d06a8..eee41bda1 100644 --- a/src/main/dummy/SDL_dummy_main.c +++ b/src/main/dummy/SDL_dummy_main.c @@ -4,10 +4,12 @@ #ifdef main #undef main -int main(int argc, char *argv[]) +int +main (int argc, char *argv[]) { - return(SDL_main(argc, argv)); + return (SDL_main (argc, argv)); } #else /* Nothing to do on this platform */ #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/main/macos/SDL_main.c b/src/main/macos/SDL_main.c index 348638b0d..c50a263c8 100644 --- a/src/main/macos/SDL_main.c +++ b/src/main/macos/SDL_main.c @@ -50,561 +50,599 @@ #endif #if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON - /* In MPW, the qd global has been removed from the libraries */ - QDGlobals qd; + /* In MPW, the qd global has been removed from the libraries */ +QDGlobals qd; #endif /* Structure for keeping prefs in 1 variable */ -typedef struct { - Str255 command_line; - Str255 video_driver_name; +typedef struct +{ + Str255 command_line; + Str255 video_driver_name; Boolean output_to_file; -} PrefsRecord; +} PrefsRecord; /* See if the command key is held down at startup */ -static Boolean CommandKeyIsDown(void) +static Boolean +CommandKeyIsDown (void) { - KeyMap theKeyMap; + KeyMap theKeyMap; - GetKeys(theKeyMap); + GetKeys (theKeyMap); - if (((unsigned char *) theKeyMap)[6] & 0x80) { - return(true); - } - return(false); + if (((unsigned char *) theKeyMap)[6] & 0x80) { + return (true); + } + return (false); } #if !(defined(__APPLE__) && defined(__MACH__)) /* Parse a command line buffer into arguments */ -static int ParseCommandLine(char *cmdline, char **argv) +static int +ParseCommandLine (char *cmdline, char **argv) { - char *bufp; - int argc; - - argc = 0; - for ( bufp = cmdline; *bufp; ) { - /* Skip leading whitespace */ - while ( SDL_isspace(*bufp) ) { - ++bufp; - } - /* Skip over argument */ - if ( *bufp == '"' ) { - ++bufp; - if ( *bufp ) { - if ( argv ) { - argv[argc] = bufp; - } - ++argc; - } - /* Skip over word */ - while ( *bufp && (*bufp != '"') ) { - ++bufp; - } - } else { - if ( *bufp ) { - if ( argv ) { - argv[argc] = bufp; - } - ++argc; - } - /* Skip over word */ - while ( *bufp && ! SDL_isspace(*bufp) ) { - ++bufp; - } - } - if ( *bufp ) { - if ( argv ) { - *bufp = '\0'; - } - ++bufp; - } - } - if ( argv ) { - argv[argc] = NULL; - } - return(argc); + char *bufp; + int argc; + + argc = 0; + for (bufp = cmdline; *bufp;) { + /* Skip leading whitespace */ + while (SDL_isspace (*bufp)) { + ++bufp; + } + /* Skip over argument */ + if (*bufp == '"') { + ++bufp; + if (*bufp) { + if (argv) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while (*bufp && (*bufp != '"')) { + ++bufp; + } + } else { + if (*bufp) { + if (argv) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while (*bufp && !SDL_isspace (*bufp)) { + ++bufp; + } + } + if (*bufp) { + if (argv) { + *bufp = '\0'; + } + ++bufp; + } + } + if (argv) { + argv[argc] = NULL; + } + return (argc); } /* Remove the output files if there was no output written */ -static void cleanup_output(void) +static void +cleanup_output (void) { - FILE *file; - int empty; - - /* Flush the output in case anything is queued */ - fclose(stdout); - fclose(stderr); - - /* See if the files have any output in them */ - file = fopen(STDOUT_FILE, "rb"); - if ( file ) { - empty = (fgetc(file) == EOF) ? 1 : 0; - fclose(file); - if ( empty ) { - remove(STDOUT_FILE); - } - } - file = fopen(STDERR_FILE, "rb"); - if ( file ) { - empty = (fgetc(file) == EOF) ? 1 : 0; - fclose(file); - if ( empty ) { - remove(STDERR_FILE); - } - } + FILE *file; + int empty; + + /* Flush the output in case anything is queued */ + fclose (stdout); + fclose (stderr); + + /* See if the files have any output in them */ + file = fopen (STDOUT_FILE, "rb"); + if (file) { + empty = (fgetc (file) == EOF) ? 1 : 0; + fclose (file); + if (empty) { + remove (STDOUT_FILE); + } + } + file = fopen (STDERR_FILE, "rb"); + if (file) { + empty = (fgetc (file) == EOF) ? 1 : 0; + fclose (file); + if (empty) { + remove (STDERR_FILE); + } + } } #endif //!(defined(__APPLE__) && defined(__MACH__)) -static int getCurrentAppName (StrFileName name) { - +static int +getCurrentAppName (StrFileName name) +{ + ProcessSerialNumber process; - ProcessInfoRec process_info; - FSSpec process_fsp; - + ProcessInfoRec process_info; + FSSpec process_fsp; + process.highLongOfPSN = 0; - process.lowLongOfPSN = kCurrentProcess; + process.lowLongOfPSN = kCurrentProcess; process_info.processInfoLength = sizeof (process_info); - process_info.processName = NULL; + process_info.processName = NULL; process_info.processAppSpec = &process_fsp; - - if ( noErr != GetProcessInformation (&process, &process_info) ) - return 0; - - SDL_memcpy(name, process_fsp.name, process_fsp.name[0] + 1); + + if (noErr != GetProcessInformation (&process, &process_info)) + return 0; + + SDL_memcpy (name, process_fsp.name, process_fsp.name[0] + 1); return 1; } -static int getPrefsFile (FSSpec *prefs_fsp, int create) { +static int +getPrefsFile (FSSpec * prefs_fsp, int create) +{ /* The prefs file name is the application name, possibly truncated, */ /* plus " Preferences */ - - #define SUFFIX " Preferences" - #define MAX_NAME 19 /* 31 - strlen (SUFFIX) */ - - short volume_ref_number; - long directory_id; - StrFileName prefs_name; - StrFileName app_name; - + +#define SUFFIX " Preferences" +#define MAX_NAME 19 /* 31 - strlen (SUFFIX) */ + + short volume_ref_number; + long directory_id; + StrFileName prefs_name; + StrFileName app_name; + /* Get Preferences folder - works with Multiple Users */ - if ( noErr != FindFolder ( kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, - &volume_ref_number, &directory_id) ) + if (noErr != + FindFolder (kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, + &volume_ref_number, &directory_id)) exit (-1); - - if ( ! getCurrentAppName (app_name) ) + + if (!getCurrentAppName (app_name)) exit (-1); - + /* Truncate if name is too long */ - if (app_name[0] > MAX_NAME ) + if (app_name[0] > MAX_NAME) app_name[0] = MAX_NAME; - - SDL_memcpy(prefs_name + 1, app_name + 1, app_name[0]); - SDL_memcpy(prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); + + SDL_memcpy (prefs_name + 1, app_name + 1, app_name[0]); + SDL_memcpy (prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); prefs_name[0] = app_name[0] + strlen (SUFFIX); - + /* Make the file spec for prefs file */ - if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { - if ( !create ) + if (noErr != + FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp)) + { + if (!create) return 0; else { /* Create the prefs file */ - SDL_memcpy(prefs_fsp->name, prefs_name, prefs_name[0] + 1); - prefs_fsp->parID = directory_id; + SDL_memcpy (prefs_fsp->name, prefs_name, prefs_name[0] + 1); + prefs_fsp->parID = directory_id; prefs_fsp->vRefNum = volume_ref_number; - - FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph - - if ( noErr != ResError () ) + + FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph + + if (noErr != ResError ()) return 0; } - } + } return 1; } -static int readPrefsResource (PrefsRecord *prefs) { - +static int +readPrefsResource (PrefsRecord * prefs) +{ + Handle prefs_handle; - - prefs_handle = Get1Resource( 'CLne', 128 ); - - if (prefs_handle != NULL) { - int offset = 0; -// int j = 0; - - HLock(prefs_handle); - - /* Get command line string */ - SDL_memcpy(prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); - - /* Get video driver name */ - offset += (*prefs_handle)[0] + 1; - SDL_memcpy(prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1); - - /* Get save-to-file option (1 or 0) */ - offset += (*prefs_handle)[offset] + 1; - prefs->output_to_file = (*prefs_handle)[offset]; - - ReleaseResource( prefs_handle ); - - return ResError() == noErr; + + prefs_handle = Get1Resource ('CLne', 128); + + if (prefs_handle != NULL) { + int offset = 0; +// int j = 0; + + HLock (prefs_handle); + + /* Get command line string */ + SDL_memcpy (prefs->command_line, *prefs_handle, + (*prefs_handle)[0] + 1); + + /* Get video driver name */ + offset += (*prefs_handle)[0] + 1; + SDL_memcpy (prefs->video_driver_name, *prefs_handle + offset, + (*prefs_handle)[offset] + 1); + + /* Get save-to-file option (1 or 0) */ + offset += (*prefs_handle)[offset] + 1; + prefs->output_to_file = (*prefs_handle)[offset]; + + ReleaseResource (prefs_handle); + + return ResError () == noErr; } return 0; } -static int writePrefsResource (PrefsRecord *prefs, short resource_file) { +static int +writePrefsResource (PrefsRecord * prefs, short resource_file) +{ Handle prefs_handle; - + UseResFile (resource_file); - - prefs_handle = Get1Resource ( 'CLne', 128 ); + + prefs_handle = Get1Resource ('CLne', 128); if (prefs_handle != NULL) RemoveResource (prefs_handle); - - prefs_handle = NewHandle ( prefs->command_line[0] + prefs->video_driver_name[0] + 4 ); + + prefs_handle = + NewHandle (prefs->command_line[0] + prefs->video_driver_name[0] + 4); if (prefs_handle != NULL) { - + int offset; - + HLock (prefs_handle); - + /* Command line text */ offset = 0; - SDL_memcpy(*prefs_handle, prefs->command_line, prefs->command_line[0] + 1); - + SDL_memcpy (*prefs_handle, prefs->command_line, + prefs->command_line[0] + 1); + /* Video driver name */ offset += prefs->command_line[0] + 1; - SDL_memcpy(*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1); - + SDL_memcpy (*prefs_handle + offset, prefs->video_driver_name, + prefs->video_driver_name[0] + 1); + /* Output-to-file option */ offset += prefs->video_driver_name[0] + 1; - *( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file; - *( *((char**)prefs_handle) + offset + 1) = 0; - - AddResource (prefs_handle, 'CLne', 128, "\pCommand Line"); + *(*((char **) prefs_handle) + offset) = (char) prefs->output_to_file; + *(*((char **) prefs_handle) + offset + 1) = 0; + + AddResource (prefs_handle, 'CLne', 128, "\pCommand Line"); WriteResource (prefs_handle); UpdateResFile (resource_file); DisposeHandle (prefs_handle); - - return ResError() == noErr; + + return ResError () == noErr; } - + return 0; } -static int readPreferences (PrefsRecord *prefs) { +static int +readPreferences (PrefsRecord * prefs) +{ - int no_error = 1; + int no_error = 1; FSSpec prefs_fsp; /* Check for prefs file first */ - if ( getPrefsFile (&prefs_fsp, 0) ) { - - short prefs_resource; - + if (getPrefsFile (&prefs_fsp, 0)) { + + short prefs_resource; + prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdPerm); - if ( prefs_resource == -1 ) /* this shouldn't happen, but... */ + if (prefs_resource == -1) /* this shouldn't happen, but... */ return 0; - - UseResFile (prefs_resource); - no_error = readPrefsResource (prefs); + + UseResFile (prefs_resource); + no_error = readPrefsResource (prefs); CloseResFile (prefs_resource); } - + /* Fall back to application's resource fork (reading only, so this is safe) */ else { - - no_error = readPrefsResource (prefs); - } + + no_error = readPrefsResource (prefs); + } return no_error; } -static int writePreferences (PrefsRecord *prefs) { - - int no_error = 1; +static int +writePreferences (PrefsRecord * prefs) +{ + + int no_error = 1; FSSpec prefs_fsp; - + /* Get prefs file, create if it doesn't exist */ - if ( getPrefsFile (&prefs_fsp, 1) ) { - - short prefs_resource; - + if (getPrefsFile (&prefs_fsp, 1)) { + + short prefs_resource; + prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdWrPerm); if (prefs_resource == -1) return 0; no_error = writePrefsResource (prefs, prefs_resource); CloseResFile (prefs_resource); } - + return no_error; } /* This is where execution begins */ -int main(int argc, char *argv[]) +int +main (int argc, char *argv[]) { #if !(defined(__APPLE__) && defined(__MACH__)) #pragma unused(argc, argv) #endif - -#define DEFAULT_ARGS "\p" /* pascal string for default args */ -#define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ -#define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ -#define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ +#define DEFAULT_ARGS "\p" /* pascal string for default args */ +#define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ +#define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ + +#define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ #define VIDEO_ID_TOOLBOX 2 - PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; - + PrefsRecord prefs = + { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; + #if !(defined(__APPLE__) && defined(__MACH__)) - int nargs; - char **args; - char *commandLine; - - StrFileName appNameText; + int nargs; + char **args; + char *commandLine; + + StrFileName appNameText; #endif - int videodriver = VIDEO_ID_TOOLBOX; - int settingsChanged = 0; - - long i; + int videodriver = VIDEO_ID_TOOLBOX; + int settingsChanged = 0; + + long i; - /* Kyle's SDL command-line dialog code ... */ + /* Kyle's SDL command-line dialog code ... */ #if !TARGET_API_MAC_CARBON - InitGraf (&qd.thePort); - InitFonts (); - InitWindows (); - InitMenus (); - InitDialogs (nil); + InitGraf (&qd.thePort); + InitFonts (); + InitWindows (); + InitMenus (); + InitDialogs (nil); #endif - InitCursor (); - FlushEvents(everyEvent,0); + InitCursor (); + FlushEvents (everyEvent, 0); #if !TARGET_API_MAC_CARBON - MaxApplZone (); + MaxApplZone (); #endif - MoreMasters (); - MoreMasters (); + MoreMasters (); + MoreMasters (); #if 0 - /* Intialize SDL, and put up a dialog if we fail */ - if ( SDL_Init (0) < 0 ) { + /* Intialize SDL, and put up a dialog if we fail */ + if (SDL_Init (0) < 0) { #define kErr_OK 1 #define kErr_Text 2 DialogPtr errorDialog; - short dummyType; - Rect dummyRect; - Handle dummyHandle; - short itemHit; - - errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1); - if (errorDialog == NULL) - return -1; - DrawDialog (errorDialog); - - GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect); - SetDialogItemText (dummyHandle, "\pError Initializing SDL"); - + short dummyType; + Rect dummyRect; + Handle dummyHandle; + short itemHit; + + errorDialog = GetNewDialog (1001, nil, (WindowPtr) - 1); + if (errorDialog == NULL) + return -1; + DrawDialog (errorDialog); + + GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, + &dummyRect); + SetDialogItemText (dummyHandle, "\pError Initializing SDL"); + #if TARGET_API_MAC_CARBON - SetPort (GetDialogPort(errorDialog)); + SetPort (GetDialogPort (errorDialog)); #else - SetPort (errorDialog); + SetPort (errorDialog); #endif - do { - ModalDialog (nil, &itemHit); - } while (itemHit != kErr_OK); - - DisposeDialog (errorDialog); - exit (-1); - } - atexit(cleanup_output); - atexit(SDL_Quit); + do { + ModalDialog (nil, &itemHit); + } + while (itemHit != kErr_OK); + + DisposeDialog (errorDialog); + exit (-1); + } + atexit (cleanup_output); + atexit (SDL_Quit); #endif /* Set up SDL's QuickDraw environment */ #if !TARGET_API_MAC_CARBON - SDL_InitQuickDraw(&qd); + SDL_InitQuickDraw (&qd); #endif - if ( readPreferences (&prefs) ) { - - if (SDL_memcmp(prefs.video_driver_name+1, "DSp", 3) == 0) + if (readPreferences (&prefs)) { + + if (SDL_memcmp (prefs.video_driver_name + 1, "DSp", 3) == 0) videodriver = 1; - else if (SDL_memcmp(prefs.video_driver_name+1, "toolbox", 7) == 0) + else if (SDL_memcmp (prefs.video_driver_name + 1, "toolbox", 7) == 0) videodriver = 2; - } - - if ( CommandKeyIsDown() ) { + } + + if (CommandKeyIsDown ()) { #define kCL_OK 1 #define kCL_Cancel 2 #define kCL_Text 3 #define kCL_File 4 #define kCL_Video 6 - + DialogPtr commandDialog; - short dummyType; - Rect dummyRect; - Handle dummyHandle; - short itemHit; - #if TARGET_API_MAC_CARBON + short dummyType; + Rect dummyRect; + Handle dummyHandle; + short itemHit; +#if TARGET_API_MAC_CARBON ControlRef control; - #endif - +#endif + /* Assume that they will change settings, rather than do exhaustive check */ settingsChanged = 1; - + /* Create dialog and display it */ - commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1); - #if TARGET_API_MAC_CARBON - SetPort ( GetDialogPort(commandDialog) ); - #else + commandDialog = GetNewDialog (1000, nil, (WindowPtr) - 1); +#if TARGET_API_MAC_CARBON + SetPort (GetDialogPort (commandDialog)); +#else SetPort (commandDialog); - #endif - +#endif + /* Setup controls */ - #if TARGET_API_MAC_CARBON - GetDialogItemAsControl(commandDialog, kCL_File, &control); +#if TARGET_API_MAC_CARBON + GetDialogItemAsControl (commandDialog, kCL_File, &control); SetControlValue (control, prefs.output_to_file); - #else - GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ - SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file ); - #endif +#else + GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + SetControlValue ((ControlHandle) dummyHandle, prefs.output_to_file); +#endif - GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); + GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, + &dummyRect); SetDialogItemText (dummyHandle, prefs.command_line); - #if TARGET_API_MAC_CARBON - GetDialogItemAsControl(commandDialog, kCL_Video, &control); +#if TARGET_API_MAC_CARBON + GetDialogItemAsControl (commandDialog, kCL_Video, &control); SetControlValue (control, videodriver); - #else - GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); - SetControlValue ((ControlRef)dummyHandle, videodriver); - #endif +#else + GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, + &dummyRect); + SetControlValue ((ControlRef) dummyHandle, videodriver); +#endif SetDialogDefaultItem (commandDialog, kCL_OK); - SetDialogCancelItem (commandDialog, kCL_Cancel); + SetDialogCancelItem (commandDialog, kCL_Cancel); do { - - ModalDialog(nil, &itemHit); /* wait for user response */ - - /* Toggle command-line output checkbox */ - if ( itemHit == kCL_File ) { - #if TARGET_API_MAC_CARBON - GetDialogItemAsControl(commandDialog, kCL_File, &control); - SetControlValue (control, !GetControlValue(control)); - #else - GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ - SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) ); - #endif - } - - } while (itemHit != kCL_OK && itemHit != kCL_Cancel); + + ModalDialog (nil, &itemHit); /* wait for user response */ + + /* Toggle command-line output checkbox */ + if (itemHit == kCL_File) { +#if TARGET_API_MAC_CARBON + GetDialogItemAsControl (commandDialog, kCL_File, &control); + SetControlValue (control, !GetControlValue (control)); +#else + GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + SetControlValue ((ControlHandle) dummyHandle, + !GetControlValue ((ControlHandle) + dummyHandle)); +#endif + } + + } + while (itemHit != kCL_OK && itemHit != kCL_Cancel); /* Get control values, even if they did not change */ - GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ GetDialogItemText (dummyHandle, prefs.command_line); - #if TARGET_API_MAC_CARBON - GetDialogItemAsControl(commandDialog, kCL_File, &control); - prefs.output_to_file = GetControlValue(control); - #else - GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ - prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle); - #endif - - #if TARGET_API_MAC_CARBON - GetDialogItemAsControl(commandDialog, kCL_Video, &control); - videodriver = GetControlValue(control); - #else - GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); - videodriver = GetControlValue ((ControlRef)dummyHandle); - #endif +#if TARGET_API_MAC_CARBON + GetDialogItemAsControl (commandDialog, kCL_File, &control); + prefs.output_to_file = GetControlValue (control); +#else + GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ + prefs.output_to_file = GetControlValue ((ControlHandle) dummyHandle); +#endif + +#if TARGET_API_MAC_CARBON + GetDialogItemAsControl (commandDialog, kCL_Video, &control); + videodriver = GetControlValue (control); +#else + GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, + &dummyRect); + videodriver = GetControlValue ((ControlRef) dummyHandle); +#endif DisposeDialog (commandDialog); - if (itemHit == kCL_Cancel ) { - exit (0); + if (itemHit == kCL_Cancel) { + exit (0); } - } - + } + /* Set pseudo-environment variables for video driver, update prefs */ - switch ( videodriver ) { - case VIDEO_ID_DRAWSPROCKET: - SDL_putenv("SDL_VIDEODRIVER=DSp"); - SDL_memcpy(prefs.video_driver_name, "\pDSp", 4); - break; - case VIDEO_ID_TOOLBOX: - SDL_putenv("SDL_VIDEODRIVER=toolbox"); - SDL_memcpy(prefs.video_driver_name, "\ptoolbox", 8); - break; - } + switch (videodriver) { + case VIDEO_ID_DRAWSPROCKET: + SDL_putenv ("SDL_VIDEODRIVER=DSp"); + SDL_memcpy (prefs.video_driver_name, "\pDSp", 4); + break; + case VIDEO_ID_TOOLBOX: + SDL_putenv ("SDL_VIDEODRIVER=toolbox"); + SDL_memcpy (prefs.video_driver_name, "\ptoolbox", 8); + break; + } #if !(defined(__APPLE__) && defined(__MACH__)) /* Redirect standard I/O to files */ - if ( prefs.output_to_file ) { - freopen (STDOUT_FILE, "w", stdout); - freopen (STDERR_FILE, "w", stderr); - } else { - fclose (stdout); - fclose (stderr); - } + if (prefs.output_to_file) { + freopen (STDOUT_FILE, "w", stdout); + freopen (STDERR_FILE, "w", stderr); + } else { + fclose (stdout); + fclose (stderr); + } #endif - + if (settingsChanged) { /* Save the prefs, even if they might not have changed (but probably did) */ - if ( ! writePreferences (&prefs) ) + if (!writePreferences (&prefs)) fprintf (stderr, "WARNING: Could not save preferences!\n"); } - #if !(defined(__APPLE__) && defined(__MACH__)) appNameText[0] = 0; - getCurrentAppName (appNameText); /* check for error here ? */ + getCurrentAppName (appNameText); /* check for error here ? */ - commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2); - if ( commandLine == NULL ) { - exit(-1); + commandLine = + (char *) malloc (appNameText[0] + prefs.command_line[0] + 2); + if (commandLine == NULL) { + exit (-1); } /* Rather than rewrite ParseCommandLine method, let's replace */ /* any spaces in application name with underscores, */ - /* so that the app name is only 1 argument */ - for (i = 1; i < 1+appNameText[0]; i++) - if ( appNameText[i] == ' ' ) appNameText[i] = '_'; + /* so that the app name is only 1 argument */ + for (i = 1; i < 1 + appNameText[0]; i++) + if (appNameText[i] == ' ') + appNameText[i] = '_'; - /* Copy app name & full command text to command-line C-string */ - SDL_memcpy(commandLine, appNameText + 1, appNameText[0]); + /* Copy app name & full command text to command-line C-string */ + SDL_memcpy (commandLine, appNameText + 1, appNameText[0]); commandLine[appNameText[0]] = ' '; - SDL_memcpy(commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]); - commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0'; + SDL_memcpy (commandLine + appNameText[0] + 1, prefs.command_line + 1, + prefs.command_line[0]); + commandLine[appNameText[0] + 1 + prefs.command_line[0]] = '\0'; /* Parse C-string into argv and argc */ nargs = ParseCommandLine (commandLine, NULL); - args = (char **)malloc((nargs+1)*(sizeof *args)); - if ( args == NULL ) { - exit(-1); - } - ParseCommandLine (commandLine, args); - - /* Run the main application code */ - SDL_main(nargs, args); - free (args); - free (commandLine); - - /* Remove useless stdout.txt and stderr.txt */ - cleanup_output (); + args = (char **) malloc ((nargs + 1) * (sizeof *args)); + if (args == NULL) { + exit (-1); + } + ParseCommandLine (commandLine, args); + + /* Run the main application code */ + SDL_main (nargs, args); + free (args); + free (commandLine); + + /* Remove useless stdout.txt and stderr.txt */ + cleanup_output (); #else // defined(__APPLE__) && defined(__MACH__) - SDL_main(argc, argv); + SDL_main (argc, argv); #endif - - /* Exit cleanly, calling atexit() functions */ - exit (0); - /* Never reached, but keeps the compiler quiet */ - return (0); + /* Exit cleanly, calling atexit() functions */ + exit (0); + + /* Never reached, but keeps the compiler quiet */ + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/main/macosx/SDLMain.h b/src/main/macosx/SDLMain.h index 4683df57a..e0a9a826b 100644 --- a/src/main/macosx/SDLMain.h +++ b/src/main/macosx/SDLMain.h @@ -7,5 +7,5 @@ #import -@interface SDLMain : NSObject -@end +@ interface SDLMain:NSObject @ end +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/main/macosx/SDLMain.m b/src/main/macosx/SDLMain.m index 2eaa1c11e..1c69c2da0 100644 --- a/src/main/macosx/SDLMain.m +++ b/src/main/macosx/SDLMain.m @@ -7,162 +7,176 @@ #import "SDL.h" #import "SDLMain.h" -#import /* for MAXPATHLEN */ +#import /* for MAXPATHLEN */ #import /* For some reaon, Apple removed setAppleMenu from the headers in 10.4, but the method still is there and works. To avoid warnings, we declare it ourselves here. */ -@interface NSApplication(SDL_Missing_Methods) -- (void)setAppleMenu:(NSMenu *)menu; +@ interface NSApplication (SDL_Missing_Methods) - (void) setAppleMenu:(NSMenu + *) + menu; @end - /* Use this flag to determine whether we use SDLMain.nib or not */ #define SDL_USE_NIB_FILE 0 - /* Use this flag to determine whether we use CPS (docking) or not */ #define SDL_USE_CPS 1 #ifdef SDL_USE_CPS /* Portions of CPS.h */ -typedef struct CPSProcessSerNum -{ - UInt32 lo; - UInt32 hi; -} CPSProcessSerNum; - -extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); -extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); -extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); + typedef struct CPSProcessSerNum + { + UInt32 + lo; + UInt32 + hi; + } CPSProcessSerNum; + + extern + OSErr + CPSGetCurrentProcess (CPSProcessSerNum * psn); + extern + OSErr + CPSEnableForegroundOperation (CPSProcessSerNum * psn, UInt32 _arg2, + UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); + extern + OSErr + CPSSetFrontProcess (CPSProcessSerNum * psn); #endif /* SDL_USE_CPS */ -static int gArgc; -static char **gArgv; -static BOOL gFinderLaunch; -static BOOL gCalledAppMainline = FALSE; - -static NSString *getApplicationName(void) + static int + gArgc; + static char ** + gArgv; + static + BOOL + gFinderLaunch; + static + BOOL + gCalledAppMainline = FALSE; + + static NSString * + getApplicationName (void) { NSDictionary *dict; NSString *appName = 0; /* Determine the application name */ - dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + dict = + (NSDictionary *) CFBundleGetInfoDictionary (CFBundleGetMainBundle ()); if (dict) - appName = [dict objectForKey: @"CFBundleName"]; - + appName =[dict objectForKey:@"CFBundleName"]; + if (![appName length]) - appName = [[NSProcessInfo processInfo] processName]; + appName =[[NSProcessInfo processInfo] processName]; return appName; } #if SDL_USE_NIB_FILE /* A helper category for NSString */ -@interface NSString (ReplaceSubString) -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; +@interface NSString (ReplaceSubString) - (NSString *) stringByReplacingRange:(NSRange) +aRange with:(NSString *) + aString; @end #endif - -@interface SDLApplication : NSApplication -@end - -@implementation SDLApplication +@ interface SDLApplication:NSApplication + @ end @ implementation SDLApplication /* Invoked from the Quit menu item */ -- (void)terminate:(id)sender +- (void) terminate:(id) sender { /* Post a SDL_QUIT event */ SDL_Event event; event.type = SDL_QUIT; - SDL_PushEvent(&event); + SDL_PushEvent (&event); } -@end +@end /* The main class of the application, the application's delegate */ -@implementation SDLMain - + @ implementation SDLMain /* Set the working directory to the .app's parent directory */ -- (void) setupWorkingDirectory:(BOOL)shouldChdir -{ - if (shouldChdir) - { +- (void) setupWorkingDirectory:(BOOL) shouldChdir { + if (shouldChdir) { char parentdir[MAXPATHLEN]; - CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); - if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) { - assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ - } - CFRelease(url); - CFRelease(url2); - } + CFURLRef url = CFBundleCopyBundleURL (CFBundleGetMainBundle ()); + CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent (0, url); + if (CFURLGetFileSystemRepresentation + (url2, true, (UInt8 *) parentdir, MAXPATHLEN)) { + assert (chdir (parentdir) == 0); /* chdir to the binary app's parent */ + } + CFRelease (url); + CFRelease (url2); + } } #if SDL_USE_NIB_FILE /* Fix menu to contain the real app name instead of "SDL App" */ -- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName -{ +-(void) fixMenu:(NSMenu *) +aMenu withAppName:(NSString *) + appName { NSRange aRange; NSEnumerator *enumerator; NSMenuItem *menuItem; - aRange = [[aMenu title] rangeOfString:@"SDL App"]; + aRange =[[aMenu title] rangeOfString:@"SDL App"]; if (aRange.length != 0) - [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; + [aMenu setTitle: [[aMenu title] stringByReplacingRange: aRange with:appName]]; - enumerator = [[aMenu itemArray] objectEnumerator]; - while ((menuItem = [enumerator nextObject])) - { - aRange = [[menuItem title] rangeOfString:@"SDL App"]; + enumerator =[[aMenu itemArray] objectEnumerator]; + while ((menuItem =[enumerator nextObject])) { + aRange =[[menuItem title] rangeOfString:@"SDL App"]; if (aRange.length != 0) - [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; + [menuItem setTitle: [[menuItem title] stringByReplacingRange: aRange with:appName]]; if ([menuItem hasSubmenu]) - [self fixMenu:[menuItem submenu] withAppName:appName]; + [self fixMenu: [menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; + [aMenu sizeToFit]; } #else -static void setApplicationMenu(void) +static void +setApplicationMenu (void) { /* warning: this code is very odd */ NSMenu *appleMenu; NSMenuItem *menuItem; NSString *title; NSString *appName; - - appName = getApplicationName(); - appleMenu = [[NSMenu alloc] initWithTitle:@""]; - + + appName = getApplicationName (); + appleMenu =[[NSMenu alloc] initWithTitle:@""]; + /* Add menu items */ - title = [@"About " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + title =[@"About " stringByAppendingString:appName]; + [appleMenu addItemWithTitle: title action: @selector (orderFrontStandardAboutPanel: )keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; - [appleMenu addItem:[NSMenuItem separatorItem]]; + title =[@"Hide " stringByAppendingString:appName]; + [appleMenu addItemWithTitle: title action: @selector (hide: )keyEquivalent:@"h"]; - title = [@"Hide " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle: @"Hide Others" action: @selector (hideOtherApplications: )keyEquivalent:@"h"]; + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | + NSCommandKeyMask)]; - menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; - [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + [appleMenu addItemWithTitle: @"Show All" action: @selector (unhideAllApplications: )keyEquivalent:@""]; - [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + [appleMenu addItem:[NSMenuItem separatorItem]]; - [appleMenu addItem:[NSMenuItem separatorItem]]; + title =[@"Quit " stringByAppendingString:appName]; + [appleMenu addItemWithTitle: title action: @selector (terminate: )keyEquivalent:@"q"]; - title = [@"Quit " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; - /* Put menu into the menubar */ - menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; - [menuItem setSubmenu:appleMenu]; - [[NSApp mainMenu] addItem:menuItem]; + menuItem =[[NSMenuItem alloc] initWithTitle: @"" action: nil keyEquivalent:@""]; + [menuItem setSubmenu:appleMenu]; + [[NSApp mainMenu] addItem:menuItem]; /* Tell the application object that this is now the application menu */ - [NSApp setAppleMenu:appleMenu]; + [NSApp setAppleMenu:appleMenu]; /* Finally give up our references to the objects */ [appleMenu release]; @@ -170,26 +184,27 @@ static void setApplicationMenu(void) } /* Create a window menu */ -static void setupWindowMenu(void) +static void +setupWindowMenu (void) { - NSMenu *windowMenu; - NSMenuItem *windowMenuItem; - NSMenuItem *menuItem; + NSMenu *windowMenu; + NSMenuItem *windowMenuItem; + NSMenuItem *menuItem; + + windowMenu =[[NSMenu alloc] initWithTitle:@"Window"]; - windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; - /* "Minimize" item */ - menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; - [windowMenu addItem:menuItem]; + menuItem =[[NSMenuItem alloc] initWithTitle: @"Minimize" action: @selector (performMiniaturize: )keyEquivalent:@"m"]; + [windowMenu addItem:menuItem]; [menuItem release]; - + /* Put menu into the menubar */ - windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; - [windowMenuItem setSubmenu:windowMenu]; - [[NSApp mainMenu] addItem:windowMenuItem]; - + windowMenuItem =[[NSMenuItem alloc] initWithTitle: @"Window" action: nil keyEquivalent:@""]; + [windowMenuItem setSubmenu:windowMenu]; + [[NSApp mainMenu] addItem:windowMenuItem]; + /* Tell the application object that this is now the window menu */ - [NSApp setWindowsMenu:windowMenu]; + [NSApp setWindowsMenu:windowMenu]; /* Finally give up our references to the objects */ [windowMenu release]; @@ -197,37 +212,39 @@ static void setupWindowMenu(void) } /* Replacement for NSApplicationMain */ -static void CustomApplicationMain (int argc, char **argv) +static void +CustomApplicationMain (int argc, char **argv) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - SDLMain *sdlMain; + NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init]; + SDLMain *sdlMain; /* Ensure the application object is initialised */ [SDLApplication sharedApplication]; - + #ifdef SDL_USE_CPS { CPSProcessSerNum PSN; /* Tell the dock about us */ - if (!CPSGetCurrentProcess(&PSN)) - if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) - if (!CPSSetFrontProcess(&PSN)) + if (!CPSGetCurrentProcess (&PSN)) + if (!CPSEnableForegroundOperation + (&PSN, 0x03, 0x3C, 0x2C, 0x1103)) + if (!CPSSetFrontProcess (&PSN)) [SDLApplication sharedApplication]; } #endif /* SDL_USE_CPS */ /* Set up the menubar */ - [NSApp setMainMenu:[[NSMenu alloc] init]]; - setApplicationMenu(); - setupWindowMenu(); + [NSApp setMainMenu:[[NSMenu alloc] init]]; + setApplicationMenu (); + setupWindowMenu (); /* Create SDLMain and make it the app delegate */ - sdlMain = [[SDLMain alloc] init]; - [NSApp setDelegate:sdlMain]; - + sdlMain =[[SDLMain alloc] init]; + [NSApp setDelegate:sdlMain]; + /* Start the main event loop */ [NSApp run]; - + [sdlMain release]; [pool release]; } @@ -250,34 +267,34 @@ static void CustomApplicationMain (int argc, char **argv) * * This message is ignored once the app's mainline has been called. */ -- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename +-(BOOL) application:(NSApplication *) + theApplication openFile:(NSString *) filename { const char *temparg; size_t arglen; char *arg; char **newargv; - if (!gFinderLaunch) /* MacOS is passing command line args. */ + if (!gFinderLaunch) /* MacOS is passing command line args. */ return FALSE; - if (gCalledAppMainline) /* app has started, ignore this document. */ + if (gCalledAppMainline) /* app has started, ignore this document. */ return FALSE; - temparg = [filename UTF8String]; - arglen = SDL_strlen(temparg) + 1; - arg = (char *) SDL_malloc(arglen); + temparg =[filename UTF8String]; + arglen = SDL_strlen (temparg) + 1; + arg = (char *) SDL_malloc (arglen); if (arg == NULL) return FALSE; - newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); - if (newargv == NULL) - { - SDL_free(arg); + newargv = (char **) realloc (gArgv, sizeof (char *) * (gArgc + 2)); + if (newargv == NULL) { + SDL_free (arg); return FALSE; } gArgv = newargv; - SDL_strlcpy(arg, temparg, arglen); + SDL_strlcpy (arg, temparg, arglen); gArgv[gArgc++] = arg; gArgv[gArgc] = NULL; return TRUE; @@ -285,16 +302,15 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam /* Called when the internal event loop has just started running */ -- (void) applicationDidFinishLaunching: (NSNotification *) note -{ +-(void) applicationDidFinishLaunching:(NSNotification *) note { int status; /* Set the working directory to the .app's parent directory */ - [self setupWorkingDirectory:gFinderLaunch]; + [self setupWorkingDirectory:gFinderLaunch]; #if SDL_USE_NIB_FILE /* Set the main menu to contain the real app name instead of "SDL App" */ - [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; + [self fixMenu: [NSApp mainMenu] withAppName:getApplicationName ()]; #endif /* Hand off to main application code */ @@ -302,64 +318,58 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note status = SDL_main (gArgc, gArgv); /* We're done, thank you for playing */ - exit(status); + exit (status); } -@end - -@implementation NSString (ReplaceSubString) - -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString +@end @ implementation NSString (ReplaceSubString) - (NSString *) stringByReplacingRange:(NSRange) +aRange with:(NSString *) + aString { unsigned int bufferSize; - unsigned int selfLen = [self length]; - unsigned int aStringLen = [aString length]; + unsigned int selfLen =[self length]; + unsigned int aStringLen =[aString length]; unichar *buffer; NSRange localRange; NSString *result; bufferSize = selfLen + aStringLen - aRange.length; - buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar)); - + buffer = NSAllocateMemoryPages (bufferSize * sizeof (unichar)); + /* Get first part into buffer */ localRange.location = 0; localRange.length = aRange.location; - [self getCharacters:buffer range:localRange]; - + [self getCharacters: buffer range:localRange]; + /* Get middle part into buffer */ localRange.location = 0; localRange.length = aStringLen; - [aString getCharacters:(buffer+aRange.location) range:localRange]; - + [aString getCharacters: (buffer + aRange.location) range:localRange]; + /* Get last part into buffer */ localRange.location = aRange.location + aRange.length; localRange.length = selfLen - localRange.location; - [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; - + [self getCharacters: (buffer + aRange.location + aStringLen) range:localRange]; + /* Build output string */ - result = [NSString stringWithCharacters:buffer length:bufferSize]; - - NSDeallocateMemoryPages(buffer, bufferSize); - + result =[NSString stringWithCharacters: buffer length:bufferSize]; + + NSDeallocateMemoryPages (buffer, bufferSize); + return result; } @end - - - #ifdef main # undef main #endif - - /* Main entry point to executable - should *not* be SDL_main! */ -int main (int argc, char **argv) + int +main (int argc, char **argv) { /* Copy the arguments into a global variable */ /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { - gArgv = (char **) SDL_malloc(sizeof (char *) * 2); + if (argc >= 2 && strncmp (argv[1], "-psn", 4) == 0) { + gArgv = (char **) SDL_malloc (sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; gArgc = 1; @@ -367,18 +377,17 @@ int main (int argc, char **argv) } else { int i; gArgc = argc; - gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); + gArgv = (char **) SDL_malloc (sizeof (char *) * (argc + 1)); for (i = 0; i <= argc; i++) gArgv[i] = argv[i]; gFinderLaunch = NO; } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; + [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); #endif return 0; } - diff --git a/src/main/qtopia/SDL_qtopia_main.cc b/src/main/qtopia/SDL_qtopia_main.cc index 46fd518ff..727ea0018 100644 --- a/src/main/qtopia/SDL_qtopia_main.cc +++ b/src/main/qtopia/SDL_qtopia_main.cc @@ -16,32 +16,41 @@ // some issues in Qtopia where there are left-over qcop files in /tmp/. // I'm guessing this will also clean up the taskbar in the Sharp version // of Qtopia. -static inline void cleanupQCop() { - QString appname(qApp->argv()[0]); - int slash = appname.findRev("/"); - if(slash != -1) { appname = appname.mid(slash+1); } - QString cmd = QPEApplication::qpeDir() + "bin/qcop QPE/System 'closing(QString)' '"+appname+"'"; - system(cmd.latin1()); - cmd = "/tmp/qcop-msg-"+appname; - unlink(cmd.latin1()); +static inline void +cleanupQCop () +{ + QString appname (qApp->argv ()[0]); + int slash = appname.findRev ("/"); + if (slash != -1) { + appname = appname.mid (slash + 1); + } + QString cmd = + QPEApplication::qpeDir () + + "bin/qcop QPE/System 'closing(QString)' '" + appname + "'"; + system (cmd.latin1 ()); + cmd = "/tmp/qcop-msg-" + appname; + unlink (cmd.latin1 ()); } static QPEApplication *app; #endif -extern int SDL_main(int argc, char *argv[]); +extern int SDL_main (int argc, char *argv[]); -int main(int argc, char *argv[]) +int +main (int argc, char *argv[]) { #ifdef QWS - // This initializes the Qtopia application. It needs to be done here - // because it parses command line options. - app = new QPEApplication(argc, argv); - QWidget dummy; - app->showMainWidget(&dummy); - atexit(cleanupQCop); + // This initializes the Qtopia application. It needs to be done here + // because it parses command line options. + app = new QPEApplication (argc, argv); + QWidget dummy; + app->showMainWidget (&dummy); + atexit (cleanupQCop); #endif - // Exit here because if return is used, the application - // doesn't seem to quit correctly. - exit(SDL_main(argc, argv)); + // Exit here because if return is used, the application + // doesn't seem to quit correctly. + exit (SDL_main (argc, argv)); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/main/win32/SDL_win32_main.c b/src/main/win32/SDL_win32_main.c index d78708f33..da1a2f0da 100644 --- a/src/main/win32/SDL_win32_main.c +++ b/src/main/win32/SDL_win32_main.c @@ -40,11 +40,11 @@ #ifndef NO_STDIO_REDIRECT # ifdef _WIN32_WCE - static wchar_t stdoutPath[MAX_PATH]; - static wchar_t stderrPath[MAX_PATH]; +static wchar_t stdoutPath[MAX_PATH]; +static wchar_t stderrPath[MAX_PATH]; # else - static char stdoutPath[MAX_PATH]; - static char stderrPath[MAX_PATH]; +static char stdoutPath[MAX_PATH]; +static char stderrPath[MAX_PATH]; # endif #endif @@ -54,114 +54,119 @@ #endif /* _WIN32_WCE < 300 */ /* Parse a command line buffer into arguments */ -static int ParseCommandLine(char *cmdline, char **argv) +static int +ParseCommandLine (char *cmdline, char **argv) { - char *bufp; - int argc; - - argc = 0; - for ( bufp = cmdline; *bufp; ) { - /* Skip leading whitespace */ - while ( isspace(*bufp) ) { - ++bufp; - } - /* Skip over argument */ - if ( *bufp == '"' ) { - ++bufp; - if ( *bufp ) { - if ( argv ) { - argv[argc] = bufp; - } - ++argc; - } - /* Skip over word */ - while ( *bufp && (*bufp != '"') ) { - ++bufp; - } - } else { - if ( *bufp ) { - if ( argv ) { - argv[argc] = bufp; - } - ++argc; - } - /* Skip over word */ - while ( *bufp && ! isspace(*bufp) ) { - ++bufp; - } - } - if ( *bufp ) { - if ( argv ) { - *bufp = '\0'; - } - ++bufp; - } - } - if ( argv ) { - argv[argc] = NULL; - } - return(argc); + char *bufp; + int argc; + + argc = 0; + for (bufp = cmdline; *bufp;) { + /* Skip leading whitespace */ + while (isspace (*bufp)) { + ++bufp; + } + /* Skip over argument */ + if (*bufp == '"') { + ++bufp; + if (*bufp) { + if (argv) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while (*bufp && (*bufp != '"')) { + ++bufp; + } + } else { + if (*bufp) { + if (argv) { + argv[argc] = bufp; + } + ++argc; + } + /* Skip over word */ + while (*bufp && !isspace (*bufp)) { + ++bufp; + } + } + if (*bufp) { + if (argv) { + *bufp = '\0'; + } + ++bufp; + } + } + if (argv) { + argv[argc] = NULL; + } + return (argc); } /* Show an error message */ -static void ShowError(const char *title, const char *message) +static void +ShowError (const char *title, const char *message) { /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */ #ifdef USE_MESSAGEBOX - MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK); + MessageBox (NULL, message, title, MB_ICONEXCLAMATION | MB_OK); #else - fprintf(stderr, "%s: %s\n", title, message); + fprintf (stderr, "%s: %s\n", title, message); #endif } /* Pop up an out of memory message, returns to Windows */ -static BOOL OutOfMemory(void) +static BOOL +OutOfMemory (void) { - ShowError("Fatal Error", "Out of memory - aborting"); - return FALSE; + ShowError ("Fatal Error", "Out of memory - aborting"); + return FALSE; } /* SDL_Quit() shouldn't be used with atexit() directly because calling conventions may differ... */ -static void cleanup(void) +static void +cleanup (void) { - SDL_Quit(); + SDL_Quit (); } /* Remove the output files if there was no output written */ -static void cleanup_output(void) +static void +cleanup_output (void) { #ifndef NO_STDIO_REDIRECT - FILE *file; - int empty; + FILE *file; + int empty; #endif - /* Flush the output in case anything is queued */ - fclose(stdout); - fclose(stderr); + /* Flush the output in case anything is queued */ + fclose (stdout); + fclose (stderr); #ifndef NO_STDIO_REDIRECT - /* See if the files have any output in them */ - if ( stdoutPath[0] ) { - file = fopen(stdoutPath, TEXT("rb")); - if ( file ) { - empty = (fgetc(file) == EOF) ? 1 : 0; - fclose(file); - if ( empty ) { - remove(stdoutPath); - } - } - } - if ( stderrPath[0] ) { - file = fopen(stderrPath, TEXT("rb")); - if ( file ) { - empty = (fgetc(file) == EOF) ? 1 : 0; - fclose(file); - if ( empty ) { - remove(stderrPath); - } - } - } + /* See if the files have any output in them */ + if (stdoutPath[0]) { + file = fopen (stdoutPath, TEXT ("rb")); + if (file) { + empty = (fgetc (file) == EOF) ? 1 : 0; + fclose (file); + if (empty) { + remove (stdoutPath); + } + } + } + if (stderrPath[0]) { + file = fopen (stderrPath, TEXT ("rb")); + if (file) { + empty = (fgetc (file) == EOF) ? 1 : 0; + fclose (file); + if (empty) { + remove (stderrPath); + } + } + } #endif } @@ -171,187 +176,194 @@ static void cleanup_output(void) #endif /* This is where execution begins [console apps] */ -int console_main(int argc, char *argv[]) +int +console_main (int argc, char *argv[]) { - size_t n; - char *bufp, *appname; - int status; - - /* Get the class name from argv[0] */ - appname = argv[0]; - if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) { - appname = bufp+1; - } else - if ( (bufp=SDL_strrchr(argv[0], '/')) != NULL ) { - appname = bufp+1; - } - - if ( (bufp=SDL_strrchr(appname, '.')) == NULL ) - n = SDL_strlen(appname); - else - n = (bufp-appname); - - bufp = SDL_stack_alloc(char, n+1); - if ( bufp == NULL ) { - return OutOfMemory(); - } - SDL_strlcpy(bufp, appname, n+1); - appname = bufp; - - /* Load SDL dynamic link library */ - if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { - ShowError("WinMain() error", SDL_GetError()); - return(FALSE); - } - atexit(cleanup_output); - atexit(cleanup); - - /* Sam: - We still need to pass in the application handle so that - DirectInput will initialize properly when SDL_RegisterApp() - is called later in the video initialization. - */ - SDL_SetModuleHandle(GetModuleHandle(NULL)); - - /* Run the application main() code */ - status = SDL_main(argc, argv); - - /* Exit cleanly, calling atexit() functions */ - exit(status); - - /* Hush little compiler, don't you cry... */ - return 0; + size_t n; + char *bufp, *appname; + int status; + + /* Get the class name from argv[0] */ + appname = argv[0]; + if ((bufp = SDL_strrchr (argv[0], '\\')) != NULL) { + appname = bufp + 1; + } else if ((bufp = SDL_strrchr (argv[0], '/')) != NULL) { + appname = bufp + 1; + } + + if ((bufp = SDL_strrchr (appname, '.')) == NULL) + n = SDL_strlen (appname); + else + n = (bufp - appname); + + bufp = SDL_stack_alloc (char, n + 1); + if (bufp == NULL) { + return OutOfMemory (); + } + SDL_strlcpy (bufp, appname, n + 1); + appname = bufp; + + /* Load SDL dynamic link library */ + if (SDL_Init (SDL_INIT_NOPARACHUTE) < 0) { + ShowError ("WinMain() error", SDL_GetError ()); + return (FALSE); + } + atexit (cleanup_output); + atexit (cleanup); + + /* Sam: + We still need to pass in the application handle so that + DirectInput will initialize properly when SDL_RegisterApp() + is called later in the video initialization. + */ + SDL_SetModuleHandle (GetModuleHandle (NULL)); + + /* Run the application main() code */ + status = SDL_main (argc, argv); + + /* Exit cleanly, calling atexit() functions */ + exit (status); + + /* Hush little compiler, don't you cry... */ + return 0; } /* This is where execution begins [windowed apps] */ #ifdef _WIN32_WCE -int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw) +int WINAPI +WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw) #else -int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) +int WINAPI +WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) #endif { - HINSTANCE handle; - char **argv; - int argc; - char *cmdline; - DWORD pathlen; + HINSTANCE handle; + char **argv; + int argc; + char *cmdline; + DWORD pathlen; #ifdef _WIN32_WCE - wchar_t path[MAX_PATH]; + wchar_t path[MAX_PATH]; #else - char path[MAX_PATH]; + char path[MAX_PATH]; #endif #ifdef _WIN32_WCE - wchar_t *bufp; - int nLen; + wchar_t *bufp; + int nLen; #else - char *bufp; - size_t nLen; + char *bufp; + size_t nLen; #endif #ifndef NO_STDIO_REDIRECT - FILE *newfp; + FILE *newfp; #endif - /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't - keep them open. This is a hack.. hopefully it will be fixed - someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. - */ - handle = LoadLibrary(TEXT("DDRAW.DLL")); - if ( handle != NULL ) { - FreeLibrary(handle); - } - + /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't + keep them open. This is a hack.. hopefully it will be fixed + someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. + */ + handle = LoadLibrary (TEXT ("DDRAW.DLL")); + if (handle != NULL) { + FreeLibrary (handle); + } #ifndef NO_STDIO_REDIRECT - pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path)); - while ( pathlen > 0 && path[pathlen] != '\\' ) { - --pathlen; - } - path[pathlen] = '\0'; + pathlen = GetModuleFileName (NULL, path, SDL_arraysize (path)); + while (pathlen > 0 && path[pathlen] != '\\') { + --pathlen; + } + path[pathlen] = '\0'; #ifdef _WIN32_WCE - wcsncpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); - wcsncat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); + wcsncpy (stdoutPath, path, SDL_arraysize (stdoutPath)); + wcsncat (stdoutPath, DIR_SEPERATOR STDOUT_FILE, + SDL_arraysize (stdoutPath)); #else - SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); - SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); + SDL_strlcpy (stdoutPath, path, SDL_arraysize (stdoutPath)); + SDL_strlcat (stdoutPath, DIR_SEPERATOR STDOUT_FILE, + SDL_arraysize (stdoutPath)); #endif - - /* Redirect standard input and standard output */ - newfp = freopen(stdoutPath, TEXT("w"), stdout); + + /* Redirect standard input and standard output */ + newfp = freopen (stdoutPath, TEXT ("w"), stdout); #ifndef _WIN32_WCE - if ( newfp == NULL ) { /* This happens on NT */ + if (newfp == NULL) { /* This happens on NT */ #if !defined(stdout) - stdout = fopen(stdoutPath, TEXT("w")); + stdout = fopen (stdoutPath, TEXT ("w")); #else - newfp = fopen(stdoutPath, TEXT("w")); - if ( newfp ) { - *stdout = *newfp; - } + newfp = fopen (stdoutPath, TEXT ("w")); + if (newfp) { + *stdout = *newfp; + } #endif - } + } #endif /* _WIN32_WCE */ #ifdef _WIN32_WCE - wcsncpy( stderrPath, path, SDL_arraysize(stdoutPath) ); - wcsncat( stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); + wcsncpy (stderrPath, path, SDL_arraysize (stdoutPath)); + wcsncat (stderrPath, DIR_SEPERATOR STDOUT_FILE, + SDL_arraysize (stdoutPath)); #else - SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) ); - SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) ); + SDL_strlcpy (stderrPath, path, SDL_arraysize (stderrPath)); + SDL_strlcat (stderrPath, DIR_SEPERATOR STDERR_FILE, + SDL_arraysize (stderrPath)); #endif - newfp = freopen(stderrPath, TEXT("w"), stderr); + newfp = freopen (stderrPath, TEXT ("w"), stderr); #ifndef _WIN32_WCE - if ( newfp == NULL ) { /* This happens on NT */ + if (newfp == NULL) { /* This happens on NT */ #if !defined(stderr) - stderr = fopen(stderrPath, TEXT("w")); + stderr = fopen (stderrPath, TEXT ("w")); #else - newfp = fopen(stderrPath, TEXT("w")); - if ( newfp ) { - *stderr = *newfp; - } + newfp = fopen (stderrPath, TEXT ("w")); + if (newfp) { + *stderr = *newfp; + } #endif - } + } #endif /* _WIN32_WCE */ - setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ - setbuf(stderr, NULL); /* No buffering */ + setvbuf (stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ + setbuf (stderr, NULL); /* No buffering */ #endif /* !NO_STDIO_REDIRECT */ #ifdef _WIN32_WCE - nLen = wcslen(szCmdLine)+128+1; - bufp = SDL_stack_alloc(wchar_t, nLen*2); - wcscpy (bufp, TEXT("\"")); - GetModuleFileName(NULL, bufp+1, 128-3); - wcscpy (bufp+wcslen(bufp), TEXT("\" ")); - wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp)); - nLen = wcslen(bufp)+1; - cmdline = SDL_stack_alloc(char, nLen); - if ( cmdline == NULL ) { - return OutOfMemory(); - } - WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); + nLen = wcslen (szCmdLine) + 128 + 1; + bufp = SDL_stack_alloc (wchar_t, nLen * 2); + wcscpy (bufp, TEXT ("\"")); + GetModuleFileName (NULL, bufp + 1, 128 - 3); + wcscpy (bufp + wcslen (bufp), TEXT ("\" ")); + wcsncpy (bufp + wcslen (bufp), szCmdLine, nLen - wcslen (bufp)); + nLen = wcslen (bufp) + 1; + cmdline = SDL_stack_alloc (char, nLen); + if (cmdline == NULL) { + return OutOfMemory (); + } + WideCharToMultiByte (CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); #else - /* Grab the command line */ - bufp = GetCommandLine(); - nLen = SDL_strlen(bufp)+1; - cmdline = SDL_stack_alloc(char, nLen); - if ( cmdline == NULL ) { - return OutOfMemory(); - } - SDL_strlcpy(cmdline, bufp, nLen); + /* Grab the command line */ + bufp = GetCommandLine (); + nLen = SDL_strlen (bufp) + 1; + cmdline = SDL_stack_alloc (char, nLen); + if (cmdline == NULL) { + return OutOfMemory (); + } + SDL_strlcpy (cmdline, bufp, nLen); #endif - /* Parse it into argv and argc */ - argc = ParseCommandLine(cmdline, NULL); - argv = SDL_stack_alloc(char*, argc+1); - if ( argv == NULL ) { - return OutOfMemory(); - } - ParseCommandLine(cmdline, argv); + /* Parse it into argv and argc */ + argc = ParseCommandLine (cmdline, NULL); + argv = SDL_stack_alloc (char *, argc + 1); + if (argv == NULL) { + return OutOfMemory (); + } + ParseCommandLine (cmdline, argv); - /* Run the main program (after a little SDL initialization) */ - console_main(argc, argv); + /* Run the main program (after a little SDL initialization) */ + console_main (argc, argv); - /* Hush little compiler, don't you cry... */ - return 0; + /* Hush little compiler, don't you cry... */ + return 0; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 74116cc97..239c3bf15 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -32,143 +32,148 @@ /* Note this isn't thread-safe! */ -static char *SDL_envmem = NULL; /* Ugh, memory leak */ +static char *SDL_envmem = NULL; /* Ugh, memory leak */ static size_t SDL_envmemlen = 0; /* Put a variable of the form "name=value" into the environment */ -int SDL_putenv(const char *variable) +int +SDL_putenv (const char *variable) { - size_t bufferlen; - char *value; - const char *sep; - - sep = SDL_strchr(variable, '='); - if ( sep == NULL ) { - return -1; - } - bufferlen = SDL_strlen(variable)+1; - if ( bufferlen > SDL_envmemlen ) { - char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen); - if ( newmem == NULL ) { - return -1; - } - SDL_envmem = newmem; - SDL_envmemlen = bufferlen; - } - SDL_strlcpy(SDL_envmem, variable, bufferlen); - value = SDL_envmem + (sep - variable); - *value++ = '\0'; - if ( !SetEnvironmentVariable(SDL_envmem, *value ? value : NULL) ) { - return -1; - } - return 0; + size_t bufferlen; + char *value; + const char *sep; + + sep = SDL_strchr (variable, '='); + if (sep == NULL) { + return -1; + } + bufferlen = SDL_strlen (variable) + 1; + if (bufferlen > SDL_envmemlen) { + char *newmem = (char *) SDL_realloc (SDL_envmem, bufferlen); + if (newmem == NULL) { + return -1; + } + SDL_envmem = newmem; + SDL_envmemlen = bufferlen; + } + SDL_strlcpy (SDL_envmem, variable, bufferlen); + value = SDL_envmem + (sep - variable); + *value++ = '\0'; + if (!SetEnvironmentVariable (SDL_envmem, *value ? value : NULL)) { + return -1; + } + return 0; } /* Retrieve a variable named "name" from the environment */ -char *SDL_getenv(const char *name) +char * +SDL_getenv (const char *name) { - size_t bufferlen; - - bufferlen = GetEnvironmentVariable(name, SDL_envmem, (DWORD)SDL_envmemlen); - if ( bufferlen == 0 ) { - return NULL; - } - if ( bufferlen > SDL_envmemlen ) { - char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen); - if ( newmem == NULL ) { - return NULL; - } - SDL_envmem = newmem; - SDL_envmemlen = bufferlen; - GetEnvironmentVariable(name, SDL_envmem, (DWORD)SDL_envmemlen); - } - return SDL_envmem; + size_t bufferlen; + + bufferlen = + GetEnvironmentVariable (name, SDL_envmem, (DWORD) SDL_envmemlen); + if (bufferlen == 0) { + return NULL; + } + if (bufferlen > SDL_envmemlen) { + char *newmem = (char *) SDL_realloc (SDL_envmem, bufferlen); + if (newmem == NULL) { + return NULL; + } + SDL_envmem = newmem; + SDL_envmemlen = bufferlen; + GetEnvironmentVariable (name, SDL_envmem, (DWORD) SDL_envmemlen); + } + return SDL_envmem; } #else /* roll our own */ -static char **SDL_env = (char **)0; +static char **SDL_env = (char **) 0; /* Put a variable of the form "name=value" into the environment */ -int SDL_putenv(const char *variable) +int +SDL_putenv (const char *variable) { - const char *name, *value; - int added; - int len, i; - char **new_env; - char *new_variable; - - /* A little error checking */ - if ( ! variable ) { - return(-1); - } - name = variable; - for ( value=variable; *value && (*value != '='); ++value ) { - /* Keep looking for '=' */ ; - } - if ( *value ) { - ++value; - } else { - return(-1); - } - - /* Allocate memory for the variable */ - new_variable = SDL_strdup(variable); - if ( ! new_variable ) { - return(-1); - } - - /* Actually put it into the environment */ - added = 0; - i = 0; - if ( SDL_env ) { - /* Check to see if it's already there... */ - len = (value - name); - for ( ; SDL_env[i]; ++i ) { - if ( SDL_strncmp(SDL_env[i], name, len) == 0 ) { - break; - } - } - /* If we found it, just replace the entry */ - if ( SDL_env[i] ) { - SDL_free(SDL_env[i]); - SDL_env[i] = new_variable; - added = 1; - } - } - - /* Didn't find it in the environment, expand and add */ - if ( ! added ) { - new_env = SDL_realloc(SDL_env, (i+2)*sizeof(char *)); - if ( new_env ) { - SDL_env = new_env; - SDL_env[i++] = new_variable; - SDL_env[i++] = (char *)0; - added = 1; - } else { - SDL_free(new_variable); - } - } - return (added ? 0 : -1); + const char *name, *value; + int added; + int len, i; + char **new_env; + char *new_variable; + + /* A little error checking */ + if (!variable) { + return (-1); + } + name = variable; + for (value = variable; *value && (*value != '='); ++value) { + /* Keep looking for '=' */ ; + } + if (*value) { + ++value; + } else { + return (-1); + } + + /* Allocate memory for the variable */ + new_variable = SDL_strdup (variable); + if (!new_variable) { + return (-1); + } + + /* Actually put it into the environment */ + added = 0; + i = 0; + if (SDL_env) { + /* Check to see if it's already there... */ + len = (value - name); + for (; SDL_env[i]; ++i) { + if (SDL_strncmp (SDL_env[i], name, len) == 0) { + break; + } + } + /* If we found it, just replace the entry */ + if (SDL_env[i]) { + SDL_free (SDL_env[i]); + SDL_env[i] = new_variable; + added = 1; + } + } + + /* Didn't find it in the environment, expand and add */ + if (!added) { + new_env = SDL_realloc (SDL_env, (i + 2) * sizeof (char *)); + if (new_env) { + SDL_env = new_env; + SDL_env[i++] = new_variable; + SDL_env[i++] = (char *) 0; + added = 1; + } else { + SDL_free (new_variable); + } + } + return (added ? 0 : -1); } /* Retrieve a variable named "name" from the environment */ -char *SDL_getenv(const char *name) +char * +SDL_getenv (const char *name) { - int len, i; - char *value; - - value = (char *)0; - if ( SDL_env ) { - len = SDL_strlen(name); - for ( i=0; SDL_env[i] && !value; ++i ) { - if ( (SDL_strncmp(SDL_env[i], name, len) == 0) && - (SDL_env[i][len] == '=') ) { - value = &SDL_env[i][len+1]; - } - } - } - return value; + int len, i; + char *value; + + value = (char *) 0; + if (SDL_env) { + len = SDL_strlen (name); + for (i = 0; SDL_env[i] && !value; ++i) { + if ((SDL_strncmp (SDL_env[i], name, len) == 0) && + (SDL_env[i][len] == '=')) { + value = &SDL_env[i][len + 1]; + } + } + } + return value; } #endif /* __WIN32__ */ @@ -178,70 +183,71 @@ char *SDL_getenv(const char *name) #ifdef TEST_MAIN #include -int main(int argc, char *argv[]) +int +main (int argc, char *argv[]) { - char *value; - - printf("Checking for non-existent variable... "); - fflush(stdout); - if ( ! SDL_getenv("EXISTS") ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Setting FIRST=VALUE1 in the environment... "); - fflush(stdout); - if ( SDL_putenv("FIRST=VALUE1") == 0 ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Getting FIRST from the environment... "); - fflush(stdout); - value = SDL_getenv("FIRST"); - if ( value && (SDL_strcmp(value, "VALUE1") == 0) ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Setting SECOND=VALUE2 in the environment... "); - fflush(stdout); - if ( SDL_putenv("SECOND=VALUE2") == 0 ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Getting SECOND from the environment... "); - fflush(stdout); - value = SDL_getenv("SECOND"); - if ( value && (SDL_strcmp(value, "VALUE2") == 0) ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Setting FIRST=NOVALUE in the environment... "); - fflush(stdout); - if ( SDL_putenv("FIRST=NOVALUE") == 0 ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Getting FIRST from the environment... "); - fflush(stdout); - value = SDL_getenv("FIRST"); - if ( value && (SDL_strcmp(value, "NOVALUE") == 0) ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Checking for non-existent variable... "); - fflush(stdout); - if ( ! SDL_getenv("EXISTS") ) { - printf("okay\n"); - } else { - printf("failed\n"); - } - return(0); + char *value; + + printf ("Checking for non-existent variable... "); + fflush (stdout); + if (!SDL_getenv ("EXISTS")) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + printf ("Setting FIRST=VALUE1 in the environment... "); + fflush (stdout); + if (SDL_putenv ("FIRST=VALUE1") == 0) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + printf ("Getting FIRST from the environment... "); + fflush (stdout); + value = SDL_getenv ("FIRST"); + if (value && (SDL_strcmp (value, "VALUE1") == 0)) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + printf ("Setting SECOND=VALUE2 in the environment... "); + fflush (stdout); + if (SDL_putenv ("SECOND=VALUE2") == 0) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + printf ("Getting SECOND from the environment... "); + fflush (stdout); + value = SDL_getenv ("SECOND"); + if (value && (SDL_strcmp (value, "VALUE2") == 0)) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + printf ("Setting FIRST=NOVALUE in the environment... "); + fflush (stdout); + if (SDL_putenv ("FIRST=NOVALUE") == 0) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + printf ("Getting FIRST from the environment... "); + fflush (stdout); + value = SDL_getenv ("FIRST"); + if (value && (SDL_strcmp (value, "NOVALUE") == 0)) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + printf ("Checking for non-existent variable... "); + fflush (stdout); + if (!SDL_getenv ("EXISTS")) { + printf ("okay\n"); + } else { + printf ("failed\n"); + } + return (0); } #endif /* TEST_MAIN */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index 680a3f297..cfee46770 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -30,24 +30,25 @@ #include -size_t SDL_iconv(SDL_iconv_t cd, - char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) +size_t +SDL_iconv (SDL_iconv_t cd, + char **inbuf, size_t * inbytesleft, + char **outbuf, size_t * outbytesleft) { - size_t retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); - if ( retCode == (size_t)-1 ) { - switch(errno) { - case E2BIG: - return SDL_ICONV_E2BIG; - case EILSEQ: - return SDL_ICONV_EILSEQ; - case EINVAL: - return SDL_ICONV_EINVAL; - default: - return SDL_ICONV_ERROR; - } - } - return retCode; + size_t retCode = iconv (cd, inbuf, inbytesleft, outbuf, outbytesleft); + if (retCode == (size_t) - 1) { + switch (errno) { + case E2BIG: + return SDL_ICONV_E2BIG; + case EILSEQ: + return SDL_ICONV_EILSEQ; + case EINVAL: + return SDL_ICONV_EINVAL; + default: + return SDL_ICONV_ERROR; + } + } + return retCode; } #else @@ -61,19 +62,20 @@ size_t SDL_iconv(SDL_iconv_t cd, #define UNKNOWN_ASCII '?' #define UNKNOWN_UNICODE 0xFFFD -enum { - ENCODING_UNKNOWN, - ENCODING_ASCII, - ENCODING_LATIN1, - ENCODING_UTF8, - ENCODING_UTF16, /* Needs byte order marker */ - ENCODING_UTF16BE, - ENCODING_UTF16LE, - ENCODING_UTF32, /* Needs byte order marker */ - ENCODING_UTF32BE, - ENCODING_UTF32LE, - ENCODING_UCS2, /* Native byte order assumed */ - ENCODING_UCS4, /* Native byte order assumed */ +enum +{ + ENCODING_UNKNOWN, + ENCODING_ASCII, + ENCODING_LATIN1, + ENCODING_UTF8, + ENCODING_UTF16, /* Needs byte order marker */ + ENCODING_UTF16BE, + ENCODING_UTF16LE, + ENCODING_UTF32, /* Needs byte order marker */ + ENCODING_UTF32BE, + ENCODING_UTF32LE, + ENCODING_UCS2, /* Native byte order assumed */ + ENCODING_UCS4, /* Native byte order assumed */ }; #if SDL_BYTEORDER == SDL_BIG_ENDIAN #define ENCODING_UTF16NATIVE ENCODING_UTF16BE @@ -85,730 +87,732 @@ enum { struct _SDL_iconv_t { - int src_fmt; - int dst_fmt; + int src_fmt; + int dst_fmt; }; -static struct { - const char *name; - int format; +static struct +{ + const char *name; + int format; } encodings[] = { - { "ASCII", ENCODING_ASCII }, - { "US-ASCII", ENCODING_ASCII }, - { "LATIN1", ENCODING_LATIN1 }, - { "ISO-8859-1", ENCODING_LATIN1 }, - { "UTF8", ENCODING_UTF8 }, - { "UTF-8", ENCODING_UTF8 }, - { "UTF16", ENCODING_UTF16 }, - { "UTF-16", ENCODING_UTF16 }, - { "UTF16BE", ENCODING_UTF16BE }, - { "UTF-16BE", ENCODING_UTF16BE }, - { "UTF16LE", ENCODING_UTF16LE }, - { "UTF-16LE", ENCODING_UTF16LE }, - { "UTF32", ENCODING_UTF32 }, - { "UTF-32", ENCODING_UTF32 }, - { "UTF32BE", ENCODING_UTF32BE }, - { "UTF-32BE", ENCODING_UTF32BE }, - { "UTF32LE", ENCODING_UTF32LE }, - { "UTF-32LE", ENCODING_UTF32LE }, - { "UCS2", ENCODING_UCS2 }, - { "UCS-2", ENCODING_UCS2 }, - { "UCS4", ENCODING_UCS4 }, - { "UCS-4", ENCODING_UCS4 }, -}; - -SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode) + { + "ASCII", ENCODING_ASCII}, { + "US-ASCII", ENCODING_ASCII}, { + "LATIN1", ENCODING_LATIN1}, { + "ISO-8859-1", ENCODING_LATIN1}, { + "UTF8", ENCODING_UTF8}, { + "UTF-8", ENCODING_UTF8}, { + "UTF16", ENCODING_UTF16}, { + "UTF-16", ENCODING_UTF16}, { + "UTF16BE", ENCODING_UTF16BE}, { + "UTF-16BE", ENCODING_UTF16BE}, { + "UTF16LE", ENCODING_UTF16LE}, { + "UTF-16LE", ENCODING_UTF16LE}, { + "UTF32", ENCODING_UTF32}, { + "UTF-32", ENCODING_UTF32}, { + "UTF32BE", ENCODING_UTF32BE}, { + "UTF-32BE", ENCODING_UTF32BE}, { + "UTF32LE", ENCODING_UTF32LE}, { + "UTF-32LE", ENCODING_UTF32LE}, { + "UCS2", ENCODING_UCS2}, { + "UCS-2", ENCODING_UCS2}, { + "UCS4", ENCODING_UCS4}, { +"UCS-4", ENCODING_UCS4},}; + +SDL_iconv_t +SDL_iconv_open (const char *tocode, const char *fromcode) { - int src_fmt = ENCODING_UNKNOWN; - int dst_fmt = ENCODING_UNKNOWN; - int i; - - for ( i = 0; i < SDL_arraysize(encodings); ++i ) { - if ( SDL_strcasecmp(fromcode, encodings[i].name) == 0 ) { - src_fmt = encodings[i].format; - if ( dst_fmt != ENCODING_UNKNOWN ) { - break; - } - } - if ( SDL_strcasecmp(tocode, encodings[i].name) == 0 ) { - dst_fmt = encodings[i].format; - if ( src_fmt != ENCODING_UNKNOWN ) { - break; - } - } - } - if ( src_fmt != ENCODING_UNKNOWN && dst_fmt != ENCODING_UNKNOWN ) { - SDL_iconv_t cd = (SDL_iconv_t)SDL_malloc(sizeof(*cd)); - if ( cd ) { - cd->src_fmt = src_fmt; - cd->dst_fmt = dst_fmt; - return cd; - } - } - return (SDL_iconv_t)-1; + int src_fmt = ENCODING_UNKNOWN; + int dst_fmt = ENCODING_UNKNOWN; + int i; + + for (i = 0; i < SDL_arraysize (encodings); ++i) { + if (SDL_strcasecmp (fromcode, encodings[i].name) == 0) { + src_fmt = encodings[i].format; + if (dst_fmt != ENCODING_UNKNOWN) { + break; + } + } + if (SDL_strcasecmp (tocode, encodings[i].name) == 0) { + dst_fmt = encodings[i].format; + if (src_fmt != ENCODING_UNKNOWN) { + break; + } + } + } + if (src_fmt != ENCODING_UNKNOWN && dst_fmt != ENCODING_UNKNOWN) { + SDL_iconv_t cd = (SDL_iconv_t) SDL_malloc (sizeof (*cd)); + if (cd) { + cd->src_fmt = src_fmt; + cd->dst_fmt = dst_fmt; + return cd; + } + } + return (SDL_iconv_t) - 1; } -size_t SDL_iconv(SDL_iconv_t cd, - char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) +size_t +SDL_iconv (SDL_iconv_t cd, + char **inbuf, size_t * inbytesleft, + char **outbuf, size_t * outbytesleft) { - /* For simplicity, we'll convert everything to and from UCS-4 */ - char *src, *dst; - size_t srclen, dstlen; - Uint32 ch; - size_t total; - - if ( !inbuf || !*inbuf ) { - /* Reset the context */ - return 0; - } - if ( !outbuf || !*outbuf || !outbytesleft || !*outbytesleft ) { - return SDL_ICONV_E2BIG; - } - src = *inbuf; - srclen = (inbytesleft ? *inbytesleft : 0); - dst = *outbuf; - dstlen = *outbytesleft; - - switch ( cd->src_fmt ) { - case ENCODING_UTF16: - /* Scan for a byte order marker */ - { - Uint8 *p = (Uint8 *)src; - size_t n = srclen / 2; - while ( n ) { - if ( p[0] == 0xFF && p[1] == 0xFE ) { - cd->src_fmt = ENCODING_UTF16BE; - break; - } else if ( p[0] == 0xFE && p[1] == 0xFF ) { - cd->src_fmt = ENCODING_UTF16LE; - break; - } - p += 2; - --n; - } - if ( n == 0 ) { - /* We can't tell, default to host order */ - cd->src_fmt = ENCODING_UTF16NATIVE; - } - } - break; - case ENCODING_UTF32: - /* Scan for a byte order marker */ - { - Uint8 *p = (Uint8 *)src; - size_t n = srclen / 4; - while ( n ) { - if ( p[0] == 0xFF && p[1] == 0xFE && - p[2] == 0x00 && p[3] == 0x00 ) { - cd->src_fmt = ENCODING_UTF32BE; - break; - } else if ( p[0] == 0x00 && p[1] == 0x00 && - p[2] == 0xFE && p[3] == 0xFF ) { - cd->src_fmt = ENCODING_UTF32LE; - break; - } - p += 4; - --n; - } - if ( n == 0 ) { - /* We can't tell, default to host order */ - cd->src_fmt = ENCODING_UTF32NATIVE; - } - } - break; - } - - switch ( cd->dst_fmt ) { - case ENCODING_UTF16: - /* Default to host order, need to add byte order marker */ - if ( dstlen < 2 ) { - return SDL_ICONV_E2BIG; - } - *(Uint16 *)dst = UNICODE_BOM; - dst += 2; - dstlen -= 2; - cd->dst_fmt = ENCODING_UTF16NATIVE; - break; - case ENCODING_UTF32: - /* Default to host order, need to add byte order marker */ - if ( dstlen < 4 ) { - return SDL_ICONV_E2BIG; - } - *(Uint32 *)dst = UNICODE_BOM; - dst += 4; - dstlen -= 4; - cd->dst_fmt = ENCODING_UTF32NATIVE; - break; - } - - total = 0; - while ( srclen > 0 ) { - /* Decode a character */ - switch ( cd->src_fmt ) { - case ENCODING_ASCII: - { - Uint8 *p = (Uint8 *)src; - ch = (Uint32)(p[0] & 0x7F); - ++src; - --srclen; - } - break; - case ENCODING_LATIN1: - { - Uint8 *p = (Uint8 *)src; - ch = (Uint32)p[0]; - ++src; - --srclen; - } - break; - case ENCODING_UTF8: /* RFC 3629 */ - { - Uint8 *p = (Uint8 *)src; - size_t left = 0; - SDL_bool overlong = SDL_FALSE; - if ( p[0] >= 0xFC ) { - if ( (p[0] & 0xFE) != 0xFC ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } else { - if ( p[0] == 0xFC ) { - overlong = SDL_TRUE; - } - ch = (Uint32)(p[0] & 0x01); - left = 5; - } - } else if ( p[0] >= 0xF8 ) { - if ( (p[0] & 0xFC) != 0xF8 ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } else { - if ( p[0] == 0xF8 ) { - overlong = SDL_TRUE; - } - ch = (Uint32)(p[0] & 0x03); - left = 4; - } - } else if ( p[0] >= 0xF0 ) { - if ( (p[0] & 0xF8) != 0xF0 ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } else { - if ( p[0] == 0xF0 ) { - overlong = SDL_TRUE; - } - ch = (Uint32)(p[0] & 0x07); - left = 3; - } - } else if ( p[0] >= 0xE0 ) { - if ( (p[0] & 0xF0) != 0xE0 ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } else { - if ( p[0] == 0xE0 ) { - overlong = SDL_TRUE; - } - ch = (Uint32)(p[0] & 0x0F); - left = 2; - } - } else if ( p[0] >= 0xC0 ) { - if ( (p[0] & 0xE0) != 0xC0 ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } else { - if ( (p[0] & 0xCE) == 0xC0 ) { - overlong = SDL_TRUE; - } - ch = (Uint32)(p[0] & 0x1F); - left = 1; - } - } else { - if ( (p[0] & 0x80) != 0x00 ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } else { - ch = (Uint32)p[0]; - } - } - ++src; - --srclen; - if ( srclen < left ) { - return SDL_ICONV_EINVAL; - } - while ( left-- ) { - ++p; - if ( (p[0] & 0xC0) != 0x80 ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - break; - } - ch <<= 6; - ch |= (p[0] & 0x3F); - ++src; - --srclen; - } - if ( overlong ) { - /* Potential security risk - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } - if ( (ch >= 0xD800 && ch <= 0xDFFF) || - (ch == 0xFFFE || ch == 0xFFFF) || - ch > 0x10FFFF ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - } - } - break; - case ENCODING_UTF16BE: /* RFC 2781 */ - { - Uint8 *p = (Uint8 *)src; - Uint16 W1, W2; - if ( srclen < 2 ) { - return SDL_ICONV_EINVAL; - } - W1 = ((Uint16)p[0] << 8) | - (Uint16)p[1]; - src += 2; - srclen -= 2; - if ( W1 < 0xD800 || W1 > 0xDFFF ) { - ch = (Uint32)W1; - break; - } - if ( W1 > 0xDBFF ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - break; - } - if ( srclen < 2 ) { - return SDL_ICONV_EINVAL; - } - p = (Uint8 *)src; - W2 = ((Uint16)p[0] << 8) | - (Uint16)p[1]; - src += 2; - srclen -= 2; - if ( W2 < 0xDC00 || W2 > 0xDFFF ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - break; - } - ch = (((Uint32)(W1 & 0x3FF) << 10) | - (Uint32)(W2 & 0x3FF)) + 0x10000; - } - break; - case ENCODING_UTF16LE: /* RFC 2781 */ - { - Uint8 *p = (Uint8 *)src; - Uint16 W1, W2; - if ( srclen < 2 ) { - return SDL_ICONV_EINVAL; - } - W1 = ((Uint16)p[1] << 8) | - (Uint16)p[0]; - src += 2; - srclen -= 2; - if ( W1 < 0xD800 || W1 > 0xDFFF ) { - ch = (Uint32)W1; - break; - } - if ( W1 > 0xDBFF ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - break; - } - if ( srclen < 2 ) { - return SDL_ICONV_EINVAL; - } - p = (Uint8 *)src; - W2 = ((Uint16)p[1] << 8) | - (Uint16)p[0]; - src += 2; - srclen -= 2; - if ( W2 < 0xDC00 || W2 > 0xDFFF ) { - /* Skip illegal sequences - return SDL_ICONV_EILSEQ; - */ - ch = UNKNOWN_UNICODE; - break; - } - ch = (((Uint32)(W1 & 0x3FF) << 10) | - (Uint32)(W2 & 0x3FF)) + 0x10000; - } - break; - case ENCODING_UTF32BE: - { - Uint8 *p = (Uint8 *)src; - if ( srclen < 4 ) { - return SDL_ICONV_EINVAL; - } - ch = ((Uint32)p[0] << 24) | - ((Uint32)p[1] << 16) | - ((Uint32)p[2] << 8) | - (Uint32)p[3]; - src += 4; - srclen -= 4; - } - break; - case ENCODING_UTF32LE: - { - Uint8 *p = (Uint8 *)src; - if ( srclen < 4 ) { - return SDL_ICONV_EINVAL; - } - ch = ((Uint32)p[3] << 24) | - ((Uint32)p[2] << 16) | - ((Uint32)p[1] << 8) | - (Uint32)p[0]; - src += 4; - srclen -= 4; - } - break; - case ENCODING_UCS2: - { - Uint16 *p = (Uint16 *)src; - if ( srclen < 2 ) { - return SDL_ICONV_EINVAL; - } - ch = *p; - src += 2; - srclen -= 2; - } - break; - case ENCODING_UCS4: - { - Uint32 *p = (Uint32 *)src; - if ( srclen < 4 ) { - return SDL_ICONV_EINVAL; - } - ch = *p; - src += 4; - srclen -= 4; - } - break; - } - - /* Encode a character */ - switch ( cd->dst_fmt ) { - case ENCODING_ASCII: - { - Uint8 *p = (Uint8 *)dst; - if ( dstlen < 1 ) { - return SDL_ICONV_E2BIG; - } - if ( ch > 0x7F ) { - *p = UNKNOWN_ASCII; - } else { - *p = (Uint8)ch; - } - ++dst; - --dstlen; - } - break; - case ENCODING_LATIN1: - { - Uint8 *p = (Uint8 *)dst; - if ( dstlen < 1 ) { - return SDL_ICONV_E2BIG; - } - if ( ch > 0xFF ) { - *p = UNKNOWN_ASCII; - } else { - *p = (Uint8)ch; - } - ++dst; - --dstlen; - } - break; - case ENCODING_UTF8: /* RFC 3629 */ - { - Uint8 *p = (Uint8 *)dst; - if ( ch > 0x10FFFF ) { - ch = UNKNOWN_UNICODE; - } - if ( ch <= 0x7F ) { - if ( dstlen < 1 ) { - return SDL_ICONV_E2BIG; - } - *p = (Uint8)ch; - ++dst; - --dstlen; - } else if ( ch <= 0x7FF ) { - if ( dstlen < 2 ) { - return SDL_ICONV_E2BIG; - } - p[0] = 0xC0 | (Uint8)((ch >> 6) & 0x1F); - p[1] = 0x80 | (Uint8)(ch & 0x3F); - dst += 2; - dstlen -= 2; - } else if ( ch <= 0xFFFF ) { - if ( dstlen < 3 ) { - return SDL_ICONV_E2BIG; - } - p[0] = 0xE0 | (Uint8)((ch >> 12) & 0x0F); - p[1] = 0x80 | (Uint8)((ch >> 6) & 0x3F); - p[2] = 0x80 | (Uint8)(ch & 0x3F); - dst += 3; - dstlen -= 3; - } else if ( ch <= 0x1FFFFF ) { - if ( dstlen < 4 ) { - return SDL_ICONV_E2BIG; - } - p[0] = 0xF0 | (Uint8)((ch >> 18) & 0x07); - p[1] = 0x80 | (Uint8)((ch >> 12) & 0x3F); - p[2] = 0x80 | (Uint8)((ch >> 6) & 0x3F); - p[3] = 0x80 | (Uint8)(ch & 0x3F); - dst += 4; - dstlen -= 4; - } else if ( ch <= 0x3FFFFFF ) { - if ( dstlen < 5 ) { - return SDL_ICONV_E2BIG; - } - p[0] = 0xF8 | (Uint8)((ch >> 24) & 0x03); - p[1] = 0x80 | (Uint8)((ch >> 18) & 0x3F); - p[2] = 0x80 | (Uint8)((ch >> 12) & 0x3F); - p[3] = 0x80 | (Uint8)((ch >> 6) & 0x3F); - p[4] = 0x80 | (Uint8)(ch & 0x3F); - dst += 5; - dstlen -= 5; - } else { - if ( dstlen < 6 ) { - return SDL_ICONV_E2BIG; - } - p[0] = 0xFC | (Uint8)((ch >> 30) & 0x01); - p[1] = 0x80 | (Uint8)((ch >> 24) & 0x3F); - p[2] = 0x80 | (Uint8)((ch >> 18) & 0x3F); - p[3] = 0x80 | (Uint8)((ch >> 12) & 0x3F); - p[4] = 0x80 | (Uint8)((ch >> 6) & 0x3F); - p[5] = 0x80 | (Uint8)(ch & 0x3F); - dst += 6; - dstlen -= 6; - } - } - break; - case ENCODING_UTF16BE: /* RFC 2781 */ - { - Uint8 *p = (Uint8 *)dst; - if ( ch > 0x10FFFF ) { - ch = UNKNOWN_UNICODE; - } - if ( ch < 0x10000 ) { - if ( dstlen < 2 ) { - return SDL_ICONV_E2BIG; - } - p[0] = (Uint8)(ch >> 8); - p[1] = (Uint8)ch; - dst += 2; - dstlen -= 2; - } else { - Uint16 W1, W2; - if ( dstlen < 4 ) { - return SDL_ICONV_E2BIG; - } - ch = ch - 0x10000; - W1 = 0xD800 | (Uint16)((ch >> 10) & 0x3FF); - W2 = 0xDC00 | (Uint16)(ch & 0x3FF); - p[0] = (Uint8)(W1 >> 8); - p[1] = (Uint8)W1; - p[2] = (Uint8)(W2 >> 8); - p[3] = (Uint8)W2; - dst += 4; - dstlen -= 4; - } - } - break; - case ENCODING_UTF16LE: /* RFC 2781 */ - { - Uint8 *p = (Uint8 *)dst; - if ( ch > 0x10FFFF ) { - ch = UNKNOWN_UNICODE; - } - if ( ch < 0x10000 ) { - if ( dstlen < 2 ) { - return SDL_ICONV_E2BIG; - } - p[1] = (Uint8)(ch >> 8); - p[0] = (Uint8)ch; - dst += 2; - dstlen -= 2; - } else { - Uint16 W1, W2; - if ( dstlen < 4 ) { - return SDL_ICONV_E2BIG; - } - ch = ch - 0x10000; - W1 = 0xD800 | (Uint16)((ch >> 10) & 0x3FF); - W2 = 0xDC00 | (Uint16)(ch & 0x3FF); - p[1] = (Uint8)(W1 >> 8); - p[0] = (Uint8)W1; - p[3] = (Uint8)(W2 >> 8); - p[2] = (Uint8)W2; - dst += 4; - dstlen -= 4; - } - } - break; - case ENCODING_UTF32BE: - { - Uint8 *p = (Uint8 *)dst; - if ( ch > 0x10FFFF ) { - ch = UNKNOWN_UNICODE; - } - if ( dstlen < 4 ) { - return SDL_ICONV_E2BIG; - } - p[0] = (Uint8)(ch >> 24); - p[1] = (Uint8)(ch >> 16); - p[2] = (Uint8)(ch >> 8); - p[3] = (Uint8)ch; - dst += 4; - dstlen -= 4; - } - break; - case ENCODING_UTF32LE: - { - Uint8 *p = (Uint8 *)dst; - if ( ch > 0x10FFFF ) { - ch = UNKNOWN_UNICODE; - } - if ( dstlen < 4 ) { - return SDL_ICONV_E2BIG; - } - p[3] = (Uint8)(ch >> 24); - p[2] = (Uint8)(ch >> 16); - p[1] = (Uint8)(ch >> 8); - p[0] = (Uint8)ch; - dst += 4; - dstlen -= 4; - } - break; - case ENCODING_UCS2: - { - Uint16 *p = (Uint16 *)dst; - if ( ch > 0xFFFF ) { - ch = UNKNOWN_UNICODE; - } - if ( dstlen < 2 ) { - return SDL_ICONV_E2BIG; - } - *p = (Uint16)ch; - dst += 2; - dstlen -= 2; - } - break; - case ENCODING_UCS4: - { - Uint32 *p = (Uint32 *)dst; - if ( ch > 0x7FFFFFFF ) { - ch = UNKNOWN_UNICODE; - } - if ( dstlen < 4 ) { - return SDL_ICONV_E2BIG; - } - *p = ch; - dst += 4; - dstlen -= 4; - } - break; - } - - /* Update state */ - *inbuf = src; - *inbytesleft = srclen; - *outbuf = dst; - *outbytesleft = dstlen; - ++total; - } - return total; + /* For simplicity, we'll convert everything to and from UCS-4 */ + char *src, *dst; + size_t srclen, dstlen; + Uint32 ch; + size_t total; + + if (!inbuf || !*inbuf) { + /* Reset the context */ + return 0; + } + if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) { + return SDL_ICONV_E2BIG; + } + src = *inbuf; + srclen = (inbytesleft ? *inbytesleft : 0); + dst = *outbuf; + dstlen = *outbytesleft; + + switch (cd->src_fmt) { + case ENCODING_UTF16: + /* Scan for a byte order marker */ + { + Uint8 *p = (Uint8 *) src; + size_t n = srclen / 2; + while (n) { + if (p[0] == 0xFF && p[1] == 0xFE) { + cd->src_fmt = ENCODING_UTF16BE; + break; + } else if (p[0] == 0xFE && p[1] == 0xFF) { + cd->src_fmt = ENCODING_UTF16LE; + break; + } + p += 2; + --n; + } + if (n == 0) { + /* We can't tell, default to host order */ + cd->src_fmt = ENCODING_UTF16NATIVE; + } + } + break; + case ENCODING_UTF32: + /* Scan for a byte order marker */ + { + Uint8 *p = (Uint8 *) src; + size_t n = srclen / 4; + while (n) { + if (p[0] == 0xFF && p[1] == 0xFE && + p[2] == 0x00 && p[3] == 0x00) { + cd->src_fmt = ENCODING_UTF32BE; + break; + } else if (p[0] == 0x00 && p[1] == 0x00 && + p[2] == 0xFE && p[3] == 0xFF) { + cd->src_fmt = ENCODING_UTF32LE; + break; + } + p += 4; + --n; + } + if (n == 0) { + /* We can't tell, default to host order */ + cd->src_fmt = ENCODING_UTF32NATIVE; + } + } + break; + } + + switch (cd->dst_fmt) { + case ENCODING_UTF16: + /* Default to host order, need to add byte order marker */ + if (dstlen < 2) { + return SDL_ICONV_E2BIG; + } + *(Uint16 *) dst = UNICODE_BOM; + dst += 2; + dstlen -= 2; + cd->dst_fmt = ENCODING_UTF16NATIVE; + break; + case ENCODING_UTF32: + /* Default to host order, need to add byte order marker */ + if (dstlen < 4) { + return SDL_ICONV_E2BIG; + } + *(Uint32 *) dst = UNICODE_BOM; + dst += 4; + dstlen -= 4; + cd->dst_fmt = ENCODING_UTF32NATIVE; + break; + } + + total = 0; + while (srclen > 0) { + /* Decode a character */ + switch (cd->src_fmt) { + case ENCODING_ASCII: + { + Uint8 *p = (Uint8 *) src; + ch = (Uint32) (p[0] & 0x7F); + ++src; + --srclen; + } + break; + case ENCODING_LATIN1: + { + Uint8 *p = (Uint8 *) src; + ch = (Uint32) p[0]; + ++src; + --srclen; + } + break; + case ENCODING_UTF8: /* RFC 3629 */ + { + Uint8 *p = (Uint8 *) src; + size_t left = 0; + SDL_bool overlong = SDL_FALSE; + if (p[0] >= 0xFC) { + if ((p[0] & 0xFE) != 0xFC) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } else { + if (p[0] == 0xFC) { + overlong = SDL_TRUE; + } + ch = (Uint32) (p[0] & 0x01); + left = 5; + } + } else if (p[0] >= 0xF8) { + if ((p[0] & 0xFC) != 0xF8) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } else { + if (p[0] == 0xF8) { + overlong = SDL_TRUE; + } + ch = (Uint32) (p[0] & 0x03); + left = 4; + } + } else if (p[0] >= 0xF0) { + if ((p[0] & 0xF8) != 0xF0) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } else { + if (p[0] == 0xF0) { + overlong = SDL_TRUE; + } + ch = (Uint32) (p[0] & 0x07); + left = 3; + } + } else if (p[0] >= 0xE0) { + if ((p[0] & 0xF0) != 0xE0) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } else { + if (p[0] == 0xE0) { + overlong = SDL_TRUE; + } + ch = (Uint32) (p[0] & 0x0F); + left = 2; + } + } else if (p[0] >= 0xC0) { + if ((p[0] & 0xE0) != 0xC0) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } else { + if ((p[0] & 0xCE) == 0xC0) { + overlong = SDL_TRUE; + } + ch = (Uint32) (p[0] & 0x1F); + left = 1; + } + } else { + if ((p[0] & 0x80) != 0x00) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } else { + ch = (Uint32) p[0]; + } + } + ++src; + --srclen; + if (srclen < left) { + return SDL_ICONV_EINVAL; + } + while (left--) { + ++p; + if ((p[0] & 0xC0) != 0x80) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + break; + } + ch <<= 6; + ch |= (p[0] & 0x3F); + ++src; + --srclen; + } + if (overlong) { + /* Potential security risk + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } + if ((ch >= 0xD800 && ch <= 0xDFFF) || + (ch == 0xFFFE || ch == 0xFFFF) || ch > 0x10FFFF) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + } + } + break; + case ENCODING_UTF16BE: /* RFC 2781 */ + { + Uint8 *p = (Uint8 *) src; + Uint16 W1, W2; + if (srclen < 2) { + return SDL_ICONV_EINVAL; + } + W1 = ((Uint16) p[0] << 8) | (Uint16) p[1]; + src += 2; + srclen -= 2; + if (W1 < 0xD800 || W1 > 0xDFFF) { + ch = (Uint32) W1; + break; + } + if (W1 > 0xDBFF) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + break; + } + if (srclen < 2) { + return SDL_ICONV_EINVAL; + } + p = (Uint8 *) src; + W2 = ((Uint16) p[0] << 8) | (Uint16) p[1]; + src += 2; + srclen -= 2; + if (W2 < 0xDC00 || W2 > 0xDFFF) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + break; + } + ch = (((Uint32) (W1 & 0x3FF) << 10) | + (Uint32) (W2 & 0x3FF)) + 0x10000; + } + break; + case ENCODING_UTF16LE: /* RFC 2781 */ + { + Uint8 *p = (Uint8 *) src; + Uint16 W1, W2; + if (srclen < 2) { + return SDL_ICONV_EINVAL; + } + W1 = ((Uint16) p[1] << 8) | (Uint16) p[0]; + src += 2; + srclen -= 2; + if (W1 < 0xD800 || W1 > 0xDFFF) { + ch = (Uint32) W1; + break; + } + if (W1 > 0xDBFF) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + break; + } + if (srclen < 2) { + return SDL_ICONV_EINVAL; + } + p = (Uint8 *) src; + W2 = ((Uint16) p[1] << 8) | (Uint16) p[0]; + src += 2; + srclen -= 2; + if (W2 < 0xDC00 || W2 > 0xDFFF) { + /* Skip illegal sequences + return SDL_ICONV_EILSEQ; + */ + ch = UNKNOWN_UNICODE; + break; + } + ch = (((Uint32) (W1 & 0x3FF) << 10) | + (Uint32) (W2 & 0x3FF)) + 0x10000; + } + break; + case ENCODING_UTF32BE: + { + Uint8 *p = (Uint8 *) src; + if (srclen < 4) { + return SDL_ICONV_EINVAL; + } + ch = ((Uint32) p[0] << 24) | + ((Uint32) p[1] << 16) | + ((Uint32) p[2] << 8) | (Uint32) p[3]; + src += 4; + srclen -= 4; + } + break; + case ENCODING_UTF32LE: + { + Uint8 *p = (Uint8 *) src; + if (srclen < 4) { + return SDL_ICONV_EINVAL; + } + ch = ((Uint32) p[3] << 24) | + ((Uint32) p[2] << 16) | + ((Uint32) p[1] << 8) | (Uint32) p[0]; + src += 4; + srclen -= 4; + } + break; + case ENCODING_UCS2: + { + Uint16 *p = (Uint16 *) src; + if (srclen < 2) { + return SDL_ICONV_EINVAL; + } + ch = *p; + src += 2; + srclen -= 2; + } + break; + case ENCODING_UCS4: + { + Uint32 *p = (Uint32 *) src; + if (srclen < 4) { + return SDL_ICONV_EINVAL; + } + ch = *p; + src += 4; + srclen -= 4; + } + break; + } + + /* Encode a character */ + switch (cd->dst_fmt) { + case ENCODING_ASCII: + { + Uint8 *p = (Uint8 *) dst; + if (dstlen < 1) { + return SDL_ICONV_E2BIG; + } + if (ch > 0x7F) { + *p = UNKNOWN_ASCII; + } else { + *p = (Uint8) ch; + } + ++dst; + --dstlen; + } + break; + case ENCODING_LATIN1: + { + Uint8 *p = (Uint8 *) dst; + if (dstlen < 1) { + return SDL_ICONV_E2BIG; + } + if (ch > 0xFF) { + *p = UNKNOWN_ASCII; + } else { + *p = (Uint8) ch; + } + ++dst; + --dstlen; + } + break; + case ENCODING_UTF8: /* RFC 3629 */ + { + Uint8 *p = (Uint8 *) dst; + if (ch > 0x10FFFF) { + ch = UNKNOWN_UNICODE; + } + if (ch <= 0x7F) { + if (dstlen < 1) { + return SDL_ICONV_E2BIG; + } + *p = (Uint8) ch; + ++dst; + --dstlen; + } else if (ch <= 0x7FF) { + if (dstlen < 2) { + return SDL_ICONV_E2BIG; + } + p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F); + p[1] = 0x80 | (Uint8) (ch & 0x3F); + dst += 2; + dstlen -= 2; + } else if (ch <= 0xFFFF) { + if (dstlen < 3) { + return SDL_ICONV_E2BIG; + } + p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F); + p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); + p[2] = 0x80 | (Uint8) (ch & 0x3F); + dst += 3; + dstlen -= 3; + } else if (ch <= 0x1FFFFF) { + if (dstlen < 4) { + return SDL_ICONV_E2BIG; + } + p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07); + p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); + p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); + p[3] = 0x80 | (Uint8) (ch & 0x3F); + dst += 4; + dstlen -= 4; + } else if (ch <= 0x3FFFFFF) { + if (dstlen < 5) { + return SDL_ICONV_E2BIG; + } + p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03); + p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F); + p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); + p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); + p[4] = 0x80 | (Uint8) (ch & 0x3F); + dst += 5; + dstlen -= 5; + } else { + if (dstlen < 6) { + return SDL_ICONV_E2BIG; + } + p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01); + p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F); + p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F); + p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); + p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); + p[5] = 0x80 | (Uint8) (ch & 0x3F); + dst += 6; + dstlen -= 6; + } + } + break; + case ENCODING_UTF16BE: /* RFC 2781 */ + { + Uint8 *p = (Uint8 *) dst; + if (ch > 0x10FFFF) { + ch = UNKNOWN_UNICODE; + } + if (ch < 0x10000) { + if (dstlen < 2) { + return SDL_ICONV_E2BIG; + } + p[0] = (Uint8) (ch >> 8); + p[1] = (Uint8) ch; + dst += 2; + dstlen -= 2; + } else { + Uint16 W1, W2; + if (dstlen < 4) { + return SDL_ICONV_E2BIG; + } + ch = ch - 0x10000; + W1 = 0xD800 | (Uint16) ((ch >> 10) & 0x3FF); + W2 = 0xDC00 | (Uint16) (ch & 0x3FF); + p[0] = (Uint8) (W1 >> 8); + p[1] = (Uint8) W1; + p[2] = (Uint8) (W2 >> 8); + p[3] = (Uint8) W2; + dst += 4; + dstlen -= 4; + } + } + break; + case ENCODING_UTF16LE: /* RFC 2781 */ + { + Uint8 *p = (Uint8 *) dst; + if (ch > 0x10FFFF) { + ch = UNKNOWN_UNICODE; + } + if (ch < 0x10000) { + if (dstlen < 2) { + return SDL_ICONV_E2BIG; + } + p[1] = (Uint8) (ch >> 8); + p[0] = (Uint8) ch; + dst += 2; + dstlen -= 2; + } else { + Uint16 W1, W2; + if (dstlen < 4) { + return SDL_ICONV_E2BIG; + } + ch = ch - 0x10000; + W1 = 0xD800 | (Uint16) ((ch >> 10) & 0x3FF); + W2 = 0xDC00 | (Uint16) (ch & 0x3FF); + p[1] = (Uint8) (W1 >> 8); + p[0] = (Uint8) W1; + p[3] = (Uint8) (W2 >> 8); + p[2] = (Uint8) W2; + dst += 4; + dstlen -= 4; + } + } + break; + case ENCODING_UTF32BE: + { + Uint8 *p = (Uint8 *) dst; + if (ch > 0x10FFFF) { + ch = UNKNOWN_UNICODE; + } + if (dstlen < 4) { + return SDL_ICONV_E2BIG; + } + p[0] = (Uint8) (ch >> 24); + p[1] = (Uint8) (ch >> 16); + p[2] = (Uint8) (ch >> 8); + p[3] = (Uint8) ch; + dst += 4; + dstlen -= 4; + } + break; + case ENCODING_UTF32LE: + { + Uint8 *p = (Uint8 *) dst; + if (ch > 0x10FFFF) { + ch = UNKNOWN_UNICODE; + } + if (dstlen < 4) { + return SDL_ICONV_E2BIG; + } + p[3] = (Uint8) (ch >> 24); + p[2] = (Uint8) (ch >> 16); + p[1] = (Uint8) (ch >> 8); + p[0] = (Uint8) ch; + dst += 4; + dstlen -= 4; + } + break; + case ENCODING_UCS2: + { + Uint16 *p = (Uint16 *) dst; + if (ch > 0xFFFF) { + ch = UNKNOWN_UNICODE; + } + if (dstlen < 2) { + return SDL_ICONV_E2BIG; + } + *p = (Uint16) ch; + dst += 2; + dstlen -= 2; + } + break; + case ENCODING_UCS4: + { + Uint32 *p = (Uint32 *) dst; + if (ch > 0x7FFFFFFF) { + ch = UNKNOWN_UNICODE; + } + if (dstlen < 4) { + return SDL_ICONV_E2BIG; + } + *p = ch; + dst += 4; + dstlen -= 4; + } + break; + } + + /* Update state */ + *inbuf = src; + *inbytesleft = srclen; + *outbuf = dst; + *outbytesleft = dstlen; + ++total; + } + return total; } -int SDL_iconv_close(SDL_iconv_t cd) +int +SDL_iconv_close (SDL_iconv_t cd) { - if ( cd && cd != (SDL_iconv_t)-1 ) { - SDL_free(cd); - } - return 0; + if (cd && cd != (SDL_iconv_t) - 1) { + SDL_free (cd); + } + return 0; } #endif /* !HAVE_ICONV */ -char *SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf, size_t inbytesleft) +char * +SDL_iconv_string (const char *tocode, const char *fromcode, char *inbuf, + size_t inbytesleft) { - SDL_iconv_t cd; - char *string; - size_t stringsize; - char *outbuf; - size_t outbytesleft; - size_t retCode = 0; - - cd = SDL_iconv_open(tocode, fromcode); - if ( cd == (SDL_iconv_t)-1 ) { - return NULL; - } - - stringsize = inbytesleft > 4 ? inbytesleft : 4; - string = SDL_malloc(stringsize); - if ( !string ) { - SDL_iconv_close(cd); - return NULL; - } - outbuf = string; - outbytesleft = stringsize; - SDL_memset(outbuf, 0, 4); - - while ( inbytesleft > 0 ) { - retCode = SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - switch (retCode) { - case SDL_ICONV_E2BIG: - { - char *oldstring = string; - stringsize *= 2; - string = SDL_realloc(string, stringsize); - if ( !string ) { - SDL_iconv_close(cd); - return NULL; - } - outbuf = string + (outbuf - oldstring); - outbytesleft = stringsize - (outbuf - string); - SDL_memset(outbuf, 0, 4); - } - break; - case SDL_ICONV_EILSEQ: - /* Try skipping some input data - not perfect, but... */ - ++inbuf; - --inbytesleft; - break; - case SDL_ICONV_EINVAL: - case SDL_ICONV_ERROR: - /* We can't continue... */ - inbytesleft = 0; - break; - } - } - SDL_iconv_close(cd); - - return string; + SDL_iconv_t cd; + char *string; + size_t stringsize; + char *outbuf; + size_t outbytesleft; + size_t retCode = 0; + + cd = SDL_iconv_open (tocode, fromcode); + if (cd == (SDL_iconv_t) - 1) { + return NULL; + } + + stringsize = inbytesleft > 4 ? inbytesleft : 4; + string = SDL_malloc (stringsize); + if (!string) { + SDL_iconv_close (cd); + return NULL; + } + outbuf = string; + outbytesleft = stringsize; + SDL_memset (outbuf, 0, 4); + + while (inbytesleft > 0) { + retCode = + SDL_iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + switch (retCode) { + case SDL_ICONV_E2BIG: + { + char *oldstring = string; + stringsize *= 2; + string = SDL_realloc (string, stringsize); + if (!string) { + SDL_iconv_close (cd); + return NULL; + } + outbuf = string + (outbuf - oldstring); + outbytesleft = stringsize - (outbuf - string); + SDL_memset (outbuf, 0, 4); + } + break; + case SDL_ICONV_EILSEQ: + /* Try skipping some input data - not perfect, but... */ + ++inbuf; + --inbytesleft; + break; + case SDL_ICONV_EINVAL: + case SDL_ICONV_ERROR: + /* We can't continue... */ + inbytesleft = 0; + break; + } + } + SDL_iconv_close (cd); + + return string; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c index 3d973f625..153294585 100644 --- a/src/stdlib/SDL_malloc.c +++ b/src/stdlib/SDL_malloc.c @@ -477,8 +477,8 @@ DEFAULT_MMAP_THRESHOLD default: 256K #ifndef WIN32 #ifdef _WIN32 #define WIN32 1 -#endif /* _WIN32 */ -#endif /* WIN32 */ +#endif /* _WIN32 */ +#endif /* WIN32 */ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include @@ -491,123 +491,123 @@ DEFAULT_MMAP_THRESHOLD default: 256K #define LACKS_STRINGS_H #define LACKS_SYS_TYPES_H #define LACKS_ERRNO_H -#define LACKS_FCNTL_H +#define LACKS_FCNTL_H #define MALLOC_FAILURE_ACTION -#define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */ -#endif /* WIN32 */ +#define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */ +#endif /* WIN32 */ #if defined(DARWIN) || defined(_DARWIN) /* Mac OSX docs advise not to use sbrk; it seems better to use mmap */ #ifndef HAVE_MORECORE #define HAVE_MORECORE 0 #define HAVE_MMAP 1 -#endif /* HAVE_MORECORE */ -#endif /* DARWIN */ +#endif /* HAVE_MORECORE */ +#endif /* DARWIN */ #ifndef LACKS_SYS_TYPES_H -#include /* For size_t */ -#endif /* LACKS_SYS_TYPES_H */ +#include /* For size_t */ +#endif /* LACKS_SYS_TYPES_H */ /* The maximum possible size_t value has all bits set */ #define MAX_SIZE_T (~(size_t)0) #ifndef ONLY_MSPACES #define ONLY_MSPACES 0 -#endif /* ONLY_MSPACES */ +#endif /* ONLY_MSPACES */ #ifndef MSPACES #if ONLY_MSPACES #define MSPACES 1 -#else /* ONLY_MSPACES */ +#else /* ONLY_MSPACES */ #define MSPACES 0 -#endif /* ONLY_MSPACES */ -#endif /* MSPACES */ +#endif /* ONLY_MSPACES */ +#endif /* MSPACES */ #ifndef MALLOC_ALIGNMENT #define MALLOC_ALIGNMENT ((size_t)8U) -#endif /* MALLOC_ALIGNMENT */ +#endif /* MALLOC_ALIGNMENT */ #ifndef FOOTERS #define FOOTERS 0 -#endif /* FOOTERS */ +#endif /* FOOTERS */ #ifndef ABORT #define ABORT abort() -#endif /* ABORT */ +#endif /* ABORT */ #ifndef ABORT_ON_ASSERT_FAILURE #define ABORT_ON_ASSERT_FAILURE 1 -#endif /* ABORT_ON_ASSERT_FAILURE */ +#endif /* ABORT_ON_ASSERT_FAILURE */ #ifndef PROCEED_ON_ERROR #define PROCEED_ON_ERROR 0 -#endif /* PROCEED_ON_ERROR */ +#endif /* PROCEED_ON_ERROR */ #ifndef USE_LOCKS #define USE_LOCKS 0 -#endif /* USE_LOCKS */ +#endif /* USE_LOCKS */ #ifndef INSECURE #define INSECURE 0 -#endif /* INSECURE */ +#endif /* INSECURE */ #ifndef HAVE_MMAP #define HAVE_MMAP 1 -#endif /* HAVE_MMAP */ +#endif /* HAVE_MMAP */ #ifndef MMAP_CLEARS #define MMAP_CLEARS 1 -#endif /* MMAP_CLEARS */ +#endif /* MMAP_CLEARS */ #ifndef HAVE_MREMAP #ifdef linux #define HAVE_MREMAP 1 -#else /* linux */ +#else /* linux */ #define HAVE_MREMAP 0 -#endif /* linux */ -#endif /* HAVE_MREMAP */ +#endif /* linux */ +#endif /* HAVE_MREMAP */ #ifndef MALLOC_FAILURE_ACTION #define MALLOC_FAILURE_ACTION errno = ENOMEM; -#endif /* MALLOC_FAILURE_ACTION */ +#endif /* MALLOC_FAILURE_ACTION */ #ifndef HAVE_MORECORE #if ONLY_MSPACES #define HAVE_MORECORE 0 -#else /* ONLY_MSPACES */ +#else /* ONLY_MSPACES */ #define HAVE_MORECORE 1 -#endif /* ONLY_MSPACES */ -#endif /* HAVE_MORECORE */ +#endif /* ONLY_MSPACES */ +#endif /* HAVE_MORECORE */ #if !HAVE_MORECORE #define MORECORE_CONTIGUOUS 0 -#else /* !HAVE_MORECORE */ +#else /* !HAVE_MORECORE */ #ifndef MORECORE #define MORECORE sbrk -#endif /* MORECORE */ +#endif /* MORECORE */ #ifndef MORECORE_CONTIGUOUS #define MORECORE_CONTIGUOUS 1 -#endif /* MORECORE_CONTIGUOUS */ -#endif /* HAVE_MORECORE */ +#endif /* MORECORE_CONTIGUOUS */ +#endif /* HAVE_MORECORE */ #ifndef DEFAULT_GRANULARITY #if MORECORE_CONTIGUOUS -#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */ -#else /* MORECORE_CONTIGUOUS */ +#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */ +#else /* MORECORE_CONTIGUOUS */ #define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U) -#endif /* MORECORE_CONTIGUOUS */ -#endif /* DEFAULT_GRANULARITY */ +#endif /* MORECORE_CONTIGUOUS */ +#endif /* DEFAULT_GRANULARITY */ #ifndef DEFAULT_TRIM_THRESHOLD #ifndef MORECORE_CANNOT_TRIM #define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) -#else /* MORECORE_CANNOT_TRIM */ +#else /* MORECORE_CANNOT_TRIM */ #define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T -#endif /* MORECORE_CANNOT_TRIM */ -#endif /* DEFAULT_TRIM_THRESHOLD */ +#endif /* MORECORE_CANNOT_TRIM */ +#endif /* DEFAULT_TRIM_THRESHOLD */ #ifndef DEFAULT_MMAP_THRESHOLD #if HAVE_MMAP #define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U) -#else /* HAVE_MMAP */ +#else /* HAVE_MMAP */ #define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T -#endif /* HAVE_MMAP */ -#endif /* DEFAULT_MMAP_THRESHOLD */ +#endif /* HAVE_MMAP */ +#endif /* DEFAULT_MMAP_THRESHOLD */ #ifndef USE_BUILTIN_FFS #define USE_BUILTIN_FFS 0 -#endif /* USE_BUILTIN_FFS */ +#endif /* USE_BUILTIN_FFS */ #ifndef USE_DEV_RANDOM #define USE_DEV_RANDOM 0 -#endif /* USE_DEV_RANDOM */ +#endif /* USE_DEV_RANDOM */ #ifndef NO_MALLINFO #define NO_MALLINFO 0 -#endif /* NO_MALLINFO */ +#endif /* NO_MALLINFO */ #ifndef MALLINFO_FIELD_TYPE #define MALLINFO_FIELD_TYPE size_t -#endif /* MALLINFO_FIELD_TYPE */ +#endif /* MALLINFO_FIELD_TYPE */ #define memset SDL_memset #define memcpy SDL_memcpy @@ -658,25 +658,27 @@ DEFAULT_MMAP_THRESHOLD default: 256K #include "/usr/include/malloc.h" #else /* HAVE_USR_INCLUDE_MALLOC_H */ -struct mallinfo { - MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ - MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ - MALLINFO_FIELD_TYPE smblks; /* always 0 */ - MALLINFO_FIELD_TYPE hblks; /* always 0 */ - MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ - MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ - MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ - MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ - MALLINFO_FIELD_TYPE fordblks; /* total free space */ - MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ +struct mallinfo +{ + MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ + MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ + MALLINFO_FIELD_TYPE smblks; /* always 0 */ + MALLINFO_FIELD_TYPE hblks; /* always 0 */ + MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ + MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ + MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ + MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ + MALLINFO_FIELD_TYPE fordblks; /* total free space */ + MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ }; #endif /* HAVE_USR_INCLUDE_MALLOC_H */ #endif /* NO_MALLINFO */ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #if !ONLY_MSPACES @@ -699,7 +701,7 @@ extern "C" { #define dlmalloc_max_footprint malloc_max_footprint #define dlindependent_calloc independent_calloc #define dlindependent_comalloc independent_comalloc -#endif /* USE_DL_PREFIX */ +#endif /* USE_DL_PREFIX */ /* @@ -716,7 +718,7 @@ extern "C" { maximum supported value of n differs across systems, but is in all cases less than the maximum representable value of a size_t. */ -void* dlmalloc(size_t); + void *dlmalloc (size_t); /* free(void* p) @@ -725,14 +727,14 @@ void* dlmalloc(size_t); It has no effect if p is null. If p was not malloced or already freed, free(p) will by default cause the current program to abort. */ -void dlfree(void*); + void dlfree (void *); /* calloc(size_t n_elements, size_t element_size); Returns a pointer to n_elements * element_size bytes, with all locations set to zero. */ -void* dlcalloc(size_t, size_t); + void *dlcalloc (size_t, size_t); /* realloc(void* p, size_t n) @@ -757,7 +759,7 @@ void* dlcalloc(size_t, size_t); to be used as an argument to realloc is not supported. */ -void* dlrealloc(void*, size_t); + void *dlrealloc (void *, size_t); /* memalign(size_t alignment, size_t n); @@ -771,14 +773,14 @@ void* dlrealloc(void*, size_t); Overreliance on memalign is a sure way to fragment space. */ -void* dlmemalign(size_t, size_t); + void *dlmemalign (size_t, size_t); /* valloc(size_t n); Equivalent to memalign(pagesize, n), where pagesize is the page size of the system. If the pagesize is unknown, 4096 is used. */ -void* dlvalloc(size_t); + void *dlvalloc (size_t); /* mallopt(int parameter_number, int parameter_value) @@ -798,7 +800,7 @@ void* dlvalloc(size_t); M_GRANULARITY -2 page size any power of 2 >= page size M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support) */ -int dlmallopt(int, int); + int dlmallopt (int, int); /* malloc_footprint(); @@ -809,7 +811,7 @@ int dlmallopt(int, int); Even if locks are otherwise defined, this function does not use them, so results might not be up to date. */ -size_t dlmalloc_footprint(void); + size_t dlmalloc_footprint (void); /* malloc_max_footprint(); @@ -822,7 +824,7 @@ size_t dlmalloc_footprint(void); otherwise defined, this function does not use them, so results might not be up to date. */ -size_t dlmalloc_max_footprint(void); + size_t dlmalloc_max_footprint (void); #if !NO_MALLINFO /* @@ -847,8 +849,8 @@ size_t dlmalloc_max_footprint(void); be kept as longs, the reported values may wrap around zero and thus be inaccurate. */ -struct mallinfo dlmallinfo(void); -#endif /* NO_MALLINFO */ + struct mallinfo dlmallinfo (void); +#endif /* NO_MALLINFO */ /* independent_calloc(size_t n_elements, size_t element_size, void* chunks[]); @@ -902,7 +904,7 @@ struct mallinfo dlmallinfo(void); return first; } */ -void** dlindependent_calloc(size_t, size_t, void**); + void **dlindependent_calloc (size_t, size_t, void **); /* independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]); @@ -963,7 +965,7 @@ void** dlindependent_calloc(size_t, size_t, void**); since it cannot reuse existing noncontiguous small chunks that might be available for some of the elements. */ -void** dlindependent_comalloc(size_t, size_t*, void**); + void **dlindependent_comalloc (size_t, size_t *, void **); /* @@ -971,7 +973,7 @@ void** dlindependent_comalloc(size_t, size_t*, void**); Equivalent to valloc(minimum-page-that-holds(n)), that is, round up n to nearest pagesize. */ -void* dlpvalloc(size_t); + void *dlpvalloc (size_t); /* malloc_trim(size_t pad); @@ -994,7 +996,7 @@ void* dlpvalloc(size_t); Malloc_trim returns 1 if it actually released any memory, else 0. */ -int dlmalloc_trim(size_t); + int dlmalloc_trim (size_t); /* malloc_usable_size(void* p); @@ -1010,7 +1012,7 @@ int dlmalloc_trim(size_t); p = malloc(n); assert(malloc_usable_size(p) >= 256); */ -size_t dlmalloc_usable_size(void*); + size_t dlmalloc_usable_size (void *); /* malloc_stats(); @@ -1031,9 +1033,9 @@ size_t dlmalloc_usable_size(void*); malloc_stats prints only the most commonly interesting statistics. More information can be obtained by calling mallinfo. */ -void dlmalloc_stats(void); + void dlmalloc_stats (void); -#endif /* ONLY_MSPACES */ +#endif /* ONLY_MSPACES */ #if MSPACES @@ -1041,7 +1043,7 @@ void dlmalloc_stats(void); mspace is an opaque type representing an independent region of space that supports mspace_malloc, etc. */ -typedef void* mspace; + typedef void *mspace; /* create_mspace creates and returns a new independent space with the @@ -1054,7 +1056,7 @@ typedef void* mspace; compiling with a different DEFAULT_GRANULARITY or dynamically setting with mallopt(M_GRANULARITY, value). */ -mspace create_mspace(size_t capacity, int locked); + mspace create_mspace (size_t capacity, int locked); /* destroy_mspace destroys the given space, and attempts to return all @@ -1062,7 +1064,7 @@ mspace create_mspace(size_t capacity, int locked); bytes freed. After destruction, the results of access to all memory used by the space become undefined. */ -size_t destroy_mspace(mspace msp); + size_t destroy_mspace (mspace msp); /* create_mspace_with_base uses the memory supplied as the initial base @@ -1073,13 +1075,13 @@ size_t destroy_mspace(mspace msp); Destroying this space will deallocate all additionally allocated space (if possible) but not the initial base. */ -mspace create_mspace_with_base(void* base, size_t capacity, int locked); + mspace create_mspace_with_base (void *base, size_t capacity, int locked); /* mspace_malloc behaves as malloc, but operates within the given space. */ -void* mspace_malloc(mspace msp, size_t bytes); + void *mspace_malloc (mspace msp, size_t bytes); /* mspace_free behaves as free, but operates within @@ -1089,7 +1091,7 @@ void* mspace_malloc(mspace msp, size_t bytes); free may be called instead of mspace_free because freed chunks from any space are handled by their originating spaces. */ -void mspace_free(mspace msp, void* mem); + void mspace_free (mspace msp, void *mem); /* mspace_realloc behaves as realloc, but operates within @@ -1100,45 +1102,45 @@ void mspace_free(mspace msp, void* mem); realloced chunks from any space are handled by their originating spaces. */ -void* mspace_realloc(mspace msp, void* mem, size_t newsize); + void *mspace_realloc (mspace msp, void *mem, size_t newsize); /* mspace_calloc behaves as calloc, but operates within the given space. */ -void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size); + void *mspace_calloc (mspace msp, size_t n_elements, size_t elem_size); /* mspace_memalign behaves as memalign, but operates within the given space. */ -void* mspace_memalign(mspace msp, size_t alignment, size_t bytes); + void *mspace_memalign (mspace msp, size_t alignment, size_t bytes); /* mspace_independent_calloc behaves as independent_calloc, but operates within the given space. */ -void** mspace_independent_calloc(mspace msp, size_t n_elements, - size_t elem_size, void* chunks[]); + void **mspace_independent_calloc (mspace msp, size_t n_elements, + size_t elem_size, void *chunks[]); /* mspace_independent_comalloc behaves as independent_comalloc, but operates within the given space. */ -void** mspace_independent_comalloc(mspace msp, size_t n_elements, - size_t sizes[], void* chunks[]); + void **mspace_independent_comalloc (mspace msp, size_t n_elements, + size_t sizes[], void *chunks[]); /* mspace_footprint() returns the number of bytes obtained from the system for this space. */ -size_t mspace_footprint(mspace msp); + size_t mspace_footprint (mspace msp); /* mspace_max_footprint() returns the peak number of bytes obtained from the system for this space. */ -size_t mspace_max_footprint(mspace msp); + size_t mspace_max_footprint (mspace msp); #if !NO_MALLINFO @@ -1146,30 +1148,30 @@ size_t mspace_max_footprint(mspace msp); mspace_mallinfo behaves as mallinfo, but reports properties of the given space. */ -struct mallinfo mspace_mallinfo(mspace msp); -#endif /* NO_MALLINFO */ + struct mallinfo mspace_mallinfo (mspace msp); +#endif /* NO_MALLINFO */ /* mspace_malloc_stats behaves as malloc_stats, but reports properties of the given space. */ -void mspace_malloc_stats(mspace msp); + void mspace_malloc_stats (mspace msp); /* mspace_trim behaves as malloc_trim, but operates within the given space. */ -int mspace_trim(mspace msp, size_t pad); + int mspace_trim (mspace msp, size_t pad); /* An alias for mallopt. */ -int mspace_mallopt(int, int); + int mspace_mallopt (int, int); -#endif /* MSPACES */ +#endif /* MSPACES */ #ifdef __cplusplus -}; /* end of extern "C" */ +}; /* end of extern "C" */ #endif /* __cplusplus */ /* @@ -1185,21 +1187,21 @@ int mspace_mallopt(int, int); /*------------------------------ internal #includes ---------------------- */ #ifdef _MSC_VER -#pragma warning( disable : 4146 ) /* no "unsigned" warnings */ +#pragma warning( disable : 4146 ) /* no "unsigned" warnings */ #endif /* _MSC_VER */ #ifndef LACKS_STDIO_H -#include /* for printing in malloc_stats */ +#include /* for printing in malloc_stats */ #endif #ifndef LACKS_ERRNO_H -#include /* for MALLOC_FAILURE_ACTION */ +#include /* for MALLOC_FAILURE_ACTION */ #endif /* LACKS_ERRNO_H */ #if FOOTERS -#include /* for magic initialization */ +#include /* for magic initialization */ #endif /* FOOTERS */ #ifndef LACKS_STDLIB_H -#include /* for abort() */ +#include /* for abort() */ #endif /* LACKS_STDLIB_H */ #ifdef DEBUG #if ABORT_ON_ASSERT_FAILURE @@ -1207,20 +1209,20 @@ int mspace_mallopt(int, int); #else /* ABORT_ON_ASSERT_FAILURE */ #include #endif /* ABORT_ON_ASSERT_FAILURE */ -#else /* DEBUG */ +#else /* DEBUG */ #define assert(x) #endif /* DEBUG */ #ifndef LACKS_STRING_H -#include /* for memset etc */ -#endif /* LACKS_STRING_H */ +#include /* for memset etc */ +#endif /* LACKS_STRING_H */ #if USE_BUILTIN_FFS #ifndef LACKS_STRINGS_H -#include /* for ffs */ +#include /* for ffs */ #endif /* LACKS_STRINGS_H */ #endif /* USE_BUILTIN_FFS */ #if HAVE_MMAP #ifndef LACKS_SYS_MMAN_H -#include /* for mmap */ +#include /* for mmap */ #endif /* LACKS_SYS_MMAN_H */ #ifndef LACKS_FCNTL_H #include @@ -1228,17 +1230,17 @@ int mspace_mallopt(int, int); #endif /* HAVE_MMAP */ #if HAVE_MORECORE #ifndef LACKS_UNISTD_H -#include /* for sbrk */ +#include /* for sbrk */ #else /* LACKS_UNISTD_H */ #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) -extern void* sbrk(ptrdiff_t); +extern void *sbrk (ptrdiff_t); #endif /* FreeBSD etc */ #endif /* LACKS_UNISTD_H */ #endif /* HAVE_MMAP */ #ifndef WIN32 #ifndef malloc_getpagesize -# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ +# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ # ifndef _SC_PAGE_SIZE # define _SC_PAGE_SIZE _SC_PAGESIZE # endif @@ -1247,10 +1249,10 @@ extern void* sbrk(ptrdiff_t); # define malloc_getpagesize sysconf(_SC_PAGE_SIZE) # else # if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) - extern size_t getpagesize(); +extern size_t getpagesize (); # define malloc_getpagesize getpagesize() # else -# ifdef WIN32 /* use supplied emulation of getpagesize */ +# ifdef WIN32 /* use supplied emulation of getpagesize */ # define malloc_getpagesize getpagesize() # else # ifndef LACKS_SYS_PARAM_H @@ -1321,7 +1323,7 @@ extern void* sbrk(ptrdiff_t); /* MORECORE and MMAP must return MFAIL on failure */ #define MFAIL ((void*)(MAX_SIZE_T)) -#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */ +#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */ #if !HAVE_MMAP #define IS_MMAPPED_BIT (SIZE_T_ZERO) @@ -1349,7 +1351,7 @@ extern void* sbrk(ptrdiff_t); is unlikely to be needed, but is supplied just in case. */ #define MMAP_FLAGS (MAP_PRIVATE) -static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ +static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ #define CALL_MMAP(s) ((dev_zero_fd < 0) ? \ (dev_zero_fd = open("/dev/zero", O_RDWR), \ mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \ @@ -1360,34 +1362,42 @@ static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ #else /* WIN32 */ /* Win32 MMAP via VirtualAlloc */ -static void* win32mmap(size_t size) { - void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); - return (ptr != 0)? ptr: MFAIL; +static void * +win32mmap (size_t size) +{ + void *ptr = + VirtualAlloc (0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + return (ptr != 0) ? ptr : MFAIL; } /* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ -static void* win32direct_mmap(size_t size) { - void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, - PAGE_READWRITE); - return (ptr != 0)? ptr: MFAIL; +static void * +win32direct_mmap (size_t size) +{ + void *ptr = + VirtualAlloc (0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, + PAGE_READWRITE); + return (ptr != 0) ? ptr : MFAIL; } /* This function supports releasing coalesed segments */ -static int win32munmap(void* ptr, size_t size) { - MEMORY_BASIC_INFORMATION minfo; - char* cptr = ptr; - while (size) { - if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) - return -1; - if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || - minfo.State != MEM_COMMIT || minfo.RegionSize > size) - return -1; - if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) - return -1; - cptr += minfo.RegionSize; - size -= minfo.RegionSize; - } - return 0; +static int +win32munmap (void *ptr, size_t size) +{ + MEMORY_BASIC_INFORMATION minfo; + char *cptr = ptr; + while (size) { + if (VirtualQuery (cptr, &minfo, sizeof (minfo)) == 0) + return -1; + if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || + minfo.State != MEM_COMMIT || minfo.RegionSize > size) + return -1; + if (VirtualFree (cptr, 0, MEM_RELEASE) == 0) + return -1; + cptr += minfo.RegionSize; + size -= minfo.RegionSize; + } + return 0; } #define CALL_MMAP(s) win32mmap(s) @@ -1398,13 +1408,13 @@ static int win32munmap(void* ptr, size_t size) { #if HAVE_MMAP && HAVE_MREMAP #define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) -#else /* HAVE_MMAP && HAVE_MREMAP */ +#else /* HAVE_MMAP && HAVE_MREMAP */ #define CALL_MREMAP(addr, osz, nsz, mv) MFAIL #endif /* HAVE_MMAP && HAVE_MREMAP */ #if HAVE_MORECORE #define CALL_MORECORE(S) MORECORE(S) -#else /* HAVE_MORECORE */ +#else /* HAVE_MORECORE */ #define CALL_MORECORE(S) MFAIL #endif /* HAVE_MORECORE */ @@ -1454,21 +1464,26 @@ static MLOCK_T magic_init_mutex = PTHREAD_MUTEX_INITIALIZER; */ #define MLOCK_T long -static int win32_acquire_lock (MLOCK_T *sl) { - for (;;) { +static int +win32_acquire_lock (MLOCK_T * sl) +{ + for (;;) { #ifdef InterlockedCompareExchangePointer - if (!InterlockedCompareExchange(sl, 1, 0)) - return 0; -#else /* Use older void* version */ - if (!InterlockedCompareExchange((void**)sl, (void*)1, (void*)0)) - return 0; + if (!InterlockedCompareExchange (sl, 1, 0)) + return 0; +#else /* Use older void* version */ + if (!InterlockedCompareExchange + ((void **) sl, (void *) 1, (void *) 0)) + return 0; #endif /* InterlockedCompareExchangePointer */ - Sleep (0); - } + Sleep (0); + } } -static void win32_release_lock (MLOCK_T *sl) { - InterlockedExchange (sl, 0); +static void +win32_release_lock (MLOCK_T * sl) +{ + InterlockedExchange (sl, 0); } #define INITIAL_LOCK(l) *(l)=0 @@ -1481,7 +1496,7 @@ static MLOCK_T magic_init_mutex; #endif /* WIN32 */ #define USE_LOCK_BIT (2U) -#else /* USE_LOCKS */ +#else /* USE_LOCKS */ #define USE_LOCK_BIT (0U) #define INITIAL_LOCK(l) #endif /* USE_LOCKS */ @@ -1497,7 +1512,7 @@ static MLOCK_T magic_init_mutex; #if USE_LOCKS #define ACQUIRE_MAGIC_INIT_LOCK() ACQUIRE_LOCK(&magic_init_mutex); #define RELEASE_MAGIC_INIT_LOCK() RELEASE_LOCK(&magic_init_mutex); -#else /* USE_LOCKS */ +#else /* USE_LOCKS */ #define ACQUIRE_MAGIC_INIT_LOCK() #define RELEASE_MAGIC_INIT_LOCK() #endif /* USE_LOCKS */ @@ -1640,19 +1655,20 @@ static MLOCK_T magic_init_mutex; */ -struct malloc_chunk { - size_t prev_foot; /* Size of previous chunk (if free). */ - size_t head; /* Size and inuse bits. */ - struct malloc_chunk* fd; /* double links -- used only if free. */ - struct malloc_chunk* bk; +struct malloc_chunk +{ + size_t prev_foot; /* Size of previous chunk (if free). */ + size_t head; /* Size and inuse bits. */ + struct malloc_chunk *fd; /* double links -- used only if free. */ + struct malloc_chunk *bk; }; -typedef struct malloc_chunk mchunk; -typedef struct malloc_chunk* mchunkptr; -typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */ -typedef size_t bindex_t; /* Described below */ -typedef unsigned int binmap_t; /* Described below */ -typedef unsigned int flag_t; /* The type of various bit flag sets */ +typedef struct malloc_chunk mchunk; +typedef struct malloc_chunk *mchunkptr; +typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */ +typedef size_t bindex_t; /* Described below */ +typedef unsigned int binmap_t; /* Described below */ +typedef unsigned int flag_t; /* The type of various bit flag sets */ /* ------------------- Chunks sizes and alignments ----------------------- */ @@ -1845,21 +1861,22 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ is of course much better. */ -struct malloc_tree_chunk { - /* The first four fields must be compatible with malloc_chunk */ - size_t prev_foot; - size_t head; - struct malloc_tree_chunk* fd; - struct malloc_tree_chunk* bk; - - struct malloc_tree_chunk* child[2]; - struct malloc_tree_chunk* parent; - bindex_t index; +struct malloc_tree_chunk +{ + /* The first four fields must be compatible with malloc_chunk */ + size_t prev_foot; + size_t head; + struct malloc_tree_chunk *fd; + struct malloc_tree_chunk *bk; + + struct malloc_tree_chunk *child[2]; + struct malloc_tree_chunk *parent; + bindex_t index; }; -typedef struct malloc_tree_chunk tchunk; -typedef struct malloc_tree_chunk* tchunkptr; -typedef struct malloc_tree_chunk* tbinptr; /* The type of bins of trees */ +typedef struct malloc_tree_chunk tchunk; +typedef struct malloc_tree_chunk *tchunkptr; +typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */ /* A little helper macro for trees */ #define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) @@ -1921,18 +1938,19 @@ typedef struct malloc_tree_chunk* tbinptr; /* The type of bins of trees */ and deallocated/trimmed using MORECORE with negative arguments. */ -struct malloc_segment { - char* base; /* base address */ - size_t size; /* allocated size */ - struct malloc_segment* next; /* ptr to next segment */ - flag_t sflags; /* mmap and extern flag */ +struct malloc_segment +{ + char *base; /* base address */ + size_t size; /* allocated size */ + struct malloc_segment *next; /* ptr to next segment */ + flag_t sflags; /* mmap and extern flag */ }; #define is_mmapped_segment(S) ((S)->sflags & IS_MMAPPED_BIT) #define is_extern_segment(S) ((S)->sflags & EXTERN_BIT) -typedef struct malloc_segment msegment; -typedef struct malloc_segment* msegmentptr; +typedef struct malloc_segment msegment; +typedef struct malloc_segment *msegmentptr; /* ---------------------------- malloc_state ----------------------------- */ @@ -2019,28 +2037,29 @@ typedef struct malloc_segment* msegmentptr; #define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) #define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) -struct malloc_state { - binmap_t smallmap; - binmap_t treemap; - size_t dvsize; - size_t topsize; - char* least_addr; - mchunkptr dv; - mchunkptr top; - size_t trim_check; - size_t magic; - mchunkptr smallbins[(NSMALLBINS+1)*2]; - tbinptr treebins[NTREEBINS]; - size_t footprint; - size_t max_footprint; - flag_t mflags; +struct malloc_state +{ + binmap_t smallmap; + binmap_t treemap; + size_t dvsize; + size_t topsize; + char *least_addr; + mchunkptr dv; + mchunkptr top; + size_t trim_check; + size_t magic; + mchunkptr smallbins[(NSMALLBINS + 1) * 2]; + tbinptr treebins[NTREEBINS]; + size_t footprint; + size_t max_footprint; + flag_t mflags; #if USE_LOCKS - MLOCK_T mutex; /* locate lock among fields that rarely change */ -#endif /* USE_LOCKS */ - msegment seg; + MLOCK_T mutex; /* locate lock among fields that rarely change */ +#endif /* USE_LOCKS */ + msegment seg; }; -typedef struct malloc_state* mstate; +typedef struct malloc_state *mstate; /* ------------- Global malloc_state and malloc_params ------------------- */ @@ -2050,13 +2069,14 @@ typedef struct malloc_state* mstate; initialized in init_mparams. */ -struct malloc_params { - size_t magic; - size_t page_size; - size_t granularity; - size_t mmap_threshold; - size_t trim_threshold; - flag_t default_mflags; +struct malloc_params +{ + size_t magic; + size_t page_size; + size_t granularity; + size_t mmap_threshold; + size_t trim_threshold; + flag_t default_mflags; }; static struct malloc_params mparams; @@ -2105,30 +2125,34 @@ static struct malloc_state _gm_; ((char*)(A) >= S->base && (char*)(A) < S->base + S->size) /* Return segment holding given address */ -static msegmentptr segment_holding(mstate m, char* addr) { - msegmentptr sp = &m->seg; - for (;;) { - if (addr >= sp->base && addr < sp->base + sp->size) - return sp; - if ((sp = sp->next) == 0) - return 0; - } +static msegmentptr +segment_holding (mstate m, char *addr) +{ + msegmentptr sp = &m->seg; + for (;;) { + if (addr >= sp->base && addr < sp->base + sp->size) + return sp; + if ((sp = sp->next) == 0) + return 0; + } } /* Return true if segment contains a segment link */ -static int has_segment_link(mstate m, msegmentptr ss) { - msegmentptr sp = &m->seg; - for (;;) { - if ((char*)sp >= ss->base && (char*)sp < ss->base + ss->size) - return 1; - if ((sp = sp->next) == 0) - return 0; - } +static int +has_segment_link (mstate m, msegmentptr ss) +{ + msegmentptr sp = &m->seg; + for (;;) { + if ((char *) sp >= ss->base && (char *) sp < ss->base + ss->size) + return 1; + if ((sp = sp->next) == 0) + return 0; + } } #ifndef MORECORE_CANNOT_TRIM #define should_trim(M,s) ((s) > (M)->trim_check) -#else /* MORECORE_CANNOT_TRIM */ +#else /* MORECORE_CANNOT_TRIM */ #define should_trim(M,s) (0) #endif /* MORECORE_CANNOT_TRIM */ @@ -2160,11 +2184,11 @@ static int has_segment_link(mstate m, msegmentptr ss) { #ifndef PREACTION #define PREACTION(M) (0) -#endif /* PREACTION */ +#endif /* PREACTION */ #ifndef POSTACTION #define POSTACTION(M) -#endif /* POSTACTION */ +#endif /* POSTACTION */ #endif /* USE_LOCKS */ @@ -2182,7 +2206,7 @@ static int has_segment_link(mstate m, msegmentptr ss) { int malloc_corruption_error_count; /* default corruption action */ -static void reset_on_error(mstate m); +static void reset_on_error (mstate m); #define CORRUPTION_ERROR_ACTION(m) reset_on_error(m) #define USAGE_ERROR_ACTION(m, p) @@ -2218,18 +2242,18 @@ static void reset_on_error(mstate m); #define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P) #define check_malloc_state(M) do_check_malloc_state(M) -static void do_check_any_chunk(mstate m, mchunkptr p); -static void do_check_top_chunk(mstate m, mchunkptr p); -static void do_check_mmapped_chunk(mstate m, mchunkptr p); -static void do_check_inuse_chunk(mstate m, mchunkptr p); -static void do_check_free_chunk(mstate m, mchunkptr p); -static void do_check_malloced_chunk(mstate m, void* mem, size_t s); -static void do_check_tree(mstate m, tchunkptr t); -static void do_check_treebin(mstate m, bindex_t i); -static void do_check_smallbin(mstate m, bindex_t i); -static void do_check_malloc_state(mstate m); -static int bin_find(mstate m, mchunkptr x); -static size_t traverse_and_check(mstate m); +static void do_check_any_chunk (mstate m, mchunkptr p); +static void do_check_top_chunk (mstate m, mchunkptr p); +static void do_check_mmapped_chunk (mstate m, mchunkptr p); +static void do_check_inuse_chunk (mstate m, mchunkptr p); +static void do_check_free_chunk (mstate m, mchunkptr p); +static void do_check_malloced_chunk (mstate m, void *mem, size_t s); +static void do_check_tree (mstate m, tchunkptr t); +static void do_check_treebin (mstate m, bindex_t i); +static void do_check_smallbin (mstate m, bindex_t i); +static void do_check_malloc_state (mstate m); +static int bin_find (mstate m, mchunkptr x); +static size_t traverse_and_check (mstate m); #endif /* DEBUG */ /* ---------------------------- Indexing Bins ---------------------------- */ @@ -2394,7 +2418,7 @@ static size_t traverse_and_check(mstate m); #if (FOOTERS && !INSECURE) /* Check if (alleged) mstate m has expected magic field */ #define ok_magic(M) ((M)->magic == mparams.magic) -#else /* (FOOTERS && !INSECURE) */ +#else /* (FOOTERS && !INSECURE) */ #define ok_magic(M) (1) #endif /* (FOOTERS && !INSECURE) */ @@ -2459,446 +2483,478 @@ static size_t traverse_and_check(mstate m); /* ---------------------------- setting mparams -------------------------- */ /* Initialize mparams */ -static int init_mparams(void) { - if (mparams.page_size == 0) { - size_t s; - - mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; - mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; +static int +init_mparams (void) +{ + if (mparams.page_size == 0) { + size_t s; + + mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; + mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; #if MORECORE_CONTIGUOUS - mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT; -#else /* MORECORE_CONTIGUOUS */ - mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT|USE_NONCONTIGUOUS_BIT; + mparams.default_mflags = USE_LOCK_BIT | USE_MMAP_BIT; +#else /* MORECORE_CONTIGUOUS */ + mparams.default_mflags = + USE_LOCK_BIT | USE_MMAP_BIT | USE_NONCONTIGUOUS_BIT; #endif /* MORECORE_CONTIGUOUS */ #if (FOOTERS && !INSECURE) - { + { #if USE_DEV_RANDOM - int fd; - unsigned char buf[sizeof(size_t)]; - /* Try to use /dev/urandom, else fall back on using time */ - if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 && - read(fd, buf, sizeof(buf)) == sizeof(buf)) { - s = *((size_t *) buf); - close(fd); - } - else + int fd; + unsigned char buf[sizeof (size_t)]; + /* Try to use /dev/urandom, else fall back on using time */ + if ((fd = open ("/dev/urandom", O_RDONLY)) >= 0 && + read (fd, buf, sizeof (buf)) == sizeof (buf)) { + s = *((size_t *) buf); + close (fd); + } else #endif /* USE_DEV_RANDOM */ - s = (size_t)(time(0) ^ (size_t)0x55555555U); + s = (size_t) (time (0) ^ (size_t) 0x55555555U); - s |= (size_t)8U; /* ensure nonzero */ - s &= ~(size_t)7U; /* improve chances of fault for bad values */ + s |= (size_t) 8U; /* ensure nonzero */ + s &= ~(size_t) 7U; /* improve chances of fault for bad values */ - } + } #else /* (FOOTERS && !INSECURE) */ - s = (size_t)0x58585858U; + s = (size_t) 0x58585858U; #endif /* (FOOTERS && !INSECURE) */ - ACQUIRE_MAGIC_INIT_LOCK(); - if (mparams.magic == 0) { - mparams.magic = s; - /* Set up lock for main malloc area */ - INITIAL_LOCK(&gm->mutex); - gm->mflags = mparams.default_mflags; - } - RELEASE_MAGIC_INIT_LOCK(); + ACQUIRE_MAGIC_INIT_LOCK (); + if (mparams.magic == 0) { + mparams.magic = s; + /* Set up lock for main malloc area */ + INITIAL_LOCK (&gm->mutex); + gm->mflags = mparams.default_mflags; + } + RELEASE_MAGIC_INIT_LOCK (); #ifndef WIN32 - mparams.page_size = malloc_getpagesize; - mparams.granularity = ((DEFAULT_GRANULARITY != 0)? - DEFAULT_GRANULARITY : mparams.page_size); + mparams.page_size = malloc_getpagesize; + mparams.granularity = ((DEFAULT_GRANULARITY != 0) ? + DEFAULT_GRANULARITY : mparams.page_size); #else /* WIN32 */ - { - SYSTEM_INFO system_info; - GetSystemInfo(&system_info); - mparams.page_size = system_info.dwPageSize; - mparams.granularity = system_info.dwAllocationGranularity; - } + { + SYSTEM_INFO system_info; + GetSystemInfo (&system_info); + mparams.page_size = system_info.dwPageSize; + mparams.granularity = system_info.dwAllocationGranularity; + } #endif /* WIN32 */ - /* Sanity-check configuration: - size_t must be unsigned and as wide as pointer type. - ints must be at least 4 bytes. - alignment must be at least 8. - Alignment, min chunk size, and page size must all be powers of 2. - */ - if ((sizeof(size_t) != sizeof(char*)) || - (MAX_SIZE_T < MIN_CHUNK_SIZE) || - (sizeof(int) < 4) || - (MALLOC_ALIGNMENT < (size_t)8U) || - ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT-SIZE_T_ONE)) != 0) || - ((MCHUNK_SIZE & (MCHUNK_SIZE-SIZE_T_ONE)) != 0) || - ((mparams.granularity & (mparams.granularity-SIZE_T_ONE)) != 0) || - ((mparams.page_size & (mparams.page_size-SIZE_T_ONE)) != 0)) - ABORT; - } - return 0; + /* Sanity-check configuration: + size_t must be unsigned and as wide as pointer type. + ints must be at least 4 bytes. + alignment must be at least 8. + Alignment, min chunk size, and page size must all be powers of 2. + */ + if ((sizeof (size_t) != sizeof (char *)) || + (MAX_SIZE_T < MIN_CHUNK_SIZE) || + (sizeof (int) < 4) || + (MALLOC_ALIGNMENT < (size_t) 8U) || + ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT - SIZE_T_ONE)) != 0) || + ((MCHUNK_SIZE & (MCHUNK_SIZE - SIZE_T_ONE)) != 0) || + ((mparams.granularity & (mparams.granularity - SIZE_T_ONE)) != 0) + || ((mparams.page_size & (mparams.page_size - SIZE_T_ONE)) != 0)) + ABORT; + } + return 0; } /* support for mallopt */ -static int change_mparam(int param_number, int value) { - size_t val = (size_t)value; - init_mparams(); - switch(param_number) { - case M_TRIM_THRESHOLD: - mparams.trim_threshold = val; - return 1; - case M_GRANULARITY: - if (val >= mparams.page_size && ((val & (val-1)) == 0)) { - mparams.granularity = val; - return 1; +static int +change_mparam (int param_number, int value) +{ + size_t val = (size_t) value; + init_mparams (); + switch (param_number) { + case M_TRIM_THRESHOLD: + mparams.trim_threshold = val; + return 1; + case M_GRANULARITY: + if (val >= mparams.page_size && ((val & (val - 1)) == 0)) { + mparams.granularity = val; + return 1; + } else + return 0; + case M_MMAP_THRESHOLD: + mparams.mmap_threshold = val; + return 1; + default: + return 0; } - else - return 0; - case M_MMAP_THRESHOLD: - mparams.mmap_threshold = val; - return 1; - default: - return 0; - } } #if DEBUG /* ------------------------- Debugging Support --------------------------- */ /* Check properties of any chunk, whether free, inuse, mmapped etc */ -static void do_check_any_chunk(mstate m, mchunkptr p) { - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); +static void +do_check_any_chunk (mstate m, mchunkptr p) +{ + assert ((is_aligned (chunk2mem (p))) || (p->head == FENCEPOST_HEAD)); + assert (ok_address (m, p)); } /* Check properties of top chunk */ -static void do_check_top_chunk(mstate m, mchunkptr p) { - msegmentptr sp = segment_holding(m, (char*)p); - size_t sz = chunksize(p); - assert(sp != 0); - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); - assert(sz == m->topsize); - assert(sz > 0); - assert(sz == ((sp->base + sp->size) - (char*)p) - TOP_FOOT_SIZE); - assert(pinuse(p)); - assert(!next_pinuse(p)); +static void +do_check_top_chunk (mstate m, mchunkptr p) +{ + msegmentptr sp = segment_holding (m, (char *) p); + size_t sz = chunksize (p); + assert (sp != 0); + assert ((is_aligned (chunk2mem (p))) || (p->head == FENCEPOST_HEAD)); + assert (ok_address (m, p)); + assert (sz == m->topsize); + assert (sz > 0); + assert (sz == ((sp->base + sp->size) - (char *) p) - TOP_FOOT_SIZE); + assert (pinuse (p)); + assert (!next_pinuse (p)); } /* Check properties of (inuse) mmapped chunks */ -static void do_check_mmapped_chunk(mstate m, mchunkptr p) { - size_t sz = chunksize(p); - size_t len = (sz + (p->prev_foot & ~IS_MMAPPED_BIT) + MMAP_FOOT_PAD); - assert(is_mmapped(p)); - assert(use_mmap(m)); - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); - assert(!is_small(sz)); - assert((len & (mparams.page_size-SIZE_T_ONE)) == 0); - assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD); - assert(chunk_plus_offset(p, sz+SIZE_T_SIZE)->head == 0); +static void +do_check_mmapped_chunk (mstate m, mchunkptr p) +{ + size_t sz = chunksize (p); + size_t len = (sz + (p->prev_foot & ~IS_MMAPPED_BIT) + MMAP_FOOT_PAD); + assert (is_mmapped (p)); + assert (use_mmap (m)); + assert ((is_aligned (chunk2mem (p))) || (p->head == FENCEPOST_HEAD)); + assert (ok_address (m, p)); + assert (!is_small (sz)); + assert ((len & (mparams.page_size - SIZE_T_ONE)) == 0); + assert (chunk_plus_offset (p, sz)->head == FENCEPOST_HEAD); + assert (chunk_plus_offset (p, sz + SIZE_T_SIZE)->head == 0); } /* Check properties of inuse chunks */ -static void do_check_inuse_chunk(mstate m, mchunkptr p) { - do_check_any_chunk(m, p); - assert(cinuse(p)); - assert(next_pinuse(p)); - /* If not pinuse and not mmapped, previous chunk has OK offset */ - assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p); - if (is_mmapped(p)) - do_check_mmapped_chunk(m, p); +static void +do_check_inuse_chunk (mstate m, mchunkptr p) +{ + do_check_any_chunk (m, p); + assert (cinuse (p)); + assert (next_pinuse (p)); + /* If not pinuse and not mmapped, previous chunk has OK offset */ + assert (is_mmapped (p) || pinuse (p) || next_chunk (prev_chunk (p)) == p); + if (is_mmapped (p)) + do_check_mmapped_chunk (m, p); } /* Check properties of free chunks */ -static void do_check_free_chunk(mstate m, mchunkptr p) { - size_t sz = p->head & ~(PINUSE_BIT|CINUSE_BIT); - mchunkptr next = chunk_plus_offset(p, sz); - do_check_any_chunk(m, p); - assert(!cinuse(p)); - assert(!next_pinuse(p)); - assert (!is_mmapped(p)); - if (p != m->dv && p != m->top) { - if (sz >= MIN_CHUNK_SIZE) { - assert((sz & CHUNK_ALIGN_MASK) == 0); - assert(is_aligned(chunk2mem(p))); - assert(next->prev_foot == sz); - assert(pinuse(p)); - assert (next == m->top || cinuse(next)); - assert(p->fd->bk == p); - assert(p->bk->fd == p); +static void +do_check_free_chunk (mstate m, mchunkptr p) +{ + size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT); + mchunkptr next = chunk_plus_offset (p, sz); + do_check_any_chunk (m, p); + assert (!cinuse (p)); + assert (!next_pinuse (p)); + assert (!is_mmapped (p)); + if (p != m->dv && p != m->top) { + if (sz >= MIN_CHUNK_SIZE) { + assert ((sz & CHUNK_ALIGN_MASK) == 0); + assert (is_aligned (chunk2mem (p))); + assert (next->prev_foot == sz); + assert (pinuse (p)); + assert (next == m->top || cinuse (next)); + assert (p->fd->bk == p); + assert (p->bk->fd == p); + } else /* markers are always of size SIZE_T_SIZE */ + assert (sz == SIZE_T_SIZE); } - else /* markers are always of size SIZE_T_SIZE */ - assert(sz == SIZE_T_SIZE); - } } /* Check properties of malloced chunks at the point they are malloced */ -static void do_check_malloced_chunk(mstate m, void* mem, size_t s) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - size_t sz = p->head & ~(PINUSE_BIT|CINUSE_BIT); - do_check_inuse_chunk(m, p); - assert((sz & CHUNK_ALIGN_MASK) == 0); - assert(sz >= MIN_CHUNK_SIZE); - assert(sz >= s); - /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */ - assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE)); - } +static void +do_check_malloced_chunk (mstate m, void *mem, size_t s) +{ + if (mem != 0) { + mchunkptr p = mem2chunk (mem); + size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT); + do_check_inuse_chunk (m, p); + assert ((sz & CHUNK_ALIGN_MASK) == 0); + assert (sz >= MIN_CHUNK_SIZE); + assert (sz >= s); + /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */ + assert (is_mmapped (p) || sz < (s + MIN_CHUNK_SIZE)); + } } /* Check a tree and its subtrees. */ -static void do_check_tree(mstate m, tchunkptr t) { - tchunkptr head = 0; - tchunkptr u = t; - bindex_t tindex = t->index; - size_t tsize = chunksize(t); - bindex_t idx; - compute_tree_index(tsize, idx); - assert(tindex == idx); - assert(tsize >= MIN_LARGE_SIZE); - assert(tsize >= minsize_for_tree_index(idx)); - assert((idx == NTREEBINS-1) || (tsize < minsize_for_tree_index((idx+1)))); - - do { /* traverse through chain of same-sized nodes */ - do_check_any_chunk(m, ((mchunkptr)u)); - assert(u->index == tindex); - assert(chunksize(u) == tsize); - assert(!cinuse(u)); - assert(!next_pinuse(u)); - assert(u->fd->bk == u); - assert(u->bk->fd == u); - if (u->parent == 0) { - assert(u->child[0] == 0); - assert(u->child[1] == 0); - } - else { - assert(head == 0); /* only one node on chain has parent */ - head = u; - assert(u->parent != u); - assert (u->parent->child[0] == u || - u->parent->child[1] == u || - *((tbinptr*)(u->parent)) == u); - if (u->child[0] != 0) { - assert(u->child[0]->parent == u); - assert(u->child[0] != u); - do_check_tree(m, u->child[0]); - } - if (u->child[1] != 0) { - assert(u->child[1]->parent == u); - assert(u->child[1] != u); - do_check_tree(m, u->child[1]); - } - if (u->child[0] != 0 && u->child[1] != 0) { - assert(chunksize(u->child[0]) < chunksize(u->child[1])); - } +static void +do_check_tree (mstate m, tchunkptr t) +{ + tchunkptr head = 0; + tchunkptr u = t; + bindex_t tindex = t->index; + size_t tsize = chunksize (t); + bindex_t idx; + compute_tree_index (tsize, idx); + assert (tindex == idx); + assert (tsize >= MIN_LARGE_SIZE); + assert (tsize >= minsize_for_tree_index (idx)); + assert ((idx == NTREEBINS - 1) + || (tsize < minsize_for_tree_index ((idx + 1)))); + + do { /* traverse through chain of same-sized nodes */ + do_check_any_chunk (m, ((mchunkptr) u)); + assert (u->index == tindex); + assert (chunksize (u) == tsize); + assert (!cinuse (u)); + assert (!next_pinuse (u)); + assert (u->fd->bk == u); + assert (u->bk->fd == u); + if (u->parent == 0) { + assert (u->child[0] == 0); + assert (u->child[1] == 0); + } else { + assert (head == 0); /* only one node on chain has parent */ + head = u; + assert (u->parent != u); + assert (u->parent->child[0] == u || + u->parent->child[1] == u || + *((tbinptr *) (u->parent)) == u); + if (u->child[0] != 0) { + assert (u->child[0]->parent == u); + assert (u->child[0] != u); + do_check_tree (m, u->child[0]); + } + if (u->child[1] != 0) { + assert (u->child[1]->parent == u); + assert (u->child[1] != u); + do_check_tree (m, u->child[1]); + } + if (u->child[0] != 0 && u->child[1] != 0) { + assert (chunksize (u->child[0]) < chunksize (u->child[1])); + } + } + u = u->fd; } - u = u->fd; - } while (u != t); - assert(head != 0); + while (u != t); + assert (head != 0); } /* Check all the chunks in a treebin. */ -static void do_check_treebin(mstate m, bindex_t i) { - tbinptr* tb = treebin_at(m, i); - tchunkptr t = *tb; - int empty = (m->treemap & (1U << i)) == 0; - if (t == 0) - assert(empty); - if (!empty) - do_check_tree(m, t); +static void +do_check_treebin (mstate m, bindex_t i) +{ + tbinptr *tb = treebin_at (m, i); + tchunkptr t = *tb; + int empty = (m->treemap & (1U << i)) == 0; + if (t == 0) + assert (empty); + if (!empty) + do_check_tree (m, t); } /* Check all the chunks in a smallbin. */ -static void do_check_smallbin(mstate m, bindex_t i) { - sbinptr b = smallbin_at(m, i); - mchunkptr p = b->bk; - unsigned int empty = (m->smallmap & (1U << i)) == 0; - if (p == b) - assert(empty); - if (!empty) { - for (; p != b; p = p->bk) { - size_t size = chunksize(p); - mchunkptr q; - /* each chunk claims to be free */ - do_check_free_chunk(m, p); - /* chunk belongs in bin */ - assert(small_index(size) == i); - assert(p->bk == b || chunksize(p->bk) == chunksize(p)); - /* chunk is followed by an inuse chunk */ - q = next_chunk(p); - if (q->head != FENCEPOST_HEAD) - do_check_inuse_chunk(m, q); +static void +do_check_smallbin (mstate m, bindex_t i) +{ + sbinptr b = smallbin_at (m, i); + mchunkptr p = b->bk; + unsigned int empty = (m->smallmap & (1U << i)) == 0; + if (p == b) + assert (empty); + if (!empty) { + for (; p != b; p = p->bk) { + size_t size = chunksize (p); + mchunkptr q; + /* each chunk claims to be free */ + do_check_free_chunk (m, p); + /* chunk belongs in bin */ + assert (small_index (size) == i); + assert (p->bk == b || chunksize (p->bk) == chunksize (p)); + /* chunk is followed by an inuse chunk */ + q = next_chunk (p); + if (q->head != FENCEPOST_HEAD) + do_check_inuse_chunk (m, q); + } } - } } /* Find x in a bin. Used in other check functions. */ -static int bin_find(mstate m, mchunkptr x) { - size_t size = chunksize(x); - if (is_small(size)) { - bindex_t sidx = small_index(size); - sbinptr b = smallbin_at(m, sidx); - if (smallmap_is_marked(m, sidx)) { - mchunkptr p = b; - do { - if (p == x) - return 1; - } while ((p = p->fd) != b); - } - } - else { - bindex_t tidx; - compute_tree_index(size, tidx); - if (treemap_is_marked(m, tidx)) { - tchunkptr t = *treebin_at(m, tidx); - size_t sizebits = size << leftshift_for_tree_index(tidx); - while (t != 0 && chunksize(t) != size) { - t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; - sizebits <<= 1; - } - if (t != 0) { - tchunkptr u = t; - do { - if (u == (tchunkptr)x) - return 1; - } while ((u = u->fd) != t); - } +static int +bin_find (mstate m, mchunkptr x) +{ + size_t size = chunksize (x); + if (is_small (size)) { + bindex_t sidx = small_index (size); + sbinptr b = smallbin_at (m, sidx); + if (smallmap_is_marked (m, sidx)) { + mchunkptr p = b; + do { + if (p == x) + return 1; + } + while ((p = p->fd) != b); + } + } else { + bindex_t tidx; + compute_tree_index (size, tidx); + if (treemap_is_marked (m, tidx)) { + tchunkptr t = *treebin_at (m, tidx); + size_t sizebits = size << leftshift_for_tree_index (tidx); + while (t != 0 && chunksize (t) != size) { + t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1]; + sizebits <<= 1; + } + if (t != 0) { + tchunkptr u = t; + do { + if (u == (tchunkptr) x) + return 1; + } + while ((u = u->fd) != t); + } + } } - } - return 0; + return 0; } /* Traverse each chunk and check it; return total */ -static size_t traverse_and_check(mstate m) { - size_t sum = 0; - if (is_initialized(m)) { - msegmentptr s = &m->seg; - sum += m->topsize + TOP_FOOT_SIZE; - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - mchunkptr lastq = 0; - assert(pinuse(q)); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - sum += chunksize(q); - if (cinuse(q)) { - assert(!bin_find(m, q)); - do_check_inuse_chunk(m, q); - } - else { - assert(q == m->dv || bin_find(m, q)); - assert(lastq == 0 || cinuse(lastq)); /* Not 2 consecutive free */ - do_check_free_chunk(m, q); +static size_t +traverse_and_check (mstate m) +{ + size_t sum = 0; + if (is_initialized (m)) { + msegmentptr s = &m->seg; + sum += m->topsize + TOP_FOOT_SIZE; + while (s != 0) { + mchunkptr q = align_as_chunk (s->base); + mchunkptr lastq = 0; + assert (pinuse (q)); + while (segment_holds (s, q) && + q != m->top && q->head != FENCEPOST_HEAD) { + sum += chunksize (q); + if (cinuse (q)) { + assert (!bin_find (m, q)); + do_check_inuse_chunk (m, q); + } else { + assert (q == m->dv || bin_find (m, q)); + assert (lastq == 0 || cinuse (lastq)); /* Not 2 consecutive free */ + do_check_free_chunk (m, q); + } + lastq = q; + q = next_chunk (q); + } + s = s->next; } - lastq = q; - q = next_chunk(q); - } - s = s->next; } - } - return sum; + return sum; } /* Check all properties of malloc_state. */ -static void do_check_malloc_state(mstate m) { - bindex_t i; - size_t total; - /* check bins */ - for (i = 0; i < NSMALLBINS; ++i) - do_check_smallbin(m, i); - for (i = 0; i < NTREEBINS; ++i) - do_check_treebin(m, i); - - if (m->dvsize != 0) { /* check dv chunk */ - do_check_any_chunk(m, m->dv); - assert(m->dvsize == chunksize(m->dv)); - assert(m->dvsize >= MIN_CHUNK_SIZE); - assert(bin_find(m, m->dv) == 0); - } +static void +do_check_malloc_state (mstate m) +{ + bindex_t i; + size_t total; + /* check bins */ + for (i = 0; i < NSMALLBINS; ++i) + do_check_smallbin (m, i); + for (i = 0; i < NTREEBINS; ++i) + do_check_treebin (m, i); + + if (m->dvsize != 0) { /* check dv chunk */ + do_check_any_chunk (m, m->dv); + assert (m->dvsize == chunksize (m->dv)); + assert (m->dvsize >= MIN_CHUNK_SIZE); + assert (bin_find (m, m->dv) == 0); + } - if (m->top != 0) { /* check top chunk */ - do_check_top_chunk(m, m->top); - assert(m->topsize == chunksize(m->top)); - assert(m->topsize > 0); - assert(bin_find(m, m->top) == 0); - } + if (m->top != 0) { /* check top chunk */ + do_check_top_chunk (m, m->top); + assert (m->topsize == chunksize (m->top)); + assert (m->topsize > 0); + assert (bin_find (m, m->top) == 0); + } - total = traverse_and_check(m); - assert(total <= m->footprint); - assert(m->footprint <= m->max_footprint); + total = traverse_and_check (m); + assert (total <= m->footprint); + assert (m->footprint <= m->max_footprint); } #endif /* DEBUG */ /* ----------------------------- statistics ------------------------------ */ #if !NO_MALLINFO -static struct mallinfo internal_mallinfo(mstate m) { - struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - if (!PREACTION(m)) { - check_malloc_state(m); - if (is_initialized(m)) { - size_t nfree = SIZE_T_ONE; /* top always free */ - size_t mfree = m->topsize + TOP_FOOT_SIZE; - size_t sum = mfree; - msegmentptr s = &m->seg; - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - size_t sz = chunksize(q); - sum += sz; - if (!cinuse(q)) { - mfree += sz; - ++nfree; - } - q = next_chunk(q); +static struct mallinfo +internal_mallinfo (mstate m) +{ + struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + if (!PREACTION (m)) { + check_malloc_state (m); + if (is_initialized (m)) { + size_t nfree = SIZE_T_ONE; /* top always free */ + size_t mfree = m->topsize + TOP_FOOT_SIZE; + size_t sum = mfree; + msegmentptr s = &m->seg; + while (s != 0) { + mchunkptr q = align_as_chunk (s->base); + while (segment_holds (s, q) && + q != m->top && q->head != FENCEPOST_HEAD) { + size_t sz = chunksize (q); + sum += sz; + if (!cinuse (q)) { + mfree += sz; + ++nfree; + } + q = next_chunk (q); + } + s = s->next; + } + + nm.arena = sum; + nm.ordblks = nfree; + nm.hblkhd = m->footprint - sum; + nm.usmblks = m->max_footprint; + nm.uordblks = m->footprint - mfree; + nm.fordblks = mfree; + nm.keepcost = m->topsize; } - s = s->next; - } - nm.arena = sum; - nm.ordblks = nfree; - nm.hblkhd = m->footprint - sum; - nm.usmblks = m->max_footprint; - nm.uordblks = m->footprint - mfree; - nm.fordblks = mfree; - nm.keepcost = m->topsize; + POSTACTION (m); } - - POSTACTION(m); - } - return nm; + return nm; } #endif /* !NO_MALLINFO */ -static void internal_malloc_stats(mstate m) { - if (!PREACTION(m)) { - size_t maxfp = 0; - size_t fp = 0; - size_t used = 0; - check_malloc_state(m); - if (is_initialized(m)) { - msegmentptr s = &m->seg; - maxfp = m->max_footprint; - fp = m->footprint; - used = fp - (m->topsize + TOP_FOOT_SIZE); - - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - if (!cinuse(q)) - used -= chunksize(q); - q = next_chunk(q); +static void +internal_malloc_stats (mstate m) +{ + if (!PREACTION (m)) { + size_t maxfp = 0; + size_t fp = 0; + size_t used = 0; + check_malloc_state (m); + if (is_initialized (m)) { + msegmentptr s = &m->seg; + maxfp = m->max_footprint; + fp = m->footprint; + used = fp - (m->topsize + TOP_FOOT_SIZE); + + while (s != 0) { + mchunkptr q = align_as_chunk (s->base); + while (segment_holds (s, q) && + q != m->top && q->head != FENCEPOST_HEAD) { + if (!cinuse (q)) + used -= chunksize (q); + q = next_chunk (q); + } + s = s->next; + } } - s = s->next; - } - } - #ifndef LACKS_STDIO_H - fprintf(stderr, "max system bytes = %10lu\n", (unsigned long)(maxfp)); - fprintf(stderr, "system bytes = %10lu\n", (unsigned long)(fp)); - fprintf(stderr, "in use bytes = %10lu\n", (unsigned long)(used)); + fprintf (stderr, "max system bytes = %10lu\n", + (unsigned long) (maxfp)); + fprintf (stderr, "system bytes = %10lu\n", (unsigned long) (fp)); + fprintf (stderr, "in use bytes = %10lu\n", + (unsigned long) (used)); #endif - POSTACTION(m); - } + POSTACTION (m); + } } /* ----------------------- Operations on smallbins ----------------------- */ @@ -3162,905 +3218,925 @@ static void internal_malloc_stats(mstate m) { */ /* Malloc using mmap */ -static void* mmap_alloc(mstate m, size_t nb) { - size_t mmsize = granularity_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); - if (mmsize > nb) { /* Check for wrap around 0 */ - char* mm = (char*)(DIRECT_MMAP(mmsize)); - if (mm != CMFAIL) { - size_t offset = align_offset(chunk2mem(mm)); - size_t psize = mmsize - offset - MMAP_FOOT_PAD; - mchunkptr p = (mchunkptr)(mm + offset); - p->prev_foot = offset | IS_MMAPPED_BIT; - (p)->head = (psize|CINUSE_BIT); - mark_inuse_foot(m, p, psize); - chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; - chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0; - - if (mm < m->least_addr) - m->least_addr = mm; - if ((m->footprint += mmsize) > m->max_footprint) - m->max_footprint = m->footprint; - assert(is_aligned(chunk2mem(p))); - check_mmapped_chunk(m, p); - return chunk2mem(p); +static void * +mmap_alloc (mstate m, size_t nb) +{ + size_t mmsize = + granularity_align (nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + if (mmsize > nb) { /* Check for wrap around 0 */ + char *mm = (char *) (DIRECT_MMAP (mmsize)); + if (mm != CMFAIL) { + size_t offset = align_offset (chunk2mem (mm)); + size_t psize = mmsize - offset - MMAP_FOOT_PAD; + mchunkptr p = (mchunkptr) (mm + offset); + p->prev_foot = offset | IS_MMAPPED_BIT; + (p)->head = (psize | CINUSE_BIT); + mark_inuse_foot (m, p, psize); + chunk_plus_offset (p, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset (p, psize + SIZE_T_SIZE)->head = 0; + + if (mm < m->least_addr) + m->least_addr = mm; + if ((m->footprint += mmsize) > m->max_footprint) + m->max_footprint = m->footprint; + assert (is_aligned (chunk2mem (p))); + check_mmapped_chunk (m, p); + return chunk2mem (p); + } } - } - return 0; + return 0; } /* Realloc using mmap */ -static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb) { - size_t oldsize = chunksize(oldp); - if (is_small(nb)) /* Can't shrink mmap regions below small size */ - return 0; - /* Keep old chunk if big enough but not too big */ - if (oldsize >= nb + SIZE_T_SIZE && - (oldsize - nb) <= (mparams.granularity << 1)) - return oldp; - else { - size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT; - size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD; - size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES + - CHUNK_ALIGN_MASK); - char* cp = (char*)CALL_MREMAP((char*)oldp - offset, - oldmmsize, newmmsize, 1); - if (cp != CMFAIL) { - mchunkptr newp = (mchunkptr)(cp + offset); - size_t psize = newmmsize - offset - MMAP_FOOT_PAD; - newp->head = (psize|CINUSE_BIT); - mark_inuse_foot(m, newp, psize); - chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; - chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0; - - if (cp < m->least_addr) - m->least_addr = cp; - if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint) - m->max_footprint = m->footprint; - check_mmapped_chunk(m, newp); - return newp; +static mchunkptr +mmap_resize (mstate m, mchunkptr oldp, size_t nb) +{ + size_t oldsize = chunksize (oldp); + if (is_small (nb)) /* Can't shrink mmap regions below small size */ + return 0; + /* Keep old chunk if big enough but not too big */ + if (oldsize >= nb + SIZE_T_SIZE && + (oldsize - nb) <= (mparams.granularity << 1)) + return oldp; + else { + size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT; + size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD; + size_t newmmsize = granularity_align (nb + SIX_SIZE_T_SIZES + + CHUNK_ALIGN_MASK); + char *cp = (char *) CALL_MREMAP ((char *) oldp - offset, + oldmmsize, newmmsize, 1); + if (cp != CMFAIL) { + mchunkptr newp = (mchunkptr) (cp + offset); + size_t psize = newmmsize - offset - MMAP_FOOT_PAD; + newp->head = (psize | CINUSE_BIT); + mark_inuse_foot (m, newp, psize); + chunk_plus_offset (newp, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset (newp, psize + SIZE_T_SIZE)->head = 0; + + if (cp < m->least_addr) + m->least_addr = cp; + if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint) + m->max_footprint = m->footprint; + check_mmapped_chunk (m, newp); + return newp; + } } - } - return 0; + return 0; } /* -------------------------- mspace management -------------------------- */ /* Initialize top chunk and its size */ -static void init_top(mstate m, mchunkptr p, size_t psize) { - /* Ensure alignment */ - size_t offset = align_offset(chunk2mem(p)); - p = (mchunkptr)((char*)p + offset); - psize -= offset; - - m->top = p; - m->topsize = psize; - p->head = psize | PINUSE_BIT; - /* set size of fake trailing chunk holding overhead space only once */ - chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; - m->trim_check = mparams.trim_threshold; /* reset on each update */ +static void +init_top (mstate m, mchunkptr p, size_t psize) +{ + /* Ensure alignment */ + size_t offset = align_offset (chunk2mem (p)); + p = (mchunkptr) ((char *) p + offset); + psize -= offset; + + m->top = p; + m->topsize = psize; + p->head = psize | PINUSE_BIT; + /* set size of fake trailing chunk holding overhead space only once */ + chunk_plus_offset (p, psize)->head = TOP_FOOT_SIZE; + m->trim_check = mparams.trim_threshold; /* reset on each update */ } /* Initialize bins for a new mstate that is otherwise zeroed out */ -static void init_bins(mstate m) { - /* Establish circular links for smallbins */ - bindex_t i; - for (i = 0; i < NSMALLBINS; ++i) { - sbinptr bin = smallbin_at(m,i); - bin->fd = bin->bk = bin; - } +static void +init_bins (mstate m) +{ + /* Establish circular links for smallbins */ + bindex_t i; + for (i = 0; i < NSMALLBINS; ++i) { + sbinptr bin = smallbin_at (m, i); + bin->fd = bin->bk = bin; + } } #if PROCEED_ON_ERROR /* default corruption action */ -static void reset_on_error(mstate m) { - int i; - ++malloc_corruption_error_count; - /* Reinitialize fields to forget about all memory */ - m->smallbins = m->treebins = 0; - m->dvsize = m->topsize = 0; - m->seg.base = 0; - m->seg.size = 0; - m->seg.next = 0; - m->top = m->dv = 0; - for (i = 0; i < NTREEBINS; ++i) - *treebin_at(m, i) = 0; - init_bins(m); +static void +reset_on_error (mstate m) +{ + int i; + ++malloc_corruption_error_count; + /* Reinitialize fields to forget about all memory */ + m->smallbins = m->treebins = 0; + m->dvsize = m->topsize = 0; + m->seg.base = 0; + m->seg.size = 0; + m->seg.next = 0; + m->top = m->dv = 0; + for (i = 0; i < NTREEBINS; ++i) + *treebin_at (m, i) = 0; + init_bins (m); } #endif /* PROCEED_ON_ERROR */ /* Allocate chunk and prepend remainder with chunk in successor base. */ -static void* prepend_alloc(mstate m, char* newbase, char* oldbase, - size_t nb) { - mchunkptr p = align_as_chunk(newbase); - mchunkptr oldfirst = align_as_chunk(oldbase); - size_t psize = (char*)oldfirst - (char*)p; - mchunkptr q = chunk_plus_offset(p, nb); - size_t qsize = psize - nb; - set_size_and_pinuse_of_inuse_chunk(m, p, nb); - - assert((char*)oldfirst > (char*)q); - assert(pinuse(oldfirst)); - assert(qsize >= MIN_CHUNK_SIZE); - - /* consolidate remainder with first chunk of old base */ - if (oldfirst == m->top) { - size_t tsize = m->topsize += qsize; - m->top = q; - q->head = tsize | PINUSE_BIT; - check_top_chunk(m, q); - } - else if (oldfirst == m->dv) { - size_t dsize = m->dvsize += qsize; - m->dv = q; - set_size_and_pinuse_of_free_chunk(q, dsize); - } - else { - if (!cinuse(oldfirst)) { - size_t nsize = chunksize(oldfirst); - unlink_chunk(m, oldfirst, nsize); - oldfirst = chunk_plus_offset(oldfirst, nsize); - qsize += nsize; +static void * +prepend_alloc (mstate m, char *newbase, char *oldbase, size_t nb) +{ + mchunkptr p = align_as_chunk (newbase); + mchunkptr oldfirst = align_as_chunk (oldbase); + size_t psize = (char *) oldfirst - (char *) p; + mchunkptr q = chunk_plus_offset (p, nb); + size_t qsize = psize - nb; + set_size_and_pinuse_of_inuse_chunk (m, p, nb); + + assert ((char *) oldfirst > (char *) q); + assert (pinuse (oldfirst)); + assert (qsize >= MIN_CHUNK_SIZE); + + /* consolidate remainder with first chunk of old base */ + if (oldfirst == m->top) { + size_t tsize = m->topsize += qsize; + m->top = q; + q->head = tsize | PINUSE_BIT; + check_top_chunk (m, q); + } else if (oldfirst == m->dv) { + size_t dsize = m->dvsize += qsize; + m->dv = q; + set_size_and_pinuse_of_free_chunk (q, dsize); + } else { + if (!cinuse (oldfirst)) { + size_t nsize = chunksize (oldfirst); + unlink_chunk (m, oldfirst, nsize); + oldfirst = chunk_plus_offset (oldfirst, nsize); + qsize += nsize; + } + set_free_with_pinuse (q, qsize, oldfirst); + insert_chunk (m, q, qsize); + check_free_chunk (m, q); } - set_free_with_pinuse(q, qsize, oldfirst); - insert_chunk(m, q, qsize); - check_free_chunk(m, q); - } - check_malloced_chunk(m, chunk2mem(p), nb); - return chunk2mem(p); + check_malloced_chunk (m, chunk2mem (p), nb); + return chunk2mem (p); } /* Add a segment to hold a new noncontiguous region */ -static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) { - /* Determine locations and sizes of segment, fenceposts, old top */ - char* old_top = (char*)m->top; - msegmentptr oldsp = segment_holding(m, old_top); - char* old_end = oldsp->base + oldsp->size; - size_t ssize = pad_request(sizeof(struct malloc_segment)); - char* rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); - size_t offset = align_offset(chunk2mem(rawsp)); - char* asp = rawsp + offset; - char* csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp; - mchunkptr sp = (mchunkptr)csp; - msegmentptr ss = (msegmentptr)(chunk2mem(sp)); - mchunkptr tnext = chunk_plus_offset(sp, ssize); - mchunkptr p = tnext; - int nfences = 0; - - /* reset top to new space */ - init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); - - /* Set up segment record */ - assert(is_aligned(ss)); - set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); - *ss = m->seg; /* Push current record */ - m->seg.base = tbase; - m->seg.size = tsize; - m->seg.sflags = mmapped; - m->seg.next = ss; - - /* Insert trailing fenceposts */ - for (;;) { - mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); - p->head = FENCEPOST_HEAD; - ++nfences; - if ((char*)(&(nextp->head)) < old_end) - p = nextp; - else - break; - } - assert(nfences >= 2); - - /* Insert the rest of old top into a bin as an ordinary free chunk */ - if (csp != old_top) { - mchunkptr q = (mchunkptr)old_top; - size_t psize = csp - old_top; - mchunkptr tn = chunk_plus_offset(q, psize); - set_free_with_pinuse(q, psize, tn); - insert_chunk(m, q, psize); - } +static void +add_segment (mstate m, char *tbase, size_t tsize, flag_t mmapped) +{ + /* Determine locations and sizes of segment, fenceposts, old top */ + char *old_top = (char *) m->top; + msegmentptr oldsp = segment_holding (m, old_top); + char *old_end = oldsp->base + oldsp->size; + size_t ssize = pad_request (sizeof (struct malloc_segment)); + char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + size_t offset = align_offset (chunk2mem (rawsp)); + char *asp = rawsp + offset; + char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp; + mchunkptr sp = (mchunkptr) csp; + msegmentptr ss = (msegmentptr) (chunk2mem (sp)); + mchunkptr tnext = chunk_plus_offset (sp, ssize); + mchunkptr p = tnext; + int nfences = 0; + + /* reset top to new space */ + init_top (m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE); + + /* Set up segment record */ + assert (is_aligned (ss)); + set_size_and_pinuse_of_inuse_chunk (m, sp, ssize); + *ss = m->seg; /* Push current record */ + m->seg.base = tbase; + m->seg.size = tsize; + m->seg.sflags = mmapped; + m->seg.next = ss; + + /* Insert trailing fenceposts */ + for (;;) { + mchunkptr nextp = chunk_plus_offset (p, SIZE_T_SIZE); + p->head = FENCEPOST_HEAD; + ++nfences; + if ((char *) (&(nextp->head)) < old_end) + p = nextp; + else + break; + } + assert (nfences >= 2); + + /* Insert the rest of old top into a bin as an ordinary free chunk */ + if (csp != old_top) { + mchunkptr q = (mchunkptr) old_top; + size_t psize = csp - old_top; + mchunkptr tn = chunk_plus_offset (q, psize); + set_free_with_pinuse (q, psize, tn); + insert_chunk (m, q, psize); + } - check_top_chunk(m, m->top); + check_top_chunk (m, m->top); } /* -------------------------- System allocation -------------------------- */ /* Get memory from system using MORECORE or MMAP */ -static void* sys_alloc(mstate m, size_t nb) { - char* tbase = CMFAIL; - size_t tsize = 0; - flag_t mmap_flag = 0; - - init_mparams(); - - /* Directly map large chunks */ - if (use_mmap(m) && nb >= mparams.mmap_threshold) { - void* mem = mmap_alloc(m, nb); - if (mem != 0) - return mem; - } +static void * +sys_alloc (mstate m, size_t nb) +{ + char *tbase = CMFAIL; + size_t tsize = 0; + flag_t mmap_flag = 0; + + init_mparams (); + + /* Directly map large chunks */ + if (use_mmap (m) && nb >= mparams.mmap_threshold) { + void *mem = mmap_alloc (m, nb); + if (mem != 0) + return mem; + } - /* - Try getting memory in any of three ways (in most-preferred to - least-preferred order): - 1. A call to MORECORE that can normally contiguously extend memory. + /* + Try getting memory in any of three ways (in most-preferred to + least-preferred order): + 1. A call to MORECORE that can normally contiguously extend memory. (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or or main space is mmapped or a previous contiguous call failed) - 2. A call to MMAP new space (disabled if not HAVE_MMAP). + 2. A call to MMAP new space (disabled if not HAVE_MMAP). Note that under the default settings, if MORECORE is unable to fulfill a request, and HAVE_MMAP is true, then mmap is used as a noncontiguous system allocator. This is a useful backup strategy for systems with holes in address spaces -- in this case sbrk cannot contiguously expand the heap, but mmap may be able to find space. - 3. A call to MORECORE that cannot usually contiguously extend memory. + 3. A call to MORECORE that cannot usually contiguously extend memory. (disabled if not HAVE_MORECORE) - */ - - if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) { - char* br = CMFAIL; - msegmentptr ss = (m->top == 0)? 0 : segment_holding(m, (char*)m->top); - size_t asize = 0; - ACQUIRE_MORECORE_LOCK(); - - if (ss == 0) { /* First time through or recovery */ - char* base = (char*)CALL_MORECORE(0); - if (base != CMFAIL) { - asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE); - /* Adjust to end on a page boundary */ - if (!is_page_aligned(base)) - asize += (page_align((size_t)base) - (size_t)base); - /* Can't call MORECORE if size is negative when treated as signed */ - if (asize < HALF_MAX_SIZE_T && - (br = (char*)(CALL_MORECORE(asize))) == base) { - tbase = base; - tsize = asize; + */ + + if (MORECORE_CONTIGUOUS && !use_noncontiguous (m)) { + char *br = CMFAIL; + msegmentptr ss = + (m->top == 0) ? 0 : segment_holding (m, (char *) m->top); + size_t asize = 0; + ACQUIRE_MORECORE_LOCK (); + + if (ss == 0) { /* First time through or recovery */ + char *base = (char *) CALL_MORECORE (0); + if (base != CMFAIL) { + asize = granularity_align (nb + TOP_FOOT_SIZE + SIZE_T_ONE); + /* Adjust to end on a page boundary */ + if (!is_page_aligned (base)) + asize += (page_align ((size_t) base) - (size_t) base); + /* Can't call MORECORE if size is negative when treated as signed */ + if (asize < HALF_MAX_SIZE_T && + (br = (char *) (CALL_MORECORE (asize))) == base) { + tbase = base; + tsize = asize; + } + } + } else { + /* Subtract out existing available top space from MORECORE request. */ + asize = + granularity_align (nb - m->topsize + TOP_FOOT_SIZE + + SIZE_T_ONE); + /* Use mem here only if it did continuously extend old space */ + if (asize < HALF_MAX_SIZE_T && + (br = + (char *) (CALL_MORECORE (asize))) == ss->base + ss->size) { + tbase = br; + tsize = asize; + } } - } - } - else { - /* Subtract out existing available top space from MORECORE request. */ - asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + SIZE_T_ONE); - /* Use mem here only if it did continuously extend old space */ - if (asize < HALF_MAX_SIZE_T && - (br = (char*)(CALL_MORECORE(asize))) == ss->base+ss->size) { - tbase = br; - tsize = asize; - } - } - if (tbase == CMFAIL) { /* Cope with partial failure */ - if (br != CMFAIL) { /* Try to use/extend the space we did get */ - if (asize < HALF_MAX_SIZE_T && - asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) { - size_t esize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE - asize); - if (esize < HALF_MAX_SIZE_T) { - char* end = (char*)CALL_MORECORE(esize); - if (end != CMFAIL) - asize += esize; - else { /* Can't use; try to release */ - end = (char*)CALL_MORECORE(-asize); - br = CMFAIL; + if (tbase == CMFAIL) { /* Cope with partial failure */ + if (br != CMFAIL) { /* Try to use/extend the space we did get */ + if (asize < HALF_MAX_SIZE_T && + asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) { + size_t esize = + granularity_align (nb + TOP_FOOT_SIZE + + SIZE_T_ONE - asize); + if (esize < HALF_MAX_SIZE_T) { + char *end = (char *) CALL_MORECORE (esize); + if (end != CMFAIL) + asize += esize; + else { /* Can't use; try to release */ + end = (char *) CALL_MORECORE (-asize); + br = CMFAIL; + } + } + } } - } + if (br != CMFAIL) { /* Use the space we did get */ + tbase = br; + tsize = asize; + } else + disable_contiguous (m); /* Don't try contiguous path in the future */ } - } - if (br != CMFAIL) { /* Use the space we did get */ - tbase = br; - tsize = asize; - } - else - disable_contiguous(m); /* Don't try contiguous path in the future */ - } - RELEASE_MORECORE_LOCK(); - } - - if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */ - size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE; - size_t rsize = granularity_align(req); - if (rsize > nb) { /* Fail if wraps around zero */ - char* mp = (char*)(CALL_MMAP(rsize)); - if (mp != CMFAIL) { - tbase = mp; - tsize = rsize; - mmap_flag = IS_MMAPPED_BIT; - } + RELEASE_MORECORE_LOCK (); } - } - if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */ - size_t asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE); - if (asize < HALF_MAX_SIZE_T) { - char* br = CMFAIL; - char* end = CMFAIL; - ACQUIRE_MORECORE_LOCK(); - br = (char*)(CALL_MORECORE(asize)); - end = (char*)(CALL_MORECORE(0)); - RELEASE_MORECORE_LOCK(); - if (br != CMFAIL && end != CMFAIL && br < end) { - size_t ssize = end - br; - if (ssize > nb + TOP_FOOT_SIZE) { - tbase = br; - tsize = ssize; + if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */ + size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE; + size_t rsize = granularity_align (req); + if (rsize > nb) { /* Fail if wraps around zero */ + char *mp = (char *) (CALL_MMAP (rsize)); + if (mp != CMFAIL) { + tbase = mp; + tsize = rsize; + mmap_flag = IS_MMAPPED_BIT; + } } - } } - } - if (tbase != CMFAIL) { - - if ((m->footprint += tsize) > m->max_footprint) - m->max_footprint = m->footprint; - - if (!is_initialized(m)) { /* first-time initialization */ - m->seg.base = m->least_addr = tbase; - m->seg.size = tsize; - m->seg.sflags = mmap_flag; - m->magic = mparams.magic; - init_bins(m); - if (is_global(m)) - init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); - else { - /* Offset top by embedded malloc_state */ - mchunkptr mn = next_chunk(mem2chunk(m)); - init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) -TOP_FOOT_SIZE); - } + if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */ + size_t asize = granularity_align (nb + TOP_FOOT_SIZE + SIZE_T_ONE); + if (asize < HALF_MAX_SIZE_T) { + char *br = CMFAIL; + char *end = CMFAIL; + ACQUIRE_MORECORE_LOCK (); + br = (char *) (CALL_MORECORE (asize)); + end = (char *) (CALL_MORECORE (0)); + RELEASE_MORECORE_LOCK (); + if (br != CMFAIL && end != CMFAIL && br < end) { + size_t ssize = end - br; + if (ssize > nb + TOP_FOOT_SIZE) { + tbase = br; + tsize = ssize; + } + } + } } - else { - /* Try to merge with an existing segment */ - msegmentptr sp = &m->seg; - while (sp != 0 && tbase != sp->base + sp->size) - sp = sp->next; - if (sp != 0 && - !is_extern_segment(sp) && - (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && - segment_holds(sp, m->top)) { /* append */ - sp->size += tsize; - init_top(m, m->top, m->topsize + tsize); - } - else { - if (tbase < m->least_addr) - m->least_addr = tbase; - sp = &m->seg; - while (sp != 0 && sp->base != tbase + tsize) - sp = sp->next; - if (sp != 0 && - !is_extern_segment(sp) && - (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) { - char* oldbase = sp->base; - sp->base = tbase; - sp->size += tsize; - return prepend_alloc(m, tbase, oldbase, nb); + if (tbase != CMFAIL) { + + if ((m->footprint += tsize) > m->max_footprint) + m->max_footprint = m->footprint; + + if (!is_initialized (m)) { /* first-time initialization */ + m->seg.base = m->least_addr = tbase; + m->seg.size = tsize; + m->seg.sflags = mmap_flag; + m->magic = mparams.magic; + init_bins (m); + if (is_global (m)) + init_top (m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE); + else { + /* Offset top by embedded malloc_state */ + mchunkptr mn = next_chunk (mem2chunk (m)); + init_top (m, mn, + (size_t) ((tbase + tsize) - (char *) mn) - + TOP_FOOT_SIZE); + } + } + + else { + /* Try to merge with an existing segment */ + msegmentptr sp = &m->seg; + while (sp != 0 && tbase != sp->base + sp->size) + sp = sp->next; + if (sp != 0 && !is_extern_segment (sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && segment_holds (sp, m->top)) { /* append */ + sp->size += tsize; + init_top (m, m->top, m->topsize + tsize); + } else { + if (tbase < m->least_addr) + m->least_addr = tbase; + sp = &m->seg; + while (sp != 0 && sp->base != tbase + tsize) + sp = sp->next; + if (sp != 0 && + !is_extern_segment (sp) && + (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) { + char *oldbase = sp->base; + sp->base = tbase; + sp->size += tsize; + return prepend_alloc (m, tbase, oldbase, nb); + } else + add_segment (m, tbase, tsize, mmap_flag); + } } - else - add_segment(m, tbase, tsize, mmap_flag); - } - } - if (nb < m->topsize) { /* Allocate from new or extended top space */ - size_t rsize = m->topsize -= nb; - mchunkptr p = m->top; - mchunkptr r = m->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(m, p, nb); - check_top_chunk(m, m->top); - check_malloced_chunk(m, chunk2mem(p), nb); - return chunk2mem(p); + if (nb < m->topsize) { /* Allocate from new or extended top space */ + size_t rsize = m->topsize -= nb; + mchunkptr p = m->top; + mchunkptr r = m->top = chunk_plus_offset (p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk (m, p, nb); + check_top_chunk (m, m->top); + check_malloced_chunk (m, chunk2mem (p), nb); + return chunk2mem (p); + } } - } - MALLOC_FAILURE_ACTION; - return 0; + MALLOC_FAILURE_ACTION; + return 0; } /* ----------------------- system deallocation -------------------------- */ /* Unmap and unlink any mmapped segments that don't contain used chunks */ -static size_t release_unused_segments(mstate m) { - size_t released = 0; - msegmentptr pred = &m->seg; - msegmentptr sp = pred->next; - while (sp != 0) { - char* base = sp->base; - size_t size = sp->size; - msegmentptr next = sp->next; - if (is_mmapped_segment(sp) && !is_extern_segment(sp)) { - mchunkptr p = align_as_chunk(base); - size_t psize = chunksize(p); - /* Can unmap if first chunk holds entire segment and not pinned */ - if (!cinuse(p) && (char*)p + psize >= base + size - TOP_FOOT_SIZE) { - tchunkptr tp = (tchunkptr)p; - assert(segment_holds(sp, (char*)sp)); - if (p == m->dv) { - m->dv = 0; - m->dvsize = 0; - } - else { - unlink_large_chunk(m, tp); - } - if (CALL_MUNMAP(base, size) == 0) { - released += size; - m->footprint -= size; - /* unlink obsoleted record */ - sp = pred; - sp->next = next; - } - else { /* back out if cannot unmap */ - insert_large_chunk(m, tp, psize); +static size_t +release_unused_segments (mstate m) +{ + size_t released = 0; + msegmentptr pred = &m->seg; + msegmentptr sp = pred->next; + while (sp != 0) { + char *base = sp->base; + size_t size = sp->size; + msegmentptr next = sp->next; + if (is_mmapped_segment (sp) && !is_extern_segment (sp)) { + mchunkptr p = align_as_chunk (base); + size_t psize = chunksize (p); + /* Can unmap if first chunk holds entire segment and not pinned */ + if (!cinuse (p) + && (char *) p + psize >= base + size - TOP_FOOT_SIZE) { + tchunkptr tp = (tchunkptr) p; + assert (segment_holds (sp, (char *) sp)); + if (p == m->dv) { + m->dv = 0; + m->dvsize = 0; + } else { + unlink_large_chunk (m, tp); + } + if (CALL_MUNMAP (base, size) == 0) { + released += size; + m->footprint -= size; + /* unlink obsoleted record */ + sp = pred; + sp->next = next; + } else { /* back out if cannot unmap */ + insert_large_chunk (m, tp, psize); + } + } } - } + pred = sp; + sp = next; } - pred = sp; - sp = next; - } - return released; + return released; } -static int sys_trim(mstate m, size_t pad) { - size_t released = 0; - if (pad < MAX_REQUEST && is_initialized(m)) { - pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ - - if (m->topsize > pad) { - /* Shrink top space in granularity-size units, keeping at least one */ - size_t unit = mparams.granularity; - size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - - SIZE_T_ONE) * unit; - msegmentptr sp = segment_holding(m, (char*)m->top); - - if (!is_extern_segment(sp)) { - if (is_mmapped_segment(sp)) { - if (HAVE_MMAP && - sp->size >= extra && - !has_segment_link(m, sp)) { /* can't shrink if pinned */ - size_t newsize = sp->size - extra; - /* Prefer mremap, fall back to munmap */ - if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != MFAIL) || - (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { - released = extra; +static int +sys_trim (mstate m, size_t pad) +{ + size_t released = 0; + if (pad < MAX_REQUEST && is_initialized (m)) { + pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ + + if (m->topsize > pad) { + /* Shrink top space in granularity-size units, keeping at least one */ + size_t unit = mparams.granularity; + size_t extra = + ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - + SIZE_T_ONE) * unit; + msegmentptr sp = segment_holding (m, (char *) m->top); + + if (!is_extern_segment (sp)) { + if (is_mmapped_segment (sp)) { + if (HAVE_MMAP && sp->size >= extra && !has_segment_link (m, sp)) { /* can't shrink if pinned */ + size_t newsize = sp->size - extra; + /* Prefer mremap, fall back to munmap */ + if ((CALL_MREMAP + (sp->base, sp->size, newsize, 0) != MFAIL) + || (CALL_MUNMAP (sp->base + newsize, extra) + == 0)) { + released = extra; + } + } + } else if (HAVE_MORECORE) { + if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */ + extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit; + ACQUIRE_MORECORE_LOCK (); + { + /* Make sure end of memory is where we last set it. */ + char *old_br = (char *) (CALL_MORECORE (0)); + if (old_br == sp->base + sp->size) { + char *rel_br = (char *) (CALL_MORECORE (-extra)); + char *new_br = (char *) (CALL_MORECORE (0)); + if (rel_br != CMFAIL && new_br < old_br) + released = old_br - new_br; + } + } + RELEASE_MORECORE_LOCK (); + } } - } - } - else if (HAVE_MORECORE) { - if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */ - extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit; - ACQUIRE_MORECORE_LOCK(); - { - /* Make sure end of memory is where we last set it. */ - char* old_br = (char*)(CALL_MORECORE(0)); - if (old_br == sp->base + sp->size) { - char* rel_br = (char*)(CALL_MORECORE(-extra)); - char* new_br = (char*)(CALL_MORECORE(0)); - if (rel_br != CMFAIL && new_br < old_br) - released = old_br - new_br; + + if (released != 0) { + sp->size -= released; + m->footprint -= released; + init_top (m, m->top, m->topsize - released); + check_top_chunk (m, m->top); } - } - RELEASE_MORECORE_LOCK(); } - } - if (released != 0) { - sp->size -= released; - m->footprint -= released; - init_top(m, m->top, m->topsize - released); - check_top_chunk(m, m->top); - } - } + /* Unmap any unused mmapped segments */ + if (HAVE_MMAP) + released += release_unused_segments (m); - /* Unmap any unused mmapped segments */ - if (HAVE_MMAP) - released += release_unused_segments(m); - - /* On failure, disable autotrim to avoid repeated failed future calls */ - if (released == 0) - m->trim_check = MAX_SIZE_T; - } + /* On failure, disable autotrim to avoid repeated failed future calls */ + if (released == 0) + m->trim_check = MAX_SIZE_T; + } - return (released != 0)? 1 : 0; + return (released != 0) ? 1 : 0; } /* ---------------------------- malloc support --------------------------- */ /* allocate a large request from the best fitting chunk in a treebin */ -static void* tmalloc_large(mstate m, size_t nb) { - tchunkptr v = 0; - size_t rsize = -nb; /* Unsigned negation */ - tchunkptr t; - bindex_t idx; - compute_tree_index(nb, idx); - - if ((t = *treebin_at(m, idx)) != 0) { - /* Traverse tree for this bin looking for node with size == nb */ - size_t sizebits = nb << leftshift_for_tree_index(idx); - tchunkptr rst = 0; /* The deepest untaken right subtree */ - for (;;) { - tchunkptr rt; - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - v = t; - if ((rsize = trem) == 0) - break; - } - rt = t->child[1]; - t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; - if (rt != 0 && rt != t) - rst = rt; - if (t == 0) { - t = rst; /* set t to least subtree holding sizes > nb */ - break; - } - sizebits <<= 1; +static void * +tmalloc_large (mstate m, size_t nb) +{ + tchunkptr v = 0; + size_t rsize = -nb; /* Unsigned negation */ + tchunkptr t; + bindex_t idx; + compute_tree_index (nb, idx); + + if ((t = *treebin_at (m, idx)) != 0) { + /* Traverse tree for this bin looking for node with size == nb */ + size_t sizebits = nb << leftshift_for_tree_index (idx); + tchunkptr rst = 0; /* The deepest untaken right subtree */ + for (;;) { + tchunkptr rt; + size_t trem = chunksize (t) - nb; + if (trem < rsize) { + v = t; + if ((rsize = trem) == 0) + break; + } + rt = t->child[1]; + t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1]; + if (rt != 0 && rt != t) + rst = rt; + if (t == 0) { + t = rst; /* set t to least subtree holding sizes > nb */ + break; + } + sizebits <<= 1; + } } - } - if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ - binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; - if (leftbits != 0) { - bindex_t i; - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - t = *treebin_at(m, i); + if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ + binmap_t leftbits = left_bits (idx2bit (idx)) & m->treemap; + if (leftbits != 0) { + bindex_t i; + binmap_t leastbit = least_bit (leftbits); + compute_bit2idx (leastbit, i); + t = *treebin_at (m, i); + } } - } - while (t != 0) { /* find smallest of tree or subtree */ - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - rsize = trem; - v = t; + while (t != 0) { /* find smallest of tree or subtree */ + size_t trem = chunksize (t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } + t = leftmost_child (t); } - t = leftmost_child(t); - } - /* If dv is a better fit, return 0 so malloc will use it */ - if (v != 0 && rsize < (size_t)(m->dvsize - nb)) { - if (RTCHECK(ok_address(m, v))) { /* split */ - mchunkptr r = chunk_plus_offset(v, nb); - assert(chunksize(v) == rsize + nb); - if (RTCHECK(ok_next(v, r))) { - unlink_large_chunk(m, v); - if (rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(m, v, (rsize + nb)); - else { - set_size_and_pinuse_of_inuse_chunk(m, v, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - insert_chunk(m, r, rsize); + /* If dv is a better fit, return 0 so malloc will use it */ + if (v != 0 && rsize < (size_t) (m->dvsize - nb)) { + if (RTCHECK (ok_address (m, v))) { /* split */ + mchunkptr r = chunk_plus_offset (v, nb); + assert (chunksize (v) == rsize + nb); + if (RTCHECK (ok_next (v, r))) { + unlink_large_chunk (m, v); + if (rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse (m, v, (rsize + nb)); + else { + set_size_and_pinuse_of_inuse_chunk (m, v, nb); + set_size_and_pinuse_of_free_chunk (r, rsize); + insert_chunk (m, r, rsize); + } + return chunk2mem (v); + } } - return chunk2mem(v); - } + CORRUPTION_ERROR_ACTION (m); } - CORRUPTION_ERROR_ACTION(m); - } - return 0; + return 0; } /* allocate a small request from the best fitting chunk in a treebin */ -static void* tmalloc_small(mstate m, size_t nb) { - tchunkptr t, v; - size_t rsize; - bindex_t i; - binmap_t leastbit = least_bit(m->treemap); - compute_bit2idx(leastbit, i); - - v = t = *treebin_at(m, i); - rsize = chunksize(t) - nb; - - while ((t = leftmost_child(t)) != 0) { - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - rsize = trem; - v = t; +static void * +tmalloc_small (mstate m, size_t nb) +{ + tchunkptr t, v; + size_t rsize; + bindex_t i; + binmap_t leastbit = least_bit (m->treemap); + compute_bit2idx (leastbit, i); + + v = t = *treebin_at (m, i); + rsize = chunksize (t) - nb; + + while ((t = leftmost_child (t)) != 0) { + size_t trem = chunksize (t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } } - } - if (RTCHECK(ok_address(m, v))) { - mchunkptr r = chunk_plus_offset(v, nb); - assert(chunksize(v) == rsize + nb); - if (RTCHECK(ok_next(v, r))) { - unlink_large_chunk(m, v); - if (rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(m, v, (rsize + nb)); - else { - set_size_and_pinuse_of_inuse_chunk(m, v, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(m, r, rsize); - } - return chunk2mem(v); + if (RTCHECK (ok_address (m, v))) { + mchunkptr r = chunk_plus_offset (v, nb); + assert (chunksize (v) == rsize + nb); + if (RTCHECK (ok_next (v, r))) { + unlink_large_chunk (m, v); + if (rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse (m, v, (rsize + nb)); + else { + set_size_and_pinuse_of_inuse_chunk (m, v, nb); + set_size_and_pinuse_of_free_chunk (r, rsize); + replace_dv (m, r, rsize); + } + return chunk2mem (v); + } } - } - CORRUPTION_ERROR_ACTION(m); - return 0; + CORRUPTION_ERROR_ACTION (m); + return 0; } /* --------------------------- realloc support --------------------------- */ -static void* internal_realloc(mstate m, void* oldmem, size_t bytes) { - if (bytes >= MAX_REQUEST) { - MALLOC_FAILURE_ACTION; - return 0; - } - if (!PREACTION(m)) { - mchunkptr oldp = mem2chunk(oldmem); - size_t oldsize = chunksize(oldp); - mchunkptr next = chunk_plus_offset(oldp, oldsize); - mchunkptr newp = 0; - void* extra = 0; - - /* Try to either shrink or extend into top. Else malloc-copy-free */ - - if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) && - ok_next(oldp, next) && ok_pinuse(next))) { - size_t nb = request2size(bytes); - if (is_mmapped(oldp)) - newp = mmap_resize(m, oldp, nb); - else if (oldsize >= nb) { /* already big enough */ - size_t rsize = oldsize - nb; - newp = oldp; - if (rsize >= MIN_CHUNK_SIZE) { - mchunkptr remainder = chunk_plus_offset(newp, nb); - set_inuse(m, newp, nb); - set_inuse(m, remainder, rsize); - extra = chunk2mem(remainder); - } - } - else if (next == m->top && oldsize + m->topsize > nb) { - /* Expand into top */ - size_t newsize = oldsize + m->topsize; - size_t newtopsize = newsize - nb; - mchunkptr newtop = chunk_plus_offset(oldp, nb); - set_inuse(m, oldp, nb); - newtop->head = newtopsize |PINUSE_BIT; - m->top = newtop; - m->topsize = newtopsize; - newp = oldp; - } - } - else { - USAGE_ERROR_ACTION(m, oldmem); - POSTACTION(m); - return 0; +static void * +internal_realloc (mstate m, void *oldmem, size_t bytes) +{ + if (bytes >= MAX_REQUEST) { + MALLOC_FAILURE_ACTION; + return 0; } + if (!PREACTION (m)) { + mchunkptr oldp = mem2chunk (oldmem); + size_t oldsize = chunksize (oldp); + mchunkptr next = chunk_plus_offset (oldp, oldsize); + mchunkptr newp = 0; + void *extra = 0; + + /* Try to either shrink or extend into top. Else malloc-copy-free */ + + if (RTCHECK (ok_address (m, oldp) && ok_cinuse (oldp) && + ok_next (oldp, next) && ok_pinuse (next))) { + size_t nb = request2size (bytes); + if (is_mmapped (oldp)) + newp = mmap_resize (m, oldp, nb); + else if (oldsize >= nb) { /* already big enough */ + size_t rsize = oldsize - nb; + newp = oldp; + if (rsize >= MIN_CHUNK_SIZE) { + mchunkptr remainder = chunk_plus_offset (newp, nb); + set_inuse (m, newp, nb); + set_inuse (m, remainder, rsize); + extra = chunk2mem (remainder); + } + } else if (next == m->top && oldsize + m->topsize > nb) { + /* Expand into top */ + size_t newsize = oldsize + m->topsize; + size_t newtopsize = newsize - nb; + mchunkptr newtop = chunk_plus_offset (oldp, nb); + set_inuse (m, oldp, nb); + newtop->head = newtopsize | PINUSE_BIT; + m->top = newtop; + m->topsize = newtopsize; + newp = oldp; + } + } else { + USAGE_ERROR_ACTION (m, oldmem); + POSTACTION (m); + return 0; + } - POSTACTION(m); + POSTACTION (m); - if (newp != 0) { - if (extra != 0) { - internal_free(m, extra); - } - check_inuse_chunk(m, newp); - return chunk2mem(newp); - } - else { - void* newmem = internal_malloc(m, bytes); - if (newmem != 0) { - size_t oc = oldsize - overhead_for(oldp); - memcpy(newmem, oldmem, (oc < bytes)? oc : bytes); - internal_free(m, oldmem); - } - return newmem; + if (newp != 0) { + if (extra != 0) { + internal_free (m, extra); + } + check_inuse_chunk (m, newp); + return chunk2mem (newp); + } else { + void *newmem = internal_malloc (m, bytes); + if (newmem != 0) { + size_t oc = oldsize - overhead_for (oldp); + memcpy (newmem, oldmem, (oc < bytes) ? oc : bytes); + internal_free (m, oldmem); + } + return newmem; + } } - } - return 0; + return 0; } /* --------------------------- memalign support -------------------------- */ -static void* internal_memalign(mstate m, size_t alignment, size_t bytes) { - if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */ - return internal_malloc(m, bytes); - if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ - alignment = MIN_CHUNK_SIZE; - if ((alignment & (alignment-SIZE_T_ONE)) != 0) {/* Ensure a power of 2 */ - size_t a = MALLOC_ALIGNMENT << 1; - while (a < alignment) a <<= 1; - alignment = a; - } - - if (bytes >= MAX_REQUEST - alignment) { - if (m != 0) { /* Test isn't needed but avoids compiler warning */ - MALLOC_FAILURE_ACTION; +static void * +internal_memalign (mstate m, size_t alignment, size_t bytes) +{ + if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */ + return internal_malloc (m, bytes); + if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ + alignment = MIN_CHUNK_SIZE; + if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */ + size_t a = MALLOC_ALIGNMENT << 1; + while (a < alignment) + a <<= 1; + alignment = a; } - } - else { - size_t nb = request2size(bytes); - size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD; - char* mem = (char*)internal_malloc(m, req); - if (mem != 0) { - void* leader = 0; - void* trailer = 0; - mchunkptr p = mem2chunk(mem); - - if (PREACTION(m)) return 0; - if ((((size_t)(mem)) % alignment) != 0) { /* misaligned */ - /* - Find an aligned spot inside chunk. Since we need to give - back leading space in a chunk of at least MIN_CHUNK_SIZE, if - the first calculation places us at a spot with less than - MIN_CHUNK_SIZE leader, we can move to the next aligned spot. - We've allocated enough total room so that this is always - possible. - */ - char* br = (char*)mem2chunk((size_t)(((size_t)(mem + - alignment - - SIZE_T_ONE)) & - -alignment)); - char* pos = ((size_t)(br - (char*)(p)) >= MIN_CHUNK_SIZE)? - br : br+alignment; - mchunkptr newp = (mchunkptr)pos; - size_t leadsize = pos - (char*)(p); - size_t newsize = chunksize(p) - leadsize; - - if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */ - newp->prev_foot = p->prev_foot + leadsize; - newp->head = (newsize|CINUSE_BIT); - } - else { /* Otherwise, give back leader, use the rest */ - set_inuse(m, newp, newsize); - set_inuse(m, p, leadsize); - leader = chunk2mem(p); - } - p = newp; - } - /* Give back spare room at the end */ - if (!is_mmapped(p)) { - size_t size = chunksize(p); - if (size > nb + MIN_CHUNK_SIZE) { - size_t remainder_size = size - nb; - mchunkptr remainder = chunk_plus_offset(p, nb); - set_inuse(m, p, nb); - set_inuse(m, remainder, remainder_size); - trailer = chunk2mem(remainder); + if (bytes >= MAX_REQUEST - alignment) { + if (m != 0) { /* Test isn't needed but avoids compiler warning */ + MALLOC_FAILURE_ACTION; } - } + } else { + size_t nb = request2size (bytes); + size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD; + char *mem = (char *) internal_malloc (m, req); + if (mem != 0) { + void *leader = 0; + void *trailer = 0; + mchunkptr p = mem2chunk (mem); + + if (PREACTION (m)) + return 0; + if ((((size_t) (mem)) % alignment) != 0) { /* misaligned */ + /* + Find an aligned spot inside chunk. Since we need to give + back leading space in a chunk of at least MIN_CHUNK_SIZE, if + the first calculation places us at a spot with less than + MIN_CHUNK_SIZE leader, we can move to the next aligned spot. + We've allocated enough total room so that this is always + possible. + */ + char *br = (char *) + mem2chunk ((size_t) + (((size_t) + (mem + alignment - + SIZE_T_ONE)) & -alignment)); + char *pos = + ((size_t) (br - (char *) (p)) >= + MIN_CHUNK_SIZE) ? br : br + alignment; + mchunkptr newp = (mchunkptr) pos; + size_t leadsize = pos - (char *) (p); + size_t newsize = chunksize (p) - leadsize; + + if (is_mmapped (p)) { /* For mmapped chunks, just adjust offset */ + newp->prev_foot = p->prev_foot + leadsize; + newp->head = (newsize | CINUSE_BIT); + } else { /* Otherwise, give back leader, use the rest */ + set_inuse (m, newp, newsize); + set_inuse (m, p, leadsize); + leader = chunk2mem (p); + } + p = newp; + } - assert (chunksize(p) >= nb); - assert((((size_t)(chunk2mem(p))) % alignment) == 0); - check_inuse_chunk(m, p); - POSTACTION(m); - if (leader != 0) { - internal_free(m, leader); - } - if (trailer != 0) { - internal_free(m, trailer); - } - return chunk2mem(p); + /* Give back spare room at the end */ + if (!is_mmapped (p)) { + size_t size = chunksize (p); + if (size > nb + MIN_CHUNK_SIZE) { + size_t remainder_size = size - nb; + mchunkptr remainder = chunk_plus_offset (p, nb); + set_inuse (m, p, nb); + set_inuse (m, remainder, remainder_size); + trailer = chunk2mem (remainder); + } + } + + assert (chunksize (p) >= nb); + assert ((((size_t) (chunk2mem (p))) % alignment) == 0); + check_inuse_chunk (m, p); + POSTACTION (m); + if (leader != 0) { + internal_free (m, leader); + } + if (trailer != 0) { + internal_free (m, trailer); + } + return chunk2mem (p); + } } - } - return 0; + return 0; } /* ------------------------ comalloc/coalloc support --------------------- */ -static void** ialloc(mstate m, - size_t n_elements, - size_t* sizes, - int opts, - void* chunks[]) { - /* - This provides common support for independent_X routines, handling - all of the combinations that can result. - - The opts arg has: - bit 0 set if all elements are same size (using sizes[0]) - bit 1 set if elements should be zeroed - */ - - size_t element_size; /* chunksize of each element, if all same */ - size_t contents_size; /* total size of elements */ - size_t array_size; /* request size of pointer array */ - void* mem; /* malloced aggregate space */ - mchunkptr p; /* corresponding chunk */ - size_t remainder_size; /* remaining bytes while splitting */ - void** marray; /* either "chunks" or malloced ptr array */ - mchunkptr array_chunk; /* chunk for malloced ptr array */ - flag_t was_enabled; /* to disable mmap */ - size_t size; - size_t i; - - /* compute array length, if needed */ - if (chunks != 0) { - if (n_elements == 0) - return chunks; /* nothing to do */ - marray = chunks; - array_size = 0; - } - else { - /* if empty req, must still return chunk representing empty array */ - if (n_elements == 0) - return (void**)internal_malloc(m, 0); - marray = 0; - array_size = request2size(n_elements * (sizeof(void*))); - } - - /* compute total element size */ - if (opts & 0x1) { /* all-same-size */ - element_size = request2size(*sizes); - contents_size = n_elements * element_size; - } - else { /* add up all the sizes */ - element_size = 0; - contents_size = 0; - for (i = 0; i != n_elements; ++i) - contents_size += request2size(sizes[i]); - } - - size = contents_size + array_size; - - /* - Allocate the aggregate chunk. First disable direct-mmapping so - malloc won't use it, since we would not be able to later - free/realloc space internal to a segregated mmap region. - */ - was_enabled = use_mmap(m); - disable_mmap(m); - mem = internal_malloc(m, size - CHUNK_OVERHEAD); - if (was_enabled) - enable_mmap(m); - if (mem == 0) - return 0; - - if (PREACTION(m)) return 0; - p = mem2chunk(mem); - remainder_size = chunksize(p); - - assert(!is_mmapped(p)); +static void ** +ialloc (mstate m, size_t n_elements, size_t * sizes, int opts, void *chunks[]) +{ + /* + This provides common support for independent_X routines, handling + all of the combinations that can result. + + The opts arg has: + bit 0 set if all elements are same size (using sizes[0]) + bit 1 set if elements should be zeroed + */ + + size_t element_size; /* chunksize of each element, if all same */ + size_t contents_size; /* total size of elements */ + size_t array_size; /* request size of pointer array */ + void *mem; /* malloced aggregate space */ + mchunkptr p; /* corresponding chunk */ + size_t remainder_size; /* remaining bytes while splitting */ + void **marray; /* either "chunks" or malloced ptr array */ + mchunkptr array_chunk; /* chunk for malloced ptr array */ + flag_t was_enabled; /* to disable mmap */ + size_t size; + size_t i; + + /* compute array length, if needed */ + if (chunks != 0) { + if (n_elements == 0) + return chunks; /* nothing to do */ + marray = chunks; + array_size = 0; + } else { + /* if empty req, must still return chunk representing empty array */ + if (n_elements == 0) + return (void **) internal_malloc (m, 0); + marray = 0; + array_size = request2size (n_elements * (sizeof (void *))); + } - if (opts & 0x2) { /* optionally clear the elements */ - memset((size_t*)mem, 0, remainder_size - SIZE_T_SIZE - array_size); - } + /* compute total element size */ + if (opts & 0x1) { /* all-same-size */ + element_size = request2size (*sizes); + contents_size = n_elements * element_size; + } else { /* add up all the sizes */ + element_size = 0; + contents_size = 0; + for (i = 0; i != n_elements; ++i) + contents_size += request2size (sizes[i]); + } - /* If not provided, allocate the pointer array as final part of chunk */ - if (marray == 0) { - size_t array_chunk_size; - array_chunk = chunk_plus_offset(p, contents_size); - array_chunk_size = remainder_size - contents_size; - marray = (void**) (chunk2mem(array_chunk)); - set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size); - remainder_size = contents_size; - } + size = contents_size + array_size; + + /* + Allocate the aggregate chunk. First disable direct-mmapping so + malloc won't use it, since we would not be able to later + free/realloc space internal to a segregated mmap region. + */ + was_enabled = use_mmap (m); + disable_mmap (m); + mem = internal_malloc (m, size - CHUNK_OVERHEAD); + if (was_enabled) + enable_mmap (m); + if (mem == 0) + return 0; + + if (PREACTION (m)) + return 0; + p = mem2chunk (mem); + remainder_size = chunksize (p); + + assert (!is_mmapped (p)); + + if (opts & 0x2) { /* optionally clear the elements */ + memset ((size_t *) mem, 0, remainder_size - SIZE_T_SIZE - array_size); + } - /* split out elements */ - for (i = 0; ; ++i) { - marray[i] = chunk2mem(p); - if (i != n_elements-1) { - if (element_size != 0) - size = element_size; - else - size = request2size(sizes[i]); - remainder_size -= size; - set_size_and_pinuse_of_inuse_chunk(m, p, size); - p = chunk_plus_offset(p, size); + /* If not provided, allocate the pointer array as final part of chunk */ + if (marray == 0) { + size_t array_chunk_size; + array_chunk = chunk_plus_offset (p, contents_size); + array_chunk_size = remainder_size - contents_size; + marray = (void **) (chunk2mem (array_chunk)); + set_size_and_pinuse_of_inuse_chunk (m, array_chunk, array_chunk_size); + remainder_size = contents_size; } - else { /* the final element absorbs any overallocation slop */ - set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size); - break; + + /* split out elements */ + for (i = 0;; ++i) { + marray[i] = chunk2mem (p); + if (i != n_elements - 1) { + if (element_size != 0) + size = element_size; + else + size = request2size (sizes[i]); + remainder_size -= size; + set_size_and_pinuse_of_inuse_chunk (m, p, size); + p = chunk_plus_offset (p, size); + } else { /* the final element absorbs any overallocation slop */ + set_size_and_pinuse_of_inuse_chunk (m, p, remainder_size); + break; + } } - } #if DEBUG - if (marray != chunks) { - /* final element must have exactly exhausted chunk */ - if (element_size != 0) { - assert(remainder_size == element_size); - } - else { - assert(remainder_size == request2size(sizes[i])); + if (marray != chunks) { + /* final element must have exactly exhausted chunk */ + if (element_size != 0) { + assert (remainder_size == element_size); + } else { + assert (remainder_size == request2size (sizes[i])); + } + check_inuse_chunk (m, mem2chunk (marray)); } - check_inuse_chunk(m, mem2chunk(marray)); - } - for (i = 0; i != n_elements; ++i) - check_inuse_chunk(m, mem2chunk(marray[i])); + for (i = 0; i != n_elements; ++i) + check_inuse_chunk (m, mem2chunk (marray[i])); #endif /* DEBUG */ - POSTACTION(m); - return marray; + POSTACTION (m); + return marray; } @@ -4068,343 +4144,370 @@ static void** ialloc(mstate m, #if !ONLY_MSPACES -void* dlmalloc(size_t bytes) { - /* - Basic algorithm: - If a small request (< 256 bytes minus per-chunk overhead): +void * +dlmalloc (size_t bytes) +{ + /* + Basic algorithm: + If a small request (< 256 bytes minus per-chunk overhead): 1. If one exists, use a remainderless chunk in associated smallbin. - (Remainderless means that there are too few excess bytes to - represent as a chunk.) + (Remainderless means that there are too few excess bytes to + represent as a chunk.) 2. If it is big enough, use the dv chunk, which is normally the - chunk adjacent to the one used for the most recent small request. + chunk adjacent to the one used for the most recent small request. 3. If one exists, split the smallest available chunk in a bin, - saving remainder in dv. + saving remainder in dv. 4. If it is big enough, use the top chunk. 5. If available, get memory from system and use it - Otherwise, for a large request: + Otherwise, for a large request: 1. Find the smallest available binned chunk that fits, and use it - if it is better fitting than dv chunk, splitting if necessary. + if it is better fitting than dv chunk, splitting if necessary. 2. If better fitting than any binned chunk, use the dv chunk. 3. If it is big enough, use the top chunk. 4. If request size >= mmap threshold, try to directly mmap this chunk. 5. If available, get memory from system and use it - The ugly goto's here ensure that postaction occurs along all paths. - */ - - if (!PREACTION(gm)) { - void* mem; - size_t nb; - if (bytes <= MAX_SMALL_REQUEST) { - bindex_t idx; - binmap_t smallbits; - nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); - idx = small_index(nb); - smallbits = gm->smallmap >> idx; - - if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ - mchunkptr b, p; - idx += ~smallbits & 1; /* Uses next bin if idx empty */ - b = smallbin_at(gm, idx); - p = b->fd; - assert(chunksize(p) == small_index2size(idx)); - unlink_first_small_chunk(gm, b, p, idx); - set_inuse_and_pinuse(gm, p, small_index2size(idx)); - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } + The ugly goto's here ensure that postaction occurs along all paths. + */ + + if (!PREACTION (gm)) { + void *mem; + size_t nb; + if (bytes <= MAX_SMALL_REQUEST) { + bindex_t idx; + binmap_t smallbits; + nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request (bytes); + idx = small_index (nb); + smallbits = gm->smallmap >> idx; + + if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ + mchunkptr b, p; + idx += ~smallbits & 1; /* Uses next bin if idx empty */ + b = smallbin_at (gm, idx); + p = b->fd; + assert (chunksize (p) == small_index2size (idx)); + unlink_first_small_chunk (gm, b, p, idx); + set_inuse_and_pinuse (gm, p, small_index2size (idx)); + mem = chunk2mem (p); + check_malloced_chunk (gm, mem, nb); + goto postaction; + } - else if (nb > gm->dvsize) { - if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ - mchunkptr b, p, r; - size_t rsize; - bindex_t i; - binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - b = smallbin_at(gm, i); - p = b->fd; - assert(chunksize(p) == small_index2size(i)); - unlink_first_small_chunk(gm, b, p, i); - rsize = small_index2size(i) - nb; - /* Fit here cannot be remainderless if 4byte sizes */ - if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(gm, p, small_index2size(i)); - else { - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - r = chunk_plus_offset(p, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(gm, r, rsize); - } - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; + else if (nb > gm->dvsize) { + if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ + mchunkptr b, p, r; + size_t rsize; + bindex_t i; + binmap_t leftbits = + (smallbits << idx) & left_bits (idx2bit (idx)); + binmap_t leastbit = least_bit (leftbits); + compute_bit2idx (leastbit, i); + b = smallbin_at (gm, i); + p = b->fd; + assert (chunksize (p) == small_index2size (i)); + unlink_first_small_chunk (gm, b, p, i); + rsize = small_index2size (i) - nb; + /* Fit here cannot be remainderless if 4byte sizes */ + if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse (gm, p, small_index2size (i)); + else { + set_size_and_pinuse_of_inuse_chunk (gm, p, nb); + r = chunk_plus_offset (p, nb); + set_size_and_pinuse_of_free_chunk (r, rsize); + replace_dv (gm, r, rsize); + } + mem = chunk2mem (p); + check_malloced_chunk (gm, mem, nb); + goto postaction; + } + + else if (gm->treemap != 0 + && (mem = tmalloc_small (gm, nb)) != 0) { + check_malloced_chunk (gm, mem, nb); + goto postaction; + } + } + } else if (bytes >= MAX_REQUEST) + nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ + else { + nb = pad_request (bytes); + if (gm->treemap != 0 && (mem = tmalloc_large (gm, nb)) != 0) { + check_malloced_chunk (gm, mem, nb); + goto postaction; + } } - else if (gm->treemap != 0 && (mem = tmalloc_small(gm, nb)) != 0) { - check_malloced_chunk(gm, mem, nb); - goto postaction; + if (nb <= gm->dvsize) { + size_t rsize = gm->dvsize - nb; + mchunkptr p = gm->dv; + if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ + mchunkptr r = gm->dv = chunk_plus_offset (p, nb); + gm->dvsize = rsize; + set_size_and_pinuse_of_free_chunk (r, rsize); + set_size_and_pinuse_of_inuse_chunk (gm, p, nb); + } else { /* exhaust dv */ + size_t dvs = gm->dvsize; + gm->dvsize = 0; + gm->dv = 0; + set_inuse_and_pinuse (gm, p, dvs); + } + mem = chunk2mem (p); + check_malloced_chunk (gm, mem, nb); + goto postaction; } - } - } - else if (bytes >= MAX_REQUEST) - nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ - else { - nb = pad_request(bytes); - if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) { - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - } - if (nb <= gm->dvsize) { - size_t rsize = gm->dvsize - nb; - mchunkptr p = gm->dv; - if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ - mchunkptr r = gm->dv = chunk_plus_offset(p, nb); - gm->dvsize = rsize; - set_size_and_pinuse_of_free_chunk(r, rsize); - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - } - else { /* exhaust dv */ - size_t dvs = gm->dvsize; - gm->dvsize = 0; - gm->dv = 0; - set_inuse_and_pinuse(gm, p, dvs); - } - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - else if (nb < gm->topsize) { /* Split top */ - size_t rsize = gm->topsize -= nb; - mchunkptr p = gm->top; - mchunkptr r = gm->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - mem = chunk2mem(p); - check_top_chunk(gm, gm->top); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } + else if (nb < gm->topsize) { /* Split top */ + size_t rsize = gm->topsize -= nb; + mchunkptr p = gm->top; + mchunkptr r = gm->top = chunk_plus_offset (p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk (gm, p, nb); + mem = chunk2mem (p); + check_top_chunk (gm, gm->top); + check_malloced_chunk (gm, mem, nb); + goto postaction; + } - mem = sys_alloc(gm, nb); + mem = sys_alloc (gm, nb); - postaction: - POSTACTION(gm); - return mem; - } + postaction: + POSTACTION (gm); + return mem; + } - return 0; + return 0; } -void dlfree(void* mem) { - /* - Consolidate freed chunks with preceeding or succeeding bordering - free chunks, if they exist, and then place in a bin. Intermixed - with special cases for top, dv, mmapped chunks, and usage errors. - */ +void +dlfree (void *mem) +{ + /* + Consolidate freed chunks with preceeding or succeeding bordering + free chunks, if they exist, and then place in a bin. Intermixed + with special cases for top, dv, mmapped chunks, and usage errors. + */ - if (mem != 0) { - mchunkptr p = mem2chunk(mem); + if (mem != 0) { + mchunkptr p = mem2chunk (mem); #if FOOTERS - mstate fm = get_mstate_for(p); - if (!ok_magic(fm)) { - USAGE_ERROR_ACTION(fm, p); - return; - } + mstate fm = get_mstate_for (p); + if (!ok_magic (fm)) { + USAGE_ERROR_ACTION (fm, p); + return; + } #else /* FOOTERS */ #define fm gm #endif /* FOOTERS */ - if (!PREACTION(fm)) { - check_inuse_chunk(fm, p); - if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { - size_t psize = chunksize(p); - mchunkptr next = chunk_plus_offset(p, psize); - if (!pinuse(p)) { - size_t prevsize = p->prev_foot; - if ((prevsize & IS_MMAPPED_BIT) != 0) { - prevsize &= ~IS_MMAPPED_BIT; - psize += prevsize + MMAP_FOOT_PAD; - if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) - fm->footprint -= psize; - goto postaction; - } - else { - mchunkptr prev = chunk_minus_offset(p, prevsize); - psize += prevsize; - p = prev; - if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ - if (p != fm->dv) { - unlink_chunk(fm, p, prevsize); - } - else if ((next->head & INUSE_BITS) == INUSE_BITS) { - fm->dvsize = psize; - set_free_with_pinuse(p, psize, next); - goto postaction; - } + if (!PREACTION (fm)) { + check_inuse_chunk (fm, p); + if (RTCHECK (ok_address (fm, p) && ok_cinuse (p))) { + size_t psize = chunksize (p); + mchunkptr next = chunk_plus_offset (p, psize); + if (!pinuse (p)) { + size_t prevsize = p->prev_foot; + if ((prevsize & IS_MMAPPED_BIT) != 0) { + prevsize &= ~IS_MMAPPED_BIT; + psize += prevsize + MMAP_FOOT_PAD; + if (CALL_MUNMAP ((char *) p - prevsize, psize) == 0) + fm->footprint -= psize; + goto postaction; + } else { + mchunkptr prev = chunk_minus_offset (p, prevsize); + psize += prevsize; + p = prev; + if (RTCHECK (ok_address (fm, prev))) { /* consolidate backward */ + if (p != fm->dv) { + unlink_chunk (fm, p, prevsize); + } else if ((next->head & INUSE_BITS) == + INUSE_BITS) { + fm->dvsize = psize; + set_free_with_pinuse (p, psize, next); + goto postaction; + } + } else + goto erroraction; + } + } + + if (RTCHECK (ok_next (p, next) && ok_pinuse (next))) { + if (!cinuse (next)) { /* consolidate forward */ + if (next == fm->top) { + size_t tsize = fm->topsize += psize; + fm->top = p; + p->head = tsize | PINUSE_BIT; + if (p == fm->dv) { + fm->dv = 0; + fm->dvsize = 0; + } + if (should_trim (fm, tsize)) + sys_trim (fm, 0); + goto postaction; + } else if (next == fm->dv) { + size_t dsize = fm->dvsize += psize; + fm->dv = p; + set_size_and_pinuse_of_free_chunk (p, dsize); + goto postaction; + } else { + size_t nsize = chunksize (next); + psize += nsize; + unlink_chunk (fm, next, nsize); + set_size_and_pinuse_of_free_chunk (p, psize); + if (p == fm->dv) { + fm->dvsize = psize; + goto postaction; + } + } + } else + set_free_with_pinuse (p, psize, next); + insert_chunk (fm, p, psize); + check_free_chunk (fm, p); + goto postaction; + } } - else - goto erroraction; - } + erroraction: + USAGE_ERROR_ACTION (fm, p); + postaction: + POSTACTION (fm); } - - if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { - if (!cinuse(next)) { /* consolidate forward */ - if (next == fm->top) { - size_t tsize = fm->topsize += psize; - fm->top = p; - p->head = tsize | PINUSE_BIT; - if (p == fm->dv) { - fm->dv = 0; - fm->dvsize = 0; - } - if (should_trim(fm, tsize)) - sys_trim(fm, 0); - goto postaction; - } - else if (next == fm->dv) { - size_t dsize = fm->dvsize += psize; - fm->dv = p; - set_size_and_pinuse_of_free_chunk(p, dsize); - goto postaction; - } - else { - size_t nsize = chunksize(next); - psize += nsize; - unlink_chunk(fm, next, nsize); - set_size_and_pinuse_of_free_chunk(p, psize); - if (p == fm->dv) { - fm->dvsize = psize; - goto postaction; - } - } - } - else - set_free_with_pinuse(p, psize, next); - insert_chunk(fm, p, psize); - check_free_chunk(fm, p); - goto postaction; - } - } - erroraction: - USAGE_ERROR_ACTION(fm, p); - postaction: - POSTACTION(fm); } - } #if !FOOTERS #undef fm #endif /* FOOTERS */ } -void* dlcalloc(size_t n_elements, size_t elem_size) { - void* mem; - size_t req = 0; - if (n_elements != 0) { - req = n_elements * elem_size; - if (((n_elements | elem_size) & ~(size_t)0xffff) && - (req / n_elements != elem_size)) - req = MAX_SIZE_T; /* force downstream failure on overflow */ - } - mem = dlmalloc(req); - if (mem != 0 && calloc_must_clear(mem2chunk(mem))) - memset(mem, 0, req); - return mem; +void * +dlcalloc (size_t n_elements, size_t elem_size) +{ + void *mem; + size_t req = 0; + if (n_elements != 0) { + req = n_elements * elem_size; + if (((n_elements | elem_size) & ~(size_t) 0xffff) && + (req / n_elements != elem_size)) + req = MAX_SIZE_T; /* force downstream failure on overflow */ + } + mem = dlmalloc (req); + if (mem != 0 && calloc_must_clear (mem2chunk (mem))) + memset (mem, 0, req); + return mem; } -void* dlrealloc(void* oldmem, size_t bytes) { - if (oldmem == 0) - return dlmalloc(bytes); +void * +dlrealloc (void *oldmem, size_t bytes) +{ + if (oldmem == 0) + return dlmalloc (bytes); #ifdef REALLOC_ZERO_BYTES_FREES - if (bytes == 0) { - dlfree(oldmem); - return 0; - } + if (bytes == 0) { + dlfree (oldmem); + return 0; + } #endif /* REALLOC_ZERO_BYTES_FREES */ - else { + else { #if ! FOOTERS - mstate m = gm; + mstate m = gm; #else /* FOOTERS */ - mstate m = get_mstate_for(mem2chunk(oldmem)); - if (!ok_magic(m)) { - USAGE_ERROR_ACTION(m, oldmem); - return 0; - } + mstate m = get_mstate_for (mem2chunk (oldmem)); + if (!ok_magic (m)) { + USAGE_ERROR_ACTION (m, oldmem); + return 0; + } #endif /* FOOTERS */ - return internal_realloc(m, oldmem, bytes); - } + return internal_realloc (m, oldmem, bytes); + } } -void* dlmemalign(size_t alignment, size_t bytes) { - return internal_memalign(gm, alignment, bytes); +void * +dlmemalign (size_t alignment, size_t bytes) +{ + return internal_memalign (gm, alignment, bytes); } -void** dlindependent_calloc(size_t n_elements, size_t elem_size, - void* chunks[]) { - size_t sz = elem_size; /* serves as 1-element array */ - return ialloc(gm, n_elements, &sz, 3, chunks); +void ** +dlindependent_calloc (size_t n_elements, size_t elem_size, void *chunks[]) +{ + size_t sz = elem_size; /* serves as 1-element array */ + return ialloc (gm, n_elements, &sz, 3, chunks); } -void** dlindependent_comalloc(size_t n_elements, size_t sizes[], - void* chunks[]) { - return ialloc(gm, n_elements, sizes, 0, chunks); +void ** +dlindependent_comalloc (size_t n_elements, size_t sizes[], void *chunks[]) +{ + return ialloc (gm, n_elements, sizes, 0, chunks); } -void* dlvalloc(size_t bytes) { - size_t pagesz; - init_mparams(); - pagesz = mparams.page_size; - return dlmemalign(pagesz, bytes); +void * +dlvalloc (size_t bytes) +{ + size_t pagesz; + init_mparams (); + pagesz = mparams.page_size; + return dlmemalign (pagesz, bytes); } -void* dlpvalloc(size_t bytes) { - size_t pagesz; - init_mparams(); - pagesz = mparams.page_size; - return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); +void * +dlpvalloc (size_t bytes) +{ + size_t pagesz; + init_mparams (); + pagesz = mparams.page_size; + return dlmemalign (pagesz, + (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - + SIZE_T_ONE)); } -int dlmalloc_trim(size_t pad) { - int result = 0; - if (!PREACTION(gm)) { - result = sys_trim(gm, pad); - POSTACTION(gm); - } - return result; +int +dlmalloc_trim (size_t pad) +{ + int result = 0; + if (!PREACTION (gm)) { + result = sys_trim (gm, pad); + POSTACTION (gm); + } + return result; } -size_t dlmalloc_footprint(void) { - return gm->footprint; +size_t +dlmalloc_footprint (void) +{ + return gm->footprint; } -size_t dlmalloc_max_footprint(void) { - return gm->max_footprint; +size_t +dlmalloc_max_footprint (void) +{ + return gm->max_footprint; } #if !NO_MALLINFO -struct mallinfo dlmallinfo(void) { - return internal_mallinfo(gm); +struct mallinfo +dlmallinfo (void) +{ + return internal_mallinfo (gm); } #endif /* NO_MALLINFO */ -void dlmalloc_stats() { - internal_malloc_stats(gm); +void +dlmalloc_stats () +{ + internal_malloc_stats (gm); } -size_t dlmalloc_usable_size(void* mem) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - if (cinuse(p)) - return chunksize(p) - overhead_for(p); - } - return 0; +size_t +dlmalloc_usable_size (void *mem) +{ + if (mem != 0) { + mchunkptr p = mem2chunk (mem); + if (cinuse (p)) + return chunksize (p) - overhead_for (p); + } + return 0; } -int dlmallopt(int param_number, int value) { - return change_mparam(param_number, value); +int +dlmallopt (int param_number, int value) +{ + return change_mparam (param_number, value); } #endif /* !ONLY_MSPACES */ @@ -4413,78 +4516,86 @@ int dlmallopt(int param_number, int value) { #if MSPACES -static mstate init_user_mstate(char* tbase, size_t tsize) { - size_t msize = pad_request(sizeof(struct malloc_state)); - mchunkptr mn; - mchunkptr msp = align_as_chunk(tbase); - mstate m = (mstate)(chunk2mem(msp)); - memset(m, 0, msize); - INITIAL_LOCK(&m->mutex); - msp->head = (msize|PINUSE_BIT|CINUSE_BIT); - m->seg.base = m->least_addr = tbase; - m->seg.size = m->footprint = m->max_footprint = tsize; - m->magic = mparams.magic; - m->mflags = mparams.default_mflags; - disable_contiguous(m); - init_bins(m); - mn = next_chunk(mem2chunk(m)); - init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) - TOP_FOOT_SIZE); - check_top_chunk(m, m->top); - return m; +static mstate +init_user_mstate (char *tbase, size_t tsize) +{ + size_t msize = pad_request (sizeof (struct malloc_state)); + mchunkptr mn; + mchunkptr msp = align_as_chunk (tbase); + mstate m = (mstate) (chunk2mem (msp)); + memset (m, 0, msize); + INITIAL_LOCK (&m->mutex); + msp->head = (msize | PINUSE_BIT | CINUSE_BIT); + m->seg.base = m->least_addr = tbase; + m->seg.size = m->footprint = m->max_footprint = tsize; + m->magic = mparams.magic; + m->mflags = mparams.default_mflags; + disable_contiguous (m); + init_bins (m); + mn = next_chunk (mem2chunk (m)); + init_top (m, mn, + (size_t) ((tbase + tsize) - (char *) mn) - TOP_FOOT_SIZE); + check_top_chunk (m, m->top); + return m; } -mspace create_mspace(size_t capacity, int locked) { - mstate m = 0; - size_t msize = pad_request(sizeof(struct malloc_state)); - init_mparams(); /* Ensure pagesize etc initialized */ - - if (capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { - size_t rs = ((capacity == 0)? mparams.granularity : - (capacity + TOP_FOOT_SIZE + msize)); - size_t tsize = granularity_align(rs); - char* tbase = (char*)(CALL_MMAP(tsize)); - if (tbase != CMFAIL) { - m = init_user_mstate(tbase, tsize); - m->seg.sflags = IS_MMAPPED_BIT; - set_lock(m, locked); +mspace +create_mspace (size_t capacity, int locked) +{ + mstate m = 0; + size_t msize = pad_request (sizeof (struct malloc_state)); + init_mparams (); /* Ensure pagesize etc initialized */ + + if (capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) { + size_t rs = ((capacity == 0) ? mparams.granularity : + (capacity + TOP_FOOT_SIZE + msize)); + size_t tsize = granularity_align (rs); + char *tbase = (char *) (CALL_MMAP (tsize)); + if (tbase != CMFAIL) { + m = init_user_mstate (tbase, tsize); + m->seg.sflags = IS_MMAPPED_BIT; + set_lock (m, locked); + } } - } - return (mspace)m; + return (mspace) m; } -mspace create_mspace_with_base(void* base, size_t capacity, int locked) { - mstate m = 0; - size_t msize = pad_request(sizeof(struct malloc_state)); - init_mparams(); /* Ensure pagesize etc initialized */ - - if (capacity > msize + TOP_FOOT_SIZE && - capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { - m = init_user_mstate((char*)base, capacity); - m->seg.sflags = EXTERN_BIT; - set_lock(m, locked); - } - return (mspace)m; +mspace +create_mspace_with_base (void *base, size_t capacity, int locked) +{ + mstate m = 0; + size_t msize = pad_request (sizeof (struct malloc_state)); + init_mparams (); /* Ensure pagesize etc initialized */ + + if (capacity > msize + TOP_FOOT_SIZE && + capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) { + m = init_user_mstate ((char *) base, capacity); + m->seg.sflags = EXTERN_BIT; + set_lock (m, locked); + } + return (mspace) m; } -size_t destroy_mspace(mspace msp) { - size_t freed = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - msegmentptr sp = &ms->seg; - while (sp != 0) { - char* base = sp->base; - size_t size = sp->size; - flag_t flag = sp->sflags; - sp = sp->next; - if ((flag & IS_MMAPPED_BIT) && !(flag & EXTERN_BIT) && - CALL_MUNMAP(base, size) == 0) - freed += size; +size_t +destroy_mspace (mspace msp) +{ + size_t freed = 0; + mstate ms = (mstate) msp; + if (ok_magic (ms)) { + msegmentptr sp = &ms->seg; + while (sp != 0) { + char *base = sp->base; + size_t size = sp->size; + flag_t flag = sp->sflags; + sp = sp->next; + if ((flag & IS_MMAPPED_BIT) && !(flag & EXTERN_BIT) && + CALL_MUNMAP (base, size) == 0) + freed += size; + } + } else { + USAGE_ERROR_ACTION (ms, ms); } - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return freed; + return freed; } /* @@ -4493,344 +4604,363 @@ size_t destroy_mspace(mspace msp) { */ -void* mspace_malloc(mspace msp, size_t bytes) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - if (!PREACTION(ms)) { - void* mem; - size_t nb; - if (bytes <= MAX_SMALL_REQUEST) { - bindex_t idx; - binmap_t smallbits; - nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); - idx = small_index(nb); - smallbits = ms->smallmap >> idx; - - if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ - mchunkptr b, p; - idx += ~smallbits & 1; /* Uses next bin if idx empty */ - b = smallbin_at(ms, idx); - p = b->fd; - assert(chunksize(p) == small_index2size(idx)); - unlink_first_small_chunk(ms, b, p, idx); - set_inuse_and_pinuse(ms, p, small_index2size(idx)); - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } +void * +mspace_malloc (mspace msp, size_t bytes) +{ + mstate ms = (mstate) msp; + if (!ok_magic (ms)) { + USAGE_ERROR_ACTION (ms, ms); + return 0; + } + if (!PREACTION (ms)) { + void *mem; + size_t nb; + if (bytes <= MAX_SMALL_REQUEST) { + bindex_t idx; + binmap_t smallbits; + nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request (bytes); + idx = small_index (nb); + smallbits = ms->smallmap >> idx; + + if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ + mchunkptr b, p; + idx += ~smallbits & 1; /* Uses next bin if idx empty */ + b = smallbin_at (ms, idx); + p = b->fd; + assert (chunksize (p) == small_index2size (idx)); + unlink_first_small_chunk (ms, b, p, idx); + set_inuse_and_pinuse (ms, p, small_index2size (idx)); + mem = chunk2mem (p); + check_malloced_chunk (ms, mem, nb); + goto postaction; + } - else if (nb > ms->dvsize) { - if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ - mchunkptr b, p, r; - size_t rsize; - bindex_t i; - binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - b = smallbin_at(ms, i); - p = b->fd; - assert(chunksize(p) == small_index2size(i)); - unlink_first_small_chunk(ms, b, p, i); - rsize = small_index2size(i) - nb; - /* Fit here cannot be remainderless if 4byte sizes */ - if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(ms, p, small_index2size(i)); - else { - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - r = chunk_plus_offset(p, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(ms, r, rsize); - } - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; + else if (nb > ms->dvsize) { + if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ + mchunkptr b, p, r; + size_t rsize; + bindex_t i; + binmap_t leftbits = + (smallbits << idx) & left_bits (idx2bit (idx)); + binmap_t leastbit = least_bit (leftbits); + compute_bit2idx (leastbit, i); + b = smallbin_at (ms, i); + p = b->fd; + assert (chunksize (p) == small_index2size (i)); + unlink_first_small_chunk (ms, b, p, i); + rsize = small_index2size (i) - nb; + /* Fit here cannot be remainderless if 4byte sizes */ + if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse (ms, p, small_index2size (i)); + else { + set_size_and_pinuse_of_inuse_chunk (ms, p, nb); + r = chunk_plus_offset (p, nb); + set_size_and_pinuse_of_free_chunk (r, rsize); + replace_dv (ms, r, rsize); + } + mem = chunk2mem (p); + check_malloced_chunk (ms, mem, nb); + goto postaction; + } + + else if (ms->treemap != 0 + && (mem = tmalloc_small (ms, nb)) != 0) { + check_malloced_chunk (ms, mem, nb); + goto postaction; + } + } + } else if (bytes >= MAX_REQUEST) + nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ + else { + nb = pad_request (bytes); + if (ms->treemap != 0 && (mem = tmalloc_large (ms, nb)) != 0) { + check_malloced_chunk (ms, mem, nb); + goto postaction; + } } - else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) { - check_malloced_chunk(ms, mem, nb); - goto postaction; + if (nb <= ms->dvsize) { + size_t rsize = ms->dvsize - nb; + mchunkptr p = ms->dv; + if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ + mchunkptr r = ms->dv = chunk_plus_offset (p, nb); + ms->dvsize = rsize; + set_size_and_pinuse_of_free_chunk (r, rsize); + set_size_and_pinuse_of_inuse_chunk (ms, p, nb); + } else { /* exhaust dv */ + size_t dvs = ms->dvsize; + ms->dvsize = 0; + ms->dv = 0; + set_inuse_and_pinuse (ms, p, dvs); + } + mem = chunk2mem (p); + check_malloced_chunk (ms, mem, nb); + goto postaction; } - } - } - else if (bytes >= MAX_REQUEST) - nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ - else { - nb = pad_request(bytes); - if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - } - if (nb <= ms->dvsize) { - size_t rsize = ms->dvsize - nb; - mchunkptr p = ms->dv; - if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ - mchunkptr r = ms->dv = chunk_plus_offset(p, nb); - ms->dvsize = rsize; - set_size_and_pinuse_of_free_chunk(r, rsize); - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - } - else { /* exhaust dv */ - size_t dvs = ms->dvsize; - ms->dvsize = 0; - ms->dv = 0; - set_inuse_and_pinuse(ms, p, dvs); - } - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - else if (nb < ms->topsize) { /* Split top */ - size_t rsize = ms->topsize -= nb; - mchunkptr p = ms->top; - mchunkptr r = ms->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - mem = chunk2mem(p); - check_top_chunk(ms, ms->top); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } + else if (nb < ms->topsize) { /* Split top */ + size_t rsize = ms->topsize -= nb; + mchunkptr p = ms->top; + mchunkptr r = ms->top = chunk_plus_offset (p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk (ms, p, nb); + mem = chunk2mem (p); + check_top_chunk (ms, ms->top); + check_malloced_chunk (ms, mem, nb); + goto postaction; + } - mem = sys_alloc(ms, nb); + mem = sys_alloc (ms, nb); - postaction: - POSTACTION(ms); - return mem; - } + postaction: + POSTACTION (ms); + return mem; + } - return 0; + return 0; } -void mspace_free(mspace msp, void* mem) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); +void +mspace_free (mspace msp, void *mem) +{ + if (mem != 0) { + mchunkptr p = mem2chunk (mem); #if FOOTERS - mstate fm = get_mstate_for(p); + mstate fm = get_mstate_for (p); #else /* FOOTERS */ - mstate fm = (mstate)msp; + mstate fm = (mstate) msp; #endif /* FOOTERS */ - if (!ok_magic(fm)) { - USAGE_ERROR_ACTION(fm, p); - return; - } - if (!PREACTION(fm)) { - check_inuse_chunk(fm, p); - if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { - size_t psize = chunksize(p); - mchunkptr next = chunk_plus_offset(p, psize); - if (!pinuse(p)) { - size_t prevsize = p->prev_foot; - if ((prevsize & IS_MMAPPED_BIT) != 0) { - prevsize &= ~IS_MMAPPED_BIT; - psize += prevsize + MMAP_FOOT_PAD; - if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) - fm->footprint -= psize; - goto postaction; - } - else { - mchunkptr prev = chunk_minus_offset(p, prevsize); - psize += prevsize; - p = prev; - if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ - if (p != fm->dv) { - unlink_chunk(fm, p, prevsize); - } - else if ((next->head & INUSE_BITS) == INUSE_BITS) { - fm->dvsize = psize; - set_free_with_pinuse(p, psize, next); - goto postaction; - } - } - else - goto erroraction; - } + if (!ok_magic (fm)) { + USAGE_ERROR_ACTION (fm, p); + return; } - - if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { - if (!cinuse(next)) { /* consolidate forward */ - if (next == fm->top) { - size_t tsize = fm->topsize += psize; - fm->top = p; - p->head = tsize | PINUSE_BIT; - if (p == fm->dv) { - fm->dv = 0; - fm->dvsize = 0; - } - if (should_trim(fm, tsize)) - sys_trim(fm, 0); - goto postaction; - } - else if (next == fm->dv) { - size_t dsize = fm->dvsize += psize; - fm->dv = p; - set_size_and_pinuse_of_free_chunk(p, dsize); - goto postaction; + if (!PREACTION (fm)) { + check_inuse_chunk (fm, p); + if (RTCHECK (ok_address (fm, p) && ok_cinuse (p))) { + size_t psize = chunksize (p); + mchunkptr next = chunk_plus_offset (p, psize); + if (!pinuse (p)) { + size_t prevsize = p->prev_foot; + if ((prevsize & IS_MMAPPED_BIT) != 0) { + prevsize &= ~IS_MMAPPED_BIT; + psize += prevsize + MMAP_FOOT_PAD; + if (CALL_MUNMAP ((char *) p - prevsize, psize) == 0) + fm->footprint -= psize; + goto postaction; + } else { + mchunkptr prev = chunk_minus_offset (p, prevsize); + psize += prevsize; + p = prev; + if (RTCHECK (ok_address (fm, prev))) { /* consolidate backward */ + if (p != fm->dv) { + unlink_chunk (fm, p, prevsize); + } else if ((next->head & INUSE_BITS) == + INUSE_BITS) { + fm->dvsize = psize; + set_free_with_pinuse (p, psize, next); + goto postaction; + } + } else + goto erroraction; + } + } + + if (RTCHECK (ok_next (p, next) && ok_pinuse (next))) { + if (!cinuse (next)) { /* consolidate forward */ + if (next == fm->top) { + size_t tsize = fm->topsize += psize; + fm->top = p; + p->head = tsize | PINUSE_BIT; + if (p == fm->dv) { + fm->dv = 0; + fm->dvsize = 0; + } + if (should_trim (fm, tsize)) + sys_trim (fm, 0); + goto postaction; + } else if (next == fm->dv) { + size_t dsize = fm->dvsize += psize; + fm->dv = p; + set_size_and_pinuse_of_free_chunk (p, dsize); + goto postaction; + } else { + size_t nsize = chunksize (next); + psize += nsize; + unlink_chunk (fm, next, nsize); + set_size_and_pinuse_of_free_chunk (p, psize); + if (p == fm->dv) { + fm->dvsize = psize; + goto postaction; + } + } + } else + set_free_with_pinuse (p, psize, next); + insert_chunk (fm, p, psize); + check_free_chunk (fm, p); + goto postaction; + } } - else { - size_t nsize = chunksize(next); - psize += nsize; - unlink_chunk(fm, next, nsize); - set_size_and_pinuse_of_free_chunk(p, psize); - if (p == fm->dv) { - fm->dvsize = psize; - goto postaction; - } - } - } - else - set_free_with_pinuse(p, psize, next); - insert_chunk(fm, p, psize); - check_free_chunk(fm, p); - goto postaction; + erroraction: + USAGE_ERROR_ACTION (fm, p); + postaction: + POSTACTION (fm); } - } - erroraction: - USAGE_ERROR_ACTION(fm, p); - postaction: - POSTACTION(fm); } - } } -void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size) { - void* mem; - size_t req = 0; - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - if (n_elements != 0) { - req = n_elements * elem_size; - if (((n_elements | elem_size) & ~(size_t)0xffff) && - (req / n_elements != elem_size)) - req = MAX_SIZE_T; /* force downstream failure on overflow */ - } - mem = internal_malloc(ms, req); - if (mem != 0 && calloc_must_clear(mem2chunk(mem))) - memset(mem, 0, req); - return mem; +void * +mspace_calloc (mspace msp, size_t n_elements, size_t elem_size) +{ + void *mem; + size_t req = 0; + mstate ms = (mstate) msp; + if (!ok_magic (ms)) { + USAGE_ERROR_ACTION (ms, ms); + return 0; + } + if (n_elements != 0) { + req = n_elements * elem_size; + if (((n_elements | elem_size) & ~(size_t) 0xffff) && + (req / n_elements != elem_size)) + req = MAX_SIZE_T; /* force downstream failure on overflow */ + } + mem = internal_malloc (ms, req); + if (mem != 0 && calloc_must_clear (mem2chunk (mem))) + memset (mem, 0, req); + return mem; } -void* mspace_realloc(mspace msp, void* oldmem, size_t bytes) { - if (oldmem == 0) - return mspace_malloc(msp, bytes); +void * +mspace_realloc (mspace msp, void *oldmem, size_t bytes) +{ + if (oldmem == 0) + return mspace_malloc (msp, bytes); #ifdef REALLOC_ZERO_BYTES_FREES - if (bytes == 0) { - mspace_free(msp, oldmem); - return 0; - } + if (bytes == 0) { + mspace_free (msp, oldmem); + return 0; + } #endif /* REALLOC_ZERO_BYTES_FREES */ - else { + else { #if FOOTERS - mchunkptr p = mem2chunk(oldmem); - mstate ms = get_mstate_for(p); + mchunkptr p = mem2chunk (oldmem); + mstate ms = get_mstate_for (p); #else /* FOOTERS */ - mstate ms = (mstate)msp; + mstate ms = (mstate) msp; #endif /* FOOTERS */ - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; + if (!ok_magic (ms)) { + USAGE_ERROR_ACTION (ms, ms); + return 0; + } + return internal_realloc (ms, oldmem, bytes); } - return internal_realloc(ms, oldmem, bytes); - } } -void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - return internal_memalign(ms, alignment, bytes); +void * +mspace_memalign (mspace msp, size_t alignment, size_t bytes) +{ + mstate ms = (mstate) msp; + if (!ok_magic (ms)) { + USAGE_ERROR_ACTION (ms, ms); + return 0; + } + return internal_memalign (ms, alignment, bytes); } -void** mspace_independent_calloc(mspace msp, size_t n_elements, - size_t elem_size, void* chunks[]) { - size_t sz = elem_size; /* serves as 1-element array */ - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - return ialloc(ms, n_elements, &sz, 3, chunks); +void ** +mspace_independent_calloc (mspace msp, size_t n_elements, + size_t elem_size, void *chunks[]) +{ + size_t sz = elem_size; /* serves as 1-element array */ + mstate ms = (mstate) msp; + if (!ok_magic (ms)) { + USAGE_ERROR_ACTION (ms, ms); + return 0; + } + return ialloc (ms, n_elements, &sz, 3, chunks); } -void** mspace_independent_comalloc(mspace msp, size_t n_elements, - size_t sizes[], void* chunks[]) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - return ialloc(ms, n_elements, sizes, 0, chunks); +void ** +mspace_independent_comalloc (mspace msp, size_t n_elements, + size_t sizes[], void *chunks[]) +{ + mstate ms = (mstate) msp; + if (!ok_magic (ms)) { + USAGE_ERROR_ACTION (ms, ms); + return 0; + } + return ialloc (ms, n_elements, sizes, 0, chunks); } -int mspace_trim(mspace msp, size_t pad) { - int result = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - if (!PREACTION(ms)) { - result = sys_trim(ms, pad); - POSTACTION(ms); +int +mspace_trim (mspace msp, size_t pad) +{ + int result = 0; + mstate ms = (mstate) msp; + if (ok_magic (ms)) { + if (!PREACTION (ms)) { + result = sys_trim (ms, pad); + POSTACTION (ms); + } + } else { + USAGE_ERROR_ACTION (ms, ms); } - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return result; + return result; } -void mspace_malloc_stats(mspace msp) { - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - internal_malloc_stats(ms); - } - else { - USAGE_ERROR_ACTION(ms,ms); - } +void +mspace_malloc_stats (mspace msp) +{ + mstate ms = (mstate) msp; + if (ok_magic (ms)) { + internal_malloc_stats (ms); + } else { + USAGE_ERROR_ACTION (ms, ms); + } } -size_t mspace_footprint(mspace msp) { - size_t result; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - result = ms->footprint; - } - USAGE_ERROR_ACTION(ms,ms); - return result; +size_t +mspace_footprint (mspace msp) +{ + size_t result; + mstate ms = (mstate) msp; + if (ok_magic (ms)) { + result = ms->footprint; + } + USAGE_ERROR_ACTION (ms, ms); + return result; } -size_t mspace_max_footprint(mspace msp) { - size_t result; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - result = ms->max_footprint; - } - USAGE_ERROR_ACTION(ms,ms); - return result; +size_t +mspace_max_footprint (mspace msp) +{ + size_t result; + mstate ms = (mstate) msp; + if (ok_magic (ms)) { + result = ms->max_footprint; + } + USAGE_ERROR_ACTION (ms, ms); + return result; } #if !NO_MALLINFO -struct mallinfo mspace_mallinfo(mspace msp) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - } - return internal_mallinfo(ms); +struct mallinfo +mspace_mallinfo (mspace msp) +{ + mstate ms = (mstate) msp; + if (!ok_magic (ms)) { + USAGE_ERROR_ACTION (ms, ms); + } + return internal_mallinfo (ms); } #endif /* NO_MALLINFO */ -int mspace_mallopt(int param_number, int value) { - return change_mparam(param_number, value); +int +mspace_mallopt (int param_number, int value) +{ + return change_mparam (param_number, value); } #endif /* MSPACES */ @@ -5109,3 +5239,4 @@ int mspace_mallopt(int param_number, int value) { */ #endif /* !HAVE_MALLOC */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 9278d2579..f59404f70 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -60,7 +60,7 @@ #ifndef HAVE_QSORT -static char _ID[]=""; +static char _ID[] = ""; /* How many bytes are there per word? (Must be a power of 2, * and must in fact equal sizeof(int).) @@ -81,7 +81,7 @@ static char _ID[]=""; */ #define TRUNC_nonaligned 12 #define TRUNC_aligned 12 -#define TRUNC_words 12*WORD_BYTES /* nb different meaning */ +#define TRUNC_words 12*WORD_BYTES /* nb different meaning */ /* We use a simple pivoting algorithm for shortish sub-arrays * and a more complicated one for larger ones. The threshold @@ -89,7 +89,11 @@ static char _ID[]=""; */ #define PIVOT_THRESHOLD 40 -typedef struct { char * first; char * last; } stack_entry; +typedef struct +{ + char *first; + char *last; +} stack_entry; #define pushLeft {stack[stacktop].first=ffirst;stack[stacktop++].last=last;} #define pushRight {stack[stacktop].first=first;stack[stacktop++].last=llast;} #define doLeft {first=ffirst;llast=last;continue;} @@ -261,165 +265,187 @@ typedef struct { char * first; char * last; } stack_entry; /* ---------------------------------------------------------------------- */ -static char * pivot_big(char *first, char *mid, char *last, size_t size, - int compare(const void *, const void *)) { - size_t d=(((last-first)/size)>>3)*size; - char *m1,*m2,*m3; - { char *a=first, *b=first+d, *c=first+2*d; +static char * +pivot_big (char *first, char *mid, char *last, size_t size, + int compare (const void *, const void *)) +{ + size_t d = (((last - first) / size) >> 3) * size; + char *m1, *m2, *m3; + { + char *a = first, *b = first + d, *c = first + 2 * d; #ifdef DEBUG_QSORT -fprintf(stderr,"< %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); + fprintf (stderr, "< %d %d %d\n", *(int *) a, *(int *) b, *(int *) c); #endif - m1 = compare(a,b)<0 ? - (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) - : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b)); - } - { char *a=mid-d, *b=mid, *c=mid+d; + m1 = compare (a, b) < 0 ? + (compare (b, c) < 0 ? b : (compare (a, c) < 0 ? c : a)) + : (compare (a, c) < 0 ? a : (compare (b, c) < 0 ? c : b)); + } + { + char *a = mid - d, *b = mid, *c = mid + d; #ifdef DEBUG_QSORT -fprintf(stderr,". %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); + fprintf (stderr, ". %d %d %d\n", *(int *) a, *(int *) b, *(int *) c); #endif - m2 = compare(a,b)<0 ? - (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) - : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b)); - } - { char *a=last-2*d, *b=last-d, *c=last; + m2 = compare (a, b) < 0 ? + (compare (b, c) < 0 ? b : (compare (a, c) < 0 ? c : a)) + : (compare (a, c) < 0 ? a : (compare (b, c) < 0 ? c : b)); + } + { + char *a = last - 2 * d, *b = last - d, *c = last; #ifdef DEBUG_QSORT -fprintf(stderr,"> %d %d %d\n",*(int*)a,*(int*)b,*(int*)c); + fprintf (stderr, "> %d %d %d\n", *(int *) a, *(int *) b, *(int *) c); #endif - m3 = compare(a,b)<0 ? - (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) - : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b)); - } + m3 = compare (a, b) < 0 ? + (compare (b, c) < 0 ? b : (compare (a, c) < 0 ? c : a)) + : (compare (a, c) < 0 ? a : (compare (b, c) < 0 ? c : b)); + } #ifdef DEBUG_QSORT -fprintf(stderr,"-> %d %d %d\n",*(int*)m1,*(int*)m2,*(int*)m3); + fprintf (stderr, "-> %d %d %d\n", *(int *) m1, *(int *) m2, *(int *) m3); #endif - return compare(m1,m2)<0 ? - (compare(m2,m3)<0 ? m2 : (compare(m1,m3)<0 ? m3 : m1)) - : (compare(m1,m3)<0 ? m1 : (compare(m2,m3)<0 ? m3 : m2)); + return compare (m1, m2) < 0 ? + (compare (m2, m3) < 0 ? m2 : (compare (m1, m3) < 0 ? m3 : m1)) + : (compare (m1, m3) < 0 ? m1 : (compare (m2, m3) < 0 ? m3 : m2)); } /* ---------------------------------------------------------------------- */ -static void qsort_nonaligned(void *base, size_t nmemb, size_t size, - int (*compare)(const void *, const void *)) { - - stack_entry stack[STACK_SIZE]; - int stacktop=0; - char *first,*last; - char *pivot=malloc(size); - size_t trunc=TRUNC_nonaligned*size; - assert(pivot!=0); - - first=(char*)base; last=first+(nmemb-1)*size; - - if ((size_t)(last-first)>trunc) { - char *ffirst=first, *llast=last; - while (1) { - /* Select pivot */ - { char * mid=first+size*((last-first)/size >> 1); - Pivot(SWAP_nonaligned,size); - memcpy(pivot,mid,size); - } - /* Partition. */ - Partition(SWAP_nonaligned,size); - /* Prepare to recurse/iterate. */ - Recurse(trunc) +static void +qsort_nonaligned (void *base, size_t nmemb, size_t size, + int (*compare) (const void *, const void *)) +{ + + stack_entry stack[STACK_SIZE]; + int stacktop = 0; + char *first, *last; + char *pivot = malloc (size); + size_t trunc = TRUNC_nonaligned * size; + assert (pivot != 0); + + first = (char *) base; + last = first + (nmemb - 1) * size; + + if ((size_t) (last - first) > trunc) { + char *ffirst = first, *llast = last; + while (1) { + /* Select pivot */ + { + char *mid = first + size * ((last - first) / size >> 1); + Pivot (SWAP_nonaligned, size); + memcpy (pivot, mid, size); + } + /* Partition. */ + Partition (SWAP_nonaligned, size); + /* Prepare to recurse/iterate. */ + Recurse (trunc)} } - } - PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size); - Insertion(SWAP_nonaligned); - free(pivot); + PreInsertion (SWAP_nonaligned, TRUNC_nonaligned, size); + Insertion (SWAP_nonaligned); + free (pivot); } -static void qsort_aligned(void *base, size_t nmemb, size_t size, - int (*compare)(const void *, const void *)) { - - stack_entry stack[STACK_SIZE]; - int stacktop=0; - char *first,*last; - char *pivot=malloc(size); - size_t trunc=TRUNC_aligned*size; - assert(pivot!=0); - - first=(char*)base; last=first+(nmemb-1)*size; - - if ((size_t)(last-first)>trunc) { - char *ffirst=first,*llast=last; - while (1) { - /* Select pivot */ - { char * mid=first+size*((last-first)/size >> 1); - Pivot(SWAP_aligned,size); - memcpy(pivot,mid,size); - } - /* Partition. */ - Partition(SWAP_aligned,size); - /* Prepare to recurse/iterate. */ - Recurse(trunc) +static void +qsort_aligned (void *base, size_t nmemb, size_t size, + int (*compare) (const void *, const void *)) +{ + + stack_entry stack[STACK_SIZE]; + int stacktop = 0; + char *first, *last; + char *pivot = malloc (size); + size_t trunc = TRUNC_aligned * size; + assert (pivot != 0); + + first = (char *) base; + last = first + (nmemb - 1) * size; + + if ((size_t) (last - first) > trunc) { + char *ffirst = first, *llast = last; + while (1) { + /* Select pivot */ + { + char *mid = first + size * ((last - first) / size >> 1); + Pivot (SWAP_aligned, size); + memcpy (pivot, mid, size); + } + /* Partition. */ + Partition (SWAP_aligned, size); + /* Prepare to recurse/iterate. */ + Recurse (trunc)} } - } - PreInsertion(SWAP_aligned,TRUNC_aligned,size); - Insertion(SWAP_aligned); - free(pivot); + PreInsertion (SWAP_aligned, TRUNC_aligned, size); + Insertion (SWAP_aligned); + free (pivot); } -static void qsort_words(void *base, size_t nmemb, - int (*compare)(const void *, const void *)) { +static void +qsort_words (void *base, size_t nmemb, + int (*compare) (const void *, const void *)) +{ - stack_entry stack[STACK_SIZE]; - int stacktop=0; - char *first,*last; - char *pivot=malloc(WORD_BYTES); - assert(pivot!=0); + stack_entry stack[STACK_SIZE]; + int stacktop = 0; + char *first, *last; + char *pivot = malloc (WORD_BYTES); + assert (pivot != 0); - first=(char*)base; last=first+(nmemb-1)*WORD_BYTES; + first = (char *) base; + last = first + (nmemb - 1) * WORD_BYTES; - if (last-first>TRUNC_words) { - char *ffirst=first, *llast=last; - while (1) { + if (last - first > TRUNC_words) { + char *ffirst = first, *llast = last; + while (1) { #ifdef DEBUG_QSORT -fprintf(stderr,"Doing %d:%d: ", - (first-(char*)base)/WORD_BYTES, - (last-(char*)base)/WORD_BYTES); + fprintf (stderr, "Doing %d:%d: ", + (first - (char *) base) / WORD_BYTES, + (last - (char *) base) / WORD_BYTES); #endif - /* Select pivot */ - { char * mid=first+WORD_BYTES*((last-first) / (2*WORD_BYTES)); - Pivot(SWAP_words,WORD_BYTES); - *(int*)pivot=*(int*)mid; - } + /* Select pivot */ + { + char *mid = + first + WORD_BYTES * ((last - first) / (2 * WORD_BYTES)); + Pivot (SWAP_words, WORD_BYTES); + *(int *) pivot = *(int *) mid; + } #ifdef DEBUG_QSORT -fprintf(stderr,"pivot=%d\n",*(int*)pivot); + fprintf (stderr, "pivot=%d\n", *(int *) pivot); #endif - /* Partition. */ - Partition(SWAP_words,WORD_BYTES); - /* Prepare to recurse/iterate. */ - Recurse(TRUNC_words) + /* Partition. */ + Partition (SWAP_words, WORD_BYTES); + /* Prepare to recurse/iterate. */ + Recurse (TRUNC_words)} } - } - PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES); - /* Now do insertion sort. */ - last=((char*)base)+nmemb*WORD_BYTES; - for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) { - /* Find the right place for |first|. My apologies for var reuse */ - int *pl=(int*)(first-WORD_BYTES),*pr=(int*)first; - *(int*)pivot=*(int*)first; - for (;compare(pl,pivot)>0;pr=pl,--pl) { - *pr=*pl; } - if (pr!=(int*)first) *pr=*(int*)pivot; - } - free(pivot); + PreInsertion (SWAP_words, (TRUNC_words / WORD_BYTES), WORD_BYTES); + /* Now do insertion sort. */ + last = ((char *) base) + nmemb * WORD_BYTES; + for (first = ((char *) base) + WORD_BYTES; first != last; + first += WORD_BYTES) { + /* Find the right place for |first|. My apologies for var reuse */ + int *pl = (int *) (first - WORD_BYTES), *pr = (int *) first; + *(int *) pivot = *(int *) first; + for (; compare (pl, pivot) > 0; pr = pl, --pl) { + *pr = *pl; + } + if (pr != (int *) first) + *pr = *(int *) pivot; + } + free (pivot); } /* ---------------------------------------------------------------------- */ -void qsort(void *base, size_t nmemb, size_t size, - int (*compare)(const void *, const void *)) { - - if (nmemb<=1) return; - if (((uintptr_t)base|size)&(WORD_BYTES-1)) - qsort_nonaligned(base,nmemb,size,compare); - else if (size!=WORD_BYTES) - qsort_aligned(base,nmemb,size,compare); - else - qsort_words(base,nmemb,compare); +void +qsort (void *base, size_t nmemb, size_t size, + int (*compare) (const void *, const void *)) +{ + + if (nmemb <= 1) + return; + if (((uintptr_t) base | size) & (WORD_BYTES - 1)) + qsort_nonaligned (base, nmemb, size, compare); + else if (size != WORD_BYTES) + qsort_aligned (base, nmemb, size, compare); + else + qsort_words (base, nmemb, compare); } #endif /* !HAVE_QSORT */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index b9c3bacc6..2d9f2dbfb 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -33,588 +33,368 @@ #ifndef __FLTUSED__ #define __FLTUSED__ #ifdef __cplusplus - extern "C" +extern "C" #endif - __declspec(selectany) int _fltused=1; +__declspec (selectany) + int _fltused = 1; #endif /* Float to long */ -void __declspec(naked) _ftol() + void __declspec (naked) _ftol () { - __asm { - push ebp - mov ebp,esp - sub esp,20h - and esp,0FFFFFFF0h - fld st(0) - fst dword ptr [esp+18h] - fistp qword ptr [esp+10h] - fild qword ptr [esp+10h] - mov edx,dword ptr [esp+18h] - mov eax,dword ptr [esp+10h] - test eax,eax - je integer_QnaN_or_zero -arg_is_not_integer_QnaN: - fsubp st(1),st - test edx,edx - jns positive - fstp dword ptr [esp] - mov ecx,dword ptr [esp] - xor ecx,80000000h - add ecx,7FFFFFFFh - adc eax,0 - mov edx,dword ptr [esp+14h] - adc edx,0 - jmp localexit -positive: - fstp dword ptr [esp] - mov ecx,dword ptr [esp] - add ecx,7FFFFFFFh - sbb eax,0 - mov edx,dword ptr [esp+14h] - sbb edx,0 - jmp localexit -integer_QnaN_or_zero: - mov edx,dword ptr [esp+14h] - test edx,7FFFFFFFh - jne arg_is_not_integer_QnaN - fstp dword ptr [esp+18h] - fstp dword ptr [esp+18h] -localexit: - leave - ret - } + __asm { + push ebp mov ebp, esp sub esp, 20 h and esp, 0F FFFFFF0h fld st (0) + fst dword ptr[esp + 18 h] + fistp qword ptr[esp + 10 h] + fild qword ptr[esp + 10 h] + mov edx, dword ptr[esp + 18 h] + mov eax, dword ptr[esp + 10 h] + test eax, eax + je integer_QnaN_or_zero + arg_is_not_integer_QnaN:fsubp st (1), st + test edx, edx jns positive fstp dword ptr[esp] + mov ecx, dword ptr[esp] + xor ecx, 80000000 h + add ecx, 7F FFFFFFh adc eax, 0 mov edx, dword ptr[esp + 14 h] + adc edx, 0 jmp localexit positive:fstp dword ptr[esp] + mov ecx, dword ptr[esp] + add ecx, 7F FFFFFFh sbb eax, 0 mov edx, dword ptr[esp + 14 h] + sbb edx, 0 + jmp localexit integer_QnaN_or_zero:mov edx, dword ptr[esp + 14 h] + test edx, 7F FFFFFFh + jne arg_is_not_integer_QnaN fstp dword ptr[esp + 18 h] + fstp dword ptr[esp + 18 h] localexit:leave ret} } -void __declspec(naked) _ftol2_sse() +void +__declspec (naked) +_ftol2_sse () { - _ftol(); + _ftol (); } /* 64-bit math operators for 32-bit systems */ -void __declspec(naked) _allmul() +void +__declspec (naked) +_allmul () { - __asm { - push ebp - mov ebp,esp - push edi - push esi - push ebx - sub esp,0Ch - mov eax,dword ptr [ebp+10h] - mov edi,dword ptr [ebp+8] - mov ebx,eax - mov esi,eax - sar esi,1Fh - mov eax,dword ptr [ebp+8] - mul ebx - imul edi,esi - mov ecx,edx - mov dword ptr [ebp-18h],eax - mov edx,dword ptr [ebp+0Ch] - add ecx,edi - imul ebx,edx - mov eax,dword ptr [ebp-18h] - lea ebx,[ebx+ecx] - mov dword ptr [ebp-14h],ebx - mov edx,dword ptr [ebp-14h] - add esp,0Ch - pop ebx - pop esi - pop edi - pop ebp - ret - } + __asm { + push ebp + mov ebp, esp + push edi + push esi push ebx sub esp, 0 Ch mov eax, dword ptr[ebp + 10 h] + mov edi, dword ptr[ebp + 8] + mov ebx, eax mov esi, eax sar esi, 1F h mov eax, dword ptr[ebp + 8] + mul ebx + imul edi, esi + mov ecx, edx + mov dword ptr[ebp - 18 h], eax mov edx, dword ptr[ebp + 0 Ch] + add ecx, edi imul ebx, edx mov eax, dword ptr[ebp - 18 h] + lea ebx,[ebx + ecx] + mov dword ptr[ebp - 14 h], ebx mov edx, dword ptr[ebp - 14 h] + add esp, 0 Ch pop ebx pop esi pop edi pop ebp ret} } -void __declspec(naked) _alldiv() +void +__declspec (naked) +_alldiv () { - __asm { - push edi - push esi - push ebx - xor edi,edi - mov eax,dword ptr [esp+14h] - or eax,eax - jge L1 - inc edi - mov edx,dword ptr [esp+10h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+14h],eax - mov dword ptr [esp+10h],edx -L1: - mov eax,dword ptr [esp+1Ch] - or eax,eax - jge L2 - inc edi - mov edx,dword ptr [esp+18h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+1Ch],eax - mov dword ptr [esp+18h],edx -L2: - or eax,eax - jne L3 - mov ecx,dword ptr [esp+18h] - mov eax,dword ptr [esp+14h] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+10h] - div ecx - mov edx,ebx - jmp L4 -L3: - mov ebx,eax - mov ecx,dword ptr [esp+18h] - mov edx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] -L5: - shr ebx,1 - rcr ecx,1 - shr edx,1 - rcr eax,1 - or ebx,ebx - jne L5 - div ecx - mov esi,eax - mul dword ptr [esp+1Ch] - mov ecx,eax - mov eax,dword ptr [esp+18h] - mul esi - add edx,ecx - jb L6 - cmp edx,dword ptr [esp+14h] - ja L6 - jb L7 - cmp eax,dword ptr [esp+10h] - jbe L7 -L6: - dec esi -L7: - xor edx,edx - mov eax,esi -L4: - dec edi - jne L8 - neg edx - neg eax - sbb edx,0 -L8: - pop ebx - pop esi - pop edi - ret 10h - } + __asm { + push edi push esi push ebx xor edi, edi mov eax, dword ptr[esp + 14 h] + or eax, eax jge L1 inc edi mov edx, dword ptr[esp + 10 h] + neg eax + neg edx + sbb eax, 0 + mov dword ptr[esp + 14 h], eax + mov dword ptr[esp + 10 h], edx L1:mov eax, dword ptr[esp + 1 Ch] + or eax, eax jge L2 inc edi mov edx, dword ptr[esp + 18 h] + neg eax + neg edx + sbb eax, 0 + mov dword ptr[esp + 1 Ch], eax + mov dword ptr[esp + 18 h], edx + L2:or eax, eax jne L3 mov ecx, dword ptr[esp + 18 h] + mov eax, dword ptr[esp + 14 h] + xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 10 h] + div ecx + mov edx, ebx jmp L4 L3:mov ebx, eax mov ecx, dword ptr[esp + 18 h] + mov edx, dword ptr[esp + 14 h] + mov eax, dword ptr[esp + 10 h] + + + + + + + + L5:shr ebx, 1 + rcr ecx, 1 + shr edx, 1 + rcr eax, 1 + or ebx, ebx jne L5 div ecx mov esi, eax mul dword ptr[esp + 1 Ch] + mov ecx, eax mov eax, dword ptr[esp + 18 h] + mul esi add edx, ecx jb L6 cmp edx, dword ptr[esp + 14 h] + ja L6 jb L7 cmp eax, dword ptr[esp + 10 h] + jbe L7 + L6:dec esi + L7:xor edx, edx + mov eax, esi + L4:dec edi + jne L8 + neg edx neg eax sbb edx, 0 L8:pop ebx pop esi pop edi ret 10 h} } -void __declspec(naked) _aulldiv() +void +__declspec (naked) +_aulldiv () { - __asm { - push ebx - push esi - mov eax,dword ptr [esp+18h] - or eax,eax - jne L1 - mov ecx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+0Ch] - div ecx - mov edx,ebx - jmp L2 -L1: - mov ecx,eax - mov ebx,dword ptr [esp+14h] - mov edx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] -L3: - shr ecx,1 - rcr ebx,1 - shr edx,1 - rcr eax,1 - or ecx,ecx - jne L3 - div ebx - mov esi,eax - mul dword ptr [esp+18h] - mov ecx,eax - mov eax,dword ptr [esp+14h] - mul esi - add edx,ecx - jb L4 - cmp edx,dword ptr [esp+10h] - ja L4 - jb L5 - cmp eax,dword ptr [esp+0Ch] - jbe L5 -L4: - dec esi -L5: - xor edx,edx - mov eax,esi -L2: - pop esi - pop ebx - ret 10h - } + __asm { + push ebx push esi mov eax, dword ptr[esp + 18 h] + or eax, eax jne L1 mov ecx, dword ptr[esp + 14 h] + mov eax, dword ptr[esp + 10 h] + xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 0 Ch] + div ecx + mov edx, ebx jmp L2 L1:mov ecx, eax mov ebx, dword ptr[esp + 14 h] + mov edx, dword ptr[esp + 10 h] + mov eax, dword ptr[esp + 0 Ch] + + + + + + + + L3:shr ecx, 1 + rcr ebx, 1 + shr edx, 1 + rcr eax, 1 + or ecx, ecx jne L3 div ebx mov esi, eax mul dword ptr[esp + 18 h] + mov ecx, eax mov eax, dword ptr[esp + 14 h] + mul esi add edx, ecx jb L4 cmp edx, dword ptr[esp + 10 h] + ja L4 jb L5 cmp eax, dword ptr[esp + 0 Ch] + jbe L5 + L4:dec esi + L5:xor edx, edx mov eax, esi L2:pop esi pop ebx ret 10 h} } -void __declspec(naked) _allrem() +void +__declspec (naked) +_allrem () { - __asm { - push ebx - push edi - xor edi,edi - mov eax,dword ptr [esp+10h] - or eax,eax - jge L1 - inc edi - mov edx,dword ptr [esp+0Ch] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+10h],eax - mov dword ptr [esp+0Ch],edx -L1: - mov eax,dword ptr [esp+18h] - or eax,eax - jge L2 - mov edx,dword ptr [esp+14h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+18h],eax - mov dword ptr [esp+14h],edx -L2: - or eax,eax - jne L3 - mov ecx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] - xor edx,edx - div ecx - mov eax,dword ptr [esp+0Ch] - div ecx - mov eax,edx - xor edx,edx - dec edi - jns L4 - jmp L8 -L3: - mov ebx,eax - mov ecx,dword ptr [esp+14h] - mov edx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] -L5: - shr ebx,1 - rcr ecx,1 - shr edx,1 - rcr eax,1 - or ebx,ebx - jne L5 - div ecx - mov ecx,eax - mul dword ptr [esp+18h] - xchg eax,ecx - mul dword ptr [esp+14h] - add edx,ecx - jb L6 - cmp edx,dword ptr [esp+10h] - ja L6 - jb L7 - cmp eax,dword ptr [esp+0Ch] - jbe L7 -L6: - sub eax,dword ptr [esp+14h] - sbb edx,dword ptr [esp+18h] -L7: - sub eax,dword ptr [esp+0Ch] - sbb edx,dword ptr [esp+10h] - dec edi - jns L8 -L4: - neg edx - neg eax - sbb edx,0 -L8: - pop edi - pop ebx - ret 10h - } + __asm { + push ebx push edi xor edi, edi mov eax, dword ptr[esp + 10 h] + or eax, eax jge L1 inc edi mov edx, dword ptr[esp + 0 Ch] + neg eax + neg edx + sbb eax, 0 + mov dword ptr[esp + 10 h], eax + mov dword ptr[esp + 0 Ch], edx L1:mov eax, dword ptr[esp + 18 h] + or eax, eax jge L2 mov edx, dword ptr[esp + 14 h] + neg eax + neg edx + sbb eax, 0 + mov dword ptr[esp + 18 h], eax + mov dword ptr[esp + 14 h], edx + L2:or eax, eax jne L3 mov ecx, dword ptr[esp + 14 h] + mov eax, dword ptr[esp + 10 h] + xor edx, edx div ecx mov eax, dword ptr[esp + 0 Ch] + div ecx + mov eax, edx + xor edx, edx + dec edi + jns L4 jmp L8 L3:mov ebx, eax mov ecx, dword ptr[esp + 14 h] + mov edx, dword ptr[esp + 10 h] + mov eax, dword ptr[esp + 0 Ch] + + + + + + + + L5:shr ebx, 1 + rcr ecx, 1 + shr edx, 1 + rcr eax, 1 + or ebx, ebx jne L5 div ecx mov ecx, eax mul dword ptr[esp + 18 h] + xchg eax, ecx mul dword ptr[esp + 14 h] + add edx, ecx jb L6 cmp edx, dword ptr[esp + 10 h] + ja L6 jb L7 cmp eax, dword ptr[esp + 0 Ch] + jbe L7 L6:sub eax, dword ptr[esp + 14 h] + sbb edx, dword ptr[esp + 18 h] + L7:sub eax, dword ptr[esp + 0 Ch] + sbb edx, dword ptr[esp + 10 h] + dec edi + jns L8 L4:neg edx neg eax sbb edx, 0 L8:pop edi pop ebx ret 10 h} } -void __declspec(naked) _aullrem() +void +__declspec (naked) +_aullrem () { - __asm { - push ebx - mov eax,dword ptr [esp+14h] - or eax,eax - jne L1 - mov ecx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] - xor edx,edx - div ecx - mov eax,dword ptr [esp+8] - div ecx - mov eax,edx - xor edx,edx - jmp L2 -L1: - mov ecx,eax - mov ebx,dword ptr [esp+10h] - mov edx,dword ptr [esp+0Ch] - mov eax,dword ptr [esp+8] -L3: - shr ecx,1 - rcr ebx,1 - shr edx,1 - rcr eax,1 - or ecx,ecx - jne L3 - div ebx - mov ecx,eax - mul dword ptr [esp+14h] - xchg eax,ecx - mul dword ptr [esp+10h] - add edx,ecx - jb L4 - cmp edx,dword ptr [esp+0Ch] - ja L4 - jb L5 - cmp eax,dword ptr [esp+8] - jbe L5 -L4: - sub eax,dword ptr [esp+10h] - sbb edx,dword ptr [esp+14h] -L5: - sub eax,dword ptr [esp+8] - sbb edx,dword ptr [esp+0Ch] - neg edx - neg eax - sbb edx,0 -L2: - pop ebx - ret 10h - } + __asm { + push ebx mov eax, dword ptr[esp + 14 h] + or eax, eax jne L1 mov ecx, dword ptr[esp + 10 h] + mov eax, dword ptr[esp + 0 Ch] + xor edx, edx div ecx mov eax, dword ptr[esp + 8] + div ecx + mov eax, edx + xor edx, edx jmp L2 L1:mov ecx, eax mov ebx, dword ptr[esp + 10 h] + mov edx, dword ptr[esp + 0 Ch] + mov eax, dword ptr[esp + 8] + + + + + + + + L3:shr ecx, 1 + rcr ebx, 1 + shr edx, 1 + rcr eax, 1 + or ecx, ecx jne L3 div ebx mov ecx, eax mul dword ptr[esp + 14 h] + xchg eax, ecx mul dword ptr[esp + 10 h] + add edx, ecx jb L4 cmp edx, dword ptr[esp + 0 Ch] + ja L4 jb L5 cmp eax, dword ptr[esp + 8] + jbe L5 L4:sub eax, dword ptr[esp + 10 h] + sbb edx, dword ptr[esp + 14 h] + L5:sub eax, dword ptr[esp + 8] + sbb edx, dword ptr[esp + 0 Ch] + neg edx neg eax sbb edx, 0 L2:pop ebx ret 10 h} } -void __declspec(naked) _alldvrm() +void +__declspec (naked) +_alldvrm () { - __asm { - push edi - push esi - push ebp - xor edi,edi - xor ebp,ebp - mov eax,dword ptr [esp+14h] - or eax,eax - jge L1 - inc edi - inc ebp - mov edx,dword ptr [esp+10h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+14h],eax - mov dword ptr [esp+10h],edx -L1: - mov eax,dword ptr [esp+1Ch] - or eax,eax - jge L2 - inc edi - mov edx,dword ptr [esp+18h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+1Ch],eax - mov dword ptr [esp+18h],edx -L2: - or eax,eax - jne L3 - mov ecx,dword ptr [esp+18h] - mov eax,dword ptr [esp+14h] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+10h] - div ecx - mov esi,eax - mov eax,ebx - mul dword ptr [esp+18h] - mov ecx,eax - mov eax,esi - mul dword ptr [esp+18h] - add edx,ecx - jmp L4 -L3: - mov ebx,eax - mov ecx,dword ptr [esp+18h] - mov edx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] -L5: - shr ebx,1 - rcr ecx,1 - shr edx,1 - rcr eax,1 - or ebx,ebx - jne L5 - div ecx - mov esi,eax - mul dword ptr [esp+1Ch] - mov ecx,eax - mov eax,dword ptr [esp+18h] - mul esi - add edx,ecx - jb L6 - cmp edx,dword ptr [esp+14h] - ja L6 - jb L7 - cmp eax,dword ptr [esp+10h] - jbe L7 -L6: - dec esi - sub eax,dword ptr [esp+18h] - sbb edx,dword ptr [esp+1Ch] -L7: - xor ebx,ebx -L4: - sub eax,dword ptr [esp+10h] - sbb edx,dword ptr [esp+14h] - dec ebp - jns L9 - neg edx - neg eax - sbb edx,0 -L9: - mov ecx,edx - mov edx,ebx - mov ebx,ecx - mov ecx,eax - mov eax,esi - dec edi - jne L8 - neg edx - neg eax - sbb edx,0 -L8: - pop ebp - pop esi - pop edi - ret 10h - } + __asm { + push edi + push esi + push ebp xor edi, edi xor ebp, ebp mov eax, dword ptr[esp + 14 h] + or eax, eax jge L1 inc edi inc ebp mov edx, dword ptr[esp + 10 h] + neg eax + neg edx + sbb eax, 0 + mov dword ptr[esp + 14 h], eax + mov dword ptr[esp + 10 h], edx L1:mov eax, dword ptr[esp + 1 Ch] + or eax, eax jge L2 inc edi mov edx, dword ptr[esp + 18 h] + neg eax + neg edx + sbb eax, 0 + mov dword ptr[esp + 1 Ch], eax + mov dword ptr[esp + 18 h], edx + L2:or eax, eax jne L3 mov ecx, dword ptr[esp + 18 h] + mov eax, dword ptr[esp + 14 h] + xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 10 h] + div ecx mov esi, eax mov eax, ebx mul dword ptr[esp + 18 h] + mov ecx, eax mov eax, esi mul dword ptr[esp + 18 h] + add edx, ecx jmp L4 L3:mov ebx, eax mov ecx, dword ptr[esp + 18 h] + mov edx, dword ptr[esp + 14 h] + mov eax, dword ptr[esp + 10 h] + + + + + + + + L5:shr ebx, 1 + rcr ecx, 1 + shr edx, 1 + rcr eax, 1 + or ebx, ebx jne L5 div ecx mov esi, eax mul dword ptr[esp + 1 Ch] + mov ecx, eax mov eax, dword ptr[esp + 18 h] + mul esi add edx, ecx jb L6 cmp edx, dword ptr[esp + 14 h] + ja L6 jb L7 cmp eax, dword ptr[esp + 10 h] + jbe L7 L6:dec esi sub eax, dword ptr[esp + 18 h] + sbb edx, dword ptr[esp + 1 Ch] + L7:xor ebx, ebx L4:sub eax, dword ptr[esp + 10 h] + sbb edx, dword ptr[esp + 14 h] + dec ebp + jns L9 + neg edx + neg eax + sbb edx, 0 + L9:mov ecx, edx + mov edx, ebx + mov ebx, ecx + mov ecx, eax + mov eax, esi + dec edi + jne L8 + neg edx neg eax sbb edx, 0 L8:pop ebp pop esi pop edi ret 10 h} } -void __declspec(naked) _aulldvrm() +void +__declspec (naked) +_aulldvrm () { - __asm { - push esi - mov eax,dword ptr [esp+14h] - or eax,eax - jne L1 - mov ecx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+8] - div ecx - mov esi,eax - mov eax,ebx - mul dword ptr [esp+10h] - mov ecx,eax - mov eax,esi - mul dword ptr [esp+10h] - add edx,ecx - jmp L2 -L1: - mov ecx,eax - mov ebx,dword ptr [esp+10h] - mov edx,dword ptr [esp+0Ch] - mov eax,dword ptr [esp+8] -L3: - shr ecx,1 - rcr ebx,1 - shr edx,1 - rcr eax,1 - or ecx,ecx - jne L3 - div ebx - mov esi,eax - mul dword ptr [esp+14h] - mov ecx,eax - mov eax,dword ptr [esp+10h] - mul esi - add edx,ecx - jb L4 - cmp edx,dword ptr [esp+0Ch] - ja L4 - jb L5 - cmp eax,dword ptr [esp+8] - jbe L5 -L4: - dec esi - sub eax,dword ptr [esp+10h] - sbb edx,dword ptr [esp+14h] -L5: - xor ebx,ebx -L2: - sub eax,dword ptr [esp+8] - sbb edx,dword ptr [esp+0Ch] - neg edx - neg eax - sbb edx,0 - mov ecx,edx - mov edx,ebx - mov ebx,ecx - mov ecx,eax - mov eax,esi - pop esi - ret 10h - } + __asm { + push esi mov eax, dword ptr[esp + 14 h] + or eax, eax jne L1 mov ecx, dword ptr[esp + 10 h] + mov eax, dword ptr[esp + 0 Ch] + xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 8] + div ecx mov esi, eax mov eax, ebx mul dword ptr[esp + 10 h] + mov ecx, eax mov eax, esi mul dword ptr[esp + 10 h] + add edx, ecx jmp L2 L1:mov ecx, eax mov ebx, dword ptr[esp + 10 h] + mov edx, dword ptr[esp + 0 Ch] + mov eax, dword ptr[esp + 8] + + + + + + + + L3:shr ecx, 1 + rcr ebx, 1 + shr edx, 1 + rcr eax, 1 + or ecx, ecx jne L3 div ebx mov esi, eax mul dword ptr[esp + 14 h] + mov ecx, eax mov eax, dword ptr[esp + 10 h] + mul esi add edx, ecx jb L4 cmp edx, dword ptr[esp + 0 Ch] + ja L4 jb L5 cmp eax, dword ptr[esp + 8] + jbe L5 L4:dec esi sub eax, dword ptr[esp + 10 h] + sbb edx, dword ptr[esp + 14 h] + L5:xor ebx, ebx L2:sub eax, dword ptr[esp + 8] + sbb edx, dword ptr[esp + 0 Ch] + neg edx + neg eax + sbb edx, 0 + mov ecx, edx + mov edx, ebx + mov ebx, ecx mov ecx, eax mov eax, esi pop esi ret 10 h} } -void __declspec(naked) _allshl() +void +__declspec (naked) +_allshl () { - __asm { - cmp cl,40h - jae RETZERO - cmp cl,20h - jae MORE32 - shld edx,eax,cl - shl eax,cl - ret -MORE32: - mov edx,eax - xor eax,eax - and cl,1Fh - shl edx,cl - ret -RETZERO: - xor eax,eax - xor edx,edx - ret - } + __asm { + cmp cl, 40 h + jae RETZERO + cmp cl, 20 h + jae MORE32 + shld edx, eax, cl + shl eax, cl + ret + MORE32:mov edx, eax + xor eax, eax + and cl, 1F h + shl edx, cl ret RETZERO:xor eax, eax xor edx, edx ret} } -void __declspec(naked) _aullshr() +void +__declspec (naked) +_aullshr () { - __asm { - cmp cl,40h - jae RETZERO - cmp cl,20h - jae MORE32 - shrd eax,edx,cl - shr edx,cl - ret -MORE32: - mov eax,edx - xor edx,edx - and cl,1Fh - shr eax,cl - ret -RETZERO: - xor eax,eax - xor edx,edx - ret - } + __asm { + cmp cl, 40 h + jae RETZERO + cmp cl, 20 h + jae MORE32 + shrd eax, edx, cl + shr edx, cl + ret + MORE32:mov eax, edx + xor edx, edx + and cl, 1F h + shr eax, cl ret RETZERO:xor eax, eax xor edx, edx ret} } -#endif /* MSC_VER */ +#endif /* MSC_VER */ -#endif /* !HAVE_LIBC */ +#endif /* !HAVE_LIBC */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index b36b64998..e88eef354 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -30,26 +30,27 @@ #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) -static size_t SDL_ScanLong(const char *text, int radix, long *valuep) +static size_t +SDL_ScanLong (const char *text, int radix, long *valuep) { const char *textstart = text; long value = 0; SDL_bool negative = SDL_FALSE; - if ( *text == '-' ) { + if (*text == '-') { negative = SDL_TRUE; ++text; } - if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { + if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) { text += 2; } - for ( ; ; ) { + for (;;) { int v; - if ( SDL_isdigit(*text) ) { + if (SDL_isdigit (*text)) { v = *text - '0'; - } else if ( radix == 16 && SDL_isupperhex(*text) ) { + } else if (radix == 16 && SDL_isupperhex (*text)) { v = 10 + (*text - 'A'); - } else if ( radix == 16 && SDL_islowerhex(*text) ) { + } else if (radix == 16 && SDL_islowerhex (*text)) { v = 10 + (*text - 'a'); } else { break; @@ -58,8 +59,8 @@ static size_t SDL_ScanLong(const char *text, int radix, long *valuep) value += v; ++text; } - if ( valuep ) { - if ( negative && value ) { + if (valuep) { + if (negative && value) { *valuep = -value; } else { *valuep = value; @@ -70,21 +71,22 @@ static size_t SDL_ScanLong(const char *text, int radix, long *valuep) #endif #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) -static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) +static size_t +SDL_ScanUnsignedLong (const char *text, int radix, unsigned long *valuep) { const char *textstart = text; unsigned long value = 0; - if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { + if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) { text += 2; } - for ( ; ; ) { + for (;;) { int v; - if ( SDL_isdigit(*text) ) { + if (SDL_isdigit (*text)) { v = *text - '0'; - } else if ( radix == 16 && SDL_isupperhex(*text) ) { + } else if (radix == 16 && SDL_isupperhex (*text)) { v = 10 + (*text - 'A'); - } else if ( radix == 16 && SDL_islowerhex(*text) ) { + } else if (radix == 16 && SDL_islowerhex (*text)) { v = 10 + (*text - 'a'); } else { break; @@ -93,7 +95,7 @@ static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *v value += v; ++text; } - if ( valuep ) { + if (valuep) { *valuep = value; } return (text - textstart); @@ -101,21 +103,22 @@ static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *v #endif #ifndef HAVE_SSCANF -static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep) +static size_t +SDL_ScanUintPtrT (const char *text, int radix, uintptr_t * valuep) { const char *textstart = text; uintptr_t value = 0; - if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { + if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) { text += 2; } - for ( ; ; ) { + for (;;) { int v; - if ( SDL_isdigit(*text) ) { + if (SDL_isdigit (*text)) { v = *text - '0'; - } else if ( radix == 16 && SDL_isupperhex(*text) ) { + } else if (radix == 16 && SDL_isupperhex (*text)) { v = 10 + (*text - 'A'); - } else if ( radix == 16 && SDL_islowerhex(*text) ) { + } else if (radix == 16 && SDL_islowerhex (*text)) { v = 10 + (*text - 'a'); } else { break; @@ -124,7 +127,7 @@ static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep) value += v; ++text; } - if ( valuep ) { + if (valuep) { *valuep = value; } return (text - textstart); @@ -133,26 +136,27 @@ static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep) #ifdef SDL_HAS_64BIT_TYPE #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL) -static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep) +static size_t +SDL_ScanLongLong (const char *text, int radix, Sint64 * valuep) { const char *textstart = text; Sint64 value = 0; SDL_bool negative = SDL_FALSE; - if ( *text == '-' ) { + if (*text == '-') { negative = SDL_TRUE; ++text; } - if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { + if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) { text += 2; } - for ( ; ; ) { + for (;;) { int v; - if ( SDL_isdigit(*text) ) { + if (SDL_isdigit (*text)) { v = *text - '0'; - } else if ( radix == 16 && SDL_isupperhex(*text) ) { + } else if (radix == 16 && SDL_isupperhex (*text)) { v = 10 + (*text - 'A'); - } else if ( radix == 16 && SDL_islowerhex(*text) ) { + } else if (radix == 16 && SDL_islowerhex (*text)) { v = 10 + (*text - 'a'); } else { break; @@ -161,8 +165,8 @@ static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep) value += v; ++text; } - if ( valuep ) { - if ( negative && value ) { + if (valuep) { + if (negative && value) { *valuep = -value; } else { *valuep = value; @@ -173,21 +177,22 @@ static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep) #endif #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL) -static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep) +static size_t +SDL_ScanUnsignedLongLong (const char *text, int radix, Uint64 * valuep) { const char *textstart = text; Uint64 value = 0; - if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { + if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) { text += 2; } - for ( ; ; ) { + for (;;) { int v; - if ( SDL_isdigit(*text) ) { + if (SDL_isdigit (*text)) { v = *text - '0'; - } else if ( radix == 16 && SDL_isupperhex(*text) ) { + } else if (radix == 16 && SDL_isupperhex (*text)) { v = 10 + (*text - 'A'); - } else if ( radix == 16 && SDL_islowerhex(*text) ) { + } else if (radix == 16 && SDL_islowerhex (*text)) { v = 10 + (*text - 'a'); } else { break; @@ -196,7 +201,7 @@ static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valu value += v; ++text; } - if ( valuep ) { + if (valuep) { *valuep = value; } return (text - textstart); @@ -205,31 +210,32 @@ static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valu #endif /* SDL_HAS_64BIT_TYPE */ #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD) -static size_t SDL_ScanFloat(const char *text, double *valuep) +static size_t +SDL_ScanFloat (const char *text, double *valuep) { const char *textstart = text; unsigned long lvalue = 0; double value = 0.0; SDL_bool negative = SDL_FALSE; - if ( *text == '-' ) { + if (*text == '-') { negative = SDL_TRUE; ++text; } - text += SDL_ScanUnsignedLong(text, 10, &lvalue); + text += SDL_ScanUnsignedLong (text, 10, &lvalue); value += lvalue; - if ( *text == '.' ) { + if (*text == '.') { int mult = 10; ++text; - while ( SDL_isdigit(*text) ) { + while (SDL_isdigit (*text)) { lvalue = *text - '0'; - value += (double)lvalue / mult; + value += (double) lvalue / mult; mult *= 10; ++text; } } - if ( valuep ) { - if ( negative && value ) { + if (valuep) { + if (negative && value) { *valuep = -value; } else { *valuep = value; @@ -240,31 +246,32 @@ static size_t SDL_ScanFloat(const char *text, double *valuep) #endif #ifndef SDL_memset -void *SDL_memset(void *dst, int c, size_t len) +void * +SDL_memset (void *dst, int c, size_t len) { size_t left = (len % 4); - if ( len >= 4 ) { + if (len >= 4) { Uint32 value = 0; - Uint32 *dstp = (Uint32 *)dst; + Uint32 *dstp = (Uint32 *) dst; int i; for (i = 0; i < 4; ++i) { value <<= 8; value |= c; } len /= 4; - while ( len-- ) { + while (len--) { *dstp++ = value; } } - if ( left > 0 ) { - Uint8 value = (Uint8)c; - Uint8 *dstp = (Uint8 *)dst; - switch(left) { - case 3: + if (left > 0) { + Uint8 value = (Uint8) c; + Uint8 *dstp = (Uint8 *) dst; + switch (left) { + case 3: *dstp++ = value; - case 2: + case 2: *dstp++ = value; - case 1: + case 1: *dstp++ = value; } } @@ -273,11 +280,12 @@ void *SDL_memset(void *dst, int c, size_t len) #endif #ifndef SDL_memcpy -void *SDL_memcpy(void *dst, const void *src, size_t len) +void * +SDL_memcpy (void *dst, const void *src, size_t len) { - char *srcp = (char *)src; - char *dstp = (char *)dst; - while ( len-- ) { + char *srcp = (char *) src; + char *dstp = (char *) dst; + while (len--) { *dstp++ = *srcp++; } return dst; @@ -285,13 +293,14 @@ void *SDL_memcpy(void *dst, const void *src, size_t len) #endif #ifndef SDL_revcpy -void *SDL_revcpy(void *dst, const void *src, size_t len) +void * +SDL_revcpy (void *dst, const void *src, size_t len) { - char *srcp = (char *)src; - char *dstp = (char *)dst; + char *srcp = (char *) src; + char *dstp = (char *) dst; srcp += len; dstp += len; - while ( len-- ) { + while (len--) { *dstp-- = *srcp--; } return dst; @@ -299,26 +308,28 @@ void *SDL_revcpy(void *dst, const void *src, size_t len) #endif #ifndef SDL_memcmp -int SDL_memcmp(const void *s1, const void *s2, size_t len) +int +SDL_memcmp (const void *s1, const void *s2, size_t len) { - char *s1p = (char *)s1; - char *s2p = (char *)s2; - while ( len-- ) { - if ( *s1p != *s2p ) { + char *s1p = (char *) s1; + char *s2p = (char *) s2; + while (len--) { + if (*s1p != *s2p) { return (*s1p - *s2p); - } - ++s1p; - ++s2p; + } + ++s1p; + ++s2p; } return 0; } #endif #ifndef HAVE_STRLEN -size_t SDL_strlen(const char *string) +size_t +SDL_strlen (const char *string) { size_t len = 0; - while ( *string++ ) { + while (*string++) { ++len; } return len; @@ -326,12 +337,13 @@ size_t SDL_strlen(const char *string) #endif #ifndef HAVE_STRLCPY -size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) +size_t +SDL_strlcpy (char *dst, const char *src, size_t maxlen) { - size_t srclen = SDL_strlen(src); - if ( maxlen > 0 ) { - size_t len = SDL_min(srclen, maxlen-1); - SDL_memcpy(dst, src, len); + size_t srclen = SDL_strlen (src); + if (maxlen > 0) { + size_t len = SDL_min (srclen, maxlen - 1); + SDL_memcpy (dst, src, len); dst[len] = '\0'; } return srclen; @@ -339,37 +351,40 @@ size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) #endif #ifndef HAVE_STRLCAT -size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) +size_t +SDL_strlcat (char *dst, const char *src, size_t maxlen) { - size_t dstlen = SDL_strlen(dst); - size_t srclen = SDL_strlen(src); - if ( dstlen < maxlen ) { - SDL_strlcpy(dst+dstlen, src, maxlen-dstlen); + size_t dstlen = SDL_strlen (dst); + size_t srclen = SDL_strlen (src); + if (dstlen < maxlen) { + SDL_strlcpy (dst + dstlen, src, maxlen - dstlen); } - return dstlen+srclen; + return dstlen + srclen; } #endif #ifndef HAVE_STRDUP -char *SDL_strdup(const char *string) +char * +SDL_strdup (const char *string) { - size_t len = SDL_strlen(string)+1; - char *newstr = SDL_malloc(len); - if ( newstr ) { - SDL_strlcpy(newstr, string, len); + size_t len = SDL_strlen (string) + 1; + char *newstr = SDL_malloc (len); + if (newstr) { + SDL_strlcpy (newstr, string, len); } return newstr; } #endif #ifndef HAVE__STRREV -char *SDL_strrev(char *string) +char * +SDL_strrev (char *string) { - size_t len = SDL_strlen(string); + size_t len = SDL_strlen (string); char *a = &string[0]; - char *b = &string[len-1]; + char *b = &string[len - 1]; len /= 2; - while ( len-- ) { + while (len--) { char c = *a; *a++ = *b; *b-- = c; @@ -379,65 +394,70 @@ char *SDL_strrev(char *string) #endif #ifndef HAVE__STRUPR -char *SDL_strupr(char *string) +char * +SDL_strupr (char *string) { char *bufp = string; - while ( *bufp ) { - *bufp = SDL_toupper(*bufp); - ++bufp; + while (*bufp) { + *bufp = SDL_toupper (*bufp); + ++bufp; } return string; } #endif #ifndef HAVE__STRLWR -char *SDL_strlwr(char *string) +char * +SDL_strlwr (char *string) { char *bufp = string; - while ( *bufp ) { - *bufp = SDL_tolower(*bufp); - ++bufp; + while (*bufp) { + *bufp = SDL_tolower (*bufp); + ++bufp; } return string; } #endif #ifndef HAVE_STRCHR -char *SDL_strchr(const char *string, int c) +char * +SDL_strchr (const char *string, int c) { - while ( *string ) { - if ( *string == c ) { - return (char *)string; + while (*string) { + if (*string == c) { + return (char *) string; } - ++string; + ++string; } return NULL; } #endif #ifndef HAVE_STRRCHR -char *SDL_strrchr(const char *string, int c) +char * +SDL_strrchr (const char *string, int c) { - const char *bufp = string + SDL_strlen(string) - 1; - while ( bufp >= string ) { - if ( *bufp == c ) { - return (char *)bufp; + const char *bufp = string + SDL_strlen (string) - 1; + while (bufp >= string) { + if (*bufp == c) { + return (char *) bufp; } - --bufp; + --bufp; } return NULL; } #endif #ifndef HAVE_STRSTR -char *SDL_strstr(const char *haystack, const char *needle) +char * +SDL_strstr (const char *haystack, const char *needle) { - size_t length = SDL_strlen(needle); - while ( *haystack ) { - if ( SDL_strncmp(haystack, needle, length) == 0 ) { - return (char *)haystack; + size_t length = SDL_strlen (needle); + while (*haystack) { + if (SDL_strncmp (haystack, needle, length) == 0) { + return (char *) haystack; } - ++haystack; + ++haystack; } return NULL; } @@ -454,16 +474,17 @@ static const char ntoa_table[] = { #endif /* ntoa() conversion table */ #ifndef HAVE__LTOA -char *SDL_ltoa(long value, char *string, int radix) +char * +SDL_ltoa (long value, char *string, int radix) { char *bufp = string; - if ( value < 0 ) { + if (value < 0) { *bufp++ = '-'; value = -value; } - if ( value ) { - while ( value > 0 ) { + if (value) { + while (value > 0) { *bufp++ = ntoa_table[value % radix]; value /= radix; } @@ -473,10 +494,10 @@ char *SDL_ltoa(long value, char *string, int radix) *bufp = '\0'; /* The numbers went into the string backwards. :) */ - if ( *string == '-' ) { - SDL_strrev(string+1); + if (*string == '-') { + SDL_strrev (string + 1); } else { - SDL_strrev(string); + SDL_strrev (string); } return string; @@ -484,12 +505,13 @@ char *SDL_ltoa(long value, char *string, int radix) #endif #ifndef HAVE__ULTOA -char *SDL_ultoa(unsigned long value, char *string, int radix) +char * +SDL_ultoa (unsigned long value, char *string, int radix) { char *bufp = string; - if ( value ) { - while ( value > 0 ) { + if (value) { + while (value > 0) { *bufp++ = ntoa_table[value % radix]; value /= radix; } @@ -499,35 +521,37 @@ char *SDL_ultoa(unsigned long value, char *string, int radix) *bufp = '\0'; /* The numbers went into the string backwards. :) */ - SDL_strrev(string); + SDL_strrev (string); return string; } #endif #ifndef HAVE_STRTOL -long SDL_strtol(const char *string, char **endp, int base) +long +SDL_strtol (const char *string, char **endp, int base) { size_t len; long value; - len = SDL_ScanLong(string, base ? base : 10, &value); - if ( endp ) { - *endp = (char *)string + len; + len = SDL_ScanLong (string, base ? base : 10, &value); + if (endp) { + *endp = (char *) string + len; } return value; } #endif #ifndef HAVE_STRTOUL -unsigned long SDL_strtoul(const char *string, char **endp, int base) +unsigned long +SDL_strtoul (const char *string, char **endp, int base) { size_t len; unsigned long value; - len = SDL_ScanUnsignedLong(string, base ? base : 10, &value); - if ( endp ) { - *endp = (char *)string + len; + len = SDL_ScanUnsignedLong (string, base ? base : 10, &value); + if (endp) { + *endp = (char *) string + len; } return value; } @@ -536,16 +560,17 @@ unsigned long SDL_strtoul(const char *string, char **endp, int base) #ifdef SDL_HAS_64BIT_TYPE #ifndef HAVE__I64TOA -char *SDL_lltoa(Sint64 value, char *string, int radix) +char * +SDL_lltoa (Sint64 value, char *string, int radix) { char *bufp = string; - if ( value < 0 ) { + if (value < 0) { *bufp++ = '-'; value = -value; } - if ( value ) { - while ( value > 0 ) { + if (value) { + while (value > 0) { *bufp++ = ntoa_table[value % radix]; value /= radix; } @@ -555,10 +580,10 @@ char *SDL_lltoa(Sint64 value, char *string, int radix) *bufp = '\0'; /* The numbers went into the string backwards. :) */ - if ( *string == '-' ) { - SDL_strrev(string+1); + if (*string == '-') { + SDL_strrev (string + 1); } else { - SDL_strrev(string); + SDL_strrev (string); } return string; @@ -566,12 +591,13 @@ char *SDL_lltoa(Sint64 value, char *string, int radix) #endif #ifndef HAVE__UI64TOA -char *SDL_ulltoa(Uint64 value, char *string, int radix) +char * +SDL_ulltoa (Uint64 value, char *string, int radix) { char *bufp = string; - if ( value ) { - while ( value > 0 ) { + if (value) { + while (value > 0) { *bufp++ = ntoa_table[value % radix]; value /= radix; } @@ -581,35 +607,37 @@ char *SDL_ulltoa(Uint64 value, char *string, int radix) *bufp = '\0'; /* The numbers went into the string backwards. :) */ - SDL_strrev(string); + SDL_strrev (string); return string; } #endif #ifndef HAVE_STRTOLL -Sint64 SDL_strtoll(const char *string, char **endp, int base) +Sint64 +SDL_strtoll (const char *string, char **endp, int base) { size_t len; Sint64 value; - len = SDL_ScanLongLong(string, base ? base : 10, &value); - if ( endp ) { - *endp = (char *)string + len; + len = SDL_ScanLongLong (string, base ? base : 10, &value); + if (endp) { + *endp = (char *) string + len; } return value; } #endif #ifndef HAVE_STRTOULL -Uint64 SDL_strtoull(const char *string, char **endp, int base) +Uint64 +SDL_strtoull (const char *string, char **endp, int base) { size_t len; Uint64 value; - len = SDL_ScanUnsignedLongLong(string, base ? base : 10, &value); - if ( endp ) { - *endp = (char *)string + len; + len = SDL_ScanUnsignedLongLong (string, base ? base : 10, &value); + if (endp) { + *endp = (char *) string + len; } return value; } @@ -618,104 +646,111 @@ Uint64 SDL_strtoull(const char *string, char **endp, int base) #endif /* SDL_HAS_64BIT_TYPE */ #ifndef HAVE_STRTOD -double SDL_strtod(const char *string, char **endp) +double +SDL_strtod (const char *string, char **endp) { size_t len; double value; - len = SDL_ScanFloat(string, &value); - if ( endp ) { - *endp = (char *)string + len; + len = SDL_ScanFloat (string, &value); + if (endp) { + *endp = (char *) string + len; } return value; } #endif #ifndef HAVE_STRCMP -int SDL_strcmp(const char *str1, const char *str2) +int +SDL_strcmp (const char *str1, const char *str2) { while (*str1 && *str2) { - if ( *str1 != *str2 ) + if (*str1 != *str2) break; ++str1; ++str2; } - return (int)((unsigned char)*str1 - (unsigned char)*str2); + return (int) ((unsigned char) *str1 - (unsigned char) *str2); } #endif #ifndef HAVE_STRNCMP -int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) +int +SDL_strncmp (const char *str1, const char *str2, size_t maxlen) { - while ( *str1 && *str2 && maxlen ) { - if ( *str1 != *str2 ) + while (*str1 && *str2 && maxlen) { + if (*str1 != *str2) break; ++str1; ++str2; --maxlen; } - if ( ! maxlen ) { + if (!maxlen) { return 0; } - return (int)((unsigned char)*str1 - (unsigned char)*str2); + return (int) ((unsigned char) *str1 - (unsigned char) *str2); } #endif #if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP) -int SDL_strcasecmp(const char *str1, const char *str2) +int +SDL_strcasecmp (const char *str1, const char *str2) { char a = 0; char b = 0; - while ( *str1 && *str2 ) { - a = SDL_tolower(*str1); - b = SDL_tolower(*str2); - if ( a != b ) + while (*str1 && *str2) { + a = SDL_tolower (*str1); + b = SDL_tolower (*str2); + if (a != b) break; ++str1; ++str2; } - return (int)((unsigned char)a - (unsigned char)b); + return (int) ((unsigned char) a - (unsigned char) b); } #endif #if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP) -int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) +int +SDL_strncasecmp (const char *str1, const char *str2, size_t maxlen) { char a = 0; char b = 0; - while ( *str1 && *str2 && maxlen ) { - a = SDL_tolower(*str1); - b = SDL_tolower(*str2); - if ( a != b ) + while (*str1 && *str2 && maxlen) { + a = SDL_tolower (*str1); + b = SDL_tolower (*str2); + if (a != b) break; ++str1; ++str2; --maxlen; } - return (int)((unsigned char)a - (unsigned char)b); + return (int) ((unsigned char) a - (unsigned char) b); } #endif #ifndef HAVE_SSCANF -int SDL_sscanf(const char *text, const char *fmt, ...) +int +SDL_sscanf (const char *text, const char *fmt, ...) { va_list ap; int retval = 0; - va_start(ap, fmt); - while ( *fmt ) { - if ( *fmt == ' ' ) { - while ( SDL_isspace(*text) ) { + va_start (ap, fmt); + while (*fmt) { + if (*fmt == ' ') { + while (SDL_isspace (*text)) { ++text; } ++fmt; continue; } - if ( *fmt == '%' ) { + if (*fmt == '%') { SDL_bool done = SDL_FALSE; long count = 0; int radix = 10; - enum { + enum + { DO_SHORT, DO_INT, DO_LONG, @@ -724,31 +759,31 @@ int SDL_sscanf(const char *text, const char *fmt, ...) SDL_bool suppress = SDL_FALSE; ++fmt; - if ( *fmt == '%' ) { - if ( *text == '%' ) { + if (*fmt == '%') { + if (*text == '%') { ++text; ++fmt; continue; } break; } - if ( *fmt == '*' ) { + if (*fmt == '*') { suppress = SDL_TRUE; ++fmt; } - fmt += SDL_ScanLong(fmt, 10, &count); + fmt += SDL_ScanLong (fmt, 10, &count); - if ( *fmt == 'c' ) { - if ( ! count ) { + if (*fmt == 'c') { + if (!count) { count = 1; } - if ( suppress ) { - while ( count-- ) { + if (suppress) { + while (count--) { ++text; } } else { - char *valuep = va_arg(ap, char*); - while ( count-- ) { + char *valuep = va_arg (ap, char *); + while (count--) { *valuep++ = *text++; } ++retval; @@ -756,200 +791,205 @@ int SDL_sscanf(const char *text, const char *fmt, ...) continue; } - while ( SDL_isspace(*text) ) { + while (SDL_isspace (*text)) { ++text; } /* FIXME: implement more of the format specifiers */ while (!done) { - switch(*fmt) { - case '*': - suppress = SDL_TRUE; - break; - case 'h': - if ( inttype > DO_SHORT ) { - ++inttype; - } - break; - case 'l': - if ( inttype < DO_LONGLONG ) { - ++inttype; - } - break; - case 'I': - if ( SDL_strncmp(fmt, "I64", 3) == 0 ) { - fmt += 2; - inttype = DO_LONGLONG; + switch (*fmt) { + case '*': + suppress = SDL_TRUE; + break; + case 'h': + if (inttype > DO_SHORT) { + ++inttype; + } + break; + case 'l': + if (inttype < DO_LONGLONG) { + ++inttype; + } + break; + case 'I': + if (SDL_strncmp (fmt, "I64", 3) == 0) { + fmt += 2; + inttype = DO_LONGLONG; + } + break; + case 'i': + { + int index = 0; + if (text[index] == '-') { + ++index; } - break; - case 'i': - { - int index = 0; - if ( text[index] == '-' ) { - ++index; - } - if ( text[index] == '0' ) { - if ( SDL_tolower(text[index+1]) == 'x' ) { - radix = 16; - } else { - radix = 8; - } + if (text[index] == '0') { + if (SDL_tolower (text[index + 1]) == 'x') { + radix = 16; + } else { + radix = 8; } } - /* Fall through to %d handling */ - case 'd': + } + /* Fall through to %d handling */ + case 'd': #ifdef SDL_HAS_64BIT_TYPE - if ( inttype == DO_LONGLONG ) { - Sint64 value; - text += SDL_ScanLongLong(text, radix, &value); - if ( ! suppress ) { - Sint64 *valuep = va_arg(ap, Sint64*); - *valuep = value; - ++retval; - } + if (inttype == DO_LONGLONG) { + Sint64 value; + text += SDL_ScanLongLong (text, radix, &value); + if (!suppress) { + Sint64 *valuep = va_arg (ap, Sint64 *); + *valuep = value; + ++retval; } - else + } else #endif /* SDL_HAS_64BIT_TYPE */ - { - long value; - text += SDL_ScanLong(text, radix, &value); - if ( ! suppress ) { - switch (inttype) { - case DO_SHORT: - { short* valuep = va_arg(ap, short*); - *valuep = (short)value; - } - break; - case DO_INT: - { int* valuep = va_arg(ap, int*); - *valuep = (int)value; - } - break; - case DO_LONG: - { long* valuep = va_arg(ap, long*); - *valuep = value; - } - break; - case DO_LONGLONG: - /* Handled above */ - break; + { + long value; + text += SDL_ScanLong (text, radix, &value); + if (!suppress) { + switch (inttype) { + case DO_SHORT: + { + short *valuep = va_arg (ap, short *); + *valuep = (short) value; + } + break; + case DO_INT: + { + int *valuep = va_arg (ap, int *); + *valuep = (int) value; } - ++retval; + break; + case DO_LONG: + { + long *valuep = va_arg (ap, long *); + *valuep = value; + } + break; + case DO_LONGLONG: + /* Handled above */ + break; } + ++retval; } - done = SDL_TRUE; - break; - case 'o': - if ( radix == 10 ) { - radix = 8; - } - /* Fall through to unsigned handling */ - case 'x': - case 'X': - if ( radix == 10 ) { - radix = 16; - } - /* Fall through to unsigned handling */ - case 'u': + } + done = SDL_TRUE; + break; + case 'o': + if (radix == 10) { + radix = 8; + } + /* Fall through to unsigned handling */ + case 'x': + case 'X': + if (radix == 10) { + radix = 16; + } + /* Fall through to unsigned handling */ + case 'u': #ifdef SDL_HAS_64BIT_TYPE - if ( inttype == DO_LONGLONG ) { - Uint64 value; - text += SDL_ScanUnsignedLongLong(text, radix, &value); - if ( ! suppress ) { - Uint64 *valuep = va_arg(ap, Uint64*); - *valuep = value; - ++retval; - } + if (inttype == DO_LONGLONG) { + Uint64 value; + text += + SDL_ScanUnsignedLongLong (text, radix, &value); + if (!suppress) { + Uint64 *valuep = va_arg (ap, Uint64 *); + *valuep = value; + ++retval; } - else + } else #endif /* SDL_HAS_64BIT_TYPE */ - { - unsigned long value; - text += SDL_ScanUnsignedLong(text, radix, &value); - if ( ! suppress ) { - switch (inttype) { - case DO_SHORT: - { short* valuep = va_arg(ap, short*); - *valuep = (short)value; - } - break; - case DO_INT: - { int* valuep = va_arg(ap, int*); - *valuep = (int)value; - } - break; - case DO_LONG: - { long* valuep = va_arg(ap, long*); - *valuep = value; - } - break; - case DO_LONGLONG: - /* Handled above */ - break; + { + unsigned long value; + text += SDL_ScanUnsignedLong (text, radix, &value); + if (!suppress) { + switch (inttype) { + case DO_SHORT: + { + short *valuep = va_arg (ap, short *); + *valuep = (short) value; + } + break; + case DO_INT: + { + int *valuep = va_arg (ap, int *); + *valuep = (int) value; } - ++retval; + break; + case DO_LONG: + { + long *valuep = va_arg (ap, long *); + *valuep = value; + } + break; + case DO_LONGLONG: + /* Handled above */ + break; } + ++retval; } - done = SDL_TRUE; - break; - case 'p': - { - uintptr_t value; - text += SDL_ScanUintPtrT(text, 16, &value); - if ( ! suppress ) { - void** valuep = va_arg(ap, void**); - *valuep = (void*)value; - ++retval; - } + } + done = SDL_TRUE; + break; + case 'p': + { + uintptr_t value; + text += SDL_ScanUintPtrT (text, 16, &value); + if (!suppress) { + void **valuep = va_arg (ap, void **); + *valuep = (void *) value; + ++retval; } - done = SDL_TRUE; - break; - case 'f': - { - double value; - text += SDL_ScanFloat(text, &value); - if ( ! suppress ) { - float* valuep = va_arg(ap, float*); - *valuep = (float)value; - ++retval; - } + } + done = SDL_TRUE; + break; + case 'f': + { + double value; + text += SDL_ScanFloat (text, &value); + if (!suppress) { + float *valuep = va_arg (ap, float *); + *valuep = (float) value; + ++retval; } - done = SDL_TRUE; - break; - case 's': - if ( suppress ) { - while ( !SDL_isspace(*text) ) { - ++text; - if ( count ) { - if ( --count == 0 ) { - break; - } + } + done = SDL_TRUE; + break; + case 's': + if (suppress) { + while (!SDL_isspace (*text)) { + ++text; + if (count) { + if (--count == 0) { + break; } } - } else { - char *valuep = va_arg(ap, char*); - while ( !SDL_isspace(*text) ) { - *valuep++ = *text++; - if ( count ) { - if ( --count == 0 ) { - break; - } + } + } else { + char *valuep = va_arg (ap, char *); + while (!SDL_isspace (*text)) { + *valuep++ = *text++; + if (count) { + if (--count == 0) { + break; } } - *valuep = '\0'; - ++retval; } - done = SDL_TRUE; - break; - default: - done = SDL_TRUE; - break; + *valuep = '\0'; + ++retval; + } + done = SDL_TRUE; + break; + default: + done = SDL_TRUE; + break; } ++fmt; } continue; } - if ( *text == *fmt ) { + if (*text == *fmt) { ++text; ++fmt; continue; @@ -957,113 +997,123 @@ int SDL_sscanf(const char *text, const char *fmt, ...) /* Text didn't match format specifier */ break; } - va_end(ap); + va_end (ap); return retval; } #endif #ifndef HAVE_SNPRINTF -int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) +int +SDL_snprintf (char *text, size_t maxlen, const char *fmt, ...) { va_list ap; int retval; - va_start(ap, fmt); - retval = SDL_vsnprintf(text, maxlen, fmt, ap); - va_end(ap); + va_start (ap, fmt); + retval = SDL_vsnprintf (text, maxlen, fmt, ap); + va_end (ap); return retval; } #endif #ifndef HAVE_VSNPRINTF -static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen) +static size_t +SDL_PrintLong (char *text, long value, int radix, size_t maxlen) { char num[130]; size_t size; - SDL_ltoa(value, num, radix); - size = SDL_strlen(num); - if ( size >= maxlen ) { - size = maxlen-1; + SDL_ltoa (value, num, radix); + size = SDL_strlen (num); + if (size >= maxlen) { + size = maxlen - 1; } - SDL_strlcpy(text, num, size+1); + SDL_strlcpy (text, num, size + 1); return size; } -static size_t SDL_PrintUnsignedLong(char *text, unsigned long value, int radix, size_t maxlen) + +static size_t +SDL_PrintUnsignedLong (char *text, unsigned long value, int radix, + size_t maxlen) { char num[130]; size_t size; - SDL_ultoa(value, num, radix); - size = SDL_strlen(num); - if ( size >= maxlen ) { - size = maxlen-1; + SDL_ultoa (value, num, radix); + size = SDL_strlen (num); + if (size >= maxlen) { + size = maxlen - 1; } - SDL_strlcpy(text, num, size+1); + SDL_strlcpy (text, num, size + 1); return size; } + #ifdef SDL_HAS_64BIT_TYPE -static size_t SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen) +static size_t +SDL_PrintLongLong (char *text, Sint64 value, int radix, size_t maxlen) { char num[130]; size_t size; - SDL_lltoa(value, num, radix); - size = SDL_strlen(num); - if ( size >= maxlen ) { - size = maxlen-1; + SDL_lltoa (value, num, radix); + size = SDL_strlen (num); + if (size >= maxlen) { + size = maxlen - 1; } - SDL_strlcpy(text, num, size+1); + SDL_strlcpy (text, num, size + 1); return size; } -static size_t SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen) + +static size_t +SDL_PrintUnsignedLongLong (char *text, Uint64 value, int radix, size_t maxlen) { char num[130]; size_t size; - SDL_ulltoa(value, num, radix); - size = SDL_strlen(num); - if ( size >= maxlen ) { - size = maxlen-1; + SDL_ulltoa (value, num, radix); + size = SDL_strlen (num); + if (size >= maxlen) { + size = maxlen - 1; } - SDL_strlcpy(text, num, size+1); + SDL_strlcpy (text, num, size + 1); return size; } #endif /* SDL_HAS_64BIT_TYPE */ -static size_t SDL_PrintFloat(char *text, double arg, size_t maxlen) +static size_t +SDL_PrintFloat (char *text, double arg, size_t maxlen) { char *textstart = text; - if ( arg ) { + if (arg) { /* This isn't especially accurate, but hey, it's easy. :) */ const double precision = 0.00000001; size_t len; unsigned long value; - if ( arg < 0 ) { + if (arg < 0) { *text++ = '-'; --maxlen; arg = -arg; } - value = (unsigned long)arg; - len = SDL_PrintUnsignedLong(text, value, 10, maxlen); + value = (unsigned long) arg; + len = SDL_PrintUnsignedLong (text, value, 10, maxlen); text += len; maxlen -= len; arg -= value; - if ( arg > precision && maxlen ) { + if (arg > precision && maxlen) { int mult = 10; *text++ = '.'; - while ( (arg > precision) && maxlen ) { - value = (unsigned long)(arg * mult); - len = SDL_PrintUnsignedLong(text, value, 10, maxlen); + while ((arg > precision) && maxlen) { + value = (unsigned long) (arg * mult); + len = SDL_PrintUnsignedLong (text, value, 10, maxlen); text += len; maxlen -= len; - arg -= (double)value / mult; + arg -= (double) value / mult; mult *= 10; } } @@ -1072,28 +1122,33 @@ static size_t SDL_PrintFloat(char *text, double arg, size_t maxlen) } return (text - textstart); } -static size_t SDL_PrintString(char *text, const char *string, size_t maxlen) + +static size_t +SDL_PrintString (char *text, const char *string, size_t maxlen) { char *textstart = text; - while ( *string && maxlen-- ) { + while (*string && maxlen--) { *text++ = *string++; } return (text - textstart); } -int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) + +int +SDL_vsnprintf (char *text, size_t maxlen, const char *fmt, va_list ap) { char *textstart = text; - if ( maxlen <= 0 ) { + if (maxlen <= 0) { return 0; } - --maxlen; /* For the trailing '\0' */ - while ( *fmt && maxlen ) { - if ( *fmt == '%' ) { + --maxlen; /* For the trailing '\0' */ + while (*fmt && maxlen) { + if (*fmt == '%') { SDL_bool done = SDL_FALSE; size_t len = 0; SDL_bool do_lowercase = SDL_FALSE; int radix = 10; - enum { + enum + { DO_INT, DO_LONG, DO_LONGLONG @@ -1101,104 +1156,132 @@ int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) ++fmt; /* FIXME: implement more of the format specifiers */ - while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) { + while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) { ++fmt; } while (!done) { - switch(*fmt) { - case '%': - *text = '%'; - len = 1; - done = SDL_TRUE; - break; - case 'c': - /* char is promoted to int when passed through (...) */ - *text = (char)va_arg(ap, int); - len = 1; - done = SDL_TRUE; - break; - case 'h': - /* short is promoted to int when passed through (...) */ - break; - case 'l': - if ( inttype < DO_LONGLONG ) { - ++inttype; - } + switch (*fmt) { + case '%': + *text = '%'; + len = 1; + done = SDL_TRUE; + break; + case 'c': + /* char is promoted to int when passed through (...) */ + *text = (char) va_arg (ap, int); + len = 1; + done = SDL_TRUE; + break; + case 'h': + /* short is promoted to int when passed through (...) */ + break; + case 'l': + if (inttype < DO_LONGLONG) { + ++inttype; + } + break; + case 'I': + if (SDL_strncmp (fmt, "I64", 3) == 0) { + fmt += 2; + inttype = DO_LONGLONG; + } + break; + case 'i': + case 'd': + switch (inttype) { + case DO_INT: + len = + SDL_PrintLong (text, + (long) va_arg (ap, int), + radix, maxlen); break; - case 'I': - if ( SDL_strncmp(fmt, "I64", 3) == 0 ) { - fmt += 2; - inttype = DO_LONGLONG; - } + case DO_LONG: + len = + SDL_PrintLong (text, va_arg (ap, long), + radix, maxlen); break; - case 'i': - case 'd': - switch (inttype) { - case DO_INT: - len = SDL_PrintLong(text, (long)va_arg(ap, int), radix, maxlen); - break; - case DO_LONG: - len = SDL_PrintLong(text, va_arg(ap, long), radix, maxlen); - break; - case DO_LONGLONG: + case DO_LONGLONG: #ifdef SDL_HAS_64BIT_TYPE - len = SDL_PrintLongLong(text, va_arg(ap, Sint64), radix, maxlen); + len = + SDL_PrintLongLong (text, + va_arg (ap, Sint64), + radix, maxlen); #else - len = SDL_PrintLong(text, va_arg(ap, long), radix, maxlen); + len = + SDL_PrintLong (text, va_arg (ap, long), + radix, maxlen); #endif - break; - } - done = SDL_TRUE; break; - case 'p': - case 'x': - do_lowercase = SDL_TRUE; - /* Fall through to 'X' handling */ - case 'X': - if ( radix == 10 ) { - radix = 16; - } - if ( *fmt == 'p' ) { - inttype = DO_LONG; - } - /* Fall through to unsigned handling */ - case 'o': - if ( radix == 10 ) { - radix = 8; - } - /* Fall through to unsigned handling */ - case 'u': - switch (inttype) { - case DO_INT: - len = SDL_PrintUnsignedLong(text, (unsigned long)va_arg(ap, unsigned int), radix, maxlen); - break; - case DO_LONG: - len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen); - break; - case DO_LONGLONG: + } + done = SDL_TRUE; + break; + case 'p': + case 'x': + do_lowercase = SDL_TRUE; + /* Fall through to 'X' handling */ + case 'X': + if (radix == 10) { + radix = 16; + } + if (*fmt == 'p') { + inttype = DO_LONG; + } + /* Fall through to unsigned handling */ + case 'o': + if (radix == 10) { + radix = 8; + } + /* Fall through to unsigned handling */ + case 'u': + switch (inttype) { + case DO_INT: + len = SDL_PrintUnsignedLong (text, (unsigned long) + va_arg (ap, + unsigned + int), + radix, maxlen); + break; + case DO_LONG: + len = + SDL_PrintUnsignedLong (text, + va_arg (ap, + unsigned + long), + radix, maxlen); + break; + case DO_LONGLONG: #ifdef SDL_HAS_64BIT_TYPE - len = SDL_PrintUnsignedLongLong(text, va_arg(ap, Uint64), radix, maxlen); + len = + SDL_PrintUnsignedLongLong (text, + va_arg (ap, + Uint64), + radix, maxlen); #else - len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen); + len = + SDL_PrintUnsignedLong (text, + va_arg (ap, + unsigned + long), + radix, maxlen); #endif - break; - } - if ( do_lowercase ) { - SDL_strlwr(text); - } - done = SDL_TRUE; - break; - case 'f': - len = SDL_PrintFloat(text, va_arg(ap, double), maxlen); - done = SDL_TRUE; - break; - case 's': - len = SDL_PrintString(text, va_arg(ap, char*), maxlen); - done = SDL_TRUE; - break; - default: - done = SDL_TRUE; break; + } + if (do_lowercase) { + SDL_strlwr (text); + } + done = SDL_TRUE; + break; + case 'f': + len = SDL_PrintFloat (text, va_arg (ap, double), maxlen); + done = SDL_TRUE; + break; + case 's': + len = SDL_PrintString (text, va_arg (ap, char *), maxlen); + done = SDL_TRUE; + break; + default: + done = SDL_TRUE; + break; } ++fmt; } @@ -1214,3 +1297,4 @@ int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) return (text - textstart); } #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/SDL_systhread.h b/src/thread/SDL_systhread.h index ab9545c54..dd798db1b 100644 --- a/src/thread/SDL_systhread.h +++ b/src/thread/SDL_systhread.h @@ -33,20 +33,23 @@ on success. */ #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD -extern int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); +extern int SDL_SYS_CreateThread (SDL_Thread * thread, void *args, + pfnSDL_CurrentBeginThread pfnBeginThread, + pfnSDL_CurrentEndThread pfnEndThread); #else -extern int SDL_SYS_CreateThread(SDL_Thread *thread, void *args); +extern int SDL_SYS_CreateThread (SDL_Thread * thread, void *args); #endif /* This function does any necessary setup in the child thread */ -extern void SDL_SYS_SetupThread(void); +extern void SDL_SYS_SetupThread (void); /* This function waits for the thread to finish and frees any data allocated by SDL_SYS_CreateThread() */ -extern void SDL_SYS_WaitThread(SDL_Thread *thread); +extern void SDL_SYS_WaitThread (SDL_Thread * thread); /* This function kills the thread and returns */ -extern void SDL_SYS_KillThread(SDL_Thread *thread); +extern void SDL_SYS_KillThread (SDL_Thread * thread); #endif /* _SDL_systhread_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 09b07bb8f..83adc3e98 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -38,16 +38,17 @@ static int SDL_numthreads = 0; static SDL_Thread **SDL_Threads = NULL; static SDL_mutex *thread_lock = NULL; -int SDL_ThreadsInit(void) +int +SDL_ThreadsInit (void) { - int retval; - - retval = 0; - thread_lock = SDL_CreateMutex(); - if ( thread_lock == NULL ) { - retval = -1; - } - return(retval); + int retval; + + retval = 0; + thread_lock = SDL_CreateMutex (); + if (thread_lock == NULL) { + retval = -1; + } + return (retval); } /* This should never be called... @@ -55,244 +56,260 @@ int SDL_ThreadsInit(void) clean up threads here. If any threads are still running after this call, they will no longer have access to any per-thread data. */ -void SDL_ThreadsQuit(void) +void +SDL_ThreadsQuit (void) { - SDL_mutex *mutex; + SDL_mutex *mutex; - mutex = thread_lock; - thread_lock = NULL; - if ( mutex != NULL ) { - SDL_DestroyMutex(mutex); - } + mutex = thread_lock; + thread_lock = NULL; + if (mutex != NULL) { + SDL_DestroyMutex (mutex); + } } /* Routines for manipulating the thread list */ -static void SDL_AddThread(SDL_Thread *thread) +static void +SDL_AddThread (SDL_Thread * thread) { - /* WARNING: - If the very first threads are created simultaneously, then - there could be a race condition causing memory corruption. - In practice, this isn't a problem because by definition there - is only one thread running the first time this is called. - */ - if ( !thread_lock ) { - if ( SDL_ThreadsInit() < 0 ) { - return; - } - } - SDL_mutexP(thread_lock); - - /* Expand the list of threads, if necessary */ + /* WARNING: + If the very first threads are created simultaneously, then + there could be a race condition causing memory corruption. + In practice, this isn't a problem because by definition there + is only one thread running the first time this is called. + */ + if (!thread_lock) { + if (SDL_ThreadsInit () < 0) { + return; + } + } + SDL_mutexP (thread_lock); + + /* Expand the list of threads, if necessary */ #ifdef DEBUG_THREADS - printf("Adding thread (%d already - %d max)\n", - SDL_numthreads, SDL_maxthreads); + printf ("Adding thread (%d already - %d max)\n", + SDL_numthreads, SDL_maxthreads); #endif - if ( SDL_numthreads == SDL_maxthreads ) { - SDL_Thread **threads; - threads = (SDL_Thread **)SDL_realloc(SDL_Threads, - (SDL_maxthreads+ARRAY_CHUNKSIZE)*(sizeof *threads)); - if ( threads == NULL ) { - SDL_OutOfMemory(); - goto done; - } - SDL_maxthreads += ARRAY_CHUNKSIZE; - SDL_Threads = threads; - } - SDL_Threads[SDL_numthreads++] = thread; -done: - SDL_mutexV(thread_lock); + if (SDL_numthreads == SDL_maxthreads) { + SDL_Thread **threads; + threads = (SDL_Thread **) SDL_realloc (SDL_Threads, + (SDL_maxthreads + + ARRAY_CHUNKSIZE) * + (sizeof *threads)); + if (threads == NULL) { + SDL_OutOfMemory (); + goto done; + } + SDL_maxthreads += ARRAY_CHUNKSIZE; + SDL_Threads = threads; + } + SDL_Threads[SDL_numthreads++] = thread; + done: + SDL_mutexV (thread_lock); } -static void SDL_DelThread(SDL_Thread *thread) +static void +SDL_DelThread (SDL_Thread * thread) { - int i; - - if ( !thread_lock ) { - return; - } - SDL_mutexP(thread_lock); - for ( i=0; i 0 ) { - while ( i < SDL_numthreads ) { - SDL_Threads[i] = SDL_Threads[i+1]; - ++i; - } - } else { - SDL_maxthreads = 0; - SDL_free(SDL_Threads); - SDL_Threads = NULL; - } + int i; + + if (!thread_lock) { + return; + } + SDL_mutexP (thread_lock); + for (i = 0; i < SDL_numthreads; ++i) { + if (thread == SDL_Threads[i]) { + break; + } + } + if (i < SDL_numthreads) { + if (--SDL_numthreads > 0) { + while (i < SDL_numthreads) { + SDL_Threads[i] = SDL_Threads[i + 1]; + ++i; + } + } else { + SDL_maxthreads = 0; + SDL_free (SDL_Threads); + SDL_Threads = NULL; + } #ifdef DEBUG_THREADS - printf("Deleting thread (%d left - %d max)\n", - SDL_numthreads, SDL_maxthreads); + printf ("Deleting thread (%d left - %d max)\n", + SDL_numthreads, SDL_maxthreads); #endif - } - SDL_mutexV(thread_lock); + } + SDL_mutexV (thread_lock); - if ( SDL_Threads == NULL ) { - SDL_ThreadsQuit(); - } + if (SDL_Threads == NULL) { + SDL_ThreadsQuit (); + } } /* The default (non-thread-safe) global error variable */ static SDL_error SDL_global_error; /* Routine to get the thread-specific error variable */ -SDL_error *SDL_GetErrBuf(void) +SDL_error * +SDL_GetErrBuf (void) { - SDL_error *errbuf; - - errbuf = &SDL_global_error; - if ( SDL_Threads ) { - int i; - Uint32 this_thread; - - this_thread = SDL_ThreadID(); - SDL_mutexP(thread_lock); - for ( i=0; ithreadid ) { - errbuf = &SDL_Threads[i]->errbuf; - break; - } - } - SDL_mutexV(thread_lock); - } - return(errbuf); + SDL_error *errbuf; + + errbuf = &SDL_global_error; + if (SDL_Threads) { + int i; + Uint32 this_thread; + + this_thread = SDL_ThreadID (); + SDL_mutexP (thread_lock); + for (i = 0; i < SDL_numthreads; ++i) { + if (this_thread == SDL_Threads[i]->threadid) { + errbuf = &SDL_Threads[i]->errbuf; + break; + } + } + SDL_mutexV (thread_lock); + } + return (errbuf); } /* Arguments and callback to setup and run the user thread function */ -typedef struct { - int (SDLCALL *func)(void *); - void *data; - SDL_Thread *info; - SDL_sem *wait; +typedef struct +{ + int (SDLCALL * func) (void *); + void *data; + SDL_Thread *info; + SDL_sem *wait; } thread_args; -void SDL_RunThread(void *data) +void +SDL_RunThread (void *data) { - thread_args *args; - int (SDLCALL *userfunc)(void *); - void *userdata; - int *statusloc; - - /* Perform any system-dependent setup - - this function cannot fail, and cannot use SDL_SetError() - */ - SDL_SYS_SetupThread(); - - /* Get the thread id */ - args = (thread_args *)data; - args->info->threadid = SDL_ThreadID(); - - /* Figure out what function to run */ - userfunc = args->func; - userdata = args->data; - statusloc = &args->info->status; - - /* Wake up the parent thread */ - SDL_SemPost(args->wait); - - /* Run the function */ - *statusloc = userfunc(userdata); + thread_args *args; + int (SDLCALL * userfunc) (void *); + void *userdata; + int *statusloc; + + /* Perform any system-dependent setup + - this function cannot fail, and cannot use SDL_SetError() + */ + SDL_SYS_SetupThread (); + + /* Get the thread id */ + args = (thread_args *) data; + args->info->threadid = SDL_ThreadID (); + + /* Figure out what function to run */ + userfunc = args->func; + userdata = args->data; + statusloc = &args->info->status; + + /* Wake up the parent thread */ + SDL_SemPost (args->wait); + + /* Run the function */ + *statusloc = userfunc (userdata); } #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD #undef SDL_CreateThread -DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) +DECLSPEC SDL_Thread *SDLCALL +SDL_CreateThread (int (SDLCALL * fn) (void *), void *data, + pfnSDL_CurrentBeginThread pfnBeginThread, + pfnSDL_CurrentEndThread pfnEndThread) #else -DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data) +DECLSPEC SDL_Thread *SDLCALL +SDL_CreateThread (int (SDLCALL * fn) (void *), void *data) #endif { - SDL_Thread *thread; - thread_args *args; - int ret; - - /* Allocate memory for the thread info structure */ - thread = (SDL_Thread *)SDL_malloc(sizeof(*thread)); - if ( thread == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - SDL_memset(thread, 0, (sizeof *thread)); - thread->status = -1; - - /* Set up the arguments for the thread */ - args = (thread_args *)SDL_malloc(sizeof(*args)); - if ( args == NULL ) { - SDL_OutOfMemory(); - SDL_free(thread); - return(NULL); - } - args->func = fn; - args->data = data; - args->info = thread; - args->wait = SDL_CreateSemaphore(0); - if ( args->wait == NULL ) { - SDL_free(thread); - SDL_free(args); - return(NULL); - } - - /* Add the thread to the list of available threads */ - SDL_AddThread(thread); - - /* Create the thread and go! */ + SDL_Thread *thread; + thread_args *args; + int ret; + + /* Allocate memory for the thread info structure */ + thread = (SDL_Thread *) SDL_malloc (sizeof (*thread)); + if (thread == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + SDL_memset (thread, 0, (sizeof *thread)); + thread->status = -1; + + /* Set up the arguments for the thread */ + args = (thread_args *) SDL_malloc (sizeof (*args)); + if (args == NULL) { + SDL_OutOfMemory (); + SDL_free (thread); + return (NULL); + } + args->func = fn; + args->data = data; + args->info = thread; + args->wait = SDL_CreateSemaphore (0); + if (args->wait == NULL) { + SDL_free (thread); + SDL_free (args); + return (NULL); + } + + /* Add the thread to the list of available threads */ + SDL_AddThread (thread); + + /* Create the thread and go! */ #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD - ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread); + ret = SDL_SYS_CreateThread (thread, args, pfnBeginThread, pfnEndThread); #else - ret = SDL_SYS_CreateThread(thread, args); + ret = SDL_SYS_CreateThread (thread, args); #endif - if ( ret >= 0 ) { - /* Wait for the thread function to use arguments */ - SDL_SemWait(args->wait); - } else { - /* Oops, failed. Gotta free everything */ - SDL_DelThread(thread); - SDL_free(thread); - thread = NULL; - } - SDL_DestroySemaphore(args->wait); - SDL_free(args); - - /* Everything is running now */ - return(thread); + if (ret >= 0) { + /* Wait for the thread function to use arguments */ + SDL_SemWait (args->wait); + } else { + /* Oops, failed. Gotta free everything */ + SDL_DelThread (thread); + SDL_free (thread); + thread = NULL; + } + SDL_DestroySemaphore (args->wait); + SDL_free (args); + + /* Everything is running now */ + return (thread); } -void SDL_WaitThread(SDL_Thread *thread, int *status) +void +SDL_WaitThread (SDL_Thread * thread, int *status) { - if ( thread ) { - SDL_SYS_WaitThread(thread); - if ( status ) { - *status = thread->status; - } - SDL_DelThread(thread); - SDL_free(thread); - } + if (thread) { + SDL_SYS_WaitThread (thread); + if (status) { + *status = thread->status; + } + SDL_DelThread (thread); + SDL_free (thread); + } } -Uint32 SDL_GetThreadID(SDL_Thread *thread) +Uint32 +SDL_GetThreadID (SDL_Thread * thread) { - Uint32 id; - - if ( thread ) { - id = thread->threadid; - } else { - id = SDL_ThreadID(); - } - return(id); + Uint32 id; + + if (thread) { + id = thread->threadid; + } else { + id = SDL_ThreadID (); + } + return (id); } -void SDL_KillThread(SDL_Thread *thread) +void +SDL_KillThread (SDL_Thread * thread) { - if ( thread ) { - SDL_SYS_KillThread(thread); - SDL_WaitThread(thread, NULL); - } + if (thread) { + SDL_SYS_KillThread (thread); + SDL_WaitThread (thread, NULL); + } } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index 13501db6d..62e9dab0e 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -52,15 +52,17 @@ #include "../SDL_error_c.h" /* This is the system-independent thread info structure */ -struct SDL_Thread { - Uint32 threadid; - SYS_ThreadHandle handle; - int status; - SDL_error errbuf; - void *data; +struct SDL_Thread +{ + Uint32 threadid; + SYS_ThreadHandle handle; + int status; + SDL_error errbuf; + void *data; }; /* This is the function called to run a thread */ -extern void SDL_RunThread(void *data); +extern void SDL_RunThread (void *data); #endif /* _SDL_thread_c_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/amigaos/SDL_syssem.c b/src/thread/amigaos/SDL_syssem.c index a31a2133b..3a88e527d 100644 --- a/src/thread/amigaos/SDL_syssem.c +++ b/src/thread/amigaos/SDL_syssem.c @@ -29,120 +29,126 @@ struct SDL_semaphore { - struct SignalSemaphore Sem; + struct SignalSemaphore Sem; }; #undef D #define D(x) -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_sem *sem; + SDL_sem *sem; - sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); + sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); - if ( ! sem ) { - SDL_OutOfMemory(); - return(0); - } + if (!sem) { + SDL_OutOfMemory (); + return (0); + } - D(bug("Creating semaphore %lx...\n",sem)); + D (bug ("Creating semaphore %lx...\n", sem)); - SDL_memset(sem,0,sizeof(*sem)); + SDL_memset (sem, 0, sizeof (*sem)); - InitSemaphore(&sem->Sem); + InitSemaphore (&sem->Sem); - return(sem); + return (sem); } -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - D(bug("Destroying semaphore %lx...\n",sem)); + D (bug ("Destroying semaphore %lx...\n", sem)); - if ( sem ) { + if (sem) { // Condizioni per liberare i task in attesa? - SDL_free(sem); - } + SDL_free (sem); + } } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - D(bug("TryWait semaphore...%lx\n",sem)); + D (bug ("TryWait semaphore...%lx\n", sem)); - ObtainSemaphore(&sem->Sem); -// ReleaseSemaphore(&sem->Sem); + ObtainSemaphore (&sem->Sem); +// ReleaseSemaphore(&sem->Sem); - return 1; + return 1; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int retval; - - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem)); - - /* A timeout of 0 is an easy case */ - if ( timeout == 0 ) { - ObtainSemaphore(&sem->Sem); - return 1; - } - if(!(retval=AttemptSemaphore(&sem->Sem))) - { - SDL_Delay(timeout); - retval=AttemptSemaphore(&sem->Sem); - } - - if(retval==TRUE) - { -// ReleaseSemaphore(&sem->Sem); - retval=1; - } - - return retval; + int retval; + + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + D (bug ("WaitTimeout (%ld) semaphore...%lx\n", timeout, sem)); + + /* A timeout of 0 is an easy case */ + if (timeout == 0) { + ObtainSemaphore (&sem->Sem); + return 1; + } + if (!(retval = AttemptSemaphore (&sem->Sem))) { + SDL_Delay (timeout); + retval = AttemptSemaphore (&sem->Sem); + } + + if (retval == TRUE) { +// ReleaseSemaphore(&sem->Sem); + retval = 1; + } + + return retval; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - ObtainSemaphore(&sem->Sem); - return 0; + ObtainSemaphore (&sem->Sem); + return 0; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - Uint32 value; - - value = 0; - if ( sem ) { - #ifdef STORMC4_WOS - value = sem->Sem.ssppc_SS.ss_NestCount; - #else - value = sem->Sem.ss_NestCount; - #endif - } - return value; + Uint32 value; + + value = 0; + if (sem) { +#ifdef STORMC4_WOS + value = sem->Sem.ssppc_SS.ss_NestCount; +#else + value = sem->Sem.ss_NestCount; +#endif + } + return value; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - D(bug("SemPost semaphore...%lx\n",sem)); - - ReleaseSemaphore(&sem->Sem); - return 0; + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + D (bug ("SemPost semaphore...%lx\n", sem)); + + ReleaseSemaphore (&sem->Sem); + return 0; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/amigaos/SDL_systhread.c b/src/thread/amigaos/SDL_systhread.c index c6b42e776..498c3306b 100644 --- a/src/thread/amigaos/SDL_systhread.c +++ b/src/thread/amigaos/SDL_systhread.c @@ -29,123 +29,137 @@ #include "../SDL_systhread.h" #include "mydebug.h" -typedef struct { - int (*func)(void *); - void *data; - SDL_Thread *info; - struct Task *wait; +typedef struct +{ + int (*func) (void *); + void *data; + SDL_Thread *info; + struct Task *wait; } thread_args; #ifndef MORPHOS -#if defined(__SASC) && !defined(__PPC__) -__saveds __asm Uint32 RunThread(register __a0 char *args ) +#if defined(__SASC) && !defined(__PPC__) +__saveds __asm Uint32 +RunThread (register __a0 char *args) #elif defined(__PPC__) -Uint32 RunThread(char *args) +Uint32 +RunThread (char *args) #else -Uint32 __saveds RunThread(char *args __asm("a0") ) +Uint32 __saveds +RunThread (char *args __asm ("a0")) #endif { - #ifdef STORMC4_WOS - thread_args *data=(thread_args *)args; - #else - thread_args *data=(thread_args *)atol(args); - #endif +#ifdef STORMC4_WOS + thread_args *data = (thread_args *) args; +#else + thread_args *data = (thread_args *) atol (args); +#endif - struct Task *Father; + struct Task *Father; - D(bug("Received data: %lx\n",data)); - Father=data->wait; + D (bug ("Received data: %lx\n", data)); + Father = data->wait; - SDL_RunThread(data); + SDL_RunThread (data); - Signal(Father,SIGBREAKF_CTRL_F); - D(bug("Thread with data %lx ended\n",data)); - return(0); + Signal (Father, SIGBREAKF_CTRL_F); + D (bug ("Thread with data %lx ended\n", data)); + return (0); } #else #include -Uint32 RunTheThread(void) +Uint32 +RunTheThread (void) { - thread_args *data=(thread_args *)atol((char *)REG_A0); - struct Task *Father; + thread_args *data = (thread_args *) atol ((char *) REG_A0); + struct Task *Father; - D(bug("Received data: %lx\n",data)); - Father=data->wait; + D (bug ("Received data: %lx\n", data)); + Father = data->wait; - SDL_RunThread(data); + SDL_RunThread (data); - Signal(Father,SIGBREAKF_CTRL_F); - D(bug("Thread with data %lx ended\n",data)); - return(0); + Signal (Father, SIGBREAKF_CTRL_F); + D (bug ("Thread with data %lx ended\n", data)); + return (0); } -struct EmulLibEntry RunThreadStruct= -{ - TRAP_LIB, - 0, - (ULONG)RunTheThread +struct EmulLibEntry RunThreadStruct = { + TRAP_LIB, + 0, + (ULONG) RunTheThread }; -void *RunThread=&RunThreadStruct; +void *RunThread = &RunThreadStruct; #endif -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - /* Create the thread and go! */ - char buffer[20]; - - D(bug("Sending %lx to the new thread...\n",args)); - - if(args) - SDL_snprintf(buffer, SDL_arraysize(buffer),"%ld",args); - - #ifdef STORMC4_WOS - thread->handle=CreateTaskPPCTags(TASKATTR_CODE, RunThread, - TASKATTR_NAME, "SDL subtask", - TASKATTR_STACKSIZE, 100000, - (args ? TASKATTR_R3 : TAG_IGNORE), args, - TASKATTR_INHERITR2, TRUE, - TAG_DONE); - #else - thread->handle=(struct Task *)CreateNewProcTags(NP_Output,Output(), - NP_Name,(ULONG)"SDL subtask", - NP_CloseOutput, FALSE, - NP_StackSize,20000, - NP_Entry,(ULONG)RunThread, - args ? NP_Arguments : TAG_IGNORE,(ULONG)buffer, - TAG_DONE); - #endif - - if(!thread->handle) - { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - - return(0); + /* Create the thread and go! */ + char buffer[20]; + + D (bug ("Sending %lx to the new thread...\n", args)); + + if (args) + SDL_snprintf (buffer, SDL_arraysize (buffer), "%ld", args); + +#ifdef STORMC4_WOS + thread->handle = CreateTaskPPCTags (TASKATTR_CODE, RunThread, + TASKATTR_NAME, "SDL subtask", + TASKATTR_STACKSIZE, 100000, + (args ? TASKATTR_R3 : TAG_IGNORE), + args, TASKATTR_INHERITR2, TRUE, + TAG_DONE); +#else + thread->handle = (struct Task *) CreateNewProcTags (NP_Output, Output (), + NP_Name, + (ULONG) "SDL subtask", + NP_CloseOutput, FALSE, + NP_StackSize, 20000, + NP_Entry, + (ULONG) RunThread, + args ? NP_Arguments : + TAG_IGNORE, + (ULONG) buffer, + TAG_DONE); +#endif + + if (!thread->handle) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return((Uint32)FindTask(NULL)); + return ((Uint32) FindTask (NULL)); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - SetSignal(0L,SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C); - Wait(SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C); + SetSignal (0L, SIGBREAKF_CTRL_F | SIGBREAKF_CTRL_C); + Wait (SIGBREAKF_CTRL_F | SIGBREAKF_CTRL_C); } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - Signal((struct Task *)thread->handle,SIGBREAKF_CTRL_C); + Signal ((struct Task *) thread->handle, SIGBREAKF_CTRL_C); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/amigaos/SDL_systhread_c.h b/src/thread/amigaos/SDL_systhread_c.h index 53ba3c8c6..a5b879f03 100644 --- a/src/thread/amigaos/SDL_systhread_c.h +++ b/src/thread/amigaos/SDL_systhread_c.h @@ -57,5 +57,5 @@ extern struct DosLibrary *DOSBase; #else #define SYS_ThreadHandle struct Task * -#endif /*STORMC4_WOS*/ - +#endif /*STORMC4_WOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/amigaos/SDL_thread.c b/src/thread/amigaos/SDL_thread.c index 7698f49f3..ea633cfc3 100644 --- a/src/thread/amigaos/SDL_thread.c +++ b/src/thread/amigaos/SDL_thread.c @@ -39,11 +39,12 @@ static SDL_Thread **SDL_Threads = NULL; static struct SignalSemaphore thread_lock; int thread_lock_created = 0; -int SDL_ThreadsInit(void) +int +SDL_ThreadsInit (void) { - InitSemaphore(&thread_lock); - thread_lock_created=1; - return 0; + InitSemaphore (&thread_lock); + thread_lock_created = 1; + return 0; } /* This should never be called... @@ -51,228 +52,240 @@ int SDL_ThreadsInit(void) clean up threads here. If any threads are still running after this call, they will no longer have access to any per-thread data. */ -void SDL_ThreadsQuit() +void +SDL_ThreadsQuit () { - thread_lock_created=0; + thread_lock_created = 0; } /* Routines for manipulating the thread list */ -static void SDL_AddThread(SDL_Thread *thread) +static void +SDL_AddThread (SDL_Thread * thread) { - SDL_Thread **threads; - - /* WARNING: - If the very first threads are created simultaneously, then - there could be a race condition causing memory corruption. - In practice, this isn't a problem because by definition there - is only one thread running the first time this is called. - */ - if ( !thread_lock_created ) { - if ( SDL_ThreadsInit() < 0 ) { - return; - } - } - ObtainSemaphore(&thread_lock); - - /* Expand the list of threads, if necessary */ + SDL_Thread **threads; + + /* WARNING: + If the very first threads are created simultaneously, then + there could be a race condition causing memory corruption. + In practice, this isn't a problem because by definition there + is only one thread running the first time this is called. + */ + if (!thread_lock_created) { + if (SDL_ThreadsInit () < 0) { + return; + } + } + ObtainSemaphore (&thread_lock); + + /* Expand the list of threads, if necessary */ #ifdef DEBUG_THREADS - printf("Adding thread (%d already - %d max)\n", - SDL_numthreads, SDL_maxthreads); + printf ("Adding thread (%d already - %d max)\n", + SDL_numthreads, SDL_maxthreads); #endif - if ( SDL_numthreads == SDL_maxthreads ) { - threads=(SDL_Thread **)SDL_malloc((SDL_maxthreads+ARRAY_CHUNKSIZE)* - (sizeof *threads)); - if ( threads == NULL ) { - SDL_OutOfMemory(); - goto done; - } - SDL_memcpy(threads, SDL_Threads, SDL_numthreads*(sizeof *threads)); - SDL_maxthreads += ARRAY_CHUNKSIZE; - if ( SDL_Threads ) { - SDL_free(SDL_Threads); - } - SDL_Threads = threads; - } - SDL_Threads[SDL_numthreads++] = thread; -done: - ReleaseSemaphore(&thread_lock); + if (SDL_numthreads == SDL_maxthreads) { + threads = + (SDL_Thread **) SDL_malloc ((SDL_maxthreads + ARRAY_CHUNKSIZE) * + (sizeof *threads)); + if (threads == NULL) { + SDL_OutOfMemory (); + goto done; + } + SDL_memcpy (threads, SDL_Threads, SDL_numthreads * (sizeof *threads)); + SDL_maxthreads += ARRAY_CHUNKSIZE; + if (SDL_Threads) { + SDL_free (SDL_Threads); + } + SDL_Threads = threads; + } + SDL_Threads[SDL_numthreads++] = thread; + done: + ReleaseSemaphore (&thread_lock); } -static void SDL_DelThread(SDL_Thread *thread) +static void +SDL_DelThread (SDL_Thread * thread) { - int i; - - if ( thread_lock_created ) { - ObtainSemaphore(&thread_lock); - for ( i=0; ithreadid ) { - errbuf = &SDL_Threads[i]->errbuf; - break; - } - } - ReleaseSemaphore(&thread_lock); - } - return(errbuf); + SDL_error *errbuf; + + errbuf = &SDL_global_error; + if (SDL_Threads) { + int i; + Uint32 this_thread; + + this_thread = SDL_ThreadID (); + ObtainSemaphore (&thread_lock); + for (i = 0; i < SDL_numthreads; ++i) { + if (this_thread == SDL_Threads[i]->threadid) { + errbuf = &SDL_Threads[i]->errbuf; + break; + } + } + ReleaseSemaphore (&thread_lock); + } + return (errbuf); } /* Arguments and callback to setup and run the user thread function */ -typedef struct { - int (*func)(void *); - void *data; - SDL_Thread *info; - struct Task *wait; +typedef struct +{ + int (*func) (void *); + void *data; + SDL_Thread *info; + struct Task *wait; } thread_args; -void SDL_RunThread(void *data) +void +SDL_RunThread (void *data) { - thread_args *args; - int (*userfunc)(void *); - void *userdata; - int *statusloc; - - /* Perform any system-dependent setup - - this function cannot fail, and cannot use SDL_SetError() - */ - SDL_SYS_SetupThread(); - - /* Get the thread id */ - args = (thread_args *)data; - args->info->threadid = SDL_ThreadID(); - - /* Figure out what function to run */ - userfunc = args->func; - userdata = args->data; - statusloc = &args->info->status; - - /* Wake up the parent thread */ - Signal(args->wait,SIGBREAKF_CTRL_E); - - /* Run the function */ - *statusloc = userfunc(userdata); + thread_args *args; + int (*userfunc) (void *); + void *userdata; + int *statusloc; + + /* Perform any system-dependent setup + - this function cannot fail, and cannot use SDL_SetError() + */ + SDL_SYS_SetupThread (); + + /* Get the thread id */ + args = (thread_args *) data; + args->info->threadid = SDL_ThreadID (); + + /* Figure out what function to run */ + userfunc = args->func; + userdata = args->data; + statusloc = &args->info->status; + + /* Wake up the parent thread */ + Signal (args->wait, SIGBREAKF_CTRL_E); + + /* Run the function */ + *statusloc = userfunc (userdata); } -SDL_Thread *SDL_CreateThread(int (*fn)(void *), void *data) +SDL_Thread * +SDL_CreateThread (int (*fn) (void *), void *data) { - SDL_Thread *thread; - thread_args *args; - int ret; - - /* Allocate memory for the thread info structure */ - thread = (SDL_Thread *)SDL_malloc(sizeof(*thread)); - if ( thread == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - SDL_memset(thread, 0, (sizeof *thread)); - thread->status = -1; - - /* Set up the arguments for the thread */ - args = (thread_args *)SDL_malloc(sizeof(*args)); - if ( args == NULL ) { - SDL_OutOfMemory(); - SDL_free(thread); - return(NULL); - } - args->func = fn; - args->data = data; - args->info = thread; - args->wait = FindTask(NULL); - if ( args->wait == NULL ) { - SDL_free(thread); - SDL_free(args); - SDL_OutOfMemory(); - return(NULL); - } - - /* Add the thread to the list of available threads */ - SDL_AddThread(thread); - - D(bug("Starting thread...\n")); - - /* Create the thread and go! */ - ret = SDL_SYS_CreateThread(thread, args); - if ( ret >= 0 ) { - D(bug("Waiting for thread CTRL_E...\n")); - /* Wait for the thread function to use arguments */ - Wait(SIGBREAKF_CTRL_E); - D(bug(" Arrived.")); - } else { - /* Oops, failed. Gotta free everything */ - SDL_DelThread(thread); - SDL_free(thread); - thread = NULL; - } - SDL_free(args); - - /* Everything is running now */ - return(thread); + SDL_Thread *thread; + thread_args *args; + int ret; + + /* Allocate memory for the thread info structure */ + thread = (SDL_Thread *) SDL_malloc (sizeof (*thread)); + if (thread == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + SDL_memset (thread, 0, (sizeof *thread)); + thread->status = -1; + + /* Set up the arguments for the thread */ + args = (thread_args *) SDL_malloc (sizeof (*args)); + if (args == NULL) { + SDL_OutOfMemory (); + SDL_free (thread); + return (NULL); + } + args->func = fn; + args->data = data; + args->info = thread; + args->wait = FindTask (NULL); + if (args->wait == NULL) { + SDL_free (thread); + SDL_free (args); + SDL_OutOfMemory (); + return (NULL); + } + + /* Add the thread to the list of available threads */ + SDL_AddThread (thread); + + D (bug ("Starting thread...\n")); + + /* Create the thread and go! */ + ret = SDL_SYS_CreateThread (thread, args); + if (ret >= 0) { + D (bug ("Waiting for thread CTRL_E...\n")); + /* Wait for the thread function to use arguments */ + Wait (SIGBREAKF_CTRL_E); + D (bug (" Arrived.")); + } else { + /* Oops, failed. Gotta free everything */ + SDL_DelThread (thread); + SDL_free (thread); + thread = NULL; + } + SDL_free (args); + + /* Everything is running now */ + return (thread); } -void SDL_WaitThread(SDL_Thread *thread, int *status) +void +SDL_WaitThread (SDL_Thread * thread, int *status) { - if ( thread ) { - SDL_SYS_WaitThread(thread); - if ( status ) { - *status = thread->status; - } - SDL_DelThread(thread); - SDL_free(thread); - } + if (thread) { + SDL_SYS_WaitThread (thread); + if (status) { + *status = thread->status; + } + SDL_DelThread (thread); + SDL_free (thread); + } } -Uint32 SDL_GetThreadID(SDL_Thread *thread) +Uint32 +SDL_GetThreadID (SDL_Thread * thread) { - Uint32 id; - - if ( thread ) { - id = thread->threadid; - } else { - id = SDL_ThreadID(); - } - return(id); + Uint32 id; + + if (thread) { + id = thread->threadid; + } else { + id = SDL_ThreadID (); + } + return (id); } -void SDL_KillThread(SDL_Thread *thread) +void +SDL_KillThread (SDL_Thread * thread) { - if ( thread ) { - SDL_SYS_KillThread(thread); - SDL_WaitThread(thread, NULL); - } + if (thread) { + SDL_SYS_KillThread (thread); + SDL_WaitThread (thread, NULL); + } } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/beos/SDL_syssem.c b/src/thread/beos/SDL_syssem.c index 5ea4f3735..9e2b6b9ea 100644 --- a/src/thread/beos/SDL_syssem.c +++ b/src/thread/beos/SDL_syssem.c @@ -28,115 +28,125 @@ #include "SDL_thread.h" -struct SDL_semaphore { - sem_id id; +struct SDL_semaphore +{ + sem_id id; }; /* Create a counting semaphore */ -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_sem *sem; - - sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); - if ( sem ) { - sem->id = create_sem(initial_value, "SDL semaphore"); - if ( sem->id < B_NO_ERROR ) { - SDL_SetError("create_sem() failed"); - SDL_free(sem); - sem = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(sem); + SDL_sem *sem; + + sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); + if (sem) { + sem->id = create_sem (initial_value, "SDL semaphore"); + if (sem->id < B_NO_ERROR) { + SDL_SetError ("create_sem() failed"); + SDL_free (sem); + sem = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (sem); } /* Free the semaphore */ -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - if ( sem ) { - if ( sem->id >= B_NO_ERROR ) { - delete_sem(sem->id); - } - SDL_free(sem); - } + if (sem) { + if (sem->id >= B_NO_ERROR) { + delete_sem (sem->id); + } + SDL_free (sem); + } } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int32 val; - int retval; + int32 val; + int retval; - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } tryagain: - if ( timeout == SDL_MUTEX_MAXWAIT ) { - val = acquire_sem(sem->id); - } else { - timeout *= 1000; /* BeOS uses a timeout in microseconds */ - val = acquire_sem_etc(sem->id, 1, B_RELATIVE_TIMEOUT, timeout); - } - switch (val) { - case B_INTERRUPTED: - goto tryagain; - case B_NO_ERROR: - retval = 0; - break; - case B_TIMED_OUT: - retval = SDL_MUTEX_TIMEDOUT; - break; - case B_WOULD_BLOCK: - retval = SDL_MUTEX_TIMEDOUT; - break; - default: - SDL_SetError("acquire_sem() failed"); - retval = -1; - break; - } - - return retval; + if (timeout == SDL_MUTEX_MAXWAIT) { + val = acquire_sem (sem->id); + } else { + timeout *= 1000; /* BeOS uses a timeout in microseconds */ + val = acquire_sem_etc (sem->id, 1, B_RELATIVE_TIMEOUT, timeout); + } + switch (val) { + case B_INTERRUPTED: + goto tryagain; + case B_NO_ERROR: + retval = 0; + break; + case B_TIMED_OUT: + retval = SDL_MUTEX_TIMEDOUT; + break; + case B_WOULD_BLOCK: + retval = SDL_MUTEX_TIMEDOUT; + break; + default: + SDL_SetError ("acquire_sem() failed"); + retval = -1; + break; + } + + return retval; } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - return SDL_SemWaitTimeout(sem, 0); + return SDL_SemWaitTimeout (sem, 0); } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); + return SDL_SemWaitTimeout (sem, SDL_MUTEX_MAXWAIT); } /* Returns the current count of the semaphore */ -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - int32 count; - Uint32 value; - - value = 0; - if ( sem ) { - get_sem_count(sem->id, &count); - if ( count > 0 ) { - value = (Uint32)count; - } - } - return value; + int32 count; + Uint32 value; + + value = 0; + if (sem) { + get_sem_count (sem->id, &count); + if (count > 0) { + value = (Uint32) count; + } + } + return value; } /* Atomically increases the semaphore's count (not blocking) */ -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - if ( release_sem(sem->id) != B_NO_ERROR ) { - SDL_SetError("release_sem() failed"); - return -1; - } - return 0; + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + if (release_sem (sem->id) != B_NO_ERROR) { + SDL_SetError ("release_sem() failed"); + return -1; + } + return 0; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/beos/SDL_systhread.c b/src/thread/beos/SDL_systhread.c index 904fcc770..ae635c6c0 100644 --- a/src/thread/beos/SDL_systhread.c +++ b/src/thread/beos/SDL_systhread.c @@ -34,63 +34,74 @@ static int sig_list[] = { - SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0 + SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0 }; -void SDL_MaskSignals(sigset_t *omask) +void +SDL_MaskSignals (sigset_t * omask) { - sigset_t mask; - int i; - - sigemptyset(&mask); - for ( i=0; sig_list[i]; ++i ) { - sigaddset(&mask, sig_list[i]); - } - sigprocmask(SIG_BLOCK, &mask, omask); + sigset_t mask; + int i; + + sigemptyset (&mask); + for (i = 0; sig_list[i]; ++i) { + sigaddset (&mask, sig_list[i]); + } + sigprocmask (SIG_BLOCK, &mask, omask); } -void SDL_UnmaskSignals(sigset_t *omask) + +void +SDL_UnmaskSignals (sigset_t * omask) { - sigprocmask(SIG_SETMASK, omask, NULL); + sigprocmask (SIG_SETMASK, omask, NULL); } -static int32 RunThread(void *data) +static int32 +RunThread (void *data) { - SDL_RunThread(data); - return(0); + SDL_RunThread (data); + return (0); } -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - /* Create the thread and go! */ - thread->handle=spawn_thread(RunThread, "SDL", B_NORMAL_PRIORITY, args); - if ( (thread->handle == B_NO_MORE_THREADS) || - (thread->handle == B_NO_MEMORY) ) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - resume_thread(thread->handle); - return(0); + /* Create the thread and go! */ + thread->handle = spawn_thread (RunThread, "SDL", B_NORMAL_PRIORITY, args); + if ((thread->handle == B_NO_MORE_THREADS) || + (thread->handle == B_NO_MEMORY)) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + resume_thread (thread->handle); + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - /* Mask asynchronous signals for this thread */ - SDL_MaskSignals(NULL); + /* Mask asynchronous signals for this thread */ + SDL_MaskSignals (NULL); } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return((Uint32)find_thread(NULL)); + return ((Uint32) find_thread (NULL)); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - status_t the_status; + status_t the_status; - wait_for_thread(thread->handle, &the_status); + wait_for_thread (thread->handle, &the_status); } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - kill_thread(thread->handle); + kill_thread (thread->handle); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/beos/SDL_systhread_c.h b/src/thread/beos/SDL_systhread_c.h index 0d8d8546e..4381b55a3 100644 --- a/src/thread/beos/SDL_systhread_c.h +++ b/src/thread/beos/SDL_systhread_c.h @@ -27,5 +27,7 @@ typedef thread_id SYS_ThreadHandle; /* Functions needed to work with system threads in other portions of SDL */ -extern void SDL_MaskSignals(sigset_t *omask); -extern void SDL_UnmaskSignals(sigset_t *omask); +extern void SDL_MaskSignals (sigset_t * omask); +extern void SDL_UnmaskSignals (sigset_t * omask); + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_syscond.c b/src/thread/dc/SDL_syscond.c index 6a9d2dcc0..5365374ae 100644 --- a/src/thread/dc/SDL_syscond.c +++ b/src/thread/dc/SDL_syscond.c @@ -31,107 +31,111 @@ struct SDL_cond { - SDL_mutex *lock; - int waiting; - int signals; - SDL_sem *wait_sem; - SDL_sem *wait_done; + SDL_mutex *lock; + int waiting; + int signals; + SDL_sem *wait_sem; + SDL_sem *wait_done; }; /* Create a condition variable */ -SDL_cond * SDL_CreateCond(void) +SDL_cond * +SDL_CreateCond (void) { - SDL_cond *cond; - - cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); - if ( cond ) { - cond->lock = SDL_CreateMutex(); - cond->wait_sem = SDL_CreateSemaphore(0); - cond->wait_done = SDL_CreateSemaphore(0); - cond->waiting = cond->signals = 0; - if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) { - SDL_DestroyCond(cond); - cond = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(cond); + SDL_cond *cond; + + cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond)); + if (cond) { + cond->lock = SDL_CreateMutex (); + cond->wait_sem = SDL_CreateSemaphore (0); + cond->wait_done = SDL_CreateSemaphore (0); + cond->waiting = cond->signals = 0; + if (!cond->lock || !cond->wait_sem || !cond->wait_done) { + SDL_DestroyCond (cond); + cond = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (cond); } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void +SDL_DestroyCond (SDL_cond * cond) { - if ( cond ) { - if ( cond->wait_sem ) { - SDL_DestroySemaphore(cond->wait_sem); - } - if ( cond->wait_done ) { - SDL_DestroySemaphore(cond->wait_done); - } - if ( cond->lock ) { - SDL_DestroyMutex(cond->lock); - } - SDL_free(cond); - } + if (cond) { + if (cond->wait_sem) { + SDL_DestroySemaphore (cond->wait_sem); + } + if (cond->wait_done) { + SDL_DestroySemaphore (cond->wait_done); + } + if (cond->lock) { + SDL_DestroyMutex (cond->lock); + } + SDL_free (cond); + } } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int +SDL_CondSignal (SDL_cond * cond) { - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if ( cond->waiting > cond->signals ) { - ++cond->signals; - SDL_SemPost(cond->wait_sem); - SDL_UnlockMutex(cond->lock); - SDL_SemWait(cond->wait_done); - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex (cond->lock); + if (cond->waiting > cond->signals) { + ++cond->signals; + SDL_SemPost (cond->wait_sem); + SDL_UnlockMutex (cond->lock); + SDL_SemWait (cond->wait_done); + } else { + SDL_UnlockMutex (cond->lock); + } + + return 0; } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int +SDL_CondBroadcast (SDL_cond * cond) { - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if ( cond->waiting > cond->signals ) { - int i, num_waiting; - - num_waiting = (cond->waiting - cond->signals); - cond->signals = cond->waiting; - for ( i=0; iwait_sem); - } - /* Now all released threads are blocked here, waiting for us. - Collect them all (and win fabulous prizes!) :-) - */ - SDL_UnlockMutex(cond->lock); - for ( i=0; iwait_done); - } - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex (cond->lock); + if (cond->waiting > cond->signals) { + int i, num_waiting; + + num_waiting = (cond->waiting - cond->signals); + cond->signals = cond->waiting; + for (i = 0; i < num_waiting; ++i) { + SDL_SemPost (cond->wait_sem); + } + /* Now all released threads are blocked here, waiting for us. + Collect them all (and win fabulous prizes!) :-) + */ + SDL_UnlockMutex (cond->lock); + for (i = 0; i < num_waiting; ++i) { + SDL_SemWait (cond->wait_done); + } + } else { + SDL_UnlockMutex (cond->lock); + } + + return 0; } /* Wait on the condition variable for at most 'ms' milliseconds. @@ -154,62 +158,66 @@ Thread B: ... SDL_UnlockMutex(lock); */ -int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) +int +SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* Obtain the protection mutex, and increment the number of waiters. - This allows the signal mechanism to only perform a signal if there - are waiting threads. - */ - SDL_LockMutex(cond->lock); - ++cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Unlock the mutex, as is required by condition variable semantics */ - SDL_UnlockMutex(mutex); - - /* Wait for a signal */ - if ( ms == SDL_MUTEX_MAXWAIT ) { - retval = SDL_SemWait(cond->wait_sem); - } else { - retval = SDL_SemWaitTimeout(cond->wait_sem, ms); - } - - /* Let the signaler know we have completed the wait, otherwise - the signaler can race ahead and get the condition semaphore - if we are stopped between the mutex unlock and semaphore wait, - giving a deadlock. See the following URL for details: - http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html - */ - SDL_LockMutex(cond->lock); - if ( cond->signals > 0 ) { - /* If we timed out, we need to eat a condition signal */ - if ( retval > 0 ) { - SDL_SemWait(cond->wait_sem); - } - /* We always notify the signal thread that we are done */ - SDL_SemPost(cond->wait_done); - - /* Signal handshake complete */ - --cond->signals; - } - --cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Lock the mutex, as is required by condition variable semantics */ - SDL_LockMutex(mutex); - - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* Obtain the protection mutex, and increment the number of waiters. + This allows the signal mechanism to only perform a signal if there + are waiting threads. + */ + SDL_LockMutex (cond->lock); + ++cond->waiting; + SDL_UnlockMutex (cond->lock); + + /* Unlock the mutex, as is required by condition variable semantics */ + SDL_UnlockMutex (mutex); + + /* Wait for a signal */ + if (ms == SDL_MUTEX_MAXWAIT) { + retval = SDL_SemWait (cond->wait_sem); + } else { + retval = SDL_SemWaitTimeout (cond->wait_sem, ms); + } + + /* Let the signaler know we have completed the wait, otherwise + the signaler can race ahead and get the condition semaphore + if we are stopped between the mutex unlock and semaphore wait, + giving a deadlock. See the following URL for details: + http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html + */ + SDL_LockMutex (cond->lock); + if (cond->signals > 0) { + /* If we timed out, we need to eat a condition signal */ + if (retval > 0) { + SDL_SemWait (cond->wait_sem); + } + /* We always notify the signal thread that we are done */ + SDL_SemPost (cond->wait_done); + + /* Signal handshake complete */ + --cond->signals; + } + --cond->waiting; + SDL_UnlockMutex (cond->lock); + + /* Lock the mutex, as is required by condition variable semantics */ + SDL_LockMutex (mutex); + + return retval; } /* Wait on the condition variable forever */ -int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +int +SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex) { - return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); + return SDL_CondWaitTimeout (cond, mutex, SDL_MUTEX_MAXWAIT); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_syscond_c.h b/src/thread/dc/SDL_syscond_c.h index 27d55093a..8ab650f13 100644 --- a/src/thread/dc/SDL_syscond_c.h +++ b/src/thread/dc/SDL_syscond_c.h @@ -20,4 +20,4 @@ slouken@libsdl.org */ #include "SDL_config.h" - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_sysmutex.c b/src/thread/dc/SDL_sysmutex.c index 8e3d5f7a4..63dc01935 100644 --- a/src/thread/dc/SDL_sysmutex.c +++ b/src/thread/dc/SDL_sysmutex.c @@ -28,95 +28,102 @@ #include -struct SDL_mutex { - int recursive; - Uint32 owner; - spinlock_t mutex; +struct SDL_mutex +{ + int recursive; + Uint32 owner; + spinlock_t mutex; }; /* Create a mutex */ -SDL_mutex *SDL_CreateMutex(void) +SDL_mutex * +SDL_CreateMutex (void) { - SDL_mutex *mutex; - - /* Allocate mutex memory */ - mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); - if ( mutex ) { - spinlock_init(&mutex->mutex); - mutex->recursive = 0; - mutex->owner = 0; - } else { - SDL_OutOfMemory(); - } - return mutex; + SDL_mutex *mutex; + + /* Allocate mutex memory */ + mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex)); + if (mutex) { + spinlock_init (&mutex->mutex); + mutex->recursive = 0; + mutex->owner = 0; + } else { + SDL_OutOfMemory (); + } + return mutex; } /* Free the mutex */ -void SDL_DestroyMutex(SDL_mutex *mutex) +void +SDL_DestroyMutex (SDL_mutex * mutex) { - if ( mutex ) { - SDL_free(mutex); - } + if (mutex) { + SDL_free (mutex); + } } /* Lock the semaphore */ -int SDL_mutexP(SDL_mutex *mutex) +int +SDL_mutexP (SDL_mutex * mutex) { #if SDL_THREADS_DISABLED - return SDL_arraysize(return ),0; + return SDL_arraysize (return), 0; #else - Uint32 this_thread; - - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - this_thread = SDL_ThreadID(); - if ( mutex->owner == this_thread ) { - ++mutex->recursive; - } else { - /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. - */ - spinlock_lock(&mutex->mutex); - mutex->owner = this_thread; - mutex->recursive = 0; - } - - return 0; + Uint32 this_thread; + + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + + this_thread = SDL_ThreadID (); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + spinlock_lock (&mutex->mutex); + mutex->owner = this_thread; + mutex->recursive = 0; + } + + return 0; #endif /* SDL_THREADS_DISABLED */ } /* Unlock the mutex */ -int SDL_mutexV(SDL_mutex *mutex) +int +SDL_mutexV (SDL_mutex * mutex) { #if SDL_THREADS_DISABLED - return 0; + return 0; #else - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - /* If we don't own the mutex, we can't unlock it */ - if ( SDL_ThreadID() != mutex->owner ) { - SDL_SetError("mutex not owned by this thread"); - return -1; - } - - if ( mutex->recursive ) { - --mutex->recursive; - } else { - /* The order of operations is important. - First reset the owner so another thread doesn't lock - the mutex and set the ownership before we reset it, - then release the lock semaphore. - */ - mutex->owner = 0; - spinlock_unlock(&mutex->mutex); - } - return 0; + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + + /* If we don't own the mutex, we can't unlock it */ + if (SDL_ThreadID () != mutex->owner) { + SDL_SetError ("mutex not owned by this thread"); + return -1; + } + + if (mutex->recursive) { + --mutex->recursive; + } else { + /* The order of operations is important. + First reset the owner so another thread doesn't lock + the mutex and set the ownership before we reset it, + then release the lock semaphore. + */ + mutex->owner = 0; + spinlock_unlock (&mutex->mutex); + } + return 0; #endif /* SDL_THREADS_DISABLED */ } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_sysmutex_c.h b/src/thread/dc/SDL_sysmutex_c.h index 27d55093a..8ab650f13 100644 --- a/src/thread/dc/SDL_sysmutex_c.h +++ b/src/thread/dc/SDL_sysmutex_c.h @@ -20,4 +20,4 @@ slouken@libsdl.org */ #include "SDL_config.h" - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_syssem.c b/src/thread/dc/SDL_syssem.c index 51ca8ff08..cbdbccbc2 100644 --- a/src/thread/dc/SDL_syssem.c +++ b/src/thread/dc/SDL_syssem.c @@ -30,44 +30,51 @@ #if SDL_THREADS_DISABLED -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_SetError("SDL not configured with thread support"); - return (SDL_sem *)0; + SDL_SetError ("SDL not configured with thread support"); + return (SDL_sem *) 0; } -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - return; + return; } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - return 0; + return 0; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } #else @@ -76,93 +83,104 @@ int SDL_SemPost(SDL_sem *sem) struct SDL_semaphore { - semaphore_t sem; + semaphore_t sem; }; -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - return (SDL_sem *)sem_create(initial_value); + return (SDL_sem *) sem_create (initial_value); } /* WARNING: You cannot call this function when another thread is using the semaphore. */ -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return; + } - sem_destroy(&sem->sem); + sem_destroy (&sem->sem); } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - int retval; + int retval; - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - retval = sem_trywait(&sem->sem); - if (retval==0) return 0; - else return SDL_MUTEX_TIMEDOUT; + retval = sem_trywait (&sem->sem); + if (retval == 0) + return 0; + else + return SDL_MUTEX_TIMEDOUT; - return retval; + return retval; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int retval; + int retval; - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - /* A timeout of 0 is an easy case */ - if ( timeout == 0 ) { - return SDL_SemTryWait(sem); - } + /* A timeout of 0 is an easy case */ + if (timeout == 0) { + return SDL_SemTryWait (sem); + } - retval = sem_wait_timed(&sem->sem,timeout); - if (retval==-1) retval= SDL_MUTEX_TIMEDOUT; + retval = sem_wait_timed (&sem->sem, timeout); + if (retval == -1) + retval = SDL_MUTEX_TIMEDOUT; - return retval; + return retval; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - sem_wait(&sem->sem); - return 0; + sem_wait (&sem->sem); + return 0; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - return sem_count(&sem->sem); + return sem_count (&sem->sem); } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - sem_signal(&sem->sem); - return 0; + sem_signal (&sem->sem); + return 0; } #endif /* SDL_THREADS_DISABLED */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_syssem_c.h b/src/thread/dc/SDL_syssem_c.h index 27d55093a..8ab650f13 100644 --- a/src/thread/dc/SDL_syssem_c.h +++ b/src/thread/dc/SDL_syssem_c.h @@ -20,4 +20,4 @@ slouken@libsdl.org */ #include "SDL_config.h" - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_systhread.c b/src/thread/dc/SDL_systhread.c index 8c782cc62..19ee6df65 100644 --- a/src/thread/dc/SDL_systhread.c +++ b/src/thread/dc/SDL_systhread.c @@ -29,32 +29,39 @@ #include -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - thread->handle = thd_create(SDL_RunThread,args); - if (thread->handle == NULL) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - return(0); + thread->handle = thd_create (SDL_RunThread, args); + if (thread->handle == NULL) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - return; + return; } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return (Uint32)thd_get_current(); + return (Uint32) thd_get_current (); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - thd_wait(thread->handle); + thd_wait (thread->handle); } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - thd_destroy(thread->handle); + thd_destroy (thread->handle); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/dc/SDL_systhread_c.h b/src/thread/dc/SDL_systhread_c.h index 8f9553fb0..98bdf0f8d 100644 --- a/src/thread/dc/SDL_systhread_c.h +++ b/src/thread/dc/SDL_systhread_c.h @@ -21,4 +21,5 @@ */ #include "SDL_config.h" -typedef struct kthread* SYS_ThreadHandle; +typedef struct kthread *SYS_ThreadHandle; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/epoc/SDL_systhread_c.h b/src/thread/epoc/SDL_systhread_c.h index 6f5fd943b..302e63608 100644 --- a/src/thread/epoc/SDL_systhread_c.h +++ b/src/thread/epoc/SDL_systhread_c.h @@ -28,4 +28,4 @@ */ typedef int SYS_ThreadHandle; - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index 6a9d2dcc0..5365374ae 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -31,107 +31,111 @@ struct SDL_cond { - SDL_mutex *lock; - int waiting; - int signals; - SDL_sem *wait_sem; - SDL_sem *wait_done; + SDL_mutex *lock; + int waiting; + int signals; + SDL_sem *wait_sem; + SDL_sem *wait_done; }; /* Create a condition variable */ -SDL_cond * SDL_CreateCond(void) +SDL_cond * +SDL_CreateCond (void) { - SDL_cond *cond; - - cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); - if ( cond ) { - cond->lock = SDL_CreateMutex(); - cond->wait_sem = SDL_CreateSemaphore(0); - cond->wait_done = SDL_CreateSemaphore(0); - cond->waiting = cond->signals = 0; - if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) { - SDL_DestroyCond(cond); - cond = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(cond); + SDL_cond *cond; + + cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond)); + if (cond) { + cond->lock = SDL_CreateMutex (); + cond->wait_sem = SDL_CreateSemaphore (0); + cond->wait_done = SDL_CreateSemaphore (0); + cond->waiting = cond->signals = 0; + if (!cond->lock || !cond->wait_sem || !cond->wait_done) { + SDL_DestroyCond (cond); + cond = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (cond); } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void +SDL_DestroyCond (SDL_cond * cond) { - if ( cond ) { - if ( cond->wait_sem ) { - SDL_DestroySemaphore(cond->wait_sem); - } - if ( cond->wait_done ) { - SDL_DestroySemaphore(cond->wait_done); - } - if ( cond->lock ) { - SDL_DestroyMutex(cond->lock); - } - SDL_free(cond); - } + if (cond) { + if (cond->wait_sem) { + SDL_DestroySemaphore (cond->wait_sem); + } + if (cond->wait_done) { + SDL_DestroySemaphore (cond->wait_done); + } + if (cond->lock) { + SDL_DestroyMutex (cond->lock); + } + SDL_free (cond); + } } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int +SDL_CondSignal (SDL_cond * cond) { - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if ( cond->waiting > cond->signals ) { - ++cond->signals; - SDL_SemPost(cond->wait_sem); - SDL_UnlockMutex(cond->lock); - SDL_SemWait(cond->wait_done); - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex (cond->lock); + if (cond->waiting > cond->signals) { + ++cond->signals; + SDL_SemPost (cond->wait_sem); + SDL_UnlockMutex (cond->lock); + SDL_SemWait (cond->wait_done); + } else { + SDL_UnlockMutex (cond->lock); + } + + return 0; } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int +SDL_CondBroadcast (SDL_cond * cond) { - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if ( cond->waiting > cond->signals ) { - int i, num_waiting; - - num_waiting = (cond->waiting - cond->signals); - cond->signals = cond->waiting; - for ( i=0; iwait_sem); - } - /* Now all released threads are blocked here, waiting for us. - Collect them all (and win fabulous prizes!) :-) - */ - SDL_UnlockMutex(cond->lock); - for ( i=0; iwait_done); - } - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex (cond->lock); + if (cond->waiting > cond->signals) { + int i, num_waiting; + + num_waiting = (cond->waiting - cond->signals); + cond->signals = cond->waiting; + for (i = 0; i < num_waiting; ++i) { + SDL_SemPost (cond->wait_sem); + } + /* Now all released threads are blocked here, waiting for us. + Collect them all (and win fabulous prizes!) :-) + */ + SDL_UnlockMutex (cond->lock); + for (i = 0; i < num_waiting; ++i) { + SDL_SemWait (cond->wait_done); + } + } else { + SDL_UnlockMutex (cond->lock); + } + + return 0; } /* Wait on the condition variable for at most 'ms' milliseconds. @@ -154,62 +158,66 @@ Thread B: ... SDL_UnlockMutex(lock); */ -int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) +int +SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* Obtain the protection mutex, and increment the number of waiters. - This allows the signal mechanism to only perform a signal if there - are waiting threads. - */ - SDL_LockMutex(cond->lock); - ++cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Unlock the mutex, as is required by condition variable semantics */ - SDL_UnlockMutex(mutex); - - /* Wait for a signal */ - if ( ms == SDL_MUTEX_MAXWAIT ) { - retval = SDL_SemWait(cond->wait_sem); - } else { - retval = SDL_SemWaitTimeout(cond->wait_sem, ms); - } - - /* Let the signaler know we have completed the wait, otherwise - the signaler can race ahead and get the condition semaphore - if we are stopped between the mutex unlock and semaphore wait, - giving a deadlock. See the following URL for details: - http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html - */ - SDL_LockMutex(cond->lock); - if ( cond->signals > 0 ) { - /* If we timed out, we need to eat a condition signal */ - if ( retval > 0 ) { - SDL_SemWait(cond->wait_sem); - } - /* We always notify the signal thread that we are done */ - SDL_SemPost(cond->wait_done); - - /* Signal handshake complete */ - --cond->signals; - } - --cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Lock the mutex, as is required by condition variable semantics */ - SDL_LockMutex(mutex); - - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* Obtain the protection mutex, and increment the number of waiters. + This allows the signal mechanism to only perform a signal if there + are waiting threads. + */ + SDL_LockMutex (cond->lock); + ++cond->waiting; + SDL_UnlockMutex (cond->lock); + + /* Unlock the mutex, as is required by condition variable semantics */ + SDL_UnlockMutex (mutex); + + /* Wait for a signal */ + if (ms == SDL_MUTEX_MAXWAIT) { + retval = SDL_SemWait (cond->wait_sem); + } else { + retval = SDL_SemWaitTimeout (cond->wait_sem, ms); + } + + /* Let the signaler know we have completed the wait, otherwise + the signaler can race ahead and get the condition semaphore + if we are stopped between the mutex unlock and semaphore wait, + giving a deadlock. See the following URL for details: + http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html + */ + SDL_LockMutex (cond->lock); + if (cond->signals > 0) { + /* If we timed out, we need to eat a condition signal */ + if (retval > 0) { + SDL_SemWait (cond->wait_sem); + } + /* We always notify the signal thread that we are done */ + SDL_SemPost (cond->wait_done); + + /* Signal handshake complete */ + --cond->signals; + } + --cond->waiting; + SDL_UnlockMutex (cond->lock); + + /* Lock the mutex, as is required by condition variable semantics */ + SDL_LockMutex (mutex); + + return retval; } /* Wait on the condition variable forever */ -int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +int +SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex) { - return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); + return SDL_CondWaitTimeout (cond, mutex, SDL_MUTEX_MAXWAIT); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index 18099d24d..e22be2352 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -27,103 +27,110 @@ #include "SDL_systhread_c.h" -struct SDL_mutex { - int recursive; - Uint32 owner; - SDL_sem *sem; +struct SDL_mutex +{ + int recursive; + Uint32 owner; + SDL_sem *sem; }; /* Create a mutex */ -SDL_mutex *SDL_CreateMutex(void) +SDL_mutex * +SDL_CreateMutex (void) { - SDL_mutex *mutex; - - /* Allocate mutex memory */ - mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); - if ( mutex ) { - /* Create the mutex semaphore, with initial value 1 */ - mutex->sem = SDL_CreateSemaphore(1); - mutex->recursive = 0; - mutex->owner = 0; - if ( ! mutex->sem ) { - SDL_free(mutex); - mutex = NULL; - } - } else { - SDL_OutOfMemory(); - } - return mutex; + SDL_mutex *mutex; + + /* Allocate mutex memory */ + mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex)); + if (mutex) { + /* Create the mutex semaphore, with initial value 1 */ + mutex->sem = SDL_CreateSemaphore (1); + mutex->recursive = 0; + mutex->owner = 0; + if (!mutex->sem) { + SDL_free (mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory (); + } + return mutex; } /* Free the mutex */ -void SDL_DestroyMutex(SDL_mutex *mutex) +void +SDL_DestroyMutex (SDL_mutex * mutex) { - if ( mutex ) { - if ( mutex->sem ) { - SDL_DestroySemaphore(mutex->sem); - } - SDL_free(mutex); - } + if (mutex) { + if (mutex->sem) { + SDL_DestroySemaphore (mutex->sem); + } + SDL_free (mutex); + } } /* Lock the semaphore */ -int SDL_mutexP(SDL_mutex *mutex) +int +SDL_mutexP (SDL_mutex * mutex) { #if SDL_THREADS_DISABLED - return 0; + return 0; #else - Uint32 this_thread; - - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - this_thread = SDL_ThreadID(); - if ( mutex->owner == this_thread ) { - ++mutex->recursive; - } else { - /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. - */ - SDL_SemWait(mutex->sem); - mutex->owner = this_thread; - mutex->recursive = 0; - } - - return 0; + Uint32 this_thread; + + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + + this_thread = SDL_ThreadID (); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + SDL_SemWait (mutex->sem); + mutex->owner = this_thread; + mutex->recursive = 0; + } + + return 0; #endif /* SDL_THREADS_DISABLED */ } /* Unlock the mutex */ -int SDL_mutexV(SDL_mutex *mutex) +int +SDL_mutexV (SDL_mutex * mutex) { #if SDL_THREADS_DISABLED - return 0; + return 0; #else - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - - /* If we don't own the mutex, we can't unlock it */ - if ( SDL_ThreadID() != mutex->owner ) { - SDL_SetError("mutex not owned by this thread"); - return -1; - } - - if ( mutex->recursive ) { - --mutex->recursive; - } else { - /* The order of operations is important. - First reset the owner so another thread doesn't lock - the mutex and set the ownership before we reset it, - then release the lock semaphore. - */ - mutex->owner = 0; - SDL_SemPost(mutex->sem); - } - return 0; + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + + /* If we don't own the mutex, we can't unlock it */ + if (SDL_ThreadID () != mutex->owner) { + SDL_SetError ("mutex not owned by this thread"); + return -1; + } + + if (mutex->recursive) { + --mutex->recursive; + } else { + /* The order of operations is important. + First reset the owner so another thread doesn't lock + the mutex and set the ownership before we reset it, + then release the lock semaphore. + */ + mutex->owner = 0; + SDL_SemPost (mutex->sem); + } + return 0; #endif /* SDL_THREADS_DISABLED */ } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/generic/SDL_sysmutex_c.h b/src/thread/generic/SDL_sysmutex_c.h index 27d55093a..8ab650f13 100644 --- a/src/thread/generic/SDL_sysmutex_c.h +++ b/src/thread/generic/SDL_sysmutex_c.h @@ -20,4 +20,4 @@ slouken@libsdl.org */ #include "SDL_config.h" - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index c3ffd3f25..160005700 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -30,180 +30,195 @@ #if SDL_THREADS_DISABLED -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_SetError("SDL not configured with thread support"); - return (SDL_sem *)0; + SDL_SetError ("SDL not configured with thread support"); + return (SDL_sem *) 0; } -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - return; + return; } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - return 0; + return 0; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } #else struct SDL_semaphore { - Uint32 count; - Uint32 waiters_count; - SDL_mutex *count_lock; - SDL_cond *count_nonzero; + Uint32 count; + Uint32 waiters_count; + SDL_mutex *count_lock; + SDL_cond *count_nonzero; }; -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_sem *sem; - - sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); - if ( ! sem ) { - SDL_OutOfMemory(); - return NULL; - } - sem->count = initial_value; - sem->waiters_count = 0; - - sem->count_lock = SDL_CreateMutex(); - sem->count_nonzero = SDL_CreateCond(); - if ( ! sem->count_lock || ! sem->count_nonzero ) { - SDL_DestroySemaphore(sem); - return NULL; - } - - return sem; + SDL_sem *sem; + + sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); + if (!sem) { + SDL_OutOfMemory (); + return NULL; + } + sem->count = initial_value; + sem->waiters_count = 0; + + sem->count_lock = SDL_CreateMutex (); + sem->count_nonzero = SDL_CreateCond (); + if (!sem->count_lock || !sem->count_nonzero) { + SDL_DestroySemaphore (sem); + return NULL; + } + + return sem; } /* WARNING: You cannot call this function when another thread is using the semaphore. */ -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - if ( sem ) { - sem->count = 0xFFFFFFFF; - while ( sem->waiters_count > 0) { - SDL_CondSignal(sem->count_nonzero); - SDL_Delay(10); - } - SDL_DestroyCond(sem->count_nonzero); - if ( sem->count_lock ) { - SDL_mutexP(sem->count_lock); - SDL_mutexV(sem->count_lock); - SDL_DestroyMutex(sem->count_lock); - } - SDL_free(sem); - } + if (sem) { + sem->count = 0xFFFFFFFF; + while (sem->waiters_count > 0) { + SDL_CondSignal (sem->count_nonzero); + SDL_Delay (10); + } + SDL_DestroyCond (sem->count_nonzero); + if (sem->count_lock) { + SDL_mutexP (sem->count_lock); + SDL_mutexV (sem->count_lock); + SDL_DestroyMutex (sem->count_lock); + } + SDL_free (sem); + } } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = SDL_MUTEX_TIMEDOUT; - SDL_LockMutex(sem->count_lock); - if ( sem->count > 0 ) { - --sem->count; - retval = 0; - } - SDL_UnlockMutex(sem->count_lock); - - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + retval = SDL_MUTEX_TIMEDOUT; + SDL_LockMutex (sem->count_lock); + if (sem->count > 0) { + --sem->count; + retval = 0; + } + SDL_UnlockMutex (sem->count_lock); + + return retval; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - /* A timeout of 0 is an easy case */ - if ( timeout == 0 ) { - return SDL_SemTryWait(sem); - } - - SDL_LockMutex(sem->count_lock); - ++sem->waiters_count; - retval = 0; - while ( (sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT) ) { - retval = SDL_CondWaitTimeout(sem->count_nonzero, - sem->count_lock, timeout); - } - --sem->waiters_count; - --sem->count; - SDL_UnlockMutex(sem->count_lock); - - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + /* A timeout of 0 is an easy case */ + if (timeout == 0) { + return SDL_SemTryWait (sem); + } + + SDL_LockMutex (sem->count_lock); + ++sem->waiters_count; + retval = 0; + while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { + retval = SDL_CondWaitTimeout (sem->count_nonzero, + sem->count_lock, timeout); + } + --sem->waiters_count; + --sem->count; + SDL_UnlockMutex (sem->count_lock); + + return retval; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); + return SDL_SemWaitTimeout (sem, SDL_MUTEX_MAXWAIT); } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - Uint32 value; - - value = 0; - if ( sem ) { - SDL_LockMutex(sem->count_lock); - value = sem->count; - SDL_UnlockMutex(sem->count_lock); - } - return value; + Uint32 value; + + value = 0; + if (sem) { + SDL_LockMutex (sem->count_lock); + value = sem->count; + SDL_UnlockMutex (sem->count_lock); + } + return value; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - SDL_LockMutex(sem->count_lock); - if ( sem->waiters_count > 0 ) { - SDL_CondSignal(sem->count_nonzero); - } - ++sem->count; - SDL_UnlockMutex(sem->count_lock); - - return 0; + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + SDL_LockMutex (sem->count_lock); + if (sem->waiters_count > 0) { + SDL_CondSignal (sem->count_nonzero); + } + ++sem->count; + SDL_UnlockMutex (sem->count_lock); + + return 0; } #endif /* SDL_THREADS_DISABLED */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/generic/SDL_systhread.c b/src/thread/generic/SDL_systhread.c index 6739ad49d..43f49bc5a 100644 --- a/src/thread/generic/SDL_systhread.c +++ b/src/thread/generic/SDL_systhread.c @@ -26,29 +26,35 @@ #include "SDL_thread.h" #include "../SDL_systhread.h" -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - SDL_SetError("Threads are not supported on this platform"); - return(-1); + SDL_SetError ("Threads are not supported on this platform"); + return (-1); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - return; + return; } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return(0); + return (0); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - return; + return; } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - return; + return; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/generic/SDL_systhread_c.h b/src/thread/generic/SDL_systhread_c.h index 7e876b066..a7d19d035 100644 --- a/src/thread/generic/SDL_systhread_c.h +++ b/src/thread/generic/SDL_systhread_c.h @@ -23,3 +23,4 @@ /* Stub until we implement threads on this platform */ typedef int SYS_ThreadHandle; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/irix/SDL_syssem.c b/src/thread/irix/SDL_syssem.c index 8b3311b58..155edb8f2 100644 --- a/src/thread/irix/SDL_syssem.c +++ b/src/thread/irix/SDL_syssem.c @@ -36,8 +36,9 @@ #include "SDL_thread.h" -struct SDL_semaphore { - int id; +struct SDL_semaphore +{ + int id; }; /* Not defined by many operating systems, use configure to detect */ @@ -52,168 +53,178 @@ union semun { */ static struct sembuf op_trywait[2] = { - { 0, -1, (IPC_NOWAIT|SEM_UNDO) } /* Decrement semaphore, no block */ + {0, -1, (IPC_NOWAIT | SEM_UNDO)} /* Decrement semaphore, no block */ }; static struct sembuf op_wait[2] = { - { 0, -1, SEM_UNDO } /* Decrement semaphore */ + {0, -1, SEM_UNDO} /* Decrement semaphore */ }; static struct sembuf op_post[1] = { - { 0, 1, (IPC_NOWAIT|SEM_UNDO) } /* Increment semaphore */ + {0, 1, (IPC_NOWAIT | SEM_UNDO)} /* Increment semaphore */ }; /* Create a blockable semaphore */ -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - extern int _creating_thread_lock; /* SDL_threads.c */ - SDL_sem *sem; - union semun init; - - sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); - if ( sem == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - sem->id = semget(IPC_PRIVATE, 1, (0600|IPC_CREAT)); - if ( sem->id < 0 ) { - SDL_SetError("Couldn't create semaphore"); - SDL_free(sem); - return(NULL); - } - init.val = initial_value; /* Initialize semaphore */ - semctl(sem->id, 0, SETVAL, init); - return(sem); + extern int _creating_thread_lock; /* SDL_threads.c */ + SDL_sem *sem; + union semun init; + + sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); + if (sem == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + sem->id = semget (IPC_PRIVATE, 1, (0600 | IPC_CREAT)); + if (sem->id < 0) { + SDL_SetError ("Couldn't create semaphore"); + SDL_free (sem); + return (NULL); + } + init.val = initial_value; /* Initialize semaphore */ + semctl (sem->id, 0, SETVAL, init); + return (sem); } -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - if ( sem ) { + if (sem) { #ifdef __IRIX__ - semctl(sem->id, 0, IPC_RMID); + semctl (sem->id, 0, IPC_RMID); #else - union semun dummy; - dummy.val = 0; - semctl(sem->id, 0, IPC_RMID, dummy); + union semun dummy; + dummy.val = 0; + semctl (sem->id, 0, IPC_RMID, dummy); #endif - SDL_free(sem); - } + SDL_free (sem); + } } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - int retval; + int retval; - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - retval = 0; + retval = 0; tryagain: - if ( semop(sem->id, op_trywait, 1) < 0 ) { - if ( errno == EINTR ) { - goto tryagain; - } - retval = SDL_MUTEX_TIMEDOUT; - } - return retval; + if (semop (sem->id, op_trywait, 1) < 0) { + if (errno == EINTR) { + goto tryagain; + } + retval = SDL_MUTEX_TIMEDOUT; + } + return retval; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - int retval; + int retval; - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - retval = 0; + retval = 0; tryagain: - if ( semop(sem->id, op_wait, 1) < 0 ) { - if ( errno == EINTR ) { - goto tryagain; - } - SDL_SetError("Semaphore operation error"); - retval = -1; - } - return retval; + if (semop (sem->id, op_wait, 1) < 0) { + if (errno == EINTR) { + goto tryagain; + } + SDL_SetError ("Semaphore operation error"); + retval = -1; + } + return retval; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - /* Try the easy cases first */ - if ( timeout == 0 ) { - return SDL_SemTryWait(sem); - } - if ( timeout == SDL_MUTEX_MAXWAIT ) { - return SDL_SemWait(sem); - } - - /* Ack! We have to busy wait... */ - timeout += SDL_GetTicks(); - do { - retval = SDL_SemTryWait(sem); - if ( retval == 0 ) { - break; - } - SDL_Delay(1); - } while ( SDL_GetTicks() < timeout ); - - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + /* Try the easy cases first */ + if (timeout == 0) { + return SDL_SemTryWait (sem); + } + if (timeout == SDL_MUTEX_MAXWAIT) { + return SDL_SemWait (sem); + } + + /* Ack! We have to busy wait... */ + timeout += SDL_GetTicks (); + do { + retval = SDL_SemTryWait (sem); + if (retval == 0) { + break; + } + SDL_Delay (1); + } + while (SDL_GetTicks () < timeout); + + return retval; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - int semval; - Uint32 value; - - value = 0; - if ( sem ) { - tryagain: + int semval; + Uint32 value; + + value = 0; + if (sem) { + tryagain: #ifdef __IRIX__ - semval = semctl(sem->id, 0, GETVAL); + semval = semctl (sem->id, 0, GETVAL); #else - { - union semun arg; - arg.val = 0; - semval = semctl(sem->id, 0, GETVAL, arg); - } + { + union semun arg; + arg.val = 0; + semval = semctl (sem->id, 0, GETVAL, arg); + } #endif - if ( semval < 0 ) { - if ( errno == EINTR ) { - goto tryagain; - } - } else { - value = (Uint32)semval; - } - } - return value; + if (semval < 0) { + if (errno == EINTR) { + goto tryagain; + } + } else { + value = (Uint32) semval; + } + } + return value; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - int retval; + int retval; - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } - retval = 0; + retval = 0; tryagain: - if ( semop(sem->id, op_post, 1) < 0 ) { - if ( errno == EINTR ) { - goto tryagain; - } - SDL_SetError("Semaphore operation error"); - retval = -1; - } - return retval; + if (semop (sem->id, op_post, 1) < 0) { + if (errno == EINTR) { + goto tryagain; + } + SDL_SetError ("Semaphore operation error"); + retval = -1; + } + return retval; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/irix/SDL_systhread.c b/src/thread/irix/SDL_systhread.c index 16a865966..eb5b2606d 100644 --- a/src/thread/irix/SDL_systhread.c +++ b/src/thread/irix/SDL_systhread.c @@ -34,52 +34,58 @@ static int sig_list[] = { - SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCLD, SIGWINCH, - SIGVTALRM, SIGPROF, 0 + SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCLD, SIGWINCH, + SIGVTALRM, SIGPROF, 0 }; -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - /* Create the thread and go! */ - if ( sproc(SDL_RunThread, PR_SALL, args) < 0 ) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - return(0); + /* Create the thread and go! */ + if (sproc (SDL_RunThread, PR_SALL, args) < 0) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - int i; - sigset_t mask; - - /* Mask asynchronous signals for this thread */ - sigemptyset(&mask); - for ( i=0; sig_list[i]; ++i ) { - sigaddset(&mask, sig_list[i]); - } - sigprocmask(SIG_BLOCK, &mask, NULL); + int i; + sigset_t mask; + + /* Mask asynchronous signals for this thread */ + sigemptyset (&mask); + for (i = 0; sig_list[i]; ++i) { + sigaddset (&mask, sig_list[i]); + } + sigprocmask (SIG_BLOCK, &mask, NULL); } /* WARNING: This may not work for systems with 64-bit pid_t */ -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return((Uint32)getpid()); + return ((Uint32) getpid ()); } /* WARNING: This may not work for systems with 64-bit pid_t */ -void SDL_WaitThread(SDL_Thread *thread, int *status) +void +SDL_WaitThread (SDL_Thread * thread, int *status) { - errno = 0; - while ( errno != ECHILD ) { - waitpid(thread->handle, NULL, 0); - } + errno = 0; + while (errno != ECHILD) { + waitpid (thread->handle, NULL, 0); + } } /* WARNING: This may not work for systems with 64-bit pid_t */ -void SDL_KillThread(SDL_Thread *thread) +void +SDL_KillThread (SDL_Thread * thread) { - kill(thread->handle, SIGKILL); + kill (thread->handle, SIGKILL); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/irix/SDL_systhread_c.h b/src/thread/irix/SDL_systhread_c.h index 76e141a7f..0541231d9 100644 --- a/src/thread/irix/SDL_systhread_c.h +++ b/src/thread/irix/SDL_systhread_c.h @@ -24,4 +24,4 @@ #include typedef pid_t SYS_ThreadHandle; - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/os2/SDL_syscond.c b/src/thread/os2/SDL_syscond.c index 25577e40d..057f25a24 100644 --- a/src/thread/os2/SDL_syscond.c +++ b/src/thread/os2/SDL_syscond.c @@ -31,107 +31,111 @@ struct SDL_cond { - SDL_mutex *lock; - int waiting; - int signals; - SDL_sem *wait_sem; - SDL_sem *wait_done; + SDL_mutex *lock; + int waiting; + int signals; + SDL_sem *wait_sem; + SDL_sem *wait_done; }; /* Create a condition variable */ -DECLSPEC SDL_cond * SDLCALL SDL_CreateCond(void) +DECLSPEC SDL_cond *SDLCALL +SDL_CreateCond (void) { - SDL_cond *cond; - - cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); - if ( cond ) { - cond->lock = SDL_CreateMutex(); - cond->wait_sem = SDL_CreateSemaphore(0); - cond->wait_done = SDL_CreateSemaphore(0); - cond->waiting = cond->signals = 0; - if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) { - SDL_DestroyCond(cond); - cond = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(cond); + SDL_cond *cond; + + cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond)); + if (cond) { + cond->lock = SDL_CreateMutex (); + cond->wait_sem = SDL_CreateSemaphore (0); + cond->wait_done = SDL_CreateSemaphore (0); + cond->waiting = cond->signals = 0; + if (!cond->lock || !cond->wait_sem || !cond->wait_done) { + SDL_DestroyCond (cond); + cond = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (cond); } /* Destroy a condition variable */ -DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond) +DECLSPEC void SDLCALL +SDL_DestroyCond (SDL_cond * cond) { - if ( cond ) { - if ( cond->wait_sem ) { - SDL_DestroySemaphore(cond->wait_sem); - } - if ( cond->wait_done ) { - SDL_DestroySemaphore(cond->wait_done); - } - if ( cond->lock ) { - SDL_DestroyMutex(cond->lock); - } - SDL_free(cond); - } + if (cond) { + if (cond->wait_sem) { + SDL_DestroySemaphore (cond->wait_sem); + } + if (cond->wait_done) { + SDL_DestroySemaphore (cond->wait_done); + } + if (cond->lock) { + SDL_DestroyMutex (cond->lock); + } + SDL_free (cond); + } } /* Restart one of the threads that are waiting on the condition variable */ -DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond) +DECLSPEC int SDLCALL +SDL_CondSignal (SDL_cond * cond) { - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if ( cond->waiting > cond->signals ) { - ++cond->signals; - SDL_SemPost(cond->wait_sem); - SDL_UnlockMutex(cond->lock); - SDL_SemWait(cond->wait_done); - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex (cond->lock); + if (cond->waiting > cond->signals) { + ++cond->signals; + SDL_SemPost (cond->wait_sem); + SDL_UnlockMutex (cond->lock); + SDL_SemWait (cond->wait_done); + } else { + SDL_UnlockMutex (cond->lock); + } + + return 0; } /* Restart all threads that are waiting on the condition variable */ -DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond) +DECLSPEC int SDLCALL +SDL_CondBroadcast (SDL_cond * cond) { - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - SDL_LockMutex(cond->lock); - if ( cond->waiting > cond->signals ) { - int i, num_waiting; - - num_waiting = (cond->waiting - cond->signals); - cond->signals = cond->waiting; - for ( i=0; iwait_sem); - } - /* Now all released threads are blocked here, waiting for us. - Collect them all (and win fabulous prizes!) :-) - */ - SDL_UnlockMutex(cond->lock); - for ( i=0; iwait_done); - } - } else { - SDL_UnlockMutex(cond->lock); - } - - return 0; + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex (cond->lock); + if (cond->waiting > cond->signals) { + int i, num_waiting; + + num_waiting = (cond->waiting - cond->signals); + cond->signals = cond->waiting; + for (i = 0; i < num_waiting; ++i) { + SDL_SemPost (cond->wait_sem); + } + /* Now all released threads are blocked here, waiting for us. + Collect them all (and win fabulous prizes!) :-) + */ + SDL_UnlockMutex (cond->lock); + for (i = 0; i < num_waiting; ++i) { + SDL_SemWait (cond->wait_done); + } + } else { + SDL_UnlockMutex (cond->lock); + } + + return 0; } /* Wait on the condition variable for at most 'ms' milliseconds. @@ -154,62 +158,66 @@ Thread B: ... SDL_UnlockMutex(lock); */ -DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) +DECLSPEC int SDLCALL +SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - /* Obtain the protection mutex, and increment the number of waiters. - This allows the signal mechanism to only perform a signal if there - are waiting threads. - */ - SDL_LockMutex(cond->lock); - ++cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Unlock the mutex, as is required by condition variable semantics */ - SDL_UnlockMutex(mutex); - - /* Wait for a signal */ - if ( ms == SDL_MUTEX_MAXWAIT ) { - retval = SDL_SemWait(cond->wait_sem); - } else { - retval = SDL_SemWaitTimeout(cond->wait_sem, ms); - } - - /* Let the signaler know we have completed the wait, otherwise - the signaler can race ahead and get the condition semaphore - if we are stopped between the mutex unlock and semaphore wait, - giving a deadlock. See the following URL for details: - http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html - */ - SDL_LockMutex(cond->lock); - if ( cond->signals > 0 ) { - /* If we timed out, we need to eat a condition signal */ - if ( retval > 0 ) { - SDL_SemWait(cond->wait_sem); - } - /* We always notify the signal thread that we are done */ - SDL_SemPost(cond->wait_done); - - /* Signal handshake complete */ - --cond->signals; - } - --cond->waiting; - SDL_UnlockMutex(cond->lock); - - /* Lock the mutex, as is required by condition variable semantics */ - SDL_LockMutex(mutex); - - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + /* Obtain the protection mutex, and increment the number of waiters. + This allows the signal mechanism to only perform a signal if there + are waiting threads. + */ + SDL_LockMutex (cond->lock); + ++cond->waiting; + SDL_UnlockMutex (cond->lock); + + /* Unlock the mutex, as is required by condition variable semantics */ + SDL_UnlockMutex (mutex); + + /* Wait for a signal */ + if (ms == SDL_MUTEX_MAXWAIT) { + retval = SDL_SemWait (cond->wait_sem); + } else { + retval = SDL_SemWaitTimeout (cond->wait_sem, ms); + } + + /* Let the signaler know we have completed the wait, otherwise + the signaler can race ahead and get the condition semaphore + if we are stopped between the mutex unlock and semaphore wait, + giving a deadlock. See the following URL for details: + http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html + */ + SDL_LockMutex (cond->lock); + if (cond->signals > 0) { + /* If we timed out, we need to eat a condition signal */ + if (retval > 0) { + SDL_SemWait (cond->wait_sem); + } + /* We always notify the signal thread that we are done */ + SDL_SemPost (cond->wait_done); + + /* Signal handshake complete */ + --cond->signals; + } + --cond->waiting; + SDL_UnlockMutex (cond->lock); + + /* Lock the mutex, as is required by condition variable semantics */ + SDL_LockMutex (mutex); + + return retval; } /* Wait on the condition variable forever */ -DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +DECLSPEC int SDLCALL +SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex) { - return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); + return SDL_CondWaitTimeout (cond, mutex, SDL_MUTEX_MAXWAIT); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/os2/SDL_syscond_c.h b/src/thread/os2/SDL_syscond_c.h index 27d55093a..8ab650f13 100644 --- a/src/thread/os2/SDL_syscond_c.h +++ b/src/thread/os2/SDL_syscond_c.h @@ -20,4 +20,4 @@ slouken@libsdl.org */ #include "SDL_config.h" - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/os2/SDL_sysmutex.c b/src/thread/os2/SDL_sysmutex.c index ea75ccee0..ff46f060e 100644 --- a/src/thread/os2/SDL_sysmutex.c +++ b/src/thread/os2/SDL_sysmutex.c @@ -30,79 +30,78 @@ #include "SDL_mutex.h" -struct SDL_mutex { - HMTX hmtxID; +struct SDL_mutex +{ + HMTX hmtxID; }; /* Create a mutex */ -DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void) +DECLSPEC SDL_mutex *SDLCALL +SDL_CreateMutex (void) { - SDL_mutex *mutex; - APIRET ulrc; + SDL_mutex *mutex; + APIRET ulrc; - /* Allocate mutex memory */ - mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); - if (mutex) - { - /* Create the mutex, with initial value signaled */ - ulrc = DosCreateMutexSem(NULL, // Create unnamed semaphore - &(mutex->hmtxID), // Pointer to handle - 0L, // Flags: create it private (not shared) - FALSE); // Initial value: unowned - if (ulrc!=NO_ERROR) - { - SDL_SetError("Couldn't create mutex"); - SDL_free(mutex); - mutex = NULL; + /* Allocate mutex memory */ + mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex)); + if (mutex) { + /* Create the mutex, with initial value signaled */ + ulrc = DosCreateMutexSem (NULL, // Create unnamed semaphore + &(mutex->hmtxID), // Pointer to handle + 0L, // Flags: create it private (not shared) + FALSE); // Initial value: unowned + if (ulrc != NO_ERROR) { + SDL_SetError ("Couldn't create mutex"); + SDL_free (mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory (); } - } else { - SDL_OutOfMemory(); - } - return(mutex); + return (mutex); } /* Free the mutex */ -DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex) +DECLSPEC void SDLCALL +SDL_DestroyMutex (SDL_mutex * mutex) { - if ( mutex ) - { - if ( mutex->hmtxID ) - { - DosCloseMutexSem(mutex->hmtxID); - mutex->hmtxID = 0; + if (mutex) { + if (mutex->hmtxID) { + DosCloseMutexSem (mutex->hmtxID); + mutex->hmtxID = 0; + } + SDL_free (mutex); } - SDL_free(mutex); - } } /* Lock the mutex */ -DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex) +DECLSPEC int SDLCALL +SDL_mutexP (SDL_mutex * mutex) { - if ( mutex == NULL ) - { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - if ( DosRequestMutexSem(mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR ) - { - SDL_SetError("Couldn't wait on mutex"); - return -1; - } - return(0); + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + if (DosRequestMutexSem (mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR) { + SDL_SetError ("Couldn't wait on mutex"); + return -1; + } + return (0); } /* Unlock the mutex */ -DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex) +DECLSPEC int SDLCALL +SDL_mutexV (SDL_mutex * mutex) { - if ( mutex == NULL ) - { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - if ( DosReleaseMutexSem(mutex->hmtxID) != NO_ERROR ) - { - SDL_SetError("Couldn't release mutex"); - return -1; - } - return(0); + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + if (DosReleaseMutexSem (mutex->hmtxID) != NO_ERROR) { + SDL_SetError ("Couldn't release mutex"); + return -1; + } + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/os2/SDL_syssem.c b/src/thread/os2/SDL_syssem.c index d44593403..376b7462f 100644 --- a/src/thread/os2/SDL_syssem.c +++ b/src/thread/os2/SDL_syssem.c @@ -32,161 +32,163 @@ #include "SDL_timer.h" -struct SDL_semaphore { - HMTX id; - HEV changed; - Uint32 value; +struct SDL_semaphore +{ + HMTX id; + HEV changed; + Uint32 value; }; /* Create a semaphore */ -DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value) +DECLSPEC SDL_sem *SDLCALL +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_sem *sem; - ULONG ulrc; - - /* Allocate sem memory */ - sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); - if ( sem ) { - /* Create the mutex semaphore */ - ulrc = DosCreateMutexSem(NULL,&(sem->id),0,TRUE); - if ( ulrc ) { - SDL_SetError("Couldn't create semaphore"); - SDL_free(sem); - sem = NULL; - } else - { - DosCreateEventSem(NULL, &(sem->changed), 0, FALSE); - sem->value = initial_value; - DosReleaseMutexSem(sem->id); - } + SDL_sem *sem; + ULONG ulrc; + + /* Allocate sem memory */ + sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); + if (sem) { + /* Create the mutex semaphore */ + ulrc = DosCreateMutexSem (NULL, &(sem->id), 0, TRUE); + if (ulrc) { + SDL_SetError ("Couldn't create semaphore"); + SDL_free (sem); + sem = NULL; } else { - SDL_OutOfMemory(); + DosCreateEventSem (NULL, &(sem->changed), 0, FALSE); + sem->value = initial_value; + DosReleaseMutexSem (sem->id); } - return(sem); + } else { + SDL_OutOfMemory (); + } + return (sem); } /* Free the semaphore */ -DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem) +DECLSPEC void SDLCALL +SDL_DestroySemaphore (SDL_sem * sem) { - if ( sem ) { - if ( sem->id ) { - DosCloseEventSem(sem->changed); - DosCloseMutexSem(sem->id); - sem->id = 0; - } - SDL_free(sem); + if (sem) { + if (sem->id) { + DosCloseEventSem (sem->changed); + DosCloseMutexSem (sem->id); + sem->id = 0; } + SDL_free (sem); + } } -DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +DECLSPEC int SDLCALL +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - ULONG ulrc; + ULONG ulrc; - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return -1; - } + if (!sem) { + SDL_SetError ("Passed a NULL sem"); + return -1; + } - if ( timeout == SDL_MUTEX_MAXWAIT ) { - while (1) { - ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT); - if (ulrc) { - /* if error waiting mutex */ - SDL_SetError("DosRequestMutexSem() failed"); - return -1; - } else if (sem->value) { - sem->value--; - DosReleaseMutexSem(sem->id); - return 0; - } else { - ULONG ulPostCount; - DosResetEventSem(sem->changed, &ulPostCount); - DosReleaseMutexSem(sem->id); - /* continue waiting until somebody posts the semaphore */ - DosWaitEventSem(sem->changed, SEM_INDEFINITE_WAIT); - } - } - } else - if ( timeout == 0 ) - { - ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT); - if (ulrc==NO_ERROR) - { - if (sem->value) - { - sem->value--; - DosReleaseMutexSem(sem->id); - return 0; - } else - { - DosReleaseMutexSem(sem->id); - return SDL_MUTEX_TIMEDOUT; - } - } else - { - SDL_SetError("DosRequestMutexSem() failed"); - return -1; - } - } else { - ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT); + if (timeout == SDL_MUTEX_MAXWAIT) { + while (1) { + ulrc = DosRequestMutexSem (sem->id, SEM_INDEFINITE_WAIT); if (ulrc) { - /* if error waiting mutex */ - SDL_SetError("DosRequestMutexSem() failed"); - return -1; - } else - if (sem->value) { + /* if error waiting mutex */ + SDL_SetError ("DosRequestMutexSem() failed"); + return -1; + } else if (sem->value) { sem->value--; - DosReleaseMutexSem(sem->id); + DosReleaseMutexSem (sem->id); return 0; - } else { + } else { ULONG ulPostCount; - DosResetEventSem(sem->changed, &ulPostCount); - DosReleaseMutexSem(sem->id); + DosResetEventSem (sem->changed, &ulPostCount); + DosReleaseMutexSem (sem->id); /* continue waiting until somebody posts the semaphore */ - ulrc = DosWaitEventSem(sem->changed, timeout); - if (ulrc==NO_ERROR) - return 0; - else - return SDL_MUTEX_TIMEDOUT; - } + DosWaitEventSem (sem->changed, SEM_INDEFINITE_WAIT); + } } - /* never reached */ - return -1; + } else if (timeout == 0) { + ulrc = DosRequestMutexSem (sem->id, SEM_INDEFINITE_WAIT); + if (ulrc == NO_ERROR) { + if (sem->value) { + sem->value--; + DosReleaseMutexSem (sem->id); + return 0; + } else { + DosReleaseMutexSem (sem->id); + return SDL_MUTEX_TIMEDOUT; + } + } else { + SDL_SetError ("DosRequestMutexSem() failed"); + return -1; + } + } else { + ulrc = DosRequestMutexSem (sem->id, SEM_INDEFINITE_WAIT); + if (ulrc) { + /* if error waiting mutex */ + SDL_SetError ("DosRequestMutexSem() failed"); + return -1; + } else if (sem->value) { + sem->value--; + DosReleaseMutexSem (sem->id); + return 0; + } else { + ULONG ulPostCount; + DosResetEventSem (sem->changed, &ulPostCount); + DosReleaseMutexSem (sem->id); + /* continue waiting until somebody posts the semaphore */ + ulrc = DosWaitEventSem (sem->changed, timeout); + if (ulrc == NO_ERROR) + return 0; + else + return SDL_MUTEX_TIMEDOUT; + } + } + /* never reached */ + return -1; } -DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem) +DECLSPEC int SDLCALL +SDL_SemTryWait (SDL_sem * sem) { - return SDL_SemWaitTimeout(sem, 0); + return SDL_SemWaitTimeout (sem, 0); } -DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem) +DECLSPEC int SDLCALL +SDL_SemWait (SDL_sem * sem) { - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); + return SDL_SemWaitTimeout (sem, SDL_MUTEX_MAXWAIT); } /* Returns the current count of the semaphore */ -DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem) +DECLSPEC Uint32 SDLCALL +SDL_SemValue (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return 0; - } - return sem->value; + if (!sem) { + SDL_SetError ("Passed a NULL sem"); + return 0; + } + return sem->value; } -DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem) +DECLSPEC int SDLCALL +SDL_SemPost (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return -1; - } - if ( DosRequestMutexSem(sem->id,SEM_INDEFINITE_WAIT) ) { - SDL_SetError("DosRequestMutexSem() failed"); - return -1; - } - sem->value++; - DosPostEventSem(sem->changed); - DosReleaseMutexSem(sem->id); - return 0; + if (!sem) { + SDL_SetError ("Passed a NULL sem"); + return -1; + } + if (DosRequestMutexSem (sem->id, SEM_INDEFINITE_WAIT)) { + SDL_SetError ("DosRequestMutexSem() failed"); + return -1; + } + sem->value++; + DosPostEventSem (sem->changed); + DosReleaseMutexSem (sem->id); + return 0; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/os2/SDL_systhread.c b/src/thread/os2/SDL_systhread.c index 5a174d928..50819e077 100644 --- a/src/thread/os2/SDL_systhread.c +++ b/src/thread/os2/SDL_systhread.c @@ -34,75 +34,82 @@ typedef struct ThreadStartParms { - void *args; - pfnSDL_CurrentEndThread pfnCurrentEndThread; + void *args; + pfnSDL_CurrentEndThread pfnCurrentEndThread; } tThreadStartParms, *pThreadStartParms; -static void threadfunc(void *pparm) +static void +threadfunc (void *pparm) { - pThreadStartParms pThreadParms = pparm; - pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; - - // Call the thread function! - SDL_RunThread(pThreadParms->args); - - // Get the current endthread we have to use! - if (pThreadParms) - { - pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; - SDL_free(pThreadParms); - } - // Call endthread! - if (pfnCurrentEndThread) - (*pfnCurrentEndThread)(); + pThreadStartParms pThreadParms = pparm; + pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; + + // Call the thread function! + SDL_RunThread (pThreadParms->args); + + // Get the current endthread we have to use! + if (pThreadParms) { + pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; + SDL_free (pThreadParms); + } + // Call endthread! + if (pfnCurrentEndThread) + (*pfnCurrentEndThread) (); } -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args, + pfnSDL_CurrentBeginThread pfnBeginThread, + pfnSDL_CurrentEndThread pfnEndThread) { - pThreadStartParms pThreadParms = SDL_malloc(sizeof(tThreadStartParms)); - if (!pThreadParms) - { - SDL_SetError("Not enough memory to create thread"); - return(-1); - } - - // Save the function which we will have to call to clear the RTL of calling app! - pThreadParms->pfnCurrentEndThread = pfnEndThread; - // Also save the real parameters we have to pass to thread function - pThreadParms->args = args; - // Start the thread using the runtime library of calling app! - thread->threadid = thread->handle = (*pfnBeginThread)(threadfunc, NULL, 512*1024, pThreadParms); - if ((int)thread->threadid <= 0) - { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - return(0); + pThreadStartParms pThreadParms = SDL_malloc (sizeof (tThreadStartParms)); + if (!pThreadParms) { + SDL_SetError ("Not enough memory to create thread"); + return (-1); + } + // Save the function which we will have to call to clear the RTL of calling app! + pThreadParms->pfnCurrentEndThread = pfnEndThread; + // Also save the real parameters we have to pass to thread function + pThreadParms->args = args; + // Start the thread using the runtime library of calling app! + thread->threadid = thread->handle = + (*pfnBeginThread) (threadfunc, NULL, 512 * 1024, pThreadParms); + if ((int) thread->threadid <= 0) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - return; + return; } -DECLSPEC Uint32 SDLCALL SDL_ThreadID(void) +DECLSPEC Uint32 SDLCALL +SDL_ThreadID (void) { - PTIB tib; - DosGetInfoBlocks(&tib, NULL); - return((Uint32) (tib->tib_ptib2->tib2_ultid)); + PTIB tib; + DosGetInfoBlocks (&tib, NULL); + return ((Uint32) (tib->tib_ptib2->tib2_ultid)); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - TID tid = thread->handle; - DosWaitThread(&tid, DCWW_WAIT); + TID tid = thread->handle; + DosWaitThread (&tid, DCWW_WAIT); } /* WARNING: This function is really a last resort. * Threads should be signaled and then exit by themselves. * TerminateThread() doesn't perform stack and DLL cleanup. */ -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - DosKillThread(thread->handle); + DosKillThread (thread->handle); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/os2/SDL_systhread_c.h b/src/thread/os2/SDL_systhread_c.h index 186419de7..9008830b2 100644 --- a/src/thread/os2/SDL_systhread_c.h +++ b/src/thread/os2/SDL_systhread_c.h @@ -25,4 +25,4 @@ #include typedef TID SYS_ThreadHandle; - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pth/SDL_syscond.c b/src/thread/pth/SDL_syscond.c index 715aff118..bd80bf596 100644 --- a/src/thread/pth/SDL_syscond.c +++ b/src/thread/pth/SDL_syscond.c @@ -34,69 +34,73 @@ struct SDL_cond { - pth_cond_t condpth_p; + pth_cond_t condpth_p; }; /* Create a condition variable */ -SDL_cond * SDL_CreateCond(void) +SDL_cond * +SDL_CreateCond (void) { - SDL_cond *cond; - - cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); - if ( cond ) { - if ( pth_cond_init(&(cond->condpth_p)) < 0 ) { - SDL_SetError("pthread_cond_init() failed"); - SDL_free(cond); - cond = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(cond); + SDL_cond *cond; + + cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond)); + if (cond) { + if (pth_cond_init (&(cond->condpth_p)) < 0) { + SDL_SetError ("pthread_cond_init() failed"); + SDL_free (cond); + cond = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (cond); } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void +SDL_DestroyCond (SDL_cond * cond) { - if ( cond ) { - SDL_free(cond); - } + if (cond) { + SDL_free (cond); + } } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int +SDL_CondSignal (SDL_cond * cond) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pth_cond_notify(&(cond->condpth_p), FALSE) != 0 ) { - SDL_SetError("pth_cond_notify() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pth_cond_notify (&(cond->condpth_p), FALSE) != 0) { + SDL_SetError ("pth_cond_notify() failed"); + retval = -1; + } + return retval; } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int +SDL_CondBroadcast (SDL_cond * cond) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pth_cond_notify(&(cond->condpth_p), TRUE) != 0 ) { - SDL_SetError("pth_cond_notify() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pth_cond_notify (&(cond->condpth_p), TRUE) != 0) { + SDL_SetError ("pth_cond_notify() failed"); + retval = -1; + } + return retval; } /* Wait on the condition variable for at most 'ms' milliseconds. @@ -119,46 +123,51 @@ Thread B: ... SDL_UnlockMutex(lock); */ -int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) +int +SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { - int retval; - pth_event_t ev; - int sec; + int retval; + pth_event_t ev; + int sec; - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } - retval = 0; + retval = 0; - sec = ms/1000; - ev = pth_event(PTH_EVENT_TIME, pth_timeout(sec,(ms-sec*1000)*1000)); + sec = ms / 1000; + ev = pth_event (PTH_EVENT_TIME, + pth_timeout (sec, (ms - sec * 1000) * 1000)); - if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), ev) != 0 ) { - SDL_SetError("pth_cond_await() failed"); - retval = -1; - } + if (pth_cond_await (&(cond->condpth_p), &(mutex->mutexpth_p), ev) != 0) { + SDL_SetError ("pth_cond_await() failed"); + retval = -1; + } - pth_event_free(ev, PTH_FREE_ALL); + pth_event_free (ev, PTH_FREE_ALL); - return retval; + return retval; } /* Wait on the condition variable forever */ -int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +int +SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), NULL) != 0 ) { - SDL_SetError("pth_cond_await() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pth_cond_await (&(cond->condpth_p), &(mutex->mutexpth_p), NULL) != 0) { + SDL_SetError ("pth_cond_await() failed"); + retval = -1; + } + return retval; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pth/SDL_sysmutex.c b/src/thread/pth/SDL_sysmutex.c index 9d5b197c5..516ca46a5 100644 --- a/src/thread/pth/SDL_sysmutex.c +++ b/src/thread/pth/SDL_sysmutex.c @@ -33,55 +33,61 @@ #include "SDL_sysmutex_c.h" /* Create a mutex */ -SDL_mutex *SDL_CreateMutex(void) +SDL_mutex * +SDL_CreateMutex (void) { - SDL_mutex *mutex; - - /* Allocate mutex memory */ - mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); - if ( mutex ) { - /* Create the mutex, with initial value signaled */ - if (!pth_mutex_init(&(mutex->mutexpth_p))) { - SDL_SetError("Couldn't create mutex"); - SDL_free(mutex); - mutex = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(mutex); + SDL_mutex *mutex; + + /* Allocate mutex memory */ + mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex)); + if (mutex) { + /* Create the mutex, with initial value signaled */ + if (!pth_mutex_init (&(mutex->mutexpth_p))) { + SDL_SetError ("Couldn't create mutex"); + SDL_free (mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (mutex); } /* Free the mutex */ -void SDL_DestroyMutex(SDL_mutex *mutex) +void +SDL_DestroyMutex (SDL_mutex * mutex) { - if ( mutex ) { - SDL_free(mutex); - } + if (mutex) { + SDL_free (mutex); + } } /* Lock the mutex */ -int SDL_mutexP(SDL_mutex *mutex) +int +SDL_mutexP (SDL_mutex * mutex) { - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } - pth_mutex_acquire(&(mutex->mutexpth_p), FALSE, NULL); + pth_mutex_acquire (&(mutex->mutexpth_p), FALSE, NULL); - return(0); + return (0); } /* Unlock the mutex */ -int SDL_mutexV(SDL_mutex *mutex) +int +SDL_mutexV (SDL_mutex * mutex) { - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } - pth_mutex_release(&(mutex->mutexpth_p)); + pth_mutex_release (&(mutex->mutexpth_p)); - return(0); + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pth/SDL_sysmutex_c.h b/src/thread/pth/SDL_sysmutex_c.h index e0e9ef53a..aa60f52c6 100644 --- a/src/thread/pth/SDL_sysmutex_c.h +++ b/src/thread/pth/SDL_sysmutex_c.h @@ -24,8 +24,10 @@ #ifndef _SDL_SYSMUTEX_C_H_ #define _SDL_SYSMUTEX_C_H_ -struct SDL_mutex { - pth_mutex_t mutexpth_p; +struct SDL_mutex +{ + pth_mutex_t mutexpth_p; }; #endif /* _SDL_SYSMUTEX_C_H_ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pth/SDL_systhread.c b/src/thread/pth/SDL_systhread.c index 284003a63..4d1cf7acb 100644 --- a/src/thread/pth/SDL_systhread.c +++ b/src/thread/pth/SDL_systhread.c @@ -36,68 +36,76 @@ /* List of signals to mask in the subthreads */ static int sig_list[] = { - SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, - SIGVTALRM, SIGPROF, 0 + SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, + SIGVTALRM, SIGPROF, 0 }; -static void *RunThread(void *data) +static void * +RunThread (void *data) { - SDL_RunThread(data); - pth_exit((void*)0); - return((void *)0); /* Prevent compiler warning */ + SDL_RunThread (data); + pth_exit ((void *) 0); + return ((void *) 0); /* Prevent compiler warning */ } -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - pth_attr_t type; - - /* Create a new attribute */ - type = pth_attr_new(); - if ( type == NULL ) { - SDL_SetError("Couldn't initialize pth attributes"); - return(-1); - } - pth_attr_set(type, PTH_ATTR_JOINABLE, TRUE); - - /* Create the thread and go! */ - thread->handle = pth_spawn(type, RunThread, args); - if ( thread->handle == NULL ) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - return(0); + pth_attr_t type; + + /* Create a new attribute */ + type = pth_attr_new (); + if (type == NULL) { + SDL_SetError ("Couldn't initialize pth attributes"); + return (-1); + } + pth_attr_set (type, PTH_ATTR_JOINABLE, TRUE); + + /* Create the thread and go! */ + thread->handle = pth_spawn (type, RunThread, args); + if (thread->handle == NULL) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - int i; - sigset_t mask; - int oldstate; - - /* Mask asynchronous signals for this thread */ - sigemptyset(&mask); - for ( i=0; sig_list[i]; ++i ) { - sigaddset(&mask, sig_list[i]); - } - pth_sigmask(SIG_BLOCK, &mask, 0); - - /* Allow ourselves to be asynchronously cancelled */ - pth_cancel_state(PTH_CANCEL_ASYNCHRONOUS, &oldstate); + int i; + sigset_t mask; + int oldstate; + + /* Mask asynchronous signals for this thread */ + sigemptyset (&mask); + for (i = 0; sig_list[i]; ++i) { + sigaddset (&mask, sig_list[i]); + } + pth_sigmask (SIG_BLOCK, &mask, 0); + + /* Allow ourselves to be asynchronously cancelled */ + pth_cancel_state (PTH_CANCEL_ASYNCHRONOUS, &oldstate); } /* WARNING: This may not work for systems with 64-bit pid_t */ -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return((Uint32)pth_self()); + return ((Uint32) pth_self ()); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - pth_join(thread->handle, NULL); + pth_join (thread->handle, NULL); } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - pth_cancel(thread->handle); - pth_join(thread->handle, NULL); + pth_cancel (thread->handle); + pth_join (thread->handle, NULL); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pth/SDL_systhread_c.h b/src/thread/pth/SDL_systhread_c.h index 791eb1bdc..297d7838c 100644 --- a/src/thread/pth/SDL_systhread_c.h +++ b/src/thread/pth/SDL_systhread_c.h @@ -29,3 +29,4 @@ typedef pth_t SYS_ThreadHandle; #endif /* _SDL_SYSTHREAD_C_H_ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_syscond.c b/src/thread/pthread/SDL_syscond.c index 333f83c71..d3d2231e9 100644 --- a/src/thread/pthread/SDL_syscond.c +++ b/src/thread/pthread/SDL_syscond.c @@ -31,125 +31,133 @@ struct SDL_cond { - pthread_cond_t cond; + pthread_cond_t cond; }; /* Create a condition variable */ -SDL_cond * SDL_CreateCond(void) +SDL_cond * +SDL_CreateCond (void) { - SDL_cond *cond; - - cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); - if ( cond ) { - if ( pthread_cond_init(&cond->cond, NULL) < 0 ) { - SDL_SetError("pthread_cond_init() failed"); - SDL_free(cond); - cond = NULL; - } - } - return(cond); + SDL_cond *cond; + + cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond)); + if (cond) { + if (pthread_cond_init (&cond->cond, NULL) < 0) { + SDL_SetError ("pthread_cond_init() failed"); + SDL_free (cond); + cond = NULL; + } + } + return (cond); } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void +SDL_DestroyCond (SDL_cond * cond) { - if ( cond ) { - pthread_cond_destroy(&cond->cond); - SDL_free(cond); - } + if (cond) { + pthread_cond_destroy (&cond->cond); + SDL_free (cond); + } } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int +SDL_CondSignal (SDL_cond * cond) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pthread_cond_signal(&cond->cond) != 0 ) { - SDL_SetError("pthread_cond_signal() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pthread_cond_signal (&cond->cond) != 0) { + SDL_SetError ("pthread_cond_signal() failed"); + retval = -1; + } + return retval; } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int +SDL_CondBroadcast (SDL_cond * cond) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pthread_cond_broadcast(&cond->cond) != 0 ) { - SDL_SetError("pthread_cond_broadcast() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pthread_cond_broadcast (&cond->cond) != 0) { + SDL_SetError ("pthread_cond_broadcast() failed"); + retval = -1; + } + return retval; } -int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) +int +SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { - int retval; - struct timeval delta; - struct timespec abstime; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - gettimeofday(&delta, NULL); - - abstime.tv_sec = delta.tv_sec + (ms/1000); - abstime.tv_nsec = (delta.tv_usec + (ms%1000) * 1000) * 1000; - if ( abstime.tv_nsec > 1000000000 ) { - abstime.tv_sec += 1; - abstime.tv_nsec -= 1000000000; - } + int retval; + struct timeval delta; + struct timespec abstime; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + gettimeofday (&delta, NULL); + + abstime.tv_sec = delta.tv_sec + (ms / 1000); + abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000; + if (abstime.tv_nsec > 1000000000) { + abstime.tv_sec += 1; + abstime.tv_nsec -= 1000000000; + } tryagain: - retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime); - switch (retval) { - case EINTR: - goto tryagain; - break; - case ETIMEDOUT: - retval = SDL_MUTEX_TIMEDOUT; - break; - case 0: - break; - default: - SDL_SetError("pthread_cond_timedwait() failed"); - retval = -1; - break; - } - return retval; + retval = pthread_cond_timedwait (&cond->cond, &mutex->id, &abstime); + switch (retval) { + case EINTR: + goto tryagain; + break; + case ETIMEDOUT: + retval = SDL_MUTEX_TIMEDOUT; + break; + case 0: + break; + default: + SDL_SetError ("pthread_cond_timedwait() failed"); + retval = -1; + break; + } + return retval; } /* Wait on the condition variable, unlocking the provided mutex. The mutex must be locked before entering this function! */ -int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +int +SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pthread_cond_wait(&cond->cond, &mutex->id) != 0 ) { - SDL_SetError("pthread_cond_wait() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pthread_cond_wait (&cond->cond, &mutex->id) != 0) { + SDL_SetError ("pthread_cond_wait() failed"); + retval = -1; + } + return retval; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index 42e99b4ee..8b839f66b 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -30,124 +30,131 @@ #define FAKE_RECURSIVE_MUTEX #endif -struct SDL_mutex { - pthread_mutex_t id; +struct SDL_mutex +{ + pthread_mutex_t id; #if FAKE_RECURSIVE_MUTEX - int recursive; - pthread_t owner; + int recursive; + pthread_t owner; #endif }; -SDL_mutex *SDL_CreateMutex (void) +SDL_mutex * +SDL_CreateMutex (void) { - SDL_mutex *mutex; - pthread_mutexattr_t attr; + SDL_mutex *mutex; + pthread_mutexattr_t attr; - /* Allocate the structure */ - mutex = (SDL_mutex *)SDL_calloc(1, sizeof(*mutex)); - if ( mutex ) { - pthread_mutexattr_init(&attr); + /* Allocate the structure */ + mutex = (SDL_mutex *) SDL_calloc (1, sizeof (*mutex)); + if (mutex) { + pthread_mutexattr_init (&attr); #if SDL_THREAD_PTHREAD_RECURSIVE_MUTEX - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); #elif SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP - pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutexattr_setkind_np (&attr, PTHREAD_MUTEX_RECURSIVE_NP); #else - /* No extra attributes necessary */ + /* No extra attributes necessary */ #endif - if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) { - SDL_SetError("pthread_mutex_init() failed"); - SDL_free(mutex); - mutex = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(mutex); + if (pthread_mutex_init (&mutex->id, &attr) != 0) { + SDL_SetError ("pthread_mutex_init() failed"); + SDL_free (mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (mutex); } -void SDL_DestroyMutex(SDL_mutex *mutex) +void +SDL_DestroyMutex (SDL_mutex * mutex) { - if ( mutex ) { - pthread_mutex_destroy(&mutex->id); - SDL_free(mutex); - } + if (mutex) { + pthread_mutex_destroy (&mutex->id); + SDL_free (mutex); + } } /* Lock the mutex */ -int SDL_mutexP(SDL_mutex *mutex) +int +SDL_mutexP (SDL_mutex * mutex) { - int retval; + int retval; #if FAKE_RECURSIVE_MUTEX - pthread_t this_thread; + pthread_t this_thread; #endif - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } - retval = 0; + retval = 0; #if FAKE_RECURSIVE_MUTEX - this_thread = pthread_self(); - if ( mutex->owner == this_thread ) { - ++mutex->recursive; - } else { - /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. - */ - if ( pthread_mutex_lock(&mutex->id) == 0 ) { - mutex->owner = this_thread; - mutex->recursive = 0; - } else { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; - } - } + this_thread = pthread_self (); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + if (pthread_mutex_lock (&mutex->id) == 0) { + mutex->owner = this_thread; + mutex->recursive = 0; + } else { + SDL_SetError ("pthread_mutex_lock() failed"); + retval = -1; + } + } #else - if ( pthread_mutex_lock(&mutex->id) < 0 ) { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; - } + if (pthread_mutex_lock (&mutex->id) < 0) { + SDL_SetError ("pthread_mutex_lock() failed"); + retval = -1; + } #endif - return retval; + return retval; } -int SDL_mutexV(SDL_mutex *mutex) +int +SDL_mutexV (SDL_mutex * mutex) { - int retval; + int retval; - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } - retval = 0; + retval = 0; #if FAKE_RECURSIVE_MUTEX - /* We can only unlock the mutex if we own it */ - if ( pthread_self() == mutex->owner ) { - if ( mutex->recursive ) { - --mutex->recursive; - } else { - /* The order of operations is important. - First reset the owner so another thread doesn't lock - the mutex and set the ownership before we reset it, - then release the lock semaphore. - */ - mutex->owner = 0; - pthread_mutex_unlock(&mutex->id); - } - } else { - SDL_SetError("mutex not owned by this thread"); - retval = -1; - } + /* We can only unlock the mutex if we own it */ + if (pthread_self () == mutex->owner) { + if (mutex->recursive) { + --mutex->recursive; + } else { + /* The order of operations is important. + First reset the owner so another thread doesn't lock + the mutex and set the ownership before we reset it, + then release the lock semaphore. + */ + mutex->owner = 0; + pthread_mutex_unlock (&mutex->id); + } + } else { + SDL_SetError ("mutex not owned by this thread"); + retval = -1; + } #else - if ( pthread_mutex_unlock(&mutex->id) < 0 ) { - SDL_SetError("pthread_mutex_unlock() failed"); - retval = -1; - } + if (pthread_mutex_unlock (&mutex->id) < 0) { + SDL_SetError ("pthread_mutex_unlock() failed"); + retval = -1; + } #endif /* FAKE_RECURSIVE_MUTEX */ - return retval; + return retval; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_sysmutex_c.h b/src/thread/pthread/SDL_sysmutex_c.h index 187e7c83e..c5a129432 100644 --- a/src/thread/pthread/SDL_sysmutex_c.h +++ b/src/thread/pthread/SDL_sysmutex_c.h @@ -24,8 +24,10 @@ #ifndef _SDL_mutex_c_h #define _SDL_mutex_c_h -struct SDL_mutex { - pthread_mutex_t id; +struct SDL_mutex +{ + pthread_mutex_t id; }; #endif /* _SDL_mutex_c_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index 50c06613b..8c110e1ca 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -34,122 +34,132 @@ #include "../generic/SDL_syssem.c" #else -struct SDL_semaphore { - sem_t sem; +struct SDL_semaphore +{ + sem_t sem; }; /* Create a semaphore, initialized with value */ -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem)); - if ( sem ) { - if ( sem_init(&sem->sem, 0, initial_value) < 0 ) { - SDL_SetError("sem_init() failed"); - SDL_free(sem); - sem = NULL; - } - } else { - SDL_OutOfMemory(); - } - return sem; + SDL_sem *sem = (SDL_sem *) SDL_malloc (sizeof (SDL_sem)); + if (sem) { + if (sem_init (&sem->sem, 0, initial_value) < 0) { + SDL_SetError ("sem_init() failed"); + SDL_free (sem); + sem = NULL; + } + } else { + SDL_OutOfMemory (); + } + return sem; } -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - if ( sem ) { - sem_destroy(&sem->sem); - SDL_free(sem); - } + if (sem) { + sem_destroy (&sem->sem); + SDL_free (sem); + } } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - retval = SDL_MUTEX_TIMEDOUT; - if ( sem_trywait(&sem->sem) == 0 ) { - retval = 0; - } - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + retval = SDL_MUTEX_TIMEDOUT; + if (sem_trywait (&sem->sem) == 0) { + retval = 0; + } + return retval; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = sem_wait(&sem->sem); - if ( retval < 0 ) { - SDL_SetError("sem_wait() failed"); - } - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + retval = sem_wait (&sem->sem); + if (retval < 0) { + SDL_SetError ("sem_wait() failed"); + } + return retval; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - /* Try the easy cases first */ - if ( timeout == 0 ) { - return SDL_SemTryWait(sem); - } - if ( timeout == SDL_MUTEX_MAXWAIT ) { - return SDL_SemWait(sem); - } - - /* Ack! We have to busy wait... */ - /* FIXME: Use sem_timedwait()? */ - timeout += SDL_GetTicks(); - do { - retval = SDL_SemTryWait(sem); - if ( retval == 0 ) { - break; - } - SDL_Delay(1); - } while ( SDL_GetTicks() < timeout ); - - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + /* Try the easy cases first */ + if (timeout == 0) { + return SDL_SemTryWait (sem); + } + if (timeout == SDL_MUTEX_MAXWAIT) { + return SDL_SemWait (sem); + } + + /* Ack! We have to busy wait... */ + /* FIXME: Use sem_timedwait()? */ + timeout += SDL_GetTicks (); + do { + retval = SDL_SemTryWait (sem); + if (retval == 0) { + break; + } + SDL_Delay (1); + } + while (SDL_GetTicks () < timeout); + + return retval; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - int ret = 0; - if ( sem ) { - sem_getvalue(&sem->sem, &ret); - if ( ret < 0 ) { - ret = 0; - } - } - return (Uint32)ret; + int ret = 0; + if (sem) { + sem_getvalue (&sem->sem, &ret); + if (ret < 0) { + ret = 0; + } + } + return (Uint32) ret; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = sem_post(&sem->sem); - if ( retval < 0 ) { - SDL_SetError("sem_post() failed"); - } - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + retval = sem_post (&sem->sem); + if (retval < 0) { + SDL_SetError ("sem_post() failed"); + } + return retval; } #endif /* __MACOSX__ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index e9923facf..a9650b4b4 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -30,91 +30,99 @@ /* List of signals to mask in the subthreads */ static int sig_list[] = { - SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, - SIGVTALRM, SIGPROF, 0 + SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, + SIGVTALRM, SIGPROF, 0 }; #ifdef __RISCOS__ /* RISC OS needs to know the main thread for * it's timer and event processing. */ int riscos_using_threads = 0; -Uint32 riscos_main_thread = 0; /* Thread running events */ +Uint32 riscos_main_thread = 0; /* Thread running events */ #endif - -static void *RunThread(void *data) + +static void * +RunThread (void *data) { - SDL_RunThread(data); - pthread_exit((void*)0); - return((void *)0); /* Prevent compiler warning */ + SDL_RunThread (data); + pthread_exit ((void *) 0); + return ((void *) 0); /* Prevent compiler warning */ } -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - pthread_attr_t type; - - /* Set the thread attributes */ - if ( pthread_attr_init(&type) != 0 ) { - SDL_SetError("Couldn't initialize pthread attributes"); - return(-1); - } - pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); - - /* Create the thread and go! */ - if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - + pthread_attr_t type; + + /* Set the thread attributes */ + if (pthread_attr_init (&type) != 0) { + SDL_SetError ("Couldn't initialize pthread attributes"); + return (-1); + } + pthread_attr_setdetachstate (&type, PTHREAD_CREATE_JOINABLE); + + /* Create the thread and go! */ + if (pthread_create (&thread->handle, &type, RunThread, args) != 0) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } #ifdef __RISCOS__ - if (riscos_using_threads == 0) { - riscos_using_threads = 1; - riscos_main_thread = SDL_ThreadID(); - } + if (riscos_using_threads == 0) { + riscos_using_threads = 1; + riscos_main_thread = SDL_ThreadID (); + } #endif - return(0); + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - int i; - sigset_t mask; + int i; + sigset_t mask; - /* Mask asynchronous signals for this thread */ - sigemptyset(&mask); - for ( i=0; sig_list[i]; ++i ) { - sigaddset(&mask, sig_list[i]); - } - pthread_sigmask(SIG_BLOCK, &mask, 0); + /* Mask asynchronous signals for this thread */ + sigemptyset (&mask); + for (i = 0; sig_list[i]; ++i) { + sigaddset (&mask, sig_list[i]); + } + pthread_sigmask (SIG_BLOCK, &mask, 0); #ifdef PTHREAD_CANCEL_ASYNCHRONOUS - /* Allow ourselves to be asynchronously cancelled */ - { int oldstate; - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); - } + /* Allow ourselves to be asynchronously cancelled */ + { + int oldstate; + pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); + } #endif } /* WARNING: This may not work for systems with 64-bit pid_t */ -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return((Uint32)pthread_self()); + return ((Uint32) pthread_self ()); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - pthread_join(thread->handle, 0); + pthread_join (thread->handle, 0); } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { #ifdef PTHREAD_CANCEL_ASYNCHRONOUS - pthread_cancel(thread->handle); + pthread_cancel (thread->handle); #else #ifdef __FREEBSD__ #warning For some reason, this doesnt actually kill a thread - FreeBSD 3.2 #endif - pthread_kill(thread->handle, SIGKILL); + pthread_kill (thread->handle, SIGKILL); #endif } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_systhread_c.h b/src/thread/pthread/SDL_systhread_c.h index 2aab23ab0..c1ef4bc16 100644 --- a/src/thread/pthread/SDL_systhread_c.h +++ b/src/thread/pthread/SDL_systhread_c.h @@ -24,3 +24,4 @@ #include typedef pthread_t SYS_ThreadHandle; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_syscond.c b/src/thread/riscos/SDL_syscond.c index c04739a98..23cedd260 100644 --- a/src/thread/riscos/SDL_syscond.c +++ b/src/thread/riscos/SDL_syscond.c @@ -35,126 +35,133 @@ struct SDL_cond { - pthread_cond_t cond; + pthread_cond_t cond; }; /* Create a condition variable */ -SDL_cond * SDL_CreateCond(void) +SDL_cond * +SDL_CreateCond (void) { - SDL_cond *cond; - - cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); - if ( cond ) { - if ( pthread_cond_init(&cond->cond, NULL) < 0 ) { - SDL_SetError("pthread_cond_init() failed"); - SDL_free(cond); - cond = NULL; - } - } - return(cond); + SDL_cond *cond; + + cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond)); + if (cond) { + if (pthread_cond_init (&cond->cond, NULL) < 0) { + SDL_SetError ("pthread_cond_init() failed"); + SDL_free (cond); + cond = NULL; + } + } + return (cond); } /* Destroy a condition variable */ -void SDL_DestroyCond(SDL_cond *cond) +void +SDL_DestroyCond (SDL_cond * cond) { - if ( cond ) { - pthread_cond_destroy(&cond->cond); - SDL_free(cond); - } + if (cond) { + pthread_cond_destroy (&cond->cond); + SDL_free (cond); + } } /* Restart one of the threads that are waiting on the condition variable */ -int SDL_CondSignal(SDL_cond *cond) +int +SDL_CondSignal (SDL_cond * cond) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pthread_cond_signal(&cond->cond) != 0 ) { - SDL_SetError("pthread_cond_signal() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pthread_cond_signal (&cond->cond) != 0) { + SDL_SetError ("pthread_cond_signal() failed"); + retval = -1; + } + return retval; } /* Restart all threads that are waiting on the condition variable */ -int SDL_CondBroadcast(SDL_cond *cond) +int +SDL_CondBroadcast (SDL_cond * cond) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pthread_cond_broadcast(&cond->cond) != 0 ) { - SDL_SetError("pthread_cond_broadcast() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pthread_cond_broadcast (&cond->cond) != 0) { + SDL_SetError ("pthread_cond_broadcast() failed"); + retval = -1; + } + return retval; } -int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) +int +SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { - int retval; - struct timeval delta; - struct timespec abstime; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - gettimeofday(&delta, NULL); - - abstime.tv_sec = delta.tv_sec + (ms/1000); - abstime.tv_nsec = (delta.tv_usec + (ms%1000) * 1000) * 1000; - if ( abstime.tv_nsec > 1000000000 ) { - abstime.tv_sec += 1; - abstime.tv_nsec -= 1000000000; - } + int retval; + struct timeval delta; + struct timespec abstime; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + gettimeofday (&delta, NULL); + + abstime.tv_sec = delta.tv_sec + (ms / 1000); + abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000; + if (abstime.tv_nsec > 1000000000) { + abstime.tv_sec += 1; + abstime.tv_nsec -= 1000000000; + } tryagain: - retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime); - switch (retval) { - case EINTR: - goto tryagain; - break; - case ETIMEDOUT: - retval = SDL_MUTEX_TIMEDOUT; - break; - case 0: - break; - default: - SDL_SetError("pthread_cond_timedwait() failed"); - retval = -1; - break; - } - return retval; + retval = pthread_cond_timedwait (&cond->cond, &mutex->id, &abstime); + switch (retval) { + case EINTR: + goto tryagain; + break; + case ETIMEDOUT: + retval = SDL_MUTEX_TIMEDOUT; + break; + case 0: + break; + default: + SDL_SetError ("pthread_cond_timedwait() failed"); + retval = -1; + break; + } + return retval; } /* Wait on the condition variable, unlocking the provided mutex. The mutex must be locked before entering this function! */ -int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) +int +SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex) { - int retval; - - if ( ! cond ) { - SDL_SetError("Passed a NULL condition variable"); - return -1; - } - - retval = 0; - if ( pthread_cond_wait(&cond->cond, &mutex->id) != 0 ) { - SDL_SetError("pthread_cond_wait() failed"); - retval = -1; - } - return retval; + int retval; + + if (!cond) { + SDL_SetError ("Passed a NULL condition variable"); + return -1; + } + + retval = 0; + if (pthread_cond_wait (&cond->cond, &mutex->id) != 0) { + SDL_SetError ("pthread_cond_wait() failed"); + retval = -1; + } + return retval; } #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_sysmutex.c b/src/thread/riscos/SDL_sysmutex.c index aa4d65ee9..4edb9e9fe 100644 --- a/src/thread/riscos/SDL_sysmutex.c +++ b/src/thread/riscos/SDL_sysmutex.c @@ -31,123 +31,129 @@ #include -struct SDL_mutex { - pthread_mutex_t id; +struct SDL_mutex +{ + pthread_mutex_t id; #if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - int recursive; - pthread_t owner; + int recursive; + pthread_t owner; #endif }; -SDL_mutex *SDL_CreateMutex (void) +SDL_mutex * +SDL_CreateMutex (void) { - SDL_mutex *mutex; - pthread_mutexattr_t attr; + SDL_mutex *mutex; + pthread_mutexattr_t attr; - /* Allocate the structure */ - mutex = (SDL_mutex *)SDL_calloc(1, sizeof(*mutex)); - if ( mutex ) { - pthread_mutexattr_init(&attr); + /* Allocate the structure */ + mutex = (SDL_mutex *) SDL_calloc (1, sizeof (*mutex)); + if (mutex) { + pthread_mutexattr_init (&attr); #if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - /* No extra attributes necessary */ + /* No extra attributes necessary */ #else - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); #endif /* SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX */ - if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) { - SDL_SetError("pthread_mutex_init() failed"); - SDL_free(mutex); - mutex = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(mutex); + if (pthread_mutex_init (&mutex->id, &attr) != 0) { + SDL_SetError ("pthread_mutex_init() failed"); + SDL_free (mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (mutex); } -void SDL_DestroyMutex(SDL_mutex *mutex) +void +SDL_DestroyMutex (SDL_mutex * mutex) { - if ( mutex ) { - pthread_mutex_destroy(&mutex->id); - SDL_free(mutex); - } + if (mutex) { + pthread_mutex_destroy (&mutex->id); + SDL_free (mutex); + } } /* Lock the mutex */ -int SDL_mutexP(SDL_mutex *mutex) +int +SDL_mutexP (SDL_mutex * mutex) { - int retval; + int retval; #if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - pthread_t this_thread; + pthread_t this_thread; #endif - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } - retval = 0; + retval = 0; #if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - this_thread = pthread_self(); - if ( mutex->owner == this_thread ) { - ++mutex->recursive; - } else { - /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. - */ - if ( pthread_mutex_lock(&mutex->id) == 0 ) { - mutex->owner = this_thread; - mutex->recursive = 0; - } else { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; - } - } + this_thread = pthread_self (); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + if (pthread_mutex_lock (&mutex->id) == 0) { + mutex->owner = this_thread; + mutex->recursive = 0; + } else { + SDL_SetError ("pthread_mutex_lock() failed"); + retval = -1; + } + } #else - if ( pthread_mutex_lock(&mutex->id) < 0 ) { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; - } + if (pthread_mutex_lock (&mutex->id) < 0) { + SDL_SetError ("pthread_mutex_lock() failed"); + retval = -1; + } #endif - return retval; + return retval; } -int SDL_mutexV(SDL_mutex *mutex) +int +SDL_mutexV (SDL_mutex * mutex) { - int retval; + int retval; - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } - retval = 0; + retval = 0; #if SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX - /* We can only unlock the mutex if we own it */ - if ( pthread_self() == mutex->owner ) { - if ( mutex->recursive ) { - --mutex->recursive; - } else { - /* The order of operations is important. - First reset the owner so another thread doesn't lock - the mutex and set the ownership before we reset it, - then release the lock semaphore. - */ - mutex->owner = 0; - pthread_mutex_unlock(&mutex->id); - } - } else { - SDL_SetError("mutex not owned by this thread"); - retval = -1; - } + /* We can only unlock the mutex if we own it */ + if (pthread_self () == mutex->owner) { + if (mutex->recursive) { + --mutex->recursive; + } else { + /* The order of operations is important. + First reset the owner so another thread doesn't lock + the mutex and set the ownership before we reset it, + then release the lock semaphore. + */ + mutex->owner = 0; + pthread_mutex_unlock (&mutex->id); + } + } else { + SDL_SetError ("mutex not owned by this thread"); + retval = -1; + } #else - if ( pthread_mutex_unlock(&mutex->id) < 0 ) { - SDL_SetError("pthread_mutex_unlock() failed"); - retval = -1; - } + if (pthread_mutex_unlock (&mutex->id) < 0) { + SDL_SetError ("pthread_mutex_unlock() failed"); + retval = -1; + } #endif /* SDL_THREAD_PTHREAD_NO_RECURSIVE_MUTEX */ - return retval; + return retval; } #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_sysmutex_c.h b/src/thread/riscos/SDL_sysmutex_c.h index fcd03d256..65fc2e314 100644 --- a/src/thread/riscos/SDL_sysmutex_c.h +++ b/src/thread/riscos/SDL_sysmutex_c.h @@ -25,10 +25,12 @@ #define _SDL_mutex_c_h #if !SDL_THREADS_DISABLED -struct SDL_mutex { - pthread_mutex_t id; +struct SDL_mutex +{ + pthread_mutex_t id; }; #endif #endif /* _SDL_mutex_c_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_syssem.c b/src/thread/riscos/SDL_syssem.c index 0e563883b..91499fde1 100644 --- a/src/thread/riscos/SDL_syssem.c +++ b/src/thread/riscos/SDL_syssem.c @@ -30,171 +30,188 @@ #if !SDL_THREADS_DISABLED -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_SetError("SDL not configured with thread support"); - return (SDL_sem *)0; + SDL_SetError ("SDL not configured with thread support"); + return (SDL_sem *) 0; } -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - return; + return; } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - return 0; + return 0; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + SDL_SetError ("SDL not configured with thread support"); + return -1; } #else -#include /* For getpid() */ +#include /* For getpid() */ #include #include -struct SDL_semaphore { - sem_t *sem; - sem_t sem_data; +struct SDL_semaphore +{ + sem_t *sem; + sem_t sem_data; }; /* Create a semaphore, initialized with value */ -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem)); - if ( sem ) { - if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) { - SDL_SetError("sem_init() failed"); - SDL_free(sem); - sem = NULL; - } else { - sem->sem = &sem->sem_data; - } - } else { - SDL_OutOfMemory(); - } - return sem; + SDL_sem *sem = (SDL_sem *) SDL_malloc (sizeof (SDL_sem)); + if (sem) { + if (sem_init (&sem->sem_data, 0, initial_value) < 0) { + SDL_SetError ("sem_init() failed"); + SDL_free (sem); + sem = NULL; + } else { + sem->sem = &sem->sem_data; + } + } else { + SDL_OutOfMemory (); + } + return sem; } -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - if ( sem ) { - sem_destroy(sem->sem); - SDL_free(sem); - } + if (sem) { + sem_destroy (sem->sem); + SDL_free (sem); + } } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - retval = SDL_MUTEX_TIMEDOUT; - if ( sem_trywait(sem->sem) == 0 ) { - retval = 0; - } - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + retval = SDL_MUTEX_TIMEDOUT; + if (sem_trywait (sem->sem) == 0) { + retval = 0; + } + return retval; } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = sem_wait(sem->sem); - if ( retval < 0 ) { - SDL_SetError("sem_wait() failed"); - } - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + retval = sem_wait (sem->sem); + if (retval < 0) { + SDL_SetError ("sem_wait() failed"); + } + return retval; } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - /* Try the easy cases first */ - if ( timeout == 0 ) { - return SDL_SemTryWait(sem); - } - if ( timeout == SDL_MUTEX_MAXWAIT ) { - return SDL_SemWait(sem); - } - - /* Ack! We have to busy wait... */ - timeout += SDL_GetTicks(); - do { - retval = SDL_SemTryWait(sem); - if ( retval == 0 ) { - break; - } - SDL_Delay(1); - } while ( SDL_GetTicks() < timeout ); - - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + /* Try the easy cases first */ + if (timeout == 0) { + return SDL_SemTryWait (sem); + } + if (timeout == SDL_MUTEX_MAXWAIT) { + return SDL_SemWait (sem); + } + + /* Ack! We have to busy wait... */ + timeout += SDL_GetTicks (); + do { + retval = SDL_SemTryWait (sem); + if (retval == 0) { + break; + } + SDL_Delay (1); + } + while (SDL_GetTicks () < timeout); + + return retval; } -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - int ret = 0; - if ( sem ) { - sem_getvalue(sem->sem, &ret); - if ( ret < 0 ) { - ret = 0; - } - } - return (Uint32)ret; + int ret = 0; + if (sem) { + sem_getvalue (sem->sem, &ret); + if (ret < 0) { + ret = 0; + } + } + return (Uint32) ret; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - int retval; - - if ( ! sem ) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = sem_post(sem->sem); - if ( retval < 0 ) { - SDL_SetError("sem_post() failed"); - } - return retval; + int retval; + + if (!sem) { + SDL_SetError ("Passed a NULL semaphore"); + return -1; + } + + retval = sem_post (sem->sem); + if (retval < 0) { + SDL_SetError ("sem_post() failed"); + } + return retval; } #endif /* !SDL_THREADS_DISABLED */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_systhread.c b/src/thread/riscos/SDL_systhread.c index 318bb9d60..1d6740ce8 100644 --- a/src/thread/riscos/SDL_systhread.c +++ b/src/thread/riscos/SDL_systhread.c @@ -28,30 +28,36 @@ #if SDL_THREADS_DISABLED -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - SDL_SetError("Threads have not been compiled into this version of the library"); - return(-1); + SDL_SetError + ("Threads have not been compiled into this version of the library"); + return (-1); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - return; + return; } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return(0); + return (0); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - return; + return; } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - return; + return; } #else @@ -60,85 +66,92 @@ void SDL_SYS_KillThread(SDL_Thread *thread) /* List of signals to mask in the subthreads */ static int sig_list[] = { - SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, - SIGVTALRM, SIGPROF, 0 + SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, + SIGVTALRM, SIGPROF, 0 }; #include int riscos_using_threads = 0; -Uint32 riscos_main_thread = 0; /* Thread running events */ +Uint32 riscos_main_thread = 0; /* Thread running events */ -static void *RunThread(void *data) +static void * +RunThread (void *data) { - SDL_RunThread(data); - pthread_exit((void*)0); - return((void *)0); /* Prevent compiler warning */ + SDL_RunThread (data); + pthread_exit ((void *) 0); + return ((void *) 0); /* Prevent compiler warning */ } -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { - pthread_attr_t type; - - /* Set the thread attributes */ - if ( pthread_attr_init(&type) != 0 ) { - SDL_SetError("Couldn't initialize pthread attributes"); - return(-1); - } - pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); - - /* Create the thread and go! */ - if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - - if (riscos_using_threads == 0) - { - riscos_using_threads = 1; - riscos_main_thread = SDL_ThreadID(); - } - - return(0); + pthread_attr_t type; + + /* Set the thread attributes */ + if (pthread_attr_init (&type) != 0) { + SDL_SetError ("Couldn't initialize pthread attributes"); + return (-1); + } + pthread_attr_setdetachstate (&type, PTHREAD_CREATE_JOINABLE); + + /* Create the thread and go! */ + if (pthread_create (&thread->handle, &type, RunThread, args) != 0) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + + if (riscos_using_threads == 0) { + riscos_using_threads = 1; + riscos_main_thread = SDL_ThreadID (); + } + + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - int i; - sigset_t mask; - - /* Mask asynchronous signals for this thread */ - sigemptyset(&mask); - for ( i=0; sig_list[i]; ++i ) { - sigaddset(&mask, sig_list[i]); - } - pthread_sigmask(SIG_BLOCK, &mask, 0); - + int i; + sigset_t mask; + + /* Mask asynchronous signals for this thread */ + sigemptyset (&mask); + for (i = 0; sig_list[i]; ++i) { + sigaddset (&mask, sig_list[i]); + } + pthread_sigmask (SIG_BLOCK, &mask, 0); + #ifdef PTHREAD_CANCEL_ASYNCHRONOUS - /* Allow ourselves to be asynchronously cancelled */ - { int oldstate; - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); - } + /* Allow ourselves to be asynchronously cancelled */ + { + int oldstate; + pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); + } #endif } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return((Uint32)pthread_self()); + return ((Uint32) pthread_self ()); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - pthread_join(thread->handle, 0); + pthread_join (thread->handle, 0); } -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { #ifdef PTHREAD_CANCEL_ASYNCHRONOUS - pthread_cancel(thread->handle); + pthread_cancel (thread->handle); #else - pthread_kill(thread->handle, SIGKILL); + pthread_kill (thread->handle, SIGKILL); #endif } #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/riscos/SDL_systhread_c.h b/src/thread/riscos/SDL_systhread_c.h index 22867a627..aa9357e5f 100644 --- a/src/thread/riscos/SDL_systhread_c.h +++ b/src/thread/riscos/SDL_systhread_c.h @@ -32,3 +32,4 @@ typedef int SYS_ThreadHandle; typedef pthread_t SYS_ThreadHandle; #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/win32/SDL_sysmutex.c b/src/thread/win32/SDL_sysmutex.c index da8382927..d9af75863 100644 --- a/src/thread/win32/SDL_sysmutex.c +++ b/src/thread/win32/SDL_sysmutex.c @@ -29,67 +29,74 @@ #include "SDL_mutex.h" -struct SDL_mutex { - HANDLE id; +struct SDL_mutex +{ + HANDLE id; }; /* Create a mutex */ -SDL_mutex *SDL_CreateMutex(void) +SDL_mutex * +SDL_CreateMutex (void) { - SDL_mutex *mutex; + SDL_mutex *mutex; - /* Allocate mutex memory */ - mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); - if ( mutex ) { - /* Create the mutex, with initial value signaled */ - mutex->id = CreateMutex(NULL, FALSE, NULL); - if ( ! mutex->id ) { - SDL_SetError("Couldn't create mutex"); - SDL_free(mutex); - mutex = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(mutex); + /* Allocate mutex memory */ + mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex)); + if (mutex) { + /* Create the mutex, with initial value signaled */ + mutex->id = CreateMutex (NULL, FALSE, NULL); + if (!mutex->id) { + SDL_SetError ("Couldn't create mutex"); + SDL_free (mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (mutex); } /* Free the mutex */ -void SDL_DestroyMutex(SDL_mutex *mutex) +void +SDL_DestroyMutex (SDL_mutex * mutex) { - if ( mutex ) { - if ( mutex->id ) { - CloseHandle(mutex->id); - mutex->id = 0; - } - SDL_free(mutex); - } + if (mutex) { + if (mutex->id) { + CloseHandle (mutex->id); + mutex->id = 0; + } + SDL_free (mutex); + } } /* Lock the mutex */ -int SDL_mutexP(SDL_mutex *mutex) +int +SDL_mutexP (SDL_mutex * mutex) { - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - if ( WaitForSingleObject(mutex->id, INFINITE) == WAIT_FAILED ) { - SDL_SetError("Couldn't wait on mutex"); - return -1; - } - return(0); + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + if (WaitForSingleObject (mutex->id, INFINITE) == WAIT_FAILED) { + SDL_SetError ("Couldn't wait on mutex"); + return -1; + } + return (0); } /* Unlock the mutex */ -int SDL_mutexV(SDL_mutex *mutex) +int +SDL_mutexV (SDL_mutex * mutex) { - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - if ( ReleaseMutex(mutex->id) == FALSE ) { - SDL_SetError("Couldn't release mutex"); - return -1; - } - return(0); + if (mutex == NULL) { + SDL_SetError ("Passed a NULL mutex"); + return -1; + } + if (ReleaseMutex (mutex->id) == FALSE) { + SDL_SetError ("Couldn't release mutex"); + return -1; + } + return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/win32/SDL_syssem.c b/src/thread/win32/SDL_syssem.c index c7a1bfd53..a8a378151 100644 --- a/src/thread/win32/SDL_syssem.c +++ b/src/thread/win32/SDL_syssem.c @@ -32,133 +32,143 @@ #endif -struct SDL_semaphore { +struct SDL_semaphore +{ #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - SYNCHHANDLE id; + SYNCHHANDLE id; #else - HANDLE id; + HANDLE id; #endif - Uint32 volatile count; + Uint32 volatile count; }; /* Create a semaphore */ -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +SDL_sem * +SDL_CreateSemaphore (Uint32 initial_value) { - SDL_sem *sem; + SDL_sem *sem; - /* Allocate sem memory */ - sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); - if ( sem ) { - /* Create the semaphore, with max value 32K */ + /* Allocate sem memory */ + sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); + if (sem) { + /* Create the semaphore, with max value 32K */ #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - sem->id = CreateSemaphoreCE(NULL, initial_value, 32*1024, NULL); + sem->id = CreateSemaphoreCE (NULL, initial_value, 32 * 1024, NULL); #else - sem->id = CreateSemaphore(NULL, initial_value, 32*1024, NULL); + sem->id = CreateSemaphore (NULL, initial_value, 32 * 1024, NULL); #endif - sem->count = initial_value; - if ( ! sem->id ) { - SDL_SetError("Couldn't create semaphore"); - SDL_free(sem); - sem = NULL; - } - } else { - SDL_OutOfMemory(); - } - return(sem); + sem->count = initial_value; + if (!sem->id) { + SDL_SetError ("Couldn't create semaphore"); + SDL_free (sem); + sem = NULL; + } + } else { + SDL_OutOfMemory (); + } + return (sem); } /* Free the semaphore */ -void SDL_DestroySemaphore(SDL_sem *sem) +void +SDL_DestroySemaphore (SDL_sem * sem) { - if ( sem ) { - if ( sem->id ) { + if (sem) { + if (sem->id) { #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - CloseSynchHandle(sem->id); + CloseSynchHandle (sem->id); #else - CloseHandle(sem->id); + CloseHandle (sem->id); #endif - sem->id = 0; - } - SDL_free(sem); - } + sem->id = 0; + } + SDL_free (sem); + } } -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +int +SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) { - int retval; - DWORD dwMilliseconds; - - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return -1; - } - - if ( timeout == SDL_MUTEX_MAXWAIT ) { - dwMilliseconds = INFINITE; - } else { - dwMilliseconds = (DWORD)timeout; - } + int retval; + DWORD dwMilliseconds; + + if (!sem) { + SDL_SetError ("Passed a NULL sem"); + return -1; + } + + if (timeout == SDL_MUTEX_MAXWAIT) { + dwMilliseconds = INFINITE; + } else { + dwMilliseconds = (DWORD) timeout; + } #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - switch (WaitForSemaphoreCE(sem->id, dwMilliseconds)) { + switch (WaitForSemaphoreCE (sem->id, dwMilliseconds)) { #else - switch (WaitForSingleObject(sem->id, dwMilliseconds)) { + switch (WaitForSingleObject (sem->id, dwMilliseconds)) { #endif - case WAIT_OBJECT_0: - --sem->count; - retval = 0; - break; - case WAIT_TIMEOUT: - retval = SDL_MUTEX_TIMEDOUT; - break; - default: - SDL_SetError("WaitForSingleObject() failed"); - retval = -1; - break; - } - return retval; + case WAIT_OBJECT_0: + --sem->count; + retval = 0; + break; + case WAIT_TIMEOUT: + retval = SDL_MUTEX_TIMEDOUT; + break; + default: + SDL_SetError ("WaitForSingleObject() failed"); + retval = -1; + break; + } + return retval; } -int SDL_SemTryWait(SDL_sem *sem) +int +SDL_SemTryWait (SDL_sem * sem) { - return SDL_SemWaitTimeout(sem, 0); + return SDL_SemWaitTimeout (sem, 0); } -int SDL_SemWait(SDL_sem *sem) +int +SDL_SemWait (SDL_sem * sem) { - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); + return SDL_SemWaitTimeout (sem, SDL_MUTEX_MAXWAIT); } /* Returns the current count of the semaphore */ -Uint32 SDL_SemValue(SDL_sem *sem) +Uint32 +SDL_SemValue (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return 0; - } - return sem->count; + if (!sem) { + SDL_SetError ("Passed a NULL sem"); + return 0; + } + return sem->count; } -int SDL_SemPost(SDL_sem *sem) +int +SDL_SemPost (SDL_sem * sem) { - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return -1; - } - /* Increase the counter in the first place, because - * after a successful release the semaphore may - * immediately get destroyed by another thread which - * is waiting for this semaphore. - */ - ++sem->count; + if (!sem) { + SDL_SetError ("Passed a NULL sem"); + return -1; + } + /* Increase the counter in the first place, because + * after a successful release the semaphore may + * immediately get destroyed by another thread which + * is waiting for this semaphore. + */ + ++sem->count; #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - if ( ReleaseSemaphoreCE(sem->id, 1, NULL) == FALSE ) { + if (ReleaseSemaphoreCE (sem->id, 1, NULL) == FALSE) { #else - if ( ReleaseSemaphore(sem->id, 1, NULL) == FALSE ) { + if (ReleaseSemaphore (sem->id, 1, NULL) == FALSE) { #endif - --sem->count; /* restore */ - SDL_SetError("ReleaseSemaphore() failed"); - return -1; - } - return 0; + --sem->count; /* restore */ + SDL_SetError ("ReleaseSemaphore() failed"); + return -1; + } + return 0; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/win32/SDL_systhread.c b/src/thread/win32/SDL_systhread.c index 67b176dfb..415fb2ad6 100644 --- a/src/thread/win32/SDL_systhread.c +++ b/src/thread/win32/SDL_systhread.c @@ -37,114 +37,141 @@ #endif #if __GNUC__ -typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned + (__stdcall * + func) (void *), + void *arg, + unsigned, + unsigned + *threadID); +typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); #elif defined(__WATCOMC__) /* This is for Watcom targets except OS2 */ #if __WATCOMC__ < 1240 #define __watcall #endif -typedef unsigned long (__watcall *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__watcall *pfnSDL_CurrentEndThread)(unsigned code); +typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (void *, + unsigned, + unsigned + (__stdcall * + func) (void + *), + void *arg, + unsigned, + unsigned + *threadID); +typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code); #else -typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned (__stdcall * + func) (void + *), + void *arg, unsigned, + unsigned *threadID); +typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); #endif #endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */ typedef struct ThreadStartParms { - void *args; - pfnSDL_CurrentEndThread pfnCurrentEndThread; + void *args; + pfnSDL_CurrentEndThread pfnCurrentEndThread; } tThreadStartParms, *pThreadStartParms; -static unsigned __stdcall RunThread(void *data) +static unsigned __stdcall +RunThread (void *data) { - pThreadStartParms pThreadParms = (pThreadStartParms)data; - pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; - - // Call the thread function! - SDL_RunThread(pThreadParms->args); - - // Get the current endthread we have to use! - if (pThreadParms) - { - pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; - SDL_free(pThreadParms); - } - // Call endthread! - if (pfnCurrentEndThread) - (*pfnCurrentEndThread)(0); - return(0); + pThreadStartParms pThreadParms = (pThreadStartParms) data; + pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; + + // Call the thread function! + SDL_RunThread (pThreadParms->args); + + // Get the current endthread we have to use! + if (pThreadParms) { + pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; + SDL_free (pThreadParms); + } + // Call endthread! + if (pfnCurrentEndThread) + (*pfnCurrentEndThread) (0); + return (0); } #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args, + pfnSDL_CurrentBeginThread pfnBeginThread, + pfnSDL_CurrentEndThread pfnEndThread) { #else -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread (SDL_Thread * thread, void *args) { #ifdef _WIN32_WCE - pfnSDL_CurrentBeginThread pfnBeginThread = NULL; - pfnSDL_CurrentEndThread pfnEndThread = NULL; + pfnSDL_CurrentBeginThread pfnBeginThread = NULL; + pfnSDL_CurrentEndThread pfnEndThread = NULL; #else - pfnSDL_CurrentBeginThread pfnBeginThread = _beginthreadex; - pfnSDL_CurrentEndThread pfnEndThread = _endthreadex; + pfnSDL_CurrentBeginThread pfnBeginThread = _beginthreadex; + pfnSDL_CurrentEndThread pfnEndThread = _endthreadex; #endif #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */ - unsigned threadid; - pThreadStartParms pThreadParms = (pThreadStartParms)SDL_malloc(sizeof(tThreadStartParms)); - if (!pThreadParms) { - SDL_OutOfMemory(); - return(-1); - } - - // Save the function which we will have to call to clear the RTL of calling app! - pThreadParms->pfnCurrentEndThread = pfnEndThread; - // Also save the real parameters we have to pass to thread function - pThreadParms->args = args; - - if (pfnBeginThread) { - thread->handle = (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread, - pThreadParms, 0, &threadid); - } else { - thread->handle = CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid); - } - if (thread->handle == NULL) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - return(0); + unsigned threadid; + pThreadStartParms pThreadParms = + (pThreadStartParms) SDL_malloc (sizeof (tThreadStartParms)); + if (!pThreadParms) { + SDL_OutOfMemory (); + return (-1); + } + // Save the function which we will have to call to clear the RTL of calling app! + pThreadParms->pfnCurrentEndThread = pfnEndThread; + // Also save the real parameters we have to pass to thread function + pThreadParms->args = args; + + if (pfnBeginThread) { + thread->handle = + (SYS_ThreadHandle) pfnBeginThread (NULL, 0, RunThread, + pThreadParms, 0, &threadid); + } else { + thread->handle = + CreateThread (NULL, 0, RunThread, pThreadParms, 0, &threadid); + } + if (thread->handle == NULL) { + SDL_SetError ("Not enough resources to create thread"); + return (-1); + } + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread (void) { - return; + return; } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID (void) { - return((Uint32)GetCurrentThreadId()); + return ((Uint32) GetCurrentThreadId ()); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread (SDL_Thread * thread) { - WaitForSingleObject(thread->handle, INFINITE); - CloseHandle(thread->handle); + WaitForSingleObject (thread->handle, INFINITE); + CloseHandle (thread->handle); } /* WARNING: This function is really a last resort. * Threads should be signaled and then exit by themselves. * TerminateThread() doesn't perform stack and DLL cleanup. */ -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread (SDL_Thread * thread) { - TerminateThread(thread->handle, FALSE); + TerminateThread (thread->handle, FALSE); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/win32/SDL_systhread_c.h b/src/thread/win32/SDL_systhread_c.h index 906a9586a..b1c719172 100644 --- a/src/thread/win32/SDL_systhread_c.h +++ b/src/thread/win32/SDL_systhread_c.h @@ -25,4 +25,4 @@ #include typedef HANDLE SYS_ThreadHandle; - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/win32/win_ce_semaphore.c b/src/thread/win32/win_ce_semaphore.c index 9db45c439..eb9848841 100644 --- a/src/thread/win32/win_ce_semaphore.c +++ b/src/thread/win32/win_ce_semaphore.c @@ -35,13 +35,11 @@ static SYNCHHANDLE CleanUp (SYNCHHANDLE hSynch, DWORD Flags); -SYNCHHANDLE CreateSemaphoreCE ( - - LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, /* pointer to security attributes */ - LONG lInitialCount, /* initial count */ - LONG lMaximumCount, /* maximum count */ - LPCTSTR lpName ) - +SYNCHHANDLE +CreateSemaphoreCE (LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, /* pointer to security attributes */ + LONG lInitialCount, /* initial count */ + LONG lMaximumCount, /* maximum count */ + LPCTSTR lpName) /* Semaphore for use with Windows CE that does not support them directly. Requires a counter, a mutex to protect the counter, and an autoreset event. @@ -57,160 +55,176 @@ SYNCHHANDLE CreateSemaphoreCE ( 2. The event is in a signaled state if and only if the current semaphore count ("CurCount") is greater than zero. 3. The semaphore count is always >= 0 and <= the maximum count */ - { - SYNCHHANDLE hSynch = NULL, result = NULL; - - __try - { - if (lInitialCount > lMaximumCount || lMaximumCount < 0 || lInitialCount < 0) - { - /* Bad parameters */ - SetLastError (SYNCH_ERROR); - __leave; - } - - hSynch = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, SYNCH_HANDLE_SIZE); - if (hSynch == NULL) __leave; - - hSynch->MaxCount = lMaximumCount; - hSynch->CurCount = lInitialCount; - hSynch->lpName = lpName; - - hSynch->hMutex = CreateMutex (lpSemaphoreAttributes, FALSE, NULL); - - WaitForSingleObject (hSynch->hMutex, INFINITE); - /* Create the event. It is initially signaled if and only if the - initial count is > 0 */ - hSynch->hEvent = CreateEvent (lpSemaphoreAttributes, FALSE, - lInitialCount > 0, NULL); - ReleaseMutex (hSynch->hMutex); - hSynch->hSemph = NULL; - } - __finally - { - /* Return with the handle, or, if there was any error, return - a null after closing any open handles and freeing any allocated memory. */ - result=CleanUp(hSynch, 6 /* An event and a mutex, but no semaphore. */); - } - - return result; + SYNCHHANDLE hSynch = NULL, result = NULL; + + __try { + if (lInitialCount > lMaximumCount || lMaximumCount < 0 + || lInitialCount < 0) { + /* Bad parameters */ + SetLastError (SYNCH_ERROR); + __leave; + } + + hSynch = + HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, + SYNCH_HANDLE_SIZE); + if (hSynch == NULL) + __leave; + + hSynch->MaxCount = lMaximumCount; + hSynch->CurCount = lInitialCount; + hSynch->lpName = lpName; + + hSynch->hMutex = CreateMutex (lpSemaphoreAttributes, FALSE, NULL); + + WaitForSingleObject (hSynch->hMutex, INFINITE); + /* Create the event. It is initially signaled if and only if the + initial count is > 0 */ + hSynch->hEvent = CreateEvent (lpSemaphoreAttributes, FALSE, + lInitialCount > 0, NULL); + ReleaseMutex (hSynch->hMutex); + hSynch->hSemph = NULL; + } + __finally { + /* Return with the handle, or, if there was any error, return + a null after closing any open handles and freeing any allocated memory. */ + result = + CleanUp (hSynch, + 6 /* An event and a mutex, but no semaphore. */ ); + } + + return result; } -BOOL ReleaseSemaphoreCE (SYNCHHANDLE hSemCE, LONG cReleaseCount, LPLONG lpPreviousCount) +BOOL +ReleaseSemaphoreCE (SYNCHHANDLE hSemCE, LONG cReleaseCount, + LPLONG lpPreviousCount) /* Windows CE equivalent to ReleaseSemaphore. */ { - BOOL Result = TRUE; - - /* Gain access to the object to assure that the release count - would not cause the total count to exceed the maximum. */ - - __try - { - WaitForSingleObject (hSemCE->hMutex, INFINITE); - /* reply only if asked to */ - if (lpPreviousCount!=NULL) - *lpPreviousCount = hSemCE->CurCount; - if (hSemCE->CurCount + cReleaseCount > hSemCE->MaxCount || cReleaseCount <= 0) - { - SetLastError (SYNCH_ERROR); - Result = FALSE; - __leave; - } - hSemCE->CurCount += cReleaseCount; - - /* Set the autoreset event, releasing exactly one waiting thread, now or - in the future. */ - - SetEvent (hSemCE->hEvent); - } - __finally - { - ReleaseMutex (hSemCE->hMutex); - } - - return Result; + BOOL Result = TRUE; + + /* Gain access to the object to assure that the release count + would not cause the total count to exceed the maximum. */ + + __try { + WaitForSingleObject (hSemCE->hMutex, INFINITE); + /* reply only if asked to */ + if (lpPreviousCount != NULL) + *lpPreviousCount = hSemCE->CurCount; + if (hSemCE->CurCount + cReleaseCount > hSemCE->MaxCount + || cReleaseCount <= 0) { + SetLastError (SYNCH_ERROR); + Result = FALSE; + __leave; + } + hSemCE->CurCount += cReleaseCount; + + /* Set the autoreset event, releasing exactly one waiting thread, now or + in the future. */ + + SetEvent (hSemCE->hEvent); + } + __finally { + ReleaseMutex (hSemCE->hMutex); + } + + return Result; } -DWORD WaitForSemaphoreCE (SYNCHHANDLE hSemCE, DWORD dwMilliseconds) +DWORD +WaitForSemaphoreCE (SYNCHHANDLE hSemCE, DWORD dwMilliseconds) /* Windows CE semaphore equivalent of WaitForSingleObject. */ { - DWORD WaitResult; - - WaitResult = WaitForSingleObject (hSemCE->hMutex, dwMilliseconds); - if (WaitResult != WAIT_OBJECT_0 && WaitResult != WAIT_ABANDONED_0) return WaitResult; - while (hSemCE->CurCount <= 0) - { - - /* The count is 0, and the thread must wait on the event (which, by - the rules, is currently reset) for semaphore resources to become - available. First, of course, the mutex must be released so that another - thread will be capable of setting the event. */ - - ReleaseMutex (hSemCE->hMutex); - - /* Wait for the event to be signaled, indicating a semaphore state change. - The event is autoreset and signaled with a SetEvent (not PulseEvent) - so exactly one waiting thread (whether or not there is currently - a waiting thread) is released as a result of the SetEvent. */ - - WaitResult = WaitForSingleObject (hSemCE->hEvent, dwMilliseconds); - if (WaitResult != WAIT_OBJECT_0) return WaitResult; - - /* This is where the properties of setting of an autoreset event is critical - to assure that, even if the semaphore state changes between the - preceding Wait and the next, and even if NO threads are waiting - on the event at the time of the SetEvent, at least one thread - will be released. - Pulsing a manual reset event would appear to work, but it would have - a defect which could appear if the semaphore state changed between - the two waits. */ - - WaitResult = WaitForSingleObject (hSemCE->hMutex, dwMilliseconds); - if (WaitResult != WAIT_OBJECT_0 && WaitResult != WAIT_ABANDONED_0) return WaitResult; - - } - /* The count is not zero and this thread owns the mutex. */ - - hSemCE->CurCount--; - /* The event is now unsignaled, BUT, the semaphore count may not be - zero, in which case the event should be signaled again - before releasing the mutex. */ - - if (hSemCE->CurCount > 0) SetEvent (hSemCE->hEvent); - ReleaseMutex (hSemCE->hMutex); - return WaitResult; + DWORD WaitResult; + + WaitResult = WaitForSingleObject (hSemCE->hMutex, dwMilliseconds); + if (WaitResult != WAIT_OBJECT_0 && WaitResult != WAIT_ABANDONED_0) + return WaitResult; + while (hSemCE->CurCount <= 0) { + + /* The count is 0, and the thread must wait on the event (which, by + the rules, is currently reset) for semaphore resources to become + available. First, of course, the mutex must be released so that another + thread will be capable of setting the event. */ + + ReleaseMutex (hSemCE->hMutex); + + /* Wait for the event to be signaled, indicating a semaphore state change. + The event is autoreset and signaled with a SetEvent (not PulseEvent) + so exactly one waiting thread (whether or not there is currently + a waiting thread) is released as a result of the SetEvent. */ + + WaitResult = WaitForSingleObject (hSemCE->hEvent, dwMilliseconds); + if (WaitResult != WAIT_OBJECT_0) + return WaitResult; + + /* This is where the properties of setting of an autoreset event is critical + to assure that, even if the semaphore state changes between the + preceding Wait and the next, and even if NO threads are waiting + on the event at the time of the SetEvent, at least one thread + will be released. + Pulsing a manual reset event would appear to work, but it would have + a defect which could appear if the semaphore state changed between + the two waits. */ + + WaitResult = WaitForSingleObject (hSemCE->hMutex, dwMilliseconds); + if (WaitResult != WAIT_OBJECT_0 && WaitResult != WAIT_ABANDONED_0) + return WaitResult; + + } + /* The count is not zero and this thread owns the mutex. */ + + hSemCE->CurCount--; + /* The event is now unsignaled, BUT, the semaphore count may not be + zero, in which case the event should be signaled again + before releasing the mutex. */ + + if (hSemCE->CurCount > 0) + SetEvent (hSemCE->hEvent); + ReleaseMutex (hSemCE->hMutex); + return WaitResult; } -BOOL CloseSynchHandle (SYNCHHANDLE hSynch) +BOOL +CloseSynchHandle (SYNCHHANDLE hSynch) /* Close a synchronization handle. Improvement: Test for a valid handle before dereferencing the handle. */ { - BOOL Result = TRUE; - if (hSynch->hEvent != NULL) Result = Result && CloseHandle (hSynch->hEvent); - if (hSynch->hMutex != NULL) Result = Result && CloseHandle (hSynch->hMutex); - if (hSynch->hSemph != NULL) Result = Result && CloseHandle (hSynch->hSemph); - HeapFree (GetProcessHeap (), 0, hSynch); - return (Result); + BOOL Result = TRUE; + if (hSynch->hEvent != NULL) + Result = Result && CloseHandle (hSynch->hEvent); + if (hSynch->hMutex != NULL) + Result = Result && CloseHandle (hSynch->hMutex); + if (hSynch->hSemph != NULL) + Result = Result && CloseHandle (hSynch->hSemph); + HeapFree (GetProcessHeap (), 0, hSynch); + return (Result); } -static SYNCHHANDLE CleanUp (SYNCHHANDLE hSynch, DWORD Flags) -{ /* Prepare to return from a create of a synchronization handle. - If there was any failure, free any allocated resources. - "Flags" indicates which Win32 objects are required in the - synchronization handle. */ - - BOOL ok = TRUE; - - if (hSynch == NULL) return NULL; - if ((Flags & 4) == 1 && (hSynch->hEvent == NULL)) ok = FALSE; - if ((Flags & 2) == 1 && (hSynch->hMutex == NULL)) ok = FALSE; - if ((Flags & 1) == 1 && (hSynch->hEvent == NULL)) ok = FALSE; - if (!ok) - { - CloseSynchHandle (hSynch); - return NULL; - } - /* Everything worked */ - return hSynch; +static SYNCHHANDLE +CleanUp (SYNCHHANDLE hSynch, DWORD Flags) +{ /* Prepare to return from a create of a synchronization handle. + If there was any failure, free any allocated resources. + "Flags" indicates which Win32 objects are required in the + synchronization handle. */ + + BOOL ok = TRUE; + + if (hSynch == NULL) + return NULL; + if ((Flags & 4) == 1 && (hSynch->hEvent == NULL)) + ok = FALSE; + if ((Flags & 2) == 1 && (hSynch->hMutex == NULL)) + ok = FALSE; + if ((Flags & 1) == 1 && (hSynch->hEvent == NULL)) + ok = FALSE; + if (!ok) { + CloseSynchHandle (hSynch); + return NULL; + } + /* Everything worked */ + return hSynch; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/win32/win_ce_semaphore.h b/src/thread/win32/win_ce_semaphore.h index af2d7b613..d2bc104cf 100644 --- a/src/thread/win32/win_ce_semaphore.h +++ b/src/thread/win32/win_ce_semaphore.h @@ -1,22 +1,25 @@ /* win_ce_semaphore.h - header file to go with win_ce_semaphore.c */ -typedef struct _SYNCH_HANDLE_STRUCTURE { - HANDLE hEvent; - HANDLE hMutex; - HANDLE hSemph; - LONG MaxCount; - volatile LONG CurCount; - LPCTSTR lpName; +typedef struct _SYNCH_HANDLE_STRUCTURE +{ + HANDLE hEvent; + HANDLE hMutex; + HANDLE hSemph; + LONG MaxCount; + volatile LONG CurCount; + LPCTSTR lpName; } SYNCH_HANDLE_STRUCTURE, *SYNCHHANDLE; #define SYNCH_HANDLE_SIZE sizeof (SYNCH_HANDLE_STRUCTURE) /* Error codes - all must have bit 29 set */ -#define SYNCH_ERROR 0X20000000 /* EXERCISE - REFINE THE ERROR NUMBERS */ +#define SYNCH_ERROR 0X20000000 /* EXERCISE - REFINE THE ERROR NUMBERS */ -extern SYNCHHANDLE CreateSemaphoreCE (LPSECURITY_ATTRIBUTES, LONG, LONG, LPCTSTR); +extern SYNCHHANDLE CreateSemaphoreCE (LPSECURITY_ATTRIBUTES, LONG, LONG, + LPCTSTR); extern BOOL ReleaseSemaphoreCE (SYNCHHANDLE, LONG, LPLONG); extern DWORD WaitForSemaphoreCE (SYNCHHANDLE, DWORD); extern BOOL CloseSynchHandle (SYNCHHANDLE); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/SDL_systimer.h b/src/timer/SDL_systimer.h index e9c7b3b30..b39beae8c 100644 --- a/src/timer/SDL_systimer.h +++ b/src/timer/SDL_systimer.h @@ -28,13 +28,14 @@ /* Initialize the system dependent timer subsystem */ -extern int SDL_SYS_TimerInit(void); +extern int SDL_SYS_TimerInit (void); /* Quit the system dependent timer subsystem */ -extern void SDL_SYS_TimerQuit(void); +extern void SDL_SYS_TimerQuit (void); /* Start a timer set up by SDL_SetTimer() */ -extern int SDL_SYS_StartTimer(void); +extern int SDL_SYS_StartTimer (void); /* Stop a previously started timer */ -extern void SDL_SYS_StopTimer(void); +extern void SDL_SYS_StopTimer (void); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 2c98431ac..fa66c909d 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -38,12 +38,13 @@ SDL_TimerCallback SDL_alarm_callback; /* Data used for a thread-based timer */ static int SDL_timer_threaded = 0; -struct _SDL_TimerID { - Uint32 interval; - SDL_NewTimerCallback cb; - void *param; - Uint32 last_alarm; - struct _SDL_TimerID *next; +struct _SDL_TimerID +{ + Uint32 interval; + SDL_NewTimerCallback cb; + void *param; + Uint32 last_alarm; + struct _SDL_TimerID *next; }; static SDL_TimerID SDL_timers = NULL; @@ -53,233 +54,247 @@ static volatile SDL_bool list_changed = SDL_FALSE; /* Set whether or not the timer should use a thread. This should not be called while the timer subsystem is running. */ -int SDL_SetTimerThreaded(int value) +int +SDL_SetTimerThreaded (int value) { - int retval; + int retval; - if ( SDL_timer_started ) { - SDL_SetError("Timer already initialized"); - retval = -1; - } else { - retval = 0; - SDL_timer_threaded = value; - } - return retval; + if (SDL_timer_started) { + SDL_SetError ("Timer already initialized"); + retval = -1; + } else { + retval = 0; + SDL_timer_threaded = value; + } + return retval; } -int SDL_TimerInit(void) +int +SDL_TimerInit (void) { - int retval; + int retval; - retval = 0; - if ( SDL_timer_started ) { - SDL_TimerQuit(); - } - if ( ! SDL_timer_threaded ) { - retval = SDL_SYS_TimerInit(); - } - if ( SDL_timer_threaded ) { - SDL_timer_mutex = SDL_CreateMutex(); - } - if ( retval == 0 ) { - SDL_timer_started = 1; - } - return(retval); + retval = 0; + if (SDL_timer_started) { + SDL_TimerQuit (); + } + if (!SDL_timer_threaded) { + retval = SDL_SYS_TimerInit (); + } + if (SDL_timer_threaded) { + SDL_timer_mutex = SDL_CreateMutex (); + } + if (retval == 0) { + SDL_timer_started = 1; + } + return (retval); } -void SDL_TimerQuit(void) +void +SDL_TimerQuit (void) { - SDL_SetTimer(0, NULL); - if ( SDL_timer_threaded < 2 ) { - SDL_SYS_TimerQuit(); - } - if ( SDL_timer_threaded ) { - SDL_DestroyMutex(SDL_timer_mutex); - SDL_timer_mutex = NULL; - } - SDL_timer_started = 0; - SDL_timer_threaded = 0; + SDL_SetTimer (0, NULL); + if (SDL_timer_threaded < 2) { + SDL_SYS_TimerQuit (); + } + if (SDL_timer_threaded) { + SDL_DestroyMutex (SDL_timer_mutex); + SDL_timer_mutex = NULL; + } + SDL_timer_started = 0; + SDL_timer_threaded = 0; } -void SDL_ThreadedTimerCheck(void) +void +SDL_ThreadedTimerCheck (void) { - Uint32 now, ms; - SDL_TimerID t, prev, next; - SDL_bool removed; + Uint32 now, ms; + SDL_TimerID t, prev, next; + SDL_bool removed; - SDL_mutexP(SDL_timer_mutex); - list_changed = SDL_FALSE; - now = SDL_GetTicks(); - for ( prev = NULL, t = SDL_timers; t; t = next ) { - removed = SDL_FALSE; - ms = t->interval - SDL_TIMESLICE; - next = t->next; - if ( (int)(now - t->last_alarm) > (int)ms ) { - struct _SDL_TimerID timer; + SDL_mutexP (SDL_timer_mutex); + list_changed = SDL_FALSE; + now = SDL_GetTicks (); + for (prev = NULL, t = SDL_timers; t; t = next) { + removed = SDL_FALSE; + ms = t->interval - SDL_TIMESLICE; + next = t->next; + if ((int) (now - t->last_alarm) > (int) ms) { + struct _SDL_TimerID timer; - if ( (now - t->last_alarm) < t->interval ) { - t->last_alarm += t->interval; - } else { - t->last_alarm = now; - } + if ((now - t->last_alarm) < t->interval) { + t->last_alarm += t->interval; + } else { + t->last_alarm = now; + } #ifdef DEBUG_TIMERS - printf("Executing timer %p (thread = %d)\n", - t, SDL_ThreadID()); + printf ("Executing timer %p (thread = %d)\n", t, SDL_ThreadID ()); #endif - timer = *t; - SDL_mutexV(SDL_timer_mutex); - ms = timer.cb(timer.interval, timer.param); - SDL_mutexP(SDL_timer_mutex); - if ( list_changed ) { - /* Abort, list of timers modified */ - /* FIXME: what if ms was changed? */ - break; - } - if ( ms != t->interval ) { - if ( ms ) { - t->interval = ROUND_RESOLUTION(ms); - } else { - /* Remove timer from the list */ + timer = *t; + SDL_mutexV (SDL_timer_mutex); + ms = timer.cb (timer.interval, timer.param); + SDL_mutexP (SDL_timer_mutex); + if (list_changed) { + /* Abort, list of timers modified */ + /* FIXME: what if ms was changed? */ + break; + } + if (ms != t->interval) { + if (ms) { + t->interval = ROUND_RESOLUTION (ms); + } else { + /* Remove timer from the list */ #ifdef DEBUG_TIMERS - printf("SDL: Removing timer %p\n", t); + printf ("SDL: Removing timer %p\n", t); #endif - if ( prev ) { - prev->next = next; - } else { - SDL_timers = next; - } - SDL_free(t); - --SDL_timer_running; - removed = SDL_TRUE; - } - } - } - /* Don't update prev if the timer has disappeared */ - if ( ! removed ) { - prev = t; - } - } - SDL_mutexV(SDL_timer_mutex); + if (prev) { + prev->next = next; + } else { + SDL_timers = next; + } + SDL_free (t); + --SDL_timer_running; + removed = SDL_TRUE; + } + } + } + /* Don't update prev if the timer has disappeared */ + if (!removed) { + prev = t; + } + } + SDL_mutexV (SDL_timer_mutex); } -static SDL_TimerID SDL_AddTimerInternal(Uint32 interval, SDL_NewTimerCallback callback, void *param) +static SDL_TimerID +SDL_AddTimerInternal (Uint32 interval, SDL_NewTimerCallback callback, + void *param) { - SDL_TimerID t; - t = (SDL_TimerID) SDL_malloc(sizeof(struct _SDL_TimerID)); - if ( t ) { - t->interval = ROUND_RESOLUTION(interval); - t->cb = callback; - t->param = param; - t->last_alarm = SDL_GetTicks(); - t->next = SDL_timers; - SDL_timers = t; - ++SDL_timer_running; - list_changed = SDL_TRUE; - } + SDL_TimerID t; + t = (SDL_TimerID) SDL_malloc (sizeof (struct _SDL_TimerID)); + if (t) { + t->interval = ROUND_RESOLUTION (interval); + t->cb = callback; + t->param = param; + t->last_alarm = SDL_GetTicks (); + t->next = SDL_timers; + SDL_timers = t; + ++SDL_timer_running; + list_changed = SDL_TRUE; + } #ifdef DEBUG_TIMERS - printf("SDL_AddTimer(%d) = %08x num_timers = %d\n", interval, (Uint32)t, SDL_timer_running); + printf ("SDL_AddTimer(%d) = %08x num_timers = %d\n", interval, (Uint32) t, + SDL_timer_running); #endif - return t; + return t; } -SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param) +SDL_TimerID +SDL_AddTimer (Uint32 interval, SDL_NewTimerCallback callback, void *param) { - SDL_TimerID t; - if ( ! SDL_timer_mutex ) { - if ( SDL_timer_started ) { - SDL_SetError("This platform doesn't support multiple timers"); - } else { - SDL_SetError("You must call SDL_Init(SDL_INIT_TIMER) first"); - } - return NULL; - } - if ( ! SDL_timer_threaded ) { - SDL_SetError("Multiple timers require threaded events!"); - return NULL; - } - SDL_mutexP(SDL_timer_mutex); - t = SDL_AddTimerInternal(interval, callback, param); - SDL_mutexV(SDL_timer_mutex); - return t; + SDL_TimerID t; + if (!SDL_timer_mutex) { + if (SDL_timer_started) { + SDL_SetError ("This platform doesn't support multiple timers"); + } else { + SDL_SetError ("You must call SDL_Init(SDL_INIT_TIMER) first"); + } + return NULL; + } + if (!SDL_timer_threaded) { + SDL_SetError ("Multiple timers require threaded events!"); + return NULL; + } + SDL_mutexP (SDL_timer_mutex); + t = SDL_AddTimerInternal (interval, callback, param); + SDL_mutexV (SDL_timer_mutex); + return t; } -SDL_bool SDL_RemoveTimer(SDL_TimerID id) +SDL_bool +SDL_RemoveTimer (SDL_TimerID id) { - SDL_TimerID t, prev = NULL; - SDL_bool removed; + SDL_TimerID t, prev = NULL; + SDL_bool removed; - removed = SDL_FALSE; - SDL_mutexP(SDL_timer_mutex); - /* Look for id in the linked list of timers */ - for (t = SDL_timers; t; prev=t, t = t->next ) { - if ( t == id ) { - if(prev) { - prev->next = t->next; - } else { - SDL_timers = t->next; - } - SDL_free(t); - --SDL_timer_running; - removed = SDL_TRUE; - list_changed = SDL_TRUE; - break; - } - } + removed = SDL_FALSE; + SDL_mutexP (SDL_timer_mutex); + /* Look for id in the linked list of timers */ + for (t = SDL_timers; t; prev = t, t = t->next) { + if (t == id) { + if (prev) { + prev->next = t->next; + } else { + SDL_timers = t->next; + } + SDL_free (t); + --SDL_timer_running; + removed = SDL_TRUE; + list_changed = SDL_TRUE; + break; + } + } #ifdef DEBUG_TIMERS - printf("SDL_RemoveTimer(%08x) = %d num_timers = %d thread = %d\n", (Uint32)id, removed, SDL_timer_running, SDL_ThreadID()); + printf ("SDL_RemoveTimer(%08x) = %d num_timers = %d thread = %d\n", + (Uint32) id, removed, SDL_timer_running, SDL_ThreadID ()); #endif - SDL_mutexV(SDL_timer_mutex); - return removed; + SDL_mutexV (SDL_timer_mutex); + return removed; } /* Old style callback functions are wrapped through this */ -static Uint32 SDLCALL callback_wrapper(Uint32 ms, void *param) +static Uint32 SDLCALL +callback_wrapper (Uint32 ms, void *param) { - SDL_TimerCallback func = (SDL_TimerCallback) param; - return (*func)(ms); + SDL_TimerCallback func = (SDL_TimerCallback) param; + return (*func) (ms); } -int SDL_SetTimer(Uint32 ms, SDL_TimerCallback callback) +int +SDL_SetTimer (Uint32 ms, SDL_TimerCallback callback) { - int retval; + int retval; #ifdef DEBUG_TIMERS - printf("SDL_SetTimer(%d)\n", ms); + printf ("SDL_SetTimer(%d)\n", ms); #endif - retval = 0; + retval = 0; - if ( SDL_timer_threaded ) { - SDL_mutexP(SDL_timer_mutex); - } - if ( SDL_timer_running ) { /* Stop any currently running timer */ - if ( SDL_timer_threaded ) { - while ( SDL_timers ) { - SDL_TimerID freeme = SDL_timers; - SDL_timers = SDL_timers->next; - SDL_free(freeme); - } - SDL_timer_running = 0; - list_changed = SDL_TRUE; - } else { - SDL_SYS_StopTimer(); - SDL_timer_running = 0; - } - } - if ( ms ) { - if ( SDL_timer_threaded ) { - if ( SDL_AddTimerInternal(ms, callback_wrapper, (void *)callback) == NULL ) { - retval = -1; - } - } else { - SDL_timer_running = 1; - SDL_alarm_interval = ms; - SDL_alarm_callback = callback; - retval = SDL_SYS_StartTimer(); - } - } - if ( SDL_timer_threaded ) { - SDL_mutexV(SDL_timer_mutex); - } + if (SDL_timer_threaded) { + SDL_mutexP (SDL_timer_mutex); + } + if (SDL_timer_running) { /* Stop any currently running timer */ + if (SDL_timer_threaded) { + while (SDL_timers) { + SDL_TimerID freeme = SDL_timers; + SDL_timers = SDL_timers->next; + SDL_free (freeme); + } + SDL_timer_running = 0; + list_changed = SDL_TRUE; + } else { + SDL_SYS_StopTimer (); + SDL_timer_running = 0; + } + } + if (ms) { + if (SDL_timer_threaded) { + if (SDL_AddTimerInternal + (ms, callback_wrapper, (void *) callback) == NULL) { + retval = -1; + } + } else { + SDL_timer_running = 1; + SDL_alarm_interval = ms; + SDL_alarm_callback = callback; + retval = SDL_SYS_StartTimer (); + } + } + if (SDL_timer_threaded) { + SDL_mutexV (SDL_timer_mutex); + } - return retval; + return retval; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/SDL_timer_c.h b/src/timer/SDL_timer_c.h index a69cd12ac..7fe8ab775 100644 --- a/src/timer/SDL_timer_c.h +++ b/src/timer/SDL_timer_c.h @@ -37,10 +37,11 @@ extern SDL_TimerCallback SDL_alarm_callback; /* Set whether or not the timer should use a thread. This should be called while the timer subsystem is running. */ -extern int SDL_SetTimerThreaded(int value); +extern int SDL_SetTimerThreaded (int value); -extern int SDL_TimerInit(void); -extern void SDL_TimerQuit(void); +extern int SDL_TimerInit (void); +extern void SDL_TimerQuit (void); /* This function is called from the SDL event thread if it is available */ -extern void SDL_ThreadedTimerCheck(void); +extern void SDL_ThreadedTimerCheck (void); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/amigaos/SDL_systimer.c b/src/timer/amigaos/SDL_systimer.c index a213b6142..29565fbcc 100644 --- a/src/timer/amigaos/SDL_systimer.c +++ b/src/timer/amigaos/SDL_systimer.c @@ -59,145 +59,142 @@ static struct GfxBase *GfxBase; #if !defined(__PPC__) || defined(STORMC4_WOS) || defined(MORPHOS) static clock_t start; -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - /* Set first ticks value */ - start=clock(); + /* Set first ticks value */ + start = clock (); } -Uint32 SDL_GetTicks (void) +Uint32 +SDL_GetTicks (void) { - clock_t ticks; + clock_t ticks; - ticks=clock()-start; + ticks = clock () - start; #ifdef __SASC // CLOCKS_PER_SEC == 1000 ! - return(ticks); + return (ticks); #else // CLOCKS_PER_SEC != 1000 ! - return ticks*(1000/CLOCKS_PER_SEC); + return ticks * (1000 / CLOCKS_PER_SEC); #endif } -void SDL_Delay (Uint32 ms) +void +SDL_Delay (Uint32 ms) { // Do a busy wait if time is less than 50ms - if(ms<50) - { - clock_t to_wait=clock(); + if (ms < 50) { + clock_t to_wait = clock (); #ifndef __SASC - ms*=(CLOCKS_PER_SEC/1000); + ms *= (CLOCKS_PER_SEC / 1000); #endif - to_wait+=ms; - - while(clock()>=10; - start[1]|=((result[0]&0x3ff)<<22); - start[0]>>=10; + /* Set first ticks value */ + if (!MyTimer) + PPC_TimerInit (); + + PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, start); + start[1] >>= 10; + start[1] |= ((result[0] & 0x3ff) << 22); + start[0] >>= 10; } -Uint32 SDL_GetTicks (void) +Uint32 +SDL_GetTicks (void) { - ULONG result[2]; - PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,result); + ULONG result[2]; + PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, result); -// PPCAsr64p(result,10); +// PPCAsr64p(result,10); // Non va, la emulo: - result[1]>>=10; - result[1]|=((result[0]&0x3ff)<<22); + result[1] >>= 10; + result[1] |= ((result[0] & 0x3ff) << 22); // Non mi interessa piu' result[0] - return result[1]*1000/MY_CLOCKS_PER_SEC; + return result[1] * 1000 / MY_CLOCKS_PER_SEC; } -void SDL_Delay (Uint32 ms) +void +SDL_Delay (Uint32 ms) { // Do a busy wait if time is less than 50ms - if(ms<50) - { - ULONG to_wait[2],actual[2]; - PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,result); - actual[1]=0; - to_wait[1]+=ms*1000/MY_CLOCKS_PER_SEC; - - while(actual[1]>=10; - result[1]|=((result[0]&0x3ff)<<22); - result[0]>>=10; - - D(bug("Shiftato TPS: %lu - %lu\n",result[0],result[1])); - MY_CLOCKS_PER_SEC=result[1]; - - PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,result); - - D(bug("Current ticks: %lu - %lu\n",result[0],result[1])); - result[1]>>=10; - result[1]|=((result[0]&0x3ff)<<22); - result[0]>>=10; -// PPCAsr64p(result,10); - D(bug("Shiftato: %lu - %lu\n",result[0],result[1])); - } - else - { - D(bug("Errore nell'inizializzazione del timer!\n")); - } + struct TagItem tags[] = { + PPCTIMERTAG_CPU, TRUE, + TAG_DONE, 0 + }; + + + if (MyTimer = PPCCreateTimerObject (tags)) { + ULONG result[2]; + + PPCGetTimerObject (MyTimer, PPCTIMERTAG_TICKSPERSEC, result); + D (bug + ("Timer inizializzato, TPS: %lu - %lu\n", result[0], result[1])); +// PPCAsr64p(result,10); + result[1] >>= 10; + result[1] |= ((result[0] & 0x3ff) << 22); + result[0] >>= 10; + + D (bug ("Shiftato TPS: %lu - %lu\n", result[0], result[1])); + MY_CLOCKS_PER_SEC = result[1]; + + PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, result); + + D (bug ("Current ticks: %lu - %lu\n", result[0], result[1])); + result[1] >>= 10; + result[1] |= ((result[0] & 0x3ff) << 22); + result[0] >>= 10; +// PPCAsr64p(result,10); + D (bug ("Shiftato: %lu - %lu\n", result[0], result[1])); + } else { + D (bug ("Errore nell'inizializzazione del timer!\n")); + } } #endif @@ -208,60 +205,65 @@ void PPC_TimerInit(void) static int timer_alive = 0; static SDL_Thread *timer_thread = NULL; -static int RunTimer(void *unused) +static int +RunTimer (void *unused) { - D(bug("SYSTimer: Entering RunTimer loop...")); - - if(GfxBase==NULL) - GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37); - - while ( timer_alive ) { - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - if(GfxBase) - WaitTOF(); // Check the timer every fifth of seconds. Was SDL_Delay(1)->BusyWait! - else - Delay(1); - } - D(bug("SYSTimer: EXITING RunTimer loop...")); - return(0); + D (bug ("SYSTimer: Entering RunTimer loop...")); + + if (GfxBase == NULL) + GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 37); + + while (timer_alive) { + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); + } + if (GfxBase) + WaitTOF (); // Check the timer every fifth of seconds. Was SDL_Delay(1)->BusyWait! + else + Delay (1); + } + D (bug ("SYSTimer: EXITING RunTimer loop...")); + return (0); } /* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - D(bug("Creating thread for the timer (NOITIMER)...\n")); + D (bug ("Creating thread for the timer (NOITIMER)...\n")); - timer_alive = 1; - timer_thread = SDL_CreateThread(RunTimer, NULL); - if ( timer_thread == NULL ) - { - D(bug("Creazione del thread fallita...\n")); + timer_alive = 1; + timer_thread = SDL_CreateThread (RunTimer, NULL); + if (timer_thread == NULL) { + D (bug ("Creazione del thread fallita...\n")); - return(-1); - } - return(SDL_SetTimerThreaded(1)); + return (-1); + } + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - timer_alive = 0; - if ( timer_thread ) { - SDL_WaitThread(timer_thread, NULL); - timer_thread = NULL; - } + timer_alive = 0; + if (timer_thread) { + SDL_WaitThread (timer_thread, NULL); + timer_thread = NULL; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: AmigaOS uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: AmigaOS uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_TIMER_AMIGA */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/beos/SDL_systimer.c b/src/timer/beos/SDL_systimer.c index 74ff7f6a4..ff791b618 100644 --- a/src/timer/beos/SDL_systimer.c +++ b/src/timer/beos/SDL_systimer.c @@ -31,65 +31,74 @@ static bigtime_t start; -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - /* Set first ticks value */ - start = system_time(); + /* Set first ticks value */ + start = system_time (); } -Uint32 SDL_GetTicks(void) +Uint32 +SDL_GetTicks (void) { - return((system_time()-start)/1000); + return ((system_time () - start) / 1000); } -void SDL_Delay(Uint32 ms) +void +SDL_Delay (Uint32 ms) { - snooze(ms*1000); + snooze (ms * 1000); } /* Data to handle a single periodic alarm */ static int timer_alive = 0; static SDL_Thread *timer = NULL; -static int RunTimer(void *unused) +static int +RunTimer (void *unused) { - while ( timer_alive ) { - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(10); - } - return(0); + while (timer_alive) { + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); + } + SDL_Delay (10); + } + return (0); } /* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if ( timer == NULL ) - return(-1); - return(SDL_SetTimerThreaded(1)); + timer_alive = 1; + timer = SDL_CreateThread (RunTimer, NULL); + if (timer == NULL) + return (-1); + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - timer_alive = 0; - if ( timer ) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } + timer_alive = 0; + if (timer) { + SDL_WaitThread (timer, NULL); + timer = NULL; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: BeOS uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: BeOS uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_TIMER_BEOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/dc/SDL_systimer.c b/src/timer/dc/SDL_systimer.c index d04a6545d..977fd5027 100644 --- a/src/timer/dc/SDL_systimer.c +++ b/src/timer/dc/SDL_systimer.c @@ -36,65 +36,74 @@ static unsigned start; ms = jif * 1000/HZ */ -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - /* Set first ticks value */ - start = jiffies; + /* Set first ticks value */ + start = jiffies; } -Uint32 SDL_GetTicks(void) +Uint32 +SDL_GetTicks (void) { - return((jiffies-start)*1000/HZ); + return ((jiffies - start) * 1000 / HZ); } -void SDL_Delay(Uint32 ms) +void +SDL_Delay (Uint32 ms) { - thd_sleep(ms); + thd_sleep (ms); } /* Data to handle a single periodic alarm */ static int timer_alive = 0; static SDL_Thread *timer = NULL; -static int RunTimer(void *unused) +static int +RunTimer (void *unused) { - while ( timer_alive ) { - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(10); - } - return(0); + while (timer_alive) { + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); + } + SDL_Delay (10); + } + return (0); } /* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if ( timer == NULL ) - return(-1); - return(SDL_SetTimerThreaded(1)); + timer_alive = 1; + timer = SDL_CreateThread (RunTimer, NULL); + if (timer == NULL) + return (-1); + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - timer_alive = 0; - if ( timer ) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } + timer_alive = 0; + if (timer) { + SDL_WaitThread (timer, NULL); + timer = NULL; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: DC uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: DC uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_TIMER_DC */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/dummy/SDL_systimer.c b/src/timer/dummy/SDL_systimer.c index f4dae0357..aebcfb814 100644 --- a/src/timer/dummy/SDL_systimer.c +++ b/src/timer/dummy/SDL_systimer.c @@ -26,19 +26,22 @@ #include "SDL_timer.h" #include "../SDL_timer_c.h" -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { } -Uint32 SDL_GetTicks (void) +Uint32 +SDL_GetTicks (void) { - SDL_Unsupported(); - return 0; + SDL_Unsupported (); + return 0; } -void SDL_Delay (Uint32 ms) +void +SDL_Delay (Uint32 ms) { - SDL_Unsupported(); + SDL_Unsupported (); } #include "SDL_thread.h" @@ -47,45 +50,51 @@ void SDL_Delay (Uint32 ms) static int timer_alive = 0; static SDL_Thread *timer = NULL; -static int RunTimer(void *unused) +static int +RunTimer (void *unused) { - while ( timer_alive ) { - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(1); - } - return(0); + while (timer_alive) { + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); + } + SDL_Delay (1); + } + return (0); } /* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if ( timer == NULL ) - return(-1); - return(SDL_SetTimerThreaded(1)); + timer_alive = 1; + timer = SDL_CreateThread (RunTimer, NULL); + if (timer == NULL) + return (-1); + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - timer_alive = 0; - if ( timer ) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } + timer_alive = 0; + if (timer) { + SDL_WaitThread (timer, NULL); + timer = NULL; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: threaded timer in use"); - return(-1); + SDL_SetError ("Internal logic error: threaded timer in use"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/macos/FastTimes.c b/src/timer/macos/FastTimes.c index 8eb4260fb..9aed0e95c 100644 --- a/src/timer/macos/FastTimes.c +++ b/src/timer/macos/FastTimes.c @@ -20,7 +20,7 @@ #include "FastTimes.h" #ifdef TARGET_CPU_PPC -#undef GENERATINGPOWERPC /* stop whining */ +#undef GENERATINGPOWERPC /* stop whining */ #define GENERATINGPOWERPC TARGET_CPU_PPC #endif @@ -78,275 +78,271 @@ #if GENERATINGPOWERPC -static asm UnsignedWide PollRTC(void); -static asm UnsignedWide PollTBR(void); -static Ptr FindFunctionInSharedLib(StringPtr libName, StringPtr funcName); +static asm UnsignedWide PollRTC (void); +static asm UnsignedWide PollTBR (void); +static Ptr FindFunctionInSharedLib (StringPtr libName, StringPtr funcName); -static Boolean gInited = false; -static Boolean gNative = false; -static Boolean gUseRTC = false; -static Boolean gUseTBR = false; -static double gScaleUSec = 1.0 / 1000.0; /* 1 / ( nsec / usec) */ -static double gScaleMSec = 1.0 / 1000000.0; /* 1 / ( nsec / msec) */ +static Boolean gInited = false; +static Boolean gNative = false; +static Boolean gUseRTC = false; +static Boolean gUseTBR = false; +static double gScaleUSec = 1.0 / 1000.0; /* 1 / ( nsec / usec) */ +static double gScaleMSec = 1.0 / 1000000.0; /* 1 / ( nsec / msec) */ /* Functions loaded from DriverServicesLib */ -typedef AbsoluteTime (*UpTimeProcPtr)(void); -typedef Nanoseconds (*A2NSProcPtr)(AbsoluteTime); -static UpTimeProcPtr gUpTime = NULL; -static A2NSProcPtr gA2NS = NULL; +typedef AbsoluteTime (*UpTimeProcPtr) (void); +typedef Nanoseconds (*A2NSProcPtr) (AbsoluteTime); +static UpTimeProcPtr gUpTime = NULL; +static A2NSProcPtr gA2NS = NULL; #endif /* GENERATINGPOWERPC */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ -void FastInitialize() { - SInt32 result; +void +FastInitialize () +{ + SInt32 result; - if (!gInited) { + if (!gInited) { #if GENERATINGPOWERPC - /* Initialize the feature flags */ - gNative = gUseRTC = gUseTBR = false; - - /* We use CFM to find and load needed symbols from shared libraries, so - the application doesn't have to weak-link them, for convenience. */ - gUpTime = (UpTimeProcPtr) FindFunctionInSharedLib( - "\pDriverServicesLib", "\pUpTime"); - if (gUpTime) gA2NS = (A2NSProcPtr) FindFunctionInSharedLib( - "\pDriverServicesLib", "\pAbsoluteToNanoseconds"); - if (!gA2NS) gUpTime = nil; /* Pedantic but necessary */ - - if (gUpTime) { - /* If we loaded UpTime(), then we need to know if the system has - a native implementation of the Time Manager. If so, then it's - pointless to calculate a scale factor against the missing VIA */ - - /* gestaltNativeTimeMgr = 4 in some future version of the headers */ - if (!Gestalt(gestaltTimeMgrVersion, &result) && - (result > gestaltExtendedTimeMgr)) - gNative = true; - } - else { - /* If no DriverServicesLib, use Gestalt() to get the processor type. - Only NuBus PowerMacs with old System Software won't have DSL, so - we know it should either be a 601 or 603. */ - - /* Use the processor gestalt to determine which register to use */ - if (!Gestalt(gestaltNativeCPUtype, &result)) { - if (result == gestaltCPU601) gUseRTC = true; - else if (result > gestaltCPU601) gUseTBR = true; - } - } - - /* Now calculate a scale factor to keep us accurate. */ - if ((gUpTime && !gNative) || gUseRTC || gUseTBR) { - UInt64 tick, usec1, usec2; - UnsignedWide wide; - - /* Wait for the beginning of the very next tick */ - for(tick = MyLMGetTicks() + 1; tick > MyLMGetTicks(); ); - - /* Poll the selected timer and prepare it (since we have time) */ - wide = (gUpTime) ? (*gA2NS)((*gUpTime)()) : - ((gUseRTC) ? PollRTC() : PollTBR()); - usec1 = (gUseRTC) ? RTCToNano(wide) : WideTo64bit(wide); - - /* Wait for the exact 60th tick to roll over */ - while(tick + 60 > MyLMGetTicks()); - - /* Poll the selected timer again and prepare it */ - wide = (gUpTime) ? (*gA2NS)((*gUpTime)()) : - ((gUseRTC) ? PollRTC() : PollTBR()); - usec2 = (gUseRTC) ? RTCToNano(wide) : WideTo64bit(wide); - - /* Calculate a scale value that will give microseconds per second. - Remember, there are actually 60.15 ticks in a second, not 60. */ - gScaleUSec = (60.0 * 1000000.0) / ((usec2 - usec1) * 60.15); - gScaleMSec = gScaleUSec / 1000.0; - } - + /* Initialize the feature flags */ + gNative = gUseRTC = gUseTBR = false; + + /* We use CFM to find and load needed symbols from shared libraries, so + the application doesn't have to weak-link them, for convenience. */ + gUpTime = + (UpTimeProcPtr) FindFunctionInSharedLib ("\pDriverServicesLib", + "\pUpTime"); + if (gUpTime) + gA2NS = (A2NSProcPtr) + FindFunctionInSharedLib ("\pDriverServicesLib", + "\pAbsoluteToNanoseconds"); + if (!gA2NS) + gUpTime = nil; /* Pedantic but necessary */ + + if (gUpTime) { + /* If we loaded UpTime(), then we need to know if the system has + a native implementation of the Time Manager. If so, then it's + pointless to calculate a scale factor against the missing VIA */ + + /* gestaltNativeTimeMgr = 4 in some future version of the headers */ + if (!Gestalt (gestaltTimeMgrVersion, &result) && + (result > gestaltExtendedTimeMgr)) + gNative = true; + } else { + /* If no DriverServicesLib, use Gestalt() to get the processor type. + Only NuBus PowerMacs with old System Software won't have DSL, so + we know it should either be a 601 or 603. */ + + /* Use the processor gestalt to determine which register to use */ + if (!Gestalt (gestaltNativeCPUtype, &result)) { + if (result == gestaltCPU601) + gUseRTC = true; + else if (result > gestaltCPU601) + gUseTBR = true; + } + } + + /* Now calculate a scale factor to keep us accurate. */ + if ((gUpTime && !gNative) || gUseRTC || gUseTBR) { + UInt64 tick, usec1, usec2; + UnsignedWide wide; + + /* Wait for the beginning of the very next tick */ + for (tick = MyLMGetTicks () + 1; tick > MyLMGetTicks ();); + + /* Poll the selected timer and prepare it (since we have time) */ + wide = (gUpTime) ? (*gA2NS) ((*gUpTime) ()) : + ((gUseRTC) ? PollRTC () : PollTBR ()); + usec1 = (gUseRTC) ? RTCToNano (wide) : WideTo64bit (wide); + + /* Wait for the exact 60th tick to roll over */ + while (tick + 60 > MyLMGetTicks ()); + + /* Poll the selected timer again and prepare it */ + wide = (gUpTime) ? (*gA2NS) ((*gUpTime) ()) : + ((gUseRTC) ? PollRTC () : PollTBR ()); + usec2 = (gUseRTC) ? RTCToNano (wide) : WideTo64bit (wide); + + /* Calculate a scale value that will give microseconds per second. + Remember, there are actually 60.15 ticks in a second, not 60. */ + gScaleUSec = (60.0 * 1000000.0) / ((usec2 - usec1) * 60.15); + gScaleMSec = gScaleUSec / 1000.0; + } #endif /* GENERATINGPOWERPC */ - /* We've initialized our globals */ - gInited = true; - } - } + /* We've initialized our globals */ + gInited = true; + } +} /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ -UInt64 FastMicroseconds() { - UnsignedWide wide; - UInt64 usec; - +UInt64 +FastMicroseconds () +{ + UnsignedWide wide; + UInt64 usec; + #if GENERATINGPOWERPC - /* Initialize globals the first time we are called */ - if (!gInited) FastInitialize(); - - if (gNative) { - /* Use DriverServices if it's available -- it's fast and compatible */ - wide = (*gA2NS)((*gUpTime)()); - usec = (double) WideTo64bit(wide) * gScaleUSec + 0.5; - } - else if (gUpTime) { - /* Use DriverServices if it's available -- it's fast and compatible */ - wide = (*gA2NS)((*gUpTime)()); - usec = (double) WideTo64bit(wide) * gScaleUSec + 0.5; - } - else if (gUseTBR) { - /* On a recent PowerPC, we poll the TBR directly */ - wide = PollTBR(); - usec = (double) WideTo64bit(wide) * gScaleUSec + 0.5; - } - else if (gUseRTC) { - /* On a 601, we can poll the RTC instead */ - wide = PollRTC(); - usec = (double) RTCToNano(wide) * gScaleUSec + 0.5; - } - else + /* Initialize globals the first time we are called */ + if (!gInited) + FastInitialize (); + + if (gNative) { + /* Use DriverServices if it's available -- it's fast and compatible */ + wide = (*gA2NS) ((*gUpTime) ()); + usec = (double) WideTo64bit (wide) * gScaleUSec + 0.5; + } else if (gUpTime) { + /* Use DriverServices if it's available -- it's fast and compatible */ + wide = (*gA2NS) ((*gUpTime) ()); + usec = (double) WideTo64bit (wide) * gScaleUSec + 0.5; + } else if (gUseTBR) { + /* On a recent PowerPC, we poll the TBR directly */ + wide = PollTBR (); + usec = (double) WideTo64bit (wide) * gScaleUSec + 0.5; + } else if (gUseRTC) { + /* On a 601, we can poll the RTC instead */ + wide = PollRTC (); + usec = (double) RTCToNano (wide) * gScaleUSec + 0.5; + } else #endif /* GENERATINGPOWERPC */ - { - /* If all else fails, suffer the mixed mode overhead */ - Microseconds(&wide); - usec = WideTo64bit(wide); - } + { + /* If all else fails, suffer the mixed mode overhead */ + Microseconds (&wide); + usec = WideTo64bit (wide); + } - return(usec); - } + return (usec); +} /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ -UInt64 FastMilliseconds() { - UnsignedWide wide; - UInt64 msec; - +UInt64 +FastMilliseconds () +{ + UnsignedWide wide; + UInt64 msec; + #if GENERATINGPOWERPC - /* Initialize globals the first time we are called */ - if (!gInited) FastInitialize(); - - if (gNative) { - /* Use DriverServices if it's available -- it's fast and compatible */ - wide = (*gA2NS)((*gUpTime)()); - msec = (double) WideTo64bit(wide) * gScaleMSec + 0.5; - } - else if (gUpTime) { - /* Use DriverServices if it's available -- it's fast and compatible */ - wide = (*gA2NS)((*gUpTime)()); - msec = (double) WideTo64bit(wide) * gScaleMSec + 0.5; - } - else if (gUseTBR) { - /* On a recent PowerPC, we poll the TBR directly */ - wide = PollTBR(); - msec = (double) WideTo64bit(wide) * gScaleMSec + 0.5; - } - else if (gUseRTC) { - /* On a 601, we can poll the RTC instead */ - wide = PollRTC(); - msec = (double) RTCToNano(wide) * gScaleMSec + 0.5; - } - else + /* Initialize globals the first time we are called */ + if (!gInited) + FastInitialize (); + + if (gNative) { + /* Use DriverServices if it's available -- it's fast and compatible */ + wide = (*gA2NS) ((*gUpTime) ()); + msec = (double) WideTo64bit (wide) * gScaleMSec + 0.5; + } else if (gUpTime) { + /* Use DriverServices if it's available -- it's fast and compatible */ + wide = (*gA2NS) ((*gUpTime) ()); + msec = (double) WideTo64bit (wide) * gScaleMSec + 0.5; + } else if (gUseTBR) { + /* On a recent PowerPC, we poll the TBR directly */ + wide = PollTBR (); + msec = (double) WideTo64bit (wide) * gScaleMSec + 0.5; + } else if (gUseRTC) { + /* On a 601, we can poll the RTC instead */ + wide = PollRTC (); + msec = (double) RTCToNano (wide) * gScaleMSec + 0.5; + } else #endif /* GENERATINGPOWERPC */ - { - /* If all else fails, suffer the mixed mode overhead */ - Microseconds(&wide); - msec = ((double) WideTo64bit(wide) + 500.0) / 1000.0; - } + { + /* If all else fails, suffer the mixed mode overhead */ + Microseconds (&wide); + msec = ((double) WideTo64bit (wide) + 500.0) / 1000.0; + } - return(msec); - } + return (msec); +} /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ -StringPtr FastMethod() { - StringPtr method = "\p"; +StringPtr +FastMethod () +{ + StringPtr method = "\p"; #if GENERATINGPOWERPC - /* Initialize globals the first time we are called */ - if (!gInited) FastInitialize(); - - if (gNative) { - /* The Time Manager and UpTime() are entirely native on this machine */ - method = "\pNative UpTime()"; - } - else if (gUpTime) { - /* Use DriverServices if it's available -- it's fast and compatible */ - method = "\pUpTime()"; - } - else if (gUseTBR) { - /* On a recent PowerPC, we poll the TBR directly */ - method = "\pPowerPC TBR"; - } - else if (gUseRTC) { - /* On a 601, we can poll the RTC instead */ - method = "\pPowerPC RTC"; - } - else + /* Initialize globals the first time we are called */ + if (!gInited) + FastInitialize (); + + if (gNative) { + /* The Time Manager and UpTime() are entirely native on this machine */ + method = "\pNative UpTime()"; + } else if (gUpTime) { + /* Use DriverServices if it's available -- it's fast and compatible */ + method = "\pUpTime()"; + } else if (gUseTBR) { + /* On a recent PowerPC, we poll the TBR directly */ + method = "\pPowerPC TBR"; + } else if (gUseRTC) { + /* On a 601, we can poll the RTC instead */ + method = "\pPowerPC RTC"; + } else #endif /* GENERATINGPOWERPC */ - { - /* If all else fails, suffer the mixed mode overhead */ - method = "\pMicroseconds()"; - } + { + /* If all else fails, suffer the mixed mode overhead */ + method = "\pMicroseconds()"; + } - return(method); - } + return (method); +} /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ #pragma mark - #if GENERATINGPOWERPC -asm static UnsignedWide PollRTC_() { -entry PollRTC /* Avoid CodeWarrior glue */ - machine 601 -@AGAIN: - mfrtcu r4 /* RTCU = SPR 4 */ - mfrtcl r5 /* RTCL = SPR 5 */ - mfrtcu r6 - cmpw r4,r6 - bne @AGAIN - stw r4,0(r3) - stw r5,4(r3) - blr - } +asm static UnsignedWide +PollRTC_ () +{ + entry PollRTC /* Avoid CodeWarrior glue */ + machine 601 @ AGAIN:mfrtcu r4 /* RTCU = SPR 4 */ + mfrtcl r5 /* RTCL = SPR 5 */ + mfrtcu r6 cmpw r4, r6 bne @ AGAIN stw r4, 0 (r3) stw r5, 4 (r3) blr} /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ -asm static UnsignedWide PollTBR_() { -entry PollTBR /* Avoid CodeWarrior glue */ - machine 604 -@AGAIN: - mftbu r4 /* TBRU = SPR 268 */ - mftb r5 /* TBRL = SPR 269 */ - mftbu r6 - cmpw r4,r6 - bne @AGAIN - stw r4,0(r3) - stw r5,4(r3) - blr - } +asm static UnsignedWide +PollTBR_ () +{ + entry PollTBR /* Avoid CodeWarrior glue */ + machine 604 @ AGAIN:mftbu r4 /* TBRU = SPR 268 */ + mftb r5 /* TBRL = SPR 269 */ + mftbu r6 cmpw r4, r6 bne @ AGAIN stw r4, 0 (r3) stw r5, 4 (r3) blr} /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ -static Ptr FindFunctionInSharedLib(StringPtr libName, StringPtr funcName) { - OSErr error = noErr; - Str255 errorStr; - Ptr func = NULL; - Ptr entry = NULL; - CFragSymbolClass symClass; - CFragConnectionID connID; - - /* Find CFM containers for the current archecture -- CFM-PPC or CFM-68K */ - if (/* error = */ GetSharedLibrary(libName, kCompiledCFragArch, - kLoadCFrag, &connID, &entry, errorStr)) return(NULL); - if (/* error = */ FindSymbol(connID, funcName, &func, &symClass)) - return(NULL); - - return(func); - } +static Ptr +FindFunctionInSharedLib (StringPtr libName, StringPtr funcName) +{ + OSErr error = noErr; + Str255 errorStr; + Ptr func = NULL; + Ptr entry = NULL; + CFragSymbolClass symClass; + CFragConnectionID connID; + + /* Find CFM containers for the current archecture -- CFM-PPC or CFM-68K */ + if ( /* error = */ GetSharedLibrary (libName, kCompiledCFragArch, + kLoadCFrag, &connID, &entry, + errorStr)) + return (NULL); + if ( /* error = */ FindSymbol (connID, funcName, &func, &symClass)) + return (NULL); + + return (func); +} #endif /* GENERATINGPOWERPC */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/macos/FastTimes.h b/src/timer/macos/FastTimes.h index bde8db763..950efdbb3 100644 --- a/src/timer/macos/FastTimes.h +++ b/src/timer/macos/FastTimes.h @@ -16,12 +16,13 @@ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ -extern void FastInitialize(void); -extern UInt64 FastMicroseconds(void); -extern UInt64 FastMilliseconds(void); -extern StringPtr FastMethod(void); +extern void FastInitialize (void); +extern UInt64 FastMicroseconds (void); +extern UInt64 FastMilliseconds (void); +extern StringPtr FastMethod (void); /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ #endif /* __FAST_TIMES_HEADER__ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/macos/SDL_MPWtimer.c b/src/timer/macos/SDL_MPWtimer.c index 7aee4aa17..cef2ddee3 100644 --- a/src/timer/macos/SDL_MPWtimer.c +++ b/src/timer/macos/SDL_MPWtimer.c @@ -34,7 +34,7 @@ #include "SDL_timer.h" #include "../SDL_timer_c.h" -#define MS_PER_TICK (1000/60) /* MacOS tick = 1/60 second */ +#define MS_PER_TICK (1000/60) /* MacOS tick = 1/60 second */ /* Note: This is only a step above the original 1/60s implementation. * For a good implementation, see FastTimes.[ch], by Matt Slot. @@ -44,42 +44,46 @@ UInt64 start; -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { #ifdef USE_MICROSECONDS - UnsignedWide now; - - Microseconds(&now); - start = WideTo64bit(now); + UnsignedWide now; + + Microseconds (&now); + start = WideTo64bit (now); #else - /* FIXME: Should we implement a wrapping algorithm, like Win32? */ + /* FIXME: Should we implement a wrapping algorithm, like Win32? */ #endif } -Uint32 SDL_GetTicks(void) +Uint32 +SDL_GetTicks (void) { #ifdef USE_MICROSECONDS - UnsignedWide now; - - Microseconds(&now); - return (Uint32)((WideTo64bit(now)-start)/1000); + UnsignedWide now; + + Microseconds (&now); + return (Uint32) ((WideTo64bit (now) - start) / 1000); #else - return(LMGetTicks()*MS_PER_TICK); + return (LMGetTicks () * MS_PER_TICK); #endif } -void SDL_Delay(Uint32 ms) +void +SDL_Delay (Uint32 ms) { #ifdef USE_MICROSECONDS - Uint32 end_ms; - - end_ms = SDL_GetTicks() + ms; - do { - /* FIXME: Yield CPU? */ ; - } while ( SDL_GetTicks() < end_ms ); + Uint32 end_ms; + + end_ms = SDL_GetTicks () + ms; + do { + /* FIXME: Yield CPU? */ ; + } + while (SDL_GetTicks () < end_ms); #else - UInt32 unused; /* MJS */ - Delay(ms/MS_PER_TICK, &unused); + UInt32 unused; /* MJS */ + Delay (ms / MS_PER_TICK, &unused); #endif } @@ -87,66 +91,71 @@ void SDL_Delay(Uint32 ms) /* Data to handle a single periodic alarm */ typedef struct _ExtendedTimerRec { - TMTask tmTask; - ProcessSerialNumber taskPSN; + TMTask tmTask; + ProcessSerialNumber taskPSN; } ExtendedTimerRec, *ExtendedTimerPtr; static ExtendedTimerRec gExtendedTimerRec; -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - /* We don't need a setup? */ - return(0); + /* We don't need a setup? */ + return (0); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - /* We don't need a cleanup? */ - return; + /* We don't need a cleanup? */ + return; } /* Our Stub routine to set up and then call the real routine. */ -pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) +pascal void +TimerCallbackProc (TMTaskPtr tmTaskPtr) { - Uint32 ms; - - WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); - - ms = SDL_alarm_callback(SDL_alarm_interval); - if ( ms ) { - SDL_alarm_interval = ROUND_RESOLUTION(ms); - PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, - SDL_alarm_interval); - } else { - SDL_alarm_interval = 0; - } + Uint32 ms; + + WakeUpProcess (&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); + + ms = SDL_alarm_callback (SDL_alarm_interval); + if (ms) { + SDL_alarm_interval = ROUND_RESOLUTION (ms); + PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); + } else { + SDL_alarm_interval = 0; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - /* - * Configure the global structure that stores the timing information. - */ - gExtendedTimerRec.tmTask.qLink = NULL; - gExtendedTimerRec.tmTask.qType = 0; - gExtendedTimerRec.tmTask.tmAddr = NewTimerUPP(TimerCallbackProc); - gExtendedTimerRec.tmTask.tmCount = 0; - gExtendedTimerRec.tmTask.tmWakeUp = 0; - gExtendedTimerRec.tmTask.tmReserved = 0; - GetCurrentProcess(&gExtendedTimerRec.taskPSN); - - /* Install the task record */ - InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); - - /* Go! */ - PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); - return(0); + /* + * Configure the global structure that stores the timing information. + */ + gExtendedTimerRec.tmTask.qLink = NULL; + gExtendedTimerRec.tmTask.qType = 0; + gExtendedTimerRec.tmTask.tmAddr = NewTimerUPP (TimerCallbackProc); + gExtendedTimerRec.tmTask.tmCount = 0; + gExtendedTimerRec.tmTask.tmWakeUp = 0; + gExtendedTimerRec.tmTask.tmReserved = 0; + GetCurrentProcess (&gExtendedTimerRec.taskPSN); + + /* Install the task record */ + InsXTime ((QElemPtr) & gExtendedTimerRec.tmTask); + + /* Go! */ + PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); + return (0); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); + RmvTime ((QElemPtr) & gExtendedTimerRec.tmTask); } #endif /* SDL_TIMER_MACOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/macos/SDL_systimer.c b/src/timer/macos/SDL_systimer.c index 33fb664bf..79241be5f 100644 --- a/src/timer/macos/SDL_systimer.c +++ b/src/timer/macos/SDL_systimer.c @@ -40,46 +40,50 @@ #define NewTimerProc NewTimerUPP #endif -#define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ +#define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ -#define kTwoPower32 (4294967296.0) /* 2^32 */ +#define kTwoPower32 (4294967296.0) /* 2^32 */ static double start_tick; -static int is_fast_inited = 0; +static int is_fast_inited = 0; -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - if ( ! is_fast_inited ) // important to check or FastTime may hang machine! - SDL_SYS_TimerInit(); + if (!is_fast_inited) // important to check or FastTime may hang machine! + SDL_SYS_TimerInit (); - start_tick = FastMicroseconds(); + start_tick = FastMicroseconds (); } -Uint32 SDL_GetTicks(void) +Uint32 +SDL_GetTicks (void) { - - if ( ! is_fast_inited ) - SDL_SYS_TimerInit(); - - return FastMilliseconds(); + + if (!is_fast_inited) + SDL_SYS_TimerInit (); + + return FastMilliseconds (); } -void SDL_Delay(Uint32 ms) +void +SDL_Delay (Uint32 ms) { - Uint32 stop, now; + Uint32 stop, now; - stop = SDL_GetTicks() + ms; - do { - #if TARGET_API_MAC_CARBON - MPYield(); - #else - SystemTask(); - #endif + stop = SDL_GetTicks () + ms; + do { +#if TARGET_API_MAC_CARBON + MPYield (); +#else + SystemTask (); +#endif - now = SDL_GetTicks(); + now = SDL_GetTicks (); - } while ( stop > now ); + } + while (stop > now); } /* @@ -115,72 +119,77 @@ void SDL_Delay(Uint32 ms) } }*/ - + /* Data to handle a single periodic alarm */ typedef struct _ExtendedTimerRec { - TMTask tmTask; - ProcessSerialNumber taskPSN; + TMTask tmTask; + ProcessSerialNumber taskPSN; } ExtendedTimerRec, *ExtendedTimerPtr; static ExtendedTimerRec gExtendedTimerRec; -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - FastInitialize (); - is_fast_inited = 1; - - return(0); + FastInitialize (); + is_fast_inited = 1; + + return (0); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - /* We don't need a cleanup? */ - return; + /* We don't need a cleanup? */ + return; } /* Our Stub routine to set up and then call the real routine. */ -pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) +pascal void +TimerCallbackProc (TMTaskPtr tmTaskPtr) { - Uint32 ms; + Uint32 ms; - WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); + WakeUpProcess (&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); - ms = SDL_alarm_callback(SDL_alarm_interval); - if ( ms ) { - SDL_alarm_interval = ROUND_RESOLUTION(ms); - PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, - SDL_alarm_interval); - } else { - SDL_alarm_interval = 0; - } + ms = SDL_alarm_callback (SDL_alarm_interval); + if (ms) { + SDL_alarm_interval = ROUND_RESOLUTION (ms); + PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); + } else { + SDL_alarm_interval = 0; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - /* - * Configure the global structure that stores the timing information. - */ - gExtendedTimerRec.tmTask.qLink = NULL; - gExtendedTimerRec.tmTask.qType = 0; - gExtendedTimerRec.tmTask.tmAddr = NewTimerProc(TimerCallbackProc); - gExtendedTimerRec.tmTask.tmCount = 0; - gExtendedTimerRec.tmTask.tmWakeUp = 0; - gExtendedTimerRec.tmTask.tmReserved = 0; - GetCurrentProcess(&gExtendedTimerRec.taskPSN); - - /* Install the task record */ - InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); - - /* Go! */ - PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); - return(0); + /* + * Configure the global structure that stores the timing information. + */ + gExtendedTimerRec.tmTask.qLink = NULL; + gExtendedTimerRec.tmTask.qType = 0; + gExtendedTimerRec.tmTask.tmAddr = NewTimerProc (TimerCallbackProc); + gExtendedTimerRec.tmTask.tmCount = 0; + gExtendedTimerRec.tmTask.tmWakeUp = 0; + gExtendedTimerRec.tmTask.tmReserved = 0; + GetCurrentProcess (&gExtendedTimerRec.taskPSN); + + /* Install the task record */ + InsXTime ((QElemPtr) & gExtendedTimerRec.tmTask); + + /* Go! */ + PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); + return (0); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); + RmvTime ((QElemPtr) & gExtendedTimerRec.tmTask); } #endif /* SDL_TIMER_MACOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/mint/SDL_systimer.c b/src/timer/mint/SDL_systimer.c index 8963ca0b7..88db1ada3 100644 --- a/src/timer/mint/SDL_systimer.c +++ b/src/timer/mint/SDL_systimer.c @@ -51,107 +51,116 @@ /* The first ticks value of the application */ static Uint32 start; static SDL_bool supervisor; -static int mint_present; /* can we use Syield() ? */ +static int mint_present; /* can we use Syield() ? */ -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - void *oldpile; - unsigned long dummy; + void *oldpile; + unsigned long dummy; - /* Set first ticks value */ - oldpile=(void *)Super(0); - start=*((volatile long *)_hz_200); - Super(oldpile); + /* Set first ticks value */ + oldpile = (void *) Super (0); + start = *((volatile long *) _hz_200); + Super (oldpile); - start *= 5; /* One _hz_200 tic is 5ms */ + start *= 5; /* One _hz_200 tic is 5ms */ - mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); + mint_present = (Getcookie (C_MiNT, &dummy) == C_FOUND); } -Uint32 SDL_GetTicks (void) +Uint32 +SDL_GetTicks (void) { - Uint32 now; - void *oldpile=NULL; + Uint32 now; + void *oldpile = NULL; - /* Check if we are in supervisor mode - (this is the case when called from SDL_ThreadedTimerCheck, - which is called from RunTimer, running in the vbl vector) - */ - if (!supervisor) { - oldpile=(void *)Super(0); - } + /* Check if we are in supervisor mode + (this is the case when called from SDL_ThreadedTimerCheck, + which is called from RunTimer, running in the vbl vector) + */ + if (!supervisor) { + oldpile = (void *) Super (0); + } - now=*((volatile long *)_hz_200); + now = *((volatile long *) _hz_200); - if (!supervisor) { - Super(oldpile); - } + if (!supervisor) { + Super (oldpile); + } - return((now*5)-start); + return ((now * 5) - start); } -void SDL_Delay (Uint32 ms) +void +SDL_Delay (Uint32 ms) { - Uint32 now; - - now = SDL_GetTicks(); - while ((SDL_GetTicks()-now)= switch_priority) - switch_priority = 0; - if (switch_priority) - { - if (DosGetInfoBlocks(&tib, &pib)!=NO_ERROR) - switch_priority = 0; - else - { - /* In Warp3, to switch scheduling to 8ms step, one needs to do - DosAsyncTimer() in time-critical thread. On laters versions, - more and more cases of wait-for-something are covered. - - It turns out that on Warp3fp42 it is the priority at the time - of DosAsyncTimer() which matters. Let's hope that this works - with later versions too... XXXX - */ - priority = (tib->tib_ptib2->tib2_ulpri); - if ((priority & 0xFF00) == 0x0300) /* already time-critical */ - switch_priority = 0; - /* Make us time-critical. Just modifying TIB is not enough... */ - /* tib->tib_ptib2->tib2_ulpri = 0x0300;*/ - /* We do not want to run at high priority if a signal causes us - to longjmp() out of this section... */ - if (DosEnterMustComplete(&nesting)) + /* This is similar to DosSleep(), but has 8ms granularity in time-critical + threads even on Warp3. */ + HEV hevEvent1 = 0; /* Event semaphore handle */ + HTIMER htimerEvent1 = 0; /* Timer handle */ + APIRET rc = NO_ERROR; /* Return code */ + int ret = 1; + ULONG priority = 0, nesting; /* Shut down the warnings */ + PPIB pib; + PTIB tib; + char *e = NULL; + APIRET badrc; + int switch_priority = 50; + + DosCreateEventSem (NULL, /* Unnamed */ + &hevEvent1, /* Handle of semaphore returned */ + DC_SEM_SHARED, /* Shared needed for DosAsyncTimer */ + FALSE); /* Semaphore is in RESET state */ + + if (ms >= switch_priority) switch_priority = 0; - else - DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); + if (switch_priority) { + if (DosGetInfoBlocks (&tib, &pib) != NO_ERROR) + switch_priority = 0; + else { + /* In Warp3, to switch scheduling to 8ms step, one needs to do + DosAsyncTimer() in time-critical thread. On laters versions, + more and more cases of wait-for-something are covered. + + It turns out that on Warp3fp42 it is the priority at the time + of DosAsyncTimer() which matters. Let's hope that this works + with later versions too... XXXX + */ + priority = (tib->tib_ptib2->tib2_ulpri); + if ((priority & 0xFF00) == 0x0300) /* already time-critical */ + switch_priority = 0; + /* Make us time-critical. Just modifying TIB is not enough... */ + /* tib->tib_ptib2->tib2_ulpri = 0x0300; */ + /* We do not want to run at high priority if a signal causes us + to longjmp() out of this section... */ + if (DosEnterMustComplete (&nesting)) + switch_priority = 0; + else + DosSetPriority (PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); + } + } + + if ((badrc = DosAsyncTimer (ms, (HSEM) hevEvent1, /* Semaphore to post */ + &htimerEvent1))) /* Timer handler (returned) */ + e = "DosAsyncTimer"; + + if (switch_priority && tib->tib_ptib2->tib2_ulpri == 0x0300) { + /* Nobody switched priority while we slept... Ignore errors... */ + /* tib->tib_ptib2->tib2_ulpri = priority; *//* Get back... */ + if (! + (rc = + DosSetPriority (PRTYS_THREAD, (priority >> 8) & 0xFF, 0, 0))) + rc = DosSetPriority (PRTYS_THREAD, 0, priority & 0xFF, 0); + } + if (switch_priority) + rc = DosExitMustComplete (&nesting); /* Ignore errors */ + + /* The actual blocking call is made with "normal" priority. This way we + should not bother with DosSleep(0) etc. to compensate for us interrupting + higher-priority threads. The goal is to prohibit the system spending too + much time halt()ing, not to run us "no matter what". */ + if (!e) /* Wait for AsyncTimer event */ + badrc = DosWaitEventSem (hevEvent1, SEM_INDEFINITE_WAIT); + + if (e); /* Do nothing */ + else if (badrc == ERROR_INTERRUPT) + ret = 0; + else if (badrc) + e = "DosWaitEventSem"; + if ((rc = DosCloseEventSem (hevEvent1)) && !e) { /* Get rid of semaphore */ + e = "DosCloseEventSem"; + badrc = rc; + } + if (e) { + SDL_SetError ("[SDL_Delay] : Had error in %s(), rc is 0x%x\n", e, + badrc); } - } - - if ((badrc = DosAsyncTimer(ms, - (HSEM) hevEvent1, /* Semaphore to post */ - &htimerEvent1))) /* Timer handler (returned) */ - e = "DosAsyncTimer"; - - if (switch_priority && tib->tib_ptib2->tib2_ulpri == 0x0300) - { - /* Nobody switched priority while we slept... Ignore errors... */ - /* tib->tib_ptib2->tib2_ulpri = priority; */ /* Get back... */ - if (!(rc = DosSetPriority(PRTYS_THREAD, (priority>>8) & 0xFF, 0, 0))) - rc = DosSetPriority(PRTYS_THREAD, 0, priority & 0xFF, 0); - } - if (switch_priority) - rc = DosExitMustComplete(&nesting); /* Ignore errors */ - - /* The actual blocking call is made with "normal" priority. This way we - should not bother with DosSleep(0) etc. to compensate for us interrupting - higher-priority threads. The goal is to prohibit the system spending too - much time halt()ing, not to run us "no matter what". */ - if (!e) /* Wait for AsyncTimer event */ - badrc = DosWaitEventSem(hevEvent1, SEM_INDEFINITE_WAIT); - - if (e) ; /* Do nothing */ - else if (badrc == ERROR_INTERRUPT) - ret = 0; - else if (badrc) - e = "DosWaitEventSem"; - if ((rc = DosCloseEventSem(hevEvent1)) && !e) { /* Get rid of semaphore */ - e = "DosCloseEventSem"; - badrc = rc; - } - if (e) - { - SDL_SetError("[SDL_Delay] : Had error in %s(), rc is 0x%x\n", e, badrc); - } } /* Data to handle a single periodic alarm */ static int timer_alive = 0; static SDL_Thread *timer = NULL; -static int RunTimer(void *unused) +static int +RunTimer (void *unused) { - DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); - while ( timer_alive ) { - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(10); + DosSetPriority (PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); + while (timer_alive) { + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); } - return(0); + SDL_Delay (10); + } + return (0); } /* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if ( timer == NULL ) - return(-1); - return(SDL_SetTimerThreaded(1)); + timer_alive = 1; + timer = SDL_CreateThread (RunTimer, NULL); + if (timer == NULL) + return (-1); + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - timer_alive = 0; - if ( timer ) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } + timer_alive = 0; + if (timer) { + SDL_WaitThread (timer, NULL); + timer = NULL; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: OS/2 uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: OS/2 uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_TIMER_OS2 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/riscos/SDL_systimer.c b/src/timer/riscos/SDL_systimer.c index b782f39ee..8ce152a3f 100644 --- a/src/timer/riscos/SDL_systimer.c +++ b/src/timer/riscos/SDL_systimer.c @@ -37,144 +37,154 @@ /* Timer SDL_arraysize(Timer ),start/reset time */ static Uint32 timerStart; /* Timer running function */ -void RISCOS_CheckTimer(); +void RISCOS_CheckTimer (); #else #include extern Uint32 riscos_main_thread; extern int riscos_using_threads; -extern Uint32 SDL_ThreadID(); -extern Uint32 SDL_EventThreadID(void); +extern Uint32 SDL_ThreadID (); +extern Uint32 SDL_EventThreadID (void); #endif -extern void RISCOS_BackgroundTasks(void); +extern void RISCOS_BackgroundTasks (void); /* The first ticks value of the application */ clock_t start; -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - /* Set first ticks value */ - start = clock(); + /* Set first ticks value */ + start = clock (); } -Uint32 SDL_GetTicks (void) +Uint32 +SDL_GetTicks (void) { - clock_t ticks; + clock_t ticks; - ticks=clock()-start; + ticks = clock () - start; #if CLOCKS_PER_SEC == 1000 - return(ticks); + return (ticks); #elif CLOCKS_PER_SEC == 100 - return (ticks * 10); + return (ticks * 10); #else - return ticks*(1000/CLOCKS_PER_SEC); + return ticks * (1000 / CLOCKS_PER_SEC); #endif } -void SDL_Delay (Uint32 ms) +void +SDL_Delay (Uint32 ms) { - Uint32 now,then,elapsed; + Uint32 now, then, elapsed; #if !SDL_THREADS_DISABLED int is_event_thread; - if (riscos_using_threads) - { - is_event_thread = 0; - if (SDL_EventThreadID()) - { - if (SDL_EventThreadID() == SDL_ThreadID()) is_event_thread = 1; - } else if (SDL_ThreadID() == riscos_main_thread) is_event_thread = 1; - } else is_event_thread = 1; + if (riscos_using_threads) { + is_event_thread = 0; + if (SDL_EventThreadID ()) { + if (SDL_EventThreadID () == SDL_ThreadID ()) + is_event_thread = 1; + } else if (SDL_ThreadID () == riscos_main_thread) + is_event_thread = 1; + } else + is_event_thread = 1; #endif - /*TODO: Next version of Unixlib may allow us to use usleep here */ - /* for non event threads */ + /*TODO: Next version of Unixlib may allow us to use usleep here */ + /* for non event threads */ - /* Set the timeout interval - Linux only needs to do this once */ - then = SDL_GetTicks(); + /* Set the timeout interval - Linux only needs to do this once */ + then = SDL_GetTicks (); - do { - /* Do background tasks required while sleeping as we are not multithreaded */ + do { + /* Do background tasks required while sleeping as we are not multithreaded */ #if SDL_THREADS_DISABLED - RISCOS_BackgroundTasks(); + RISCOS_BackgroundTasks (); #else - /* For threaded build only run background tasks in event thread */ - if (is_event_thread) RISCOS_BackgroundTasks(); + /* For threaded build only run background tasks in event thread */ + if (is_event_thread) + RISCOS_BackgroundTasks (); #endif - /* Calculate the time interval left (in case of interrupt) */ - now = SDL_GetTicks(); - elapsed = (now-then); - then = now; - if ( elapsed >= ms ) { - break; - } - ms -= elapsed; + /* Calculate the time interval left (in case of interrupt) */ + now = SDL_GetTicks (); + elapsed = (now - then); + then = now; + if (elapsed >= ms) { + break; + } + ms -= elapsed; #if !SDL_THREADS_DISABLED - /* Need to yield to let other threads have a go */ - if (riscos_using_threads) pthread_yield(); + /* Need to yield to let other threads have a go */ + if (riscos_using_threads) + pthread_yield (); #endif - } while ( 1 ); + } + while (1); } #if SDL_THREADS_DISABLED /* Non-threaded version of timer */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - return(0); + return (0); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - SDL_SetTimer(0, NULL); + SDL_SetTimer (0, NULL); } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - timerStart = SDL_GetTicks(); + timerStart = SDL_GetTicks (); - return(0); + return (0); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - /* Don't need to do anything as we use SDL_timer_running - to detect if we need to check the timer */ + /* Don't need to do anything as we use SDL_timer_running + to detect if we need to check the timer */ } -void RISCOS_CheckTimer() +void +RISCOS_CheckTimer () { - if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval) - { - Uint32 ms; - - ms = SDL_alarm_callback(SDL_alarm_interval); - if ( ms != SDL_alarm_interval ) - { - if ( ms ) - { - SDL_alarm_interval = ROUND_RESOLUTION(ms); - } else - { - SDL_alarm_interval = 0; - SDL_timer_running = 0; - } - } - if (SDL_alarm_interval) timerStart = SDL_GetTicks(); - } + if (SDL_timer_running + && SDL_GetTicks () - timerStart >= SDL_alarm_interval) { + Uint32 ms; + + ms = SDL_alarm_callback (SDL_alarm_interval); + if (ms != SDL_alarm_interval) { + if (ms) { + SDL_alarm_interval = ROUND_RESOLUTION (ms); + } else { + SDL_alarm_interval = 0; + SDL_timer_running = 0; + } + } + if (SDL_alarm_interval) + timerStart = SDL_GetTicks (); + } } #else @@ -187,47 +197,53 @@ void RISCOS_CheckTimer() static int timer_alive = 0; static SDL_Thread *timer = NULL; -static int RunTimer(void *unused) +static int +RunTimer (void *unused) { - while ( timer_alive ) { - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(1); - } - return(0); + while (timer_alive) { + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); + } + SDL_Delay (1); + } + return (0); } /* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if ( timer == NULL ) - return(-1); - return(SDL_SetTimerThreaded(1)); + timer_alive = 1; + timer = SDL_CreateThread (RunTimer, NULL); + if (timer == NULL) + return (-1); + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - timer_alive = 0; - if ( timer ) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } + timer_alive = 0; + if (timer) { + SDL_WaitThread (timer, NULL); + timer = NULL; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: RISC OS uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: RISC OS uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_THREADS_DISABLED */ #endif /* SDL_TIMER_RISCOS */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/unix/SDL_systimer.c b/src/timer/unix/SDL_systimer.c index 58b53ed01..01755e26a 100644 --- a/src/timer/unix/SDL_systimer.c +++ b/src/timer/unix/SDL_systimer.c @@ -58,132 +58,145 @@ static struct timeval start; #endif /* HAVE_CLOCK_GETTIME */ -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - /* Set first ticks value */ + /* Set first ticks value */ #if HAVE_CLOCK_GETTIME - clock_gettime(CLOCK_MONOTONIC,&start); + clock_gettime (CLOCK_MONOTONIC, &start); #else - gettimeofday(&start, NULL); + gettimeofday (&start, NULL); #endif } -Uint32 SDL_GetTicks (void) +Uint32 +SDL_GetTicks (void) { #if HAVE_CLOCK_GETTIME - Uint32 ticks; - struct timespec now; - clock_gettime(CLOCK_MONOTONIC,&now); - ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_nsec-start.tv_nsec)/1000000; - return(ticks); + Uint32 ticks; + struct timespec now; + clock_gettime (CLOCK_MONOTONIC, &now); + ticks = + (now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec - + start.tv_nsec) / 1000000; + return (ticks); #else - Uint32 ticks; - struct timeval now; - gettimeofday(&now, NULL); - ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; - return(ticks); + Uint32 ticks; + struct timeval now; + gettimeofday (&now, NULL); + ticks = + (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - + start.tv_usec) / 1000; + return (ticks); #endif } -void SDL_Delay (Uint32 ms) +void +SDL_Delay (Uint32 ms) { #if SDL_THREAD_PTH - pth_time_t tv; - tv.tv_sec = ms/1000; - tv.tv_usec = (ms%1000)*1000; - pth_nap(tv); + pth_time_t tv; + tv.tv_sec = ms / 1000; + tv.tv_usec = (ms % 1000) * 1000; + pth_nap (tv); #else - int was_error; + int was_error; #if HAVE_NANOSLEEP - struct timespec elapsed, tv; + struct timespec elapsed, tv; #else - struct timeval tv; - Uint32 then, now, elapsed; + struct timeval tv; + Uint32 then, now, elapsed; #endif - /* Set the timeout interval */ + /* Set the timeout interval */ #if HAVE_NANOSLEEP - elapsed.tv_sec = ms/1000; - elapsed.tv_nsec = (ms%1000)*1000000; + elapsed.tv_sec = ms / 1000; + elapsed.tv_nsec = (ms % 1000) * 1000000; #else - then = SDL_GetTicks(); + then = SDL_GetTicks (); #endif - do { - errno = 0; + do { + errno = 0; #if HAVE_NANOSLEEP - tv.tv_sec = elapsed.tv_sec; - tv.tv_nsec = elapsed.tv_nsec; - was_error = nanosleep(&tv, &elapsed); + tv.tv_sec = elapsed.tv_sec; + tv.tv_nsec = elapsed.tv_nsec; + was_error = nanosleep (&tv, &elapsed); #else - /* Calculate the time interval left (in case of interrupt) */ - now = SDL_GetTicks(); - elapsed = (now-then); - then = now; - if ( elapsed >= ms ) { - break; - } - ms -= elapsed; - tv.tv_sec = ms/1000; - tv.tv_usec = (ms%1000)*1000; - - was_error = select(0, NULL, NULL, NULL, &tv); + /* Calculate the time interval left (in case of interrupt) */ + now = SDL_GetTicks (); + elapsed = (now - then); + then = now; + if (elapsed >= ms) { + break; + } + ms -= elapsed; + tv.tv_sec = ms / 1000; + tv.tv_usec = (ms % 1000) * 1000; + + was_error = select (0, NULL, NULL, NULL, &tv); #endif /* HAVE_NANOSLEEP */ - } while ( was_error && (errno == EINTR) ); + } + while (was_error && (errno == EINTR)); #endif /* SDL_THREAD_PTH */ } #ifdef USE_ITIMER -static void HandleAlarm(int sig) +static void +HandleAlarm (int sig) { - Uint32 ms; - - if ( SDL_alarm_callback ) { - ms = (*SDL_alarm_callback)(SDL_alarm_interval); - if ( ms != SDL_alarm_interval ) { - SDL_SetTimer(ms, SDL_alarm_callback); - } - } + Uint32 ms; + + if (SDL_alarm_callback) { + ms = (*SDL_alarm_callback) (SDL_alarm_interval); + if (ms != SDL_alarm_interval) { + SDL_SetTimer (ms, SDL_alarm_callback); + } + } } -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - struct sigaction action; - - /* Set the alarm handler (Linux specific) */ - SDL_memset(&action, 0, sizeof(action)); - action.sa_handler = HandleAlarm; - action.sa_flags = SA_RESTART; - sigemptyset(&action.sa_mask); - sigaction(SIGALRM, &action, NULL); - return(0); + struct sigaction action; + + /* Set the alarm handler (Linux specific) */ + SDL_memset (&action, 0, sizeof (action)); + action.sa_handler = HandleAlarm; + action.sa_flags = SA_RESTART; + sigemptyset (&action.sa_mask); + sigaction (SIGALRM, &action, NULL); + return (0); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - SDL_SetTimer(0, NULL); + SDL_SetTimer (0, NULL); } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - struct itimerval timer; - - timer.it_value.tv_sec = (SDL_alarm_interval/1000); - timer.it_value.tv_usec = (SDL_alarm_interval%1000)*1000; - timer.it_interval.tv_sec = (SDL_alarm_interval/1000); - timer.it_interval.tv_usec = (SDL_alarm_interval%1000)*1000; - setitimer(ITIMER_REAL, &timer, NULL); - return(0); + struct itimerval timer; + + timer.it_value.tv_sec = (SDL_alarm_interval / 1000); + timer.it_value.tv_usec = (SDL_alarm_interval % 1000) * 1000; + timer.it_interval.tv_sec = (SDL_alarm_interval / 1000); + timer.it_interval.tv_usec = (SDL_alarm_interval % 1000) * 1000; + setitimer (ITIMER_REAL, &timer, NULL); + return (0); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - struct itimerval timer; + struct itimerval timer; - SDL_memset(&timer, 0, (sizeof timer)); - setitimer(ITIMER_REAL, &timer, NULL); + SDL_memset (&timer, 0, (sizeof timer)); + setitimer (ITIMER_REAL, &timer, NULL); } #else /* USE_ITIMER */ @@ -194,47 +207,53 @@ void SDL_SYS_StopTimer(void) static int timer_alive = 0; static SDL_Thread *timer = NULL; -static int RunTimer(void *unused) +static int +RunTimer (void *unused) { - while ( timer_alive ) { - if ( SDL_timer_running ) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(1); - } - return(0); + while (timer_alive) { + if (SDL_timer_running) { + SDL_ThreadedTimerCheck (); + } + SDL_Delay (1); + } + return (0); } /* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if ( timer == NULL ) - return(-1); - return(SDL_SetTimerThreaded(1)); + timer_alive = 1; + timer = SDL_CreateThread (RunTimer, NULL); + if (timer == NULL) + return (-1); + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - timer_alive = 0; - if ( timer ) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } + timer_alive = 0; + if (timer) { + SDL_WaitThread (timer, NULL); + timer = NULL; + } } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: Linux uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: Linux uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* USE_ITIMER */ #endif /* SDL_TIMER_UNIX */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/win32/SDL_systimer.c b/src/timer/win32/SDL_systimer.c index 4a24d130f..0d3d96b5b 100644 --- a/src/timer/win32/SDL_systimer.c +++ b/src/timer/win32/SDL_systimer.c @@ -31,7 +31,7 @@ #include "../SDL_timer_c.h" #ifdef _WIN32_WCE - #error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead. +#error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead. #endif #define TIME_WRAP_VALUE (~(DWORD)0) @@ -48,113 +48,118 @@ static LARGE_INTEGER hires_start_ticks; static LARGE_INTEGER hires_ticks_per_second; #endif -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - /* Set first ticks value */ + /* Set first ticks value */ #ifdef USE_GETTICKCOUNT - start = GetTickCount(); + start = GetTickCount (); #else -#if 0 /* Apparently there are problems with QPC on Win2K */ - if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) - { - hires_timer_available = TRUE; - QueryPerformanceCounter(&hires_start_ticks); - } - else +#if 0 /* Apparently there are problems with QPC on Win2K */ + if (QueryPerformanceFrequency (&hires_ticks_per_second) == TRUE) { + hires_timer_available = TRUE; + QueryPerformanceCounter (&hires_start_ticks); + } else #endif - { - hires_timer_available = FALSE; - timeBeginPeriod(1); /* use 1 ms timer precision */ - start = timeGetTime(); - } + { + hires_timer_available = FALSE; + timeBeginPeriod (1); /* use 1 ms timer precision */ + start = timeGetTime (); + } #endif } -Uint32 SDL_GetTicks(void) +Uint32 +SDL_GetTicks (void) { - DWORD now, ticks; + DWORD now, ticks; #ifndef USE_GETTICKCOUNT - LARGE_INTEGER hires_now; + LARGE_INTEGER hires_now; #endif #ifdef USE_GETTICKCOUNT - now = GetTickCount(); + now = GetTickCount (); #else - if (hires_timer_available) - { - QueryPerformanceCounter(&hires_now); - - hires_now.QuadPart -= hires_start_ticks.QuadPart; - hires_now.QuadPart *= 1000; - hires_now.QuadPart /= hires_ticks_per_second.QuadPart; - - return (DWORD)hires_now.QuadPart; - } - else - { - now = timeGetTime(); - } + if (hires_timer_available) { + QueryPerformanceCounter (&hires_now); + + hires_now.QuadPart -= hires_start_ticks.QuadPart; + hires_now.QuadPart *= 1000; + hires_now.QuadPart /= hires_ticks_per_second.QuadPart; + + return (DWORD) hires_now.QuadPart; + } else { + now = timeGetTime (); + } #endif - if ( now < start ) { - ticks = (TIME_WRAP_VALUE-start) + now; - } else { - ticks = (now - start); - } - return(ticks); + if (now < start) { + ticks = (TIME_WRAP_VALUE - start) + now; + } else { + ticks = (now - start); + } + return (ticks); } -void SDL_Delay(Uint32 ms) +void +SDL_Delay (Uint32 ms) { - Sleep(ms); + Sleep (ms); } /* Data to handle a single periodic alarm */ static UINT timerID = 0; -static void CALLBACK HandleAlarm(UINT uID, UINT uMsg, DWORD_PTR dwUser, - DWORD_PTR dw1, DWORD_PTR dw2) +static void CALLBACK +HandleAlarm (UINT uID, UINT uMsg, DWORD_PTR dwUser, + DWORD_PTR dw1, DWORD_PTR dw2) { - SDL_ThreadedTimerCheck(); + SDL_ThreadedTimerCheck (); } -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - MMRESULT result; - - /* Set timer resolution */ - result = timeBeginPeriod(TIMER_RESOLUTION); - if ( result != TIMERR_NOERROR ) { - SDL_SetError("Warning: Can't set %d ms timer resolution", - TIMER_RESOLUTION); - } - /* Allow 10 ms of drift so we don't chew on CPU */ - timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC); - if ( ! timerID ) { - SDL_SetError("timeSetEvent() failed"); - return(-1); - } - return(SDL_SetTimerThreaded(1)); + MMRESULT result; + + /* Set timer resolution */ + result = timeBeginPeriod (TIMER_RESOLUTION); + if (result != TIMERR_NOERROR) { + SDL_SetError ("Warning: Can't set %d ms timer resolution", + TIMER_RESOLUTION); + } + /* Allow 10 ms of drift so we don't chew on CPU */ + timerID = + timeSetEvent (TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC); + if (!timerID) { + SDL_SetError ("timeSetEvent() failed"); + return (-1); + } + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - if ( timerID ) { - timeKillEvent(timerID); - } - timeEndPeriod(TIMER_RESOLUTION); + if (timerID) { + timeKillEvent (timerID); + } + timeEndPeriod (TIMER_RESOLUTION); } -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: Win32 uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: Win32 uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_TIMER_WIN32 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/timer/wince/SDL_systimer.c b/src/timer/wince/SDL_systimer.c index 1e129db76..f552fd341 100644 --- a/src/timer/wince/SDL_systimer.c +++ b/src/timer/wince/SDL_systimer.c @@ -34,62 +34,68 @@ static Uint64 start_date; static Uint64 start_ticks; -static Uint64 wce_ticks(void) +static Uint64 +wce_ticks (void) { - return((Uint64)GetTickCount()); + return ((Uint64) GetTickCount ()); } -static Uint64 wce_date(void) +static Uint64 +wce_date (void) { - union - { - FILETIME ftime; - Uint64 itime; - } ftime; - SYSTEMTIME stime; - - GetSystemTime(&stime); - SystemTimeToFileTime(&stime,&ftime.ftime); - ftime.itime/=10000; // Convert 100ns intervals to 1ms intervals - // Remove ms portion, which can't be relied on - ftime.itime -= (ftime.itime % 1000); - return(ftime.itime); + union + { + FILETIME ftime; + Uint64 itime; + } ftime; + SYSTEMTIME stime; + + GetSystemTime (&stime); + SystemTimeToFileTime (&stime, &ftime.ftime); + ftime.itime /= 10000; // Convert 100ns intervals to 1ms intervals + // Remove ms portion, which can't be relied on + ftime.itime -= (ftime.itime % 1000); + return (ftime.itime); } -static Sint32 wce_rel_ticks(void) +static Sint32 +wce_rel_ticks (void) { - return((Sint32)(wce_ticks()-start_ticks)); + return ((Sint32) (wce_ticks () - start_ticks)); } -static Sint32 wce_rel_date(void) +static Sint32 +wce_rel_date (void) { - return((Sint32)(wce_date()-start_date)); + return ((Sint32) (wce_date () - start_date)); } /* Return time in ms relative to when SDL was started */ -Uint32 SDL_GetTicks() +Uint32 +SDL_GetTicks () { - Sint32 offset=wce_rel_date()-wce_rel_ticks(); - if((offset < -1000) || (offset > 1000)) - { + Sint32 offset = wce_rel_date () - wce_rel_ticks (); + if ((offset < -1000) || (offset > 1000)) { // fprintf(stderr,"Time desync(%+d), resyncing\n",offset/1000); - start_ticks-=offset; - } + start_ticks -= offset; + } - return((Uint32)wce_rel_ticks()); + return ((Uint32) wce_rel_ticks ()); } /* Give up approx. givem milliseconds to the OS. */ -void SDL_Delay(Uint32 ms) +void +SDL_Delay (Uint32 ms) { - Sleep(ms); + Sleep (ms); } /* Recard start-time of application for reference */ -void SDL_StartTicks(void) +void +SDL_StartTicks (void) { - start_date=wce_date(); - start_ticks=wce_ticks(); + start_date = wce_date (); + start_ticks = wce_ticks (); } static UINT WIN_timer; @@ -99,46 +105,47 @@ static UINT WIN_timer; static HANDLE timersThread = 0; static HANDLE timersQuitEvent = 0; -DWORD TimersThreadProc(void *data) +DWORD +TimersThreadProc (void *data) { - while(WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT) - { - SDL_ThreadedTimerCheck(); - } - return 0; + while (WaitForSingleObject (timersQuitEvent, 10) == WAIT_TIMEOUT) { + SDL_ThreadedTimerCheck (); + } + return 0; } -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - // create a thread to process a threaded timers - // SetTimer does not suit the needs because - // TimerCallbackProc will be called only when WM_TIMER occured - - timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0); - if( !timersQuitEvent ) - { - SDL_SetError("Cannot create event for timers thread"); - return -1; - } - timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0); - if( !timersThread ) - { - SDL_SetError("Cannot create timers thread, check amount of RAM available"); - return -1; - } - SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST); - - return(SDL_SetTimerThreaded(1)); + // create a thread to process a threaded timers + // SetTimer does not suit the needs because + // TimerCallbackProc will be called only when WM_TIMER occured + + timersQuitEvent = CreateEvent (0, TRUE, FALSE, 0); + if (!timersQuitEvent) { + SDL_SetError ("Cannot create event for timers thread"); + return -1; + } + timersThread = CreateThread (NULL, 0, TimersThreadProc, 0, 0, 0); + if (!timersThread) { + SDL_SetError + ("Cannot create timers thread, check amount of RAM available"); + return -1; + } + SetThreadPriority (timersThread, THREAD_PRIORITY_HIGHEST); + + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - SetEvent(timersQuitEvent); - if( WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT ) - TerminateThread(timersThread, 0); - CloseHandle(timersThread); - CloseHandle(timersQuitEvent); - return; + SetEvent (timersQuitEvent); + if (WaitForSingleObject (timersThread, 2000) == WAIT_TIMEOUT) + TerminateThread (timersThread, 0); + CloseHandle (timersThread); + CloseHandle (timersQuitEvent); + return; } #else @@ -148,51 +155,57 @@ void SDL_SYS_TimerQuit(void) /* Data to handle a single periodic alarm */ static UINT timerID = 0; -static void CALLBACK HandleAlarm(UINT uID, UINT uMsg, DWORD dwUser, - DWORD dw1, DWORD dw2) +static void CALLBACK +HandleAlarm (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { - SDL_ThreadedTimerCheck(); + SDL_ThreadedTimerCheck (); } -int SDL_SYS_TimerInit(void) +int +SDL_SYS_TimerInit (void) { - MMRESULT result; - - /* Set timer resolution */ - result = timeBeginPeriod(TIMER_RESOLUTION); - if ( result != TIMERR_NOERROR ) { - SDL_SetError("Warning: Can't set %d ms timer resolution", - TIMER_RESOLUTION); - } - /* Allow 10 ms of drift so we don't chew on CPU */ - timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC); - if ( ! timerID ) { - SDL_SetError("timeSetEvent() failed"); - return(-1); - } - return(SDL_SetTimerThreaded(1)); + MMRESULT result; + + /* Set timer resolution */ + result = timeBeginPeriod (TIMER_RESOLUTION); + if (result != TIMERR_NOERROR) { + SDL_SetError ("Warning: Can't set %d ms timer resolution", + TIMER_RESOLUTION); + } + /* Allow 10 ms of drift so we don't chew on CPU */ + timerID = + timeSetEvent (TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC); + if (!timerID) { + SDL_SetError ("timeSetEvent() failed"); + return (-1); + } + return (SDL_SetTimerThreaded (1)); } -void SDL_SYS_TimerQuit(void) +void +SDL_SYS_TimerQuit (void) { - if ( timerID ) { - timeKillEvent(timerID); - } - timeEndPeriod(TIMER_RESOLUTION); + if (timerID) { + timeKillEvent (timerID); + } + timeEndPeriod (TIMER_RESOLUTION); } #endif -int SDL_SYS_StartTimer(void) +int +SDL_SYS_StartTimer (void) { - SDL_SetError("Internal logic error: WinCE uses threaded timer"); - return(-1); + SDL_SetError ("Internal logic error: WinCE uses threaded timer"); + return (-1); } -void SDL_SYS_StopTimer(void) +void +SDL_SYS_StopTimer (void) { - return; + return; } #endif /* SDL_TIMER_WINCE */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index cf33352ba..bfadd4cdb 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -545,7 +545,7 @@ do { \ } while(0) #endif - + /* * Special case: 50% alpha (alpha=128) * This is treated specially because it can be optimized very well, and @@ -704,7 +704,7 @@ do { \ } while(0) #else - + #define CHOOSE_BLIT(blitter, alpha, fmt) \ do { \ if(alpha == 255) { \ @@ -779,8 +779,9 @@ do { \ * This takes care of the case when the surface is clipped on the left and/or * right. Top clipping has already been taken care of. */ -static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, - Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha) +static void +RLEClipBlit (int w, Uint8 * srcbuf, SDL_Surface * dst, + Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha) { SDL_PixelFormat *fmt = dst->format; @@ -828,7 +829,7 @@ static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, } \ } while(0) - CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt); + CHOOSE_BLIT (RLECLIPBLIT, alpha, fmt); #undef RLECLIPBLIT @@ -836,34 +837,35 @@ static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, /* blit a colorkeyed RLE surface */ -int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) +int +SDL_RLEBlit (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect) { - Uint8 *dstbuf; - Uint8 *srcbuf; - int x, y; - int w = src->w; - unsigned alpha; - - /* Lock the destination if necessary */ - if ( SDL_MUSTLOCK(dst) ) { - if ( SDL_LockSurface(dst) < 0 ) { - return(-1); - } - } + Uint8 *dstbuf; + Uint8 *srcbuf; + int x, y; + int w = src->w; + unsigned alpha; - /* Set up the source and destination pointers */ - x = dstrect->x; - y = dstrect->y; - dstbuf = (Uint8 *)dst->pixels - + y * dst->pitch + x * src->format->BytesPerPixel; - srcbuf = (Uint8 *)src->map->sw_data->aux_data; + /* Lock the destination if necessary */ + if (SDL_MUSTLOCK (dst)) { + if (SDL_LockSurface (dst) < 0) { + return (-1); + } + } - { - /* skip lines at the top if neccessary */ - int vskip = srcrect->y; - int ofs = 0; - if(vskip) { + /* Set up the source and destination pointers */ + x = dstrect->x; + y = dstrect->y; + dstbuf = (Uint8 *) dst->pixels + + y * dst->pitch + x * src->format->BytesPerPixel; + srcbuf = (Uint8 *) src->map->sw_data->aux_data; + + { + /* skip lines at the top if neccessary */ + int vskip = srcrect->y; + int ofs = 0; + if (vskip) { #define RLESKIP(bpp, Type) \ for(;;) { \ @@ -883,25 +885,33 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, } \ } - switch(src->format->BytesPerPixel) { - case 1: RLESKIP(1, Uint8); break; - case 2: RLESKIP(2, Uint8); break; - case 3: RLESKIP(3, Uint8); break; - case 4: RLESKIP(4, Uint16); break; - } + switch (src->format->BytesPerPixel) { + case 1: + RLESKIP (1, Uint8); + break; + case 2: + RLESKIP (2, Uint8); + break; + case 3: + RLESKIP (3, Uint8); + break; + case 4: + RLESKIP (4, Uint16); + break; + } #undef RLESKIP - } - } + } + } - alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA - ? src->format->alpha : 255; - /* if left or right edge clipping needed, call clip blit */ - if ( srcrect->x || srcrect->w != src->w ) { - RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha); - } else { - SDL_PixelFormat *fmt = src->format; + alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA + ? src->format->alpha : 255; + /* if left or right edge clipping needed, call clip blit */ + if (srcrect->x || srcrect->w != src->w) { + RLEClipBlit (w, srcbuf, dst, dstbuf, srcrect, alpha); + } else { + SDL_PixelFormat *fmt = src->format; #define RLEBLIT(bpp, Type, do_blit) \ do { \ @@ -927,17 +937,17 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, } \ } while(0) - CHOOSE_BLIT(RLEBLIT, alpha, fmt); + CHOOSE_BLIT (RLEBLIT, alpha, fmt); #undef RLEBLIT - } + } -done: - /* Unlock the destination if necessary */ - if ( SDL_MUSTLOCK(dst) ) { - SDL_UnlockSurface(dst); - } - return(0); + done: + /* Unlock the destination if necessary */ + if (SDL_MUSTLOCK (dst)) { + SDL_UnlockSurface (dst); + } + return (0); } #undef OPAQUE_BLIT @@ -995,24 +1005,26 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, /* used to save the destination format in the encoding. Designed to be macro-compatible with SDL_PixelFormat but without the unneeded fields */ -typedef struct { - Uint8 BytesPerPixel; - Uint8 Rloss; - Uint8 Gloss; - Uint8 Bloss; - Uint8 Rshift; - Uint8 Gshift; - Uint8 Bshift; - Uint8 Ashift; - Uint32 Rmask; - Uint32 Gmask; - Uint32 Bmask; - Uint32 Amask; +typedef struct +{ + Uint8 BytesPerPixel; + Uint8 Rloss; + Uint8 Gloss; + Uint8 Bloss; + Uint8 Rshift; + Uint8 Gshift; + Uint8 Bshift; + Uint8 Ashift; + Uint32 Rmask; + Uint32 Gmask; + Uint32 Bmask; + Uint32 Amask; } RLEDestFormat; /* blit a pixel-alpha RLE surface clipped at the right and/or left edges */ -static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, - Uint8 *dstbuf, SDL_Rect *srcrect) +static void +RLEAlphaClipBlit (int w, Uint8 * srcbuf, SDL_Surface * dst, + Uint8 * dstbuf, SDL_Rect * srcrect) { SDL_PixelFormat *df = dst->format; /* @@ -1088,23 +1100,23 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, } while(--linecount); \ } while(0) - switch(df->BytesPerPixel) { + switch (df->BytesPerPixel) { case 2: - if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0 - || df->Bmask == 0x07e0) - RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565); - else - RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555); - break; + if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) + RLEALPHACLIPBLIT (Uint16, Uint8, BLIT_TRANSL_565); + else + RLEALPHACLIPBLIT (Uint16, Uint8, BLIT_TRANSL_555); + break; case 4: - RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888); - break; + RLEALPHACLIPBLIT (Uint32, Uint16, BLIT_TRANSL_888); + break; } } /* blit a pixel-alpha RLE surface */ -int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) +int +SDL_RLEAlphaBlit (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect) { int x, y; int w = src->w; @@ -1112,84 +1124,88 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_PixelFormat *df = dst->format; /* Lock the destination if necessary */ - if ( SDL_MUSTLOCK(dst) ) { - if ( SDL_LockSurface(dst) < 0 ) { - return -1; - } + if (SDL_MUSTLOCK (dst)) { + if (SDL_LockSurface (dst) < 0) { + return -1; + } } x = dstrect->x; y = dstrect->y; - dstbuf = (Uint8 *)dst->pixels - + y * dst->pitch + x * df->BytesPerPixel; - srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat); + dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel; + srcbuf = (Uint8 *) src->map->sw_data->aux_data + sizeof (RLEDestFormat); { - /* skip lines at the top if necessary */ - int vskip = srcrect->y; - if(vskip) { - int ofs; - if(df->BytesPerPixel == 2) { - /* the 16/32 interleaved format */ - do { - /* skip opaque line */ - ofs = 0; - do { - int run; - ofs += srcbuf[0]; - run = srcbuf[1]; - srcbuf += 2; - if(run) { - srcbuf += 2 * run; - ofs += run; - } else if(!ofs) - goto done; - } while(ofs < w); - - /* skip padding */ - srcbuf += (uintptr_t)srcbuf & 2; - - /* skip translucent line */ - ofs = 0; - do { - int run; - ofs += ((Uint16 *)srcbuf)[0]; - run = ((Uint16 *)srcbuf)[1]; - srcbuf += 4 * (run + 1); - ofs += run; - } while(ofs < w); - } while(--vskip); - } else { - /* the 32/32 interleaved format */ - vskip <<= 1; /* opaque and translucent have same format */ - do { - ofs = 0; - do { - int run; - ofs += ((Uint16 *)srcbuf)[0]; - run = ((Uint16 *)srcbuf)[1]; - srcbuf += 4; - if(run) { - srcbuf += 4 * run; - ofs += run; - } else if(!ofs) - goto done; - } while(ofs < w); - } while(--vskip); - } - } + /* skip lines at the top if necessary */ + int vskip = srcrect->y; + if (vskip) { + int ofs; + if (df->BytesPerPixel == 2) { + /* the 16/32 interleaved format */ + do { + /* skip opaque line */ + ofs = 0; + do { + int run; + ofs += srcbuf[0]; + run = srcbuf[1]; + srcbuf += 2; + if (run) { + srcbuf += 2 * run; + ofs += run; + } else if (!ofs) + goto done; + } + while (ofs < w); + + /* skip padding */ + srcbuf += (uintptr_t) srcbuf & 2; + + /* skip translucent line */ + ofs = 0; + do { + int run; + ofs += ((Uint16 *) srcbuf)[0]; + run = ((Uint16 *) srcbuf)[1]; + srcbuf += 4 * (run + 1); + ofs += run; + } + while (ofs < w); + } + while (--vskip); + } else { + /* the 32/32 interleaved format */ + vskip <<= 1; /* opaque and translucent have same format */ + do { + ofs = 0; + do { + int run; + ofs += ((Uint16 *) srcbuf)[0]; + run = ((Uint16 *) srcbuf)[1]; + srcbuf += 4; + if (run) { + srcbuf += 4 * run; + ofs += run; + } else if (!ofs) + goto done; + } + while (ofs < w); + } + while (--vskip); + } + } } /* if left or right edge clipping needed, call clip blit */ - if(srcrect->x || srcrect->w != src->w) { - RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect); + if (srcrect->x || srcrect->w != src->w) { + RLEAlphaClipBlit (w, srcbuf, dst, dstbuf, srcrect); } else { - /* - * non-clipped blitter. Ptype is the destination pixel type, - * Ctype the translucent count type, and do_blend the - * macro to blend one pixel. - */ + /* + * non-clipped blitter. Ptype is the destination pixel type, + * Ctype the translucent count type, and do_blend the + * macro to blend one pixel. + */ #define RLEALPHABLIT(Ptype, Ctype, do_blend) \ do { \ int linecount = srcrect->h; \ @@ -1235,24 +1251,24 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, } while(--linecount); \ } while(0) - switch(df->BytesPerPixel) { - case 2: - if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0 - || df->Bmask == 0x07e0) - RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565); - else - RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555); - break; - case 4: - RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888); - break; - } + switch (df->BytesPerPixel) { + case 2: + if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 + || df->Bmask == 0x07e0) + RLEALPHABLIT (Uint16, Uint8, BLIT_TRANSL_565); + else + RLEALPHABLIT (Uint16, Uint8, BLIT_TRANSL_555); + break; + case 4: + RLEALPHABLIT (Uint32, Uint16, BLIT_TRANSL_888); + break; + } } - done: + done: /* Unlock the destination if necessary */ - if ( SDL_MUSTLOCK(dst) ) { - SDL_UnlockSurface(dst); + if (SDL_MUSTLOCK (dst)) { + SDL_UnlockSurface (dst); } return 0; } @@ -1268,34 +1284,36 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, */ /* encode 32bpp rgb + a into 16bpp rgb, losing alpha */ -static int copy_opaque_16(void *dst, Uint32 *src, int n, - SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) +static int +copy_opaque_16 (void *dst, Uint32 * src, int n, + SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) { int i; Uint16 *d = dst; - for(i = 0; i < n; i++) { - unsigned r, g, b; - RGB_FROM_PIXEL(*src, sfmt, r, g, b); - PIXEL_FROM_RGB(*d, dfmt, r, g, b); - src++; - d++; + for (i = 0; i < n; i++) { + unsigned r, g, b; + RGB_FROM_PIXEL (*src, sfmt, r, g, b); + PIXEL_FROM_RGB (*d, dfmt, r, g, b); + src++; + d++; } return n * 2; } /* decode opaque pixels from 16bpp to 32bpp rgb + a */ -static int uncopy_opaque_16(Uint32 *dst, void *src, int n, - RLEDestFormat *sfmt, SDL_PixelFormat *dfmt) +static int +uncopy_opaque_16 (Uint32 * dst, void *src, int n, + RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) { int i; Uint16 *s = src; unsigned alpha = dfmt->Amask ? 255 : 0; - for(i = 0; i < n; i++) { - unsigned r, g, b; - RGB_FROM_PIXEL(*s, sfmt, r, g, b); - PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha); - s++; - dst++; + for (i = 0; i < n; i++) { + unsigned r, g, b; + RGB_FROM_PIXEL (*s, sfmt, r, g, b); + PIXEL_FROM_RGBA (*dst, dfmt, r, g, b, alpha); + s++; + dst++; } return n * 2; } @@ -1303,89 +1321,94 @@ static int uncopy_opaque_16(Uint32 *dst, void *src, int n, /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */ -static int copy_transl_565(void *dst, Uint32 *src, int n, - SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) +static int +copy_transl_565 (void *dst, Uint32 * src, int n, + SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) { int i; Uint32 *d = dst; - for(i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint16 pix; - RGBA_FROM_8888(*src, sfmt, r, g, b, a); - PIXEL_FROM_RGB(pix, dfmt, r, g, b); - *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0); - src++; - d++; + for (i = 0; i < n; i++) { + unsigned r, g, b, a; + Uint16 pix; + RGBA_FROM_8888 (*src, sfmt, r, g, b, a); + PIXEL_FROM_RGB (pix, dfmt, r, g, b); + *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0); + src++; + d++; } return n * 4; } /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */ -static int copy_transl_555(void *dst, Uint32 *src, int n, - SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) +static int +copy_transl_555 (void *dst, Uint32 * src, int n, + SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) { int i; Uint32 *d = dst; - for(i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint16 pix; - RGBA_FROM_8888(*src, sfmt, r, g, b, a); - PIXEL_FROM_RGB(pix, dfmt, r, g, b); - *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0); - src++; - d++; + for (i = 0; i < n; i++) { + unsigned r, g, b, a; + Uint16 pix; + RGBA_FROM_8888 (*src, sfmt, r, g, b, a); + PIXEL_FROM_RGB (pix, dfmt, r, g, b); + *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0); + src++; + d++; } return n * 4; } /* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */ -static int uncopy_transl_16(Uint32 *dst, void *src, int n, - RLEDestFormat *sfmt, SDL_PixelFormat *dfmt) +static int +uncopy_transl_16 (Uint32 * dst, void *src, int n, + RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) { int i; Uint32 *s = src; - for(i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint32 pix = *s++; - a = (pix & 0x3e0) >> 2; - pix = (pix & ~0x3e0) | pix >> 16; - RGB_FROM_PIXEL(pix, sfmt, r, g, b); - PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a); - dst++; + for (i = 0; i < n; i++) { + unsigned r, g, b, a; + Uint32 pix = *s++; + a = (pix & 0x3e0) >> 2; + pix = (pix & ~0x3e0) | pix >> 16; + RGB_FROM_PIXEL (pix, sfmt, r, g, b); + PIXEL_FROM_RGBA (*dst, dfmt, r, g, b, a); + dst++; } return n * 4; } /* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ -static int copy_32(void *dst, Uint32 *src, int n, - SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) +static int +copy_32 (void *dst, Uint32 * src, int n, + SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) { int i; Uint32 *d = dst; - for(i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint32 pixel; - RGBA_FROM_8888(*src, sfmt, r, g, b, a); - PIXEL_FROM_RGB(pixel, dfmt, r, g, b); - *d++ = pixel | a << 24; - src++; + for (i = 0; i < n; i++) { + unsigned r, g, b, a; + Uint32 pixel; + RGBA_FROM_8888 (*src, sfmt, r, g, b, a); + PIXEL_FROM_RGB (pixel, dfmt, r, g, b); + *d++ = pixel | a << 24; + src++; } return n * 4; } /* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ -static int uncopy_32(Uint32 *dst, void *src, int n, - RLEDestFormat *sfmt, SDL_PixelFormat *dfmt) +static int +uncopy_32 (Uint32 * dst, void *src, int n, + RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) { int i; Uint32 *s = src; - for(i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint32 pixel = *s++; - RGB_FROM_PIXEL(pixel, sfmt, r, g, b); - a = pixel >> 24; - PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a); - dst++; + for (i = 0; i < n; i++) { + unsigned r, g, b, a; + Uint32 pixel = *s++; + RGB_FROM_PIXEL (pixel, sfmt, r, g, b); + a = pixel >> 24; + PIXEL_FROM_RGBA (*dst, dfmt, r, g, b, a); + dst++; } return n * 4; } @@ -1396,7 +1419,8 @@ static int uncopy_32(Uint32 *dst, void *src, int n, ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U) /* convert surface to be quickly alpha-blittable onto dest, if possible */ -static int RLEAlphaSurface(SDL_Surface *surface) +static int +RLEAlphaSurface (SDL_Surface * surface) { SDL_Surface *dest; SDL_PixelFormat *df; @@ -1405,97 +1429,97 @@ static int RLEAlphaSurface(SDL_Surface *surface) int max_transl_run = 65535; unsigned masksum; Uint8 *rlebuf, *dst; - int (*copy_opaque)(void *, Uint32 *, int, - SDL_PixelFormat *, SDL_PixelFormat *); - int (*copy_transl)(void *, Uint32 *, int, - SDL_PixelFormat *, SDL_PixelFormat *); + int (*copy_opaque) (void *, Uint32 *, int, + SDL_PixelFormat *, SDL_PixelFormat *); + int (*copy_transl) (void *, Uint32 *, int, + SDL_PixelFormat *, SDL_PixelFormat *); dest = surface->map->dst; - if(!dest) - return -1; + if (!dest) + return -1; df = dest->format; - if(surface->format->BitsPerPixel != 32) - return -1; /* only 32bpp source supported */ + if (surface->format->BitsPerPixel != 32) + return -1; /* only 32bpp source supported */ /* find out whether the destination is one we support, and determine the max size of the encoded result */ masksum = df->Rmask | df->Gmask | df->Bmask; - switch(df->BytesPerPixel) { + switch (df->BytesPerPixel) { case 2: - /* 16bpp: only support 565 and 555 formats */ - switch(masksum) { - case 0xffff: - if(df->Gmask == 0x07e0 - || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) { - copy_opaque = copy_opaque_16; - copy_transl = copy_transl_565; - } else - return -1; - break; - case 0x7fff: - if(df->Gmask == 0x03e0 - || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) { - copy_opaque = copy_opaque_16; - copy_transl = copy_transl_555; - } else - return -1; - break; - default: - return -1; - } - max_opaque_run = 255; /* runs stored as bytes */ - - /* worst case is alternating opaque and translucent pixels, - with room for alignment padding between lines */ - maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2; - break; + /* 16bpp: only support 565 and 555 formats */ + switch (masksum) { + case 0xffff: + if (df->Gmask == 0x07e0 + || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) { + copy_opaque = copy_opaque_16; + copy_transl = copy_transl_565; + } else + return -1; + break; + case 0x7fff: + if (df->Gmask == 0x03e0 + || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) { + copy_opaque = copy_opaque_16; + copy_transl = copy_transl_555; + } else + return -1; + break; + default: + return -1; + } + max_opaque_run = 255; /* runs stored as bytes */ + + /* worst case is alternating opaque and translucent pixels, + with room for alignment padding between lines */ + maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2; + break; case 4: - if(masksum != 0x00ffffff) - return -1; /* requires unused high byte */ - copy_opaque = copy_32; - copy_transl = copy_32; - max_opaque_run = 255; /* runs stored as short ints */ - - /* worst case is alternating opaque and translucent pixels */ - maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4; - break; + if (masksum != 0x00ffffff) + return -1; /* requires unused high byte */ + copy_opaque = copy_32; + copy_transl = copy_32; + max_opaque_run = 255; /* runs stored as short ints */ + + /* worst case is alternating opaque and translucent pixels */ + maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4; + break; default: - return -1; /* anything else unsupported right now */ + return -1; /* anything else unsupported right now */ } - maxsize += sizeof(RLEDestFormat); - rlebuf = (Uint8 *)SDL_malloc(maxsize); - if(!rlebuf) { - SDL_OutOfMemory(); - return -1; + maxsize += sizeof (RLEDestFormat); + rlebuf = (Uint8 *) SDL_malloc (maxsize); + if (!rlebuf) { + SDL_OutOfMemory (); + return -1; } { - /* save the destination format so we can undo the encoding later */ - RLEDestFormat *r = (RLEDestFormat *)rlebuf; - r->BytesPerPixel = df->BytesPerPixel; - r->Rloss = df->Rloss; - r->Gloss = df->Gloss; - r->Bloss = df->Bloss; - r->Rshift = df->Rshift; - r->Gshift = df->Gshift; - r->Bshift = df->Bshift; - r->Ashift = df->Ashift; - r->Rmask = df->Rmask; - r->Gmask = df->Gmask; - r->Bmask = df->Bmask; - r->Amask = df->Amask; + /* save the destination format so we can undo the encoding later */ + RLEDestFormat *r = (RLEDestFormat *) rlebuf; + r->BytesPerPixel = df->BytesPerPixel; + r->Rloss = df->Rloss; + r->Gloss = df->Gloss; + r->Bloss = df->Bloss; + r->Rshift = df->Rshift; + r->Gshift = df->Gshift; + r->Bshift = df->Bshift; + r->Ashift = df->Ashift; + r->Rmask = df->Rmask; + r->Gmask = df->Gmask; + r->Bmask = df->Bmask; + r->Amask = df->Amask; } - dst = rlebuf + sizeof(RLEDestFormat); + dst = rlebuf + sizeof (RLEDestFormat); /* Do the actual encoding */ { - int x, y; - int h = surface->h, w = surface->w; - SDL_PixelFormat *sf = surface->format; - Uint32 *src = (Uint32 *)surface->pixels; - Uint8 *lastline = dst; /* end of last non-blank line */ + int x, y; + int h = surface->h, w = surface->w; + SDL_PixelFormat *sf = surface->format; + Uint32 *src = (Uint32 *) surface->pixels; + Uint8 *lastline = dst; /* end of last non-blank line */ - /* opaque counts are 8 or 16 bits, depending on target depth */ + /* opaque counts are 8 or 16 bits, depending on target depth */ #define ADD_OPAQUE_COUNTS(n, m) \ if(df->BytesPerPixel == 4) { \ ((Uint16 *)dst)[0] = n; \ @@ -1507,119 +1531,124 @@ static int RLEAlphaSurface(SDL_Surface *surface) dst += 2; \ } - /* translucent counts are always 16 bit */ + /* translucent counts are always 16 bit */ #define ADD_TRANSL_COUNTS(n, m) \ (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4) - for(y = 0; y < h; y++) { - int runstart, skipstart; - int blankline = 0; - /* First encode all opaque pixels of a scan line */ - x = 0; - do { - int run, skip, len; - skipstart = x; - while(x < w && !ISOPAQUE(src[x], sf)) - x++; - runstart = x; - while(x < w && ISOPAQUE(src[x], sf)) - x++; - skip = runstart - skipstart; - if(skip == w) - blankline = 1; - run = x - runstart; - while(skip > max_opaque_run) { - ADD_OPAQUE_COUNTS(max_opaque_run, 0); - skip -= max_opaque_run; - } - len = MIN(run, max_opaque_run); - ADD_OPAQUE_COUNTS(skip, len); - dst += copy_opaque(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - while(run) { - len = MIN(run, max_opaque_run); - ADD_OPAQUE_COUNTS(0, len); - dst += copy_opaque(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - } - } while(x < w); - - /* Make sure the next output address is 32-bit aligned */ - dst += (uintptr_t)dst & 2; - - /* Next, encode all translucent pixels of the same scan line */ - x = 0; - do { - int run, skip, len; - skipstart = x; - while(x < w && !ISTRANSL(src[x], sf)) - x++; - runstart = x; - while(x < w && ISTRANSL(src[x], sf)) - x++; - skip = runstart - skipstart; - blankline &= (skip == w); - run = x - runstart; - while(skip > max_transl_run) { - ADD_TRANSL_COUNTS(max_transl_run, 0); - skip -= max_transl_run; - } - len = MIN(run, max_transl_run); - ADD_TRANSL_COUNTS(skip, len); - dst += copy_transl(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - while(run) { - len = MIN(run, max_transl_run); - ADD_TRANSL_COUNTS(0, len); - dst += copy_transl(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - } - if(!blankline) - lastline = dst; - } while(x < w); - - src += surface->pitch >> 2; - } - dst = lastline; /* back up past trailing blank lines */ - ADD_OPAQUE_COUNTS(0, 0); + for (y = 0; y < h; y++) { + int runstart, skipstart; + int blankline = 0; + /* First encode all opaque pixels of a scan line */ + x = 0; + do { + int run, skip, len; + skipstart = x; + while (x < w && !ISOPAQUE (src[x], sf)) + x++; + runstart = x; + while (x < w && ISOPAQUE (src[x], sf)) + x++; + skip = runstart - skipstart; + if (skip == w) + blankline = 1; + run = x - runstart; + while (skip > max_opaque_run) { + ADD_OPAQUE_COUNTS (max_opaque_run, 0); + skip -= max_opaque_run; + } + len = MIN (run, max_opaque_run); + ADD_OPAQUE_COUNTS (skip, len); + dst += copy_opaque (dst, src + runstart, len, sf, df); + runstart += len; + run -= len; + while (run) { + len = MIN (run, max_opaque_run); + ADD_OPAQUE_COUNTS (0, len); + dst += copy_opaque (dst, src + runstart, len, sf, df); + runstart += len; + run -= len; + } + } + while (x < w); + + /* Make sure the next output address is 32-bit aligned */ + dst += (uintptr_t) dst & 2; + + /* Next, encode all translucent pixels of the same scan line */ + x = 0; + do { + int run, skip, len; + skipstart = x; + while (x < w && !ISTRANSL (src[x], sf)) + x++; + runstart = x; + while (x < w && ISTRANSL (src[x], sf)) + x++; + skip = runstart - skipstart; + blankline &= (skip == w); + run = x - runstart; + while (skip > max_transl_run) { + ADD_TRANSL_COUNTS (max_transl_run, 0); + skip -= max_transl_run; + } + len = MIN (run, max_transl_run); + ADD_TRANSL_COUNTS (skip, len); + dst += copy_transl (dst, src + runstart, len, sf, df); + runstart += len; + run -= len; + while (run) { + len = MIN (run, max_transl_run); + ADD_TRANSL_COUNTS (0, len); + dst += copy_transl (dst, src + runstart, len, sf, df); + runstart += len; + run -= len; + } + if (!blankline) + lastline = dst; + } + while (x < w); + + src += surface->pitch >> 2; + } + dst = lastline; /* back up past trailing blank lines */ + ADD_OPAQUE_COUNTS (0, 0); } #undef ADD_OPAQUE_COUNTS #undef ADD_TRANSL_COUNTS /* Now that we have it encoded, release the original pixels */ - if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC - && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { - SDL_free( surface->pixels ); - surface->pixels = NULL; + if ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC + && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { + SDL_free (surface->pixels); + surface->pixels = NULL; } /* realloc the buffer to release unused memory */ { - Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf); - if(!p) - p = rlebuf; - surface->map->sw_data->aux_data = p; + Uint8 *p = SDL_realloc (rlebuf, dst - rlebuf); + if (!p) + p = rlebuf; + surface->map->sw_data->aux_data = p; } return 0; } -static Uint32 getpix_8(Uint8 *srcbuf) +static Uint32 +getpix_8 (Uint8 * srcbuf) { return *srcbuf; } -static Uint32 getpix_16(Uint8 *srcbuf) +static Uint32 +getpix_16 (Uint8 * srcbuf) { - return *(Uint16 *)srcbuf; + return *(Uint16 *) srcbuf; } -static Uint32 getpix_24(Uint8 *srcbuf) +static Uint32 +getpix_24 (Uint8 * srcbuf) { #if SDL_BYTEORDER == SDL_LIL_ENDIAN return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16); @@ -1628,68 +1657,70 @@ static Uint32 getpix_24(Uint8 *srcbuf) #endif } -static Uint32 getpix_32(Uint8 *srcbuf) +static Uint32 +getpix_32 (Uint8 * srcbuf) { - return *(Uint32 *)srcbuf; + return *(Uint32 *) srcbuf; } -typedef Uint32 (*getpix_func)(Uint8 *); +typedef Uint32 (*getpix_func) (Uint8 *); static getpix_func getpixes[4] = { getpix_8, getpix_16, getpix_24, getpix_32 }; -static int RLEColorkeySurface(SDL_Surface *surface) +static int +RLEColorkeySurface (SDL_Surface * surface) { - Uint8 *rlebuf, *dst; - int maxn; - int y; - Uint8 *srcbuf, *curbuf, *lastline; - int maxsize = 0; - int skip, run; - int bpp = surface->format->BytesPerPixel; - getpix_func getpix; - Uint32 ckey, rgbmask; - int w, h; - - /* calculate the worst case size for the compressed surface */ - switch(bpp) { - case 1: - /* worst case is alternating opaque and transparent pixels, - starting with an opaque pixel */ - maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2; - break; - case 2: - case 3: - /* worst case is solid runs, at most 255 pixels wide */ - maxsize = surface->h * (2 * (surface->w / 255 + 1) - + surface->w * bpp) + 2; - break; - case 4: - /* worst case is solid runs, at most 65535 pixels wide */ - maxsize = surface->h * (4 * (surface->w / 65535 + 1) - + surface->w * 4) + 4; - break; - } + Uint8 *rlebuf, *dst; + int maxn; + int y; + Uint8 *srcbuf, *curbuf, *lastline; + int maxsize = 0; + int skip, run; + int bpp = surface->format->BytesPerPixel; + getpix_func getpix; + Uint32 ckey, rgbmask; + int w, h; + + /* calculate the worst case size for the compressed surface */ + switch (bpp) { + case 1: + /* worst case is alternating opaque and transparent pixels, + starting with an opaque pixel */ + maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2; + break; + case 2: + case 3: + /* worst case is solid runs, at most 255 pixels wide */ + maxsize = surface->h * (2 * (surface->w / 255 + 1) + + surface->w * bpp) + 2; + break; + case 4: + /* worst case is solid runs, at most 65535 pixels wide */ + maxsize = surface->h * (4 * (surface->w / 65535 + 1) + + surface->w * 4) + 4; + break; + } - rlebuf = (Uint8 *)SDL_malloc(maxsize); - if ( rlebuf == NULL ) { - SDL_OutOfMemory(); - return(-1); - } + rlebuf = (Uint8 *) SDL_malloc (maxsize); + if (rlebuf == NULL) { + SDL_OutOfMemory (); + return (-1); + } - /* Set up the conversion */ - srcbuf = (Uint8 *)surface->pixels; - curbuf = srcbuf; - maxn = bpp == 4 ? 65535 : 255; - skip = run = 0; - dst = rlebuf; - rgbmask = ~surface->format->Amask; - ckey = surface->format->colorkey & rgbmask; - lastline = dst; - getpix = getpixes[bpp - 1]; - w = surface->w; - h = surface->h; + /* Set up the conversion */ + srcbuf = (Uint8 *) surface->pixels; + curbuf = srcbuf; + maxn = bpp == 4 ? 65535 : 255; + skip = run = 0; + dst = rlebuf; + rgbmask = ~surface->format->Amask; + ckey = surface->format->colorkey & rgbmask; + lastline = dst; + getpix = getpixes[bpp - 1]; + w = surface->w; + h = surface->h; #define ADD_COUNTS(n, m) \ if(bpp == 4) { \ @@ -1702,118 +1733,120 @@ static int RLEColorkeySurface(SDL_Surface *surface) dst += 2; \ } - for(y = 0; y < h; y++) { - int x = 0; - int blankline = 0; - do { - int run, skip, len; - int runstart; - int skipstart = x; - - /* find run of transparent, then opaque pixels */ - while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey) - x++; - runstart = x; - while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey) - x++; - skip = runstart - skipstart; - if(skip == w) - blankline = 1; - run = x - runstart; - - /* encode segment */ - while(skip > maxn) { - ADD_COUNTS(maxn, 0); - skip -= maxn; - } - len = MIN(run, maxn); - ADD_COUNTS(skip, len); - SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp); - dst += len * bpp; - run -= len; - runstart += len; - while(run) { - len = MIN(run, maxn); - ADD_COUNTS(0, len); - SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp); - dst += len * bpp; - runstart += len; - run -= len; - } - if(!blankline) - lastline = dst; - } while(x < w); - - srcbuf += surface->pitch; - } - dst = lastline; /* back up bast trailing blank lines */ - ADD_COUNTS(0, 0); + for (y = 0; y < h; y++) { + int x = 0; + int blankline = 0; + do { + int run, skip, len; + int runstart; + int skipstart = x; + + /* find run of transparent, then opaque pixels */ + while (x < w && (getpix (srcbuf + x * bpp) & rgbmask) == ckey) + x++; + runstart = x; + while (x < w && (getpix (srcbuf + x * bpp) & rgbmask) != ckey) + x++; + skip = runstart - skipstart; + if (skip == w) + blankline = 1; + run = x - runstart; + + /* encode segment */ + while (skip > maxn) { + ADD_COUNTS (maxn, 0); + skip -= maxn; + } + len = MIN (run, maxn); + ADD_COUNTS (skip, len); + SDL_memcpy (dst, srcbuf + runstart * bpp, len * bpp); + dst += len * bpp; + run -= len; + runstart += len; + while (run) { + len = MIN (run, maxn); + ADD_COUNTS (0, len); + SDL_memcpy (dst, srcbuf + runstart * bpp, len * bpp); + dst += len * bpp; + runstart += len; + run -= len; + } + if (!blankline) + lastline = dst; + } + while (x < w); + + srcbuf += surface->pitch; + } + dst = lastline; /* back up bast trailing blank lines */ + ADD_COUNTS (0, 0); #undef ADD_COUNTS - /* Now that we have it encoded, release the original pixels */ - if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC - && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { - SDL_free( surface->pixels ); - surface->pixels = NULL; - } + /* Now that we have it encoded, release the original pixels */ + if ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC + && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { + SDL_free (surface->pixels); + surface->pixels = NULL; + } - /* realloc the buffer to release unused memory */ - { - /* If realloc returns NULL, the original block is left intact */ - Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf); - if(!p) - p = rlebuf; - surface->map->sw_data->aux_data = p; - } + /* realloc the buffer to release unused memory */ + { + /* If realloc returns NULL, the original block is left intact */ + Uint8 *p = SDL_realloc (rlebuf, dst - rlebuf); + if (!p) + p = rlebuf; + surface->map->sw_data->aux_data = p; + } - return(0); + return (0); } -int SDL_RLESurface(SDL_Surface *surface) +int +SDL_RLESurface (SDL_Surface * surface) { - int retcode; + int retcode; - /* Clear any previous RLE conversion */ - if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { - SDL_UnRLESurface(surface, 1); - } + /* Clear any previous RLE conversion */ + if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + SDL_UnRLESurface (surface, 1); + } - /* We don't support RLE encoding of bitmaps */ - if ( surface->format->BitsPerPixel < 8 ) { - return(-1); - } + /* We don't support RLE encoding of bitmaps */ + if (surface->format->BitsPerPixel < 8) { + return (-1); + } - /* Lock the surface if it's in hardware */ - if ( SDL_MUSTLOCK(surface) ) { - if ( SDL_LockSurface(surface) < 0 ) { - return(-1); - } - } + /* Lock the surface if it's in hardware */ + if (SDL_MUSTLOCK (surface)) { + if (SDL_LockSurface (surface) < 0) { + return (-1); + } + } - /* Encode */ - if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { - retcode = RLEColorkeySurface(surface); - } else { - if((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA - && surface->format->Amask != 0) - retcode = RLEAlphaSurface(surface); - else - retcode = -1; /* no RLE for per-surface alpha sans ckey */ - } + /* Encode */ + if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { + retcode = RLEColorkeySurface (surface); + } else { + if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA + && surface->format->Amask != 0) + retcode = RLEAlphaSurface (surface); + else + retcode = -1; /* no RLE for per-surface alpha sans ckey */ + } - /* Unlock the surface if it's in hardware */ - if ( SDL_MUSTLOCK(surface) ) { - SDL_UnlockSurface(surface); - } + /* Unlock the surface if it's in hardware */ + if (SDL_MUSTLOCK (surface)) { + SDL_UnlockSurface (surface); + } - if(retcode < 0) - return -1; + if (retcode < 0) + return -1; - /* The surface is now accelerated */ - surface->flags |= SDL_RLEACCEL; + /* The surface is now accelerated */ + surface->flags |= SDL_RLEACCEL; - return(0); + return (0); } /* @@ -1822,122 +1855,126 @@ int SDL_RLESurface(SDL_Surface *surface) * completely transparent pixels will be lost, and colour and alpha depth * may have been reduced (when encoding for 16bpp targets). */ -static SDL_bool UnRLEAlpha(SDL_Surface *surface) +static SDL_bool +UnRLEAlpha (SDL_Surface * surface) { Uint8 *srcbuf; Uint32 *dst; SDL_PixelFormat *sf = surface->format; RLEDestFormat *df = surface->map->sw_data->aux_data; - int (*uncopy_opaque)(Uint32 *, void *, int, - RLEDestFormat *, SDL_PixelFormat *); - int (*uncopy_transl)(Uint32 *, void *, int, - RLEDestFormat *, SDL_PixelFormat *); + int (*uncopy_opaque) (Uint32 *, void *, int, + RLEDestFormat *, SDL_PixelFormat *); + int (*uncopy_transl) (Uint32 *, void *, int, + RLEDestFormat *, SDL_PixelFormat *); int w = surface->w; int bpp = df->BytesPerPixel; - if(bpp == 2) { - uncopy_opaque = uncopy_opaque_16; - uncopy_transl = uncopy_transl_16; + if (bpp == 2) { + uncopy_opaque = uncopy_opaque_16; + uncopy_transl = uncopy_transl_16; } else { - uncopy_opaque = uncopy_transl = uncopy_32; + uncopy_opaque = uncopy_transl = uncopy_32; } - surface->pixels = SDL_malloc(surface->h * surface->pitch); - if ( !surface->pixels ) { - return(SDL_FALSE); + surface->pixels = SDL_malloc (surface->h * surface->pitch); + if (!surface->pixels) { + return (SDL_FALSE); } /* fill background with transparent pixels */ - SDL_memset(surface->pixels, 0, surface->h * surface->pitch); + SDL_memset (surface->pixels, 0, surface->h * surface->pitch); dst = surface->pixels; - srcbuf = (Uint8 *)(df + 1); - for(;;) { - /* copy opaque pixels */ - int ofs = 0; - do { - unsigned run; - if(bpp == 2) { - ofs += srcbuf[0]; - run = srcbuf[1]; - srcbuf += 2; - } else { - ofs += ((Uint16 *)srcbuf)[0]; - run = ((Uint16 *)srcbuf)[1]; - srcbuf += 4; - } - if(run) { - srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf); - ofs += run; - } else if(!ofs) - return(SDL_TRUE); - } while(ofs < w); - - /* skip padding if needed */ - if(bpp == 2) - srcbuf += (uintptr_t)srcbuf & 2; - - /* copy translucent pixels */ - ofs = 0; - do { - unsigned run; - ofs += ((Uint16 *)srcbuf)[0]; - run = ((Uint16 *)srcbuf)[1]; - srcbuf += 4; - if(run) { - srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf); - ofs += run; - } - } while(ofs < w); - dst += surface->pitch >> 2; + srcbuf = (Uint8 *) (df + 1); + for (;;) { + /* copy opaque pixels */ + int ofs = 0; + do { + unsigned run; + if (bpp == 2) { + ofs += srcbuf[0]; + run = srcbuf[1]; + srcbuf += 2; + } else { + ofs += ((Uint16 *) srcbuf)[0]; + run = ((Uint16 *) srcbuf)[1]; + srcbuf += 4; + } + if (run) { + srcbuf += uncopy_opaque (dst + ofs, srcbuf, run, df, sf); + ofs += run; + } else if (!ofs) + return (SDL_TRUE); + } + while (ofs < w); + + /* skip padding if needed */ + if (bpp == 2) + srcbuf += (uintptr_t) srcbuf & 2; + + /* copy translucent pixels */ + ofs = 0; + do { + unsigned run; + ofs += ((Uint16 *) srcbuf)[0]; + run = ((Uint16 *) srcbuf)[1]; + srcbuf += 4; + if (run) { + srcbuf += uncopy_transl (dst + ofs, srcbuf, run, df, sf); + ofs += run; + } + } + while (ofs < w); + dst += surface->pitch >> 2; } /* Make the compiler happy */ - return(SDL_TRUE); + return (SDL_TRUE); } -void SDL_UnRLESurface(SDL_Surface *surface, int recode) +void +SDL_UnRLESurface (SDL_Surface * surface, int recode) { - if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { - surface->flags &= ~SDL_RLEACCEL; - - if(recode && (surface->flags & SDL_PREALLOC) != SDL_PREALLOC - && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { - if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { - SDL_Rect full; - unsigned alpha_flag; - - /* re-create the original surface */ - surface->pixels = SDL_malloc(surface->h * surface->pitch); - if ( !surface->pixels ) { - /* Oh crap... */ - surface->flags |= SDL_RLEACCEL; - return; - } - - /* fill it with the background colour */ - SDL_FillRect(surface, NULL, surface->format->colorkey); - - /* now render the encoded surface */ - full.x = full.y = 0; - full.w = surface->w; - full.h = surface->h; - alpha_flag = surface->flags & SDL_SRCALPHA; - surface->flags &= ~SDL_SRCALPHA; /* opaque blit */ - SDL_RLEBlit(surface, &full, surface, &full); - surface->flags |= alpha_flag; - } else { - if ( !UnRLEAlpha(surface) ) { - /* Oh crap... */ - surface->flags |= SDL_RLEACCEL; - return; - } - } - } - - if ( surface->map && surface->map->sw_data->aux_data ) { - SDL_free(surface->map->sw_data->aux_data); - surface->map->sw_data->aux_data = NULL; - } + if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + surface->flags &= ~SDL_RLEACCEL; + + if (recode && (surface->flags & SDL_PREALLOC) != SDL_PREALLOC + && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { + if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { + SDL_Rect full; + unsigned alpha_flag; + + /* re-create the original surface */ + surface->pixels = SDL_malloc (surface->h * surface->pitch); + if (!surface->pixels) { + /* Oh crap... */ + surface->flags |= SDL_RLEACCEL; + return; + } + + /* fill it with the background colour */ + SDL_FillRect (surface, NULL, surface->format->colorkey); + + /* now render the encoded surface */ + full.x = full.y = 0; + full.w = surface->w; + full.h = surface->h; + alpha_flag = surface->flags & SDL_SRCALPHA; + surface->flags &= ~SDL_SRCALPHA; /* opaque blit */ + SDL_RLEBlit (surface, &full, surface, &full); + surface->flags |= alpha_flag; + } else { + if (!UnRLEAlpha (surface)) { + /* Oh crap... */ + surface->flags |= SDL_RLEACCEL; + return; + } + } + } + + if (surface->map && surface->map->sw_data->aux_data) { + SDL_free (surface->map->sw_data->aux_data); + surface->map->sw_data->aux_data = NULL; + } } } - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_RLEaccel_c.h b/src/video/SDL_RLEaccel_c.h index ba9d35d3f..cad8ad4c5 100644 --- a/src/video/SDL_RLEaccel_c.h +++ b/src/video/SDL_RLEaccel_c.h @@ -23,9 +23,10 @@ /* Useful functions and variables from SDL_RLEaccel.c */ -extern int SDL_RLESurface(SDL_Surface *surface); -extern int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); -extern int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); -extern void SDL_UnRLESurface(SDL_Surface *surface, int recode); +extern int SDL_RLESurface (SDL_Surface * surface); +extern int SDL_RLEBlit (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect); +extern int SDL_RLEAlphaBlit (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect); +extern void SDL_UnRLESurface (SDL_Surface * surface, int recode); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c index 73922ae01..e9f56f97d 100644 --- a/src/video/SDL_blit.c +++ b/src/video/SDL_blit.c @@ -37,316 +37,308 @@ #endif /* The general purpose software blit routine */ -static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) +static int +SDL_SoftBlit (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect) { - int okay; - int src_locked; - int dst_locked; - - /* Everything is okay at the beginning... */ - okay = 1; - - /* Lock the destination if it's in hardware */ - dst_locked = 0; - if ( SDL_MUSTLOCK(dst) ) { - if ( SDL_LockSurface(dst) < 0 ) { - okay = 0; - } else { - dst_locked = 1; - } - } - /* Lock the source if it's in hardware */ - src_locked = 0; - if ( SDL_MUSTLOCK(src) ) { - if ( SDL_LockSurface(src) < 0 ) { - okay = 0; - } else { - src_locked = 1; - } - } - - /* Set up source and destination buffer pointers, and BLIT! */ - if ( okay && srcrect->w && srcrect->h ) { - SDL_BlitInfo info; - SDL_loblit RunBlit; - - /* Set up the blit information */ - info.s_pixels = (Uint8 *)src->pixels + - (Uint16)srcrect->y*src->pitch + - (Uint16)srcrect->x*src->format->BytesPerPixel; - info.s_width = srcrect->w; - info.s_height = srcrect->h; - info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel; - info.d_pixels = (Uint8 *)dst->pixels + - (Uint16)dstrect->y*dst->pitch + - (Uint16)dstrect->x*dst->format->BytesPerPixel; - info.d_width = dstrect->w; - info.d_height = dstrect->h; - info.d_skip=dst->pitch-info.d_width*dst->format->BytesPerPixel; - info.aux_data = src->map->sw_data->aux_data; - info.src = src->format; - info.table = src->map->table; - info.dst = dst->format; - RunBlit = src->map->sw_data->blit; - - /* Run the actual software blit */ - RunBlit(&info); - } - - /* We need to unlock the surfaces if they're locked */ - if ( dst_locked ) { - SDL_UnlockSurface(dst); - } - if ( src_locked ) { - SDL_UnlockSurface(src); - } - /* Blit is done! */ - return(okay ? 0 : -1); + int okay; + int src_locked; + int dst_locked; + + /* Everything is okay at the beginning... */ + okay = 1; + + /* Lock the destination if it's in hardware */ + dst_locked = 0; + if (SDL_MUSTLOCK (dst)) { + if (SDL_LockSurface (dst) < 0) { + okay = 0; + } else { + dst_locked = 1; + } + } + /* Lock the source if it's in hardware */ + src_locked = 0; + if (SDL_MUSTLOCK (src)) { + if (SDL_LockSurface (src) < 0) { + okay = 0; + } else { + src_locked = 1; + } + } + + /* Set up source and destination buffer pointers, and BLIT! */ + if (okay && srcrect->w && srcrect->h) { + SDL_BlitInfo info; + SDL_loblit RunBlit; + + /* Set up the blit information */ + info.s_pixels = (Uint8 *) src->pixels + + (Uint16) srcrect->y * src->pitch + + (Uint16) srcrect->x * src->format->BytesPerPixel; + info.s_width = srcrect->w; + info.s_height = srcrect->h; + info.s_skip = src->pitch - info.s_width * src->format->BytesPerPixel; + info.d_pixels = (Uint8 *) dst->pixels + + (Uint16) dstrect->y * dst->pitch + + (Uint16) dstrect->x * dst->format->BytesPerPixel; + info.d_width = dstrect->w; + info.d_height = dstrect->h; + info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel; + info.aux_data = src->map->sw_data->aux_data; + info.src = src->format; + info.table = src->map->table; + info.dst = dst->format; + RunBlit = src->map->sw_data->blit; + + /* Run the actual software blit */ + RunBlit (&info); + } + + /* We need to unlock the surfaces if they're locked */ + if (dst_locked) { + SDL_UnlockSurface (dst); + } + if (src_locked) { + SDL_UnlockSurface (src); + } + /* Blit is done! */ + return (okay ? 0 : -1); } #ifdef MMX_ASMBLIT -static __inline__ void SDL_memcpyMMX(Uint8 *to, const Uint8 *from, int len) +static __inline__ void +SDL_memcpyMMX (Uint8 * to, const Uint8 * from, int len) { - int i; - - for(i=0; id_width*info->dst->BytesPerPixel; - h = info->d_height; - src = info->s_pixels; - dst = info->d_pixels; - srcskip = w+info->s_skip; - dstskip = w+info->d_skip; + Uint8 *src, *dst; + int w, h; + int srcskip, dstskip; + + w = info->d_width * info->dst->BytesPerPixel; + h = info->d_height; + src = info->s_pixels; + dst = info->d_pixels; + srcskip = w + info->s_skip; + dstskip = w + info->d_skip; #ifdef MMX_ASMBLIT - if(SDL_HasSSE()) - { - while ( h-- ) { - SDL_memcpySSE(dst, src, w); - src += srcskip; - dst += dstskip; - } - __asm__ __volatile__ ( - " emms\n" - ::); - } - else - if(SDL_HasMMX()) - { - while ( h-- ) { - SDL_memcpyMMX(dst, src, w); - src += srcskip; - dst += dstskip; - } - __asm__ __volatile__ ( - " emms\n" - ::); - } - else + if (SDL_HasSSE ()) { + while (h--) { + SDL_memcpySSE (dst, src, w); + src += srcskip; + dst += dstskip; + } + __asm__ __volatile__ (" emms\n"::); + } else if (SDL_HasMMX ()) { + while (h--) { + SDL_memcpyMMX (dst, src, w); + src += srcskip; + dst += dstskip; + } + __asm__ __volatile__ (" emms\n"::); + } else #endif - while ( h-- ) { - SDL_memcpy(dst, src, w); - src += srcskip; - dst += dstskip; - } + while (h--) { + SDL_memcpy (dst, src, w); + src += srcskip; + dst += dstskip; + } } -static void SDL_BlitCopyOverlap(SDL_BlitInfo *info) +static void +SDL_BlitCopyOverlap (SDL_BlitInfo * info) { - Uint8 *src, *dst; - int w, h; - int srcskip, dstskip; - - w = info->d_width*info->dst->BytesPerPixel; - h = info->d_height; - src = info->s_pixels; - dst = info->d_pixels; - srcskip = w+info->s_skip; - dstskip = w+info->d_skip; - if ( dst < src ) { - while ( h-- ) { - SDL_memcpy(dst, src, w); - src += srcskip; - dst += dstskip; - } - } else { - src += ((h-1) * srcskip); - dst += ((h-1) * dstskip); - while ( h-- ) { - SDL_revcpy(dst, src, w); - src -= srcskip; - dst -= dstskip; - } - } + Uint8 *src, *dst; + int w, h; + int srcskip, dstskip; + + w = info->d_width * info->dst->BytesPerPixel; + h = info->d_height; + src = info->s_pixels; + dst = info->d_pixels; + srcskip = w + info->s_skip; + dstskip = w + info->d_skip; + if (dst < src) { + while (h--) { + SDL_memcpy (dst, src, w); + src += srcskip; + dst += dstskip; + } + } else { + src += ((h - 1) * srcskip); + dst += ((h - 1) * dstskip); + while (h--) { + SDL_revcpy (dst, src, w); + src -= srcskip; + dst -= dstskip; + } + } } /* Figure out which of many blit routines to set up on a surface */ -int SDL_CalculateBlit(SDL_Surface *surface) +int +SDL_CalculateBlit (SDL_Surface * surface) { - int blit_index; - - /* Clean everything out to start */ - if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { - SDL_UnRLESurface(surface, 1); - } - surface->map->sw_blit = NULL; - - /* Figure out if an accelerated hardware blit is possible */ - surface->flags &= ~SDL_HWACCEL; - if ( surface->map->identity ) { - int hw_blit_ok; - - if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { - /* We only support accelerated blitting to hardware */ - if ( surface->map->dst->flags & SDL_HWSURFACE ) { - hw_blit_ok = current_video->info.blit_hw; - } else { - hw_blit_ok = 0; - } - if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { - hw_blit_ok = current_video->info.blit_hw_CC; - } - if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { - hw_blit_ok = current_video->info.blit_hw_A; - } - } else { - /* We only support accelerated blitting to hardware */ - if ( surface->map->dst->flags & SDL_HWSURFACE ) { - hw_blit_ok = current_video->info.blit_sw; - } else { - hw_blit_ok = 0; - } - if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { - hw_blit_ok = current_video->info.blit_sw_CC; - } - if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { - hw_blit_ok = current_video->info.blit_sw_A; - } - } - if ( hw_blit_ok ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->CheckHWBlit(this, surface, surface->map->dst); - } - } - - /* if an alpha pixel format is specified, we can accelerate alpha blits */ - if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )&&(current_video->displayformatalphapixel)) - { - if ( (surface->flags & SDL_SRCALPHA) ) - if ( current_video->info.blit_hw_A ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->CheckHWBlit(this, surface, surface->map->dst); - } - } - - /* Get the blit function index, based on surface mode */ - /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ - blit_index = 0; - blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0; - if ( surface->flags & SDL_SRCALPHA - && (surface->format->alpha != SDL_ALPHA_OPAQUE - || surface->format->Amask) ) { - blit_index |= 2; - } - - /* Check for special "identity" case -- copy blit */ - if ( surface->map->identity && blit_index == 0 ) { - surface->map->sw_data->blit = SDL_BlitCopy; - - /* Handle overlapping blits on the same surface */ - if ( surface == surface->map->dst ) { - surface->map->sw_data->blit = SDL_BlitCopyOverlap; - } - } else { - if ( surface->format->BitsPerPixel < 8 ) { - surface->map->sw_data->blit = - SDL_CalculateBlit0(surface, blit_index); - } else { - switch ( surface->format->BytesPerPixel ) { - case 1: - surface->map->sw_data->blit = - SDL_CalculateBlit1(surface, blit_index); - break; - case 2: - case 3: - case 4: - surface->map->sw_data->blit = - SDL_CalculateBlitN(surface, blit_index); - break; - default: - surface->map->sw_data->blit = NULL; - break; - } - } - } - /* Make sure we have a blit function */ - if ( surface->map->sw_data->blit == NULL ) { - SDL_InvalidateMap(surface->map); - SDL_SetError("Blit combination not supported"); - return(-1); - } - - /* Choose software blitting function */ - if(surface->flags & SDL_RLEACCELOK - && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) { - - if(surface->map->identity - && (blit_index == 1 - || (blit_index == 3 && !surface->format->Amask))) { - if ( SDL_RLESurface(surface) == 0 ) - surface->map->sw_blit = SDL_RLEBlit; - } else if(blit_index == 2 && surface->format->Amask) { - if ( SDL_RLESurface(surface) == 0 ) - surface->map->sw_blit = SDL_RLEAlphaBlit; - } - } - - if ( surface->map->sw_blit == NULL ) { - surface->map->sw_blit = SDL_SoftBlit; - } - return(0); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + const SDL_VideoInfo *info = SDL_GetVideoInfo (); + int blit_index; + + /* Clean everything out to start */ + if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + SDL_UnRLESurface (surface, 1); + } + surface->map->sw_blit = NULL; + + /* Figure out if an accelerated hardware blit is possible */ + surface->flags &= ~SDL_HWACCEL; + if (surface->map->identity) { + int hw_blit_ok; + + if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { + /* We only support accelerated blitting to hardware */ + if (surface->map->dst->flags & SDL_HWSURFACE) { + hw_blit_ok = info->blit_hw; + } else { + hw_blit_ok = 0; + } + if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { + hw_blit_ok = info->blit_hw_CC; + } + if (hw_blit_ok && (surface->flags & SDL_SRCALPHA)) { + hw_blit_ok = info->blit_hw_A; + } + } else { + /* We only support accelerated blitting to hardware */ + if (surface->map->dst->flags & SDL_HWSURFACE) { + hw_blit_ok = info->blit_sw; + } else { + hw_blit_ok = 0; + } + if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { + hw_blit_ok = info->blit_sw_CC; + } + if (hw_blit_ok && (surface->flags & SDL_SRCALPHA)) { + hw_blit_ok = info->blit_sw_A; + } + } + if (hw_blit_ok) { + _this->CheckHWBlit (_this, surface, surface->map->dst); + } + } + + /* if an alpha pixel format is specified, we can accelerate alpha blits */ + if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) + && (_this->displayformatalphapixel)) { + if ((surface->flags & SDL_SRCALPHA)) + if (info->blit_hw_A) { + _this->CheckHWBlit (_this, surface, surface->map->dst); + } + } + + /* Get the blit function index, based on surface mode */ + /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ + blit_index = 0; + blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0; + if (surface->flags & SDL_SRCALPHA + && (surface->format->alpha != SDL_ALPHA_OPAQUE + || surface->format->Amask)) { + blit_index |= 2; + } + + /* Check for special "identity" case -- copy blit */ + if (surface->map->identity && blit_index == 0) { + surface->map->sw_data->blit = SDL_BlitCopy; + + /* Handle overlapping blits on the same surface */ + if (surface == surface->map->dst) { + surface->map->sw_data->blit = SDL_BlitCopyOverlap; + } + } else { + if (surface->format->BitsPerPixel < 8) { + surface->map->sw_data->blit = + SDL_CalculateBlit0 (surface, blit_index); + } else { + switch (surface->format->BytesPerPixel) { + case 1: + surface->map->sw_data->blit = + SDL_CalculateBlit1 (surface, blit_index); + break; + case 2: + case 3: + case 4: + surface->map->sw_data->blit = + SDL_CalculateBlitN (surface, blit_index); + break; + default: + surface->map->sw_data->blit = NULL; + break; + } + } + } + /* Make sure we have a blit function */ + if (surface->map->sw_data->blit == NULL) { + SDL_InvalidateMap (surface->map); + SDL_SetError ("Blit combination not supported"); + return (-1); + } + + /* Choose software blitting function */ + if (surface->flags & SDL_RLEACCELOK + && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) { + + if (surface->map->identity + && (blit_index == 1 + || (blit_index == 3 && !surface->format->Amask))) { + if (SDL_RLESurface (surface) == 0) + surface->map->sw_blit = SDL_RLEBlit; + } else if (blit_index == 2 && surface->format->Amask) { + if (SDL_RLESurface (surface) == 0) + surface->map->sw_blit = SDL_RLEAlphaBlit; + } + } + + if (surface->map->sw_blit == NULL) { + surface->map->sw_blit = SDL_SoftBlit; + } + return (0); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h index 0ef24825d..b5dc4a95e 100644 --- a/src/video/SDL_blit.h +++ b/src/video/SDL_blit.h @@ -27,54 +27,57 @@ #include "SDL_endian.h" /* The structure passed to the low level blit functions */ -typedef struct { - Uint8 *s_pixels; - int s_width; - int s_height; - int s_skip; - Uint8 *d_pixels; - int d_width; - int d_height; - int d_skip; - void *aux_data; - SDL_PixelFormat *src; - Uint8 *table; - SDL_PixelFormat *dst; +typedef struct +{ + Uint8 *s_pixels; + int s_width; + int s_height; + int s_skip; + Uint8 *d_pixels; + int d_width; + int d_height; + int d_skip; + void *aux_data; + SDL_PixelFormat *src; + Uint8 *table; + SDL_PixelFormat *dst; } SDL_BlitInfo; /* The type definition for the low level blit functions */ -typedef void (*SDL_loblit)(SDL_BlitInfo *info); +typedef void (*SDL_loblit) (SDL_BlitInfo * info); /* This is the private info structure for software accelerated blits */ -struct private_swaccel { - SDL_loblit blit; - void *aux_data; +struct private_swaccel +{ + SDL_loblit blit; + void *aux_data; }; /* Blit mapping definition */ -typedef struct SDL_BlitMap { - SDL_Surface *dst; - int identity; - Uint8 *table; - SDL_blit hw_blit; - SDL_blit sw_blit; - struct private_hwaccel *hw_data; - struct private_swaccel *sw_data; - - /* the version count matches the destination; mismatch indicates - an invalid mapping */ - unsigned int format_version; +typedef struct SDL_BlitMap +{ + SDL_Surface *dst; + int identity; + Uint8 *table; + SDL_blit hw_blit; + SDL_blit sw_blit; + struct private_hwaccel *hw_data; + struct private_swaccel *sw_data; + + /* the version count matches the destination; mismatch indicates + an invalid mapping */ + unsigned int format_version; } SDL_BlitMap; /* Functions found in SDL_blit.c */ -extern int SDL_CalculateBlit(SDL_Surface *surface); +extern int SDL_CalculateBlit (SDL_Surface * surface); /* Functions found in SDL_blit_{0,1,N,A}.c */ -extern SDL_loblit SDL_CalculateBlit0(SDL_Surface *surface, int complex); -extern SDL_loblit SDL_CalculateBlit1(SDL_Surface *surface, int complex); -extern SDL_loblit SDL_CalculateBlitN(SDL_Surface *surface, int complex); -extern SDL_loblit SDL_CalculateAlphaBlit(SDL_Surface *surface, int complex); +extern SDL_loblit SDL_CalculateBlit0 (SDL_Surface * surface, int complex); +extern SDL_loblit SDL_CalculateBlit1 (SDL_Surface * surface, int complex); +extern SDL_loblit SDL_CalculateBlitN (SDL_Surface * surface, int complex); +extern SDL_loblit SDL_CalculateAlphaBlit (SDL_Surface * surface, int complex); /* * Useful macros for blitting routines @@ -520,3 +523,4 @@ do { \ #endif #endif /* _SDL_blit_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index 7cab3dfe4..94692747d 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -26,446 +26,456 @@ /* Functions to blit from bitmaps to other surfaces */ -static void BlitBto1(SDL_BlitInfo *info) +static void +BlitBto1 (SDL_BlitInfo * info) { - int c; - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = info->d_pixels; - dstskip = info->d_skip; - map = info->table; - srcskip += width-(width+7)/8; - - if ( map ) { - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( 1 ) { - *dst = map[bit]; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( 1 ) { - *dst = bit; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } + int c; + int width, height; + Uint8 *src, *map, *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = info->d_pixels; + dstskip = info->d_skip; + map = info->table; + srcskip += width - (width + 7) / 8; + + if (map) { + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (1) { + *dst = map[bit]; + } + dst++; + byte <<= 1; + } + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (1) { + *dst = bit; + } + dst++; + byte <<= 1; + } + src += srcskip; + dst += dstskip; + } + } } -static void BlitBto2(SDL_BlitInfo *info) +static void +BlitBto2 (SDL_BlitInfo * info) { - int c; - int width, height; - Uint8 *src; - Uint16 *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = (Uint16 *)info->d_pixels; - dstskip = info->d_skip/2; - map = (Uint16 *)info->table; - srcskip += width-(width+7)/8; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( 1 ) { - *dst = map[bit]; - } - byte <<= 1; - dst++; - } - src += srcskip; - dst += dstskip; - } + int c; + int width, height; + Uint8 *src; + Uint16 *map, *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = (Uint16 *) info->d_pixels; + dstskip = info->d_skip / 2; + map = (Uint16 *) info->table; + srcskip += width - (width + 7) / 8; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (1) { + *dst = map[bit]; + } + byte <<= 1; + dst++; + } + src += srcskip; + dst += dstskip; + } } -static void BlitBto3(SDL_BlitInfo *info) +static void +BlitBto3 (SDL_BlitInfo * info) { - int c, o; - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = info->d_pixels; - dstskip = info->d_skip; - map = info->table; - srcskip += width-(width+7)/8; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( 1 ) { - o = bit * 4; - dst[0] = map[o++]; - dst[1] = map[o++]; - dst[2] = map[o++]; - } - byte <<= 1; - dst += 3; - } - src += srcskip; - dst += dstskip; - } + int c, o; + int width, height; + Uint8 *src, *map, *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = info->d_pixels; + dstskip = info->d_skip; + map = info->table; + srcskip += width - (width + 7) / 8; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (1) { + o = bit * 4; + dst[0] = map[o++]; + dst[1] = map[o++]; + dst[2] = map[o++]; + } + byte <<= 1; + dst += 3; + } + src += srcskip; + dst += dstskip; + } } -static void BlitBto4(SDL_BlitInfo *info) +static void +BlitBto4 (SDL_BlitInfo * info) { - int width, height; - Uint8 *src; - Uint32 *map, *dst; - int srcskip, dstskip; - int c; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = (Uint32 *)info->d_pixels; - dstskip = info->d_skip/4; - map = (Uint32 *)info->table; - srcskip += width-(width+7)/8; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( 1 ) { - *dst = map[bit]; - } - byte <<= 1; - dst++; - } - src += srcskip; - dst += dstskip; - } + int width, height; + Uint8 *src; + Uint32 *map, *dst; + int srcskip, dstskip; + int c; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = (Uint32 *) info->d_pixels; + dstskip = info->d_skip / 4; + map = (Uint32 *) info->table; + srcskip += width - (width + 7) / 8; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (1) { + *dst = map[bit]; + } + byte <<= 1; + dst++; + } + src += srcskip; + dst += dstskip; + } } -static void BlitBto1Key(SDL_BlitInfo *info) +static void +BlitBto1Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - Uint8 *dst = info->d_pixels; - int srcskip = info->s_skip; - int dstskip = info->d_skip; - Uint32 ckey = info->src->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width-(width+7)/8; - - if ( palmap ) { - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( bit != ckey ) { - *dst = palmap[bit]; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( bit != ckey ) { - *dst = bit; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + Uint8 *dst = info->d_pixels; + int srcskip = info->s_skip; + int dstskip = info->d_skip; + Uint32 ckey = info->src->colorkey; + Uint8 *palmap = info->table; + int c; + + /* Set up some basic variables */ + srcskip += width - (width + 7) / 8; + + if (palmap) { + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (bit != ckey) { + *dst = palmap[bit]; + } + dst++; + byte <<= 1; + } + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (bit != ckey) { + *dst = bit; + } + dst++; + byte <<= 1; + } + src += srcskip; + dst += dstskip; + } + } } -static void BlitBto2Key(SDL_BlitInfo *info) +static void +BlitBto2Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int srcskip = info->s_skip; - int dstskip = info->d_skip; - Uint32 ckey = info->src->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width-(width+7)/8; - dstskip /= 2; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( bit != ckey ) { - *dstp=((Uint16 *)palmap)[bit]; - } - byte <<= 1; - dstp++; - } - src += srcskip; - dstp += dstskip; - } + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int srcskip = info->s_skip; + int dstskip = info->d_skip; + Uint32 ckey = info->src->colorkey; + Uint8 *palmap = info->table; + int c; + + /* Set up some basic variables */ + srcskip += width - (width + 7) / 8; + dstskip /= 2; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (bit != ckey) { + *dstp = ((Uint16 *) palmap)[bit]; + } + byte <<= 1; + dstp++; + } + src += srcskip; + dstp += dstskip; + } } -static void BlitBto3Key(SDL_BlitInfo *info) +static void +BlitBto3Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - Uint8 *dst = info->d_pixels; - int srcskip = info->s_skip; - int dstskip = info->d_skip; - Uint32 ckey = info->src->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width-(width+7)/8; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( bit != ckey ) { - SDL_memcpy(dst, &palmap[bit*4], 3); - } - byte <<= 1; - dst += 3; - } - src += srcskip; - dst += dstskip; - } + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + Uint8 *dst = info->d_pixels; + int srcskip = info->s_skip; + int dstskip = info->d_skip; + Uint32 ckey = info->src->colorkey; + Uint8 *palmap = info->table; + int c; + + /* Set up some basic variables */ + srcskip += width - (width + 7) / 8; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (bit != ckey) { + SDL_memcpy (dst, &palmap[bit * 4], 3); + } + byte <<= 1; + dst += 3; + } + src += srcskip; + dst += dstskip; + } } -static void BlitBto4Key(SDL_BlitInfo *info) +static void +BlitBto4Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int srcskip = info->s_skip; - int dstskip = info->d_skip; - Uint32 ckey = info->src->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width-(width+7)/8; - dstskip /= 4; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( bit != ckey ) { - *dstp=((Uint32 *)palmap)[bit]; - } - byte <<= 1; - dstp++; - } - src += srcskip; - dstp += dstskip; - } + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int srcskip = info->s_skip; + int dstskip = info->d_skip; + Uint32 ckey = info->src->colorkey; + Uint8 *palmap = info->table; + int c; + + /* Set up some basic variables */ + srcskip += width - (width + 7) / 8; + dstskip /= 4; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (bit != ckey) { + *dstp = ((Uint32 *) palmap)[bit]; + } + byte <<= 1; + dstp++; + } + src += srcskip; + dstp += dstskip; + } } -static void BlitBtoNAlpha(SDL_BlitInfo *info) +static void +BlitBtoNAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - Uint8 *dst = info->d_pixels; - int srcskip = info->s_skip; - int dstskip = info->d_skip; - const SDL_Color *srcpal = info->src->palette->colors; - SDL_PixelFormat *dstfmt = info->dst; - int dstbpp; - int c; - const int A = info->src->alpha; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - srcskip += width-(width+7)/8; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( 1 ) { - Uint32 pixel; - unsigned sR, sG, sB; - unsigned dR, dG, dB; - sR = srcpal[bit].r; - sG = srcpal[bit].g; - sB = srcpal[bit].b; - DISEMBLE_RGB(dst, dstbpp, dstfmt, - pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB); - } - byte <<= 1; - dst += dstbpp; - } - src += srcskip; - dst += dstskip; - } + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + Uint8 *dst = info->d_pixels; + int srcskip = info->s_skip; + int dstskip = info->d_skip; + const SDL_Color *srcpal = info->src->palette->colors; + SDL_PixelFormat *dstfmt = info->dst; + int dstbpp; + int c; + const int A = info->src->alpha; + + /* Set up some basic variables */ + dstbpp = dstfmt->BytesPerPixel; + srcskip += width - (width + 7) / 8; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (1) { + Uint32 pixel; + unsigned sR, sG, sB; + unsigned dR, dG, dB; + sR = srcpal[bit].r; + sG = srcpal[bit].g; + sB = srcpal[bit].b; + DISEMBLE_RGB (dst, dstbpp, dstfmt, pixel, dR, dG, dB); + ALPHA_BLEND (sR, sG, sB, A, dR, dG, dB); + ASSEMBLE_RGB (dst, dstbpp, dstfmt, dR, dG, dB); + } + byte <<= 1; + dst += dstbpp; + } + src += srcskip; + dst += dstskip; + } } -static void BlitBtoNAlphaKey(SDL_BlitInfo *info) +static void +BlitBtoNAlphaKey (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - Uint8 *dst = info->d_pixels; - int srcskip = info->s_skip; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - const SDL_Color *srcpal = srcfmt->palette->colors; - int dstbpp; - int c; - const int A = srcfmt->alpha; - Uint32 ckey = srcfmt->colorkey; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - srcskip += width-(width+7)/8; - - while ( height-- ) { - Uint8 byte = 0, bit; - for ( c=0; c>7; - if ( bit != ckey ) { - int sR, sG, sB; - int dR, dG, dB; - Uint32 pixel; - sR = srcpal[bit].r; - sG = srcpal[bit].g; - sB = srcpal[bit].b; - DISEMBLE_RGB(dst, dstbpp, dstfmt, - pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB); - } - byte <<= 1; - dst += dstbpp; - } - src += srcskip; - dst += dstskip; - } + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + Uint8 *dst = info->d_pixels; + int srcskip = info->s_skip; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + const SDL_Color *srcpal = srcfmt->palette->colors; + int dstbpp; + int c; + const int A = srcfmt->alpha; + Uint32 ckey = srcfmt->colorkey; + + /* Set up some basic variables */ + dstbpp = dstfmt->BytesPerPixel; + srcskip += width - (width + 7) / 8; + + while (height--) { + Uint8 byte = 0, bit; + for (c = 0; c < width; ++c) { + if ((c & 7) == 0) { + byte = *src++; + } + bit = (byte & 0x80) >> 7; + if (bit != ckey) { + int sR, sG, sB; + int dR, dG, dB; + Uint32 pixel; + sR = srcpal[bit].r; + sG = srcpal[bit].g; + sB = srcpal[bit].b; + DISEMBLE_RGB (dst, dstbpp, dstfmt, pixel, dR, dG, dB); + ALPHA_BLEND (sR, sG, sB, A, dR, dG, dB); + ASSEMBLE_RGB (dst, dstbpp, dstfmt, dR, dG, dB); + } + byte <<= 1; + dst += dstbpp; + } + src += srcskip; + dst += dstskip; + } } static SDL_loblit bitmap_blit[] = { - NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 + NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 }; static SDL_loblit colorkey_blit[] = { NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key }; -SDL_loblit SDL_CalculateBlit0(SDL_Surface *surface, int blit_index) +SDL_loblit +SDL_CalculateBlit0 (SDL_Surface * surface, int blit_index) { - int which; - - if ( surface->format->BitsPerPixel != 1 ) { - /* We don't support sub 8-bit packed pixel modes */ - return NULL; - } - if ( surface->map->dst->format->BitsPerPixel < 8 ) { - which = 0; - } else { - which = surface->map->dst->format->BytesPerPixel; - } - switch(blit_index) { - case 0: /* copy */ - return bitmap_blit[which]; - - case 1: /* colorkey */ - return colorkey_blit[which]; - - case 2: /* alpha */ - return which >= 2 ? BlitBtoNAlpha : NULL; - - case 4: /* alpha + colorkey */ - return which >= 2 ? BlitBtoNAlphaKey : NULL; - } - return NULL; + int which; + + if (surface->format->BitsPerPixel != 1) { + /* We don't support sub 8-bit packed pixel modes */ + return NULL; + } + if (surface->map->dst->format->BitsPerPixel < 8) { + which = 0; + } else { + which = surface->map->dst->format->BytesPerPixel; + } + switch (blit_index) { + case 0: /* copy */ + return bitmap_blit[which]; + + case 1: /* colorkey */ + return colorkey_blit[which]; + + case 2: /* alpha */ + return which >= 2 ? BlitBtoNAlpha : NULL; + + case 4: /* alpha + colorkey */ + return which >= 2 ? BlitBtoNAlphaKey : NULL; + } + return NULL; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index d31126b26..b5d370ff1 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -28,26 +28,28 @@ /* Functions to blit from 8-bit surfaces to other surfaces */ -static void Blit1to1(SDL_BlitInfo *info) +static void +Blit1to1 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = info->d_pixels; - dstskip = info->d_skip; - map = info->table; - - while ( height-- ) { + int width, height; + Uint8 *src, *map, *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = info->d_pixels; + dstskip = info->d_skip; + map = info->table; + + while (height--) { #ifdef USE_DUFFS_LOOP + /* *INDENT-OFF* */ DUFFS_LOOP( { *dst = map[*src]; @@ -55,17 +57,19 @@ static void Blit1to1(SDL_BlitInfo *info) dst++; src++; , width); + /* *INDENT-ON* */ #else - for ( c=width; c; --c ) { - *dst = map[*src]; - dst++; - src++; - } + for (c = width; c; --c) { + *dst = map[*src]; + dst++; + src++; + } #endif - src += srcskip; - dst += dstskip; - } + src += srcskip; + dst += dstskip; + } } + /* This is now endian dependent */ #if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) #define HI 1 @@ -74,136 +78,135 @@ static void Blit1to1(SDL_BlitInfo *info) #define HI 0 #define LO 1 #endif -static void Blit1to2(SDL_BlitInfo *info) +static void +Blit1to2 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint8 *src, *dst; - Uint16 *map; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = info->d_pixels; - dstskip = info->d_skip; - map = (Uint16 *)info->table; + int width, height; + Uint8 *src, *dst; + Uint16 *map; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = info->d_pixels; + dstskip = info->d_skip; + map = (Uint16 *) info->table; #ifdef USE_DUFFS_LOOP - while ( height-- ) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { *(Uint16 *)dst = map[*src++]; dst += 2; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } #else - /* Memory align at 4-byte boundary, if necessary */ - if ( (long)dst & 0x03 ) { - /* Don't do anything if width is 0 */ - if ( width == 0 ) { - return; - } - --width; - - while ( height-- ) { - /* Perform copy alignment */ - *(Uint16 *)dst = map[*src++]; - dst += 2; - - /* Copy in 4 pixel chunks */ - for ( c=width/4; c; --c ) { - *(Uint32 *)dst = - (map[src[HI]]<<16)|(map[src[LO]]); - src += 2; - dst += 4; - *(Uint32 *)dst = - (map[src[HI]]<<16)|(map[src[LO]]); - src += 2; - dst += 4; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - *(Uint16 *)dst = map[*src++]; - dst += 2; - case 2: - *(Uint32 *)dst = - (map[src[HI]]<<16)|(map[src[LO]]); - src += 2; - dst += 4; - break; - case 1: - *(Uint16 *)dst = map[*src++]; - dst += 2; - break; - } - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { - /* Copy in 4 pixel chunks */ - for ( c=width/4; c; --c ) { - *(Uint32 *)dst = - (map[src[HI]]<<16)|(map[src[LO]]); - src += 2; - dst += 4; - *(Uint32 *)dst = - (map[src[HI]]<<16)|(map[src[LO]]); - src += 2; - dst += 4; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - *(Uint16 *)dst = map[*src++]; - dst += 2; - case 2: - *(Uint32 *)dst = - (map[src[HI]]<<16)|(map[src[LO]]); - src += 2; - dst += 4; - break; - case 1: - *(Uint16 *)dst = map[*src++]; - dst += 2; - break; - } - src += srcskip; - dst += dstskip; - } - } + /* Memory align at 4-byte boundary, if necessary */ + if ((long) dst & 0x03) { + /* Don't do anything if width is 0 */ + if (width == 0) { + return; + } + --width; + + while (height--) { + /* Perform copy alignment */ + *(Uint16 *) dst = map[*src++]; + dst += 2; + + /* Copy in 4 pixel chunks */ + for (c = width / 4; c; --c) { + *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); + src += 2; + dst += 4; + *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); + src += 2; + dst += 4; + } + /* Get any leftovers */ + switch (width & 3) { + case 3: + *(Uint16 *) dst = map[*src++]; + dst += 2; + case 2: + *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); + src += 2; + dst += 4; + break; + case 1: + *(Uint16 *) dst = map[*src++]; + dst += 2; + break; + } + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { + /* Copy in 4 pixel chunks */ + for (c = width / 4; c; --c) { + *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); + src += 2; + dst += 4; + *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); + src += 2; + dst += 4; + } + /* Get any leftovers */ + switch (width & 3) { + case 3: + *(Uint16 *) dst = map[*src++]; + dst += 2; + case 2: + *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); + src += 2; + dst += 4; + break; + case 1: + *(Uint16 *) dst = map[*src++]; + dst += 2; + break; + } + src += srcskip; + dst += dstskip; + } + } #endif /* USE_DUFFS_LOOP */ } -static void Blit1to3(SDL_BlitInfo *info) +static void +Blit1to3 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int o; - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = info->d_pixels; - dstskip = info->d_skip; - map = info->table; - - while ( height-- ) { + int o; + int width, height; + Uint8 *src, *map, *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = info->d_pixels; + dstskip = info->d_skip; + map = info->table; + + while (height--) { #ifdef USE_DUFFS_LOOP + /* *INDENT-OFF* */ DUFFS_LOOP( { o = *src * 4; @@ -214,78 +217,84 @@ static void Blit1to3(SDL_BlitInfo *info) src++; dst += 3; , width); + /* *INDENT-ON* */ #else - for ( c=width; c; --c ) { - o = *src * 4; - dst[0] = map[o++]; - dst[1] = map[o++]; - dst[2] = map[o++]; - src++; - dst += 3; - } + for (c = width; c; --c) { + o = *src * 4; + dst[0] = map[o++]; + dst[1] = map[o++]; + dst[2] = map[o++]; + src++; + dst += 3; + } #endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } + src += srcskip; + dst += dstskip; + } } -static void Blit1to4(SDL_BlitInfo *info) +static void +Blit1to4 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint8 *src; - Uint32 *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = (Uint32 *)info->d_pixels; - dstskip = info->d_skip/4; - map = (Uint32 *)info->table; - - while ( height-- ) { + int width, height; + Uint8 *src; + Uint32 *map, *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = (Uint32 *) info->d_pixels; + dstskip = info->d_skip / 4; + map = (Uint32 *) info->table; + + while (height--) { #ifdef USE_DUFFS_LOOP + /* *INDENT-OFF* */ DUFFS_LOOP( *dst++ = map[*src++]; , width); + /* *INDENT-ON* */ #else - for ( c=width/4; c; --c ) { - *dst++ = map[*src++]; - *dst++ = map[*src++]; - *dst++ = map[*src++]; - *dst++ = map[*src++]; - } - switch ( width & 3 ) { - case 3: - *dst++ = map[*src++]; - case 2: - *dst++ = map[*src++]; - case 1: - *dst++ = map[*src++]; - } + for (c = width / 4; c; --c) { + *dst++ = map[*src++]; + *dst++ = map[*src++]; + *dst++ = map[*src++]; + *dst++ = map[*src++]; + } + switch (width & 3) { + case 3: + *dst++ = map[*src++]; + case 2: + *dst++ = map[*src++]; + case 1: + *dst++ = map[*src++]; + } #endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } + src += srcskip; + dst += dstskip; + } } -static void Blit1to1Key(SDL_BlitInfo *info) +static void +Blit1to1Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - Uint8 *palmap = info->table; - Uint32 ckey = info->src->colorkey; - - if ( palmap ) { - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + Uint8 *palmap = info->table; + Uint32 ckey = info->src->colorkey; + + if (palmap) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { @@ -295,11 +304,13 @@ static void Blit1to1Key(SDL_BlitInfo *info) src++; }, width); - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { @@ -309,27 +320,30 @@ static void Blit1to1Key(SDL_BlitInfo *info) src++; }, width); - src += srcskip; - dst += dstskip; - } - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } + } } -static void Blit1to2Key(SDL_BlitInfo *info) +static void +Blit1to2Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip; - Uint16 *palmap = (Uint16 *)info->table; - Uint32 ckey = info->src->colorkey; - - /* Set up some basic variables */ - dstskip /= 2; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip; + Uint16 *palmap = (Uint16 *) info->table; + Uint32 ckey = info->src->colorkey; + + /* Set up some basic variables */ + dstskip /= 2; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { @@ -339,24 +353,27 @@ static void Blit1to2Key(SDL_BlitInfo *info) dstp++; }, width); - src += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dstp += dstskip; + } } -static void Blit1to3Key(SDL_BlitInfo *info) +static void +Blit1to3Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - Uint8 *palmap = info->table; - Uint32 ckey = info->src->colorkey; - int o; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + Uint8 *palmap = info->table; + Uint32 ckey = info->src->colorkey; + int o; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { @@ -369,26 +386,29 @@ static void Blit1to3Key(SDL_BlitInfo *info) dst += 3; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } -static void Blit1to4Key(SDL_BlitInfo *info) +static void +Blit1to4Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip; - Uint32 *palmap = (Uint32 *)info->table; - Uint32 ckey = info->src->colorkey; - - /* Set up some basic variables */ - dstskip /= 4; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip; + Uint32 *palmap = (Uint32 *) info->table; + Uint32 ckey = info->src->colorkey; + + /* Set up some basic variables */ + dstskip /= 4; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { @@ -398,30 +418,33 @@ static void Blit1to4Key(SDL_BlitInfo *info) dstp++; }, width); - src += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dstp += dstskip; + } } -static void Blit1toNAlpha(SDL_BlitInfo *info) +static void +Blit1toNAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *dstfmt = info->dst; - const SDL_Color *srcpal = info->src->palette->colors; - int dstbpp; - const int A = info->src->alpha; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - - while ( height-- ) { - int sR, sG, sB; - int dR, dG, dB; + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *dstfmt = info->dst; + const SDL_Color *srcpal = info->src->palette->colors; + int dstbpp; + const int A = info->src->alpha; + + /* Set up some basic variables */ + dstbpp = dstfmt->BytesPerPixel; + + while (height--) { + int sR, sG, sB; + int dR, dG, dB; + /* *INDENT-OFF* */ DUFFS_LOOP4( { Uint32 pixel; @@ -436,32 +459,35 @@ static void Blit1toNAlpha(SDL_BlitInfo *info) dst += dstbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } -static void Blit1toNAlphaKey(SDL_BlitInfo *info) +static void +Blit1toNAlphaKey (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - const SDL_Color *srcpal = info->src->palette->colors; - Uint32 ckey = srcfmt->colorkey; - int dstbpp; - const int A = srcfmt->alpha; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - - while ( height-- ) { - int sR, sG, sB; - int dR, dG, dB; + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + const SDL_Color *srcpal = info->src->palette->colors; + Uint32 ckey = srcfmt->colorkey; + int dstbpp; + const int A = srcfmt->alpha; + + /* Set up some basic variables */ + dstbpp = dstfmt->BytesPerPixel; + + while (height--) { + int sR, sG, sB; + int dR, dG, dB; + /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { @@ -478,46 +504,50 @@ static void Blit1toNAlphaKey(SDL_BlitInfo *info) dst += dstbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } static SDL_loblit one_blit[] = { - NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 + NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 }; static SDL_loblit one_blitkey[] = { - NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key + NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key }; -SDL_loblit SDL_CalculateBlit1(SDL_Surface *surface, int blit_index) +SDL_loblit +SDL_CalculateBlit1 (SDL_Surface * surface, int blit_index) { - int which; - SDL_PixelFormat *dstfmt; - - dstfmt = surface->map->dst->format; - if ( dstfmt->BitsPerPixel < 8 ) { - which = 0; - } else { - which = dstfmt->BytesPerPixel; - } - switch(blit_index) { - case 0: /* copy */ - return one_blit[which]; - - case 1: /* colorkey */ - return one_blitkey[which]; - - case 2: /* alpha */ - /* Supporting 8bpp->8bpp alpha is doable but requires lots of - tables which consume space and takes time to precompute, - so is better left to the user */ - return which >= 2 ? Blit1toNAlpha : NULL; - - case 3: /* alpha + colorkey */ - return which >= 2 ? Blit1toNAlphaKey : NULL; - - } - return NULL; + int which; + SDL_PixelFormat *dstfmt; + + dstfmt = surface->map->dst->format; + if (dstfmt->BitsPerPixel < 8) { + which = 0; + } else { + which = dstfmt->BytesPerPixel; + } + switch (blit_index) { + case 0: /* copy */ + return one_blit[which]; + + case 1: /* colorkey */ + return one_blitkey[which]; + + case 2: /* alpha */ + /* Supporting 8bpp->8bpp alpha is doable but requires lots of + tables which consume space and takes time to precompute, + so is better left to the user */ + return which >= 2 ? Blit1toNAlpha : NULL; + + case 3: /* alpha + colorkey */ + return which >= 2 ? Blit1toNAlphaKey : NULL; + + } + return NULL; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_A.c b/src/video/SDL_blit_A.c index 71109a27a..1bc46f911 100644 --- a/src/video/SDL_blit_A.c +++ b/src/video/SDL_blit_A.c @@ -46,22 +46,24 @@ /* Functions to perform alpha blended blitting */ /* N->1 blending with per-surface alpha */ -static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info) +static void +BlitNto1SurfaceAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - int srcbpp = srcfmt->BytesPerPixel; - - const unsigned A = srcfmt->alpha; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + Uint8 *palmap = info->table; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + int srcbpp = srcfmt->BytesPerPixel; + + const unsigned A = srcfmt->alpha; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4( { Uint32 Pixel; @@ -93,27 +95,30 @@ static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } /* N->1 blending with pixel alpha */ -static void BlitNto1PixelAlpha(SDL_BlitInfo *info) +static void +BlitNto1PixelAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - int srcbpp = srcfmt->BytesPerPixel; - - /* FIXME: fix alpha bit field expansion here too? */ - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + Uint8 *palmap = info->table; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + int srcbpp = srcfmt->BytesPerPixel; + + /* FIXME: fix alpha bit field expansion here too? */ + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4( { Uint32 Pixel; @@ -146,29 +151,32 @@ static void BlitNto1PixelAlpha(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } /* colorkeyed N->1 blending with per-surface alpha */ -static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info) +static void +BlitNto1SurfaceAlphaKey (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - int srcbpp = srcfmt->BytesPerPixel; - Uint32 ckey = srcfmt->colorkey; - - const int A = srcfmt->alpha; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + Uint8 *palmap = info->table; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + int srcbpp = srcfmt->BytesPerPixel; + Uint32 ckey = srcfmt->colorkey; + + const int A = srcfmt->alpha; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 Pixel; @@ -202,31 +210,34 @@ static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } #if GCC_ASMBLIT /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */ -static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info) +static void +BlitRGBtoRGBSurfaceAlpha128MMX (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - Uint32 dalpha = info->dst->Amask; - Uint8 load[8]; - - *(Uint64 *)load = 0x00fefefe00fefefeULL;/* alpha128 mask */ - movq_m2r(*load, mm4); /* alpha128 mask -> mm4 */ - *(Uint64 *)load = 0x0001010100010101ULL;/* !alpha128 mask */ - movq_m2r(*load, mm3); /* !alpha128 mask -> mm3 */ - movd_m2r(dalpha, mm7); /* dst alpha mask */ - punpckldq_r2r(mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */ - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + Uint32 dalpha = info->dst->Amask; + Uint8 load[8]; + + *(Uint64 *) load = 0x00fefefe00fefefeULL; /* alpha128 mask */ + movq_m2r (*load, mm4); /* alpha128 mask -> mm4 */ + *(Uint64 *) load = 0x0001010100010101ULL; /* !alpha128 mask */ + movq_m2r (*load, mm3); /* !alpha128 mask -> mm3 */ + movd_m2r (dalpha, mm7); /* dst alpha mask */ + punpckldq_r2r (mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */ + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP_DOUBLE2( { Uint32 s = *srcp++; @@ -253,43 +264,48 @@ static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info) dstp += 2; srcp += 2; }, width); - srcp += srcskip; - dstp += dstskip; - } - emms(); + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + emms (); } /* fast RGB888->(A)RGB888 blending with surface alpha */ -static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info) +static void +BlitRGBtoRGBSurfaceAlphaMMX (SDL_BlitInfo * info) { - SDL_PixelFormat* df = info->dst; - unsigned alpha = info->src->alpha; - - if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) { - /* only call a128 version when R,G,B occupy lower bits */ - BlitRGBtoRGBSurfaceAlpha128MMX(info); - } else { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - - pxor_r2r(mm5, mm5); /* 0 -> mm5 */ - /* form the alpha mult */ - movd_m2r(alpha, mm4); /* 0000000A -> mm4 */ - punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */ - punpckldq_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */ - alpha = (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->Bshift); - movd_m2r(alpha, mm0); /* 00000FFF -> mm0 */ - punpcklbw_r2r(mm0, mm0); /* 00FFFFFF -> mm0 */ - pand_r2r(mm0, mm4); /* 0A0A0A0A -> mm4, minus 1 chan */ - /* at this point mm4 can be 000A0A0A or 0A0A0A00 or another combo */ - movd_m2r(df->Amask, mm7); /* dst alpha mask */ - punpckldq_r2r(mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */ - - while(height--) { + SDL_PixelFormat *df = info->dst; + unsigned alpha = info->src->alpha; + + if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) { + /* only call a128 version when R,G,B occupy lower bits */ + BlitRGBtoRGBSurfaceAlpha128MMX (info); + } else { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + + pxor_r2r (mm5, mm5); /* 0 -> mm5 */ + /* form the alpha mult */ + movd_m2r (alpha, mm4); /* 0000000A -> mm4 */ + punpcklwd_r2r (mm4, mm4); /* 00000A0A -> mm4 */ + punpckldq_r2r (mm4, mm4); /* 0A0A0A0A -> mm4 */ + alpha = + (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df-> + Bshift); + movd_m2r (alpha, mm0); /* 00000FFF -> mm0 */ + punpcklbw_r2r (mm0, mm0); /* 00FFFFFF -> mm0 */ + pand_r2r (mm0, mm4); /* 0A0A0A0A -> mm4, minus 1 chan */ + /* at this point mm4 can be 000A0A0A or 0A0A0A00 or another combo */ + movd_m2r (df->Amask, mm7); /* dst alpha mask */ + punpckldq_r2r (mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP_DOUBLE2({ /* One Pixel Blend */ movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/ @@ -337,41 +353,44 @@ static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info) srcp += 2; dstp += 2; }, width); - srcp += srcskip; - dstp += dstskip; - } - emms(); - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + emms (); + } } /* fast ARGB888->(A)RGB888 blending with pixel alpha */ -static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info) +static void +BlitRGBtoRGBPixelAlphaMMX (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - SDL_PixelFormat* sf = info->src; - Uint32 amask = sf->Amask; - - pxor_r2r(mm6, mm6); /* 0 -> mm6 */ - /* form multiplication mask */ - movd_m2r(sf->Amask, mm7); /* 0000F000 -> mm7 */ - punpcklbw_r2r(mm7, mm7); /* FF000000 -> mm7 */ - pcmpeqb_r2r(mm0, mm0); /* FFFFFFFF -> mm0 */ - movq_r2r(mm0, mm3); /* FFFFFFFF -> mm3 (for later) */ - pxor_r2r(mm0, mm7); /* 00FFFFFF -> mm7 (mult mask) */ - /* form channel masks */ - movq_r2r(mm7, mm0); /* 00FFFFFF -> mm0 */ - packsswb_r2r(mm6, mm0); /* 00000FFF -> mm0 (channel mask) */ - packsswb_r2r(mm6, mm3); /* 0000FFFF -> mm3 */ - pxor_r2r(mm0, mm3); /* 0000F000 -> mm3 (~channel mask) */ - /* get alpha channel shift */ - movd_m2r(sf->Ashift, mm5); /* Ashift -> mm5 */ - - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + SDL_PixelFormat *sf = info->src; + Uint32 amask = sf->Amask; + + pxor_r2r (mm6, mm6); /* 0 -> mm6 */ + /* form multiplication mask */ + movd_m2r (sf->Amask, mm7); /* 0000F000 -> mm7 */ + punpcklbw_r2r (mm7, mm7); /* FF000000 -> mm7 */ + pcmpeqb_r2r (mm0, mm0); /* FFFFFFFF -> mm0 */ + movq_r2r (mm0, mm3); /* FFFFFFFF -> mm3 (for later) */ + pxor_r2r (mm0, mm7); /* 00FFFFFF -> mm7 (mult mask) */ + /* form channel masks */ + movq_r2r (mm7, mm0); /* 00FFFFFF -> mm0 */ + packsswb_r2r (mm6, mm0); /* 00000FFF -> mm0 (channel mask) */ + packsswb_r2r (mm6, mm3); /* 0000FFFF -> mm3 */ + pxor_r2r (mm0, mm3); /* 0000F000 -> mm3 (~channel mask) */ + /* get alpha channel shift */ + movd_m2r (sf->Ashift, mm5); /* Ashift -> mm5 */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 alpha = *srcp & amask; /* FIXME: Here we special-case opaque alpha since the @@ -416,185 +435,193 @@ static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info) ++srcp; ++dstp; }, width); - srcp += srcskip; - dstp += dstskip; - } - emms(); + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + emms (); } + /* End GCC_ASMBLIT */ #elif MSVC_ASMBLIT /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */ -static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info) +static void +BlitRGBtoRGBSurfaceAlpha128MMX (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - Uint32 dalpha = info->dst->Amask; - - __m64 src1, src2, dst1, dst2, lmask, hmask, dsta; - - hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */ - lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */ - dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */ - - while (height--) { - int n = width; - if ( n & 1 ) { - Uint32 s = *srcp++; - Uint32 d = *dstp; - *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) - + (s & d & 0x00010101)) | dalpha; - n--; - } - - for (n >>= 1; n > 0; --n) { - dst1 = *(__m64*)dstp; /* 2 x dst -> dst1(ARGBARGB) */ - dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ - - src1 = *(__m64*)srcp; /* 2 x src -> src1(ARGBARGB) */ - src2 = src1; /* 2 x src -> src2(ARGBARGB) */ - - dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */ - src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */ - src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */ - src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */ - - dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */ - dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */ - dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */ - dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */ - - *(__m64*)dstp = dst1; /* dst1 -> 2 x dst pixels */ - dstp += 2; - srcp += 2; - } - - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + Uint32 dalpha = info->dst->Amask; + + __m64 src1, src2, dst1, dst2, lmask, hmask, dsta; + + hmask = _mm_set_pi32 (0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */ + lmask = _mm_set_pi32 (0x00010101, 0x00010101); /* !alpha128 mask -> lmask */ + dsta = _mm_set_pi32 (dalpha, dalpha); /* dst alpha mask -> dsta */ + + while (height--) { + int n = width; + if (n & 1) { + Uint32 s = *srcp++; + Uint32 d = *dstp; + *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) + + (s & d & 0x00010101)) | dalpha; + n--; + } + + for (n >>= 1; n > 0; --n) { + dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */ + dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ + + src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */ + src2 = src1; /* 2 x src -> src2(ARGBARGB) */ + + dst2 = _mm_and_si64 (dst2, hmask); /* dst & mask -> dst2 */ + src2 = _mm_and_si64 (src2, hmask); /* src & mask -> src2 */ + src2 = _mm_add_pi32 (src2, dst2); /* dst2 + src2 -> src2 */ + src2 = _mm_srli_pi32 (src2, 1); /* src2 >> 1 -> src2 */ + + dst1 = _mm_and_si64 (dst1, src1); /* src & dst -> dst1 */ + dst1 = _mm_and_si64 (dst1, lmask); /* dst1 & !mask -> dst1 */ + dst1 = _mm_add_pi32 (dst1, src2); /* src2 + dst1 -> dst1 */ + dst1 = _mm_or_si64 (dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */ + + *(__m64 *) dstp = dst1; /* dst1 -> 2 x dst pixels */ + dstp += 2; + srcp += 2; + } + + srcp += srcskip; + dstp += dstskip; + } + _mm_empty (); } /* fast RGB888->(A)RGB888 blending with surface alpha */ -static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info) +static void +BlitRGBtoRGBSurfaceAlphaMMX (SDL_BlitInfo * info) { - SDL_PixelFormat* df = info->dst; - Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask; - unsigned alpha = info->src->alpha; - - if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) { - /* only call a128 version when R,G,B occupy lower bits */ - BlitRGBtoRGBSurfaceAlpha128MMX(info); - } else { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - Uint32 dalpha = df->Amask; - Uint32 amult; - - __m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta; - - mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ - /* form the alpha mult */ - amult = alpha | (alpha << 8); - amult = amult | (amult << 16); - chanmask = (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->Bshift); - mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */ - mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */ - /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */ - dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */ - - while (height--) { - int n = width; - if (n & 1) { - /* One Pixel Blend */ - src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB)*/ - src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */ + SDL_PixelFormat *df = info->dst; + Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask; + unsigned alpha = info->src->alpha; - dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ + if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) { + /* only call a128 version when R,G,B occupy lower bits */ + BlitRGBtoRGBSurfaceAlpha128MMX (info); + } else { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + Uint32 dalpha = df->Amask; + Uint32 amult; + + __m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta; + + mm_zero = _mm_setzero_si64 (); /* 0 -> mm_zero */ + /* form the alpha mult */ + amult = alpha | (alpha << 8); + amult = amult | (amult << 16); + chanmask = + (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df-> + Bshift); + mm_alpha = _mm_set_pi32 (0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */ + mm_alpha = _mm_unpacklo_pi8 (mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */ + /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */ + dsta = _mm_set_pi32 (dalpha, dalpha); /* dst alpha mask -> dsta */ + + while (height--) { + int n = width; + if (n & 1) { + /* One Pixel Blend */ + src2 = _mm_cvtsi32_si64 (*srcp); /* src(ARGB) -> src2 (0000ARGB) */ + src2 = _mm_unpacklo_pi8 (src2, mm_zero); /* 0A0R0G0B -> src2 */ + + dst1 = _mm_cvtsi32_si64 (*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ + dst1 = _mm_unpacklo_pi8 (dst1, mm_zero); /* 0A0R0G0B -> dst1 */ + + src2 = _mm_sub_pi16 (src2, dst1); /* src2 - dst2 -> src2 */ + src2 = _mm_mullo_pi16 (src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_srli_pi16 (src2, 8); /* src2 >> 8 -> src2 */ + dst1 = _mm_add_pi8 (src2, dst1); /* src2 + dst1 -> dst1 */ + + dst1 = _mm_packs_pu16 (dst1, mm_zero); /* 0000ARGB -> dst1 */ + dst1 = _mm_or_si64 (dst1, dsta); /* dsta | dst1 -> dst1 */ + *dstp = _mm_cvtsi64_si32 (dst1); /* dst1 -> pixel */ + + ++srcp; + ++dstp; + + n--; + } - src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */ - dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */ - - dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */ - dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */ - *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ + for (n >>= 1; n > 0; --n) { + /* Two Pixels Blend */ + src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */ + src2 = src1; /* 2 x src -> src2(ARGBARGB) */ + src1 = _mm_unpacklo_pi8 (src1, mm_zero); /* low - 0A0R0G0B -> src1 */ + src2 = _mm_unpackhi_pi8 (src2, mm_zero); /* high - 0A0R0G0B -> src2 */ - ++srcp; - ++dstp; - - n--; - } + dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */ + dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ + dst1 = _mm_unpacklo_pi8 (dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */ + dst2 = _mm_unpackhi_pi8 (dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */ - for (n >>= 1; n > 0; --n) { - /* Two Pixels Blend */ - src1 = *(__m64*)srcp; /* 2 x src -> src1(ARGBARGB)*/ - src2 = src1; /* 2 x src -> src2(ARGBARGB) */ - src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */ - src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */ - - dst1 = *(__m64*)dstp;/* 2 x dst -> dst1(ARGBARGB) */ - dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */ - dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */ - - src1 = _mm_sub_pi16(src1, dst1);/* src1 - dst1 -> src1 */ - src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */ - src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */ - dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */ - - src2 = _mm_sub_pi16(src2, dst2);/* src2 - dst2 -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */ - dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */ - - dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */ - dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */ + src1 = _mm_sub_pi16 (src1, dst1); /* src1 - dst1 -> src1 */ + src1 = _mm_mullo_pi16 (src1, mm_alpha); /* src1 * alpha -> src1 */ + src1 = _mm_srli_pi16 (src1, 8); /* src1 >> 8 -> src1 */ + dst1 = _mm_add_pi8 (src1, dst1); /* src1 + dst1(dst1) -> dst1 */ - *(__m64*)dstp = dst1; /* dst1 -> 2 x pixel */ + src2 = _mm_sub_pi16 (src2, dst2); /* src2 - dst2 -> src2 */ + src2 = _mm_mullo_pi16 (src2, mm_alpha); /* src2 * alpha -> src2 */ + src2 = _mm_srli_pi16 (src2, 8); /* src2 >> 8 -> src2 */ + dst2 = _mm_add_pi8 (src2, dst2); /* src2 + dst2(dst2) -> dst2 */ - srcp += 2; - dstp += 2; - } - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); - } + dst1 = _mm_packs_pu16 (dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */ + dst1 = _mm_or_si64 (dst1, dsta); /* dsta | dst1 -> dst1 */ + + *(__m64 *) dstp = dst1; /* dst1 -> 2 x pixel */ + + srcp += 2; + dstp += 2; + } + srcp += srcskip; + dstp += dstskip; + } + _mm_empty (); + } } /* fast ARGB888->(A)RGB888 blending with pixel alpha */ -static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info) +static void +BlitRGBtoRGBPixelAlphaMMX (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - SDL_PixelFormat* sf = info->src; - Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; - Uint32 amask = sf->Amask; - Uint32 ashift = sf->Ashift; - Uint64 multmask; - - __m64 src1, dst1, mm_alpha, mm_zero, dmask; - - mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ - multmask = ~(0xFFFFi64 << (ashift * 2)); - dmask = *(__m64*) &multmask; /* dst alpha mask -> dmask */ - - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + SDL_PixelFormat *sf = info->src; + Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; + Uint32 amask = sf->Amask; + Uint32 ashift = sf->Ashift; + Uint64 multmask; + + __m64 src1, dst1, mm_alpha, mm_zero, dmask; + + mm_zero = _mm_setzero_si64 (); /* 0 -> mm_zero */ + multmask = ~(0xFFFFi 64 << (ashift * 2)); + dmask = *(__m64 *) & multmask; /* dst alpha mask -> dmask */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 alpha = *srcp & amask; if (alpha == 0) { @@ -627,11 +654,13 @@ static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info) ++srcp; ++dstp; }, width); - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + _mm_empty (); } + /* End MSVC_ASMBLIT */ #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */ @@ -646,14 +675,14 @@ static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info) #include #if (defined(__MACOSX__) && (__GNUC__ < 4)) - #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ +#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p ) - #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ +#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ (vector unsigned short) ( a,b,c,d,e,f,g,h ) #else - #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ +#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p } - #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ +#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ (vector unsigned short) { a,b,c,d,e,f,g,h } #endif @@ -678,7 +707,7 @@ static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info) ? vec_lvsl(0, src) \ : vec_add(vec_lvsl(8, src), vec_splat_u8(8))) - + #define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \ /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \ vector unsigned short vtemp1 = vec_mule(vs, valpha); \ @@ -704,10 +733,11 @@ static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info) /* (>>8) and get ARGBARGBARGBARGB */ \ vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \ } while (0) - + /* Calculate the permute vector used for 32->32 swizzling */ -static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt, - const SDL_PixelFormat *dstfmt) +static vector unsigned char +calc_swizzle32 (const SDL_PixelFormat * srcfmt, + const SDL_PixelFormat * dstfmt) { /* * We have to assume that the bits that aren't used by other @@ -720,7 +750,8 @@ static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt, 0, 0, 0, 0, 16, 8, 0, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, - 0, 0}; + 0, 0 + }; if (!srcfmt) { srcfmt = &default_pixel_format; } @@ -728,105 +759,107 @@ static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt, dstfmt = &default_pixel_format; } const vector unsigned char plus = VECUINT8_LITERAL - ( 0x00, 0x00, 0x00, 0x00, - 0x04, 0x04, 0x04, 0x04, - 0x08, 0x08, 0x08, 0x08, - 0x0C, 0x0C, 0x0C, 0x0C ); + (0x00, 0x00, 0x00, 0x00, + 0x04, 0x04, 0x04, 0x04, + 0x08, 0x08, 0x08, 0x08, + 0x0C, 0x0C, 0x0C, 0x0C); vector unsigned char vswiz; vector unsigned int srcvec; #define RESHIFT(X) (3 - ((X) >> 3)) - Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift); - Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift); - Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift); + Uint32 rmask = RESHIFT (srcfmt->Rshift) << (dstfmt->Rshift); + Uint32 gmask = RESHIFT (srcfmt->Gshift) << (dstfmt->Gshift); + Uint32 bmask = RESHIFT (srcfmt->Bshift) << (dstfmt->Bshift); Uint32 amask; /* Use zero for alpha if either surface doesn't have alpha */ if (dstfmt->Amask) { - amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift); + amask = + ((srcfmt->Amask) ? RESHIFT (srcfmt->Ashift) : 0x10) << (dstfmt-> + Ashift); } else { - amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF); + amask = + 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ + 0xFFFFFFFF); } -#undef RESHIFT - ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask); - vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0)); - return(vswiz); +#undef RESHIFT + ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask); + vswiz = vec_add (plus, (vector unsigned char) vec_splat (srcvec, 0)); + return (vswiz); } -static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info) +static void +Blit32to565PixelAlphaAltivec (SDL_BlitInfo * info) { int height = info->d_height; - Uint8 *src = (Uint8 *)info->s_pixels; + Uint8 *src = (Uint8 *) info->s_pixels; int srcskip = info->s_skip; - Uint8 *dst = (Uint8 *)info->d_pixels; + Uint8 *dst = (Uint8 *) info->d_pixels; int dstskip = info->d_skip; SDL_PixelFormat *srcfmt = info->src; - vector unsigned char v0 = vec_splat_u8(0); - vector unsigned short v8_16 = vec_splat_u16(8); - vector unsigned short v1_16 = vec_splat_u16(1); - vector unsigned short v2_16 = vec_splat_u16(2); - vector unsigned short v3_16 = vec_splat_u16(3); - vector unsigned int v8_32 = vec_splat_u32(8); - vector unsigned int v16_32 = vec_add(v8_32, v8_32); - vector unsigned short v3f = VECUINT16_LITERAL( - 0x003f, 0x003f, 0x003f, 0x003f, - 0x003f, 0x003f, 0x003f, 0x003f); - vector unsigned short vfc = VECUINT16_LITERAL( - 0x00fc, 0x00fc, 0x00fc, 0x00fc, - 0x00fc, 0x00fc, 0x00fc, 0x00fc); + vector unsigned char v0 = vec_splat_u8 (0); + vector unsigned short v8_16 = vec_splat_u16 (8); + vector unsigned short v1_16 = vec_splat_u16 (1); + vector unsigned short v2_16 = vec_splat_u16 (2); + vector unsigned short v3_16 = vec_splat_u16 (3); + vector unsigned int v8_32 = vec_splat_u32 (8); + vector unsigned int v16_32 = vec_add (v8_32, v8_32); + vector unsigned short v3f = + VECUINT16_LITERAL (0x003f, 0x003f, 0x003f, 0x003f, + 0x003f, 0x003f, 0x003f, 0x003f); + vector unsigned short vfc = + VECUINT16_LITERAL (0x00fc, 0x00fc, 0x00fc, 0x00fc, + 0x00fc, 0x00fc, 0x00fc, 0x00fc); /* - 0x10 - 0x1f is the alpha - 0x00 - 0x0e evens are the red - 0x01 - 0x0f odds are zero - */ - vector unsigned char vredalpha1 = VECUINT8_LITERAL( - 0x10, 0x00, 0x01, 0x01, - 0x10, 0x02, 0x01, 0x01, - 0x10, 0x04, 0x01, 0x01, - 0x10, 0x06, 0x01, 0x01 - ); - vector unsigned char vredalpha2 = (vector unsigned char)( - vec_add((vector unsigned int)vredalpha1, vec_sl(v8_32, v16_32)) - ); + 0x10 - 0x1f is the alpha + 0x00 - 0x0e evens are the red + 0x01 - 0x0f odds are zero + */ + vector unsigned char vredalpha1 = + VECUINT8_LITERAL (0x10, 0x00, 0x01, 0x01, + 0x10, 0x02, 0x01, 0x01, + 0x10, 0x04, 0x01, 0x01, + 0x10, 0x06, 0x01, 0x01); + vector unsigned char vredalpha2 = + (vector unsigned char) (vec_add ((vector unsigned int) vredalpha1, + vec_sl (v8_32, v16_32)) + ); /* - 0x00 - 0x0f is ARxx ARxx ARxx ARxx - 0x11 - 0x0f odds are blue - */ - vector unsigned char vblue1 = VECUINT8_LITERAL( - 0x00, 0x01, 0x02, 0x11, - 0x04, 0x05, 0x06, 0x13, - 0x08, 0x09, 0x0a, 0x15, - 0x0c, 0x0d, 0x0e, 0x17 - ); - vector unsigned char vblue2 = (vector unsigned char)( - vec_add((vector unsigned int)vblue1, v8_32) - ); + 0x00 - 0x0f is ARxx ARxx ARxx ARxx + 0x11 - 0x0f odds are blue + */ + vector unsigned char vblue1 = VECUINT8_LITERAL (0x00, 0x01, 0x02, 0x11, + 0x04, 0x05, 0x06, 0x13, + 0x08, 0x09, 0x0a, 0x15, + 0x0c, 0x0d, 0x0e, 0x17); + vector unsigned char vblue2 = + (vector unsigned char) (vec_add ((vector unsigned int) vblue1, v8_32) + ); /* - 0x00 - 0x0f is ARxB ARxB ARxB ARxB - 0x10 - 0x0e evens are green - */ - vector unsigned char vgreen1 = VECUINT8_LITERAL( - 0x00, 0x01, 0x10, 0x03, - 0x04, 0x05, 0x12, 0x07, - 0x08, 0x09, 0x14, 0x0b, - 0x0c, 0x0d, 0x16, 0x0f - ); - vector unsigned char vgreen2 = (vector unsigned char)( - vec_add((vector unsigned int)vgreen1, vec_sl(v8_32, v8_32)) - ); - vector unsigned char vgmerge = VECUINT8_LITERAL( - 0x00, 0x02, 0x00, 0x06, - 0x00, 0x0a, 0x00, 0x0e, - 0x00, 0x12, 0x00, 0x16, - 0x00, 0x1a, 0x00, 0x1e); - vector unsigned char mergePermute = VEC_MERGE_PERMUTE(); - vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL); - vector unsigned char valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC)); - - vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); - - while(height--) { + 0x00 - 0x0f is ARxB ARxB ARxB ARxB + 0x10 - 0x0e evens are green + */ + vector unsigned char vgreen1 = VECUINT8_LITERAL (0x00, 0x01, 0x10, 0x03, + 0x04, 0x05, 0x12, 0x07, + 0x08, 0x09, 0x14, 0x0b, + 0x0c, 0x0d, 0x16, 0x0f); + vector unsigned char vgreen2 = + (vector unsigned + char) (vec_add ((vector unsigned int) vgreen1, vec_sl (v8_32, v8_32)) + ); + vector unsigned char vgmerge = VECUINT8_LITERAL (0x00, 0x02, 0x00, 0x06, + 0x00, 0x0a, 0x00, 0x0e, + 0x00, 0x12, 0x00, 0x16, + 0x00, 0x1a, 0x00, 0x1e); + vector unsigned char mergePermute = VEC_MERGE_PERMUTE (); + vector unsigned char vpermute = calc_swizzle32 (srcfmt, NULL); + vector unsigned char valphaPermute = + vec_and (vec_lvsl (0, (int *) NULL), vec_splat_u8 (0xC)); + + vector unsigned short vf800 = (vector unsigned short) vec_splat_u8 (-7); + vf800 = vec_sl (vf800, vec_splat_u16 (8)); + + while (height--) { int extrawidth; vector unsigned char valigner; vector unsigned char vsrc; @@ -852,10 +885,10 @@ static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info) dst += 2; \ widthvar--; \ } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width); + ONE_PIXEL_BLEND ((UNALIGNED_PTR (dst)) && (width), width); extrawidth = (width % 8); - valigner = VEC_ALIGNER(src); - vsrc = (vector unsigned char)vec_ld(0, src); + valigner = VEC_ALIGNER (src); + vsrc = (vector unsigned char) vec_ld (0, src); width -= extrawidth; while (width) { vector unsigned char valpha; @@ -865,64 +898,79 @@ static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info) vector unsigned short vpixel, vrpixel, vgpixel, vbpixel; /* Load 8 pixels from src as ARGB */ - voverflow = (vector unsigned char)vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - vsrc1 = vec_perm(vsrc, vsrc, vpermute); + voverflow = (vector unsigned char) vec_ld (15, src); + vsrc = vec_perm (vsrc, voverflow, valigner); + vsrc1 = vec_perm (vsrc, vsrc, vpermute); src += 16; - vsrc = (vector unsigned char)vec_ld(15, src); - voverflow = vec_perm(voverflow, vsrc, valigner); - vsrc2 = vec_perm(voverflow, voverflow, vpermute); + vsrc = (vector unsigned char) vec_ld (15, src); + voverflow = vec_perm (voverflow, vsrc, valigner); + vsrc2 = vec_perm (voverflow, voverflow, vpermute); src += 16; /* Load 8 pixels from dst as XRGB */ - voverflow = vec_ld(0, dst); - vR = vec_and((vector unsigned short)voverflow, vf800); - vB = vec_sl((vector unsigned short)voverflow, v3_16); - vG = vec_sl(vB, v2_16); - vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha1); - vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1); - vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1); - vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha2); - vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2); - vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2); + voverflow = vec_ld (0, dst); + vR = vec_and ((vector unsigned short) voverflow, vf800); + vB = vec_sl ((vector unsigned short) voverflow, v3_16); + vG = vec_sl (vB, v2_16); + vdst1 = + (vector unsigned char) vec_perm ((vector unsigned char) vR, + (vector unsigned char) vR, + vredalpha1); + vdst1 = vec_perm (vdst1, (vector unsigned char) vB, vblue1); + vdst1 = vec_perm (vdst1, (vector unsigned char) vG, vgreen1); + vdst2 = + (vector unsigned char) vec_perm ((vector unsigned char) vR, + (vector unsigned char) vR, + vredalpha2); + vdst2 = vec_perm (vdst2, (vector unsigned char) vB, vblue2); + vdst2 = vec_perm (vdst2, (vector unsigned char) vG, vgreen2); /* Alpha blend 8 pixels as ARGB */ - valpha = vec_perm(vsrc1, v0, valphaPermute); - VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16, v8_16); - valpha = vec_perm(vsrc2, v0, valphaPermute); - VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16, v8_16); + valpha = vec_perm (vsrc1, v0, valphaPermute); + VEC_MULTIPLY_ALPHA (vsrc1, vdst1, valpha, mergePermute, v1_16, + v8_16); + valpha = vec_perm (vsrc2, v0, valphaPermute); + VEC_MULTIPLY_ALPHA (vsrc2, vdst2, valpha, mergePermute, v1_16, + v8_16); /* Convert 8 pixels to 565 */ - vpixel = (vector unsigned short)vec_packpx((vector unsigned int)vdst1, (vector unsigned int)vdst2); - vgpixel = (vector unsigned short)vec_perm(vdst1, vdst2, vgmerge); - vgpixel = vec_and(vgpixel, vfc); - vgpixel = vec_sl(vgpixel, v3_16); - vrpixel = vec_sl(vpixel, v1_16); - vrpixel = vec_and(vrpixel, vf800); - vbpixel = vec_and(vpixel, v3f); - vdst1 = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel); - vdst1 = vec_or(vdst1, (vector unsigned char)vbpixel); - + vpixel = (vector unsigned short) vec_packpx ((vector unsigned int) + vdst1, + (vector unsigned int) + vdst2); + vgpixel = + (vector unsigned short) vec_perm (vdst1, vdst2, vgmerge); + vgpixel = vec_and (vgpixel, vfc); + vgpixel = vec_sl (vgpixel, v3_16); + vrpixel = vec_sl (vpixel, v1_16); + vrpixel = vec_and (vrpixel, vf800); + vbpixel = vec_and (vpixel, v3f); + vdst1 = + vec_or ((vector unsigned char) vrpixel, + (vector unsigned char) vgpixel); + vdst1 = vec_or (vdst1, (vector unsigned char) vbpixel); + /* Store 8 pixels */ - vec_st(vdst1, 0, dst); + vec_st (vdst1, 0, dst); width -= 8; dst += 16; } - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND src += srcskip; dst += dstskip; } } -static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info) +static void +Blit32to32SurfaceAlphaKeyAltivec (SDL_BlitInfo * info) { unsigned alpha = info->src->alpha; int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; + Uint32 *srcp = (Uint32 *) info->s_pixels; int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; + Uint32 *dstp = (Uint32 *) info->d_pixels; int dstskip = info->d_skip >> 2; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; @@ -943,30 +991,30 @@ static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info) vector unsigned int vckey; vector unsigned int vrgbmask; - mergePermute = VEC_MERGE_PERMUTE(); - v0 = vec_splat_u8(0); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); + mergePermute = VEC_MERGE_PERMUTE (); + v0 = vec_splat_u8 (0); + v1 = vec_splat_u16 (1); + v8 = vec_splat_u16 (8); /* set the alpha to 255 on the destination surf */ - valphamask = VEC_ALPHA_MASK(); + valphamask = VEC_ALPHA_MASK (); - vsrcPermute = calc_swizzle32(srcfmt, NULL); - vdstPermute = calc_swizzle32(NULL, dstfmt); - vsdstPermute = calc_swizzle32(dstfmt, NULL); + vsrcPermute = calc_swizzle32 (srcfmt, NULL); + vdstPermute = calc_swizzle32 (NULL, dstfmt); + vsdstPermute = calc_swizzle32 (dstfmt, NULL); /* set a vector full of alpha and 255-alpha */ - ((unsigned char *)&valpha)[0] = alpha; - valpha = vec_splat(valpha, 0); - vbits = (vector unsigned char)vec_splat_s8(-1); + ((unsigned char *) &valpha)[0] = alpha; + valpha = vec_splat (valpha, 0); + vbits = (vector unsigned char) vec_splat_s8 (-1); ckey &= rgbmask; - ((unsigned int *)(char*)&vckey)[0] = ckey; - vckey = vec_splat(vckey, 0); - ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask; - vrgbmask = vec_splat(vrgbmask, 0); + ((unsigned int *) (char *) &vckey)[0] = ckey; + vckey = vec_splat (vckey, 0); + ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask; + vrgbmask = vec_splat (vrgbmask, 0); - while(height--) { + while (height--) { int width = info->d_width; #define ONE_PIXEL_BLEND(condition, widthvar) \ while (condition) { \ @@ -983,11 +1031,11 @@ static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info) srcp++; \ widthvar--; \ } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); + ONE_PIXEL_BLEND ((UNALIGNED_PTR (dstp)) && (width), width); if (width > 0) { int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp); + vector unsigned char valigner = VEC_ALIGNER (srcp); + vector unsigned char vs = (vector unsigned char) vec_ld (0, srcp); width -= extrawidth; while (width) { vector unsigned char vsel; @@ -996,56 +1044,60 @@ static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info) vector unsigned char vd_orig; /* s = *srcp */ - voverflow = (vector unsigned char)vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - + voverflow = (vector unsigned char) vec_ld (15, srcp); + vs = vec_perm (vs, voverflow, valigner); + /* vsel is set for items that match the key */ - vsel = (vector unsigned char)vec_and((vector unsigned int)vs, vrgbmask); - vsel = (vector unsigned char)vec_cmpeq((vector unsigned int)vsel, vckey); + vsel = + (vector unsigned char) vec_and ((vector unsigned int) vs, + vrgbmask); + vsel = (vector unsigned char) vec_cmpeq ((vector unsigned int) + vsel, vckey); /* permute to source format */ - vs = vec_perm(vs, valpha, vsrcPermute); + vs = vec_perm (vs, valpha, vsrcPermute); /* d = *dstp */ - vd = (vector unsigned char)vec_ld(0, dstp); - vd_orig = vd = vec_perm(vd, v0, vsdstPermute); + vd = (vector unsigned char) vec_ld (0, dstp); + vd_orig = vd = vec_perm (vd, v0, vsdstPermute); - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); + VEC_MULTIPLY_ALPHA (vs, vd, valpha, mergePermute, v1, v8); /* set the alpha channel to full on */ - vd = vec_or(vd, valphamask); + vd = vec_or (vd, valphamask); /* mask out color key */ - vd = vec_sel(vd, vd_orig, vsel); - + vd = vec_sel (vd, vd_orig, vsel); + /* permute to dest format */ - vd = vec_perm(vd, vbits, vdstPermute); + vd = vec_perm (vd, vbits, vdstPermute); /* *dstp = res */ - vec_st((vector unsigned int)vd, 0, dstp); - + vec_st ((vector unsigned int) vd, 0, dstp); + srcp += 4; dstp += 4; width -= 4; vs = voverflow; } - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); } #undef ONE_PIXEL_BLEND - + srcp += srcskip; dstp += dstskip; } } -static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info) +static void +Blit32to32PixelAlphaAltivec (SDL_BlitInfo * info) { int width = info->d_width; int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; + Uint32 *srcp = (Uint32 *) info->s_pixels; int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; + Uint32 *dstp = (Uint32 *) info->d_pixels; int dstskip = info->d_skip >> 2; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; @@ -1060,18 +1112,18 @@ static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info) vector unsigned short v1; vector unsigned short v8; - v0 = vec_splat_u8(0); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); - mergePermute = VEC_MERGE_PERMUTE(); - valphamask = VEC_ALPHA_MASK(); - valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC)); - vpixelmask = vec_nor(valphamask, v0); - vsrcPermute = calc_swizzle32(srcfmt, NULL); - vdstPermute = calc_swizzle32(NULL, dstfmt); - vsdstPermute = calc_swizzle32(dstfmt, NULL); - - while ( height-- ) { + v0 = vec_splat_u8 (0); + v1 = vec_splat_u16 (1); + v8 = vec_splat_u16 (8); + mergePermute = VEC_MERGE_PERMUTE (); + valphamask = VEC_ALPHA_MASK (); + valphaPermute = vec_and (vec_lvsl (0, (int *) NULL), vec_splat_u8 (0xC)); + vpixelmask = vec_nor (valphamask, v0); + vsrcPermute = calc_swizzle32 (srcfmt, NULL); + vdstPermute = calc_swizzle32 (NULL, dstfmt); + vsdstPermute = calc_swizzle32 (dstfmt, NULL); + + while (height--) { width = info->d_width; #define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \ Uint32 Pixel; \ @@ -1086,13 +1138,13 @@ static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info) ++dstp; \ widthvar--; \ } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); + ONE_PIXEL_BLEND ((UNALIGNED_PTR (dstp)) && (width), width); if (width > 0) { /* vsrcPermute */ /* vdstPermute */ int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp); + vector unsigned char valigner = VEC_ALIGNER (srcp); + vector unsigned char vs = (vector unsigned char) vec_ld (0, srcp); width -= extrawidth; while (width) { vector unsigned char voverflow; @@ -1100,50 +1152,51 @@ static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info) vector unsigned char valpha; vector unsigned char vdstalpha; /* s = *srcp */ - voverflow = (vector unsigned char)vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - vs = vec_perm(vs, v0, vsrcPermute); + voverflow = (vector unsigned char) vec_ld (15, srcp); + vs = vec_perm (vs, voverflow, valigner); + vs = vec_perm (vs, v0, vsrcPermute); + + valpha = vec_perm (vs, v0, valphaPermute); - valpha = vec_perm(vs, v0, valphaPermute); - /* d = *dstp */ - vd = (vector unsigned char)vec_ld(0, dstp); - vd = vec_perm(vd, v0, vsdstPermute); - vdstalpha = vec_and(vd, valphamask); + vd = (vector unsigned char) vec_ld (0, dstp); + vd = vec_perm (vd, v0, vsdstPermute); + vdstalpha = vec_and (vd, valphamask); - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); + VEC_MULTIPLY_ALPHA (vs, vd, valpha, mergePermute, v1, v8); /* set the alpha to the dest alpha */ - vd = vec_and(vd, vpixelmask); - vd = vec_or(vd, vdstalpha); - vd = vec_perm(vd, v0, vdstPermute); + vd = vec_and (vd, vpixelmask); + vd = vec_or (vd, vdstalpha); + vd = vec_perm (vd, v0, vdstPermute); /* *dstp = res */ - vec_st((vector unsigned int)vd, 0, dstp); - + vec_st ((vector unsigned int) vd, 0, dstp); + srcp += 4; dstp += 4; width -= 4; vs = voverflow; } - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); } - srcp += srcskip; - dstp += dstskip; + srcp += srcskip; + dstp += dstskip; #undef ONE_PIXEL_BLEND - } + } } /* fast ARGB888->(A)RGB888 blending with pixel alpha */ -static void BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo *info) +static void +BlitRGBtoRGBPixelAlphaAltivec (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; vector unsigned char mergePermute; vector unsigned char valphaPermute; vector unsigned char valphamask; @@ -1151,16 +1204,16 @@ static void BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo *info) vector unsigned char v0; vector unsigned short v1; vector unsigned short v8; - v0 = vec_splat_u8(0); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); - mergePermute = VEC_MERGE_PERMUTE(); - valphamask = VEC_ALPHA_MASK(); - valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC)); - - - vpixelmask = vec_nor(valphamask, v0); - while(height--) { + v0 = vec_splat_u8 (0); + v1 = vec_splat_u16 (1); + v8 = vec_splat_u16 (8); + mergePermute = VEC_MERGE_PERMUTE (); + valphamask = VEC_ALPHA_MASK (); + valphaPermute = vec_and (vec_lvsl (0, (int *) NULL), vec_splat_u8 (0xC)); + + + vpixelmask = vec_nor (valphamask, v0); + while (height--) { width = info->d_width; #define ONE_PIXEL_BLEND(condition, widthvar) \ while ((condition)) { \ @@ -1189,11 +1242,11 @@ static void BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo *info) ++dstp; \ widthvar--; \ } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); + ONE_PIXEL_BLEND ((UNALIGNED_PTR (dstp)) && (width), width); if (width > 0) { int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp); + vector unsigned char valigner = VEC_ALIGNER (srcp); + vector unsigned char vs = (vector unsigned char) vec_ld (0, srcp); width -= extrawidth; while (width) { vector unsigned char voverflow; @@ -1201,50 +1254,51 @@ static void BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo *info) vector unsigned char valpha; vector unsigned char vdstalpha; /* s = *srcp */ - voverflow = (vector unsigned char)vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); + voverflow = (vector unsigned char) vec_ld (15, srcp); + vs = vec_perm (vs, voverflow, valigner); + + valpha = vec_perm (vs, v0, valphaPermute); - valpha = vec_perm(vs, v0, valphaPermute); - /* d = *dstp */ - vd = (vector unsigned char)vec_ld(0, dstp); - vdstalpha = vec_and(vd, valphamask); + vd = (vector unsigned char) vec_ld (0, dstp); + vdstalpha = vec_and (vd, valphamask); - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); + VEC_MULTIPLY_ALPHA (vs, vd, valpha, mergePermute, v1, v8); /* set the alpha to the dest alpha */ - vd = vec_and(vd, vpixelmask); - vd = vec_or(vd, vdstalpha); + vd = vec_and (vd, vpixelmask); + vd = vec_or (vd, vdstalpha); /* *dstp = res */ - vec_st((vector unsigned int)vd, 0, dstp); - + vec_st ((vector unsigned int) vd, 0, dstp); + srcp += 4; dstp += 4; width -= 4; vs = voverflow; } - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); } - srcp += srcskip; - dstp += dstskip; - } + srcp += srcskip; + dstp += dstskip; + } #undef ONE_PIXEL_BLEND } -static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info) +static void +Blit32to32SurfaceAlphaAltivec (SDL_BlitInfo * info) { /* XXX : 6 */ - unsigned alpha = info->src->alpha; + unsigned alpha = info->src->alpha; int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; + Uint32 *srcp = (Uint32 *) info->s_pixels; int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; + Uint32 *dstp = (Uint32 *) info->d_pixels; int dstskip = info->d_skip >> 2; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; - unsigned sA = srcfmt->alpha; - unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; + unsigned sA = srcfmt->alpha; + unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; vector unsigned char mergePermute; vector unsigned char vsrcPermute; vector unsigned char vdstPermute; @@ -1255,23 +1309,23 @@ static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info) vector unsigned short v1; vector unsigned short v8; - mergePermute = VEC_MERGE_PERMUTE(); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); + mergePermute = VEC_MERGE_PERMUTE (); + v1 = vec_splat_u16 (1); + v8 = vec_splat_u16 (8); /* set the alpha to 255 on the destination surf */ - valphamask = VEC_ALPHA_MASK(); + valphamask = VEC_ALPHA_MASK (); - vsrcPermute = calc_swizzle32(srcfmt, NULL); - vdstPermute = calc_swizzle32(NULL, dstfmt); - vsdstPermute = calc_swizzle32(dstfmt, NULL); + vsrcPermute = calc_swizzle32 (srcfmt, NULL); + vdstPermute = calc_swizzle32 (NULL, dstfmt); + vsdstPermute = calc_swizzle32 (dstfmt, NULL); /* set a vector full of alpha and 255-alpha */ - ((unsigned char *)&valpha)[0] = alpha; - valpha = vec_splat(valpha, 0); - vbits = (vector unsigned char)vec_splat_s8(-1); + ((unsigned char *) &valpha)[0] = alpha; + valpha = vec_splat (valpha, 0); + vbits = (vector unsigned char) vec_splat_s8 (-1); - while(height--) { + while (height--) { int width = info->d_width; #define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \ Uint32 Pixel; \ @@ -1284,43 +1338,43 @@ static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info) ++dstp; \ widthvar--; \ } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); + ONE_PIXEL_BLEND ((UNALIGNED_PTR (dstp)) && (width), width); if (width > 0) { int extrawidth = (width % 4); - vector unsigned char valigner = vec_lvsl(0, srcp); - vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp); + vector unsigned char valigner = vec_lvsl (0, srcp); + vector unsigned char vs = (vector unsigned char) vec_ld (0, srcp); width -= extrawidth; while (width) { vector unsigned char voverflow; vector unsigned char vd; /* s = *srcp */ - voverflow = (vector unsigned char)vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - vs = vec_perm(vs, valpha, vsrcPermute); - + voverflow = (vector unsigned char) vec_ld (15, srcp); + vs = vec_perm (vs, voverflow, valigner); + vs = vec_perm (vs, valpha, vsrcPermute); + /* d = *dstp */ - vd = (vector unsigned char)vec_ld(0, dstp); - vd = vec_perm(vd, vd, vsdstPermute); + vd = (vector unsigned char) vec_ld (0, dstp); + vd = vec_perm (vd, vd, vsdstPermute); - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); + VEC_MULTIPLY_ALPHA (vs, vd, valpha, mergePermute, v1, v8); /* set the alpha channel to full on */ - vd = vec_or(vd, valphamask); - vd = vec_perm(vd, vbits, vdstPermute); + vd = vec_or (vd, valphamask); + vd = vec_perm (vd, vbits, vdstPermute); /* *dstp = res */ - vec_st((vector unsigned int)vd, 0, dstp); - + vec_st ((vector unsigned int) vd, 0, dstp); + srcp += 4; dstp += 4; width -= 4; vs = voverflow; } - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); } #undef ONE_PIXEL_BLEND - + srcp += srcskip; dstp += dstskip; } @@ -1329,13 +1383,14 @@ static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info) /* fast RGB888->(A)RGB888 blending */ -static void BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo *info) +static void +BlitRGBtoRGBSurfaceAlphaAltivec (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; + unsigned alpha = info->src->alpha; int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; + Uint32 *srcp = (Uint32 *) info->s_pixels; int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; + Uint32 *dstp = (Uint32 *) info->d_pixels; int dstskip = info->d_skip >> 2; vector unsigned char mergePermute; vector unsigned char valpha; @@ -1343,18 +1398,18 @@ static void BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo *info) vector unsigned short v1; vector unsigned short v8; - mergePermute = VEC_MERGE_PERMUTE(); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); + mergePermute = VEC_MERGE_PERMUTE (); + v1 = vec_splat_u16 (1); + v8 = vec_splat_u16 (8); /* set the alpha to 255 on the destination surf */ - valphamask = VEC_ALPHA_MASK(); + valphamask = VEC_ALPHA_MASK (); /* set a vector full of alpha and 255-alpha */ - ((unsigned char *)&valpha)[0] = alpha; - valpha = vec_splat(valpha, 0); + ((unsigned char *) &valpha)[0] = alpha; + valpha = vec_splat (valpha, 0); - while(height--) { + while (height--) { int width = info->d_width; #define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \ Uint32 s = *srcp; \ @@ -1371,90 +1426,96 @@ static void BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo *info) ++dstp; \ widthvar--; \ } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); + ONE_PIXEL_BLEND ((UNALIGNED_PTR (dstp)) && (width), width); if (width > 0) { int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp); + vector unsigned char valigner = VEC_ALIGNER (srcp); + vector unsigned char vs = (vector unsigned char) vec_ld (0, srcp); width -= extrawidth; while (width) { vector unsigned char voverflow; vector unsigned char vd; /* s = *srcp */ - voverflow = (vector unsigned char)vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - + voverflow = (vector unsigned char) vec_ld (15, srcp); + vs = vec_perm (vs, voverflow, valigner); + /* d = *dstp */ - vd = (vector unsigned char)vec_ld(0, dstp); + vd = (vector unsigned char) vec_ld (0, dstp); - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); + VEC_MULTIPLY_ALPHA (vs, vd, valpha, mergePermute, v1, v8); /* set the alpha channel to full on */ - vd = vec_or(vd, valphamask); + vd = vec_or (vd, valphamask); /* *dstp = res */ - vec_st((vector unsigned int)vd, 0, dstp); - + vec_st ((vector unsigned int) vd, 0, dstp); + srcp += 4; dstp += 4; width -= 4; vs = voverflow; } - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); } #undef ONE_PIXEL_BLEND - + srcp += srcskip; dstp += dstskip; } } + #if __MWERKS__ #pragma altivec_model off #endif #endif /* SDL_ALTIVEC_BLITTERS */ /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */ -static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info) +static void +BlitRGBtoRGBSurfaceAlpha128 (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp++; Uint32 d = *dstp; *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) + (s & d & 0x00010101)) | 0xff000000; }, width); - srcp += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } } /* fast RGB888->(A)RGB888 blending with surface alpha */ -static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info) +static void +BlitRGBtoRGBSurfaceAlpha (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; - if(alpha == 128) { - BlitRGBtoRGBSurfaceAlpha128(info); - } else { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - Uint32 s; - Uint32 d; - Uint32 s1; - Uint32 d1; - - while(height--) { + unsigned alpha = info->src->alpha; + if (alpha == 128) { + BlitRGBtoRGBSurfaceAlpha128 (info); + } else { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + Uint32 s; + Uint32 d; + Uint32 s1; + Uint32 d1; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP_DOUBLE2({ /* One Pixel Blend */ s = *srcp; @@ -1499,23 +1560,26 @@ static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info) ++srcp; ++dstp; }, width); - srcp += srcskip; - dstp += dstskip; - } - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + } } /* fast ARGB888->(A)RGB888 blending with pixel alpha */ -static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info) +static void +BlitRGBtoRGBPixelAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 dalpha; Uint32 d; @@ -1549,48 +1613,47 @@ static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info) ++srcp; ++dstp; }, width); - srcp += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } } #if GCC_ASMBLIT /* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */ -inline static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info) +inline static void +BlitRGBtoRGBPixelAlphaMMX3DNOW (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - SDL_PixelFormat* sf = info->src; - Uint32 amask = sf->Amask; - - __asm__ ( - /* make mm6 all zeros. */ - "pxor %%mm6, %%mm6\n" - - /* Make a mask to preserve the alpha. */ - "movd %0, %%mm7\n\t" /* 0000F000 -> mm7 */ - "punpcklbw %%mm7, %%mm7\n\t" /* FF000000 -> mm7 */ - "pcmpeqb %%mm4, %%mm4\n\t" /* FFFFFFFF -> mm4 */ - "movq %%mm4, %%mm3\n\t" /* FFFFFFFF -> mm3 (for later) */ - "pxor %%mm4, %%mm7\n\t" /* 00FFFFFF -> mm7 (mult mask) */ - - /* form channel masks */ - "movq %%mm7, %%mm4\n\t" /* 00FFFFFF -> mm4 */ - "packsswb %%mm6, %%mm4\n\t" /* 00000FFF -> mm4 (channel mask) */ - "packsswb %%mm6, %%mm3\n\t" /* 0000FFFF -> mm3 */ - "pxor %%mm4, %%mm3\n\t" /* 0000F000 -> mm3 (~channel mask) */ - - /* get alpha channel shift */ - "movd %1, %%mm5\n\t" /* Ashift -> mm5 */ - - : /* nothing */ : "m" (sf->Amask), "m" (sf->Ashift) ); - - while(height--) { - + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + SDL_PixelFormat *sf = info->src; + Uint32 amask = sf->Amask; + + __asm__ ( + /* make mm6 all zeros. */ + "pxor %%mm6, %%mm6\n" + /* Make a mask to preserve the alpha. */ + "movd %0, %%mm7\n\t" /* 0000F000 -> mm7 */ + "punpcklbw %%mm7, %%mm7\n\t" /* FF000000 -> mm7 */ + "pcmpeqb %%mm4, %%mm4\n\t" /* FFFFFFFF -> mm4 */ + "movq %%mm4, %%mm3\n\t" /* FFFFFFFF -> mm3 (for later) */ + "pxor %%mm4, %%mm7\n\t" /* 00FFFFFF -> mm7 (mult mask) */ + /* form channel masks */ + "movq %%mm7, %%mm4\n\t" /* 00FFFFFF -> mm4 */ + "packsswb %%mm6, %%mm4\n\t" /* 00000FFF -> mm4 (channel mask) */ + "packsswb %%mm6, %%mm3\n\t" /* 0000FFFF -> mm3 */ + "pxor %%mm4, %%mm3\n\t" /* 0000F000 -> mm3 (~channel mask) */ + /* get alpha channel shift */ + "movd %1, %%mm5\n\t" /* Ashift -> mm5 */ + : /* nothing */ : "m" (sf->Amask), "m" (sf->Ashift)); + + while (height--) { + + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 alpha; @@ -1662,39 +1725,41 @@ inline static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info) ++srcp; ++dstp; }, width); - srcp += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } - __asm__ ( - "emms\n" - : ); + __asm__ ("emms\n":); } + /* End GCC_ASMBLIT*/ #elif MSVC_ASMBLIT /* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */ -static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info) +static void +BlitRGBtoRGBPixelAlphaMMX3DNOW (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint32 *dstp = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip >> 2; - SDL_PixelFormat* sf = info->src; - Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; - Uint32 amask = sf->Amask; - Uint32 ashift = sf->Ashift; - Uint64 multmask; - - __m64 src1, dst1, mm_alpha, mm_zero, dmask; - - mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ - multmask = ~(0xFFFFi64 << (ashift * 2)); - dmask = *(__m64*) &multmask; /* dst alpha mask -> dmask */ - - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint32 *dstp = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip >> 2; + SDL_PixelFormat *sf = info->src; + Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; + Uint32 amask = sf->Amask; + Uint32 ashift = sf->Ashift; + Uint64 multmask; + + __m64 src1, dst1, mm_alpha, mm_zero, dmask; + + mm_zero = _mm_setzero_si64 (); /* 0 -> mm_zero */ + multmask = ~(0xFFFFi 64 << (ashift * 2)); + dmask = *(__m64 *) & multmask; /* dst alpha mask -> dmask */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 alpha; @@ -1732,11 +1797,13 @@ static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info) ++srcp; ++dstp; }, width); - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + _mm_empty (); } + /* End MSVC_ASMBLIT */ #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */ @@ -1752,138 +1819,141 @@ static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info) (((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \ + (s & d & (~(mask | mask << 16)))) -static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask) +static void +Blit16to16SurfaceAlpha128 (SDL_BlitInfo * info, Uint16 mask) { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip >> 1; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - - while(height--) { - if(((uintptr_t)srcp ^ (uintptr_t)dstp) & 2) { - /* - * Source and destination not aligned, pipeline it. - * This is mostly a win for big blits but no loss for - * small ones - */ - Uint32 prev_sw; - int w = width; - - /* handle odd destination */ - if((uintptr_t)dstp & 2) { - Uint16 d = *dstp, s = *srcp; - *dstp = BLEND16_50(d, s, mask); - dstp++; - srcp++; - w--; - } - srcp++; /* srcp is now 32-bit aligned */ - - /* bootstrap pipeline with first halfword */ - prev_sw = ((Uint32 *)srcp)[-1]; - - while(w > 1) { - Uint32 sw, dw, s; - sw = *(Uint32 *)srcp; - dw = *(Uint32 *)dstp; + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip >> 1; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + + while (height--) { + if (((uintptr_t) srcp ^ (uintptr_t) dstp) & 2) { + /* + * Source and destination not aligned, pipeline it. + * This is mostly a win for big blits but no loss for + * small ones + */ + Uint32 prev_sw; + int w = width; + + /* handle odd destination */ + if ((uintptr_t) dstp & 2) { + Uint16 d = *dstp, s = *srcp; + *dstp = BLEND16_50 (d, s, mask); + dstp++; + srcp++; + w--; + } + srcp++; /* srcp is now 32-bit aligned */ + + /* bootstrap pipeline with first halfword */ + prev_sw = ((Uint32 *) srcp)[-1]; + + while (w > 1) { + Uint32 sw, dw, s; + sw = *(Uint32 *) srcp; + dw = *(Uint32 *) dstp; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - s = (prev_sw << 16) + (sw >> 16); + s = (prev_sw << 16) + (sw >> 16); #else - s = (prev_sw >> 16) + (sw << 16); + s = (prev_sw >> 16) + (sw << 16); #endif - prev_sw = sw; - *(Uint32 *)dstp = BLEND2x16_50(dw, s, mask); - dstp += 2; - srcp += 2; - w -= 2; - } - - /* final pixel if any */ - if(w) { - Uint16 d = *dstp, s; + prev_sw = sw; + *(Uint32 *) dstp = BLEND2x16_50 (dw, s, mask); + dstp += 2; + srcp += 2; + w -= 2; + } + + /* final pixel if any */ + if (w) { + Uint16 d = *dstp, s; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - s = (Uint16)prev_sw; + s = (Uint16) prev_sw; #else - s = (Uint16)(prev_sw >> 16); + s = (Uint16) (prev_sw >> 16); #endif - *dstp = BLEND16_50(d, s, mask); - srcp++; - dstp++; - } - srcp += srcskip - 1; - dstp += dstskip; - } else { - /* source and destination are aligned */ - int w = width; - - /* first odd pixel? */ - if((uintptr_t)srcp & 2) { - Uint16 d = *dstp, s = *srcp; - *dstp = BLEND16_50(d, s, mask); - srcp++; - dstp++; - w--; - } - /* srcp and dstp are now 32-bit aligned */ - - while(w > 1) { - Uint32 sw = *(Uint32 *)srcp; - Uint32 dw = *(Uint32 *)dstp; - *(Uint32 *)dstp = BLEND2x16_50(dw, sw, mask); - srcp += 2; - dstp += 2; - w -= 2; - } - - /* last odd pixel? */ - if(w) { - Uint16 d = *dstp, s = *srcp; - *dstp = BLEND16_50(d, s, mask); - srcp++; - dstp++; - } - srcp += srcskip; - dstp += dstskip; - } - } + *dstp = BLEND16_50 (d, s, mask); + srcp++; + dstp++; + } + srcp += srcskip - 1; + dstp += dstskip; + } else { + /* source and destination are aligned */ + int w = width; + + /* first odd pixel? */ + if ((uintptr_t) srcp & 2) { + Uint16 d = *dstp, s = *srcp; + *dstp = BLEND16_50 (d, s, mask); + srcp++; + dstp++; + w--; + } + /* srcp and dstp are now 32-bit aligned */ + + while (w > 1) { + Uint32 sw = *(Uint32 *) srcp; + Uint32 dw = *(Uint32 *) dstp; + *(Uint32 *) dstp = BLEND2x16_50 (dw, sw, mask); + srcp += 2; + dstp += 2; + w -= 2; + } + + /* last odd pixel? */ + if (w) { + Uint16 d = *dstp, s = *srcp; + *dstp = BLEND16_50 (d, s, mask); + srcp++; + dstp++; + } + srcp += srcskip; + dstp += dstskip; + } + } } #if GCC_ASMBLIT /* fast RGB565->RGB565 blending with surface alpha */ -static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info) +static void +Blit565to565SurfaceAlphaMMX (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */ - if(alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xf7de); - } else { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip >> 1; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - Uint32 s, d; - Uint8 load[8]; - - alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */ - *(Uint64 *)load = alpha; - alpha >>= 3; /* downscale alpha to 5 bits */ - - movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */ - punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */ - punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */ - /* position alpha to allow for mullo and mulhi on diff channels - to reduce the number of operations */ - psllq_i2r(3, mm0); - - /* Setup the 565 color channel masks */ - *(Uint64 *)load = 0x07E007E007E007E0ULL; - movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */ - *(Uint64 *)load = 0x001F001F001F001FULL; - movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */ - while(height--) { + unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */ + if (alpha == 128) { + Blit16to16SurfaceAlpha128 (info, 0xf7de); + } else { + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip >> 1; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + Uint32 s, d; + Uint8 load[8]; + + alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ + *(Uint64 *) load = alpha; + alpha >>= 3; /* downscale alpha to 5 bits */ + + movq_m2r (*load, mm0); /* alpha(0000000A) -> mm0 */ + punpcklwd_r2r (mm0, mm0); /* 00000A0A -> mm0 */ + punpcklwd_r2r (mm0, mm0); /* 0A0A0A0A -> mm0 */ + /* position alpha to allow for mullo and mulhi on diff channels + to reduce the number of operations */ + psllq_i2r (3, mm0); + + /* Setup the 565 color channel masks */ + *(Uint64 *) load = 0x07E007E007E007E0ULL; + movq_m2r (*load, mm4); /* MASKGREEN -> mm4 */ + *(Uint64 *) load = 0x001F001F001F001FULL; + movq_m2r (*load, mm7); /* MASKBLUE -> mm7 */ + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP_QUATRO2( { s = *srcp++; @@ -1983,46 +2053,49 @@ static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info) srcp += 4; dstp += 4; }, width); - srcp += srcskip; - dstp += dstskip; - } - emms(); - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + emms (); + } } /* fast RGB555->RGB555 blending with surface alpha */ -static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info) +static void +Blit555to555SurfaceAlphaMMX (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */ - if(alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xfbde); - } else { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip >> 1; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - Uint32 s, d; - Uint8 load[8]; - - alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */ - *(Uint64 *)load = alpha; - alpha >>= 3; /* downscale alpha to 5 bits */ - - movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */ - punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */ - punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */ - /* position alpha to allow for mullo and mulhi on diff channels - to reduce the number of operations */ - psllq_i2r(3, mm0); - - /* Setup the 555 color channel masks */ - *(Uint64 *)load = 0x03E003E003E003E0ULL; - movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */ - *(Uint64 *)load = 0x001F001F001F001FULL; - movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */ - while(height--) { + unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */ + if (alpha == 128) { + Blit16to16SurfaceAlpha128 (info, 0xfbde); + } else { + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip >> 1; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + Uint32 s, d; + Uint8 load[8]; + + alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ + *(Uint64 *) load = alpha; + alpha >>= 3; /* downscale alpha to 5 bits */ + + movq_m2r (*load, mm0); /* alpha(0000000A) -> mm0 */ + punpcklwd_r2r (mm0, mm0); /* 00000A0A -> mm0 */ + punpcklwd_r2r (mm0, mm0); /* 0A0A0A0A -> mm0 */ + /* position alpha to allow for mullo and mulhi on diff channels + to reduce the number of operations */ + psllq_i2r (3, mm0); + + /* Setup the 555 color channel masks */ + *(Uint64 *) load = 0x03E003E003E003E0ULL; + movq_m2r (*load, mm4); /* MASKGREEN -> mm4 */ + *(Uint64 *) load = 0x001F001F001F001FULL; + movq_m2r (*load, mm7); /* MASKBLUE -> mm7 */ + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP_QUATRO2( { s = *srcp++; @@ -2126,48 +2199,52 @@ static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info) srcp += 4; dstp += 4; - }, width); - srcp += srcskip; - dstp += dstskip; - } - emms(); - } + }, width); + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + emms (); + } } + /* End GCC_ASMBLIT */ #elif MSVC_ASMBLIT /* fast RGB565->RGB565 blending with surface alpha */ -static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info) +static void +Blit565to565SurfaceAlphaMMX (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; - if(alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xf7de); - } else { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip >> 1; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - Uint32 s, d; - - __m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha; - - alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */ - mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */ - alpha >>= 3; /* downscale alpha to 5 bits */ - - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ - /* position alpha to allow for mullo and mulhi on diff channels - to reduce the number of operations */ - mm_alpha = _mm_slli_si64(mm_alpha, 3); - - /* Setup the 565 color channel masks */ - gmask = _mm_set_pi32(0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */ - bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ - - while(height--) { + unsigned alpha = info->src->alpha; + if (alpha == 128) { + Blit16to16SurfaceAlpha128 (info, 0xf7de); + } else { + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip >> 1; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + Uint32 s, d; + + __m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha; + + alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ + mm_alpha = _mm_set_pi32 (0, alpha); /* 0000000A -> mm_alpha */ + alpha >>= 3; /* downscale alpha to 5 bits */ + + mm_alpha = _mm_unpacklo_pi16 (mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ + mm_alpha = _mm_unpacklo_pi32 (mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ + /* position alpha to allow for mullo and mulhi on diff channels + to reduce the number of operations */ + mm_alpha = _mm_slli_si64 (mm_alpha, 3); + + /* Setup the 565 color channel masks */ + gmask = _mm_set_pi32 (0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */ + bmask = _mm_set_pi32 (0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP_QUATRO2( { s = *srcp++; @@ -2262,47 +2339,50 @@ static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info) srcp += 4; dstp += 4; - }, width); - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); - } + }, width); + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + _mm_empty (); + } } /* fast RGB555->RGB555 blending with surface alpha */ -static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info) +static void +Blit555to555SurfaceAlphaMMX (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; - if(alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xfbde); - } else { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip >> 1; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - Uint32 s, d; - - __m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha; - - alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */ - mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */ - alpha >>= 3; /* downscale alpha to 5 bits */ - - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ - /* position alpha to allow for mullo and mulhi on diff channels - to reduce the number of operations */ - mm_alpha = _mm_slli_si64(mm_alpha, 3); - - /* Setup the 555 color channel masks */ - rmask = _mm_set_pi32(0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */ - gmask = _mm_set_pi32(0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */ - bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ - - while(height--) { + unsigned alpha = info->src->alpha; + if (alpha == 128) { + Blit16to16SurfaceAlpha128 (info, 0xfbde); + } else { + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip >> 1; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + Uint32 s, d; + + __m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha; + + alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ + mm_alpha = _mm_set_pi32 (0, alpha); /* 0000000A -> mm_alpha */ + alpha >>= 3; /* downscale alpha to 5 bits */ + + mm_alpha = _mm_unpacklo_pi16 (mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ + mm_alpha = _mm_unpacklo_pi32 (mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ + /* position alpha to allow for mullo and mulhi on diff channels + to reduce the number of operations */ + mm_alpha = _mm_slli_si64 (mm_alpha, 3); + + /* Setup the 555 color channel masks */ + rmask = _mm_set_pi32 (0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */ + gmask = _mm_set_pi32 (0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */ + bmask = _mm_set_pi32 (0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP_QUATRO2( { s = *srcp++; @@ -2397,31 +2477,34 @@ static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info) srcp += 4; dstp += 4; - }, width); - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); - } + }, width); + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + _mm_empty (); + } } #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */ /* fast RGB565->RGB565 blending with surface alpha */ -static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info) +static void +Blit565to565SurfaceAlpha (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; - if(alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xf7de); - } else { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip >> 1; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - alpha >>= 3; /* downscale alpha to 5 bits */ - - while(height--) { + unsigned alpha = info->src->alpha; + if (alpha == 128) { + Blit16to16SurfaceAlpha128 (info, 0xf7de); + } else { + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip >> 1; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + alpha >>= 3; /* downscale alpha to 5 bits */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp++; Uint32 d = *dstp; @@ -2436,28 +2519,31 @@ static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info) d &= 0x07e0f81f; *dstp++ = (Uint16)(d | d >> 16); }, width); - srcp += srcskip; - dstp += dstskip; - } - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + } } /* fast RGB555->RGB555 blending with surface alpha */ -static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info) +static void +Blit555to555SurfaceAlpha (SDL_BlitInfo * info) { - unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */ - if(alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xfbde); - } else { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip >> 1; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - alpha >>= 3; /* downscale alpha to 5 bits */ - - while(height--) { + unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */ + if (alpha == 128) { + Blit16to16SurfaceAlpha128 (info, 0xfbde); + } else { + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip >> 1; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + alpha >>= 3; /* downscale alpha to 5 bits */ + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp++; Uint32 d = *dstp; @@ -2472,23 +2558,26 @@ static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info) d &= 0x03e07c1f; *dstp++ = (Uint16)(d | d >> 16); }, width); - srcp += srcskip; - dstp += dstskip; - } - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } + } } /* fast ARGB8888->RGB565 blending with pixel alpha */ -static void BlitARGBto565PixelAlpha(SDL_BlitInfo *info) +static void +BlitARGBto565PixelAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp; unsigned alpha = s >> 27; /* downscale alpha to 5 bits */ @@ -2516,22 +2605,25 @@ static void BlitARGBto565PixelAlpha(SDL_BlitInfo *info) srcp++; dstp++; }, width); - srcp += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } } /* fast ARGB8888->RGB555 blending with pixel alpha */ -static void BlitARGBto555PixelAlpha(SDL_BlitInfo *info) +static void +BlitARGBto555PixelAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *srcp = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip >> 2; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip >> 1; - - while(height--) { + int width = info->d_width; + int height = info->d_height; + Uint32 *srcp = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip >> 2; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip >> 1; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4({ unsigned alpha; Uint32 s = *srcp; @@ -2560,29 +2652,32 @@ static void BlitARGBto555PixelAlpha(SDL_BlitInfo *info) srcp++; dstp++; }, width); - srcp += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } } /* General (slow) N->N blending with per-surface alpha */ -static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info) +static void +BlitNtoNSurfaceAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - int srcbpp = srcfmt->BytesPerPixel; - int dstbpp = dstfmt->BytesPerPixel; - unsigned sA = srcfmt->alpha; - unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; - - if(sA) { - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + int srcbpp = srcfmt->BytesPerPixel; + int dstbpp = dstfmt->BytesPerPixel; + unsigned sA = srcfmt->alpha; + unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; + + if (sA) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4( { Uint32 Pixel; @@ -2600,30 +2695,33 @@ static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info) dst += dstbpp; }, width); - src += srcskip; - dst += dstskip; - } - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } + } } /* General (slow) colorkeyed N->N blending with per-surface alpha */ -static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info) +static void +BlitNtoNSurfaceAlphaKey (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - Uint32 ckey = srcfmt->colorkey; - int srcbpp = srcfmt->BytesPerPixel; - int dstbpp = dstfmt->BytesPerPixel; - unsigned sA = srcfmt->alpha; - unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + Uint32 ckey = srcfmt->colorkey; + int srcbpp = srcfmt->BytesPerPixel; + int dstbpp = dstfmt->BytesPerPixel; + unsigned sA = srcfmt->alpha; + unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4( { Uint32 Pixel; @@ -2644,36 +2742,39 @@ static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info) dst += dstbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } /* General (slow) N->N blending with pixel alpha */ -static void BlitNtoNPixelAlpha(SDL_BlitInfo *info) +static void +BlitNtoNPixelAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - - int srcbpp; - int dstbpp; - - /* Set up some basic variables */ - srcbpp = srcfmt->BytesPerPixel; - dstbpp = dstfmt->BytesPerPixel; - - /* FIXME: for 8bpp source alpha, this doesn't get opaque values - quite right. for <8bpp source alpha, it gets them very wrong - (check all macros!) - It is unclear whether there is a good general solution that doesn't - need a branch (or a divide). */ - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + + int srcbpp; + int dstbpp; + + /* Set up some basic variables */ + srcbpp = srcfmt->BytesPerPixel; + dstbpp = dstfmt->BytesPerPixel; + + /* FIXME: for 8bpp source alpha, this doesn't get opaque values + quite right. for <8bpp source alpha, it gets them very wrong + (check all macros!) + It is unclear whether there is a good general solution that doesn't + need a branch (or a divide). */ + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP4( { Uint32 Pixel; @@ -2695,160 +2796,155 @@ static void BlitNtoNPixelAlpha(SDL_BlitInfo *info) dst += dstbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } -SDL_loblit SDL_CalculateAlphaBlit(SDL_Surface *surface, int blit_index) +SDL_loblit +SDL_CalculateAlphaBlit (SDL_Surface * surface, int blit_index) { SDL_PixelFormat *sf = surface->format; SDL_PixelFormat *df = surface->map->dst->format; - if(sf->Amask == 0) { - if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { - if(df->BytesPerPixel == 1) - return BlitNto1SurfaceAlphaKey; - else + if (sf->Amask == 0) { + if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { + if (df->BytesPerPixel == 1) + return BlitNto1SurfaceAlphaKey; + else #if SDL_ALTIVEC_BLITTERS - if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && - !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec()) - return Blit32to32SurfaceAlphaKeyAltivec; - else + if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && + !(surface->map->dst->flags & SDL_HWSURFACE) + && SDL_HasAltiVec ()) + return Blit32to32SurfaceAlphaKeyAltivec; + else #endif - return BlitNtoNSurfaceAlphaKey; - } else { - /* Per-surface alpha blits */ - switch(df->BytesPerPixel) { - case 1: - return BlitNto1SurfaceAlpha; - - case 2: - if(surface->map->identity) { - if(df->Gmask == 0x7e0) - { + return BlitNtoNSurfaceAlphaKey; + } else { + /* Per-surface alpha blits */ + switch (df->BytesPerPixel) { + case 1: + return BlitNto1SurfaceAlpha; + + case 2: + if (surface->map->identity) { + if (df->Gmask == 0x7e0) { #if MMX_ASMBLIT - if(SDL_HasMMX()) - return Blit565to565SurfaceAlphaMMX; - else + if (SDL_HasMMX ()) + return Blit565to565SurfaceAlphaMMX; + else #endif - return Blit565to565SurfaceAlpha; - } - else if(df->Gmask == 0x3e0) - { + return Blit565to565SurfaceAlpha; + } else if (df->Gmask == 0x3e0) { #if MMX_ASMBLIT - if(SDL_HasMMX()) - return Blit555to555SurfaceAlphaMMX; - else + if (SDL_HasMMX ()) + return Blit555to555SurfaceAlphaMMX; + else #endif - return Blit555to555SurfaceAlpha; - } - } - return BlitNtoNSurfaceAlpha; - - case 4: - if(sf->Rmask == df->Rmask - && sf->Gmask == df->Gmask - && sf->Bmask == df->Bmask - && sf->BytesPerPixel == 4) - { + return Blit555to555SurfaceAlpha; + } + } + return BlitNtoNSurfaceAlpha; + + case 4: + if (sf->Rmask == df->Rmask + && sf->Gmask == df->Gmask + && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { #if MMX_ASMBLIT - if(sf->Rshift % 8 == 0 - && sf->Gshift % 8 == 0 - && sf->Bshift % 8 == 0 - && SDL_HasMMX()) - return BlitRGBtoRGBSurfaceAlphaMMX; + if (sf->Rshift % 8 == 0 + && sf->Gshift % 8 == 0 + && sf->Bshift % 8 == 0 && SDL_HasMMX ()) + return BlitRGBtoRGBSurfaceAlphaMMX; #endif - if((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) - { + if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) { #if SDL_ALTIVEC_BLITTERS - if(!(surface->map->dst->flags & SDL_HWSURFACE) - && SDL_HasAltiVec()) - return BlitRGBtoRGBSurfaceAlphaAltivec; + if (!(surface->map->dst->flags & SDL_HWSURFACE) + && SDL_HasAltiVec ()) + return BlitRGBtoRGBSurfaceAlphaAltivec; #endif - return BlitRGBtoRGBSurfaceAlpha; - } - } + return BlitRGBtoRGBSurfaceAlpha; + } + } #if SDL_ALTIVEC_BLITTERS - if((sf->BytesPerPixel == 4) && - !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec()) - return Blit32to32SurfaceAlphaAltivec; - else + if ((sf->BytesPerPixel == 4) && + !(surface->map->dst->flags & SDL_HWSURFACE) + && SDL_HasAltiVec ()) + return Blit32to32SurfaceAlphaAltivec; + else #endif - return BlitNtoNSurfaceAlpha; + return BlitNtoNSurfaceAlpha; - case 3: - default: - return BlitNtoNSurfaceAlpha; - } - } + case 3: + default: + return BlitNtoNSurfaceAlpha; + } + } } else { - /* Per-pixel alpha blits */ - switch(df->BytesPerPixel) { - case 1: - return BlitNto1PixelAlpha; + /* Per-pixel alpha blits */ + switch (df->BytesPerPixel) { + case 1: + return BlitNto1PixelAlpha; - case 2: + case 2: #if SDL_ALTIVEC_BLITTERS - if(sf->BytesPerPixel == 4 && !(surface->map->dst->flags & SDL_HWSURFACE) && - df->Gmask == 0x7e0 && - df->Bmask == 0x1f && SDL_HasAltiVec()) - return Blit32to565PixelAlphaAltivec; - else + if (sf->BytesPerPixel == 4 + && !(surface->map->dst->flags & SDL_HWSURFACE) + && df->Gmask == 0x7e0 && df->Bmask == 0x1f + && SDL_HasAltiVec ()) + return Blit32to565PixelAlphaAltivec; + else #endif - if(sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 - && sf->Gmask == 0xff00 - && ((sf->Rmask == 0xff && df->Rmask == 0x1f) - || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { - if(df->Gmask == 0x7e0) - return BlitARGBto565PixelAlpha; - else if(df->Gmask == 0x3e0) - return BlitARGBto555PixelAlpha; - } - return BlitNtoNPixelAlpha; + if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 + && sf->Gmask == 0xff00 + && ((sf->Rmask == 0xff && df->Rmask == 0x1f) + || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { + if (df->Gmask == 0x7e0) + return BlitARGBto565PixelAlpha; + else if (df->Gmask == 0x3e0) + return BlitARGBto555PixelAlpha; + } + return BlitNtoNPixelAlpha; - case 4: - if(sf->Rmask == df->Rmask - && sf->Gmask == df->Gmask - && sf->Bmask == df->Bmask - && sf->BytesPerPixel == 4) - { + case 4: + if (sf->Rmask == df->Rmask + && sf->Gmask == df->Gmask + && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { #if MMX_ASMBLIT - if(sf->Rshift % 8 == 0 - && sf->Gshift % 8 == 0 - && sf->Bshift % 8 == 0 - && sf->Ashift % 8 == 0 - && sf->Aloss == 0) - { - if(SDL_Has3DNow()) - return BlitRGBtoRGBPixelAlphaMMX3DNOW; - if(SDL_HasMMX()) - return BlitRGBtoRGBPixelAlphaMMX; - } + if (sf->Rshift % 8 == 0 + && sf->Gshift % 8 == 0 + && sf->Bshift % 8 == 0 + && sf->Ashift % 8 == 0 && sf->Aloss == 0) { + if (SDL_Has3DNow ()) + return BlitRGBtoRGBPixelAlphaMMX3DNOW; + if (SDL_HasMMX ()) + return BlitRGBtoRGBPixelAlphaMMX; + } #endif - if(sf->Amask == 0xff000000) - { + if (sf->Amask == 0xff000000) { #if SDL_ALTIVEC_BLITTERS - if(!(surface->map->dst->flags & SDL_HWSURFACE) - && SDL_HasAltiVec()) - return BlitRGBtoRGBPixelAlphaAltivec; + if (!(surface->map->dst->flags & SDL_HWSURFACE) + && SDL_HasAltiVec ()) + return BlitRGBtoRGBPixelAlphaAltivec; #endif - return BlitRGBtoRGBPixelAlpha; - } - } + return BlitRGBtoRGBPixelAlpha; + } + } #if SDL_ALTIVEC_BLITTERS - if (sf->Amask && sf->BytesPerPixel == 4 && - !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec()) - return Blit32to32PixelAlphaAltivec; - else + if (sf->Amask && sf->BytesPerPixel == 4 && + !(surface->map->dst->flags & SDL_HWSURFACE) + && SDL_HasAltiVec ()) + return Blit32to32PixelAlphaAltivec; + else #endif - return BlitNtoNPixelAlpha; + return BlitNtoNPixelAlpha; - case 3: - default: - return BlitNtoNPixelAlpha; - } + case 3: + default: + return BlitNtoNPixelAlpha; + } } } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index 91d66ee6d..c9d655400 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -38,20 +38,23 @@ #define assert(X) #ifdef __MACOSX__ #include -static size_t GetL3CacheSize( void ) +static size_t +GetL3CacheSize (void) { const char key[] = "hw.l3cachesize"; u_int64_t result = 0; - size_t typeSize = sizeof( result ); + size_t typeSize = sizeof (result); - int err = sysctlbyname( key, &result, &typeSize, NULL, 0 ); - if( 0 != err ) return 0; + int err = sysctlbyname (key, &result, &typeSize, NULL, 0); + if (0 != err) + return 0; return result; } #else -static size_t GetL3CacheSize( void ) +static size_t +GetL3CacheSize (void) { /* XXX: Just guess G4 */ return 2097152; @@ -59,14 +62,14 @@ static size_t GetL3CacheSize( void ) #endif /* __MACOSX__ */ #if (defined(__MACOSX__) && (__GNUC__ < 4)) - #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ +#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p ) - #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ +#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ (vector unsigned short) ( a,b,c,d,e,f,g,h ) #else - #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ +#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p } - #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ +#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ (vector unsigned short) { a,b,c,d,e,f,g,h } #endif @@ -101,11 +104,12 @@ static size_t GetL3CacheSize( void ) : vec_add(vec_lvsl(8, src), vec_splat_u8(8))) /* Calculate the permute vector used for 32->32 swizzling */ -static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt, - const SDL_PixelFormat *dstfmt) +static vector unsigned char +calc_swizzle32 (const SDL_PixelFormat * srcfmt, + const SDL_PixelFormat * dstfmt) { /* - * We have to assume that the bits that aren't used by other + * We have to assume that the bits that aren't used by other * colors is alpha, and it's one complete byte, since some formats * leave alpha with a zero mask, but we should still swizzle the bits. */ @@ -115,62 +119,68 @@ static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt, 0, 0, 0, 0, 16, 8, 0, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, - 0, 0}; + 0, 0 + }; if (!srcfmt) { srcfmt = &default_pixel_format; } if (!dstfmt) { dstfmt = &default_pixel_format; } - const vector unsigned char plus = VECUINT8_LITERAL( - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x04, 0x04, 0x04, - 0x08, 0x08, 0x08, 0x08, - 0x0C, 0x0C, 0x0C, 0x0C ); + const vector unsigned char plus = + VECUINT8_LITERAL (0x00, 0x00, 0x00, 0x00, + 0x04, 0x04, 0x04, 0x04, + 0x08, 0x08, 0x08, 0x08, + 0x0C, 0x0C, 0x0C, 0x0C); vector unsigned char vswiz; vector unsigned int srcvec; #define RESHIFT(X) (3 - ((X) >> 3)) - Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift); - Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift); - Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift); + Uint32 rmask = RESHIFT (srcfmt->Rshift) << (dstfmt->Rshift); + Uint32 gmask = RESHIFT (srcfmt->Gshift) << (dstfmt->Gshift); + Uint32 bmask = RESHIFT (srcfmt->Bshift) << (dstfmt->Bshift); Uint32 amask; /* Use zero for alpha if either surface doesn't have alpha */ if (dstfmt->Amask) { - amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift); - } else { - amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF); - } -#undef RESHIFT - ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask); - vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0)); - return(vswiz); + amask = + ((srcfmt->Amask) ? RESHIFT (srcfmt->Ashift) : 0x10) << (dstfmt-> + Ashift); + } else { + amask = + 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ + 0xFFFFFFFF); + } +#undef RESHIFT + ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask); + vswiz = vec_add (plus, (vector unsigned char) vec_splat (srcvec, 0)); + return (vswiz); } -static void Blit_RGB888_RGB565(SDL_BlitInfo *info); -static void Blit_RGB888_RGB565Altivec(SDL_BlitInfo *info) { +static void Blit_RGB888_RGB565 (SDL_BlitInfo * info); +static void +Blit_RGB888_RGB565Altivec (SDL_BlitInfo * info) +{ int height = info->d_height; Uint8 *src = (Uint8 *) info->s_pixels; int srcskip = info->s_skip; Uint8 *dst = (Uint8 *) info->d_pixels; int dstskip = info->d_skip; SDL_PixelFormat *srcfmt = info->src; - vector unsigned char valpha = vec_splat_u8(0); - vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL); - vector unsigned char vgmerge = VECUINT8_LITERAL( - 0x00, 0x02, 0x00, 0x06, - 0x00, 0x0a, 0x00, 0x0e, - 0x00, 0x12, 0x00, 0x16, - 0x00, 0x1a, 0x00, 0x1e); - vector unsigned short v1 = vec_splat_u16(1); - vector unsigned short v3 = vec_splat_u16(3); - vector unsigned short v3f = VECUINT16_LITERAL( - 0x003f, 0x003f, 0x003f, 0x003f, - 0x003f, 0x003f, 0x003f, 0x003f); - vector unsigned short vfc = VECUINT16_LITERAL( - 0x00fc, 0x00fc, 0x00fc, 0x00fc, - 0x00fc, 0x00fc, 0x00fc, 0x00fc); - vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); + vector unsigned char valpha = vec_splat_u8 (0); + vector unsigned char vpermute = calc_swizzle32 (srcfmt, NULL); + vector unsigned char vgmerge = VECUINT8_LITERAL (0x00, 0x02, 0x00, 0x06, + 0x00, 0x0a, 0x00, 0x0e, + 0x00, 0x12, 0x00, 0x16, + 0x00, 0x1a, 0x00, 0x1e); + vector unsigned short v1 = vec_splat_u16 (1); + vector unsigned short v3 = vec_splat_u16 (3); + vector unsigned short v3f = + VECUINT16_LITERAL (0x003f, 0x003f, 0x003f, 0x003f, + 0x003f, 0x003f, 0x003f, 0x003f); + vector unsigned short vfc = + VECUINT16_LITERAL (0x00fc, 0x00fc, 0x00fc, 0x00fc, + 0x00fc, 0x00fc, 0x00fc, 0x00fc); + vector unsigned short vf800 = (vector unsigned short) vec_splat_u8 (-7); + vf800 = vec_sl (vf800, vec_splat_u16 (8)); while (height--) { vector unsigned char valigner; @@ -195,39 +205,42 @@ static void Blit_RGB888_RGB565Altivec(SDL_BlitInfo *info) { widthvar--; \ } - ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); + ONE_PIXEL_BLEND (((UNALIGNED_PTR (dst)) && (width)), width); /* After all that work, here's the vector part! */ - extrawidth = (width % 8); /* trailing unaligned stores */ + extrawidth = (width % 8); /* trailing unaligned stores */ width -= extrawidth; - vsrc = vec_ld(0, src); - valigner = VEC_ALIGNER(src); + vsrc = vec_ld (0, src); + valigner = VEC_ALIGNER (src); while (width) { vector unsigned short vpixel, vrpixel, vgpixel, vbpixel; vector unsigned int vsrc1, vsrc2; vector unsigned char vdst; - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - vsrc1 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute); + voverflow = vec_ld (15, src); + vsrc = vec_perm (vsrc, voverflow, valigner); + vsrc1 = (vector unsigned int) vec_perm (vsrc, valpha, vpermute); src += 16; vsrc = voverflow; - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - vsrc2 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute); + voverflow = vec_ld (15, src); + vsrc = vec_perm (vsrc, voverflow, valigner); + vsrc2 = (vector unsigned int) vec_perm (vsrc, valpha, vpermute); /* 1555 */ - vpixel = (vector unsigned short)vec_packpx(vsrc1, vsrc2); - vgpixel = (vector unsigned short)vec_perm(vsrc1, vsrc2, vgmerge); - vgpixel = vec_and(vgpixel, vfc); - vgpixel = vec_sl(vgpixel, v3); - vrpixel = vec_sl(vpixel, v1); - vrpixel = vec_and(vrpixel, vf800); - vbpixel = vec_and(vpixel, v3f); - vdst = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel); + vpixel = (vector unsigned short) vec_packpx (vsrc1, vsrc2); + vgpixel = + (vector unsigned short) vec_perm (vsrc1, vsrc2, vgmerge); + vgpixel = vec_and (vgpixel, vfc); + vgpixel = vec_sl (vgpixel, v3); + vrpixel = vec_sl (vpixel, v1); + vrpixel = vec_and (vrpixel, vf800); + vbpixel = vec_and (vpixel, v3f); + vdst = + vec_or ((vector unsigned char) vrpixel, + (vector unsigned char) vgpixel); /* 565 */ - vdst = vec_or(vdst, (vector unsigned char)vbpixel); - vec_st(vdst, 0, dst); + vdst = vec_or (vdst, (vector unsigned char) vbpixel); + vec_st (vdst, 0, dst); width -= 8; src += 16; @@ -235,20 +248,22 @@ static void Blit_RGB888_RGB565Altivec(SDL_BlitInfo *info) { vsrc = voverflow; } - assert(width == 0); + assert (width == 0); /* do scalar until we can align... */ - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND - src += srcskip; /* move to next row, accounting for pitch. */ + src += srcskip; /* move to next row, accounting for pitch. */ dst += dstskip; } } -static void Blit_RGB565_32Altivec(SDL_BlitInfo *info) { +static void +Blit_RGB565_32Altivec (SDL_BlitInfo * info) +{ int height = info->d_height; Uint8 *src = (Uint8 *) info->s_pixels; int srcskip = info->s_skip; @@ -260,67 +275,64 @@ static void Blit_RGB565_32Altivec(SDL_BlitInfo *info) { vector unsigned char valpha; vector unsigned char vpermute; vector unsigned short vf800; - vector unsigned int v8 = vec_splat_u32(8); - vector unsigned int v16 = vec_add(v8, v8); - vector unsigned short v2 = vec_splat_u16(2); - vector unsigned short v3 = vec_splat_u16(3); + vector unsigned int v8 = vec_splat_u32 (8); + vector unsigned int v16 = vec_add (v8, v8); + vector unsigned short v2 = vec_splat_u16 (2); + vector unsigned short v3 = vec_splat_u16 (3); /* - 0x10 - 0x1f is the alpha - 0x00 - 0x0e evens are the red - 0x01 - 0x0f odds are zero - */ - vector unsigned char vredalpha1 = VECUINT8_LITERAL( - 0x10, 0x00, 0x01, 0x01, - 0x10, 0x02, 0x01, 0x01, - 0x10, 0x04, 0x01, 0x01, - 0x10, 0x06, 0x01, 0x01 - ); - vector unsigned char vredalpha2 = (vector unsigned char) ( - vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16)) - ); + 0x10 - 0x1f is the alpha + 0x00 - 0x0e evens are the red + 0x01 - 0x0f odds are zero + */ + vector unsigned char vredalpha1 = + VECUINT8_LITERAL (0x10, 0x00, 0x01, 0x01, + 0x10, 0x02, 0x01, 0x01, + 0x10, 0x04, 0x01, 0x01, + 0x10, 0x06, 0x01, 0x01); + vector unsigned char vredalpha2 = + (vector unsigned + char) (vec_add ((vector unsigned int) vredalpha1, vec_sl (v8, v16)) + ); /* - 0x00 - 0x0f is ARxx ARxx ARxx ARxx - 0x11 - 0x0f odds are blue - */ - vector unsigned char vblue1 = VECUINT8_LITERAL( - 0x00, 0x01, 0x02, 0x11, - 0x04, 0x05, 0x06, 0x13, - 0x08, 0x09, 0x0a, 0x15, - 0x0c, 0x0d, 0x0e, 0x17 - ); - vector unsigned char vblue2 = (vector unsigned char)( - vec_add((vector unsigned int)vblue1, v8) - ); + 0x00 - 0x0f is ARxx ARxx ARxx ARxx + 0x11 - 0x0f odds are blue + */ + vector unsigned char vblue1 = VECUINT8_LITERAL (0x00, 0x01, 0x02, 0x11, + 0x04, 0x05, 0x06, 0x13, + 0x08, 0x09, 0x0a, 0x15, + 0x0c, 0x0d, 0x0e, 0x17); + vector unsigned char vblue2 = + (vector unsigned char) (vec_add ((vector unsigned int) vblue1, v8) + ); /* - 0x00 - 0x0f is ARxB ARxB ARxB ARxB - 0x10 - 0x0e evens are green - */ - vector unsigned char vgreen1 = VECUINT8_LITERAL( - 0x00, 0x01, 0x10, 0x03, - 0x04, 0x05, 0x12, 0x07, - 0x08, 0x09, 0x14, 0x0b, - 0x0c, 0x0d, 0x16, 0x0f - ); - vector unsigned char vgreen2 = (vector unsigned char)( - vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8)) - ); - - - assert(srcfmt->BytesPerPixel == 2); - assert(dstfmt->BytesPerPixel == 4); - - vf800 = (vector unsigned short)vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); + 0x00 - 0x0f is ARxB ARxB ARxB ARxB + 0x10 - 0x0e evens are green + */ + vector unsigned char vgreen1 = VECUINT8_LITERAL (0x00, 0x01, 0x10, 0x03, + 0x04, 0x05, 0x12, 0x07, + 0x08, 0x09, 0x14, 0x0b, + 0x0c, 0x0d, 0x16, 0x0f); + vector unsigned char vgreen2 = + (vector unsigned + char) (vec_add ((vector unsigned int) vgreen1, vec_sl (v8, v8)) + ); + + + assert (srcfmt->BytesPerPixel == 2); + assert (dstfmt->BytesPerPixel == 4); + + vf800 = (vector unsigned short) vec_splat_u8 (-7); + vf800 = vec_sl (vf800, vec_splat_u16 (8)); if (dstfmt->Amask && srcfmt->alpha) { - ((unsigned char *)&valpha)[0] = alpha = srcfmt->alpha; - valpha = vec_splat(valpha, 0); + ((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha; + valpha = vec_splat (valpha, 0); } else { alpha = 0; - valpha = vec_splat_u8(0); + valpha = vec_splat_u8 (0); } - vpermute = calc_swizzle32(NULL, dstfmt); + vpermute = calc_swizzle32 (NULL, dstfmt); while (height--) { vector unsigned char valigner; vector unsigned char voverflow; @@ -342,58 +354,64 @@ static void Blit_RGB565_32Altivec(SDL_BlitInfo *info) { dst += 4; \ widthvar--; \ } - ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); + ONE_PIXEL_BLEND (((UNALIGNED_PTR (dst)) && (width)), width); /* After all that work, here's the vector part! */ - extrawidth = (width % 8); /* trailing unaligned stores */ + extrawidth = (width % 8); /* trailing unaligned stores */ width -= extrawidth; - vsrc = vec_ld(0, src); - valigner = VEC_ALIGNER(src); + vsrc = vec_ld (0, src); + valigner = VEC_ALIGNER (src); while (width) { vector unsigned short vR, vG, vB; vector unsigned char vdst1, vdst2; - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - - vR = vec_and((vector unsigned short)vsrc, vf800); - vB = vec_sl((vector unsigned short)vsrc, v3); - vG = vec_sl(vB, v2); - - vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha1); - vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1); - vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1); - vdst1 = vec_perm(vdst1, valpha, vpermute); - vec_st(vdst1, 0, dst); - - vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha2); - vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2); - vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2); - vdst2 = vec_perm(vdst2, valpha, vpermute); - vec_st(vdst2, 16, dst); - + voverflow = vec_ld (15, src); + vsrc = vec_perm (vsrc, voverflow, valigner); + + vR = vec_and ((vector unsigned short) vsrc, vf800); + vB = vec_sl ((vector unsigned short) vsrc, v3); + vG = vec_sl (vB, v2); + + vdst1 = + (vector unsigned char) vec_perm ((vector unsigned char) vR, + valpha, vredalpha1); + vdst1 = vec_perm (vdst1, (vector unsigned char) vB, vblue1); + vdst1 = vec_perm (vdst1, (vector unsigned char) vG, vgreen1); + vdst1 = vec_perm (vdst1, valpha, vpermute); + vec_st (vdst1, 0, dst); + + vdst2 = + (vector unsigned char) vec_perm ((vector unsigned char) vR, + valpha, vredalpha2); + vdst2 = vec_perm (vdst2, (vector unsigned char) vB, vblue2); + vdst2 = vec_perm (vdst2, (vector unsigned char) vG, vgreen2); + vdst2 = vec_perm (vdst2, valpha, vpermute); + vec_st (vdst2, 16, dst); + width -= 8; dst += 32; src += 16; vsrc = voverflow; } - assert(width == 0); + assert (width == 0); /* do scalar until we can align... */ - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND - src += srcskip; /* move to next row, accounting for pitch. */ + src += srcskip; /* move to next row, accounting for pitch. */ dst += dstskip; } } -static void Blit_RGB555_32Altivec(SDL_BlitInfo *info) { +static void +Blit_RGB555_32Altivec (SDL_BlitInfo * info) +{ int height = info->d_height; Uint8 *src = (Uint8 *) info->s_pixels; int srcskip = info->s_skip; @@ -405,67 +423,64 @@ static void Blit_RGB555_32Altivec(SDL_BlitInfo *info) { vector unsigned char valpha; vector unsigned char vpermute; vector unsigned short vf800; - vector unsigned int v8 = vec_splat_u32(8); - vector unsigned int v16 = vec_add(v8, v8); - vector unsigned short v1 = vec_splat_u16(1); - vector unsigned short v3 = vec_splat_u16(3); + vector unsigned int v8 = vec_splat_u32 (8); + vector unsigned int v16 = vec_add (v8, v8); + vector unsigned short v1 = vec_splat_u16 (1); + vector unsigned short v3 = vec_splat_u16 (3); /* - 0x10 - 0x1f is the alpha - 0x00 - 0x0e evens are the red - 0x01 - 0x0f odds are zero - */ - vector unsigned char vredalpha1 = VECUINT8_LITERAL( - 0x10, 0x00, 0x01, 0x01, - 0x10, 0x02, 0x01, 0x01, - 0x10, 0x04, 0x01, 0x01, - 0x10, 0x06, 0x01, 0x01 - ); - vector unsigned char vredalpha2 = (vector unsigned char)( - vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16)) - ); + 0x10 - 0x1f is the alpha + 0x00 - 0x0e evens are the red + 0x01 - 0x0f odds are zero + */ + vector unsigned char vredalpha1 = + VECUINT8_LITERAL (0x10, 0x00, 0x01, 0x01, + 0x10, 0x02, 0x01, 0x01, + 0x10, 0x04, 0x01, 0x01, + 0x10, 0x06, 0x01, 0x01); + vector unsigned char vredalpha2 = + (vector unsigned + char) (vec_add ((vector unsigned int) vredalpha1, vec_sl (v8, v16)) + ); /* - 0x00 - 0x0f is ARxx ARxx ARxx ARxx - 0x11 - 0x0f odds are blue - */ - vector unsigned char vblue1 = VECUINT8_LITERAL( - 0x00, 0x01, 0x02, 0x11, - 0x04, 0x05, 0x06, 0x13, - 0x08, 0x09, 0x0a, 0x15, - 0x0c, 0x0d, 0x0e, 0x17 - ); - vector unsigned char vblue2 = (vector unsigned char)( - vec_add((vector unsigned int)vblue1, v8) - ); + 0x00 - 0x0f is ARxx ARxx ARxx ARxx + 0x11 - 0x0f odds are blue + */ + vector unsigned char vblue1 = VECUINT8_LITERAL (0x00, 0x01, 0x02, 0x11, + 0x04, 0x05, 0x06, 0x13, + 0x08, 0x09, 0x0a, 0x15, + 0x0c, 0x0d, 0x0e, 0x17); + vector unsigned char vblue2 = + (vector unsigned char) (vec_add ((vector unsigned int) vblue1, v8) + ); /* - 0x00 - 0x0f is ARxB ARxB ARxB ARxB - 0x10 - 0x0e evens are green - */ - vector unsigned char vgreen1 = VECUINT8_LITERAL( - 0x00, 0x01, 0x10, 0x03, - 0x04, 0x05, 0x12, 0x07, - 0x08, 0x09, 0x14, 0x0b, - 0x0c, 0x0d, 0x16, 0x0f - ); - vector unsigned char vgreen2 = (vector unsigned char)( - vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8)) - ); - - - assert(srcfmt->BytesPerPixel == 2); - assert(dstfmt->BytesPerPixel == 4); - - vf800 = (vector unsigned short)vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); + 0x00 - 0x0f is ARxB ARxB ARxB ARxB + 0x10 - 0x0e evens are green + */ + vector unsigned char vgreen1 = VECUINT8_LITERAL (0x00, 0x01, 0x10, 0x03, + 0x04, 0x05, 0x12, 0x07, + 0x08, 0x09, 0x14, 0x0b, + 0x0c, 0x0d, 0x16, 0x0f); + vector unsigned char vgreen2 = + (vector unsigned + char) (vec_add ((vector unsigned int) vgreen1, vec_sl (v8, v8)) + ); + + + assert (srcfmt->BytesPerPixel == 2); + assert (dstfmt->BytesPerPixel == 4); + + vf800 = (vector unsigned short) vec_splat_u8 (-7); + vf800 = vec_sl (vf800, vec_splat_u16 (8)); if (dstfmt->Amask && srcfmt->alpha) { - ((unsigned char *)&valpha)[0] = alpha = srcfmt->alpha; - valpha = vec_splat(valpha, 0); + ((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha; + valpha = vec_splat (valpha, 0); } else { alpha = 0; - valpha = vec_splat_u8(0); + valpha = vec_splat_u8 (0); } - vpermute = calc_swizzle32(NULL, dstfmt); + vpermute = calc_swizzle32 (NULL, dstfmt); while (height--) { vector unsigned char valigner; vector unsigned char voverflow; @@ -487,59 +502,64 @@ static void Blit_RGB555_32Altivec(SDL_BlitInfo *info) { dst += 4; \ widthvar--; \ } - ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); + ONE_PIXEL_BLEND (((UNALIGNED_PTR (dst)) && (width)), width); /* After all that work, here's the vector part! */ - extrawidth = (width % 8); /* trailing unaligned stores */ + extrawidth = (width % 8); /* trailing unaligned stores */ width -= extrawidth; - vsrc = vec_ld(0, src); - valigner = VEC_ALIGNER(src); + vsrc = vec_ld (0, src); + valigner = VEC_ALIGNER (src); while (width) { vector unsigned short vR, vG, vB; vector unsigned char vdst1, vdst2; - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - - vR = vec_and(vec_sl((vector unsigned short)vsrc,v1), vf800); - vB = vec_sl((vector unsigned short)vsrc, v3); - vG = vec_sl(vB, v3); - - vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha1); - vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1); - vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1); - vdst1 = vec_perm(vdst1, valpha, vpermute); - vec_st(vdst1, 0, dst); - - vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha2); - vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2); - vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2); - vdst2 = vec_perm(vdst2, valpha, vpermute); - vec_st(vdst2, 16, dst); - + voverflow = vec_ld (15, src); + vsrc = vec_perm (vsrc, voverflow, valigner); + + vR = vec_and (vec_sl ((vector unsigned short) vsrc, v1), vf800); + vB = vec_sl ((vector unsigned short) vsrc, v3); + vG = vec_sl (vB, v3); + + vdst1 = + (vector unsigned char) vec_perm ((vector unsigned char) vR, + valpha, vredalpha1); + vdst1 = vec_perm (vdst1, (vector unsigned char) vB, vblue1); + vdst1 = vec_perm (vdst1, (vector unsigned char) vG, vgreen1); + vdst1 = vec_perm (vdst1, valpha, vpermute); + vec_st (vdst1, 0, dst); + + vdst2 = + (vector unsigned char) vec_perm ((vector unsigned char) vR, + valpha, vredalpha2); + vdst2 = vec_perm (vdst2, (vector unsigned char) vB, vblue2); + vdst2 = vec_perm (vdst2, (vector unsigned char) vG, vgreen2); + vdst2 = vec_perm (vdst2, valpha, vpermute); + vec_st (vdst2, 16, dst); + width -= 8; dst += 32; src += 16; vsrc = voverflow; } - assert(width == 0); + assert (width == 0); /* do scalar until we can align... */ - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND - src += srcskip; /* move to next row, accounting for pitch. */ + src += srcskip; /* move to next row, accounting for pitch. */ dst += dstskip; } } -static void BlitNtoNKey(SDL_BlitInfo *info); -static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info); -static void Blit32to32KeyAltivec(SDL_BlitInfo *info) +static void BlitNtoNKey (SDL_BlitInfo * info); +static void BlitNtoNKeyCopyAlpha (SDL_BlitInfo * info); +static void +Blit32to32KeyAltivec (SDL_BlitInfo * info) { int height = info->d_height; Uint32 *srcp = (Uint32 *) info->s_pixels; @@ -551,35 +571,37 @@ static void Blit32to32KeyAltivec(SDL_BlitInfo *info) SDL_PixelFormat *dstfmt = info->dst; int dstbpp = dstfmt->BytesPerPixel; int copy_alpha = (srcfmt->Amask && dstfmt->Amask); - unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; + unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; - Uint32 ckey = info->src->colorkey; + Uint32 ckey = info->src->colorkey; vector unsigned int valpha; vector unsigned char vpermute; vector unsigned char vzero; vector unsigned int vckey; vector unsigned int vrgbmask; - vpermute = calc_swizzle32(srcfmt, dstfmt); + vpermute = calc_swizzle32 (srcfmt, dstfmt); if (info->d_width < 16) { - if(copy_alpha) { - BlitNtoNKeyCopyAlpha(info); + if (copy_alpha) { + BlitNtoNKeyCopyAlpha (info); } else { - BlitNtoNKey(info); + BlitNtoNKey (info); } return; } - vzero = vec_splat_u8(0); + vzero = vec_splat_u8 (0); if (alpha) { - ((unsigned char *)&valpha)[0] = (unsigned char)alpha; - valpha = (vector unsigned int)vec_splat((vector unsigned char)valpha, 0); + ((unsigned char *) &valpha)[0] = (unsigned char) alpha; + valpha = + (vector unsigned int) vec_splat ((vector unsigned char) valpha, + 0); } else { - valpha = (vector unsigned int)vzero; + valpha = (vector unsigned int) vzero; } ckey &= rgbmask; - ((unsigned int *)(char*)&vckey)[0] = ckey; - vckey = vec_splat(vckey, 0); - ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask; - vrgbmask = vec_splat(vrgbmask, 0); + ((unsigned int *) (char *) &vckey)[0] = ckey; + vckey = vec_splat (vckey, 0); + ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask; + vrgbmask = vec_splat (vrgbmask, 0); while (height--) { #define ONE_PIXEL_BLEND(condition, widthvar) \ @@ -613,37 +635,39 @@ static void Blit32to32KeyAltivec(SDL_BlitInfo *info) } \ } int width = info->d_width; - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); - assert(width > 0); + ONE_PIXEL_BLEND ((UNALIGNED_PTR (dstp)) && (width), width); + assert (width > 0); if (width > 0) { int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned int vs = vec_ld(0, srcp); + vector unsigned char valigner = VEC_ALIGNER (srcp); + vector unsigned int vs = vec_ld (0, srcp); width -= extrawidth; - assert(width >= 4); + assert (width >= 4); while (width) { vector unsigned char vsel; vector unsigned int vd; - vector unsigned int voverflow = vec_ld(15, srcp); + vector unsigned int voverflow = vec_ld (15, srcp); /* load the source vec */ - vs = vec_perm(vs, voverflow, valigner); + vs = vec_perm (vs, voverflow, valigner); /* vsel is set for items that match the key */ - vsel = (vector unsigned char)vec_and(vs, vrgbmask); - vsel = (vector unsigned char)vec_cmpeq(vs, vckey); + vsel = (vector unsigned char) vec_and (vs, vrgbmask); + vsel = (vector unsigned char) vec_cmpeq (vs, vckey); /* permute the src vec to the dest format */ - vs = vec_perm(vs, valpha, vpermute); + vs = vec_perm (vs, valpha, vpermute); /* load the destination vec */ - vd = vec_ld(0, dstp); + vd = vec_ld (0, dstp); /* select the source and dest into vs */ - vd = (vector unsigned int)vec_sel((vector unsigned char)vs, (vector unsigned char)vd, vsel); - - vec_st(vd, 0, dstp); + vd = (vector unsigned int) vec_sel ((vector unsigned char) vs, + (vector unsigned char) vd, + vsel); + + vec_st (vd, 0, dstp); srcp += 4; width -= 4; dstp += 4; vs = voverflow; } - ONE_PIXEL_BLEND((extrawidth), extrawidth); + ONE_PIXEL_BLEND ((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND srcp += srcskip >> 2; dstp += dstskip >> 2; @@ -653,7 +677,8 @@ static void Blit32to32KeyAltivec(SDL_BlitInfo *info) /* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */ /* Use this on a G5 */ -static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info) +static void +ConvertAltivec32to32_noprefetch (SDL_BlitInfo * info) { int height = info->d_height; Uint32 *src = (Uint32 *) info->s_pixels; @@ -662,18 +687,18 @@ static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info) int dstskip = info->d_skip; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; - vector unsigned int vzero = vec_splat_u32(0); - vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); + vector unsigned int vzero = vec_splat_u32 (0); + vector unsigned char vpermute = calc_swizzle32 (srcfmt, dstfmt); if (dstfmt->Amask && !srcfmt->Amask) { if (srcfmt->alpha) { vector unsigned char valpha; - ((unsigned char *)&valpha)[0] = srcfmt->alpha; - vzero = (vector unsigned int)vec_splat(valpha, 0); + ((unsigned char *) &valpha)[0] = srcfmt->alpha; + vzero = (vector unsigned int) vec_splat (valpha, 0); } } - assert(srcfmt->BytesPerPixel == 4); - assert(dstfmt->BytesPerPixel == 4); + assert (srcfmt->BytesPerPixel == 4); + assert (dstfmt->BytesPerPixel == 4); while (height--) { vector unsigned char valigner; @@ -686,41 +711,41 @@ static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info) int extrawidth; /* do scalar until we can align... */ - while ((UNALIGNED_PTR(dst)) && (width)) { + while ((UNALIGNED_PTR (dst)) && (width)) { bits = *(src++); - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - *(dst++) = MAKE8888(dstfmt, r, g, b, a); + RGBA_FROM_8888 (bits, srcfmt, r, g, b, a); + *(dst++) = MAKE8888 (dstfmt, r, g, b, a); width--; } /* After all that work, here's the vector part! */ extrawidth = (width % 4); width -= extrawidth; - valigner = VEC_ALIGNER(src); - vbits = vec_ld(0, src); + valigner = VEC_ALIGNER (src); + vbits = vec_ld (0, src); - while (width) { - voverflow = vec_ld(15, src); + while (width) { + voverflow = vec_ld (15, src); src += 4; width -= 4; - vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */ - vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */ - vec_st(vbits, 0, dst); /* store it back out. */ + vbits = vec_perm (vbits, voverflow, valigner); /* src is ready. */ + vbits = vec_perm (vbits, vzero, vpermute); /* swizzle it. */ + vec_st (vbits, 0, dst); /* store it back out. */ dst += 4; vbits = voverflow; } - assert(width == 0); + assert (width == 0); /* cover pixels at the end of the row that didn't fit in 16 bytes. */ while (extrawidth) { - bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - *(dst++) = MAKE8888(dstfmt, r, g, b, a); + bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ + RGBA_FROM_8888 (bits, srcfmt, r, g, b, a); + *(dst++) = MAKE8888 (dstfmt, r, g, b, a); extrawidth--; } - src += srcskip >> 2; /* move to next row, accounting for pitch. */ + src += srcskip >> 2; /* move to next row, accounting for pitch. */ dst += dstskip >> 2; } @@ -728,7 +753,8 @@ static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info) /* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */ /* Use this on a G4 */ -static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info) +static void +ConvertAltivec32to32_prefetch (SDL_BlitInfo * info) { const int scalar_dst_lead = sizeof (Uint32) * 4; const int vector_dst_lead = sizeof (Uint32) * 16; @@ -740,18 +766,18 @@ static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info) int dstskip = info->d_skip; SDL_PixelFormat *srcfmt = info->src; SDL_PixelFormat *dstfmt = info->dst; - vector unsigned int vzero = vec_splat_u32(0); - vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); + vector unsigned int vzero = vec_splat_u32 (0); + vector unsigned char vpermute = calc_swizzle32 (srcfmt, dstfmt); if (dstfmt->Amask && !srcfmt->Amask) { if (srcfmt->alpha) { vector unsigned char valpha; - ((unsigned char *)&valpha)[0] = srcfmt->alpha; - vzero = (vector unsigned int)vec_splat(valpha, 0); + ((unsigned char *) &valpha)[0] = srcfmt->alpha; + vzero = (vector unsigned int) vec_splat (valpha, 0); } } - assert(srcfmt->BytesPerPixel == 4); - assert(dstfmt->BytesPerPixel == 4); + assert (srcfmt->BytesPerPixel == 4); + assert (dstfmt->BytesPerPixel == 4); while (height--) { vector unsigned char valigner; @@ -764,75 +790,81 @@ static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info) int extrawidth; /* do scalar until we can align... */ - while ((UNALIGNED_PTR(dst)) && (width)) { - vec_dstt(src+scalar_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_SRC); - vec_dstst(dst+scalar_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_DEST); + while ((UNALIGNED_PTR (dst)) && (width)) { + vec_dstt (src + scalar_dst_lead, DST_CTRL (2, 32, 1024), + DST_CHAN_SRC); + vec_dstst (dst + scalar_dst_lead, DST_CTRL (2, 32, 1024), + DST_CHAN_DEST); bits = *(src++); - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - *(dst++) = MAKE8888(dstfmt, r, g, b, a); + RGBA_FROM_8888 (bits, srcfmt, r, g, b, a); + *(dst++) = MAKE8888 (dstfmt, r, g, b, a); width--; } /* After all that work, here's the vector part! */ extrawidth = (width % 4); width -= extrawidth; - valigner = VEC_ALIGNER(src); - vbits = vec_ld(0, src); + valigner = VEC_ALIGNER (src); + vbits = vec_ld (0, src); while (width) { - vec_dstt(src+vector_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_SRC); - vec_dstst(dst+vector_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_DEST); - voverflow = vec_ld(15, src); + vec_dstt (src + vector_dst_lead, DST_CTRL (2, 32, 1024), + DST_CHAN_SRC); + vec_dstst (dst + vector_dst_lead, DST_CTRL (2, 32, 1024), + DST_CHAN_DEST); + voverflow = vec_ld (15, src); src += 4; width -= 4; - vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */ - vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */ - vec_st(vbits, 0, dst); /* store it back out. */ + vbits = vec_perm (vbits, voverflow, valigner); /* src is ready. */ + vbits = vec_perm (vbits, vzero, vpermute); /* swizzle it. */ + vec_st (vbits, 0, dst); /* store it back out. */ dst += 4; vbits = voverflow; } - - assert(width == 0); + + assert (width == 0); /* cover pixels at the end of the row that didn't fit in 16 bytes. */ while (extrawidth) { - bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - *(dst++) = MAKE8888(dstfmt, r, g, b, a); + bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ + RGBA_FROM_8888 (bits, srcfmt, r, g, b, a); + *(dst++) = MAKE8888 (dstfmt, r, g, b, a); extrawidth--; } - src += srcskip >> 2; /* move to next row, accounting for pitch. */ + src += srcskip >> 2; /* move to next row, accounting for pitch. */ dst += dstskip >> 2; } - vec_dss(DST_CHAN_SRC); - vec_dss(DST_CHAN_DEST); + vec_dss (DST_CHAN_SRC); + vec_dss (DST_CHAN_DEST); } -static Uint32 GetBlitFeatures( void ) +static Uint32 +GetBlitFeatures (void) { static Uint32 features = 0xffffffff; if (features == 0xffffffff) { /* Provide an override for testing .. */ - char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES"); + char *override = SDL_getenv ("SDL_ALTIVEC_BLIT_FEATURES"); if (override) { features = 0; - SDL_sscanf(override, "%u", &features); + SDL_sscanf (override, "%u", &features); } else { - features = ( 0 - /* Feature 1 is has-MMX */ - | ((SDL_HasMMX()) ? 1 : 0) - /* Feature 2 is has-AltiVec */ - | ((SDL_HasAltiVec()) ? 2 : 0) - /* Feature 4 is dont-use-prefetch */ - /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */ - | ((GetL3CacheSize() == 0) ? 4 : 0) - ); + features = (0 + /* Feature 1 is has-MMX */ + | ((SDL_HasMMX ())? 1 : 0) + /* Feature 2 is has-AltiVec */ + | ((SDL_HasAltiVec ())? 2 : 0) + /* Feature 4 is dont-use-prefetch */ + /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */ + | ((GetL3CacheSize () == 0) ? 4 : 0) + ); } } return features; } + #if __MWERKS__ #pragma altivec_model off #endif @@ -869,104 +901,110 @@ static Uint32 GetBlitFeatures( void ) (((src)&0x0000E000)>>11)| \ (((src)&0x000000C0)>>6)); \ } -static void Blit_RGB888_index8(SDL_BlitInfo *info) +static void +Blit_RGB888_index8 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint32 *src; - const Uint8 *map; - Uint8 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = (Uint32 *)info->s_pixels; - srcskip = info->s_skip/4; - dst = info->d_pixels; - dstskip = info->d_skip; - map = info->table; - - if ( map == NULL ) { - while ( height-- ) { + int width, height; + Uint32 *src; + const Uint8 *map; + Uint8 *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = (Uint32 *) info->s_pixels; + srcskip = info->s_skip / 4; + dst = info->d_pixels; + dstskip = info->d_skip; + map = info->table; + + if (map == NULL) { + while (height--) { #ifdef USE_DUFFS_LOOP + /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB332(*dst++, *src); , width); + /* *INDENT-ON* */ #else - for ( c=width/4; c; --c ) { - /* Pack RGB into 8bit pixel */ - ++src; - RGB888_RGB332(*dst++, *src); - ++src; - RGB888_RGB332(*dst++, *src); - ++src; - RGB888_RGB332(*dst++, *src); - ++src; - } - switch ( width & 3 ) { - case 3: - RGB888_RGB332(*dst++, *src); - ++src; - case 2: - RGB888_RGB332(*dst++, *src); - ++src; - case 1: - RGB888_RGB332(*dst++, *src); - ++src; - } + for (c = width / 4; c; --c) { + /* Pack RGB into 8bit pixel */ + ++src; + RGB888_RGB332 (*dst++, *src); + ++src; + RGB888_RGB332 (*dst++, *src); + ++src; + RGB888_RGB332 (*dst++, *src); + ++src; + } + switch (width & 3) { + case 3: + RGB888_RGB332 (*dst++, *src); + ++src; + case 2: + RGB888_RGB332 (*dst++, *src); + ++src; + case 1: + RGB888_RGB332 (*dst++, *src); + ++src; + } #endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } - } else { - int Pixel; + src += srcskip; + dst += dstskip; + } + } else { + int Pixel; - while ( height-- ) { + while (height--) { #ifdef USE_DUFFS_LOOP + /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; , width); + /* *INDENT-ON* */ #else - for ( c=width/4; c; --c ) { - /* Pack RGB into 8bit pixel */ - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } - switch ( width & 3 ) { - case 3: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 2: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 1: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } + for (c = width / 4; c; --c) { + /* Pack RGB into 8bit pixel */ + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + } + switch (width & 3) { + case 3: + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + case 2: + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + case 1: + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + } #endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } - } + src += srcskip; + dst += dstskip; + } + } } + /* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */ #define RGB888_RGB555(dst, src) { \ *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>9)| \ @@ -981,112 +1019,116 @@ static void Blit_RGB888_index8(SDL_BlitInfo *info) (((src[LO])&0x0000F800)>>6)| \ (((src[LO])&0x000000F8)>>3); \ } -static void Blit_RGB888_RGB555(SDL_BlitInfo *info) +static void +Blit_RGB888_RGB555 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint32 *src; - Uint16 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = (Uint32 *)info->s_pixels; - srcskip = info->s_skip/4; - dst = (Uint16 *)info->d_pixels; - dstskip = info->d_skip/2; + int width, height; + Uint32 *src; + Uint16 *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = (Uint32 *) info->s_pixels; + srcskip = info->s_skip / 4; + dst = (Uint16 *) info->d_pixels; + dstskip = info->d_skip / 2; #ifdef USE_DUFFS_LOOP - while ( height-- ) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB555(dst, src); ++src; ++dst; , width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } #else - /* Memory align at 4-byte boundary, if necessary */ - if ( (long)dst & 0x03 ) { - /* Don't do anything if width is 0 */ - if ( width == 0 ) { - return; - } - --width; - - while ( height-- ) { - /* Perform copy alignment */ - RGB888_RGB555(dst, src); - ++src; - ++dst; - - /* Copy in 4 pixel chunks */ - for ( c=width/4; c; --c ) { - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB555(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB555(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { - /* Copy in 4 pixel chunks */ - for ( c=width/4; c; --c ) { - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB555(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB555(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } + /* Memory align at 4-byte boundary, if necessary */ + if ((long) dst & 0x03) { + /* Don't do anything if width is 0 */ + if (width == 0) { + return; + } + --width; + + while (height--) { + /* Perform copy alignment */ + RGB888_RGB555 (dst, src); + ++src; + ++dst; + + /* Copy in 4 pixel chunks */ + for (c = width / 4; c; --c) { + RGB888_RGB555_TWO (dst, src); + src += 2; + dst += 2; + RGB888_RGB555_TWO (dst, src); + src += 2; + dst += 2; + } + /* Get any leftovers */ + switch (width & 3) { + case 3: + RGB888_RGB555 (dst, src); + ++src; + ++dst; + case 2: + RGB888_RGB555_TWO (dst, src); + src += 2; + dst += 2; + break; + case 1: + RGB888_RGB555 (dst, src); + ++src; + ++dst; + break; + } + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { + /* Copy in 4 pixel chunks */ + for (c = width / 4; c; --c) { + RGB888_RGB555_TWO (dst, src); + src += 2; + dst += 2; + RGB888_RGB555_TWO (dst, src); + src += 2; + dst += 2; + } + /* Get any leftovers */ + switch (width & 3) { + case 3: + RGB888_RGB555 (dst, src); + ++src; + ++dst; + case 2: + RGB888_RGB555_TWO (dst, src); + src += 2; + dst += 2; + break; + case 1: + RGB888_RGB555 (dst, src); + ++src; + ++dst; + break; + } + src += srcskip; + dst += dstskip; + } + } #endif /* USE_DUFFS_LOOP */ } + /* Special optimized blit for RGB 8-8-8 --> RGB 5-6-5 */ #define RGB888_RGB565(dst, src) { \ *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>8)| \ @@ -1101,110 +1143,113 @@ static void Blit_RGB888_RGB555(SDL_BlitInfo *info) (((src[LO])&0x0000FC00)>>5)| \ (((src[LO])&0x000000F8)>>3); \ } -static void Blit_RGB888_RGB565(SDL_BlitInfo *info) +static void +Blit_RGB888_RGB565 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint32 *src; - Uint16 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = (Uint32 *)info->s_pixels; - srcskip = info->s_skip/4; - dst = (Uint16 *)info->d_pixels; - dstskip = info->d_skip/2; + int width, height; + Uint32 *src; + Uint16 *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = (Uint32 *) info->s_pixels; + srcskip = info->s_skip / 4; + dst = (Uint16 *) info->d_pixels; + dstskip = info->d_skip / 2; #ifdef USE_DUFFS_LOOP - while ( height-- ) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB565(dst, src); ++src; ++dst; , width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } #else - /* Memory align at 4-byte boundary, if necessary */ - if ( (long)dst & 0x03 ) { - /* Don't do anything if width is 0 */ - if ( width == 0 ) { - return; - } - --width; - - while ( height-- ) { - /* Perform copy alignment */ - RGB888_RGB565(dst, src); - ++src; - ++dst; - - /* Copy in 4 pixel chunks */ - for ( c=width/4; c; --c ) { - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB565(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB565(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { - /* Copy in 4 pixel chunks */ - for ( c=width/4; c; --c ) { - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB565(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB565(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } + /* Memory align at 4-byte boundary, if necessary */ + if ((long) dst & 0x03) { + /* Don't do anything if width is 0 */ + if (width == 0) { + return; + } + --width; + + while (height--) { + /* Perform copy alignment */ + RGB888_RGB565 (dst, src); + ++src; + ++dst; + + /* Copy in 4 pixel chunks */ + for (c = width / 4; c; --c) { + RGB888_RGB565_TWO (dst, src); + src += 2; + dst += 2; + RGB888_RGB565_TWO (dst, src); + src += 2; + dst += 2; + } + /* Get any leftovers */ + switch (width & 3) { + case 3: + RGB888_RGB565 (dst, src); + ++src; + ++dst; + case 2: + RGB888_RGB565_TWO (dst, src); + src += 2; + dst += 2; + break; + case 1: + RGB888_RGB565 (dst, src); + ++src; + ++dst; + break; + } + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { + /* Copy in 4 pixel chunks */ + for (c = width / 4; c; --c) { + RGB888_RGB565_TWO (dst, src); + src += 2; + dst += 2; + RGB888_RGB565_TWO (dst, src); + src += 2; + dst += 2; + } + /* Get any leftovers */ + switch (width & 3) { + case 3: + RGB888_RGB565 (dst, src); + ++src; + ++dst; + case 2: + RGB888_RGB565_TWO (dst, src); + src += 2; + dst += 2; + break; + case 1: + RGB888_RGB565 (dst, src); + ++src; + ++dst; + break; + } + src += srcskip; + dst += dstskip; + } + } #endif /* USE_DUFFS_LOOP */ } @@ -1213,609 +1258,616 @@ static void Blit_RGB888_RGB565(SDL_BlitInfo *info) /* Special optimized blit for RGB 5-6-5 --> 32-bit RGB surfaces */ #define RGB565_32(dst, src, map) (map[src[LO]*2] + map[src[HI]*2+1]) -static void Blit_RGB565_32(SDL_BlitInfo *info, const Uint32 *map) +static void +Blit_RGB565_32 (SDL_BlitInfo * info, const Uint32 * map) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint8 *src; - Uint32 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = (Uint8 *)info->s_pixels; - srcskip = info->s_skip; - dst = (Uint32 *)info->d_pixels; - dstskip = info->d_skip/4; + int width, height; + Uint8 *src; + Uint32 *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = (Uint8 *) info->s_pixels; + srcskip = info->s_skip; + dst = (Uint32 *) info->d_pixels; + dstskip = info->d_skip / 4; #ifdef USE_DUFFS_LOOP - while ( height-- ) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { *dst++ = RGB565_32(dst, src, map); src += 2; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } #else - while ( height-- ) { - /* Copy in 4 pixel chunks */ - for ( c=width/4; c; --c ) { - *dst++ = RGB565_32(dst, src, map); - src += 2; - *dst++ = RGB565_32(dst, src, map); - src += 2; - *dst++ = RGB565_32(dst, src, map); - src += 2; - *dst++ = RGB565_32(dst, src, map); - src += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - *dst++ = RGB565_32(dst, src, map); - src += 2; - case 2: - *dst++ = RGB565_32(dst, src, map); - src += 2; - case 1: - *dst++ = RGB565_32(dst, src, map); - src += 2; - break; - } - src += srcskip; - dst += dstskip; - } + while (height--) { + /* Copy in 4 pixel chunks */ + for (c = width / 4; c; --c) { + *dst++ = RGB565_32 (dst, src, map); + src += 2; + *dst++ = RGB565_32 (dst, src, map); + src += 2; + *dst++ = RGB565_32 (dst, src, map); + src += 2; + *dst++ = RGB565_32 (dst, src, map); + src += 2; + } + /* Get any leftovers */ + switch (width & 3) { + case 3: + *dst++ = RGB565_32 (dst, src, map); + src += 2; + case 2: + *dst++ = RGB565_32 (dst, src, map); + src += 2; + case 1: + *dst++ = RGB565_32 (dst, src, map); + src += 2; + break; + } + src += srcskip; + dst += dstskip; + } #endif /* USE_DUFFS_LOOP */ } /* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */ static const Uint32 RGB565_ARGB8888_LUT[512] = { - 0x00000000, 0xff000000, 0x00000008, 0xff002000, - 0x00000010, 0xff004000, 0x00000018, 0xff006100, - 0x00000020, 0xff008100, 0x00000029, 0xff00a100, - 0x00000031, 0xff00c200, 0x00000039, 0xff00e200, - 0x00000041, 0xff080000, 0x0000004a, 0xff082000, - 0x00000052, 0xff084000, 0x0000005a, 0xff086100, - 0x00000062, 0xff088100, 0x0000006a, 0xff08a100, - 0x00000073, 0xff08c200, 0x0000007b, 0xff08e200, - 0x00000083, 0xff100000, 0x0000008b, 0xff102000, - 0x00000094, 0xff104000, 0x0000009c, 0xff106100, - 0x000000a4, 0xff108100, 0x000000ac, 0xff10a100, - 0x000000b4, 0xff10c200, 0x000000bd, 0xff10e200, - 0x000000c5, 0xff180000, 0x000000cd, 0xff182000, - 0x000000d5, 0xff184000, 0x000000de, 0xff186100, - 0x000000e6, 0xff188100, 0x000000ee, 0xff18a100, - 0x000000f6, 0xff18c200, 0x000000ff, 0xff18e200, - 0x00000400, 0xff200000, 0x00000408, 0xff202000, - 0x00000410, 0xff204000, 0x00000418, 0xff206100, - 0x00000420, 0xff208100, 0x00000429, 0xff20a100, - 0x00000431, 0xff20c200, 0x00000439, 0xff20e200, - 0x00000441, 0xff290000, 0x0000044a, 0xff292000, - 0x00000452, 0xff294000, 0x0000045a, 0xff296100, - 0x00000462, 0xff298100, 0x0000046a, 0xff29a100, - 0x00000473, 0xff29c200, 0x0000047b, 0xff29e200, - 0x00000483, 0xff310000, 0x0000048b, 0xff312000, - 0x00000494, 0xff314000, 0x0000049c, 0xff316100, - 0x000004a4, 0xff318100, 0x000004ac, 0xff31a100, - 0x000004b4, 0xff31c200, 0x000004bd, 0xff31e200, - 0x000004c5, 0xff390000, 0x000004cd, 0xff392000, - 0x000004d5, 0xff394000, 0x000004de, 0xff396100, - 0x000004e6, 0xff398100, 0x000004ee, 0xff39a100, - 0x000004f6, 0xff39c200, 0x000004ff, 0xff39e200, - 0x00000800, 0xff410000, 0x00000808, 0xff412000, - 0x00000810, 0xff414000, 0x00000818, 0xff416100, - 0x00000820, 0xff418100, 0x00000829, 0xff41a100, - 0x00000831, 0xff41c200, 0x00000839, 0xff41e200, - 0x00000841, 0xff4a0000, 0x0000084a, 0xff4a2000, - 0x00000852, 0xff4a4000, 0x0000085a, 0xff4a6100, - 0x00000862, 0xff4a8100, 0x0000086a, 0xff4aa100, - 0x00000873, 0xff4ac200, 0x0000087b, 0xff4ae200, - 0x00000883, 0xff520000, 0x0000088b, 0xff522000, - 0x00000894, 0xff524000, 0x0000089c, 0xff526100, - 0x000008a4, 0xff528100, 0x000008ac, 0xff52a100, - 0x000008b4, 0xff52c200, 0x000008bd, 0xff52e200, - 0x000008c5, 0xff5a0000, 0x000008cd, 0xff5a2000, - 0x000008d5, 0xff5a4000, 0x000008de, 0xff5a6100, - 0x000008e6, 0xff5a8100, 0x000008ee, 0xff5aa100, - 0x000008f6, 0xff5ac200, 0x000008ff, 0xff5ae200, - 0x00000c00, 0xff620000, 0x00000c08, 0xff622000, - 0x00000c10, 0xff624000, 0x00000c18, 0xff626100, - 0x00000c20, 0xff628100, 0x00000c29, 0xff62a100, - 0x00000c31, 0xff62c200, 0x00000c39, 0xff62e200, - 0x00000c41, 0xff6a0000, 0x00000c4a, 0xff6a2000, - 0x00000c52, 0xff6a4000, 0x00000c5a, 0xff6a6100, - 0x00000c62, 0xff6a8100, 0x00000c6a, 0xff6aa100, - 0x00000c73, 0xff6ac200, 0x00000c7b, 0xff6ae200, - 0x00000c83, 0xff730000, 0x00000c8b, 0xff732000, - 0x00000c94, 0xff734000, 0x00000c9c, 0xff736100, - 0x00000ca4, 0xff738100, 0x00000cac, 0xff73a100, - 0x00000cb4, 0xff73c200, 0x00000cbd, 0xff73e200, - 0x00000cc5, 0xff7b0000, 0x00000ccd, 0xff7b2000, - 0x00000cd5, 0xff7b4000, 0x00000cde, 0xff7b6100, - 0x00000ce6, 0xff7b8100, 0x00000cee, 0xff7ba100, - 0x00000cf6, 0xff7bc200, 0x00000cff, 0xff7be200, - 0x00001000, 0xff830000, 0x00001008, 0xff832000, - 0x00001010, 0xff834000, 0x00001018, 0xff836100, - 0x00001020, 0xff838100, 0x00001029, 0xff83a100, - 0x00001031, 0xff83c200, 0x00001039, 0xff83e200, - 0x00001041, 0xff8b0000, 0x0000104a, 0xff8b2000, - 0x00001052, 0xff8b4000, 0x0000105a, 0xff8b6100, - 0x00001062, 0xff8b8100, 0x0000106a, 0xff8ba100, - 0x00001073, 0xff8bc200, 0x0000107b, 0xff8be200, - 0x00001083, 0xff940000, 0x0000108b, 0xff942000, - 0x00001094, 0xff944000, 0x0000109c, 0xff946100, - 0x000010a4, 0xff948100, 0x000010ac, 0xff94a100, - 0x000010b4, 0xff94c200, 0x000010bd, 0xff94e200, - 0x000010c5, 0xff9c0000, 0x000010cd, 0xff9c2000, - 0x000010d5, 0xff9c4000, 0x000010de, 0xff9c6100, - 0x000010e6, 0xff9c8100, 0x000010ee, 0xff9ca100, - 0x000010f6, 0xff9cc200, 0x000010ff, 0xff9ce200, - 0x00001400, 0xffa40000, 0x00001408, 0xffa42000, - 0x00001410, 0xffa44000, 0x00001418, 0xffa46100, - 0x00001420, 0xffa48100, 0x00001429, 0xffa4a100, - 0x00001431, 0xffa4c200, 0x00001439, 0xffa4e200, - 0x00001441, 0xffac0000, 0x0000144a, 0xffac2000, - 0x00001452, 0xffac4000, 0x0000145a, 0xffac6100, - 0x00001462, 0xffac8100, 0x0000146a, 0xffaca100, - 0x00001473, 0xffacc200, 0x0000147b, 0xfface200, - 0x00001483, 0xffb40000, 0x0000148b, 0xffb42000, - 0x00001494, 0xffb44000, 0x0000149c, 0xffb46100, - 0x000014a4, 0xffb48100, 0x000014ac, 0xffb4a100, - 0x000014b4, 0xffb4c200, 0x000014bd, 0xffb4e200, - 0x000014c5, 0xffbd0000, 0x000014cd, 0xffbd2000, - 0x000014d5, 0xffbd4000, 0x000014de, 0xffbd6100, - 0x000014e6, 0xffbd8100, 0x000014ee, 0xffbda100, - 0x000014f6, 0xffbdc200, 0x000014ff, 0xffbde200, - 0x00001800, 0xffc50000, 0x00001808, 0xffc52000, - 0x00001810, 0xffc54000, 0x00001818, 0xffc56100, - 0x00001820, 0xffc58100, 0x00001829, 0xffc5a100, - 0x00001831, 0xffc5c200, 0x00001839, 0xffc5e200, - 0x00001841, 0xffcd0000, 0x0000184a, 0xffcd2000, - 0x00001852, 0xffcd4000, 0x0000185a, 0xffcd6100, - 0x00001862, 0xffcd8100, 0x0000186a, 0xffcda100, - 0x00001873, 0xffcdc200, 0x0000187b, 0xffcde200, - 0x00001883, 0xffd50000, 0x0000188b, 0xffd52000, - 0x00001894, 0xffd54000, 0x0000189c, 0xffd56100, - 0x000018a4, 0xffd58100, 0x000018ac, 0xffd5a100, - 0x000018b4, 0xffd5c200, 0x000018bd, 0xffd5e200, - 0x000018c5, 0xffde0000, 0x000018cd, 0xffde2000, - 0x000018d5, 0xffde4000, 0x000018de, 0xffde6100, - 0x000018e6, 0xffde8100, 0x000018ee, 0xffdea100, - 0x000018f6, 0xffdec200, 0x000018ff, 0xffdee200, - 0x00001c00, 0xffe60000, 0x00001c08, 0xffe62000, - 0x00001c10, 0xffe64000, 0x00001c18, 0xffe66100, - 0x00001c20, 0xffe68100, 0x00001c29, 0xffe6a100, - 0x00001c31, 0xffe6c200, 0x00001c39, 0xffe6e200, - 0x00001c41, 0xffee0000, 0x00001c4a, 0xffee2000, - 0x00001c52, 0xffee4000, 0x00001c5a, 0xffee6100, - 0x00001c62, 0xffee8100, 0x00001c6a, 0xffeea100, - 0x00001c73, 0xffeec200, 0x00001c7b, 0xffeee200, - 0x00001c83, 0xfff60000, 0x00001c8b, 0xfff62000, - 0x00001c94, 0xfff64000, 0x00001c9c, 0xfff66100, - 0x00001ca4, 0xfff68100, 0x00001cac, 0xfff6a100, - 0x00001cb4, 0xfff6c200, 0x00001cbd, 0xfff6e200, - 0x00001cc5, 0xffff0000, 0x00001ccd, 0xffff2000, - 0x00001cd5, 0xffff4000, 0x00001cde, 0xffff6100, - 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100, - 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200 + 0x00000000, 0xff000000, 0x00000008, 0xff002000, + 0x00000010, 0xff004000, 0x00000018, 0xff006100, + 0x00000020, 0xff008100, 0x00000029, 0xff00a100, + 0x00000031, 0xff00c200, 0x00000039, 0xff00e200, + 0x00000041, 0xff080000, 0x0000004a, 0xff082000, + 0x00000052, 0xff084000, 0x0000005a, 0xff086100, + 0x00000062, 0xff088100, 0x0000006a, 0xff08a100, + 0x00000073, 0xff08c200, 0x0000007b, 0xff08e200, + 0x00000083, 0xff100000, 0x0000008b, 0xff102000, + 0x00000094, 0xff104000, 0x0000009c, 0xff106100, + 0x000000a4, 0xff108100, 0x000000ac, 0xff10a100, + 0x000000b4, 0xff10c200, 0x000000bd, 0xff10e200, + 0x000000c5, 0xff180000, 0x000000cd, 0xff182000, + 0x000000d5, 0xff184000, 0x000000de, 0xff186100, + 0x000000e6, 0xff188100, 0x000000ee, 0xff18a100, + 0x000000f6, 0xff18c200, 0x000000ff, 0xff18e200, + 0x00000400, 0xff200000, 0x00000408, 0xff202000, + 0x00000410, 0xff204000, 0x00000418, 0xff206100, + 0x00000420, 0xff208100, 0x00000429, 0xff20a100, + 0x00000431, 0xff20c200, 0x00000439, 0xff20e200, + 0x00000441, 0xff290000, 0x0000044a, 0xff292000, + 0x00000452, 0xff294000, 0x0000045a, 0xff296100, + 0x00000462, 0xff298100, 0x0000046a, 0xff29a100, + 0x00000473, 0xff29c200, 0x0000047b, 0xff29e200, + 0x00000483, 0xff310000, 0x0000048b, 0xff312000, + 0x00000494, 0xff314000, 0x0000049c, 0xff316100, + 0x000004a4, 0xff318100, 0x000004ac, 0xff31a100, + 0x000004b4, 0xff31c200, 0x000004bd, 0xff31e200, + 0x000004c5, 0xff390000, 0x000004cd, 0xff392000, + 0x000004d5, 0xff394000, 0x000004de, 0xff396100, + 0x000004e6, 0xff398100, 0x000004ee, 0xff39a100, + 0x000004f6, 0xff39c200, 0x000004ff, 0xff39e200, + 0x00000800, 0xff410000, 0x00000808, 0xff412000, + 0x00000810, 0xff414000, 0x00000818, 0xff416100, + 0x00000820, 0xff418100, 0x00000829, 0xff41a100, + 0x00000831, 0xff41c200, 0x00000839, 0xff41e200, + 0x00000841, 0xff4a0000, 0x0000084a, 0xff4a2000, + 0x00000852, 0xff4a4000, 0x0000085a, 0xff4a6100, + 0x00000862, 0xff4a8100, 0x0000086a, 0xff4aa100, + 0x00000873, 0xff4ac200, 0x0000087b, 0xff4ae200, + 0x00000883, 0xff520000, 0x0000088b, 0xff522000, + 0x00000894, 0xff524000, 0x0000089c, 0xff526100, + 0x000008a4, 0xff528100, 0x000008ac, 0xff52a100, + 0x000008b4, 0xff52c200, 0x000008bd, 0xff52e200, + 0x000008c5, 0xff5a0000, 0x000008cd, 0xff5a2000, + 0x000008d5, 0xff5a4000, 0x000008de, 0xff5a6100, + 0x000008e6, 0xff5a8100, 0x000008ee, 0xff5aa100, + 0x000008f6, 0xff5ac200, 0x000008ff, 0xff5ae200, + 0x00000c00, 0xff620000, 0x00000c08, 0xff622000, + 0x00000c10, 0xff624000, 0x00000c18, 0xff626100, + 0x00000c20, 0xff628100, 0x00000c29, 0xff62a100, + 0x00000c31, 0xff62c200, 0x00000c39, 0xff62e200, + 0x00000c41, 0xff6a0000, 0x00000c4a, 0xff6a2000, + 0x00000c52, 0xff6a4000, 0x00000c5a, 0xff6a6100, + 0x00000c62, 0xff6a8100, 0x00000c6a, 0xff6aa100, + 0x00000c73, 0xff6ac200, 0x00000c7b, 0xff6ae200, + 0x00000c83, 0xff730000, 0x00000c8b, 0xff732000, + 0x00000c94, 0xff734000, 0x00000c9c, 0xff736100, + 0x00000ca4, 0xff738100, 0x00000cac, 0xff73a100, + 0x00000cb4, 0xff73c200, 0x00000cbd, 0xff73e200, + 0x00000cc5, 0xff7b0000, 0x00000ccd, 0xff7b2000, + 0x00000cd5, 0xff7b4000, 0x00000cde, 0xff7b6100, + 0x00000ce6, 0xff7b8100, 0x00000cee, 0xff7ba100, + 0x00000cf6, 0xff7bc200, 0x00000cff, 0xff7be200, + 0x00001000, 0xff830000, 0x00001008, 0xff832000, + 0x00001010, 0xff834000, 0x00001018, 0xff836100, + 0x00001020, 0xff838100, 0x00001029, 0xff83a100, + 0x00001031, 0xff83c200, 0x00001039, 0xff83e200, + 0x00001041, 0xff8b0000, 0x0000104a, 0xff8b2000, + 0x00001052, 0xff8b4000, 0x0000105a, 0xff8b6100, + 0x00001062, 0xff8b8100, 0x0000106a, 0xff8ba100, + 0x00001073, 0xff8bc200, 0x0000107b, 0xff8be200, + 0x00001083, 0xff940000, 0x0000108b, 0xff942000, + 0x00001094, 0xff944000, 0x0000109c, 0xff946100, + 0x000010a4, 0xff948100, 0x000010ac, 0xff94a100, + 0x000010b4, 0xff94c200, 0x000010bd, 0xff94e200, + 0x000010c5, 0xff9c0000, 0x000010cd, 0xff9c2000, + 0x000010d5, 0xff9c4000, 0x000010de, 0xff9c6100, + 0x000010e6, 0xff9c8100, 0x000010ee, 0xff9ca100, + 0x000010f6, 0xff9cc200, 0x000010ff, 0xff9ce200, + 0x00001400, 0xffa40000, 0x00001408, 0xffa42000, + 0x00001410, 0xffa44000, 0x00001418, 0xffa46100, + 0x00001420, 0xffa48100, 0x00001429, 0xffa4a100, + 0x00001431, 0xffa4c200, 0x00001439, 0xffa4e200, + 0x00001441, 0xffac0000, 0x0000144a, 0xffac2000, + 0x00001452, 0xffac4000, 0x0000145a, 0xffac6100, + 0x00001462, 0xffac8100, 0x0000146a, 0xffaca100, + 0x00001473, 0xffacc200, 0x0000147b, 0xfface200, + 0x00001483, 0xffb40000, 0x0000148b, 0xffb42000, + 0x00001494, 0xffb44000, 0x0000149c, 0xffb46100, + 0x000014a4, 0xffb48100, 0x000014ac, 0xffb4a100, + 0x000014b4, 0xffb4c200, 0x000014bd, 0xffb4e200, + 0x000014c5, 0xffbd0000, 0x000014cd, 0xffbd2000, + 0x000014d5, 0xffbd4000, 0x000014de, 0xffbd6100, + 0x000014e6, 0xffbd8100, 0x000014ee, 0xffbda100, + 0x000014f6, 0xffbdc200, 0x000014ff, 0xffbde200, + 0x00001800, 0xffc50000, 0x00001808, 0xffc52000, + 0x00001810, 0xffc54000, 0x00001818, 0xffc56100, + 0x00001820, 0xffc58100, 0x00001829, 0xffc5a100, + 0x00001831, 0xffc5c200, 0x00001839, 0xffc5e200, + 0x00001841, 0xffcd0000, 0x0000184a, 0xffcd2000, + 0x00001852, 0xffcd4000, 0x0000185a, 0xffcd6100, + 0x00001862, 0xffcd8100, 0x0000186a, 0xffcda100, + 0x00001873, 0xffcdc200, 0x0000187b, 0xffcde200, + 0x00001883, 0xffd50000, 0x0000188b, 0xffd52000, + 0x00001894, 0xffd54000, 0x0000189c, 0xffd56100, + 0x000018a4, 0xffd58100, 0x000018ac, 0xffd5a100, + 0x000018b4, 0xffd5c200, 0x000018bd, 0xffd5e200, + 0x000018c5, 0xffde0000, 0x000018cd, 0xffde2000, + 0x000018d5, 0xffde4000, 0x000018de, 0xffde6100, + 0x000018e6, 0xffde8100, 0x000018ee, 0xffdea100, + 0x000018f6, 0xffdec200, 0x000018ff, 0xffdee200, + 0x00001c00, 0xffe60000, 0x00001c08, 0xffe62000, + 0x00001c10, 0xffe64000, 0x00001c18, 0xffe66100, + 0x00001c20, 0xffe68100, 0x00001c29, 0xffe6a100, + 0x00001c31, 0xffe6c200, 0x00001c39, 0xffe6e200, + 0x00001c41, 0xffee0000, 0x00001c4a, 0xffee2000, + 0x00001c52, 0xffee4000, 0x00001c5a, 0xffee6100, + 0x00001c62, 0xffee8100, 0x00001c6a, 0xffeea100, + 0x00001c73, 0xffeec200, 0x00001c7b, 0xffeee200, + 0x00001c83, 0xfff60000, 0x00001c8b, 0xfff62000, + 0x00001c94, 0xfff64000, 0x00001c9c, 0xfff66100, + 0x00001ca4, 0xfff68100, 0x00001cac, 0xfff6a100, + 0x00001cb4, 0xfff6c200, 0x00001cbd, 0xfff6e200, + 0x00001cc5, 0xffff0000, 0x00001ccd, 0xffff2000, + 0x00001cd5, 0xffff4000, 0x00001cde, 0xffff6100, + 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100, + 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200 }; -static void Blit_RGB565_ARGB8888(SDL_BlitInfo *info) +static void +Blit_RGB565_ARGB8888 (SDL_BlitInfo * info) { - Blit_RGB565_32(info, RGB565_ARGB8888_LUT); + Blit_RGB565_32 (info, RGB565_ARGB8888_LUT); } /* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */ static const Uint32 RGB565_ABGR8888_LUT[512] = { - 0xff000000, 0x00000000, 0xff080000, 0x00002000, - 0xff100000, 0x00004000, 0xff180000, 0x00006100, - 0xff200000, 0x00008100, 0xff290000, 0x0000a100, - 0xff310000, 0x0000c200, 0xff390000, 0x0000e200, - 0xff410000, 0x00000008, 0xff4a0000, 0x00002008, - 0xff520000, 0x00004008, 0xff5a0000, 0x00006108, - 0xff620000, 0x00008108, 0xff6a0000, 0x0000a108, - 0xff730000, 0x0000c208, 0xff7b0000, 0x0000e208, - 0xff830000, 0x00000010, 0xff8b0000, 0x00002010, - 0xff940000, 0x00004010, 0xff9c0000, 0x00006110, - 0xffa40000, 0x00008110, 0xffac0000, 0x0000a110, - 0xffb40000, 0x0000c210, 0xffbd0000, 0x0000e210, - 0xffc50000, 0x00000018, 0xffcd0000, 0x00002018, - 0xffd50000, 0x00004018, 0xffde0000, 0x00006118, - 0xffe60000, 0x00008118, 0xffee0000, 0x0000a118, - 0xfff60000, 0x0000c218, 0xffff0000, 0x0000e218, - 0xff000400, 0x00000020, 0xff080400, 0x00002020, - 0xff100400, 0x00004020, 0xff180400, 0x00006120, - 0xff200400, 0x00008120, 0xff290400, 0x0000a120, - 0xff310400, 0x0000c220, 0xff390400, 0x0000e220, - 0xff410400, 0x00000029, 0xff4a0400, 0x00002029, - 0xff520400, 0x00004029, 0xff5a0400, 0x00006129, - 0xff620400, 0x00008129, 0xff6a0400, 0x0000a129, - 0xff730400, 0x0000c229, 0xff7b0400, 0x0000e229, - 0xff830400, 0x00000031, 0xff8b0400, 0x00002031, - 0xff940400, 0x00004031, 0xff9c0400, 0x00006131, - 0xffa40400, 0x00008131, 0xffac0400, 0x0000a131, - 0xffb40400, 0x0000c231, 0xffbd0400, 0x0000e231, - 0xffc50400, 0x00000039, 0xffcd0400, 0x00002039, - 0xffd50400, 0x00004039, 0xffde0400, 0x00006139, - 0xffe60400, 0x00008139, 0xffee0400, 0x0000a139, - 0xfff60400, 0x0000c239, 0xffff0400, 0x0000e239, - 0xff000800, 0x00000041, 0xff080800, 0x00002041, - 0xff100800, 0x00004041, 0xff180800, 0x00006141, - 0xff200800, 0x00008141, 0xff290800, 0x0000a141, - 0xff310800, 0x0000c241, 0xff390800, 0x0000e241, - 0xff410800, 0x0000004a, 0xff4a0800, 0x0000204a, - 0xff520800, 0x0000404a, 0xff5a0800, 0x0000614a, - 0xff620800, 0x0000814a, 0xff6a0800, 0x0000a14a, - 0xff730800, 0x0000c24a, 0xff7b0800, 0x0000e24a, - 0xff830800, 0x00000052, 0xff8b0800, 0x00002052, - 0xff940800, 0x00004052, 0xff9c0800, 0x00006152, - 0xffa40800, 0x00008152, 0xffac0800, 0x0000a152, - 0xffb40800, 0x0000c252, 0xffbd0800, 0x0000e252, - 0xffc50800, 0x0000005a, 0xffcd0800, 0x0000205a, - 0xffd50800, 0x0000405a, 0xffde0800, 0x0000615a, - 0xffe60800, 0x0000815a, 0xffee0800, 0x0000a15a, - 0xfff60800, 0x0000c25a, 0xffff0800, 0x0000e25a, - 0xff000c00, 0x00000062, 0xff080c00, 0x00002062, - 0xff100c00, 0x00004062, 0xff180c00, 0x00006162, - 0xff200c00, 0x00008162, 0xff290c00, 0x0000a162, - 0xff310c00, 0x0000c262, 0xff390c00, 0x0000e262, - 0xff410c00, 0x0000006a, 0xff4a0c00, 0x0000206a, - 0xff520c00, 0x0000406a, 0xff5a0c00, 0x0000616a, - 0xff620c00, 0x0000816a, 0xff6a0c00, 0x0000a16a, - 0xff730c00, 0x0000c26a, 0xff7b0c00, 0x0000e26a, - 0xff830c00, 0x00000073, 0xff8b0c00, 0x00002073, - 0xff940c00, 0x00004073, 0xff9c0c00, 0x00006173, - 0xffa40c00, 0x00008173, 0xffac0c00, 0x0000a173, - 0xffb40c00, 0x0000c273, 0xffbd0c00, 0x0000e273, - 0xffc50c00, 0x0000007b, 0xffcd0c00, 0x0000207b, - 0xffd50c00, 0x0000407b, 0xffde0c00, 0x0000617b, - 0xffe60c00, 0x0000817b, 0xffee0c00, 0x0000a17b, - 0xfff60c00, 0x0000c27b, 0xffff0c00, 0x0000e27b, - 0xff001000, 0x00000083, 0xff081000, 0x00002083, - 0xff101000, 0x00004083, 0xff181000, 0x00006183, - 0xff201000, 0x00008183, 0xff291000, 0x0000a183, - 0xff311000, 0x0000c283, 0xff391000, 0x0000e283, - 0xff411000, 0x0000008b, 0xff4a1000, 0x0000208b, - 0xff521000, 0x0000408b, 0xff5a1000, 0x0000618b, - 0xff621000, 0x0000818b, 0xff6a1000, 0x0000a18b, - 0xff731000, 0x0000c28b, 0xff7b1000, 0x0000e28b, - 0xff831000, 0x00000094, 0xff8b1000, 0x00002094, - 0xff941000, 0x00004094, 0xff9c1000, 0x00006194, - 0xffa41000, 0x00008194, 0xffac1000, 0x0000a194, - 0xffb41000, 0x0000c294, 0xffbd1000, 0x0000e294, - 0xffc51000, 0x0000009c, 0xffcd1000, 0x0000209c, - 0xffd51000, 0x0000409c, 0xffde1000, 0x0000619c, - 0xffe61000, 0x0000819c, 0xffee1000, 0x0000a19c, - 0xfff61000, 0x0000c29c, 0xffff1000, 0x0000e29c, - 0xff001400, 0x000000a4, 0xff081400, 0x000020a4, - 0xff101400, 0x000040a4, 0xff181400, 0x000061a4, - 0xff201400, 0x000081a4, 0xff291400, 0x0000a1a4, - 0xff311400, 0x0000c2a4, 0xff391400, 0x0000e2a4, - 0xff411400, 0x000000ac, 0xff4a1400, 0x000020ac, - 0xff521400, 0x000040ac, 0xff5a1400, 0x000061ac, - 0xff621400, 0x000081ac, 0xff6a1400, 0x0000a1ac, - 0xff731400, 0x0000c2ac, 0xff7b1400, 0x0000e2ac, - 0xff831400, 0x000000b4, 0xff8b1400, 0x000020b4, - 0xff941400, 0x000040b4, 0xff9c1400, 0x000061b4, - 0xffa41400, 0x000081b4, 0xffac1400, 0x0000a1b4, - 0xffb41400, 0x0000c2b4, 0xffbd1400, 0x0000e2b4, - 0xffc51400, 0x000000bd, 0xffcd1400, 0x000020bd, - 0xffd51400, 0x000040bd, 0xffde1400, 0x000061bd, - 0xffe61400, 0x000081bd, 0xffee1400, 0x0000a1bd, - 0xfff61400, 0x0000c2bd, 0xffff1400, 0x0000e2bd, - 0xff001800, 0x000000c5, 0xff081800, 0x000020c5, - 0xff101800, 0x000040c5, 0xff181800, 0x000061c5, - 0xff201800, 0x000081c5, 0xff291800, 0x0000a1c5, - 0xff311800, 0x0000c2c5, 0xff391800, 0x0000e2c5, - 0xff411800, 0x000000cd, 0xff4a1800, 0x000020cd, - 0xff521800, 0x000040cd, 0xff5a1800, 0x000061cd, - 0xff621800, 0x000081cd, 0xff6a1800, 0x0000a1cd, - 0xff731800, 0x0000c2cd, 0xff7b1800, 0x0000e2cd, - 0xff831800, 0x000000d5, 0xff8b1800, 0x000020d5, - 0xff941800, 0x000040d5, 0xff9c1800, 0x000061d5, - 0xffa41800, 0x000081d5, 0xffac1800, 0x0000a1d5, - 0xffb41800, 0x0000c2d5, 0xffbd1800, 0x0000e2d5, - 0xffc51800, 0x000000de, 0xffcd1800, 0x000020de, - 0xffd51800, 0x000040de, 0xffde1800, 0x000061de, - 0xffe61800, 0x000081de, 0xffee1800, 0x0000a1de, - 0xfff61800, 0x0000c2de, 0xffff1800, 0x0000e2de, - 0xff001c00, 0x000000e6, 0xff081c00, 0x000020e6, - 0xff101c00, 0x000040e6, 0xff181c00, 0x000061e6, - 0xff201c00, 0x000081e6, 0xff291c00, 0x0000a1e6, - 0xff311c00, 0x0000c2e6, 0xff391c00, 0x0000e2e6, - 0xff411c00, 0x000000ee, 0xff4a1c00, 0x000020ee, - 0xff521c00, 0x000040ee, 0xff5a1c00, 0x000061ee, - 0xff621c00, 0x000081ee, 0xff6a1c00, 0x0000a1ee, - 0xff731c00, 0x0000c2ee, 0xff7b1c00, 0x0000e2ee, - 0xff831c00, 0x000000f6, 0xff8b1c00, 0x000020f6, - 0xff941c00, 0x000040f6, 0xff9c1c00, 0x000061f6, - 0xffa41c00, 0x000081f6, 0xffac1c00, 0x0000a1f6, - 0xffb41c00, 0x0000c2f6, 0xffbd1c00, 0x0000e2f6, - 0xffc51c00, 0x000000ff, 0xffcd1c00, 0x000020ff, - 0xffd51c00, 0x000040ff, 0xffde1c00, 0x000061ff, - 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff, - 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff + 0xff000000, 0x00000000, 0xff080000, 0x00002000, + 0xff100000, 0x00004000, 0xff180000, 0x00006100, + 0xff200000, 0x00008100, 0xff290000, 0x0000a100, + 0xff310000, 0x0000c200, 0xff390000, 0x0000e200, + 0xff410000, 0x00000008, 0xff4a0000, 0x00002008, + 0xff520000, 0x00004008, 0xff5a0000, 0x00006108, + 0xff620000, 0x00008108, 0xff6a0000, 0x0000a108, + 0xff730000, 0x0000c208, 0xff7b0000, 0x0000e208, + 0xff830000, 0x00000010, 0xff8b0000, 0x00002010, + 0xff940000, 0x00004010, 0xff9c0000, 0x00006110, + 0xffa40000, 0x00008110, 0xffac0000, 0x0000a110, + 0xffb40000, 0x0000c210, 0xffbd0000, 0x0000e210, + 0xffc50000, 0x00000018, 0xffcd0000, 0x00002018, + 0xffd50000, 0x00004018, 0xffde0000, 0x00006118, + 0xffe60000, 0x00008118, 0xffee0000, 0x0000a118, + 0xfff60000, 0x0000c218, 0xffff0000, 0x0000e218, + 0xff000400, 0x00000020, 0xff080400, 0x00002020, + 0xff100400, 0x00004020, 0xff180400, 0x00006120, + 0xff200400, 0x00008120, 0xff290400, 0x0000a120, + 0xff310400, 0x0000c220, 0xff390400, 0x0000e220, + 0xff410400, 0x00000029, 0xff4a0400, 0x00002029, + 0xff520400, 0x00004029, 0xff5a0400, 0x00006129, + 0xff620400, 0x00008129, 0xff6a0400, 0x0000a129, + 0xff730400, 0x0000c229, 0xff7b0400, 0x0000e229, + 0xff830400, 0x00000031, 0xff8b0400, 0x00002031, + 0xff940400, 0x00004031, 0xff9c0400, 0x00006131, + 0xffa40400, 0x00008131, 0xffac0400, 0x0000a131, + 0xffb40400, 0x0000c231, 0xffbd0400, 0x0000e231, + 0xffc50400, 0x00000039, 0xffcd0400, 0x00002039, + 0xffd50400, 0x00004039, 0xffde0400, 0x00006139, + 0xffe60400, 0x00008139, 0xffee0400, 0x0000a139, + 0xfff60400, 0x0000c239, 0xffff0400, 0x0000e239, + 0xff000800, 0x00000041, 0xff080800, 0x00002041, + 0xff100800, 0x00004041, 0xff180800, 0x00006141, + 0xff200800, 0x00008141, 0xff290800, 0x0000a141, + 0xff310800, 0x0000c241, 0xff390800, 0x0000e241, + 0xff410800, 0x0000004a, 0xff4a0800, 0x0000204a, + 0xff520800, 0x0000404a, 0xff5a0800, 0x0000614a, + 0xff620800, 0x0000814a, 0xff6a0800, 0x0000a14a, + 0xff730800, 0x0000c24a, 0xff7b0800, 0x0000e24a, + 0xff830800, 0x00000052, 0xff8b0800, 0x00002052, + 0xff940800, 0x00004052, 0xff9c0800, 0x00006152, + 0xffa40800, 0x00008152, 0xffac0800, 0x0000a152, + 0xffb40800, 0x0000c252, 0xffbd0800, 0x0000e252, + 0xffc50800, 0x0000005a, 0xffcd0800, 0x0000205a, + 0xffd50800, 0x0000405a, 0xffde0800, 0x0000615a, + 0xffe60800, 0x0000815a, 0xffee0800, 0x0000a15a, + 0xfff60800, 0x0000c25a, 0xffff0800, 0x0000e25a, + 0xff000c00, 0x00000062, 0xff080c00, 0x00002062, + 0xff100c00, 0x00004062, 0xff180c00, 0x00006162, + 0xff200c00, 0x00008162, 0xff290c00, 0x0000a162, + 0xff310c00, 0x0000c262, 0xff390c00, 0x0000e262, + 0xff410c00, 0x0000006a, 0xff4a0c00, 0x0000206a, + 0xff520c00, 0x0000406a, 0xff5a0c00, 0x0000616a, + 0xff620c00, 0x0000816a, 0xff6a0c00, 0x0000a16a, + 0xff730c00, 0x0000c26a, 0xff7b0c00, 0x0000e26a, + 0xff830c00, 0x00000073, 0xff8b0c00, 0x00002073, + 0xff940c00, 0x00004073, 0xff9c0c00, 0x00006173, + 0xffa40c00, 0x00008173, 0xffac0c00, 0x0000a173, + 0xffb40c00, 0x0000c273, 0xffbd0c00, 0x0000e273, + 0xffc50c00, 0x0000007b, 0xffcd0c00, 0x0000207b, + 0xffd50c00, 0x0000407b, 0xffde0c00, 0x0000617b, + 0xffe60c00, 0x0000817b, 0xffee0c00, 0x0000a17b, + 0xfff60c00, 0x0000c27b, 0xffff0c00, 0x0000e27b, + 0xff001000, 0x00000083, 0xff081000, 0x00002083, + 0xff101000, 0x00004083, 0xff181000, 0x00006183, + 0xff201000, 0x00008183, 0xff291000, 0x0000a183, + 0xff311000, 0x0000c283, 0xff391000, 0x0000e283, + 0xff411000, 0x0000008b, 0xff4a1000, 0x0000208b, + 0xff521000, 0x0000408b, 0xff5a1000, 0x0000618b, + 0xff621000, 0x0000818b, 0xff6a1000, 0x0000a18b, + 0xff731000, 0x0000c28b, 0xff7b1000, 0x0000e28b, + 0xff831000, 0x00000094, 0xff8b1000, 0x00002094, + 0xff941000, 0x00004094, 0xff9c1000, 0x00006194, + 0xffa41000, 0x00008194, 0xffac1000, 0x0000a194, + 0xffb41000, 0x0000c294, 0xffbd1000, 0x0000e294, + 0xffc51000, 0x0000009c, 0xffcd1000, 0x0000209c, + 0xffd51000, 0x0000409c, 0xffde1000, 0x0000619c, + 0xffe61000, 0x0000819c, 0xffee1000, 0x0000a19c, + 0xfff61000, 0x0000c29c, 0xffff1000, 0x0000e29c, + 0xff001400, 0x000000a4, 0xff081400, 0x000020a4, + 0xff101400, 0x000040a4, 0xff181400, 0x000061a4, + 0xff201400, 0x000081a4, 0xff291400, 0x0000a1a4, + 0xff311400, 0x0000c2a4, 0xff391400, 0x0000e2a4, + 0xff411400, 0x000000ac, 0xff4a1400, 0x000020ac, + 0xff521400, 0x000040ac, 0xff5a1400, 0x000061ac, + 0xff621400, 0x000081ac, 0xff6a1400, 0x0000a1ac, + 0xff731400, 0x0000c2ac, 0xff7b1400, 0x0000e2ac, + 0xff831400, 0x000000b4, 0xff8b1400, 0x000020b4, + 0xff941400, 0x000040b4, 0xff9c1400, 0x000061b4, + 0xffa41400, 0x000081b4, 0xffac1400, 0x0000a1b4, + 0xffb41400, 0x0000c2b4, 0xffbd1400, 0x0000e2b4, + 0xffc51400, 0x000000bd, 0xffcd1400, 0x000020bd, + 0xffd51400, 0x000040bd, 0xffde1400, 0x000061bd, + 0xffe61400, 0x000081bd, 0xffee1400, 0x0000a1bd, + 0xfff61400, 0x0000c2bd, 0xffff1400, 0x0000e2bd, + 0xff001800, 0x000000c5, 0xff081800, 0x000020c5, + 0xff101800, 0x000040c5, 0xff181800, 0x000061c5, + 0xff201800, 0x000081c5, 0xff291800, 0x0000a1c5, + 0xff311800, 0x0000c2c5, 0xff391800, 0x0000e2c5, + 0xff411800, 0x000000cd, 0xff4a1800, 0x000020cd, + 0xff521800, 0x000040cd, 0xff5a1800, 0x000061cd, + 0xff621800, 0x000081cd, 0xff6a1800, 0x0000a1cd, + 0xff731800, 0x0000c2cd, 0xff7b1800, 0x0000e2cd, + 0xff831800, 0x000000d5, 0xff8b1800, 0x000020d5, + 0xff941800, 0x000040d5, 0xff9c1800, 0x000061d5, + 0xffa41800, 0x000081d5, 0xffac1800, 0x0000a1d5, + 0xffb41800, 0x0000c2d5, 0xffbd1800, 0x0000e2d5, + 0xffc51800, 0x000000de, 0xffcd1800, 0x000020de, + 0xffd51800, 0x000040de, 0xffde1800, 0x000061de, + 0xffe61800, 0x000081de, 0xffee1800, 0x0000a1de, + 0xfff61800, 0x0000c2de, 0xffff1800, 0x0000e2de, + 0xff001c00, 0x000000e6, 0xff081c00, 0x000020e6, + 0xff101c00, 0x000040e6, 0xff181c00, 0x000061e6, + 0xff201c00, 0x000081e6, 0xff291c00, 0x0000a1e6, + 0xff311c00, 0x0000c2e6, 0xff391c00, 0x0000e2e6, + 0xff411c00, 0x000000ee, 0xff4a1c00, 0x000020ee, + 0xff521c00, 0x000040ee, 0xff5a1c00, 0x000061ee, + 0xff621c00, 0x000081ee, 0xff6a1c00, 0x0000a1ee, + 0xff731c00, 0x0000c2ee, 0xff7b1c00, 0x0000e2ee, + 0xff831c00, 0x000000f6, 0xff8b1c00, 0x000020f6, + 0xff941c00, 0x000040f6, 0xff9c1c00, 0x000061f6, + 0xffa41c00, 0x000081f6, 0xffac1c00, 0x0000a1f6, + 0xffb41c00, 0x0000c2f6, 0xffbd1c00, 0x0000e2f6, + 0xffc51c00, 0x000000ff, 0xffcd1c00, 0x000020ff, + 0xffd51c00, 0x000040ff, 0xffde1c00, 0x000061ff, + 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff, + 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff }; -static void Blit_RGB565_ABGR8888(SDL_BlitInfo *info) +static void +Blit_RGB565_ABGR8888 (SDL_BlitInfo * info) { - Blit_RGB565_32(info, RGB565_ABGR8888_LUT); + Blit_RGB565_32 (info, RGB565_ABGR8888_LUT); } /* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */ static const Uint32 RGB565_RGBA8888_LUT[512] = { - 0x000000ff, 0x00000000, 0x000008ff, 0x00200000, - 0x000010ff, 0x00400000, 0x000018ff, 0x00610000, - 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000, - 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000, - 0x000041ff, 0x08000000, 0x00004aff, 0x08200000, - 0x000052ff, 0x08400000, 0x00005aff, 0x08610000, - 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000, - 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000, - 0x000083ff, 0x10000000, 0x00008bff, 0x10200000, - 0x000094ff, 0x10400000, 0x00009cff, 0x10610000, - 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000, - 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000, - 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000, - 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000, - 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000, - 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000, - 0x000400ff, 0x20000000, 0x000408ff, 0x20200000, - 0x000410ff, 0x20400000, 0x000418ff, 0x20610000, - 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000, - 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000, - 0x000441ff, 0x29000000, 0x00044aff, 0x29200000, - 0x000452ff, 0x29400000, 0x00045aff, 0x29610000, - 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000, - 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000, - 0x000483ff, 0x31000000, 0x00048bff, 0x31200000, - 0x000494ff, 0x31400000, 0x00049cff, 0x31610000, - 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000, - 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000, - 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000, - 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000, - 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000, - 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000, - 0x000800ff, 0x41000000, 0x000808ff, 0x41200000, - 0x000810ff, 0x41400000, 0x000818ff, 0x41610000, - 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000, - 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000, - 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000, - 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000, - 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000, - 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000, - 0x000883ff, 0x52000000, 0x00088bff, 0x52200000, - 0x000894ff, 0x52400000, 0x00089cff, 0x52610000, - 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000, - 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000, - 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000, - 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000, - 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000, - 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000, - 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000, - 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000, - 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000, - 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000, - 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000, - 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000, - 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000, - 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000, - 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000, - 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000, - 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000, - 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000, - 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000, - 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000, - 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000, - 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000, - 0x001000ff, 0x83000000, 0x001008ff, 0x83200000, - 0x001010ff, 0x83400000, 0x001018ff, 0x83610000, - 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000, - 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000, - 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000, - 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000, - 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000, - 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000, - 0x001083ff, 0x94000000, 0x00108bff, 0x94200000, - 0x001094ff, 0x94400000, 0x00109cff, 0x94610000, - 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000, - 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000, - 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000, - 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000, - 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000, - 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000, - 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000, - 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000, - 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000, - 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000, - 0x001441ff, 0xac000000, 0x00144aff, 0xac200000, - 0x001452ff, 0xac400000, 0x00145aff, 0xac610000, - 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000, - 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000, - 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000, - 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000, - 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000, - 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000, - 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000, - 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000, - 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000, - 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000, - 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000, - 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000, - 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000, - 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000, - 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000, - 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000, - 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000, - 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000, - 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000, - 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000, - 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000, - 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000, - 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000, - 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000, - 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000, - 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000, - 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000, - 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000, - 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000, - 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000, - 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000, - 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000, - 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000, - 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000, - 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000, - 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000, - 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000, - 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000, - 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000, - 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000, - 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000, - 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000, + 0x000000ff, 0x00000000, 0x000008ff, 0x00200000, + 0x000010ff, 0x00400000, 0x000018ff, 0x00610000, + 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000, + 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000, + 0x000041ff, 0x08000000, 0x00004aff, 0x08200000, + 0x000052ff, 0x08400000, 0x00005aff, 0x08610000, + 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000, + 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000, + 0x000083ff, 0x10000000, 0x00008bff, 0x10200000, + 0x000094ff, 0x10400000, 0x00009cff, 0x10610000, + 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000, + 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000, + 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000, + 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000, + 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000, + 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000, + 0x000400ff, 0x20000000, 0x000408ff, 0x20200000, + 0x000410ff, 0x20400000, 0x000418ff, 0x20610000, + 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000, + 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000, + 0x000441ff, 0x29000000, 0x00044aff, 0x29200000, + 0x000452ff, 0x29400000, 0x00045aff, 0x29610000, + 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000, + 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000, + 0x000483ff, 0x31000000, 0x00048bff, 0x31200000, + 0x000494ff, 0x31400000, 0x00049cff, 0x31610000, + 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000, + 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000, + 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000, + 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000, + 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000, + 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000, + 0x000800ff, 0x41000000, 0x000808ff, 0x41200000, + 0x000810ff, 0x41400000, 0x000818ff, 0x41610000, + 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000, + 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000, + 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000, + 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000, + 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000, + 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000, + 0x000883ff, 0x52000000, 0x00088bff, 0x52200000, + 0x000894ff, 0x52400000, 0x00089cff, 0x52610000, + 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000, + 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000, + 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000, + 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000, + 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000, + 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000, + 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000, + 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000, + 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000, + 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000, + 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000, + 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000, + 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000, + 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000, + 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000, + 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000, + 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000, + 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000, + 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000, + 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000, + 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000, + 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000, + 0x001000ff, 0x83000000, 0x001008ff, 0x83200000, + 0x001010ff, 0x83400000, 0x001018ff, 0x83610000, + 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000, + 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000, + 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000, + 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000, + 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000, + 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000, + 0x001083ff, 0x94000000, 0x00108bff, 0x94200000, + 0x001094ff, 0x94400000, 0x00109cff, 0x94610000, + 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000, + 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000, + 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000, + 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000, + 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000, + 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000, + 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000, + 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000, + 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000, + 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000, + 0x001441ff, 0xac000000, 0x00144aff, 0xac200000, + 0x001452ff, 0xac400000, 0x00145aff, 0xac610000, + 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000, + 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000, + 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000, + 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000, + 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000, + 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000, + 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000, + 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000, + 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000, + 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000, + 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000, + 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000, + 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000, + 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000, + 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000, + 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000, + 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000, + 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000, + 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000, + 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000, + 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000, + 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000, + 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000, + 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000, + 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000, + 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000, + 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000, + 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000, + 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000, + 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000, + 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000, + 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000, + 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000, + 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000, + 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000, + 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000, + 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000, + 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000, + 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000, + 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000, + 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000, + 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000, }; -static void Blit_RGB565_RGBA8888(SDL_BlitInfo *info) +static void +Blit_RGB565_RGBA8888 (SDL_BlitInfo * info) { - Blit_RGB565_32(info, RGB565_RGBA8888_LUT); + Blit_RGB565_32 (info, RGB565_RGBA8888_LUT); } /* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */ static const Uint32 RGB565_BGRA8888_LUT[512] = { - 0x00000000, 0x000000ff, 0x08000000, 0x002000ff, - 0x10000000, 0x004000ff, 0x18000000, 0x006100ff, - 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff, - 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff, - 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff, - 0x52000000, 0x004008ff, 0x5a000000, 0x006108ff, - 0x62000000, 0x008108ff, 0x6a000000, 0x00a108ff, - 0x73000000, 0x00c208ff, 0x7b000000, 0x00e208ff, - 0x83000000, 0x000010ff, 0x8b000000, 0x002010ff, - 0x94000000, 0x004010ff, 0x9c000000, 0x006110ff, - 0xa4000000, 0x008110ff, 0xac000000, 0x00a110ff, - 0xb4000000, 0x00c210ff, 0xbd000000, 0x00e210ff, - 0xc5000000, 0x000018ff, 0xcd000000, 0x002018ff, - 0xd5000000, 0x004018ff, 0xde000000, 0x006118ff, - 0xe6000000, 0x008118ff, 0xee000000, 0x00a118ff, - 0xf6000000, 0x00c218ff, 0xff000000, 0x00e218ff, - 0x00040000, 0x000020ff, 0x08040000, 0x002020ff, - 0x10040000, 0x004020ff, 0x18040000, 0x006120ff, - 0x20040000, 0x008120ff, 0x29040000, 0x00a120ff, - 0x31040000, 0x00c220ff, 0x39040000, 0x00e220ff, - 0x41040000, 0x000029ff, 0x4a040000, 0x002029ff, - 0x52040000, 0x004029ff, 0x5a040000, 0x006129ff, - 0x62040000, 0x008129ff, 0x6a040000, 0x00a129ff, - 0x73040000, 0x00c229ff, 0x7b040000, 0x00e229ff, - 0x83040000, 0x000031ff, 0x8b040000, 0x002031ff, - 0x94040000, 0x004031ff, 0x9c040000, 0x006131ff, - 0xa4040000, 0x008131ff, 0xac040000, 0x00a131ff, - 0xb4040000, 0x00c231ff, 0xbd040000, 0x00e231ff, - 0xc5040000, 0x000039ff, 0xcd040000, 0x002039ff, - 0xd5040000, 0x004039ff, 0xde040000, 0x006139ff, - 0xe6040000, 0x008139ff, 0xee040000, 0x00a139ff, - 0xf6040000, 0x00c239ff, 0xff040000, 0x00e239ff, - 0x00080000, 0x000041ff, 0x08080000, 0x002041ff, - 0x10080000, 0x004041ff, 0x18080000, 0x006141ff, - 0x20080000, 0x008141ff, 0x29080000, 0x00a141ff, - 0x31080000, 0x00c241ff, 0x39080000, 0x00e241ff, - 0x41080000, 0x00004aff, 0x4a080000, 0x00204aff, - 0x52080000, 0x00404aff, 0x5a080000, 0x00614aff, - 0x62080000, 0x00814aff, 0x6a080000, 0x00a14aff, - 0x73080000, 0x00c24aff, 0x7b080000, 0x00e24aff, - 0x83080000, 0x000052ff, 0x8b080000, 0x002052ff, - 0x94080000, 0x004052ff, 0x9c080000, 0x006152ff, - 0xa4080000, 0x008152ff, 0xac080000, 0x00a152ff, - 0xb4080000, 0x00c252ff, 0xbd080000, 0x00e252ff, - 0xc5080000, 0x00005aff, 0xcd080000, 0x00205aff, - 0xd5080000, 0x00405aff, 0xde080000, 0x00615aff, - 0xe6080000, 0x00815aff, 0xee080000, 0x00a15aff, - 0xf6080000, 0x00c25aff, 0xff080000, 0x00e25aff, - 0x000c0000, 0x000062ff, 0x080c0000, 0x002062ff, - 0x100c0000, 0x004062ff, 0x180c0000, 0x006162ff, - 0x200c0000, 0x008162ff, 0x290c0000, 0x00a162ff, - 0x310c0000, 0x00c262ff, 0x390c0000, 0x00e262ff, - 0x410c0000, 0x00006aff, 0x4a0c0000, 0x00206aff, - 0x520c0000, 0x00406aff, 0x5a0c0000, 0x00616aff, - 0x620c0000, 0x00816aff, 0x6a0c0000, 0x00a16aff, - 0x730c0000, 0x00c26aff, 0x7b0c0000, 0x00e26aff, - 0x830c0000, 0x000073ff, 0x8b0c0000, 0x002073ff, - 0x940c0000, 0x004073ff, 0x9c0c0000, 0x006173ff, - 0xa40c0000, 0x008173ff, 0xac0c0000, 0x00a173ff, - 0xb40c0000, 0x00c273ff, 0xbd0c0000, 0x00e273ff, - 0xc50c0000, 0x00007bff, 0xcd0c0000, 0x00207bff, - 0xd50c0000, 0x00407bff, 0xde0c0000, 0x00617bff, - 0xe60c0000, 0x00817bff, 0xee0c0000, 0x00a17bff, - 0xf60c0000, 0x00c27bff, 0xff0c0000, 0x00e27bff, - 0x00100000, 0x000083ff, 0x08100000, 0x002083ff, - 0x10100000, 0x004083ff, 0x18100000, 0x006183ff, - 0x20100000, 0x008183ff, 0x29100000, 0x00a183ff, - 0x31100000, 0x00c283ff, 0x39100000, 0x00e283ff, - 0x41100000, 0x00008bff, 0x4a100000, 0x00208bff, - 0x52100000, 0x00408bff, 0x5a100000, 0x00618bff, - 0x62100000, 0x00818bff, 0x6a100000, 0x00a18bff, - 0x73100000, 0x00c28bff, 0x7b100000, 0x00e28bff, - 0x83100000, 0x000094ff, 0x8b100000, 0x002094ff, - 0x94100000, 0x004094ff, 0x9c100000, 0x006194ff, - 0xa4100000, 0x008194ff, 0xac100000, 0x00a194ff, - 0xb4100000, 0x00c294ff, 0xbd100000, 0x00e294ff, - 0xc5100000, 0x00009cff, 0xcd100000, 0x00209cff, - 0xd5100000, 0x00409cff, 0xde100000, 0x00619cff, - 0xe6100000, 0x00819cff, 0xee100000, 0x00a19cff, - 0xf6100000, 0x00c29cff, 0xff100000, 0x00e29cff, - 0x00140000, 0x0000a4ff, 0x08140000, 0x0020a4ff, - 0x10140000, 0x0040a4ff, 0x18140000, 0x0061a4ff, - 0x20140000, 0x0081a4ff, 0x29140000, 0x00a1a4ff, - 0x31140000, 0x00c2a4ff, 0x39140000, 0x00e2a4ff, - 0x41140000, 0x0000acff, 0x4a140000, 0x0020acff, - 0x52140000, 0x0040acff, 0x5a140000, 0x0061acff, - 0x62140000, 0x0081acff, 0x6a140000, 0x00a1acff, - 0x73140000, 0x00c2acff, 0x7b140000, 0x00e2acff, - 0x83140000, 0x0000b4ff, 0x8b140000, 0x0020b4ff, - 0x94140000, 0x0040b4ff, 0x9c140000, 0x0061b4ff, - 0xa4140000, 0x0081b4ff, 0xac140000, 0x00a1b4ff, - 0xb4140000, 0x00c2b4ff, 0xbd140000, 0x00e2b4ff, - 0xc5140000, 0x0000bdff, 0xcd140000, 0x0020bdff, - 0xd5140000, 0x0040bdff, 0xde140000, 0x0061bdff, - 0xe6140000, 0x0081bdff, 0xee140000, 0x00a1bdff, - 0xf6140000, 0x00c2bdff, 0xff140000, 0x00e2bdff, - 0x00180000, 0x0000c5ff, 0x08180000, 0x0020c5ff, - 0x10180000, 0x0040c5ff, 0x18180000, 0x0061c5ff, - 0x20180000, 0x0081c5ff, 0x29180000, 0x00a1c5ff, - 0x31180000, 0x00c2c5ff, 0x39180000, 0x00e2c5ff, - 0x41180000, 0x0000cdff, 0x4a180000, 0x0020cdff, - 0x52180000, 0x0040cdff, 0x5a180000, 0x0061cdff, - 0x62180000, 0x0081cdff, 0x6a180000, 0x00a1cdff, - 0x73180000, 0x00c2cdff, 0x7b180000, 0x00e2cdff, - 0x83180000, 0x0000d5ff, 0x8b180000, 0x0020d5ff, - 0x94180000, 0x0040d5ff, 0x9c180000, 0x0061d5ff, - 0xa4180000, 0x0081d5ff, 0xac180000, 0x00a1d5ff, - 0xb4180000, 0x00c2d5ff, 0xbd180000, 0x00e2d5ff, - 0xc5180000, 0x0000deff, 0xcd180000, 0x0020deff, - 0xd5180000, 0x0040deff, 0xde180000, 0x0061deff, - 0xe6180000, 0x0081deff, 0xee180000, 0x00a1deff, - 0xf6180000, 0x00c2deff, 0xff180000, 0x00e2deff, - 0x001c0000, 0x0000e6ff, 0x081c0000, 0x0020e6ff, - 0x101c0000, 0x0040e6ff, 0x181c0000, 0x0061e6ff, - 0x201c0000, 0x0081e6ff, 0x291c0000, 0x00a1e6ff, - 0x311c0000, 0x00c2e6ff, 0x391c0000, 0x00e2e6ff, - 0x411c0000, 0x0000eeff, 0x4a1c0000, 0x0020eeff, - 0x521c0000, 0x0040eeff, 0x5a1c0000, 0x0061eeff, - 0x621c0000, 0x0081eeff, 0x6a1c0000, 0x00a1eeff, - 0x731c0000, 0x00c2eeff, 0x7b1c0000, 0x00e2eeff, - 0x831c0000, 0x0000f6ff, 0x8b1c0000, 0x0020f6ff, - 0x941c0000, 0x0040f6ff, 0x9c1c0000, 0x0061f6ff, - 0xa41c0000, 0x0081f6ff, 0xac1c0000, 0x00a1f6ff, - 0xb41c0000, 0x00c2f6ff, 0xbd1c0000, 0x00e2f6ff, - 0xc51c0000, 0x0000ffff, 0xcd1c0000, 0x0020ffff, - 0xd51c0000, 0x0040ffff, 0xde1c0000, 0x0061ffff, - 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff, - 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff + 0x00000000, 0x000000ff, 0x08000000, 0x002000ff, + 0x10000000, 0x004000ff, 0x18000000, 0x006100ff, + 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff, + 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff, + 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff, + 0x52000000, 0x004008ff, 0x5a000000, 0x006108ff, + 0x62000000, 0x008108ff, 0x6a000000, 0x00a108ff, + 0x73000000, 0x00c208ff, 0x7b000000, 0x00e208ff, + 0x83000000, 0x000010ff, 0x8b000000, 0x002010ff, + 0x94000000, 0x004010ff, 0x9c000000, 0x006110ff, + 0xa4000000, 0x008110ff, 0xac000000, 0x00a110ff, + 0xb4000000, 0x00c210ff, 0xbd000000, 0x00e210ff, + 0xc5000000, 0x000018ff, 0xcd000000, 0x002018ff, + 0xd5000000, 0x004018ff, 0xde000000, 0x006118ff, + 0xe6000000, 0x008118ff, 0xee000000, 0x00a118ff, + 0xf6000000, 0x00c218ff, 0xff000000, 0x00e218ff, + 0x00040000, 0x000020ff, 0x08040000, 0x002020ff, + 0x10040000, 0x004020ff, 0x18040000, 0x006120ff, + 0x20040000, 0x008120ff, 0x29040000, 0x00a120ff, + 0x31040000, 0x00c220ff, 0x39040000, 0x00e220ff, + 0x41040000, 0x000029ff, 0x4a040000, 0x002029ff, + 0x52040000, 0x004029ff, 0x5a040000, 0x006129ff, + 0x62040000, 0x008129ff, 0x6a040000, 0x00a129ff, + 0x73040000, 0x00c229ff, 0x7b040000, 0x00e229ff, + 0x83040000, 0x000031ff, 0x8b040000, 0x002031ff, + 0x94040000, 0x004031ff, 0x9c040000, 0x006131ff, + 0xa4040000, 0x008131ff, 0xac040000, 0x00a131ff, + 0xb4040000, 0x00c231ff, 0xbd040000, 0x00e231ff, + 0xc5040000, 0x000039ff, 0xcd040000, 0x002039ff, + 0xd5040000, 0x004039ff, 0xde040000, 0x006139ff, + 0xe6040000, 0x008139ff, 0xee040000, 0x00a139ff, + 0xf6040000, 0x00c239ff, 0xff040000, 0x00e239ff, + 0x00080000, 0x000041ff, 0x08080000, 0x002041ff, + 0x10080000, 0x004041ff, 0x18080000, 0x006141ff, + 0x20080000, 0x008141ff, 0x29080000, 0x00a141ff, + 0x31080000, 0x00c241ff, 0x39080000, 0x00e241ff, + 0x41080000, 0x00004aff, 0x4a080000, 0x00204aff, + 0x52080000, 0x00404aff, 0x5a080000, 0x00614aff, + 0x62080000, 0x00814aff, 0x6a080000, 0x00a14aff, + 0x73080000, 0x00c24aff, 0x7b080000, 0x00e24aff, + 0x83080000, 0x000052ff, 0x8b080000, 0x002052ff, + 0x94080000, 0x004052ff, 0x9c080000, 0x006152ff, + 0xa4080000, 0x008152ff, 0xac080000, 0x00a152ff, + 0xb4080000, 0x00c252ff, 0xbd080000, 0x00e252ff, + 0xc5080000, 0x00005aff, 0xcd080000, 0x00205aff, + 0xd5080000, 0x00405aff, 0xde080000, 0x00615aff, + 0xe6080000, 0x00815aff, 0xee080000, 0x00a15aff, + 0xf6080000, 0x00c25aff, 0xff080000, 0x00e25aff, + 0x000c0000, 0x000062ff, 0x080c0000, 0x002062ff, + 0x100c0000, 0x004062ff, 0x180c0000, 0x006162ff, + 0x200c0000, 0x008162ff, 0x290c0000, 0x00a162ff, + 0x310c0000, 0x00c262ff, 0x390c0000, 0x00e262ff, + 0x410c0000, 0x00006aff, 0x4a0c0000, 0x00206aff, + 0x520c0000, 0x00406aff, 0x5a0c0000, 0x00616aff, + 0x620c0000, 0x00816aff, 0x6a0c0000, 0x00a16aff, + 0x730c0000, 0x00c26aff, 0x7b0c0000, 0x00e26aff, + 0x830c0000, 0x000073ff, 0x8b0c0000, 0x002073ff, + 0x940c0000, 0x004073ff, 0x9c0c0000, 0x006173ff, + 0xa40c0000, 0x008173ff, 0xac0c0000, 0x00a173ff, + 0xb40c0000, 0x00c273ff, 0xbd0c0000, 0x00e273ff, + 0xc50c0000, 0x00007bff, 0xcd0c0000, 0x00207bff, + 0xd50c0000, 0x00407bff, 0xde0c0000, 0x00617bff, + 0xe60c0000, 0x00817bff, 0xee0c0000, 0x00a17bff, + 0xf60c0000, 0x00c27bff, 0xff0c0000, 0x00e27bff, + 0x00100000, 0x000083ff, 0x08100000, 0x002083ff, + 0x10100000, 0x004083ff, 0x18100000, 0x006183ff, + 0x20100000, 0x008183ff, 0x29100000, 0x00a183ff, + 0x31100000, 0x00c283ff, 0x39100000, 0x00e283ff, + 0x41100000, 0x00008bff, 0x4a100000, 0x00208bff, + 0x52100000, 0x00408bff, 0x5a100000, 0x00618bff, + 0x62100000, 0x00818bff, 0x6a100000, 0x00a18bff, + 0x73100000, 0x00c28bff, 0x7b100000, 0x00e28bff, + 0x83100000, 0x000094ff, 0x8b100000, 0x002094ff, + 0x94100000, 0x004094ff, 0x9c100000, 0x006194ff, + 0xa4100000, 0x008194ff, 0xac100000, 0x00a194ff, + 0xb4100000, 0x00c294ff, 0xbd100000, 0x00e294ff, + 0xc5100000, 0x00009cff, 0xcd100000, 0x00209cff, + 0xd5100000, 0x00409cff, 0xde100000, 0x00619cff, + 0xe6100000, 0x00819cff, 0xee100000, 0x00a19cff, + 0xf6100000, 0x00c29cff, 0xff100000, 0x00e29cff, + 0x00140000, 0x0000a4ff, 0x08140000, 0x0020a4ff, + 0x10140000, 0x0040a4ff, 0x18140000, 0x0061a4ff, + 0x20140000, 0x0081a4ff, 0x29140000, 0x00a1a4ff, + 0x31140000, 0x00c2a4ff, 0x39140000, 0x00e2a4ff, + 0x41140000, 0x0000acff, 0x4a140000, 0x0020acff, + 0x52140000, 0x0040acff, 0x5a140000, 0x0061acff, + 0x62140000, 0x0081acff, 0x6a140000, 0x00a1acff, + 0x73140000, 0x00c2acff, 0x7b140000, 0x00e2acff, + 0x83140000, 0x0000b4ff, 0x8b140000, 0x0020b4ff, + 0x94140000, 0x0040b4ff, 0x9c140000, 0x0061b4ff, + 0xa4140000, 0x0081b4ff, 0xac140000, 0x00a1b4ff, + 0xb4140000, 0x00c2b4ff, 0xbd140000, 0x00e2b4ff, + 0xc5140000, 0x0000bdff, 0xcd140000, 0x0020bdff, + 0xd5140000, 0x0040bdff, 0xde140000, 0x0061bdff, + 0xe6140000, 0x0081bdff, 0xee140000, 0x00a1bdff, + 0xf6140000, 0x00c2bdff, 0xff140000, 0x00e2bdff, + 0x00180000, 0x0000c5ff, 0x08180000, 0x0020c5ff, + 0x10180000, 0x0040c5ff, 0x18180000, 0x0061c5ff, + 0x20180000, 0x0081c5ff, 0x29180000, 0x00a1c5ff, + 0x31180000, 0x00c2c5ff, 0x39180000, 0x00e2c5ff, + 0x41180000, 0x0000cdff, 0x4a180000, 0x0020cdff, + 0x52180000, 0x0040cdff, 0x5a180000, 0x0061cdff, + 0x62180000, 0x0081cdff, 0x6a180000, 0x00a1cdff, + 0x73180000, 0x00c2cdff, 0x7b180000, 0x00e2cdff, + 0x83180000, 0x0000d5ff, 0x8b180000, 0x0020d5ff, + 0x94180000, 0x0040d5ff, 0x9c180000, 0x0061d5ff, + 0xa4180000, 0x0081d5ff, 0xac180000, 0x00a1d5ff, + 0xb4180000, 0x00c2d5ff, 0xbd180000, 0x00e2d5ff, + 0xc5180000, 0x0000deff, 0xcd180000, 0x0020deff, + 0xd5180000, 0x0040deff, 0xde180000, 0x0061deff, + 0xe6180000, 0x0081deff, 0xee180000, 0x00a1deff, + 0xf6180000, 0x00c2deff, 0xff180000, 0x00e2deff, + 0x001c0000, 0x0000e6ff, 0x081c0000, 0x0020e6ff, + 0x101c0000, 0x0040e6ff, 0x181c0000, 0x0061e6ff, + 0x201c0000, 0x0081e6ff, 0x291c0000, 0x00a1e6ff, + 0x311c0000, 0x00c2e6ff, 0x391c0000, 0x00e2e6ff, + 0x411c0000, 0x0000eeff, 0x4a1c0000, 0x0020eeff, + 0x521c0000, 0x0040eeff, 0x5a1c0000, 0x0061eeff, + 0x621c0000, 0x0081eeff, 0x6a1c0000, 0x00a1eeff, + 0x731c0000, 0x00c2eeff, 0x7b1c0000, 0x00e2eeff, + 0x831c0000, 0x0000f6ff, 0x8b1c0000, 0x0020f6ff, + 0x941c0000, 0x0040f6ff, 0x9c1c0000, 0x0061f6ff, + 0xa41c0000, 0x0081f6ff, 0xac1c0000, 0x00a1f6ff, + 0xb41c0000, 0x00c2f6ff, 0xbd1c0000, 0x00e2f6ff, + 0xc51c0000, 0x0000ffff, 0xcd1c0000, 0x0020ffff, + 0xd51c0000, 0x0040ffff, 0xde1c0000, 0x0061ffff, + 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff, + 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff }; -static void Blit_RGB565_BGRA8888(SDL_BlitInfo *info) +static void +Blit_RGB565_BGRA8888 (SDL_BlitInfo * info) { - Blit_RGB565_32(info, RGB565_BGRA8888_LUT); + Blit_RGB565_32 (info, RGB565_BGRA8888_LUT); } /* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */ @@ -1826,102 +1878,107 @@ static void Blit_RGB565_BGRA8888(SDL_BlitInfo *info) (((src)&0x000000C0)>>6); \ } #endif -static void Blit_RGB888_index8_map(SDL_BlitInfo *info) +static void +Blit_RGB888_index8_map (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int Pixel; - int width, height; - Uint32 *src; - const Uint8 *map; - Uint8 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = (Uint32 *)info->s_pixels; - srcskip = info->s_skip/4; - dst = info->d_pixels; - dstskip = info->d_skip; - map = info->table; + int Pixel; + int width, height; + Uint32 *src; + const Uint8 *map; + Uint8 *dst; + int srcskip, dstskip; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = (Uint32 *) info->s_pixels; + srcskip = info->s_skip / 4; + dst = info->d_pixels; + dstskip = info->d_skip; + map = info->table; #ifdef USE_DUFFS_LOOP - while ( height-- ) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; , width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } #else - while ( height-- ) { - for ( c=width/4; c; --c ) { - /* Pack RGB into 8bit pixel */ - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } - switch ( width & 3 ) { - case 3: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 2: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 1: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } - src += srcskip; - dst += dstskip; - } + while (height--) { + for (c = width / 4; c; --c) { + /* Pack RGB into 8bit pixel */ + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + } + switch (width & 3) { + case 3: + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + case 2: + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + case 1: + RGB888_RGB332 (Pixel, *src); + *dst++ = map[Pixel]; + ++src; + } + src += srcskip; + dst += dstskip; + } #endif /* USE_DUFFS_LOOP */ } -static void BlitNto1(SDL_BlitInfo *info) +static void +BlitNto1 (SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP - int c; + int c; #endif - int width, height; - Uint8 *src; - const Uint8 *map; - Uint8 *dst; - int srcskip, dstskip; - int srcbpp; - Uint32 Pixel; - int sR, sG, sB; - SDL_PixelFormat *srcfmt; - - /* Set up some basic variables */ - width = info->d_width; - height = info->d_height; - src = info->s_pixels; - srcskip = info->s_skip; - dst = info->d_pixels; - dstskip = info->d_skip; - map = info->table; - srcfmt = info->src; - srcbpp = srcfmt->BytesPerPixel; - - if ( map == NULL ) { - while ( height-- ) { + int width, height; + Uint8 *src; + const Uint8 *map; + Uint8 *dst; + int srcskip, dstskip; + int srcbpp; + Uint32 Pixel; + int sR, sG, sB; + SDL_PixelFormat *srcfmt; + + /* Set up some basic variables */ + width = info->d_width; + height = info->d_height; + src = info->s_pixels; + srcskip = info->s_skip; + dst = info->d_pixels; + dstskip = info->d_skip; + map = info->table; + srcfmt = info->src; + srcbpp = srcfmt->BytesPerPixel; + + if (map == NULL) { + while (height--) { #ifdef USE_DUFFS_LOOP + /* *INDENT-OFF* */ DUFFS_LOOP( DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); @@ -1934,26 +1991,26 @@ static void BlitNto1(SDL_BlitInfo *info) dst++; src += srcbpp; , width); + /* *INDENT-ON* */ #else - for ( c=width; c; --c ) { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, - sR, sG, sB); - if ( 1 ) { - /* Pack RGB into 8bit pixel */ - *dst = ((sR>>5)<<(3+2))| - ((sG>>5)<<(2)) | - ((sB>>6)<<(0)) ; - } - dst++; - src += srcbpp; - } + for (c = width; c; --c) { + DISEMBLE_RGB (src, srcbpp, srcfmt, Pixel, sR, sG, sB); + if (1) { + /* Pack RGB into 8bit pixel */ + *dst = ((sR >> 5) << (3 + 2)) | + ((sG >> 5) << (2)) | ((sB >> 6) << (0)); + } + dst++; + src += srcbpp; + } #endif - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { #ifdef USE_DUFFS_LOOP + /* *INDENT-OFF* */ DUFFS_LOOP( DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); @@ -1966,43 +2023,44 @@ static void BlitNto1(SDL_BlitInfo *info) dst++; src += srcbpp; , width); + /* *INDENT-ON* */ #else - for ( c=width; c; --c ) { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, - sR, sG, sB); - if ( 1 ) { - /* Pack RGB into 8bit pixel */ - *dst = map[((sR>>5)<<(3+2))| - ((sG>>5)<<(2)) | - ((sB>>6)<<(0)) ]; - } - dst++; - src += srcbpp; - } + for (c = width; c; --c) { + DISEMBLE_RGB (src, srcbpp, srcfmt, Pixel, sR, sG, sB); + if (1) { + /* Pack RGB into 8bit pixel */ + *dst = map[((sR >> 5) << (3 + 2)) | + ((sG >> 5) << (2)) | ((sB >> 6) << (0))]; + } + dst++; + src += srcbpp; + } #endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } - } + src += srcskip; + dst += dstskip; + } + } } /* blits 32 bit RGB<->RGBA with both surfaces having the same R,G,B fields */ -static void Blit4to4MaskAlpha(SDL_BlitInfo *info) +static void +Blit4to4MaskAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint32 *src = (Uint32 *)info->s_pixels; - int srcskip = info->s_skip; - Uint32 *dst = (Uint32 *)info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - - if (dstfmt->Amask) { - /* RGB->RGBA, SET_ALPHA */ - Uint32 mask = (srcfmt->alpha >> dstfmt->Aloss) << dstfmt->Ashift; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint32 *src = (Uint32 *) info->s_pixels; + int srcskip = info->s_skip; + Uint32 *dst = (Uint32 *) info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + + if (dstfmt->Amask) { + /* RGB->RGBA, SET_ALPHA */ + Uint32 mask = (srcfmt->alpha >> dstfmt->Aloss) << dstfmt->Ashift; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { *dst = *src | mask; @@ -2010,14 +2068,16 @@ static void Blit4to4MaskAlpha(SDL_BlitInfo *info) ++src; }, width); - src = (Uint32*)((Uint8*)src + srcskip); - dst = (Uint32*)((Uint8*)dst + dstskip); - } - } else { - /* RGBA->RGB, NO_ALPHA */ - Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; - - while ( height-- ) { + /* *INDENT-ON* */ + src = (Uint32 *) ((Uint8 *) src + srcskip); + dst = (Uint32 *) ((Uint8 *) dst + dstskip); + } + } else { + /* RGBA->RGB, NO_ALPHA */ + Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { *dst = *src & mask; @@ -2025,27 +2085,30 @@ static void Blit4to4MaskAlpha(SDL_BlitInfo *info) ++src; }, width); - src = (Uint32*)((Uint8*)src + srcskip); - dst = (Uint32*)((Uint8*)dst + dstskip); - } - } + /* *INDENT-ON* */ + src = (Uint32 *) ((Uint8 *) src + srcskip); + dst = (Uint32 *) ((Uint8 *) dst + dstskip); + } + } } -static void BlitNtoN(SDL_BlitInfo *info) +static void +BlitNtoN (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - int srcbpp = srcfmt->BytesPerPixel; - SDL_PixelFormat *dstfmt = info->dst; - int dstbpp = dstfmt->BytesPerPixel; - unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + int srcbpp = srcfmt->BytesPerPixel; + SDL_PixelFormat *dstfmt = info->dst; + int dstbpp = dstfmt->BytesPerPixel; + unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 Pixel; @@ -2058,64 +2121,66 @@ static void BlitNtoN(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } -static void BlitNtoNCopyAlpha(SDL_BlitInfo *info) +static void +BlitNtoNCopyAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - int srcbpp = srcfmt->BytesPerPixel; - SDL_PixelFormat *dstfmt = info->dst; - int dstbpp = dstfmt->BytesPerPixel; - int c; - - /* FIXME: should map alpha to [0..255] correctly! */ - while ( height-- ) { - for ( c=width; c; --c ) { - Uint32 Pixel; - unsigned sR, sG, sB, sA; - DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, - sR, sG, sB, sA); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, - sR, sG, sB, sA); - dst += dstbpp; - src += srcbpp; - } - src += srcskip; - dst += dstskip; - } + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + int srcbpp = srcfmt->BytesPerPixel; + SDL_PixelFormat *dstfmt = info->dst; + int dstbpp = dstfmt->BytesPerPixel; + int c; + + /* FIXME: should map alpha to [0..255] correctly! */ + while (height--) { + for (c = width; c; --c) { + Uint32 Pixel; + unsigned sR, sG, sB, sA; + DISEMBLE_RGBA (src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); + ASSEMBLE_RGBA (dst, dstbpp, dstfmt, sR, sG, sB, sA); + dst += dstbpp; + src += srcbpp; + } + src += srcskip; + dst += dstskip; + } } -static void BlitNto1Key(SDL_BlitInfo *info) +static void +BlitNto1Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - SDL_PixelFormat *srcfmt = info->src; - const Uint8 *palmap = info->table; - Uint32 ckey = srcfmt->colorkey; - Uint32 rgbmask = ~srcfmt->Amask; - int srcbpp; - Uint32 Pixel; - unsigned sR, sG, sB; - - /* Set up some basic variables */ - srcbpp = srcfmt->BytesPerPixel; - ckey &= rgbmask; - - if ( palmap == NULL ) { - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + SDL_PixelFormat *srcfmt = info->src; + const Uint8 *palmap = info->table; + Uint32 ckey = srcfmt->colorkey; + Uint32 rgbmask = ~srcfmt->Amask; + int srcbpp; + Uint32 Pixel; + unsigned sR, sG, sB; + + /* Set up some basic variables */ + srcbpp = srcfmt->BytesPerPixel; + ckey &= rgbmask; + + if (palmap == NULL) { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, @@ -2130,11 +2195,13 @@ static void BlitNto1Key(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } - } else { - while ( height-- ) { + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } + } else { + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, @@ -2149,29 +2216,32 @@ static void BlitNto1Key(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } + } } -static void Blit2to2Key(SDL_BlitInfo *info) +static void +Blit2to2Key (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint16 *srcp = (Uint16 *)info->s_pixels; - int srcskip = info->s_skip; - Uint16 *dstp = (Uint16 *)info->d_pixels; - int dstskip = info->d_skip; - Uint32 ckey = info->src->colorkey; - Uint32 rgbmask = ~info->src->Amask; - - /* Set up some basic variables */ - srcskip /= 2; - dstskip /= 2; - ckey &= rgbmask; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint16 *srcp = (Uint16 *) info->s_pixels; + int srcskip = info->s_skip; + Uint16 *dstp = (Uint16 *) info->d_pixels; + int dstskip = info->d_skip; + Uint32 ckey = info->src->colorkey; + Uint32 rgbmask = ~info->src->Amask; + + /* Set up some basic variables */ + srcskip /= 2; + dstskip /= 2; + ckey &= rgbmask; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { if ( (*srcp & rgbmask) != ckey ) { @@ -2181,31 +2251,34 @@ static void Blit2to2Key(SDL_BlitInfo *info) srcp++; }, width); - srcp += srcskip; - dstp += dstskip; - } + /* *INDENT-ON* */ + srcp += srcskip; + dstp += dstskip; + } } -static void BlitNtoNKey(SDL_BlitInfo *info) +static void +BlitNtoNKey (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - Uint32 ckey = info->src->colorkey; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - int srcbpp = srcfmt->BytesPerPixel; - int dstbpp = dstfmt->BytesPerPixel; - unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; - Uint32 rgbmask = ~srcfmt->Amask; - - /* Set up some basic variables */ - ckey &= rgbmask; - - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + Uint32 ckey = info->src->colorkey; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + int srcbpp = srcfmt->BytesPerPixel; + int dstbpp = dstfmt->BytesPerPixel; + unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; + Uint32 rgbmask = ~srcfmt->Amask; + + /* Set up some basic variables */ + ckey &= rgbmask; + + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 Pixel; @@ -2222,36 +2295,39 @@ static void BlitNtoNKey(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } -static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info) +static void +BlitNtoNKeyCopyAlpha (SDL_BlitInfo * info) { - int width = info->d_width; - int height = info->d_height; - Uint8 *src = info->s_pixels; - int srcskip = info->s_skip; - Uint8 *dst = info->d_pixels; - int dstskip = info->d_skip; - Uint32 ckey = info->src->colorkey; - SDL_PixelFormat *srcfmt = info->src; - SDL_PixelFormat *dstfmt = info->dst; - Uint32 rgbmask = ~srcfmt->Amask; - - Uint8 srcbpp; - Uint8 dstbpp; - Uint32 Pixel; - unsigned sR, sG, sB, sA; - - /* Set up some basic variables */ - srcbpp = srcfmt->BytesPerPixel; - dstbpp = dstfmt->BytesPerPixel; - ckey &= rgbmask; - - /* FIXME: should map alpha to [0..255] correctly! */ - while ( height-- ) { + int width = info->d_width; + int height = info->d_height; + Uint8 *src = info->s_pixels; + int srcskip = info->s_skip; + Uint8 *dst = info->d_pixels; + int dstskip = info->d_skip; + Uint32 ckey = info->src->colorkey; + SDL_PixelFormat *srcfmt = info->src; + SDL_PixelFormat *dstfmt = info->dst; + Uint32 rgbmask = ~srcfmt->Amask; + + Uint8 srcbpp; + Uint8 dstbpp; + Uint32 Pixel; + unsigned sR, sG, sB, sA; + + /* Set up some basic variables */ + srcbpp = srcfmt->BytesPerPixel; + dstbpp = dstfmt->BytesPerPixel; + ckey &= rgbmask; + + /* FIXME: should map alpha to [0..255] correctly! */ + while (height--) { + /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, @@ -2264,227 +2340,261 @@ static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info) src += srcbpp; }, width); - src += srcskip; - dst += dstskip; - } + /* *INDENT-ON* */ + src += srcskip; + dst += dstskip; + } } /* Normal N to N optimized blitters */ -struct blit_table { - Uint32 srcR, srcG, srcB; - int dstbpp; - Uint32 dstR, dstG, dstB; - Uint32 blit_features; - void *aux_data; - SDL_loblit blitfunc; - enum { NO_ALPHA=1, SET_ALPHA=2, COPY_ALPHA=4 } alpha; +struct blit_table +{ + Uint32 srcR, srcG, srcB; + int dstbpp; + Uint32 dstR, dstG, dstB; + Uint32 blit_features; + void *aux_data; + SDL_loblit blitfunc; + enum + { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha; }; static const struct blit_table normal_blit_1[] = { - /* Default for 8-bit RGB source, an invalid combination */ - { 0,0,0, 0, 0,0,0, 0, NULL, NULL }, + /* Default for 8-bit RGB source, an invalid combination */ + {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL}, }; static const struct blit_table normal_blit_2[] = { #if SDL_HERMES_BLITTERS - { 0x0000F800,0x000007E0,0x0000001F, 2, 0x0000001F,0x000007E0,0x0000F800, - 0, ConvertX86p16_16BGR565, ConvertX86, NO_ALPHA }, - { 0x0000F800,0x000007E0,0x0000001F, 2, 0x00007C00,0x000003E0,0x0000001F, - 0, ConvertX86p16_16RGB555, ConvertX86, NO_ALPHA }, - { 0x0000F800,0x000007E0,0x0000001F, 2, 0x0000001F,0x000003E0,0x00007C00, - 0, ConvertX86p16_16BGR555, ConvertX86, NO_ALPHA }, + {0x0000F800, 0x000007E0, 0x0000001F, 2, 0x0000001F, 0x000007E0, + 0x0000F800, + 0, ConvertX86p16_16BGR565, ConvertX86, NO_ALPHA}, + {0x0000F800, 0x000007E0, 0x0000001F, 2, 0x00007C00, 0x000003E0, + 0x0000001F, + 0, ConvertX86p16_16RGB555, ConvertX86, NO_ALPHA}, + {0x0000F800, 0x000007E0, 0x0000001F, 2, 0x0000001F, 0x000003E0, + 0x00007C00, + 0, ConvertX86p16_16BGR555, ConvertX86, NO_ALPHA}, #elif SDL_ALTIVEC_BLITTERS /* has-altivec */ - { 0x0000F800,0x000007E0,0x0000001F, 4, 0x00000000,0x00000000,0x00000000, - 2, NULL, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA }, - { 0x00007C00,0x000003E0,0x0000001F, 4, 0x00000000,0x00000000,0x00000000, - 2, NULL, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA }, + {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000, + 0x00000000, + 2, NULL, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, + {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000, + 0x00000000, + 2, NULL, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, #endif - { 0x0000F800,0x000007E0,0x0000001F, 4, 0x00FF0000,0x0000FF00,0x000000FF, - 0, NULL, Blit_RGB565_ARGB8888, SET_ALPHA }, - { 0x0000F800,0x000007E0,0x0000001F, 4, 0x000000FF,0x0000FF00,0x00FF0000, - 0, NULL, Blit_RGB565_ABGR8888, SET_ALPHA }, - { 0x0000F800,0x000007E0,0x0000001F, 4, 0xFF000000,0x00FF0000,0x0000FF00, - 0, NULL, Blit_RGB565_RGBA8888, SET_ALPHA }, - { 0x0000F800,0x000007E0,0x0000001F, 4, 0x0000FF00,0x00FF0000,0xFF000000, - 0, NULL, Blit_RGB565_BGRA8888, SET_ALPHA }, + {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00, + 0x000000FF, + 0, NULL, Blit_RGB565_ARGB8888, SET_ALPHA}, + {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00, + 0x00FF0000, + 0, NULL, Blit_RGB565_ABGR8888, SET_ALPHA}, + {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000, + 0x0000FF00, + 0, NULL, Blit_RGB565_RGBA8888, SET_ALPHA}, + {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000, + 0xFF000000, + 0, NULL, Blit_RGB565_BGRA8888, SET_ALPHA}, /* Default for 16-bit RGB source, used if no other blitter matches */ - { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 } + {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0} }; static const struct blit_table normal_blit_3[] = { - /* Default for 24-bit RGB source, never optimized */ - { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 } + /* Default for 24-bit RGB source, never optimized */ + {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0} }; static const struct blit_table normal_blit_4[] = { #if SDL_HERMES_BLITTERS - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F, - 1, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F, - 0, ConvertX86p32_16RGB565, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000007E0,0x0000F800, - 1, ConvertMMXpII32_16BGR565, ConvertMMX, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000007E0,0x0000F800, - 0, ConvertX86p32_16BGR565, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x00007C00,0x000003E0,0x0000001F, - 1, ConvertMMXpII32_16RGB555, ConvertMMX, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x00007C00,0x000003E0,0x0000001F, - 0, ConvertX86p32_16RGB555, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000003E0,0x00007C00, - 1, ConvertMMXpII32_16BGR555, ConvertMMX, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000003E0,0x00007C00, - 0, ConvertX86p32_16BGR555, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 3, 0x00FF0000,0x0000FF00,0x000000FF, - 0, ConvertX86p32_24RGB888, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 3, 0x000000FF,0x0000FF00,0x00FF0000, - 0, ConvertX86p32_24BGR888, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 4, 0x000000FF,0x0000FF00,0x00FF0000, - 0, ConvertX86p32_32BGR888, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 4, 0xFF000000,0x00FF0000,0x0000FF00, - 0, ConvertX86p32_32RGBA888, ConvertX86, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 4, 0x0000FF00,0x00FF0000,0xFF000000, - 0, ConvertX86p32_32BGRA888, ConvertX86, NO_ALPHA }, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, + 0x0000001F, + 1, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, + 0x0000001F, + 0, ConvertX86p32_16RGB565, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000001F, 0x000007E0, + 0x0000F800, + 1, ConvertMMXpII32_16BGR565, ConvertMMX, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000001F, 0x000007E0, + 0x0000F800, + 0, ConvertX86p32_16BGR565, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, + 0x0000001F, + 1, ConvertMMXpII32_16RGB555, ConvertMMX, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, + 0x0000001F, + 0, ConvertX86p32_16RGB555, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000001F, 0x000003E0, + 0x00007C00, + 1, ConvertMMXpII32_16BGR555, ConvertMMX, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000001F, 0x000003E0, + 0x00007C00, + 0, ConvertX86p32_16BGR555, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x00FF0000, 0x0000FF00, + 0x000000FF, + 0, ConvertX86p32_24RGB888, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, + 0x00FF0000, + 0, ConvertX86p32_24BGR888, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, + 0x00FF0000, + 0, ConvertX86p32_32BGR888, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0xFF000000, 0x00FF0000, + 0x0000FF00, + 0, ConvertX86p32_32RGBA888, ConvertX86, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x0000FF00, 0x00FF0000, + 0xFF000000, + 0, ConvertX86p32_32BGRA888, ConvertX86, NO_ALPHA}, #else #if SDL_ALTIVEC_BLITTERS /* has-altivec | dont-use-prefetch */ - { 0x00000000,0x00000000,0x00000000, 4, 0x00000000,0x00000000,0x00000000, - 6, NULL, ConvertAltivec32to32_noprefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA }, + {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, + 0x00000000, + 6, NULL, ConvertAltivec32to32_noprefetch, + NO_ALPHA | COPY_ALPHA | SET_ALPHA}, /* has-altivec */ - { 0x00000000,0x00000000,0x00000000, 4, 0x00000000,0x00000000,0x00000000, - 2, NULL, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA }, + {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, + 0x00000000, + 2, NULL, ConvertAltivec32to32_prefetch, + NO_ALPHA | COPY_ALPHA | SET_ALPHA}, /* has-altivec */ - { 0x00000000,0x00000000,0x00000000, 2, 0x0000F800,0x000007E0,0x0000001F, - 2, NULL, Blit_RGB888_RGB565Altivec, NO_ALPHA }, + {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, + 0x0000001F, + 2, NULL, Blit_RGB888_RGB565Altivec, NO_ALPHA}, #endif - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F, - 0, NULL, Blit_RGB888_RGB565, NO_ALPHA }, - { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x00007C00,0x000003E0,0x0000001F, - 0, NULL, Blit_RGB888_RGB555, NO_ALPHA }, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, + 0x0000001F, + 0, NULL, Blit_RGB888_RGB565, NO_ALPHA}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, + 0x0000001F, + 0, NULL, Blit_RGB888_RGB555, NO_ALPHA}, #endif - /* Default for 32-bit RGB source, used if no other blitter matches */ - { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 } + /* Default for 32-bit RGB source, used if no other blitter matches */ + {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0} }; static const struct blit_table *normal_blit[] = { - normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4 + normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4 }; /* Mask matches table, or table entry is zero */ #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000)) -SDL_loblit SDL_CalculateBlitN(SDL_Surface *surface, int blit_index) +SDL_loblit +SDL_CalculateBlitN (SDL_Surface * surface, int blit_index) { - struct private_swaccel *sdata; - SDL_PixelFormat *srcfmt; - SDL_PixelFormat *dstfmt; - const struct blit_table *table; - int which; - SDL_loblit blitfun; - - /* Set up data for choosing the blit */ - sdata = surface->map->sw_data; - srcfmt = surface->format; - dstfmt = surface->map->dst->format; - - if ( blit_index & 2 ) { - /* alpha or alpha+colorkey */ - return SDL_CalculateAlphaBlit(surface, blit_index); - } - - /* We don't support destinations less than 8-bits */ - if ( dstfmt->BitsPerPixel < 8 ) { - return(NULL); - } - - if(blit_index == 1) { - /* colorkey blit: Here we don't have too many options, mostly - because RLE is the preferred fast way to deal with this. - If a particular case turns out to be useful we'll add it. */ - - if(srcfmt->BytesPerPixel == 2 - && surface->map->identity) - return Blit2to2Key; - else if(dstfmt->BytesPerPixel == 1) - return BlitNto1Key; - else { + struct private_swaccel *sdata; + SDL_PixelFormat *srcfmt; + SDL_PixelFormat *dstfmt; + const struct blit_table *table; + int which; + SDL_loblit blitfun; + + /* Set up data for choosing the blit */ + sdata = surface->map->sw_data; + srcfmt = surface->format; + dstfmt = surface->map->dst->format; + + if (blit_index & 2) { + /* alpha or alpha+colorkey */ + return SDL_CalculateAlphaBlit (surface, blit_index); + } + + /* We don't support destinations less than 8-bits */ + if (dstfmt->BitsPerPixel < 8) { + return (NULL); + } + + if (blit_index == 1) { + /* colorkey blit: Here we don't have too many options, mostly + because RLE is the preferred fast way to deal with this. + If a particular case turns out to be useful we'll add it. */ + + if (srcfmt->BytesPerPixel == 2 && surface->map->identity) + return Blit2to2Key; + else if (dstfmt->BytesPerPixel == 1) + return BlitNto1Key; + else { #if SDL_ALTIVEC_BLITTERS - if((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4) && SDL_HasAltiVec()) { - return Blit32to32KeyAltivec; - } else + if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4) + && SDL_HasAltiVec ()) { + return Blit32to32KeyAltivec; + } else #endif - if(srcfmt->Amask && dstfmt->Amask) - return BlitNtoNKeyCopyAlpha; - else - return BlitNtoNKey; - } - } - - blitfun = NULL; - if ( dstfmt->BitsPerPixel == 8 ) { - /* We assume 8-bit destinations are palettized */ - if ( (srcfmt->BytesPerPixel == 4) && - (srcfmt->Rmask == 0x00FF0000) && - (srcfmt->Gmask == 0x0000FF00) && - (srcfmt->Bmask == 0x000000FF) ) { - if ( surface->map->table ) { - blitfun = Blit_RGB888_index8_map; - } else { + if (srcfmt->Amask && dstfmt->Amask) + return BlitNtoNKeyCopyAlpha; + else + return BlitNtoNKey; + } + } + + blitfun = NULL; + if (dstfmt->BitsPerPixel == 8) { + /* We assume 8-bit destinations are palettized */ + if ((srcfmt->BytesPerPixel == 4) && + (srcfmt->Rmask == 0x00FF0000) && + (srcfmt->Gmask == 0x0000FF00) && (srcfmt->Bmask == 0x000000FF)) { + if (surface->map->table) { + blitfun = Blit_RGB888_index8_map; + } else { #if SDL_HERMES_BLITTERS - sdata->aux_data = ConvertX86p32_8RGB332; - blitfun = ConvertX86; + sdata->aux_data = ConvertX86p32_8RGB332; + blitfun = ConvertX86; #else - blitfun = Blit_RGB888_index8; + blitfun = Blit_RGB888_index8; #endif - } - } else { - blitfun = BlitNto1; - } - } else { - /* Now the meat, choose the blitter we want */ - int a_need = NO_ALPHA; - if(dstfmt->Amask) - a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA; - table = normal_blit[srcfmt->BytesPerPixel-1]; - for ( which=0; table[which].dstbpp; ++which ) { - if ( MASKOK(srcfmt->Rmask, table[which].srcR) && - MASKOK(srcfmt->Gmask, table[which].srcG) && - MASKOK(srcfmt->Bmask, table[which].srcB) && - MASKOK(dstfmt->Rmask, table[which].dstR) && - MASKOK(dstfmt->Gmask, table[which].dstG) && - MASKOK(dstfmt->Bmask, table[which].dstB) && - dstfmt->BytesPerPixel == table[which].dstbpp && - (a_need & table[which].alpha) == a_need && - ((table[which].blit_features & GetBlitFeatures()) == table[which].blit_features) ) - break; - } - sdata->aux_data = table[which].aux_data; - blitfun = table[which].blitfunc; - - if(blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ - /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ - if ( srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 && - srcfmt->Rmask == dstfmt->Rmask && - srcfmt->Gmask == dstfmt->Gmask && - srcfmt->Bmask == dstfmt->Bmask ) { - blitfun = Blit4to4MaskAlpha; - } else if ( a_need == COPY_ALPHA ) { - blitfun = BlitNtoNCopyAlpha; - } - } - } + } + } else { + blitfun = BlitNto1; + } + } else { + /* Now the meat, choose the blitter we want */ + int a_need = NO_ALPHA; + if (dstfmt->Amask) + a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA; + table = normal_blit[srcfmt->BytesPerPixel - 1]; + for (which = 0; table[which].dstbpp; ++which) { + if (MASKOK (srcfmt->Rmask, table[which].srcR) && + MASKOK (srcfmt->Gmask, table[which].srcG) && + MASKOK (srcfmt->Bmask, table[which].srcB) && + MASKOK (dstfmt->Rmask, table[which].dstR) && + MASKOK (dstfmt->Gmask, table[which].dstG) && + MASKOK (dstfmt->Bmask, table[which].dstB) && + dstfmt->BytesPerPixel == table[which].dstbpp && + (a_need & table[which].alpha) == a_need && + ((table[which].blit_features & GetBlitFeatures ()) == + table[which].blit_features)) + break; + } + sdata->aux_data = table[which].aux_data; + blitfun = table[which].blitfunc; + + if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ + /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ + if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 && + srcfmt->Rmask == dstfmt->Rmask && + srcfmt->Gmask == dstfmt->Gmask && + srcfmt->Bmask == dstfmt->Bmask) { + blitfun = Blit4to4MaskAlpha; + } else if (a_need == COPY_ALPHA) { + blitfun = BlitNtoNCopyAlpha; + } + } + } #ifdef DEBUG_ASM #if SDL_HERMES_BLITTERS - if ( blitfun == ConvertMMX ) - fprintf(stderr, "Using mmx blit\n"); - else - if ( blitfun == ConvertX86 ) - fprintf(stderr, "Using asm blit\n"); - else + if (blitfun == ConvertMMX) + fprintf (stderr, "Using mmx blit\n"); + else if (blitfun == ConvertX86) + fprintf (stderr, "Using asm blit\n"); + else #endif - if ( (blitfun == BlitNtoN) || (blitfun == BlitNto1) ) - fprintf(stderr, "Using C blit\n"); - else - fprintf(stderr, "Using optimized C blit\n"); + if ((blitfun == BlitNtoN) || (blitfun == BlitNto1)) + fprintf (stderr, "Using C blit\n"); + else + fprintf (stderr, "Using optimized C blit\n"); #endif /* DEBUG_ASM */ - return(blitfun); + return (blitfun); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index 874cb2799..d21e26b9f 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -45,476 +45,482 @@ #endif -SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc) +SDL_Surface * +SDL_LoadBMP_RW (SDL_RWops * src, int freesrc) { - int was_error; - long fp_offset; - int bmpPitch; - int i, pad; - SDL_Surface *surface; - Uint32 Rmask; - Uint32 Gmask; - Uint32 Bmask; - SDL_Palette *palette; - Uint8 *bits; - int ExpandBMP; - - /* The Win32 BMP file header (14 bytes) */ - char magic[2]; - Uint32 bfSize; - Uint16 bfReserved1; - Uint16 bfReserved2; - Uint32 bfOffBits; - - /* The Win32 BITMAPINFOHEADER struct (40 bytes) */ - Uint32 biSize; - Sint32 biWidth; - Sint32 biHeight; - Uint16 biPlanes; - Uint16 biBitCount; - Uint32 biCompression; - Uint32 biSizeImage; - Sint32 biXPelsPerMeter; - Sint32 biYPelsPerMeter; - Uint32 biClrUsed; - Uint32 biClrImportant; - - /* Make sure we are passed a valid data source */ - surface = NULL; - was_error = 0; - if ( src == NULL ) { - was_error = 1; - goto done; - } - - /* Read in the BMP file header */ - fp_offset = SDL_RWtell(src); - SDL_ClearError(); - if ( SDL_RWread(src, magic, 1, 2) != 2 ) { - SDL_Error(SDL_EFREAD); - was_error = 1; - goto done; - } - if ( SDL_strncmp(magic, "BM", 2) != 0 ) { - SDL_SetError("File is not a Windows BMP file"); - was_error = 1; - goto done; - } - bfSize = SDL_ReadLE32(src); - bfReserved1 = SDL_ReadLE16(src); - bfReserved2 = SDL_ReadLE16(src); - bfOffBits = SDL_ReadLE32(src); - - /* Read the Win32 BITMAPINFOHEADER */ - biSize = SDL_ReadLE32(src); - if ( biSize == 12 ) { - biWidth = (Uint32)SDL_ReadLE16(src); - biHeight = (Uint32)SDL_ReadLE16(src); - biPlanes = SDL_ReadLE16(src); - biBitCount = SDL_ReadLE16(src); - biCompression = BI_RGB; - biSizeImage = 0; - biXPelsPerMeter = 0; - biYPelsPerMeter = 0; - biClrUsed = 0; - biClrImportant = 0; - } else { - biWidth = SDL_ReadLE32(src); - biHeight = SDL_ReadLE32(src); - biPlanes = SDL_ReadLE16(src); - biBitCount = SDL_ReadLE16(src); - biCompression = SDL_ReadLE32(src); - biSizeImage = SDL_ReadLE32(src); - biXPelsPerMeter = SDL_ReadLE32(src); - biYPelsPerMeter = SDL_ReadLE32(src); - biClrUsed = SDL_ReadLE32(src); - biClrImportant = SDL_ReadLE32(src); - } - - /* Check for read error */ - if ( SDL_strcmp(SDL_GetError(), "") != 0 ) { - was_error = 1; - goto done; - } - - /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */ - switch (biBitCount) { - case 1: - case 4: - ExpandBMP = biBitCount; - biBitCount = 8; - break; - default: - ExpandBMP = 0; - break; - } - - /* We don't support any BMP compression right now */ - Rmask = Gmask = Bmask = 0; - switch (biCompression) { - case BI_RGB: - /* If there are no masks, use the defaults */ - if ( bfOffBits == (14+biSize) ) { - /* Default values for the BMP format */ - switch (biBitCount) { - case 15: - case 16: - Rmask = 0x7C00; - Gmask = 0x03E0; - Bmask = 0x001F; - break; - case 24: + int was_error; + long fp_offset; + int bmpPitch; + int i, pad; + SDL_Surface *surface; + Uint32 Rmask; + Uint32 Gmask; + Uint32 Bmask; + SDL_Palette *palette; + Uint8 *bits; + int ExpandBMP; + + /* The Win32 BMP file header (14 bytes) */ + char magic[2]; + Uint32 bfSize; + Uint16 bfReserved1; + Uint16 bfReserved2; + Uint32 bfOffBits; + + /* The Win32 BITMAPINFOHEADER struct (40 bytes) */ + Uint32 biSize; + Sint32 biWidth; + Sint32 biHeight; + Uint16 biPlanes; + Uint16 biBitCount; + Uint32 biCompression; + Uint32 biSizeImage; + Sint32 biXPelsPerMeter; + Sint32 biYPelsPerMeter; + Uint32 biClrUsed; + Uint32 biClrImportant; + + /* Make sure we are passed a valid data source */ + surface = NULL; + was_error = 0; + if (src == NULL) { + was_error = 1; + goto done; + } + + /* Read in the BMP file header */ + fp_offset = SDL_RWtell (src); + SDL_ClearError (); + if (SDL_RWread (src, magic, 1, 2) != 2) { + SDL_Error (SDL_EFREAD); + was_error = 1; + goto done; + } + if (SDL_strncmp (magic, "BM", 2) != 0) { + SDL_SetError ("File is not a Windows BMP file"); + was_error = 1; + goto done; + } + bfSize = SDL_ReadLE32 (src); + bfReserved1 = SDL_ReadLE16 (src); + bfReserved2 = SDL_ReadLE16 (src); + bfOffBits = SDL_ReadLE32 (src); + + /* Read the Win32 BITMAPINFOHEADER */ + biSize = SDL_ReadLE32 (src); + if (biSize == 12) { + biWidth = (Uint32) SDL_ReadLE16 (src); + biHeight = (Uint32) SDL_ReadLE16 (src); + biPlanes = SDL_ReadLE16 (src); + biBitCount = SDL_ReadLE16 (src); + biCompression = BI_RGB; + biSizeImage = 0; + biXPelsPerMeter = 0; + biYPelsPerMeter = 0; + biClrUsed = 0; + biClrImportant = 0; + } else { + biWidth = SDL_ReadLE32 (src); + biHeight = SDL_ReadLE32 (src); + biPlanes = SDL_ReadLE16 (src); + biBitCount = SDL_ReadLE16 (src); + biCompression = SDL_ReadLE32 (src); + biSizeImage = SDL_ReadLE32 (src); + biXPelsPerMeter = SDL_ReadLE32 (src); + biYPelsPerMeter = SDL_ReadLE32 (src); + biClrUsed = SDL_ReadLE32 (src); + biClrImportant = SDL_ReadLE32 (src); + } + + /* Check for read error */ + if (SDL_strcmp (SDL_GetError (), "") != 0) { + was_error = 1; + goto done; + } + + /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */ + switch (biBitCount) { + case 1: + case 4: + ExpandBMP = biBitCount; + biBitCount = 8; + break; + default: + ExpandBMP = 0; + break; + } + + /* We don't support any BMP compression right now */ + Rmask = Gmask = Bmask = 0; + switch (biCompression) { + case BI_RGB: + /* If there are no masks, use the defaults */ + if (bfOffBits == (14 + biSize)) { + /* Default values for the BMP format */ + switch (biBitCount) { + case 15: + case 16: + Rmask = 0x7C00; + Gmask = 0x03E0; + Bmask = 0x001F; + break; + case 24: #if SDL_BYTEORDER == SDL_BIG_ENDIAN - Rmask = 0x000000FF; - Gmask = 0x0000FF00; - Bmask = 0x00FF0000; - break; + Rmask = 0x000000FF; + Gmask = 0x0000FF00; + Bmask = 0x00FF0000; + break; #endif - case 32: - Rmask = 0x00FF0000; - Gmask = 0x0000FF00; - Bmask = 0x000000FF; - break; - default: - break; - } - break; - } - /* Fall through -- read the RGB masks */ - - case BI_BITFIELDS: - switch (biBitCount) { - case 15: - case 16: - case 32: - Rmask = SDL_ReadLE32(src); - Gmask = SDL_ReadLE32(src); - Bmask = SDL_ReadLE32(src); - break; - default: - break; - } - break; - default: - SDL_SetError("Compressed BMP files not supported"); - was_error = 1; - goto done; - } - - /* Create a compatible surface, note that the colors are RGB ordered */ - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, - biWidth, biHeight, biBitCount, Rmask, Gmask, Bmask, 0); - if ( surface == NULL ) { - was_error = 1; - goto done; - } - - /* Load the palette, if any */ - palette = (surface->format)->palette; - if ( palette ) { - if ( biClrUsed == 0 ) { - biClrUsed = 1 << biBitCount; - } - if ( biSize == 12 ) { - for ( i = 0; i < (int)biClrUsed; ++i ) { - SDL_RWread(src, &palette->colors[i].b, 1, 1); - SDL_RWread(src, &palette->colors[i].g, 1, 1); - SDL_RWread(src, &palette->colors[i].r, 1, 1); - palette->colors[i].unused = 0; - } - } else { - for ( i = 0; i < (int)biClrUsed; ++i ) { - SDL_RWread(src, &palette->colors[i].b, 1, 1); - SDL_RWread(src, &palette->colors[i].g, 1, 1); - SDL_RWread(src, &palette->colors[i].r, 1, 1); - SDL_RWread(src, &palette->colors[i].unused, 1, 1); - } - } - palette->ncolors = biClrUsed; - } - - /* Read the surface pixels. Note that the bmp image is upside down */ - if ( SDL_RWseek(src, fp_offset+bfOffBits, RW_SEEK_SET) < 0 ) { - SDL_Error(SDL_EFSEEK); - was_error = 1; - goto done; - } - bits = (Uint8 *)surface->pixels+(surface->h*surface->pitch); - switch (ExpandBMP) { - case 1: - bmpPitch = (biWidth + 7) >> 3; - pad = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0); - break; - case 4: - bmpPitch = (biWidth + 1) >> 1; - pad = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0); - break; - default: - pad = ((surface->pitch%4) ? - (4-(surface->pitch%4)) : 0); - break; - } - while ( bits > (Uint8 *)surface->pixels ) { - bits -= surface->pitch; - switch (ExpandBMP) { - case 1: - case 4: { - Uint8 pixel = 0; - int shift = (8-ExpandBMP); - for ( i=0; iw; ++i ) { - if ( i%(8/ExpandBMP) == 0 ) { - if ( !SDL_RWread(src, &pixel, 1, 1) ) { - SDL_SetError( - "Error reading from BMP"); - was_error = 1; - goto done; - } - } - *(bits+i) = (pixel>>shift); - pixel <<= ExpandBMP; - } } - break; - - default: - if ( SDL_RWread(src, bits, 1, surface->pitch) - != surface->pitch ) { - SDL_Error(SDL_EFREAD); - was_error = 1; - goto done; - } + case 32: + Rmask = 0x00FF0000; + Gmask = 0x0000FF00; + Bmask = 0x000000FF; + break; + default: + break; + } + break; + } + /* Fall through -- read the RGB masks */ + + case BI_BITFIELDS: + switch (biBitCount) { + case 15: + case 16: + case 32: + Rmask = SDL_ReadLE32 (src); + Gmask = SDL_ReadLE32 (src); + Bmask = SDL_ReadLE32 (src); + break; + default: + break; + } + break; + default: + SDL_SetError ("Compressed BMP files not supported"); + was_error = 1; + goto done; + } + + /* Create a compatible surface, note that the colors are RGB ordered */ + surface = SDL_CreateRGBSurface (SDL_SWSURFACE, + biWidth, biHeight, biBitCount, Rmask, + Gmask, Bmask, 0); + if (surface == NULL) { + was_error = 1; + goto done; + } + + /* Load the palette, if any */ + palette = (surface->format)->palette; + if (palette) { + if (biClrUsed == 0) { + biClrUsed = 1 << biBitCount; + } + if (biSize == 12) { + for (i = 0; i < (int) biClrUsed; ++i) { + SDL_RWread (src, &palette->colors[i].b, 1, 1); + SDL_RWread (src, &palette->colors[i].g, 1, 1); + SDL_RWread (src, &palette->colors[i].r, 1, 1); + palette->colors[i].unused = 0; + } + } else { + for (i = 0; i < (int) biClrUsed; ++i) { + SDL_RWread (src, &palette->colors[i].b, 1, 1); + SDL_RWread (src, &palette->colors[i].g, 1, 1); + SDL_RWread (src, &palette->colors[i].r, 1, 1); + SDL_RWread (src, &palette->colors[i].unused, 1, 1); + } + } + palette->ncolors = biClrUsed; + } + + /* Read the surface pixels. Note that the bmp image is upside down */ + if (SDL_RWseek (src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) { + SDL_Error (SDL_EFSEEK); + was_error = 1; + goto done; + } + bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch); + switch (ExpandBMP) { + case 1: + bmpPitch = (biWidth + 7) >> 3; + pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0); + break; + case 4: + bmpPitch = (biWidth + 1) >> 1; + pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0); + break; + default: + pad = ((surface->pitch % 4) ? (4 - (surface->pitch % 4)) : 0); + break; + } + while (bits > (Uint8 *) surface->pixels) { + bits -= surface->pitch; + switch (ExpandBMP) { + case 1: + case 4: + { + Uint8 pixel = 0; + int shift = (8 - ExpandBMP); + for (i = 0; i < surface->w; ++i) { + if (i % (8 / ExpandBMP) == 0) { + if (!SDL_RWread (src, &pixel, 1, 1)) { + SDL_SetError ("Error reading from BMP"); + was_error = 1; + goto done; + } + } + *(bits + i) = (pixel >> shift); + pixel <<= ExpandBMP; + } + } + break; + + default: + if (SDL_RWread (src, bits, 1, surface->pitch) + != surface->pitch) { + SDL_Error (SDL_EFREAD); + was_error = 1; + goto done; + } #if SDL_BYTEORDER == SDL_BIG_ENDIAN - /* Byte-swap the pixels if needed. Note that the 24bpp - case has already been taken care of above. */ - switch(biBitCount) { - case 15: - case 16: { - Uint16 *pix = (Uint16 *)bits; - for(i = 0; i < surface->w; i++) - pix[i] = SDL_Swap16(pix[i]); - break; - } - - case 32: { - Uint32 *pix = (Uint32 *)bits; - for(i = 0; i < surface->w; i++) - pix[i] = SDL_Swap32(pix[i]); - break; - } - } + /* Byte-swap the pixels if needed. Note that the 24bpp + case has already been taken care of above. */ + switch (biBitCount) { + case 15: + case 16: + { + Uint16 *pix = (Uint16 *) bits; + for (i = 0; i < surface->w; i++) + pix[i] = SDL_Swap16 (pix[i]); + break; + } + + case 32: + { + Uint32 *pix = (Uint32 *) bits; + for (i = 0; i < surface->w; i++) + pix[i] = SDL_Swap32 (pix[i]); + break; + } + } #endif - break; - } - /* Skip padding bytes, ugh */ - if ( pad ) { - Uint8 padbyte; - for ( i=0; iformat->palette ) { - if ( saveme->format->BitsPerPixel == 8 ) { - surface = saveme; - } else { - SDL_SetError("%d bpp BMP files not supported", - saveme->format->BitsPerPixel); - } - } - else if ( (saveme->format->BitsPerPixel == 24) && + long fp_offset; + int i, pad; + SDL_Surface *surface; + Uint8 *bits; + + /* The Win32 BMP file header (14 bytes) */ + char magic[2] = { 'B', 'M' }; + Uint32 bfSize; + Uint16 bfReserved1; + Uint16 bfReserved2; + Uint32 bfOffBits; + + /* The Win32 BITMAPINFOHEADER struct (40 bytes) */ + Uint32 biSize; + Sint32 biWidth; + Sint32 biHeight; + Uint16 biPlanes; + Uint16 biBitCount; + Uint32 biCompression; + Uint32 biSizeImage; + Sint32 biXPelsPerMeter; + Sint32 biYPelsPerMeter; + Uint32 biClrUsed; + Uint32 biClrImportant; + + /* Make sure we have somewhere to save */ + surface = NULL; + if (dst) { + if (saveme->format->palette) { + if (saveme->format->BitsPerPixel == 8) { + surface = saveme; + } else { + SDL_SetError ("%d bpp BMP files not supported", + saveme->format->BitsPerPixel); + } + } else if ((saveme->format->BitsPerPixel == 24) && #if SDL_BYTEORDER == SDL_LIL_ENDIAN - (saveme->format->Rmask == 0x00FF0000) && - (saveme->format->Gmask == 0x0000FF00) && - (saveme->format->Bmask == 0x000000FF) + (saveme->format->Rmask == 0x00FF0000) && + (saveme->format->Gmask == 0x0000FF00) && + (saveme->format->Bmask == 0x000000FF) #else - (saveme->format->Rmask == 0x000000FF) && - (saveme->format->Gmask == 0x0000FF00) && - (saveme->format->Bmask == 0x00FF0000) + (saveme->format->Rmask == 0x000000FF) && + (saveme->format->Gmask == 0x0000FF00) && + (saveme->format->Bmask == 0x00FF0000) #endif - ) { - surface = saveme; - } else { - SDL_Rect bounds; - - /* Convert to 24 bits per pixel */ - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, - saveme->w, saveme->h, 24, + ) { + surface = saveme; + } else { + SDL_Rect bounds; + + /* Convert to 24 bits per pixel */ + surface = SDL_CreateRGBSurface (SDL_SWSURFACE, + saveme->w, saveme->h, 24, #if SDL_BYTEORDER == SDL_LIL_ENDIAN - 0x00FF0000, 0x0000FF00, 0x000000FF, + 0x00FF0000, 0x0000FF00, + 0x000000FF, #else - 0x000000FF, 0x0000FF00, 0x00FF0000, + 0x000000FF, 0x0000FF00, + 0x00FF0000, #endif - 0); - if ( surface != NULL ) { - bounds.x = 0; - bounds.y = 0; - bounds.w = saveme->w; - bounds.h = saveme->h; - if ( SDL_LowerBlit(saveme, &bounds, surface, - &bounds) < 0 ) { - SDL_FreeSurface(surface); - SDL_SetError( - "Couldn't convert image to 24 bpp"); - surface = NULL; - } - } - } - } - - if ( surface && (SDL_LockSurface(surface) == 0) ) { - const int bw = surface->w*surface->format->BytesPerPixel; - - /* Set the BMP file header values */ - bfSize = 0; /* We'll write this when we're done */ - bfReserved1 = 0; - bfReserved2 = 0; - bfOffBits = 0; /* We'll write this when we're done */ - - /* Write the BMP file header values */ - fp_offset = SDL_RWtell(dst); - SDL_ClearError(); - SDL_RWwrite(dst, magic, 2, 1); - SDL_WriteLE32(dst, bfSize); - SDL_WriteLE16(dst, bfReserved1); - SDL_WriteLE16(dst, bfReserved2); - SDL_WriteLE32(dst, bfOffBits); - - /* Set the BMP info values */ - biSize = 40; - biWidth = surface->w; - biHeight = surface->h; - biPlanes = 1; - biBitCount = surface->format->BitsPerPixel; - biCompression = BI_RGB; - biSizeImage = surface->h*surface->pitch; - biXPelsPerMeter = 0; - biYPelsPerMeter = 0; - if ( surface->format->palette ) { - biClrUsed = surface->format->palette->ncolors; - } else { - biClrUsed = 0; - } - biClrImportant = 0; - - /* Write the BMP info values */ - SDL_WriteLE32(dst, biSize); - SDL_WriteLE32(dst, biWidth); - SDL_WriteLE32(dst, biHeight); - SDL_WriteLE16(dst, biPlanes); - SDL_WriteLE16(dst, biBitCount); - SDL_WriteLE32(dst, biCompression); - SDL_WriteLE32(dst, biSizeImage); - SDL_WriteLE32(dst, biXPelsPerMeter); - SDL_WriteLE32(dst, biYPelsPerMeter); - SDL_WriteLE32(dst, biClrUsed); - SDL_WriteLE32(dst, biClrImportant); - - /* Write the palette (in BGR color order) */ - if ( surface->format->palette ) { - SDL_Color *colors; - int ncolors; - - colors = surface->format->palette->colors; - ncolors = surface->format->palette->ncolors; - for ( i=0; ipixels+(surface->h*surface->pitch); - pad = ((bw%4) ? (4-(bw%4)) : 0); - while ( bits > (Uint8 *)surface->pixels ) { - bits -= surface->pitch; - if ( SDL_RWwrite(dst, bits, 1, bw) != bw) { - SDL_Error(SDL_EFWRITE); - break; - } - if ( pad ) { - const Uint8 padbyte = 0; - for ( i=0; iw; + bounds.h = saveme->h; + if (SDL_LowerBlit (saveme, &bounds, surface, &bounds) < 0) { + SDL_FreeSurface (surface); + SDL_SetError ("Couldn't convert image to 24 bpp"); + surface = NULL; + } + } + } + } + + if (surface && (SDL_LockSurface (surface) == 0)) { + const int bw = surface->w * surface->format->BytesPerPixel; + + /* Set the BMP file header values */ + bfSize = 0; /* We'll write this when we're done */ + bfReserved1 = 0; + bfReserved2 = 0; + bfOffBits = 0; /* We'll write this when we're done */ + + /* Write the BMP file header values */ + fp_offset = SDL_RWtell (dst); + SDL_ClearError (); + SDL_RWwrite (dst, magic, 2, 1); + SDL_WriteLE32 (dst, bfSize); + SDL_WriteLE16 (dst, bfReserved1); + SDL_WriteLE16 (dst, bfReserved2); + SDL_WriteLE32 (dst, bfOffBits); + + /* Set the BMP info values */ + biSize = 40; + biWidth = surface->w; + biHeight = surface->h; + biPlanes = 1; + biBitCount = surface->format->BitsPerPixel; + biCompression = BI_RGB; + biSizeImage = surface->h * surface->pitch; + biXPelsPerMeter = 0; + biYPelsPerMeter = 0; + if (surface->format->palette) { + biClrUsed = surface->format->palette->ncolors; + } else { + biClrUsed = 0; + } + biClrImportant = 0; + + /* Write the BMP info values */ + SDL_WriteLE32 (dst, biSize); + SDL_WriteLE32 (dst, biWidth); + SDL_WriteLE32 (dst, biHeight); + SDL_WriteLE16 (dst, biPlanes); + SDL_WriteLE16 (dst, biBitCount); + SDL_WriteLE32 (dst, biCompression); + SDL_WriteLE32 (dst, biSizeImage); + SDL_WriteLE32 (dst, biXPelsPerMeter); + SDL_WriteLE32 (dst, biYPelsPerMeter); + SDL_WriteLE32 (dst, biClrUsed); + SDL_WriteLE32 (dst, biClrImportant); + + /* Write the palette (in BGR color order) */ + if (surface->format->palette) { + SDL_Color *colors; + int ncolors; + + colors = surface->format->palette->colors; + ncolors = surface->format->palette->ncolors; + for (i = 0; i < ncolors; ++i) { + SDL_RWwrite (dst, &colors[i].b, 1, 1); + SDL_RWwrite (dst, &colors[i].g, 1, 1); + SDL_RWwrite (dst, &colors[i].r, 1, 1); + SDL_RWwrite (dst, &colors[i].unused, 1, 1); + } + } + + /* Write the bitmap offset */ + bfOffBits = SDL_RWtell (dst) - fp_offset; + if (SDL_RWseek (dst, fp_offset + 10, RW_SEEK_SET) < 0) { + SDL_Error (SDL_EFSEEK); + } + SDL_WriteLE32 (dst, bfOffBits); + if (SDL_RWseek (dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) { + SDL_Error (SDL_EFSEEK); + } + + /* Write the bitmap image upside down */ + bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch); + pad = ((bw % 4) ? (4 - (bw % 4)) : 0); + while (bits > (Uint8 *) surface->pixels) { + bits -= surface->pitch; + if (SDL_RWwrite (dst, bits, 1, bw) != bw) { + SDL_Error (SDL_EFWRITE); + break; + } + if (pad) { + const Uint8 padbyte = 0; + for (i = 0; i < pad; ++i) { + SDL_RWwrite (dst, &padbyte, 1, 1); + } + } + } + + /* Write the BMP file size */ + bfSize = SDL_RWtell (dst) - fp_offset; + if (SDL_RWseek (dst, fp_offset + 2, RW_SEEK_SET) < 0) { + SDL_Error (SDL_EFSEEK); + } + SDL_WriteLE32 (dst, bfSize); + if (SDL_RWseek (dst, fp_offset + bfSize, RW_SEEK_SET) < 0) { + SDL_Error (SDL_EFSEEK); + } + + /* Close it up.. */ + SDL_UnlockSurface (surface); + if (surface != saveme) { + SDL_FreeSurface (surface); + } + } + + if (freedst && dst) { + SDL_RWclose (dst); + } + return ((SDL_strcmp (SDL_GetError (), "") == 0) ? 0 : -1); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_cursor.c b/src/video/SDL_cursor.c index 723040e0b..4307d5b0a 100644 --- a/src/video/SDL_cursor.c +++ b/src/video/SDL_cursor.c @@ -41,514 +41,533 @@ static SDL_Cursor *SDL_defcursor = NULL; SDL_mutex *SDL_cursorlock = NULL; /* Public functions */ -void SDL_CursorQuit(void) +void +SDL_CursorQuit (void) { - if ( SDL_cursor != NULL ) { - SDL_Cursor *cursor; - - SDL_cursorstate &= ~CURSOR_VISIBLE; - if ( SDL_cursor != SDL_defcursor ) { - SDL_FreeCursor(SDL_cursor); - } - SDL_cursor = NULL; - if ( SDL_defcursor != NULL ) { - cursor = SDL_defcursor; - SDL_defcursor = NULL; - SDL_FreeCursor(cursor); - } - } - if ( SDL_cursorlock != NULL ) { - SDL_DestroyMutex(SDL_cursorlock); - SDL_cursorlock = NULL; - } + if (SDL_cursor != NULL) { + SDL_Cursor *cursor; + + SDL_cursorstate &= ~CURSOR_VISIBLE; + if (SDL_cursor != SDL_defcursor) { + SDL_FreeCursor (SDL_cursor); + } + SDL_cursor = NULL; + if (SDL_defcursor != NULL) { + cursor = SDL_defcursor; + SDL_defcursor = NULL; + SDL_FreeCursor (cursor); + } + } + if (SDL_cursorlock != NULL) { + SDL_DestroyMutex (SDL_cursorlock); + SDL_cursorlock = NULL; + } } -int SDL_CursorInit(Uint32 multithreaded) +int +SDL_CursorInit (Uint32 multithreaded) { - /* We don't have mouse focus, and the cursor isn't drawn yet */ + /* We don't have mouse focus, and the cursor isn't drawn yet */ #ifndef IPOD - SDL_cursorstate = CURSOR_VISIBLE; + SDL_cursorstate = CURSOR_VISIBLE; #endif - /* Create the default cursor */ - if ( SDL_defcursor == NULL ) { - SDL_defcursor = SDL_CreateCursor(default_cdata, default_cmask, - DEFAULT_CWIDTH, DEFAULT_CHEIGHT, - DEFAULT_CHOTX, DEFAULT_CHOTY); - SDL_SetCursor(SDL_defcursor); - } - - /* Create a lock if necessary */ - if ( multithreaded ) { - SDL_cursorlock = SDL_CreateMutex(); - } - - /* That's it! */ - return(0); + /* Create the default cursor */ + if (SDL_defcursor == NULL) { + SDL_defcursor = SDL_CreateCursor (default_cdata, default_cmask, + DEFAULT_CWIDTH, DEFAULT_CHEIGHT, + DEFAULT_CHOTX, DEFAULT_CHOTY); + SDL_SetCursor (SDL_defcursor); + } + + /* Create a lock if necessary */ + if (multithreaded) { + SDL_cursorlock = SDL_CreateMutex (); + } + + /* That's it! */ + return (0); } /* Multi-thread support for cursors */ #ifndef SDL_LockCursor -void SDL_LockCursor(void) +void +SDL_LockCursor (void) { - if ( SDL_cursorlock ) { - SDL_mutexP(SDL_cursorlock); - } + if (SDL_cursorlock) { + SDL_mutexP (SDL_cursorlock); + } } #endif #ifndef SDL_UnlockCursor -void SDL_UnlockCursor(void) +void +SDL_UnlockCursor (void) { - if ( SDL_cursorlock ) { - SDL_mutexV(SDL_cursorlock); - } + if (SDL_cursorlock) { + SDL_mutexV (SDL_cursorlock); + } } #endif /* Software cursor drawing support */ -SDL_Cursor * SDL_CreateCursor (Uint8 *data, Uint8 *mask, - int w, int h, int hot_x, int hot_y) +SDL_Cursor * +SDL_CreateCursor (Uint8 * data, Uint8 * mask, + int w, int h, int hot_x, int hot_y) { - SDL_VideoDevice *video = current_video; - int savelen; - int i; - SDL_Cursor *cursor; - - /* Make sure the width is a multiple of 8 */ - w = ((w+7)&~7); - - /* Sanity check the hot spot */ - if ( (hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h) ) { - SDL_SetError("Cursor hot spot doesn't lie within cursor"); - return(NULL); - } - - /* Allocate memory for the cursor */ - cursor = (SDL_Cursor *)SDL_malloc(sizeof *cursor); - if ( cursor == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - savelen = (w*4)*h; - cursor->area.x = 0; - cursor->area.y = 0; - cursor->area.w = w; - cursor->area.h = h; - cursor->hot_x = hot_x; - cursor->hot_y = hot_y; - cursor->data = (Uint8 *)SDL_malloc((w/8)*h*2); - cursor->mask = cursor->data+((w/8)*h); - cursor->save[0] = (Uint8 *)SDL_malloc(savelen*2); - cursor->save[1] = cursor->save[0] + savelen; - cursor->wm_cursor = NULL; - if ( ! cursor->data || ! cursor->save[0] ) { - SDL_FreeCursor(cursor); - SDL_OutOfMemory(); - return(NULL); - } - for ( i=((w/8)*h)-1; i>=0; --i ) { - cursor->data[i] = data[i]; - cursor->mask[i] = mask[i] | data[i]; - } - SDL_memset(cursor->save[0], 0, savelen*2); - - /* If the window manager gives us a good cursor, we're done! */ - if ( video->CreateWMCursor ) { - cursor->wm_cursor = video->CreateWMCursor(video, data, mask, - w, h, hot_x, hot_y); - } else { - cursor->wm_cursor = NULL; - } - return(cursor); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + int savelen; + int i; + SDL_Cursor *cursor; + + /* Make sure the width is a multiple of 8 */ + w = ((w + 7) & ~7); + + /* Sanity check the hot spot */ + if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) { + SDL_SetError ("Cursor hot spot doesn't lie within cursor"); + return (NULL); + } + + /* Allocate memory for the cursor */ + cursor = (SDL_Cursor *) SDL_malloc (sizeof *cursor); + if (cursor == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + savelen = (w * 4) * h; + cursor->area.x = 0; + cursor->area.y = 0; + cursor->area.w = w; + cursor->area.h = h; + cursor->hot_x = hot_x; + cursor->hot_y = hot_y; + cursor->data = (Uint8 *) SDL_malloc ((w / 8) * h * 2); + cursor->mask = cursor->data + ((w / 8) * h); + cursor->save[0] = (Uint8 *) SDL_malloc (savelen * 2); + cursor->save[1] = cursor->save[0] + savelen; + cursor->wm_cursor = NULL; + if (!cursor->data || !cursor->save[0]) { + SDL_FreeCursor (cursor); + SDL_OutOfMemory (); + return (NULL); + } + for (i = ((w / 8) * h) - 1; i >= 0; --i) { + cursor->data[i] = data[i]; + cursor->mask[i] = mask[i] | data[i]; + } + SDL_memset (cursor->save[0], 0, savelen * 2); + + /* If the window manager gives us a good cursor, we're done! */ + if (_this->CreateWMCursor) { + cursor->wm_cursor = _this->CreateWMCursor (_this, data, mask, + w, h, hot_x, hot_y); + } else { + cursor->wm_cursor = NULL; + } + return (cursor); } /* SDL_SetCursor(NULL) can be used to force the cursor redraw, if this is desired for any reason. This is used when setting the video mode and when the SDL window gains the mouse focus. */ -void SDL_SetCursor (SDL_Cursor *cursor) +void +SDL_SetCursor (SDL_Cursor * cursor) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - /* Make sure that the video subsystem has been initialized */ - if ( ! video ) { - return; - } - - /* Prevent the event thread from moving the mouse */ - SDL_LockCursor(); - - /* Set the new cursor */ - if ( cursor && (cursor != SDL_cursor) ) { - /* Erase the current mouse position */ - if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { - SDL_EraseCursor(SDL_VideoSurface); - } else if ( video->MoveWMCursor ) { - /* If the video driver is moving the cursor directly, - it needs to hide the old cursor before (possibly) - showing the new one. (But don't erase NULL cursor) - */ - if ( SDL_cursor ) { - video->ShowWMCursor(this, NULL); - } - } - SDL_cursor = cursor; - } - - /* Draw the new mouse cursor */ - if ( SDL_cursor && (SDL_cursorstate&CURSOR_VISIBLE) ) { - /* Use window manager cursor if possible */ - if ( SDL_cursor->wm_cursor && - video->ShowWMCursor(this, SDL_cursor->wm_cursor) ) { - SDL_cursorstate &= ~CURSOR_USINGSW; - } else { - SDL_cursorstate |= CURSOR_USINGSW; - if ( video->ShowWMCursor ) { - video->ShowWMCursor(this, NULL); - } - { int x, y; - SDL_GetMouseState(&x, &y); - SDL_cursor->area.x = (x - SDL_cursor->hot_x); - SDL_cursor->area.y = (y - SDL_cursor->hot_y); - } - SDL_DrawCursor(SDL_VideoSurface); - } - } else { - /* Erase window manager mouse (cursor not visible) */ - if ( SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW) ) { - SDL_EraseCursor(SDL_VideoSurface); - } else { - if ( video ) { - video->ShowWMCursor(this, NULL); - } - } - } - SDL_UnlockCursor(); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + /* Make sure that the video subsystem has been initialized */ + if (!_this) { + return; + } + + /* Prevent the event thread from moving the mouse */ + SDL_LockCursor (); + + /* Set the new cursor */ + if (cursor && (cursor != SDL_cursor)) { + /* Erase the current mouse position */ + if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { + SDL_EraseCursor (SDL_VideoSurface); + } else if (_this->MoveWMCursor) { + /* If the video driver is moving the cursor directly, + it needs to hide the old cursor before (possibly) + showing the new one. (But don't erase NULL cursor) + */ + if (SDL_cursor) { + _this->ShowWMCursor (_this, NULL); + } + } + SDL_cursor = cursor; + } + + /* Draw the new mouse cursor */ + if (SDL_cursor && (SDL_cursorstate & CURSOR_VISIBLE)) { + /* Use window manager cursor if possible */ + if (SDL_cursor->wm_cursor && + _this->ShowWMCursor (_this, SDL_cursor->wm_cursor)) { + SDL_cursorstate &= ~CURSOR_USINGSW; + } else { + SDL_cursorstate |= CURSOR_USINGSW; + if (_this->ShowWMCursor) { + _this->ShowWMCursor (_this, NULL); + } + { + int x, y; + SDL_GetMouseState (&x, &y); + SDL_cursor->area.x = (x - SDL_cursor->hot_x); + SDL_cursor->area.y = (y - SDL_cursor->hot_y); + } + SDL_DrawCursor (SDL_VideoSurface); + } + } else { + /* Erase window manager mouse (cursor not visible) */ + if (SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW)) { + SDL_EraseCursor (SDL_VideoSurface); + } else { + if (_this) { + _this->ShowWMCursor (_this, NULL); + } + } + } + SDL_UnlockCursor (); } -SDL_Cursor * SDL_GetCursor (void) +SDL_Cursor * +SDL_GetCursor (void) { - return(SDL_cursor); + return (SDL_cursor); } -void SDL_FreeCursor (SDL_Cursor *cursor) +void +SDL_FreeCursor (SDL_Cursor * cursor) { - if ( cursor ) { - if ( cursor == SDL_cursor ) { - SDL_SetCursor(SDL_defcursor); - } - if ( cursor != SDL_defcursor ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - if ( cursor->data ) { - SDL_free(cursor->data); - } - if ( cursor->save[0] ) { - SDL_free(cursor->save[0]); - } - if ( video && cursor->wm_cursor ) { - video->FreeWMCursor(this, cursor->wm_cursor); - } - SDL_free(cursor); - } - } + if (cursor) { + if (cursor == SDL_cursor) { + SDL_SetCursor (SDL_defcursor); + } + if (cursor != SDL_defcursor) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + if (cursor->data) { + SDL_free (cursor->data); + } + if (cursor->save[0]) { + SDL_free (cursor->save[0]); + } + if (_this && cursor->wm_cursor) { + _this->FreeWMCursor (_this, cursor->wm_cursor); + } + SDL_free (cursor); + } + } } -int SDL_ShowCursor (int toggle) +int +SDL_ShowCursor (int toggle) { - int showing; - - showing = (SDL_cursorstate & CURSOR_VISIBLE); - if ( toggle >= 0 ) { - SDL_LockCursor(); - if ( toggle ) { - SDL_cursorstate |= CURSOR_VISIBLE; - } else { - SDL_cursorstate &= ~CURSOR_VISIBLE; - } - SDL_UnlockCursor(); - if ( (SDL_cursorstate & CURSOR_VISIBLE) != showing ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - SDL_SetCursor(NULL); - if ( video && video->CheckMouseMode ) { - video->CheckMouseMode(this); - } - } - } else { - /* Query current state */ ; - } - return(showing ? 1 : 0); + int showing; + + showing = (SDL_cursorstate & CURSOR_VISIBLE); + if (toggle >= 0) { + SDL_LockCursor (); + if (toggle) { + SDL_cursorstate |= CURSOR_VISIBLE; + } else { + SDL_cursorstate &= ~CURSOR_VISIBLE; + } + SDL_UnlockCursor (); + if ((SDL_cursorstate & CURSOR_VISIBLE) != showing) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + SDL_SetCursor (NULL); + if (_this && _this->CheckMouseMode) { + _this->CheckMouseMode (_this); + } + } + } else { + /* Query current state */ ; + } + return (showing ? 1 : 0); } -void SDL_WarpMouse (Uint16 x, Uint16 y) +void +SDL_WarpMouse (Uint16 x, Uint16 y) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - if ( !video || !SDL_PublicSurface ) { - SDL_SetError("A video mode must be set before warping mouse"); - return; - } - - /* If we have an offset video mode, offset the mouse coordinates */ - if (this->screen->pitch == 0) { - x += this->screen->offset / this->screen->format->BytesPerPixel; - y += this->screen->offset; - } else { - x += (this->screen->offset % this->screen->pitch) / - this->screen->format->BytesPerPixel; - y += (this->screen->offset / this->screen->pitch); - } - - /* This generates a mouse motion event */ - if ( video->WarpWMCursor ) { - video->WarpWMCursor(this, x, y); - } else { - SDL_PrivateMouseMotion(0, 0, x, y); - } + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + if (!_this || !SDL_PublicSurface) { + SDL_SetError ("A video mode must be set before warping mouse"); + return; + } + + /* If we have an offset video mode, offset the mouse coordinates */ + if (SDL_VideoSurface->pitch == 0) { + x += SDL_VideoSurface->offset / + SDL_VideoSurface->format->BytesPerPixel; + y += SDL_VideoSurface->offset; + } else { + x += (SDL_VideoSurface->offset % SDL_VideoSurface->pitch) / + SDL_VideoSurface->format->BytesPerPixel; + y += (SDL_VideoSurface->offset / SDL_VideoSurface->pitch); + } + + /* This generates a mouse motion event */ + if (_this->WarpWMCursor) { + _this->WarpWMCursor (_this, x, y); + } else { + SDL_PrivateMouseMotion (0, 0, x, y); + } } -void SDL_MoveCursor(int x, int y) +void +SDL_MoveCursor (int x, int y) { - SDL_VideoDevice *video = current_video; - - /* Erase and update the current mouse position */ - if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { - /* Erase and redraw mouse cursor in new position */ - SDL_LockCursor(); - SDL_EraseCursor(SDL_VideoSurface); - SDL_cursor->area.x = (x - SDL_cursor->hot_x); - SDL_cursor->area.y = (y - SDL_cursor->hot_y); - SDL_DrawCursor(SDL_VideoSurface); - SDL_UnlockCursor(); - } else if ( video->MoveWMCursor ) { - video->MoveWMCursor(video, x, y); - } + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + /* Erase and update the current mouse position */ + if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { + /* Erase and redraw mouse cursor in new position */ + SDL_LockCursor (); + SDL_EraseCursor (SDL_VideoSurface); + SDL_cursor->area.x = (x - SDL_cursor->hot_x); + SDL_cursor->area.y = (y - SDL_cursor->hot_y); + SDL_DrawCursor (SDL_VideoSurface); + SDL_UnlockCursor (); + } else if (_this->MoveWMCursor) { + _this->MoveWMCursor (_this, x, y); + } } /* Keep track of the current cursor colors */ static int palette_changed = 1; static Uint8 pixels8[2]; -void SDL_CursorPaletteChanged(void) +void +SDL_CursorPaletteChanged (void) { - palette_changed = 1; + palette_changed = 1; } -void SDL_MouseRect(SDL_Rect *area) +void +SDL_MouseRect (SDL_Rect * area) { - int clip_diff; - - *area = SDL_cursor->area; - if ( area->x < 0 ) { - area->w += area->x; - area->x = 0; - } - if ( area->y < 0 ) { - area->h += area->y; - area->y = 0; - } - clip_diff = (area->x+area->w)-SDL_VideoSurface->w; - if ( clip_diff > 0 ) { - area->w = area->w < clip_diff ? 0 : area->w-clip_diff; - } - clip_diff = (area->y+area->h)-SDL_VideoSurface->h; - if ( clip_diff > 0 ) { - area->h = area->h < clip_diff ? 0 : area->h-clip_diff; - } + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + int clip_diff; + + *area = SDL_cursor->area; + if (area->x < 0) { + area->w += area->x; + area->x = 0; + } + if (area->y < 0) { + area->h += area->y; + area->y = 0; + } + clip_diff = (area->x + area->w) - SDL_VideoSurface->w; + if (clip_diff > 0) { + area->w = area->w < clip_diff ? 0 : area->w - clip_diff; + } + clip_diff = (area->y + area->h) - SDL_VideoSurface->h; + if (clip_diff > 0) { + area->h = area->h < clip_diff ? 0 : area->h - clip_diff; + } } -static void SDL_DrawCursorFast(SDL_Surface *screen, SDL_Rect *area) +static void +SDL_DrawCursorFast (SDL_Surface * screen, SDL_Rect * area) { - const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 }; - int i, w, h; - Uint8 *data, datab; - Uint8 *mask, maskb; - - data = SDL_cursor->data + area->y * SDL_cursor->area.w/8; - mask = SDL_cursor->mask + area->y * SDL_cursor->area.w/8; - switch (screen->format->BytesPerPixel) { - - case 1: { - Uint8 *dst; - int dstskip; - - if ( palette_changed ) { - pixels8[0] = (Uint8)SDL_MapRGB(screen->format, 255, 255, 255); - pixels8[1] = (Uint8)SDL_MapRGB(screen->format, 0, 0, 0); - palette_changed = 0; - } - dst = (Uint8 *)screen->pixels + - (SDL_cursor->area.y+area->y)*screen->pitch + - SDL_cursor->area.x; - dstskip = screen->pitch-area->w; - - for ( h=area->h; h; h-- ) { - for ( w=area->w/8; w; w-- ) { - maskb = *mask++; - datab = *data++; - for ( i=0; i<8; ++i ) { - if ( maskb & 0x80 ) { - *dst = pixels8[datab>>7]; - } - maskb <<= 1; - datab <<= 1; - dst++; - } - } - dst += dstskip; - } - } - break; - - case 2: { - Uint16 *dst; - int dstskip; - - dst = (Uint16 *)screen->pixels + - (SDL_cursor->area.y+area->y)*screen->pitch/2 + - SDL_cursor->area.x; - dstskip = (screen->pitch/2)-area->w; - - for ( h=area->h; h; h-- ) { - for ( w=area->w/8; w; w-- ) { - maskb = *mask++; - datab = *data++; - for ( i=0; i<8; ++i ) { - if ( maskb & 0x80 ) { - *dst = (Uint16)pixels[datab>>7]; - } - maskb <<= 1; - datab <<= 1; - dst++; - } - } - dst += dstskip; - } - } - break; - - case 3: { - Uint8 *dst; - int dstskip; - - dst = (Uint8 *)screen->pixels + - (SDL_cursor->area.y+area->y)*screen->pitch + - SDL_cursor->area.x*3; - dstskip = screen->pitch-area->w*3; - - for ( h=area->h; h; h-- ) { - for ( w=area->w/8; w; w-- ) { - maskb = *mask++; - datab = *data++; - for ( i=0; i<8; ++i ) { - if ( maskb & 0x80 ) { - SDL_memset(dst,pixels[datab>>7],3); - } - maskb <<= 1; - datab <<= 1; - dst += 3; - } - } - dst += dstskip; - } - } - break; - - case 4: { - Uint32 *dst; - int dstskip; - - dst = (Uint32 *)screen->pixels + - (SDL_cursor->area.y+area->y)*screen->pitch/4 + - SDL_cursor->area.x; - dstskip = (screen->pitch/4)-area->w; - - for ( h=area->h; h; h-- ) { - for ( w=area->w/8; w; w-- ) { - maskb = *mask++; - datab = *data++; - for ( i=0; i<8; ++i ) { - if ( maskb & 0x80 ) { - *dst = pixels[datab>>7]; - } - maskb <<= 1; - datab <<= 1; - dst++; - } - } - dst += dstskip; - } - } - break; - } + const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 }; + int i, w, h; + Uint8 *data, datab; + Uint8 *mask, maskb; + + data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8; + mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8; + switch (screen->format->BytesPerPixel) { + + case 1: + { + Uint8 *dst; + int dstskip; + + if (palette_changed) { + pixels8[0] = + (Uint8) SDL_MapRGB (screen->format, 255, 255, 255); + pixels8[1] = (Uint8) SDL_MapRGB (screen->format, 0, 0, 0); + palette_changed = 0; + } + dst = (Uint8 *) screen->pixels + + (SDL_cursor->area.y + area->y) * screen->pitch + + SDL_cursor->area.x; + dstskip = screen->pitch - area->w; + + for (h = area->h; h; h--) { + for (w = area->w / 8; w; w--) { + maskb = *mask++; + datab = *data++; + for (i = 0; i < 8; ++i) { + if (maskb & 0x80) { + *dst = pixels8[datab >> 7]; + } + maskb <<= 1; + datab <<= 1; + dst++; + } + } + dst += dstskip; + } + } + break; + + case 2: + { + Uint16 *dst; + int dstskip; + + dst = (Uint16 *) screen->pixels + + (SDL_cursor->area.y + area->y) * screen->pitch / 2 + + SDL_cursor->area.x; + dstskip = (screen->pitch / 2) - area->w; + + for (h = area->h; h; h--) { + for (w = area->w / 8; w; w--) { + maskb = *mask++; + datab = *data++; + for (i = 0; i < 8; ++i) { + if (maskb & 0x80) { + *dst = (Uint16) pixels[datab >> 7]; + } + maskb <<= 1; + datab <<= 1; + dst++; + } + } + dst += dstskip; + } + } + break; + + case 3: + { + Uint8 *dst; + int dstskip; + + dst = (Uint8 *) screen->pixels + + (SDL_cursor->area.y + area->y) * screen->pitch + + SDL_cursor->area.x * 3; + dstskip = screen->pitch - area->w * 3; + + for (h = area->h; h; h--) { + for (w = area->w / 8; w; w--) { + maskb = *mask++; + datab = *data++; + for (i = 0; i < 8; ++i) { + if (maskb & 0x80) { + SDL_memset (dst, pixels[datab >> 7], 3); + } + maskb <<= 1; + datab <<= 1; + dst += 3; + } + } + dst += dstskip; + } + } + break; + + case 4: + { + Uint32 *dst; + int dstskip; + + dst = (Uint32 *) screen->pixels + + (SDL_cursor->area.y + area->y) * screen->pitch / 4 + + SDL_cursor->area.x; + dstskip = (screen->pitch / 4) - area->w; + + for (h = area->h; h; h--) { + for (w = area->w / 8; w; w--) { + maskb = *mask++; + datab = *data++; + for (i = 0; i < 8; ++i) { + if (maskb & 0x80) { + *dst = pixels[datab >> 7]; + } + maskb <<= 1; + datab <<= 1; + dst++; + } + } + dst += dstskip; + } + } + break; + } } -static void SDL_DrawCursorSlow(SDL_Surface *screen, SDL_Rect *area) +static void +SDL_DrawCursorSlow (SDL_Surface * screen, SDL_Rect * area) { - const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 }; - int h; - int x, minx, maxx; - Uint8 *data, datab = 0; - Uint8 *mask, maskb = 0; - Uint8 *dst; - int dstbpp, dstskip; - - data = SDL_cursor->data + area->y * SDL_cursor->area.w/8; - mask = SDL_cursor->mask + area->y * SDL_cursor->area.w/8; - dstbpp = screen->format->BytesPerPixel; - dst = (Uint8 *)screen->pixels + - (SDL_cursor->area.y+area->y)*screen->pitch + - SDL_cursor->area.x*dstbpp; - dstskip = screen->pitch-SDL_cursor->area.w*dstbpp; - - minx = area->x; - maxx = area->x+area->w; - if ( screen->format->BytesPerPixel == 1 ) { - if ( palette_changed ) { - pixels8[0] = (Uint8)SDL_MapRGB(screen->format, 255, 255, 255); - pixels8[1] = (Uint8)SDL_MapRGB(screen->format, 0, 0, 0); - palette_changed = 0; - } - for ( h=area->h; h; h-- ) { - for ( x=0; xarea.w; ++x ) { - if ( (x%8) == 0 ) { - maskb = *mask++; - datab = *data++; - } - if ( (x >= minx) && (x < maxx) ) { - if ( maskb & 0x80 ) { - SDL_memset(dst, pixels8[datab>>7], dstbpp); - } - } - maskb <<= 1; - datab <<= 1; - dst += dstbpp; - } - dst += dstskip; - } - } else { - for ( h=area->h; h; h-- ) { - for ( x=0; xarea.w; ++x ) { - if ( (x%8) == 0 ) { - maskb = *mask++; - datab = *data++; - } - if ( (x >= minx) && (x < maxx) ) { - if ( maskb & 0x80 ) { - SDL_memset(dst, pixels[datab>>7], dstbpp); - } - } - maskb <<= 1; - datab <<= 1; - dst += dstbpp; - } - dst += dstskip; - } - } + const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 }; + int h; + int x, minx, maxx; + Uint8 *data, datab = 0; + Uint8 *mask, maskb = 0; + Uint8 *dst; + int dstbpp, dstskip; + + data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8; + mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8; + dstbpp = screen->format->BytesPerPixel; + dst = (Uint8 *) screen->pixels + + (SDL_cursor->area.y + area->y) * screen->pitch + + SDL_cursor->area.x * dstbpp; + dstskip = screen->pitch - SDL_cursor->area.w * dstbpp; + + minx = area->x; + maxx = area->x + area->w; + if (screen->format->BytesPerPixel == 1) { + if (palette_changed) { + pixels8[0] = (Uint8) SDL_MapRGB (screen->format, 255, 255, 255); + pixels8[1] = (Uint8) SDL_MapRGB (screen->format, 0, 0, 0); + palette_changed = 0; + } + for (h = area->h; h; h--) { + for (x = 0; x < SDL_cursor->area.w; ++x) { + if ((x % 8) == 0) { + maskb = *mask++; + datab = *data++; + } + if ((x >= minx) && (x < maxx)) { + if (maskb & 0x80) { + SDL_memset (dst, pixels8[datab >> 7], dstbpp); + } + } + maskb <<= 1; + datab <<= 1; + dst += dstbpp; + } + dst += dstskip; + } + } else { + for (h = area->h; h; h--) { + for (x = 0; x < SDL_cursor->area.w; ++x) { + if ((x % 8) == 0) { + maskb = *mask++; + datab = *data++; + } + if ((x >= minx) && (x < maxx)) { + if (maskb & 0x80) { + SDL_memset (dst, pixels[datab >> 7], dstbpp); + } + } + maskb <<= 1; + datab <<= 1; + dst += dstbpp; + } + dst += dstskip; + } + } } /* This handles the ugly work of converting the saved cursor background from @@ -556,196 +575,226 @@ static void SDL_DrawCursorSlow(SDL_Surface *screen, SDL_Rect *area) This is only necessary when blitting from a shadow surface of a different pixel format than the video surface, and using a software rendered cursor. */ -static void SDL_ConvertCursorSave(SDL_Surface *screen, int w, int h) +static void +SDL_ConvertCursorSave (SDL_Surface * screen, int w, int h) { - SDL_BlitInfo info; - SDL_loblit RunBlit; - - /* Make sure we can steal the blit mapping */ - if ( screen->map->dst != SDL_VideoSurface ) { - return; - } - - /* Set up the blit information */ - info.s_pixels = SDL_cursor->save[1]; - info.s_width = w; - info.s_height = h; - info.s_skip = 0; - info.d_pixels = SDL_cursor->save[0]; - info.d_width = w; - info.d_height = h; - info.d_skip = 0; - info.aux_data = screen->map->sw_data->aux_data; - info.src = screen->format; - info.table = screen->map->table; - info.dst = SDL_VideoSurface->format; - RunBlit = screen->map->sw_data->blit; - - /* Run the actual software blit */ - RunBlit(&info); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_BlitInfo info; + SDL_loblit RunBlit; + + /* Make sure we can steal the blit mapping */ + if (screen->map->dst != SDL_VideoSurface) { + return; + } + + /* Set up the blit information */ + info.s_pixels = SDL_cursor->save[1]; + info.s_width = w; + info.s_height = h; + info.s_skip = 0; + info.d_pixels = SDL_cursor->save[0]; + info.d_width = w; + info.d_height = h; + info.d_skip = 0; + info.aux_data = screen->map->sw_data->aux_data; + info.src = screen->format; + info.table = screen->map->table; + info.dst = SDL_VideoSurface->format; + RunBlit = screen->map->sw_data->blit; + + /* Run the actual software blit */ + RunBlit (&info); } -void SDL_DrawCursorNoLock(SDL_Surface *screen) +void +SDL_DrawCursorNoLock (SDL_Surface * screen) { - SDL_Rect area; - - /* Get the mouse rectangle, clipped to the screen */ - SDL_MouseRect(&area); - if ( (area.w == 0) || (area.h == 0) ) { - return; - } - - /* Copy mouse background */ - { int w, h, screenbpp; - Uint8 *src, *dst; - - /* Set up the copy pointers */ - screenbpp = screen->format->BytesPerPixel; - if ( (screen == SDL_VideoSurface) || - FORMAT_EQUAL(screen->format, SDL_VideoSurface->format) ) { - dst = SDL_cursor->save[0]; - } else { - dst = SDL_cursor->save[1]; - } - src = (Uint8 *)screen->pixels + area.y * screen->pitch + - area.x * screenbpp; - - /* Perform the copy */ - w = area.w*screenbpp; - h = area.h; - while ( h-- ) { - SDL_memcpy(dst, src, w); - dst += w; - src += screen->pitch; - } - } - - /* Draw the mouse cursor */ - area.x -= SDL_cursor->area.x; - area.y -= SDL_cursor->area.y; - if ( (area.x == 0) && (area.w == SDL_cursor->area.w) ) { - SDL_DrawCursorFast(screen, &area); - } else { - SDL_DrawCursorSlow(screen, &area); - } + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Rect area; + + /* Get the mouse rectangle, clipped to the screen */ + SDL_MouseRect (&area); + if ((area.w == 0) || (area.h == 0)) { + return; + } + + /* Copy mouse background */ + { + int w, h, screenbpp; + Uint8 *src, *dst; + + /* Set up the copy pointers */ + screenbpp = screen->format->BytesPerPixel; + if ((screen == SDL_VideoSurface) || + FORMAT_EQUAL (screen->format, SDL_VideoSurface->format)) { + dst = SDL_cursor->save[0]; + } else { + dst = SDL_cursor->save[1]; + } + src = (Uint8 *) screen->pixels + area.y * screen->pitch + + area.x * screenbpp; + + /* Perform the copy */ + w = area.w * screenbpp; + h = area.h; + while (h--) { + SDL_memcpy (dst, src, w); + dst += w; + src += screen->pitch; + } + } + + /* Draw the mouse cursor */ + area.x -= SDL_cursor->area.x; + area.y -= SDL_cursor->area.y; + if ((area.x == 0) && (area.w == SDL_cursor->area.w)) { + SDL_DrawCursorFast (screen, &area); + } else { + SDL_DrawCursorSlow (screen, &area); + } } -void SDL_DrawCursor(SDL_Surface *screen) +void +SDL_DrawCursor (SDL_Surface * screen) { - /* Lock the screen if necessary */ - if ( screen == NULL ) { - return; - } - if ( SDL_MUSTLOCK(screen) ) { - if ( SDL_LockSurface(screen) < 0 ) { - return; - } - } - - SDL_DrawCursorNoLock(screen); - - /* Unlock the screen and update if necessary */ - if ( SDL_MUSTLOCK(screen) ) { - SDL_UnlockSurface(screen); - } - if ( (screen == SDL_VideoSurface) && - ((screen->flags & SDL_HWSURFACE) != SDL_HWSURFACE) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - SDL_Rect area; - - SDL_MouseRect(&area); - - /* This can be called before a video mode is set */ - if ( video->UpdateRects ) { - video->UpdateRects(this, 1, &area); - } - } + /* Lock the screen if necessary */ + if (screen == NULL) { + return; + } + if (SDL_MUSTLOCK (screen)) { + if (SDL_LockSurface (screen) < 0) { + return; + } + } + + SDL_DrawCursorNoLock (screen); + + /* Unlock the screen and update if necessary */ + if (SDL_MUSTLOCK (screen)) { + SDL_UnlockSurface (screen); + } + if ((screen->flags & SDL_SCREEN_SURFACE) && + !(screen->flags & SDL_HWSURFACE)) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Window *window; + SDL_Rect area; + + window = SDL_GetWindowFromSurface (screen); + if (!window) { + return; + } + + SDL_MouseRect (&area); + + if (_this->UpdateWindowSurface) { + _this->UpdateWindowSurface (_this, window, 1, &area); + } + } } -void SDL_EraseCursorNoLock(SDL_Surface *screen) +void +SDL_EraseCursorNoLock (SDL_Surface * screen) { - SDL_Rect area; - - /* Get the mouse rectangle, clipped to the screen */ - SDL_MouseRect(&area); - if ( (area.w == 0) || (area.h == 0) ) { - return; - } - - /* Copy mouse background */ - { int w, h, screenbpp; - Uint8 *src, *dst; - - /* Set up the copy pointers */ - screenbpp = screen->format->BytesPerPixel; - if ( (screen == SDL_VideoSurface) || - FORMAT_EQUAL(screen->format, SDL_VideoSurface->format) ) { - src = SDL_cursor->save[0]; - } else { - src = SDL_cursor->save[1]; - } - dst = (Uint8 *)screen->pixels + area.y * screen->pitch + - area.x * screenbpp; - - /* Perform the copy */ - w = area.w*screenbpp; - h = area.h; - while ( h-- ) { - SDL_memcpy(dst, src, w); - src += w; - dst += screen->pitch; - } - - /* Perform pixel conversion on cursor background */ - if ( src > SDL_cursor->save[1] ) { - SDL_ConvertCursorSave(screen, area.w, area.h); - } - } + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Window *window; + SDL_Rect area; + + /* Get the window associated with the surface */ + window = SDL_GetWindowFromSurface (screen); + if (!window || !window->surface) { + return; + } + + /* Get the mouse rectangle, clipped to the screen */ + SDL_MouseRect (&area); + if ((area.w == 0) || (area.h == 0)) { + return; + } + + /* Copy mouse background */ + { + int w, h, screenbpp; + Uint8 *src, *dst; + + /* Set up the copy pointers */ + screenbpp = screen->format->BytesPerPixel; + if ((screen->flags & SDL_SCREEN_SURFACE) || + FORMAT_EQUAL (screen->format, window->surface->format)) { + src = SDL_cursor->save[0]; + } else { + src = SDL_cursor->save[1]; + } + dst = (Uint8 *) screen->pixels + area.y * screen->pitch + + area.x * screenbpp; + + /* Perform the copy */ + w = area.w * screenbpp; + h = area.h; + while (h--) { + SDL_memcpy (dst, src, w); + src += w; + dst += screen->pitch; + } + + /* Perform pixel conversion on cursor background */ + if (src > SDL_cursor->save[1]) { + SDL_ConvertCursorSave (screen, area.w, area.h); + } + } } -void SDL_EraseCursor(SDL_Surface *screen) +void +SDL_EraseCursor (SDL_Surface * screen) { - /* Lock the screen if necessary */ - if ( screen == NULL ) { - return; - } - if ( SDL_MUSTLOCK(screen) ) { - if ( SDL_LockSurface(screen) < 0 ) { - return; - } - } - - SDL_EraseCursorNoLock(screen); - - /* Unlock the screen and update if necessary */ - if ( SDL_MUSTLOCK(screen) ) { - SDL_UnlockSurface(screen); - } - if ( (screen == SDL_VideoSurface) && - ((screen->flags & SDL_HWSURFACE) != SDL_HWSURFACE) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - SDL_Rect area; - - SDL_MouseRect(&area); - if ( video->UpdateRects ) { - video->UpdateRects(this, 1, &area); - } - } + /* Lock the screen if necessary */ + if (screen == NULL) { + return; + } + if (SDL_MUSTLOCK (screen)) { + if (SDL_LockSurface (screen) < 0) { + return; + } + } + + SDL_EraseCursorNoLock (screen); + + /* Unlock the screen and update if necessary */ + if (SDL_MUSTLOCK (screen)) { + SDL_UnlockSurface (screen); + } + if ((screen->flags & SDL_SCREEN_SURFACE) && + !(screen->flags & SDL_HWSURFACE)) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Window *window; + SDL_Rect area; + + window = SDL_GetWindowFromSurface (screen); + if (!window) { + return; + } + + SDL_MouseRect (&area); + + if (_this->UpdateWindowSurface) { + _this->UpdateWindowSurface (_this, window, 1, &area); + } + } } /* Reset the cursor on video mode change FIXME: Keep track of all cursors, and reset them all. */ -void SDL_ResetCursor(void) +void +SDL_ResetCursor (void) { - int savelen; - - if ( SDL_cursor ) { - savelen = SDL_cursor->area.w*4*SDL_cursor->area.h; - SDL_cursor->area.x = 0; - SDL_cursor->area.y = 0; - SDL_memset(SDL_cursor->save[0], 0, savelen); - } + int savelen; + + if (SDL_cursor) { + savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h; + SDL_cursor->area.x = 0; + SDL_cursor->area.y = 0; + SDL_memset (SDL_cursor->save[0], 0, savelen); + } } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_cursor_c.h b/src/video/SDL_cursor_c.h index fc983e2d0..8c5f4c8f8 100644 --- a/src/video/SDL_cursor_c.h +++ b/src/video/SDL_cursor_c.h @@ -24,16 +24,16 @@ /* Useful variables and functions from SDL_cursor.c */ #include "SDL_mouse.h" -extern int SDL_CursorInit(Uint32 flags); -extern void SDL_CursorPaletteChanged(void); -extern void SDL_DrawCursor(SDL_Surface *screen); -extern void SDL_DrawCursorNoLock(SDL_Surface *screen); -extern void SDL_EraseCursor(SDL_Surface *screen); -extern void SDL_EraseCursorNoLock(SDL_Surface *screen); -extern void SDL_UpdateCursor(SDL_Surface *screen); -extern void SDL_ResetCursor(void); -extern void SDL_MoveCursor(int x, int y); -extern void SDL_CursorQuit(void); +extern int SDL_CursorInit (Uint32 flags); +extern void SDL_CursorPaletteChanged (void); +extern void SDL_DrawCursor (SDL_Surface * screen); +extern void SDL_DrawCursorNoLock (SDL_Surface * screen); +extern void SDL_EraseCursor (SDL_Surface * screen); +extern void SDL_EraseCursorNoLock (SDL_Surface * screen); +extern void SDL_UpdateCursor (SDL_Surface * screen); +extern void SDL_ResetCursor (void); +extern void SDL_MoveCursor (int x, int y); +extern void SDL_CursorQuit (void); #define INLINE_MOUSELOCK #ifdef INLINE_MOUSELOCK @@ -55,13 +55,13 @@ extern SDL_mutex *SDL_cursorlock; } \ } while ( 0 ) #else -extern void SDL_LockCursor(void); -extern void SDL_UnlockCursor(void); +extern void SDL_LockCursor (void); +extern void SDL_UnlockCursor (void); #endif /* INLINE_MOUSELOCK */ /* Only for low-level mouse cursor drawing */ extern SDL_Cursor *SDL_cursor; -extern void SDL_MouseRect(SDL_Rect *area); +extern void SDL_MouseRect (SDL_Rect * area); /* State definitions for the SDL cursor */ #define CURSOR_VISIBLE 0x01 @@ -71,3 +71,4 @@ extern void SDL_MouseRect(SDL_Rect *area); (CURSOR_VISIBLE|CURSOR_USINGSW)) extern volatile int SDL_cursorstate; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_gamma.c b/src/video/SDL_gamma.c index a5f10727c..05c6c5cb5 100644 --- a/src/video/SDL_gamma.c +++ b/src/video/SDL_gamma.c @@ -24,7 +24,7 @@ /* Gamma correction support */ #ifdef HAVE_MATH_H -#include /* Used for calculating gamma ramps */ +#include /* Used for calculating gamma ramps */ #else /* Math routines from uClibc: http://www.uclibc.org */ #include "math_private.h" @@ -38,196 +38,196 @@ #include "SDL_sysvideo.h" -static void CalculateGammaRamp(float gamma, Uint16 *ramp) +static void +CalculateGammaRamp (float gamma, Uint16 * ramp) { - int i; - - /* 0.0 gamma is all black */ - if ( gamma <= 0.0f ) { - for ( i=0; i<256; ++i ) { - ramp[i] = 0; - } - return; - } else - /* 1.0 gamma is identity */ - if ( gamma >= 1.0f ) { - for ( i=0; i<256; ++i ) { - ramp[i] = (i << 8) | i; - } - return; - } else - /* Calculate a real gamma ramp */ - { int value; - gamma = 1.0f / gamma; - for ( i=0; i<256; ++i ) { - value = (int)(pow((double)i/256.0, gamma)*65535.0+0.5); - if ( value > 65535 ) { - value = 65535; - } - ramp[i] = (Uint16)value; - } - } + int i; + + /* 0.0 gamma is all black */ + if (gamma <= 0.0f) { + for (i = 0; i < 256; ++i) { + ramp[i] = 0; + } + return; + } else + /* 1.0 gamma is identity */ + if (gamma >= 1.0f) { + for (i = 0; i < 256; ++i) { + ramp[i] = (i << 8) | i; + } + return; + } else + /* Calculate a real gamma ramp */ + { + int value; + gamma = 1.0f / gamma; + for (i = 0; i < 256; ++i) { + value = (int) (pow ((double) i / 256.0, gamma) * 65535.0 + 0.5); + if (value > 65535) { + value = 65535; + } + ramp[i] = (Uint16) value; + } + } } -static void CalculateGammaFromRamp(float *gamma, Uint16 *ramp) +static void +CalculateGammaFromRamp (float *gamma, Uint16 * ramp) { - /* The following is adapted from a post by Garrett Bass on OpenGL - Gamedev list, March 4, 2000. - */ - float sum = 0.0f; - int i, count = 0; - - *gamma = 1.0; - for ( i = 1; i < 256; ++i ) { - if ( (ramp[i] != 0) && (ramp[i] != 65535) ) { - double B = (double)i / 256.0; - double A = ramp[i] / 65535.0; - sum += (float) ( log(A) / log(B) ); - count++; - } - } - if ( count && sum > 0.0f ) { - *gamma = 1.0f / (sum / count); - } + /* The following is adapted from a post by Garrett Bass on OpenGL + Gamedev list, March 4, 2000. + */ + float sum = 0.0f; + int i, count = 0; + + *gamma = 1.0; + for (i = 1; i < 256; ++i) { + if ((ramp[i] != 0) && (ramp[i] != 65535)) { + double B = (double) i / 256.0; + double A = ramp[i] / 65535.0; + sum += (float) (log (A) / log (B)); + count++; + } + } + if (count && sum > 0.0f) { + *gamma = 1.0f / (sum / count); + } } -int SDL_SetGamma(float red, float green, float blue) +int +SDL_SetGamma (float red, float green, float blue) { - int succeeded; - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - succeeded = -1; - /* Prefer using SetGammaRamp(), as it's more flexible */ - { - Uint16 ramp[3][256]; - - CalculateGammaRamp(red, ramp[0]); - CalculateGammaRamp(green, ramp[1]); - CalculateGammaRamp(blue, ramp[2]); - succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]); - } - if ( (succeeded < 0) && video->SetGamma ) { - SDL_ClearError(); - succeeded = video->SetGamma(this, red, green, blue); - } - return succeeded; + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + int succeeded; + + succeeded = -1; + /* Prefer using SetGammaRamp(), as it's more flexible */ + { + Uint16 ramp[3][256]; + + CalculateGammaRamp (red, ramp[0]); + CalculateGammaRamp (green, ramp[1]); + CalculateGammaRamp (blue, ramp[2]); + succeeded = SDL_SetGammaRamp (ramp[0], ramp[1], ramp[2]); + } + if ((succeeded < 0) && _this->SetGamma) { + SDL_ClearError (); + succeeded = _this->SetGamma (_this, red, green, blue); + } + return succeeded; } /* Calculating the gamma by integrating the gamma ramps isn't exact, so this function isn't officially supported. */ -int SDL_GetGamma(float *red, float *green, float *blue) +int +SDL_GetGamma (float *red, float *green, float *blue) { - int succeeded; - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - succeeded = -1; - /* Prefer using GetGammaRamp(), as it's more flexible */ - { - Uint16 ramp[3][256]; - - succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]); - if ( succeeded >= 0 ) { - CalculateGammaFromRamp(red, ramp[0]); - CalculateGammaFromRamp(green, ramp[1]); - CalculateGammaFromRamp(blue, ramp[2]); - } - } - if ( (succeeded < 0) && video->GetGamma ) { - SDL_ClearError(); - succeeded = video->GetGamma(this, red, green, blue); - } - return succeeded; + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + int succeeded; + + succeeded = -1; + /* Prefer using GetGammaRamp(), as it's more flexible */ + { + Uint16 ramp[3][256]; + + succeeded = SDL_GetGammaRamp (ramp[0], ramp[1], ramp[2]); + if (succeeded >= 0) { + CalculateGammaFromRamp (red, ramp[0]); + CalculateGammaFromRamp (green, ramp[1]); + CalculateGammaFromRamp (blue, ramp[2]); + } + } + if ((succeeded < 0) && _this->GetGamma) { + SDL_ClearError (); + succeeded = _this->GetGamma (_this, red, green, blue); + } + return succeeded; } -int SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue) +int +SDL_SetGammaRamp (const Uint16 * red, const Uint16 * green, + const Uint16 * blue) { - int succeeded; - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - SDL_Surface *screen = SDL_PublicSurface; - - /* Verify the screen parameter */ - if ( !screen ) { - SDL_SetError("No video mode has been set"); - return -1; - } - - /* Lazily allocate the gamma tables */ - if ( ! video->gamma ) { - SDL_GetGammaRamp(0, 0, 0); - } - - /* Fill the gamma table with the new values */ - if ( red ) { - SDL_memcpy(&video->gamma[0*256], red, 256*sizeof(*video->gamma)); - } - if ( green ) { - SDL_memcpy(&video->gamma[1*256], green, 256*sizeof(*video->gamma)); - } - if ( blue ) { - SDL_memcpy(&video->gamma[2*256], blue, 256*sizeof(*video->gamma)); - } - - /* Gamma correction always possible on split palettes */ - if ( (screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) { - SDL_Palette *pal = screen->format->palette; - - /* If physical palette has been set independently, use it */ - if(video->physpal) - pal = video->physpal; - - SDL_SetPalette(screen, SDL_PHYSPAL, - pal->colors, 0, pal->ncolors); - return 0; - } - - /* Try to set the gamma ramp in the driver */ - succeeded = -1; - if ( video->SetGammaRamp ) { - succeeded = video->SetGammaRamp(this, video->gamma); - } else { - SDL_SetError("Gamma ramp manipulation not supported"); - } - return succeeded; + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + int succeeded; + SDL_Surface *screen = SDL_PublicSurface; + + /* Verify the screen parameter */ + if (!screen) { + SDL_SetError ("No video mode has been set"); + return -1; + } + + /* Lazily allocate the gamma tables */ + if (!SDL_CurrentWindow.gamma) { + SDL_GetGammaRamp (0, 0, 0); + } + + /* Fill the gamma table with the new values */ + if (red) { + SDL_memcpy (&SDL_CurrentWindow.gamma[0 * 256], red, + 256 * sizeof (*SDL_CurrentWindow.gamma)); + } + if (green) { + SDL_memcpy (&SDL_CurrentWindow.gamma[1 * 256], green, + 256 * sizeof (*SDL_CurrentWindow.gamma)); + } + if (blue) { + SDL_memcpy (&SDL_CurrentWindow.gamma[2 * 256], blue, + 256 * sizeof (*SDL_CurrentWindow.gamma)); + } + + /* Try to set the gamma ramp in the driver */ + succeeded = -1; + if (_this->SetGammaRamp) { + succeeded = _this->SetGammaRamp (_this, SDL_CurrentWindow.gamma); + } else { + SDL_SetError ("Gamma ramp manipulation not supported"); + } + return succeeded; } -int SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue) +int +SDL_GetGammaRamp (Uint16 * red, Uint16 * green, Uint16 * blue) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - /* Lazily allocate the gamma table */ - if ( ! video->gamma ) { - video->gamma = SDL_malloc(3*256*sizeof(*video->gamma)); - if ( ! video->gamma ) { - SDL_OutOfMemory(); - return -1; - } - if ( video->GetGammaRamp ) { - /* Get the real hardware gamma */ - video->GetGammaRamp(this, video->gamma); - } else { - /* Assume an identity gamma */ - int i; - for ( i=0; i<256; ++i ) { - video->gamma[0*256+i] = (i << 8) | i; - video->gamma[1*256+i] = (i << 8) | i; - video->gamma[2*256+i] = (i << 8) | i; - } - } - } - - /* Just copy from our internal table */ - if ( red ) { - SDL_memcpy(red, &video->gamma[0*256], 256*sizeof(*red)); - } - if ( green ) { - SDL_memcpy(green, &video->gamma[1*256], 256*sizeof(*green)); - } - if ( blue ) { - SDL_memcpy(blue, &video->gamma[2*256], 256*sizeof(*blue)); - } - return 0; + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + /* Lazily allocate the gamma table */ + if (!SDL_CurrentWindow.gamma) { + SDL_CurrentWindow.gamma = + SDL_malloc (3 * 256 * sizeof (*SDL_CurrentWindow.gamma)); + if (!SDL_CurrentWindow.gamma) { + SDL_OutOfMemory (); + return -1; + } + if (_this->GetGammaRamp) { + /* Get the real hardware gamma */ + _this->GetGammaRamp (_this, SDL_CurrentWindow.gamma); + } else { + /* Assume an identity gamma */ + int i; + for (i = 0; i < 256; ++i) { + SDL_CurrentWindow.gamma[0 * 256 + i] = (i << 8) | i; + SDL_CurrentWindow.gamma[1 * 256 + i] = (i << 8) | i; + SDL_CurrentWindow.gamma[2 * 256 + i] = (i << 8) | i; + } + } + } + + /* Just copy from our internal table */ + if (red) { + SDL_memcpy (red, &SDL_CurrentWindow.gamma[0 * 256], + 256 * sizeof (*red)); + } + if (green) { + SDL_memcpy (green, &SDL_CurrentWindow.gamma[1 * 256], + 256 * sizeof (*green)); + } + if (blue) { + SDL_memcpy (blue, &SDL_CurrentWindow.gamma[2 * 256], + 256 * sizeof (*blue)); + } + return 0; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_glfuncs.h b/src/video/SDL_glfuncs.h index e423f1be2..7cd4ec837 100644 --- a/src/video/SDL_glfuncs.h +++ b/src/video/SDL_glfuncs.h @@ -3,339 +3,457 @@ change it's entry from SDL_PROC_UNUSED to SDL_PROC and rebuild. */ #define SDL_PROC_UNUSED(ret,func,params) -SDL_PROC_UNUSED(void,glAccum,(GLenum,GLfloat)) -SDL_PROC_UNUSED(void,glAlphaFunc,(GLenum,GLclampf)) -SDL_PROC_UNUSED(GLboolean,glAreTexturesResident,(GLsizei,const GLuint*,GLboolean*)) -SDL_PROC_UNUSED(void,glArrayElement,(GLint)) -SDL_PROC(void,glBegin,(GLenum)) -SDL_PROC(void,glBindTexture,(GLenum,GLuint)) -SDL_PROC_UNUSED(void,glBitmap,(GLsizei,GLsizei,GLfloat,GLfloat,GLfloat,GLfloat,const GLubyte*)) -SDL_PROC(void,glBlendFunc,(GLenum,GLenum)) -SDL_PROC_UNUSED(void,glCallList,(GLuint)) -SDL_PROC_UNUSED(void,glCallLists,(GLsizei,GLenum,const GLvoid*)) -SDL_PROC_UNUSED(void,glClear,(GLbitfield)) -SDL_PROC_UNUSED(void,glClearAccum,(GLfloat,GLfloat,GLfloat,GLfloat)) -SDL_PROC_UNUSED(void,glClearColor,(GLclampf,GLclampf,GLclampf,GLclampf)) -SDL_PROC_UNUSED(void,glClearDepth,(GLclampd)) -SDL_PROC_UNUSED(void,glClearIndex,(GLfloat)) -SDL_PROC_UNUSED(void,glClearStencil,(GLint)) -SDL_PROC_UNUSED(void,glClipPlane,(GLenum,const GLdouble*)) -SDL_PROC_UNUSED(void,glColor3b,(GLbyte,GLbyte,GLbyte)) -SDL_PROC_UNUSED(void,glColor3bv,(const GLbyte*)) -SDL_PROC_UNUSED(void,glColor3d,(GLdouble,GLdouble,GLdouble)) -SDL_PROC_UNUSED(void,glColor3dv,(const GLdouble*)) -SDL_PROC_UNUSED(void,glColor3f,(GLfloat,GLfloat,GLfloat)) -SDL_PROC_UNUSED(void,glColor3fv,(const GLfloat*)) -SDL_PROC_UNUSED(void,glColor3i,(GLint,GLint,GLint)) -SDL_PROC_UNUSED(void,glColor3iv,(const GLint*)) -SDL_PROC_UNUSED(void,glColor3s,(GLshort,GLshort,GLshort)) -SDL_PROC_UNUSED(void,glColor3sv,(const GLshort*)) -SDL_PROC(void,glColor3ub,(GLubyte,GLubyte,GLubyte)) -SDL_PROC_UNUSED(void,glColor3ubv,(const GLubyte*)) -SDL_PROC_UNUSED(void,glColor3ui,(GLuint,GLuint,GLuint)) -SDL_PROC_UNUSED(void,glColor3uiv,(const GLuint*)) -SDL_PROC_UNUSED(void,glColor3us,(GLushort,GLushort,GLushort)) -SDL_PROC_UNUSED(void,glColor3usv,(const GLushort*)) -SDL_PROC_UNUSED(void,glColor4b,(GLbyte,GLbyte,GLbyte,GLbyte)) -SDL_PROC_UNUSED(void,glColor4bv,(const GLbyte*)) -SDL_PROC_UNUSED(void,glColor4d,(GLdouble,GLdouble,GLdouble,GLdouble)) -SDL_PROC_UNUSED(void,glColor4dv,(const GLdouble*)) -SDL_PROC(void,glColor4f,(GLfloat,GLfloat,GLfloat,GLfloat)) -SDL_PROC_UNUSED(void,glColor4fv,(const GLfloat*)) -SDL_PROC_UNUSED(void,glColor4i,(GLint,GLint,GLint,GLint)) -SDL_PROC_UNUSED(void,glColor4iv,(const GLint*)) -SDL_PROC_UNUSED(void,glColor4s,(GLshort,GLshort,GLshort,GLshort)) -SDL_PROC_UNUSED(void,glColor4sv,(const GLshort*)) -SDL_PROC(void,glColor4ub,(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)) -SDL_PROC_UNUSED(void,glColor4ubv,(const GLubyte *v)) -SDL_PROC_UNUSED(void,glColor4ui,(GLuint red, GLuint green, GLuint blue, GLuint alpha)) -SDL_PROC_UNUSED(void,glColor4uiv,(const GLuint *v)) -SDL_PROC_UNUSED(void,glColor4us,(GLushort red, GLushort green, GLushort blue, GLushort alpha)) -SDL_PROC_UNUSED(void,glColor4usv,(const GLushort *v)) -SDL_PROC_UNUSED(void,glColorMask,(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) -SDL_PROC_UNUSED(void,glColorMaterial,(GLenum face, GLenum mode)) -SDL_PROC_UNUSED(void,glColorPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)) -SDL_PROC_UNUSED(void,glCopyPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)) -SDL_PROC_UNUSED(void,glCopyTexImage1D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border)) -SDL_PROC_UNUSED(void,glCopyTexImage2D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)) -SDL_PROC_UNUSED(void,glCopyTexSubImage1D,(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width)) -SDL_PROC_UNUSED(void,glCopyTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)) -SDL_PROC_UNUSED(void,glCullFace,(GLenum mode)) -SDL_PROC_UNUSED(void,glDeleteLists,(GLuint list, GLsizei range)) -SDL_PROC(void,glDeleteTextures,(GLsizei n, const GLuint *textures)) -SDL_PROC_UNUSED(void,glDepthFunc,(GLenum func)) -SDL_PROC_UNUSED(void,glDepthMask,(GLboolean flag)) -SDL_PROC_UNUSED(void,glDepthRange,(GLclampd zNear, GLclampd zFar)) -SDL_PROC(void,glDisable,(GLenum cap)) -SDL_PROC_UNUSED(void,glDisableClientState,(GLenum array)) -SDL_PROC_UNUSED(void,glDrawArrays,(GLenum mode, GLint first, GLsizei count)) -SDL_PROC(void,glDrawBuffer,(GLenum mode)) -SDL_PROC_UNUSED(void,glDrawElements,(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)) -SDL_PROC_UNUSED(void,glDrawPixels,(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)) -SDL_PROC_UNUSED(void,glEdgeFlag,(GLboolean flag)) -SDL_PROC_UNUSED(void,glEdgeFlagPointer,(GLsizei stride, const GLvoid *pointer)) -SDL_PROC_UNUSED(void,glEdgeFlagv,(const GLboolean *flag)) -SDL_PROC(void,glEnable,(GLenum cap)) -SDL_PROC_UNUSED(void,glEnableClientState,(GLenum array)) -SDL_PROC(void,glEnd,(void)) -SDL_PROC_UNUSED(void,glEndList,(void)) -SDL_PROC_UNUSED(void,glEvalCoord1d,(GLdouble u)) -SDL_PROC_UNUSED(void,glEvalCoord1dv,(const GLdouble *u)) -SDL_PROC_UNUSED(void,glEvalCoord1f,(GLfloat u)) -SDL_PROC_UNUSED(void,glEvalCoord1fv,(const GLfloat *u)) -SDL_PROC_UNUSED(void,glEvalCoord2d,(GLdouble u, GLdouble v)) -SDL_PROC_UNUSED(void,glEvalCoord2dv,(const GLdouble *u)) -SDL_PROC_UNUSED(void,glEvalCoord2f,(GLfloat u, GLfloat v)) -SDL_PROC_UNUSED(void,glEvalCoord2fv,(const GLfloat *u)) -SDL_PROC_UNUSED(void,glEvalMesh1,(GLenum mode, GLint i1, GLint i2)) -SDL_PROC_UNUSED(void,glEvalMesh2,(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)) -SDL_PROC_UNUSED(void,glEvalPoint1,(GLint i)) -SDL_PROC_UNUSED(void,glEvalPoint2,(GLint i, GLint j)) -SDL_PROC_UNUSED(void,glFeedbackBuffer,(GLsizei size, GLenum type, GLfloat *buffer)) -SDL_PROC(void,glFinish,(void)) -SDL_PROC(void,glFlush,(void)) -SDL_PROC_UNUSED(void,glFogf,(GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glFogfv,(GLenum pname, const GLfloat *params)) -SDL_PROC_UNUSED(void,glFogi,(GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glFogiv,(GLenum pname, const GLint *params)) -SDL_PROC_UNUSED(void,glFrontFace,(GLenum mode)) -SDL_PROC_UNUSED(void,glFrustum,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)) -SDL_PROC_UNUSED(GLuint,glGenLists,(GLsizei range)) -SDL_PROC(void,glGenTextures,(GLsizei n, GLuint *textures)) -SDL_PROC_UNUSED(void,glGetBooleanv,(GLenum pname, GLboolean *params)) -SDL_PROC_UNUSED(void,glGetClipPlane,(GLenum plane, GLdouble *equation)) -SDL_PROC_UNUSED(void,glGetDoublev,(GLenum pname, GLdouble *params)) -SDL_PROC(GLenum,glGetError,(void)) -SDL_PROC_UNUSED(void,glGetFloatv,(GLenum pname, GLfloat *params)) -SDL_PROC(void,glGetIntegerv,(GLenum pname, GLint *params)) -SDL_PROC_UNUSED(void,glGetLightfv,(GLenum light, GLenum pname, GLfloat *params)) -SDL_PROC_UNUSED(void,glGetLightiv,(GLenum light, GLenum pname, GLint *params)) -SDL_PROC_UNUSED(void,glGetMapdv,(GLenum target, GLenum query, GLdouble *v)) -SDL_PROC_UNUSED(void,glGetMapfv,(GLenum target, GLenum query, GLfloat *v)) -SDL_PROC_UNUSED(void,glGetMapiv,(GLenum target, GLenum query, GLint *v)) -SDL_PROC_UNUSED(void,glGetMaterialfv,(GLenum face, GLenum pname, GLfloat *params)) -SDL_PROC_UNUSED(void,glGetMaterialiv,(GLenum face, GLenum pname, GLint *params)) -SDL_PROC_UNUSED(void,glGetPixelMapfv,(GLenum map, GLfloat *values)) -SDL_PROC_UNUSED(void,glGetPixelMapuiv,(GLenum map, GLuint *values)) -SDL_PROC_UNUSED(void,glGetPixelMapusv,(GLenum map, GLushort *values)) -SDL_PROC_UNUSED(void,glGetPointerv,(GLenum pname, GLvoid* *params)) -SDL_PROC_UNUSED(void,glGetPolygonStipple,(GLubyte *mask)) -SDL_PROC(const GLubyte *,glGetString,(GLenum name)) -SDL_PROC_UNUSED(void,glGetTexEnvfv,(GLenum target, GLenum pname, GLfloat *params)) -SDL_PROC_UNUSED(void,glGetTexEnviv,(GLenum target, GLenum pname, GLint *params)) -SDL_PROC_UNUSED(void,glGetTexGendv,(GLenum coord, GLenum pname, GLdouble *params)) -SDL_PROC_UNUSED(void,glGetTexGenfv,(GLenum coord, GLenum pname, GLfloat *params)) -SDL_PROC_UNUSED(void,glGetTexGeniv,(GLenum coord, GLenum pname, GLint *params)) -SDL_PROC_UNUSED(void,glGetTexImage,(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels)) -SDL_PROC_UNUSED(void,glGetTexLevelParameterfv,(GLenum target, GLint level, GLenum pname, GLfloat *params)) -SDL_PROC_UNUSED(void,glGetTexLevelParameteriv,(GLenum target, GLint level, GLenum pname, GLint *params)) -SDL_PROC_UNUSED(void,glGetTexParameterfv,(GLenum target, GLenum pname, GLfloat *params)) -SDL_PROC_UNUSED(void,glGetTexParameteriv,(GLenum target, GLenum pname, GLint *params)) -SDL_PROC_UNUSED(void,glHint,(GLenum target, GLenum mode)) -SDL_PROC_UNUSED(void,glIndexMask,(GLuint mask)) -SDL_PROC_UNUSED(void,glIndexPointer,(GLenum type, GLsizei stride, const GLvoid *pointer)) -SDL_PROC_UNUSED(void,glIndexd,(GLdouble c)) -SDL_PROC_UNUSED(void,glIndexdv,(const GLdouble *c)) -SDL_PROC_UNUSED(void,glIndexf,(GLfloat c)) -SDL_PROC_UNUSED(void,glIndexfv,(const GLfloat *c)) -SDL_PROC_UNUSED(void,glIndexi,(GLint c)) -SDL_PROC_UNUSED(void,glIndexiv,(const GLint *c)) -SDL_PROC_UNUSED(void,glIndexs,(GLshort c)) -SDL_PROC_UNUSED(void,glIndexsv,(const GLshort *c)) -SDL_PROC_UNUSED(void,glIndexub,(GLubyte c)) -SDL_PROC_UNUSED(void,glIndexubv,(const GLubyte *c)) -SDL_PROC_UNUSED(void,glInitNames,(void)) -SDL_PROC_UNUSED(void,glInterleavedArrays,(GLenum format, GLsizei stride, const GLvoid *pointer)) -SDL_PROC_UNUSED(GLboolean,glIsEnabled,(GLenum cap)) -SDL_PROC_UNUSED(GLboolean,glIsList,(GLuint list)) -SDL_PROC_UNUSED(GLboolean,glIsTexture,(GLuint texture)) -SDL_PROC_UNUSED(void,glLightModelf,(GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glLightModelfv,(GLenum pname, const GLfloat *params)) -SDL_PROC_UNUSED(void,glLightModeli,(GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glLightModeliv,(GLenum pname, const GLint *params)) -SDL_PROC_UNUSED(void,glLightf,(GLenum light, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glLightfv,(GLenum light, GLenum pname, const GLfloat *params)) -SDL_PROC_UNUSED(void,glLighti,(GLenum light, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glLightiv,(GLenum light, GLenum pname, const GLint *params)) -SDL_PROC_UNUSED(void,glLineStipple,(GLint factor, GLushort pattern)) -SDL_PROC_UNUSED(void,glLineWidth,(GLfloat width)) -SDL_PROC_UNUSED(void,glListBase,(GLuint base)) -SDL_PROC(void,glLoadIdentity,(void)) -SDL_PROC_UNUSED(void,glLoadMatrixd,(const GLdouble *m)) -SDL_PROC_UNUSED(void,glLoadMatrixf,(const GLfloat *m)) -SDL_PROC_UNUSED(void,glLoadName,(GLuint name)) -SDL_PROC_UNUSED(void,glLogicOp,(GLenum opcode)) -SDL_PROC_UNUSED(void,glMap1d,(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points)) -SDL_PROC_UNUSED(void,glMap1f,(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points)) -SDL_PROC_UNUSED(void,glMap2d,(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points)) -SDL_PROC_UNUSED(void,glMap2f,(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points)) -SDL_PROC_UNUSED(void,glMapGrid1d,(GLint un, GLdouble u1, GLdouble u2)) -SDL_PROC_UNUSED(void,glMapGrid1f,(GLint un, GLfloat u1, GLfloat u2)) -SDL_PROC_UNUSED(void,glMapGrid2d,(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2)) -SDL_PROC_UNUSED(void,glMapGrid2f,(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2)) -SDL_PROC_UNUSED(void,glMaterialf,(GLenum face, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glMaterialfv,(GLenum face, GLenum pname, const GLfloat *params)) -SDL_PROC_UNUSED(void,glMateriali,(GLenum face, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glMaterialiv,(GLenum face, GLenum pname, const GLint *params)) -SDL_PROC(void,glMatrixMode,(GLenum mode)) -SDL_PROC_UNUSED(void,glMultMatrixd,(const GLdouble *m)) -SDL_PROC_UNUSED(void,glMultMatrixf,(const GLfloat *m)) -SDL_PROC_UNUSED(void,glNewList,(GLuint list, GLenum mode)) -SDL_PROC_UNUSED(void,glNormal3b,(GLbyte nx, GLbyte ny, GLbyte nz)) -SDL_PROC_UNUSED(void,glNormal3bv,(const GLbyte *v)) -SDL_PROC_UNUSED(void,glNormal3d,(GLdouble nx, GLdouble ny, GLdouble nz)) -SDL_PROC_UNUSED(void,glNormal3dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glNormal3f,(GLfloat nx, GLfloat ny, GLfloat nz)) -SDL_PROC_UNUSED(void,glNormal3fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glNormal3i,(GLint nx, GLint ny, GLint nz)) -SDL_PROC_UNUSED(void,glNormal3iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glNormal3s,(GLshort nx, GLshort ny, GLshort nz)) -SDL_PROC_UNUSED(void,glNormal3sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glNormalPointer,(GLenum type, GLsizei stride, const GLvoid *pointer)) -SDL_PROC(void,glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)) -SDL_PROC_UNUSED(void,glPassThrough,(GLfloat token)) -SDL_PROC_UNUSED(void,glPixelMapfv,(GLenum map, GLsizei mapsize, const GLfloat *values)) -SDL_PROC_UNUSED(void,glPixelMapuiv,(GLenum map, GLsizei mapsize, const GLuint *values)) -SDL_PROC_UNUSED(void,glPixelMapusv,(GLenum map, GLsizei mapsize, const GLushort *values)) -SDL_PROC_UNUSED(void,glPixelStoref,(GLenum pname, GLfloat param)) -SDL_PROC(void,glPixelStorei,(GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glPixelTransferf,(GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glPixelTransferi,(GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glPixelZoom,(GLfloat xfactor, GLfloat yfactor)) -SDL_PROC_UNUSED(void,glPointSize,(GLfloat size)) -SDL_PROC_UNUSED(void,glPolygonMode,(GLenum face, GLenum mode)) -SDL_PROC_UNUSED(void,glPolygonOffset,(GLfloat factor, GLfloat units)) -SDL_PROC_UNUSED(void,glPolygonStipple,(const GLubyte *mask)) -SDL_PROC(void,glPopAttrib,(void)) -SDL_PROC(void,glPopClientAttrib,(void)) -SDL_PROC(void,glPopMatrix,(void)) -SDL_PROC_UNUSED(void,glPopName,(void)) -SDL_PROC_UNUSED(void,glPrioritizeTextures,(GLsizei n, const GLuint *textures, const GLclampf *priorities)) -SDL_PROC(void,glPushAttrib,(GLbitfield mask)) -SDL_PROC(void,glPushClientAttrib,(GLbitfield mask)) -SDL_PROC(void,glPushMatrix,(void)) -SDL_PROC_UNUSED(void,glPushName,(GLuint name)) -SDL_PROC_UNUSED(void,glRasterPos2d,(GLdouble x, GLdouble y)) -SDL_PROC_UNUSED(void,glRasterPos2dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glRasterPos2f,(GLfloat x, GLfloat y)) -SDL_PROC_UNUSED(void,glRasterPos2fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glRasterPos2i,(GLint x, GLint y)) -SDL_PROC_UNUSED(void,glRasterPos2iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glRasterPos2s,(GLshort x, GLshort y)) -SDL_PROC_UNUSED(void,glRasterPos2sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glRasterPos3d,(GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void,glRasterPos3dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glRasterPos3f,(GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void,glRasterPos3fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glRasterPos3i,(GLint x, GLint y, GLint z)) -SDL_PROC_UNUSED(void,glRasterPos3iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glRasterPos3s,(GLshort x, GLshort y, GLshort z)) -SDL_PROC_UNUSED(void,glRasterPos3sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glRasterPos4d,(GLdouble x, GLdouble y, GLdouble z, GLdouble w)) -SDL_PROC_UNUSED(void,glRasterPos4dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glRasterPos4f,(GLfloat x, GLfloat y, GLfloat z, GLfloat w)) -SDL_PROC_UNUSED(void,glRasterPos4fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glRasterPos4i,(GLint x, GLint y, GLint z, GLint w)) -SDL_PROC_UNUSED(void,glRasterPos4iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glRasterPos4s,(GLshort x, GLshort y, GLshort z, GLshort w)) -SDL_PROC_UNUSED(void,glRasterPos4sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glReadBuffer,(GLenum mode)) -SDL_PROC(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)) -SDL_PROC_UNUSED(void,glRectd,(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)) -SDL_PROC_UNUSED(void,glRectdv,(const GLdouble *v1, const GLdouble *v2)) -SDL_PROC_UNUSED(void,glRectf,(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)) -SDL_PROC_UNUSED(void,glRectfv,(const GLfloat *v1, const GLfloat *v2)) -SDL_PROC_UNUSED(void,glRecti,(GLint x1, GLint y1, GLint x2, GLint y2)) -SDL_PROC_UNUSED(void,glRectiv,(const GLint *v1, const GLint *v2)) -SDL_PROC_UNUSED(void,glRects,(GLshort x1, GLshort y1, GLshort x2, GLshort y2)) -SDL_PROC_UNUSED(void,glRectsv,(const GLshort *v1, const GLshort *v2)) -SDL_PROC_UNUSED(GLint,glRenderMode,(GLenum mode)) -SDL_PROC_UNUSED(void,glRotated,(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void,glRotatef,(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void,glScaled,(GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void,glScalef,(GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void,glScissor,(GLint x, GLint y, GLsizei width, GLsizei height)) -SDL_PROC_UNUSED(void,glSelectBuffer,(GLsizei size, GLuint *buffer)) -SDL_PROC_UNUSED(void,glShadeModel,(GLenum mode)) -SDL_PROC_UNUSED(void,glStencilFunc,(GLenum func, GLint ref, GLuint mask)) -SDL_PROC_UNUSED(void,glStencilMask,(GLuint mask)) -SDL_PROC_UNUSED(void,glStencilOp,(GLenum fail, GLenum zfail, GLenum zpass)) -SDL_PROC_UNUSED(void,glTexCoord1d,(GLdouble s)) -SDL_PROC_UNUSED(void,glTexCoord1dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glTexCoord1f,(GLfloat s)) -SDL_PROC_UNUSED(void,glTexCoord1fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glTexCoord1i,(GLint s)) -SDL_PROC_UNUSED(void,glTexCoord1iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glTexCoord1s,(GLshort s)) -SDL_PROC_UNUSED(void,glTexCoord1sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glTexCoord2d,(GLdouble s, GLdouble t)) -SDL_PROC_UNUSED(void,glTexCoord2dv,(const GLdouble *v)) -SDL_PROC(void,glTexCoord2f,(GLfloat s, GLfloat t)) -SDL_PROC_UNUSED(void,glTexCoord2fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glTexCoord2i,(GLint s, GLint t)) -SDL_PROC_UNUSED(void,glTexCoord2iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glTexCoord2s,(GLshort s, GLshort t)) -SDL_PROC_UNUSED(void,glTexCoord2sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glTexCoord3d,(GLdouble s, GLdouble t, GLdouble r)) -SDL_PROC_UNUSED(void,glTexCoord3dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glTexCoord3f,(GLfloat s, GLfloat t, GLfloat r)) -SDL_PROC_UNUSED(void,glTexCoord3fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glTexCoord3i,(GLint s, GLint t, GLint r)) -SDL_PROC_UNUSED(void,glTexCoord3iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glTexCoord3s,(GLshort s, GLshort t, GLshort r)) -SDL_PROC_UNUSED(void,glTexCoord3sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glTexCoord4d,(GLdouble s, GLdouble t, GLdouble r, GLdouble q)) -SDL_PROC_UNUSED(void,glTexCoord4dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glTexCoord4f,(GLfloat s, GLfloat t, GLfloat r, GLfloat q)) -SDL_PROC_UNUSED(void,glTexCoord4fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glTexCoord4i,(GLint s, GLint t, GLint r, GLint q)) -SDL_PROC_UNUSED(void,glTexCoord4iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glTexCoord4s,(GLshort s, GLshort t, GLshort r, GLshort q)) -SDL_PROC_UNUSED(void,glTexCoord4sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glTexCoordPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)) -SDL_PROC(void,glTexEnvf,(GLenum target, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glTexEnvfv,(GLenum target, GLenum pname, const GLfloat *params)) -SDL_PROC_UNUSED(void,glTexEnvi,(GLenum target, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glTexEnviv,(GLenum target, GLenum pname, const GLint *params)) -SDL_PROC_UNUSED(void,glTexGend,(GLenum coord, GLenum pname, GLdouble param)) -SDL_PROC_UNUSED(void,glTexGendv,(GLenum coord, GLenum pname, const GLdouble *params)) -SDL_PROC_UNUSED(void,glTexGenf,(GLenum coord, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glTexGenfv,(GLenum coord, GLenum pname, const GLfloat *params)) -SDL_PROC_UNUSED(void,glTexGeni,(GLenum coord, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glTexGeniv,(GLenum coord, GLenum pname, const GLint *params)) -SDL_PROC_UNUSED(void,glTexImage1D,(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels)) -SDL_PROC(void,glTexImage2D,(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)) -SDL_PROC_UNUSED(void,glTexParameterf,(GLenum target, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void,glTexParameterfv,(GLenum target, GLenum pname, const GLfloat *params)) -SDL_PROC(void,glTexParameteri,(GLenum target, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void,glTexParameteriv,(GLenum target, GLenum pname, const GLint *params)) -SDL_PROC_UNUSED(void,glTexSubImage1D,(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels)) -SDL_PROC(void,glTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)) -SDL_PROC(void,glTranslated,(GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void,glTranslatef,(GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void,glVertex2d,(GLdouble x, GLdouble y)) -SDL_PROC_UNUSED(void,glVertex2dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glVertex2f,(GLfloat x, GLfloat y)) -SDL_PROC_UNUSED(void,glVertex2fv,(const GLfloat *v)) -SDL_PROC(void,glVertex2i,(GLint x, GLint y)) -SDL_PROC_UNUSED(void,glVertex2iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glVertex2s,(GLshort x, GLshort y)) -SDL_PROC_UNUSED(void,glVertex2sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glVertex3d,(GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void,glVertex3dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glVertex3f,(GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void,glVertex3fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glVertex3i,(GLint x, GLint y, GLint z)) -SDL_PROC_UNUSED(void,glVertex3iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glVertex3s,(GLshort x, GLshort y, GLshort z)) -SDL_PROC_UNUSED(void,glVertex3sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glVertex4d,(GLdouble x, GLdouble y, GLdouble z, GLdouble w)) -SDL_PROC_UNUSED(void,glVertex4dv,(const GLdouble *v)) -SDL_PROC_UNUSED(void,glVertex4f,(GLfloat x, GLfloat y, GLfloat z, GLfloat w)) -SDL_PROC_UNUSED(void,glVertex4fv,(const GLfloat *v)) -SDL_PROC_UNUSED(void,glVertex4i,(GLint x, GLint y, GLint z, GLint w)) -SDL_PROC_UNUSED(void,glVertex4iv,(const GLint *v)) -SDL_PROC_UNUSED(void,glVertex4s,(GLshort x, GLshort y, GLshort z, GLshort w)) -SDL_PROC_UNUSED(void,glVertex4sv,(const GLshort *v)) -SDL_PROC_UNUSED(void,glVertexPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)) -SDL_PROC(void,glViewport,(GLint x, GLint y, GLsizei width, GLsizei height)) +SDL_PROC_UNUSED (void, glAccum, (GLenum, GLfloat)) +SDL_PROC_UNUSED (void, glAlphaFunc, (GLenum, GLclampf)) +SDL_PROC_UNUSED (GLboolean, glAreTexturesResident, + (GLsizei, const GLuint *, GLboolean *)) +SDL_PROC_UNUSED (void, glArrayElement, (GLint)) +SDL_PROC (void, glBegin, (GLenum)) +SDL_PROC (void, glBindTexture, (GLenum, GLuint)) +SDL_PROC_UNUSED (void, glBitmap, + (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat, + const GLubyte *)) +SDL_PROC (void, glBlendFunc, (GLenum, GLenum)) +SDL_PROC_UNUSED (void, glCallList, (GLuint)) +SDL_PROC_UNUSED (void, glCallLists, (GLsizei, GLenum, const GLvoid *)) +SDL_PROC_UNUSED (void, glClear, (GLbitfield)) +SDL_PROC_UNUSED (void, glClearAccum, (GLfloat, GLfloat, GLfloat, GLfloat)) +SDL_PROC_UNUSED (void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf)) +SDL_PROC_UNUSED (void, glClearDepth, (GLclampd)) +SDL_PROC_UNUSED (void, glClearIndex, (GLfloat)) +SDL_PROC_UNUSED (void, glClearStencil, (GLint)) +SDL_PROC_UNUSED (void, glClipPlane, (GLenum, const GLdouble *)) +SDL_PROC_UNUSED (void, glColor3b, (GLbyte, GLbyte, GLbyte)) +SDL_PROC_UNUSED (void, glColor3bv, (const GLbyte *)) +SDL_PROC_UNUSED (void, glColor3d, (GLdouble, GLdouble, GLdouble)) +SDL_PROC_UNUSED (void, glColor3dv, (const GLdouble *)) +SDL_PROC_UNUSED (void, glColor3f, (GLfloat, GLfloat, GLfloat)) +SDL_PROC_UNUSED (void, glColor3fv, (const GLfloat *)) +SDL_PROC_UNUSED (void, glColor3i, (GLint, GLint, GLint)) +SDL_PROC_UNUSED (void, glColor3iv, (const GLint *)) +SDL_PROC_UNUSED (void, glColor3s, (GLshort, GLshort, GLshort)) +SDL_PROC_UNUSED (void, glColor3sv, (const GLshort *)) +SDL_PROC (void, glColor3ub, (GLubyte, GLubyte, GLubyte)) +SDL_PROC_UNUSED (void, glColor3ubv, (const GLubyte *)) +SDL_PROC_UNUSED (void, glColor3ui, (GLuint, GLuint, GLuint)) +SDL_PROC_UNUSED (void, glColor3uiv, (const GLuint *)) +SDL_PROC_UNUSED (void, glColor3us, (GLushort, GLushort, GLushort)) +SDL_PROC_UNUSED (void, glColor3usv, (const GLushort *)) +SDL_PROC_UNUSED (void, glColor4b, (GLbyte, GLbyte, GLbyte, GLbyte)) +SDL_PROC_UNUSED (void, glColor4bv, (const GLbyte *)) +SDL_PROC_UNUSED (void, glColor4d, (GLdouble, GLdouble, GLdouble, GLdouble)) +SDL_PROC_UNUSED (void, glColor4dv, (const GLdouble *)) +SDL_PROC (void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat)) +SDL_PROC_UNUSED (void, glColor4fv, (const GLfloat *)) +SDL_PROC_UNUSED (void, glColor4i, (GLint, GLint, GLint, GLint)) +SDL_PROC_UNUSED (void, glColor4iv, (const GLint *)) +SDL_PROC_UNUSED (void, glColor4s, (GLshort, GLshort, GLshort, GLshort)) +SDL_PROC_UNUSED (void, glColor4sv, (const GLshort *)) +SDL_PROC (void, glColor4ub, + (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)) +SDL_PROC_UNUSED (void, glColor4ubv, (const GLubyte * v)) +SDL_PROC_UNUSED (void, glColor4ui, + (GLuint red, GLuint green, GLuint blue, GLuint alpha)) +SDL_PROC_UNUSED (void, glColor4uiv, (const GLuint * v)) +SDL_PROC_UNUSED (void, glColor4us, + (GLushort red, GLushort green, GLushort blue, + GLushort alpha)) +SDL_PROC_UNUSED (void, glColor4usv, (const GLushort * v)) +SDL_PROC_UNUSED (void, glColorMask, + (GLboolean red, GLboolean green, GLboolean blue, + GLboolean alpha)) +SDL_PROC_UNUSED (void, glColorMaterial, (GLenum face, GLenum mode)) +SDL_PROC_UNUSED (void, glColorPointer, + (GLint size, GLenum type, GLsizei stride, + const GLvoid * pointer)) +SDL_PROC_UNUSED (void, glCopyPixels, + (GLint x, GLint y, GLsizei width, GLsizei height, + GLenum type)) +SDL_PROC_UNUSED (void, glCopyTexImage1D, + (GLenum target, GLint level, GLenum internalFormat, GLint x, + GLint y, GLsizei width, GLint border)) +SDL_PROC_UNUSED (void, glCopyTexImage2D, + (GLenum target, GLint level, GLenum internalFormat, GLint x, + GLint y, GLsizei width, GLsizei height, GLint border)) +SDL_PROC_UNUSED (void, glCopyTexSubImage1D, + (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, + GLsizei width)) +SDL_PROC_UNUSED (void, glCopyTexSubImage2D, + (GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint x, GLint y, GLsizei width, GLsizei height)) +SDL_PROC_UNUSED (void, glCullFace, (GLenum mode)) +SDL_PROC_UNUSED (void, glDeleteLists, (GLuint list, GLsizei range)) +SDL_PROC (void, glDeleteTextures, (GLsizei n, const GLuint * textures)) +SDL_PROC_UNUSED (void, glDepthFunc, (GLenum func)) +SDL_PROC_UNUSED (void, glDepthMask, (GLboolean flag)) +SDL_PROC_UNUSED (void, glDepthRange, (GLclampd zNear, GLclampd zFar)) +SDL_PROC (void, glDisable, (GLenum cap)) +SDL_PROC_UNUSED (void, glDisableClientState, (GLenum array)) +SDL_PROC_UNUSED (void, glDrawArrays, + (GLenum mode, GLint first, GLsizei count)) +SDL_PROC (void, glDrawBuffer, (GLenum mode)) +SDL_PROC_UNUSED (void, glDrawElements, + (GLenum mode, GLsizei count, GLenum type, + const GLvoid * indices)) +SDL_PROC_UNUSED (void, glDrawPixels, + (GLsizei width, GLsizei height, GLenum format, GLenum type, + const GLvoid * pixels)) +SDL_PROC_UNUSED (void, glEdgeFlag, (GLboolean flag)) +SDL_PROC_UNUSED (void, glEdgeFlagPointer, + (GLsizei stride, const GLvoid * pointer)) +SDL_PROC_UNUSED (void, glEdgeFlagv, (const GLboolean * flag)) +SDL_PROC (void, glEnable, (GLenum cap)) +SDL_PROC_UNUSED (void, glEnableClientState, (GLenum array)) +SDL_PROC (void, glEnd, (void)) +SDL_PROC_UNUSED (void, glEndList, (void)) +SDL_PROC_UNUSED (void, glEvalCoord1d, (GLdouble u)) +SDL_PROC_UNUSED (void, glEvalCoord1dv, (const GLdouble * u)) +SDL_PROC_UNUSED (void, glEvalCoord1f, (GLfloat u)) +SDL_PROC_UNUSED (void, glEvalCoord1fv, (const GLfloat * u)) +SDL_PROC_UNUSED (void, glEvalCoord2d, (GLdouble u, GLdouble v)) +SDL_PROC_UNUSED (void, glEvalCoord2dv, (const GLdouble * u)) +SDL_PROC_UNUSED (void, glEvalCoord2f, (GLfloat u, GLfloat v)) +SDL_PROC_UNUSED (void, glEvalCoord2fv, (const GLfloat * u)) +SDL_PROC_UNUSED (void, glEvalMesh1, (GLenum mode, GLint i1, GLint i2)) +SDL_PROC_UNUSED (void, glEvalMesh2, + (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)) +SDL_PROC_UNUSED (void, glEvalPoint1, (GLint i)) +SDL_PROC_UNUSED (void, glEvalPoint2, (GLint i, GLint j)) +SDL_PROC_UNUSED (void, glFeedbackBuffer, + (GLsizei size, GLenum type, GLfloat * buffer)) +SDL_PROC (void, glFinish, (void)) +SDL_PROC (void, glFlush, (void)) +SDL_PROC_UNUSED (void, glFogf, (GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glFogfv, (GLenum pname, const GLfloat * params)) +SDL_PROC_UNUSED (void, glFogi, (GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glFogiv, (GLenum pname, const GLint * params)) +SDL_PROC_UNUSED (void, glFrontFace, (GLenum mode)) +SDL_PROC_UNUSED (void, glFrustum, + (GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble zNear, GLdouble zFar)) +SDL_PROC_UNUSED (GLuint, glGenLists, (GLsizei range)) +SDL_PROC (void, glGenTextures, (GLsizei n, GLuint * textures)) +SDL_PROC_UNUSED (void, glGetBooleanv, (GLenum pname, GLboolean * params)) +SDL_PROC_UNUSED (void, glGetClipPlane, (GLenum plane, GLdouble * equation)) +SDL_PROC_UNUSED (void, glGetDoublev, (GLenum pname, GLdouble * params)) +SDL_PROC (GLenum, glGetError, (void)) +SDL_PROC_UNUSED (void, glGetFloatv, (GLenum pname, GLfloat * params)) +SDL_PROC (void, glGetIntegerv, (GLenum pname, GLint * params)) +SDL_PROC_UNUSED (void, glGetLightfv, + (GLenum light, GLenum pname, GLfloat * params)) +SDL_PROC_UNUSED (void, glGetLightiv, + (GLenum light, GLenum pname, GLint * params)) +SDL_PROC_UNUSED (void, glGetMapdv, + (GLenum target, GLenum query, GLdouble * v)) +SDL_PROC_UNUSED (void, glGetMapfv, (GLenum target, GLenum query, GLfloat * v)) +SDL_PROC_UNUSED (void, glGetMapiv, (GLenum target, GLenum query, GLint * v)) +SDL_PROC_UNUSED (void, glGetMaterialfv, + (GLenum face, GLenum pname, GLfloat * params)) +SDL_PROC_UNUSED (void, glGetMaterialiv, + (GLenum face, GLenum pname, GLint * params)) +SDL_PROC_UNUSED (void, glGetPixelMapfv, (GLenum map, GLfloat * values)) +SDL_PROC_UNUSED (void, glGetPixelMapuiv, (GLenum map, GLuint * values)) +SDL_PROC_UNUSED (void, glGetPixelMapusv, (GLenum map, GLushort * values)) +SDL_PROC_UNUSED (void, glGetPointerv, (GLenum pname, GLvoid * *params)) +SDL_PROC_UNUSED (void, glGetPolygonStipple, (GLubyte * mask)) +SDL_PROC (const GLubyte *, glGetString, (GLenum name)) +SDL_PROC_UNUSED (void, glGetTexEnvfv, + (GLenum target, GLenum pname, GLfloat * params)) +SDL_PROC_UNUSED (void, glGetTexEnviv, + (GLenum target, GLenum pname, GLint * params)) +SDL_PROC_UNUSED (void, glGetTexGendv, + (GLenum coord, GLenum pname, GLdouble * params)) +SDL_PROC_UNUSED (void, glGetTexGenfv, + (GLenum coord, GLenum pname, GLfloat * params)) +SDL_PROC_UNUSED (void, glGetTexGeniv, + (GLenum coord, GLenum pname, GLint * params)) +SDL_PROC_UNUSED (void, glGetTexImage, + (GLenum target, GLint level, GLenum format, GLenum type, + GLvoid * pixels)) +SDL_PROC_UNUSED (void, glGetTexLevelParameterfv, + (GLenum target, GLint level, GLenum pname, GLfloat * params)) +SDL_PROC_UNUSED (void, glGetTexLevelParameteriv, + (GLenum target, GLint level, GLenum pname, GLint * params)) +SDL_PROC_UNUSED (void, glGetTexParameterfv, + (GLenum target, GLenum pname, GLfloat * params)) +SDL_PROC_UNUSED (void, glGetTexParameteriv, + (GLenum target, GLenum pname, GLint * params)) +SDL_PROC_UNUSED (void, glHint, (GLenum target, GLenum mode)) +SDL_PROC_UNUSED (void, glIndexMask, (GLuint mask)) +SDL_PROC_UNUSED (void, glIndexPointer, + (GLenum type, GLsizei stride, const GLvoid * pointer)) +SDL_PROC_UNUSED (void, glIndexd, (GLdouble c)) +SDL_PROC_UNUSED (void, glIndexdv, (const GLdouble * c)) +SDL_PROC_UNUSED (void, glIndexf, (GLfloat c)) +SDL_PROC_UNUSED (void, glIndexfv, (const GLfloat * c)) +SDL_PROC_UNUSED (void, glIndexi, (GLint c)) +SDL_PROC_UNUSED (void, glIndexiv, (const GLint * c)) +SDL_PROC_UNUSED (void, glIndexs, (GLshort c)) +SDL_PROC_UNUSED (void, glIndexsv, (const GLshort * c)) +SDL_PROC_UNUSED (void, glIndexub, (GLubyte c)) +SDL_PROC_UNUSED (void, glIndexubv, (const GLubyte * c)) +SDL_PROC_UNUSED (void, glInitNames, (void)) +SDL_PROC_UNUSED (void, glInterleavedArrays, + (GLenum format, GLsizei stride, const GLvoid * pointer)) +SDL_PROC_UNUSED (GLboolean, glIsEnabled, (GLenum cap)) +SDL_PROC_UNUSED (GLboolean, glIsList, (GLuint list)) +SDL_PROC_UNUSED (GLboolean, glIsTexture, (GLuint texture)) +SDL_PROC_UNUSED (void, glLightModelf, (GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glLightModelfv, (GLenum pname, const GLfloat * params)) +SDL_PROC_UNUSED (void, glLightModeli, (GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glLightModeliv, (GLenum pname, const GLint * params)) +SDL_PROC_UNUSED (void, glLightf, (GLenum light, GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glLightfv, + (GLenum light, GLenum pname, const GLfloat * params)) +SDL_PROC_UNUSED (void, glLighti, (GLenum light, GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glLightiv, + (GLenum light, GLenum pname, const GLint * params)) +SDL_PROC_UNUSED (void, glLineStipple, (GLint factor, GLushort pattern)) +SDL_PROC_UNUSED (void, glLineWidth, (GLfloat width)) +SDL_PROC_UNUSED (void, glListBase, (GLuint base)) +SDL_PROC (void, glLoadIdentity, (void)) +SDL_PROC_UNUSED (void, glLoadMatrixd, (const GLdouble * m)) +SDL_PROC_UNUSED (void, glLoadMatrixf, (const GLfloat * m)) +SDL_PROC_UNUSED (void, glLoadName, (GLuint name)) +SDL_PROC_UNUSED (void, glLogicOp, (GLenum opcode)) +SDL_PROC_UNUSED (void, glMap1d, + (GLenum target, GLdouble u1, GLdouble u2, GLint stride, + GLint order, const GLdouble * points)) +SDL_PROC_UNUSED (void, glMap1f, + (GLenum target, GLfloat u1, GLfloat u2, GLint stride, + GLint order, const GLfloat * points)) +SDL_PROC_UNUSED (void, glMap2d, + (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, + GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, + GLint vorder, const GLdouble * points)) +SDL_PROC_UNUSED (void, glMap2f, + (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, + GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, + GLint vorder, const GLfloat * points)) +SDL_PROC_UNUSED (void, glMapGrid1d, (GLint un, GLdouble u1, GLdouble u2)) +SDL_PROC_UNUSED (void, glMapGrid1f, (GLint un, GLfloat u1, GLfloat u2)) +SDL_PROC_UNUSED (void, glMapGrid2d, + (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, + GLdouble v2)) +SDL_PROC_UNUSED (void, glMapGrid2f, + (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, + GLfloat v2)) +SDL_PROC_UNUSED (void, glMaterialf, + (GLenum face, GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glMaterialfv, + (GLenum face, GLenum pname, const GLfloat * params)) +SDL_PROC_UNUSED (void, glMateriali, (GLenum face, GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glMaterialiv, + (GLenum face, GLenum pname, const GLint * params)) +SDL_PROC (void, glMatrixMode, (GLenum mode)) +SDL_PROC_UNUSED (void, glMultMatrixd, (const GLdouble * m)) +SDL_PROC_UNUSED (void, glMultMatrixf, (const GLfloat * m)) +SDL_PROC_UNUSED (void, glNewList, (GLuint list, GLenum mode)) +SDL_PROC_UNUSED (void, glNormal3b, (GLbyte nx, GLbyte ny, GLbyte nz)) +SDL_PROC_UNUSED (void, glNormal3bv, (const GLbyte * v)) +SDL_PROC_UNUSED (void, glNormal3d, (GLdouble nx, GLdouble ny, GLdouble nz)) +SDL_PROC_UNUSED (void, glNormal3dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glNormal3f, (GLfloat nx, GLfloat ny, GLfloat nz)) +SDL_PROC_UNUSED (void, glNormal3fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glNormal3i, (GLint nx, GLint ny, GLint nz)) +SDL_PROC_UNUSED (void, glNormal3iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glNormal3s, (GLshort nx, GLshort ny, GLshort nz)) +SDL_PROC_UNUSED (void, glNormal3sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glNormalPointer, + (GLenum type, GLsizei stride, const GLvoid * pointer)) +SDL_PROC (void, glOrtho, + (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, + GLdouble zNear, GLdouble zFar)) +SDL_PROC_UNUSED (void, glPassThrough, (GLfloat token)) +SDL_PROC_UNUSED (void, glPixelMapfv, + (GLenum map, GLsizei mapsize, const GLfloat * values)) +SDL_PROC_UNUSED (void, glPixelMapuiv, + (GLenum map, GLsizei mapsize, const GLuint * values)) +SDL_PROC_UNUSED (void, glPixelMapusv, + (GLenum map, GLsizei mapsize, const GLushort * values)) +SDL_PROC_UNUSED (void, glPixelStoref, (GLenum pname, GLfloat param)) +SDL_PROC (void, glPixelStorei, (GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glPixelTransferf, (GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glPixelTransferi, (GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor)) +SDL_PROC_UNUSED (void, glPointSize, (GLfloat size)) +SDL_PROC_UNUSED (void, glPolygonMode, (GLenum face, GLenum mode)) +SDL_PROC_UNUSED (void, glPolygonOffset, (GLfloat factor, GLfloat units)) +SDL_PROC_UNUSED (void, glPolygonStipple, (const GLubyte * mask)) +SDL_PROC (void, glPopAttrib, (void)) +SDL_PROC (void, glPopClientAttrib, (void)) +SDL_PROC (void, glPopMatrix, (void)) +SDL_PROC_UNUSED (void, glPopName, (void)) +SDL_PROC_UNUSED (void, glPrioritizeTextures, + (GLsizei n, const GLuint * textures, + const GLclampf * priorities)) +SDL_PROC (void, glPushAttrib, (GLbitfield mask)) +SDL_PROC (void, glPushClientAttrib, (GLbitfield mask)) +SDL_PROC (void, glPushMatrix, (void)) +SDL_PROC_UNUSED (void, glPushName, (GLuint name)) +SDL_PROC_UNUSED (void, glRasterPos2d, (GLdouble x, GLdouble y)) +SDL_PROC_UNUSED (void, glRasterPos2dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glRasterPos2f, (GLfloat x, GLfloat y)) +SDL_PROC_UNUSED (void, glRasterPos2fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glRasterPos2i, (GLint x, GLint y)) +SDL_PROC_UNUSED (void, glRasterPos2iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glRasterPos2s, (GLshort x, GLshort y)) +SDL_PROC_UNUSED (void, glRasterPos2sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glRasterPos3d, (GLdouble x, GLdouble y, GLdouble z)) +SDL_PROC_UNUSED (void, glRasterPos3dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glRasterPos3f, (GLfloat x, GLfloat y, GLfloat z)) +SDL_PROC_UNUSED (void, glRasterPos3fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glRasterPos3i, (GLint x, GLint y, GLint z)) +SDL_PROC_UNUSED (void, glRasterPos3iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glRasterPos3s, (GLshort x, GLshort y, GLshort z)) +SDL_PROC_UNUSED (void, glRasterPos3sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glRasterPos4d, + (GLdouble x, GLdouble y, GLdouble z, GLdouble w)) +SDL_PROC_UNUSED (void, glRasterPos4dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glRasterPos4f, + (GLfloat x, GLfloat y, GLfloat z, GLfloat w)) +SDL_PROC_UNUSED (void, glRasterPos4fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glRasterPos4i, (GLint x, GLint y, GLint z, GLint w)) +SDL_PROC_UNUSED (void, glRasterPos4iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glRasterPos4s, + (GLshort x, GLshort y, GLshort z, GLshort w)) +SDL_PROC_UNUSED (void, glRasterPos4sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glReadBuffer, (GLenum mode)) +SDL_PROC (void, glReadPixels, + (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, + GLenum type, GLvoid * pixels)) +SDL_PROC_UNUSED (void, glRectd, + (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)) +SDL_PROC_UNUSED (void, glRectdv, (const GLdouble * v1, const GLdouble * v2)) +SDL_PROC_UNUSED (void, glRectf, + (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)) +SDL_PROC_UNUSED (void, glRectfv, (const GLfloat * v1, const GLfloat * v2)) +SDL_PROC_UNUSED (void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2)) +SDL_PROC_UNUSED (void, glRectiv, (const GLint * v1, const GLint * v2)) +SDL_PROC_UNUSED (void, glRects, + (GLshort x1, GLshort y1, GLshort x2, GLshort y2)) +SDL_PROC_UNUSED (void, glRectsv, (const GLshort * v1, const GLshort * v2)) +SDL_PROC_UNUSED (GLint, glRenderMode, (GLenum mode)) +SDL_PROC_UNUSED (void, glRotated, + (GLdouble angle, GLdouble x, GLdouble y, GLdouble z)) +SDL_PROC_UNUSED (void, glRotatef, + (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) +SDL_PROC_UNUSED (void, glScaled, (GLdouble x, GLdouble y, GLdouble z)) +SDL_PROC_UNUSED (void, glScalef, (GLfloat x, GLfloat y, GLfloat z)) +SDL_PROC_UNUSED (void, glScissor, + (GLint x, GLint y, GLsizei width, GLsizei height)) +SDL_PROC_UNUSED (void, glSelectBuffer, (GLsizei size, GLuint * buffer)) +SDL_PROC_UNUSED (void, glShadeModel, (GLenum mode)) +SDL_PROC_UNUSED (void, glStencilFunc, (GLenum func, GLint ref, GLuint mask)) +SDL_PROC_UNUSED (void, glStencilMask, (GLuint mask)) +SDL_PROC_UNUSED (void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass)) +SDL_PROC_UNUSED (void, glTexCoord1d, (GLdouble s)) +SDL_PROC_UNUSED (void, glTexCoord1dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glTexCoord1f, (GLfloat s)) +SDL_PROC_UNUSED (void, glTexCoord1fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glTexCoord1i, (GLint s)) +SDL_PROC_UNUSED (void, glTexCoord1iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glTexCoord1s, (GLshort s)) +SDL_PROC_UNUSED (void, glTexCoord1sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glTexCoord2d, (GLdouble s, GLdouble t)) +SDL_PROC_UNUSED (void, glTexCoord2dv, (const GLdouble * v)) +SDL_PROC (void, glTexCoord2f, (GLfloat s, GLfloat t)) +SDL_PROC_UNUSED (void, glTexCoord2fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glTexCoord2i, (GLint s, GLint t)) +SDL_PROC_UNUSED (void, glTexCoord2iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glTexCoord2s, (GLshort s, GLshort t)) +SDL_PROC_UNUSED (void, glTexCoord2sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glTexCoord3d, (GLdouble s, GLdouble t, GLdouble r)) +SDL_PROC_UNUSED (void, glTexCoord3dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glTexCoord3f, (GLfloat s, GLfloat t, GLfloat r)) +SDL_PROC_UNUSED (void, glTexCoord3fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glTexCoord3i, (GLint s, GLint t, GLint r)) +SDL_PROC_UNUSED (void, glTexCoord3iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glTexCoord3s, (GLshort s, GLshort t, GLshort r)) +SDL_PROC_UNUSED (void, glTexCoord3sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glTexCoord4d, + (GLdouble s, GLdouble t, GLdouble r, GLdouble q)) +SDL_PROC_UNUSED (void, glTexCoord4dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glTexCoord4f, + (GLfloat s, GLfloat t, GLfloat r, GLfloat q)) +SDL_PROC_UNUSED (void, glTexCoord4fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glTexCoord4i, (GLint s, GLint t, GLint r, GLint q)) +SDL_PROC_UNUSED (void, glTexCoord4iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glTexCoord4s, + (GLshort s, GLshort t, GLshort r, GLshort q)) +SDL_PROC_UNUSED (void, glTexCoord4sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glTexCoordPointer, + (GLint size, GLenum type, GLsizei stride, + const GLvoid * pointer)) +SDL_PROC (void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glTexEnvfv, + (GLenum target, GLenum pname, const GLfloat * params)) +SDL_PROC_UNUSED (void, glTexEnvi, (GLenum target, GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glTexEnviv, + (GLenum target, GLenum pname, const GLint * params)) +SDL_PROC_UNUSED (void, glTexGend, + (GLenum coord, GLenum pname, GLdouble param)) +SDL_PROC_UNUSED (void, glTexGendv, + (GLenum coord, GLenum pname, const GLdouble * params)) +SDL_PROC_UNUSED (void, glTexGenf, (GLenum coord, GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glTexGenfv, + (GLenum coord, GLenum pname, const GLfloat * params)) +SDL_PROC_UNUSED (void, glTexGeni, (GLenum coord, GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glTexGeniv, + (GLenum coord, GLenum pname, const GLint * params)) +SDL_PROC_UNUSED (void, glTexImage1D, + (GLenum target, GLint level, GLint internalformat, + GLsizei width, GLint border, GLenum format, GLenum type, + const GLvoid * pixels)) +SDL_PROC (void, glTexImage2D, + (GLenum target, GLint level, GLint internalformat, GLsizei width, + GLsizei height, GLint border, GLenum format, GLenum type, + const GLvoid * pixels)) +SDL_PROC_UNUSED (void, glTexParameterf, + (GLenum target, GLenum pname, GLfloat param)) +SDL_PROC_UNUSED (void, glTexParameterfv, + (GLenum target, GLenum pname, const GLfloat * params)) +SDL_PROC (void, glTexParameteri, (GLenum target, GLenum pname, GLint param)) +SDL_PROC_UNUSED (void, glTexParameteriv, + (GLenum target, GLenum pname, const GLint * params)) +SDL_PROC_UNUSED (void, glTexSubImage1D, + (GLenum target, GLint level, GLint xoffset, GLsizei width, + GLenum format, GLenum type, const GLvoid * pixels)) +SDL_PROC (void, glTexSubImage2D, + (GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const GLvoid * pixels)) +SDL_PROC (void, glTranslated, (GLdouble x, GLdouble y, GLdouble z)) +SDL_PROC_UNUSED (void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z)) +SDL_PROC_UNUSED (void, glVertex2d, (GLdouble x, GLdouble y)) +SDL_PROC_UNUSED (void, glVertex2dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glVertex2f, (GLfloat x, GLfloat y)) +SDL_PROC_UNUSED (void, glVertex2fv, (const GLfloat * v)) +SDL_PROC (void, glVertex2i, (GLint x, GLint y)) +SDL_PROC_UNUSED (void, glVertex2iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glVertex2s, (GLshort x, GLshort y)) +SDL_PROC_UNUSED (void, glVertex2sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z)) +SDL_PROC_UNUSED (void, glVertex3dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z)) +SDL_PROC_UNUSED (void, glVertex3fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glVertex3i, (GLint x, GLint y, GLint z)) +SDL_PROC_UNUSED (void, glVertex3iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glVertex3s, (GLshort x, GLshort y, GLshort z)) +SDL_PROC_UNUSED (void, glVertex3sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glVertex4d, + (GLdouble x, GLdouble y, GLdouble z, GLdouble w)) +SDL_PROC_UNUSED (void, glVertex4dv, (const GLdouble * v)) +SDL_PROC_UNUSED (void, glVertex4f, + (GLfloat x, GLfloat y, GLfloat z, GLfloat w)) +SDL_PROC_UNUSED (void, glVertex4fv, (const GLfloat * v)) +SDL_PROC_UNUSED (void, glVertex4i, (GLint x, GLint y, GLint z, GLint w)) +SDL_PROC_UNUSED (void, glVertex4iv, (const GLint * v)) +SDL_PROC_UNUSED (void, glVertex4s, + (GLshort x, GLshort y, GLshort z, GLshort w)) +SDL_PROC_UNUSED (void, glVertex4sv, (const GLshort * v)) +SDL_PROC_UNUSED (void, glVertexPointer, + (GLint size, GLenum type, GLsizei stride, + const GLvoid * pointer)) +SDL_PROC (void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height)) +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_leaks.h b/src/video/SDL_leaks.h index 5151646fd..be400ee7f 100644 --- a/src/video/SDL_leaks.h +++ b/src/video/SDL_leaks.h @@ -29,3 +29,4 @@ #ifdef CHECK_LEAKS extern int surfaces_allocated; #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 9b8a1257e..8b74d1ebd 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -31,591 +31,806 @@ #include "SDL_RLEaccel_c.h" /* Helper functions */ + +SDL_bool +SDL_PixelFormatEnumToMasks (Uint32 format, int *bpp, Uint32 * Rmask, + Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask) +{ + Uint32 masks[4]; + + /* Initialize the values here */ + if (SDL_BITSPERPIXEL (format) == 24) { + *bpp = SDL_BYTESPERPIXEL (format) * 8; + } else { + *bpp = SDL_BITSPERPIXEL (format); + } + *Rmask = *Gmask = *Bmask = *Amask = 0; + + if (SDL_PIXELTYPE (format) != SDL_PixelType_Packed8 && + SDL_PIXELTYPE (format) != SDL_PixelType_Packed16 && + SDL_PIXELTYPE (format) != SDL_PixelType_Packed32) { + /* Not a format that uses masks */ + return SDL_TRUE; + } + + switch (SDL_PIXELLAYOUT (format)) { + case SDL_PackedLayout_332: + masks[0] = 0x00000000; + masks[1] = 0x000000E0; + masks[2] = 0x0000001C; + masks[3] = 0x00000003; + break; + case SDL_PackedLayout_4444: + masks[0] = 0x0000F000; + masks[1] = 0x00000F00; + masks[2] = 0x000000F0; + masks[3] = 0x0000000F; + break; + case SDL_PackedLayout_1555: + masks[0] = 0x00008000; + masks[1] = 0x00007C00; + masks[2] = 0x000003E0; + masks[3] = 0x0000001F; + break; + case SDL_PackedLayout_565: + masks[0] = 0x00000000; + masks[1] = 0x0000F800; + masks[2] = 0x000007E0; + masks[3] = 0x0000001F; + break; + case SDL_PackedLayout_8888: + masks[0] = 0xFF000000; + masks[1] = 0x00FF0000; + masks[2] = 0x0000FF00; + masks[3] = 0x000000FF; + break; + case SDL_PackedLayout_2101010: + masks[0] = 0xC0000000; + masks[1] = 0x3FF00000; + masks[2] = 0x000FFC00; + masks[3] = 0x000003FF; + break; + default: + /* Unknown layout */ + return SDL_FALSE; + } + + switch (SDL_PIXELORDER (format)) { + case SDL_PackedOrder_XRGB: + *Rmask = masks[1]; + *Gmask = masks[2]; + *Bmask = masks[3]; + break; + case SDL_PackedOrder_RGBX: + *Rmask = masks[0]; + *Gmask = masks[1]; + *Bmask = masks[2]; + break; + case SDL_PackedOrder_ARGB: + *Amask = masks[0]; + *Rmask = masks[1]; + *Gmask = masks[2]; + *Bmask = masks[3]; + break; + case SDL_PackedOrder_RGBA: + *Rmask = masks[0]; + *Gmask = masks[1]; + *Bmask = masks[2]; + *Amask = masks[3]; + break; + case SDL_PackedOrder_XBGR: + *Bmask = masks[1]; + *Gmask = masks[2]; + *Rmask = masks[3]; + break; + case SDL_PackedOrder_BGRX: + *Bmask = masks[0]; + *Gmask = masks[1]; + *Rmask = masks[2]; + break; + case SDL_PackedOrder_BGRA: + *Bmask = masks[0]; + *Gmask = masks[1]; + *Rmask = masks[2]; + *Amask = masks[3]; + break; + case SDL_PackedOrder_ABGR: + *Amask = masks[0]; + *Bmask = masks[1]; + *Gmask = masks[2]; + *Rmask = masks[3]; + break; + default: + /* Unknown order */ + return SDL_FALSE; + } + return SDL_TRUE; +} + +Uint32 +SDL_MasksToPixelFormatEnum (int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, + Uint32 Amask) +{ + switch (bpp) { + case 8: + switch (Rmask) { + case 0: + return SDL_PixelFormat_Index8; + case 0xE0: + return SDL_PixelFormat_RGB332; + } + break; + case 12: + switch (Rmask) { + case 0x0F00: + return SDL_PixelFormat_RGB444; + } + break; + case 15: + switch (Rmask) { + case 0x7C00: + return SDL_PixelFormat_RGB555; + } + break; + case 16: + switch (Rmask) { + case 0x0F00: + return SDL_PixelFormat_ARGB4444; + case 0x7C00: + return SDL_PixelFormat_ARGB1555; + case 0xF800: + return SDL_PixelFormat_RGB565; + } + break; + case 32: + switch (Rmask) { + case 0xFF000000: + if (Amask == 0x000000FF) { + return SDL_PixelFormat_RGBA8888; + } + break; + case 0x00FF0000: + if (Amask == 0xFF000000) { + return SDL_PixelFormat_ARGB8888; + } else { + return SDL_PixelFormat_RGB888; + } + break; + case 0x0000FF00: + if (Amask == 0x000000FF) { + return SDL_PixelFormat_BGRA8888; + } + break; + case 0x000000FF: + if (Amask == 0xFF000000) { + return SDL_PixelFormat_ABGR8888; + } else { + return SDL_PixelFormat_BGR888; + } + break; + case 0x3FF00000: + return SDL_PixelFormat_ARGB2101010; + } + } + return SDL_PixelFormat_Unknown; +} + /* * Allocate a pixel format structure and fill it according to the given info. */ -SDL_PixelFormat *SDL_AllocFormat(int bpp, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) +SDL_PixelFormat * +SDL_AllocFormat (int bpp, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) { - SDL_PixelFormat *format; - Uint32 mask; - - /* Allocate an empty pixel format structure */ - format = SDL_malloc(sizeof(*format)); - if ( format == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - SDL_memset(format, 0, sizeof(*format)); - format->alpha = SDL_ALPHA_OPAQUE; - - /* Set up the format */ - format->BitsPerPixel = bpp; - format->BytesPerPixel = (bpp+7)/8; - if ( Rmask || Bmask || Gmask ) { /* Packed pixels with custom mask */ - format->palette = NULL; - format->Rshift = 0; - format->Rloss = 8; - if ( Rmask ) { - for ( mask = Rmask; !(mask&0x01); mask >>= 1 ) - ++format->Rshift; - for ( ; (mask&0x01); mask >>= 1 ) - --format->Rloss; - } - format->Gshift = 0; - format->Gloss = 8; - if ( Gmask ) { - for ( mask = Gmask; !(mask&0x01); mask >>= 1 ) - ++format->Gshift; - for ( ; (mask&0x01); mask >>= 1 ) - --format->Gloss; - } - format->Bshift = 0; - format->Bloss = 8; - if ( Bmask ) { - for ( mask = Bmask; !(mask&0x01); mask >>= 1 ) - ++format->Bshift; - for ( ; (mask&0x01); mask >>= 1 ) - --format->Bloss; - } - format->Ashift = 0; - format->Aloss = 8; - if ( Amask ) { - for ( mask = Amask; !(mask&0x01); mask >>= 1 ) - ++format->Ashift; - for ( ; (mask&0x01); mask >>= 1 ) - --format->Aloss; - } - format->Rmask = Rmask; - format->Gmask = Gmask; - format->Bmask = Bmask; - format->Amask = Amask; - } else if ( bpp > 8 ) { /* Packed pixels with standard mask */ - /* R-G-B */ - if ( bpp > 24 ) - bpp = 24; - format->Rloss = 8-(bpp/3); - format->Gloss = 8-(bpp/3)-(bpp%3); - format->Bloss = 8-(bpp/3); - format->Rshift = ((bpp/3)+(bpp%3))+(bpp/3); - format->Gshift = (bpp/3); - format->Bshift = 0; - format->Rmask = ((0xFF>>format->Rloss)<Rshift); - format->Gmask = ((0xFF>>format->Gloss)<Gshift); - format->Bmask = ((0xFF>>format->Bloss)<Bshift); - } else { - /* Palettized formats have no mask info */ - format->Rloss = 8; - format->Gloss = 8; - format->Bloss = 8; - format->Aloss = 8; - format->Rshift = 0; - format->Gshift = 0; - format->Bshift = 0; - format->Ashift = 0; - format->Rmask = 0; - format->Gmask = 0; - format->Bmask = 0; - format->Amask = 0; - } - if ( bpp <= 8 ) { /* Palettized mode */ - int ncolors = 1<alpha = SDL_ALPHA_OPAQUE; + + /* Set up the format */ + format->BitsPerPixel = bpp; + format->BytesPerPixel = (bpp + 7) / 8; + if (Rmask || Bmask || Gmask) { /* Packed pixels with custom mask */ + format->palette = NULL; + format->Rshift = 0; + format->Rloss = 8; + if (Rmask) { + for (mask = Rmask; !(mask & 0x01); mask >>= 1) + ++format->Rshift; + for (; (mask & 0x01); mask >>= 1) + --format->Rloss; + } + format->Gshift = 0; + format->Gloss = 8; + if (Gmask) { + for (mask = Gmask; !(mask & 0x01); mask >>= 1) + ++format->Gshift; + for (; (mask & 0x01); mask >>= 1) + --format->Gloss; + } + format->Bshift = 0; + format->Bloss = 8; + if (Bmask) { + for (mask = Bmask; !(mask & 0x01); mask >>= 1) + ++format->Bshift; + for (; (mask & 0x01); mask >>= 1) + --format->Bloss; + } + format->Ashift = 0; + format->Aloss = 8; + if (Amask) { + for (mask = Amask; !(mask & 0x01); mask >>= 1) + ++format->Ashift; + for (; (mask & 0x01); mask >>= 1) + --format->Aloss; + } + format->Rmask = Rmask; + format->Gmask = Gmask; + format->Bmask = Bmask; + format->Amask = Amask; + } else if (bpp > 8) { /* Packed pixels with standard mask */ + /* R-G-B */ + if (bpp > 24) + bpp = 24; + format->Rloss = 8 - (bpp / 3); + format->Gloss = 8 - (bpp / 3) - (bpp % 3); + format->Bloss = 8 - (bpp / 3); + format->Rshift = ((bpp / 3) + (bpp % 3)) + (bpp / 3); + format->Gshift = (bpp / 3); + format->Bshift = 0; + format->Rmask = ((0xFF >> format->Rloss) << format->Rshift); + format->Gmask = ((0xFF >> format->Gloss) << format->Gshift); + format->Bmask = ((0xFF >> format->Bloss) << format->Bshift); + } else { + /* Palettized formats have no mask info */ + format->Rloss = 8; + format->Gloss = 8; + format->Bloss = 8; + format->Aloss = 8; + format->Rshift = 0; + format->Gshift = 0; + format->Bshift = 0; + format->Ashift = 0; + format->Rmask = 0; + format->Gmask = 0; + format->Bmask = 0; + format->Amask = 0; + } + if (bpp <= 8) { /* Palettized mode */ + int ncolors = 1 << bpp; #ifdef DEBUG_PALETTE - fprintf(stderr,"bpp=%d ncolors=%d\n",bpp,ncolors); + fprintf (stderr, "bpp=%d ncolors=%d\n", bpp, ncolors); #endif - format->palette = (SDL_Palette *)SDL_malloc(sizeof(SDL_Palette)); - if ( format->palette == NULL ) { - SDL_FreeFormat(format); - SDL_OutOfMemory(); - return(NULL); - } - (format->palette)->ncolors = ncolors; - (format->palette)->colors = (SDL_Color *)SDL_malloc( - (format->palette)->ncolors*sizeof(SDL_Color)); - if ( (format->palette)->colors == NULL ) { - SDL_FreeFormat(format); - SDL_OutOfMemory(); - return(NULL); - } - if ( Rmask || Bmask || Gmask ) { - /* create palette according to masks */ - int i; - int Rm=0,Gm=0,Bm=0; - int Rw=0,Gw=0,Bw=0; + format->palette = (SDL_Palette *) SDL_malloc (sizeof (SDL_Palette)); + if (format->palette == NULL) { + SDL_FreeFormat (format); + SDL_OutOfMemory (); + return (NULL); + } + (format->palette)->ncolors = ncolors; + (format->palette)->colors = (SDL_Color *) SDL_malloc ((format-> + palette)-> + ncolors * + sizeof + (SDL_Color)); + if ((format->palette)->colors == NULL) { + SDL_FreeFormat (format); + SDL_OutOfMemory (); + return (NULL); + } + if (Rmask || Bmask || Gmask) { + /* create palette according to masks */ + int i; + int Rm = 0, Gm = 0, Bm = 0; + int Rw = 0, Gw = 0, Bw = 0; #ifdef ENABLE_PALETTE_ALPHA - int Am=0,Aw=0; + int Am = 0, Aw = 0; #endif - if(Rmask) - { - Rw=8-format->Rloss; - for(i=format->Rloss;i>0;i-=Rw) - Rm|=1<Rloss; + for (i = format->Rloss; i > 0; i -= Rw) + Rm |= 1 << i; + } #ifdef DEBUG_PALETTE - fprintf(stderr,"Rw=%d Rm=0x%02X\n",Rw,Rm); + fprintf (stderr, "Rw=%d Rm=0x%02X\n", Rw, Rm); #endif - if(Gmask) - { - Gw=8-format->Gloss; - for(i=format->Gloss;i>0;i-=Gw) - Gm|=1<Gloss; + for (i = format->Gloss; i > 0; i -= Gw) + Gm |= 1 << i; + } #ifdef DEBUG_PALETTE - fprintf(stderr,"Gw=%d Gm=0x%02X\n",Gw,Gm); + fprintf (stderr, "Gw=%d Gm=0x%02X\n", Gw, Gm); #endif - if(Bmask) - { - Bw=8-format->Bloss; - for(i=format->Bloss;i>0;i-=Bw) - Bm|=1<Bloss; + for (i = format->Bloss; i > 0; i -= Bw) + Bm |= 1 << i; + } #ifdef DEBUG_PALETTE - fprintf(stderr,"Bw=%d Bm=0x%02X\n",Bw,Bm); + fprintf (stderr, "Bw=%d Bm=0x%02X\n", Bw, Bm); #endif #ifdef ENABLE_PALETTE_ALPHA - if(Amask) - { - Aw=8-format->Aloss; - for(i=format->Aloss;i>0;i-=Aw) - Am|=1<Aloss; + for (i = format->Aloss; i > 0; i -= Aw) + Am |= 1 << i; + } # ifdef DEBUG_PALETTE - fprintf(stderr,"Aw=%d Am=0x%02X\n",Aw,Am); + fprintf (stderr, "Aw=%d Am=0x%02X\n", Aw, Am); # endif #endif - for(i=0; i < ncolors; ++i) { - int r,g,b; - r=(i&Rmask)>>format->Rshift; - r=(r<Rloss)|((r*Rm)>>Rw); - format->palette->colors[i].r=r; + for (i = 0; i < ncolors; ++i) { + int r, g, b; + r = (i & Rmask) >> format->Rshift; + r = (r << format->Rloss) | ((r * Rm) >> Rw); + format->palette->colors[i].r = r; - g=(i&Gmask)>>format->Gshift; - g=(g<Gloss)|((g*Gm)>>Gw); - format->palette->colors[i].g=g; + g = (i & Gmask) >> format->Gshift; + g = (g << format->Gloss) | ((g * Gm) >> Gw); + format->palette->colors[i].g = g; - b=(i&Bmask)>>format->Bshift; - b=(b<Bloss)|((b*Bm)>>Bw); - format->palette->colors[i].b=b; + b = (i & Bmask) >> format->Bshift; + b = (b << format->Bloss) | ((b * Bm) >> Bw); + format->palette->colors[i].b = b; #ifdef ENABLE_PALETTE_ALPHA - a=(i&Amask)>>format->Ashift; - a=(a<Aloss)|((a*Am)>>Aw); - format->palette->colors[i].unused=a; + a = (i & Amask) >> format->Ashift; + a = (a << format->Aloss) | ((a * Am) >> Aw); + format->palette->colors[i].unused = a; #else - format->palette->colors[i].unused=0; + format->palette->colors[i].unused = 0; #endif - } - } else if ( ncolors == 2 ) { - /* Create a black and white bitmap palette */ - format->palette->colors[0].r = 0xFF; - format->palette->colors[0].g = 0xFF; - format->palette->colors[0].b = 0xFF; - format->palette->colors[1].r = 0x00; - format->palette->colors[1].g = 0x00; - format->palette->colors[1].b = 0x00; - } else { - /* Create an empty palette */ - SDL_memset((format->palette)->colors, 0, - (format->palette)->ncolors*sizeof(SDL_Color)); - } - } - return(format); + } + } else if (ncolors == 2) { + /* Create a black and white bitmap palette */ + format->palette->colors[0].r = 0xFF; + format->palette->colors[0].g = 0xFF; + format->palette->colors[0].b = 0xFF; + format->palette->colors[1].r = 0x00; + format->palette->colors[1].g = 0x00; + format->palette->colors[1].b = 0x00; + } else { + /* Create an empty palette */ + SDL_memset ((format->palette)->colors, 0, + (format->palette)->ncolors * sizeof (SDL_Color)); + } + } + return (format); } -SDL_PixelFormat *SDL_ReallocFormat(SDL_Surface *surface, int bpp, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) + +SDL_PixelFormat * +SDL_ReallocFormat (SDL_Surface * surface, int bpp, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) { - if ( surface->format ) { - SDL_FreeFormat(surface->format); - SDL_FormatChanged(surface); - } - surface->format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); - return surface->format; + if (surface->format) { + SDL_FreeFormat (surface->format); + SDL_FormatChanged (surface); + } + surface->format = SDL_AllocFormat (bpp, Rmask, Gmask, Bmask, Amask); + return surface->format; } /* * Change any previous mappings from/to the new surface format */ -void SDL_FormatChanged(SDL_Surface *surface) +void +SDL_FormatChanged (SDL_Surface * surface) { - static int format_version = 0; - ++format_version; - if ( format_version < 0 ) { /* It wrapped... */ - format_version = 1; - } - surface->format_version = format_version; - SDL_InvalidateMap(surface->map); + static int format_version = 0; + ++format_version; + if (format_version < 0) { /* It wrapped... */ + format_version = 1; + } + surface->format_version = format_version; + SDL_InvalidateMap (surface->map); } + /* * Free a previously allocated format structure */ -void SDL_FreeFormat(SDL_PixelFormat *format) +void +SDL_FreeFormat (SDL_PixelFormat * format) { - if ( format ) { - if ( format->palette ) { - if ( format->palette->colors ) { - SDL_free(format->palette->colors); - } - SDL_free(format->palette); - } - SDL_free(format); - } + if (format) { + if (format->palette) { + if (format->palette->colors) { + SDL_free (format->palette->colors); + } + SDL_free (format->palette); + } + SDL_free (format); + } } + /* * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors */ -void SDL_DitherColors(SDL_Color *colors, int bpp) +void +SDL_DitherColors (SDL_Color * colors, int bpp) { - int i; - if(bpp != 8) - return; /* only 8bpp supported right now */ - - for(i = 0; i < 256; i++) { - int r, g, b; - /* map each bit field to the full [0, 255] interval, - so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */ - r = i & 0xe0; - r |= r >> 3 | r >> 6; - colors[i].r = r; - g = (i << 3) & 0xe0; - g |= g >> 3 | g >> 6; - colors[i].g = g; - b = i & 0x3; - b |= b << 2; - b |= b << 4; - colors[i].b = b; - } + int i; + if (bpp != 8) + return; /* only 8bpp supported right now */ + + for (i = 0; i < 256; i++) { + int r, g, b; + /* map each bit field to the full [0, 255] interval, + so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */ + r = i & 0xe0; + r |= r >> 3 | r >> 6; + colors[i].r = r; + g = (i << 3) & 0xe0; + g |= g >> 3 | g >> 6; + colors[i].g = g; + b = i & 0x3; + b |= b << 2; + b |= b << 4; + colors[i].b = b; + } } + /* * Calculate the pad-aligned scanline width of a surface */ -Uint16 SDL_CalculatePitch(SDL_Surface *surface) +Uint16 +SDL_CalculatePitch (SDL_Surface * surface) { - Uint16 pitch; - - /* Surface should be 4-byte aligned for speed */ - pitch = surface->w*surface->format->BytesPerPixel; - switch (surface->format->BitsPerPixel) { - case 1: - pitch = (pitch+7)/8; - break; - case 4: - pitch = (pitch+1)/2; - break; - default: - break; - } - pitch = (pitch + 3) & ~3; /* 4-byte aligning */ - return(pitch); + Uint16 pitch; + + /* Surface should be 4-byte aligned for speed */ + pitch = surface->w * surface->format->BytesPerPixel; + switch (surface->format->BitsPerPixel) { + case 1: + pitch = (pitch + 7) / 8; + break; + case 4: + pitch = (pitch + 1) / 2; + break; + default: + break; + } + pitch = (pitch + 3) & ~3; /* 4-byte aligning */ + return (pitch); } + /* * Match an RGB value to a particular palette index */ -Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b) +Uint8 +SDL_FindColor (SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) { - /* Do colorspace distance matching */ - unsigned int smallest; - unsigned int distance; - int rd, gd, bd; - int i; - Uint8 pixel=0; - - smallest = ~0; - for ( i=0; incolors; ++i ) { - rd = pal->colors[i].r - r; - gd = pal->colors[i].g - g; - bd = pal->colors[i].b - b; - distance = (rd*rd)+(gd*gd)+(bd*bd); - if ( distance < smallest ) { - pixel = i; - if ( distance == 0 ) { /* Perfect match! */ - break; - } - smallest = distance; - } - } - return(pixel); + /* Do colorspace distance matching */ + unsigned int smallest; + unsigned int distance; + int rd, gd, bd; + int i; + Uint8 pixel = 0; + + smallest = ~0; + for (i = 0; i < pal->ncolors; ++i) { + rd = pal->colors[i].r - r; + gd = pal->colors[i].g - g; + bd = pal->colors[i].b - b; + distance = (rd * rd) + (gd * gd) + (bd * bd); + if (distance < smallest) { + pixel = i; + if (distance == 0) { /* Perfect match! */ + break; + } + smallest = distance; + } + } + return (pixel); } /* Find the opaque pixel value corresponding to an RGB triple */ -Uint32 SDL_MapRGB(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b) +Uint32 +SDL_MapRGB (SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b) { - if ( format->palette == NULL ) { - return (r >> format->Rloss) << format->Rshift - | (g >> format->Gloss) << format->Gshift - | (b >> format->Bloss) << format->Bshift - | format->Amask; - } else { - return SDL_FindColor(format->palette, r, g, b); - } + if (format->palette == NULL) { + return (r >> format->Rloss) << format->Rshift + | (g >> format->Gloss) << format->Gshift + | (b >> format->Bloss) << format->Bshift | format->Amask; + } else { + return SDL_FindColor (format->palette, r, g, b); + } } /* Find the pixel value corresponding to an RGBA quadruple */ -Uint32 SDL_MapRGBA(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +Uint32 +SDL_MapRGBA (SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - if ( format->palette == NULL ) { - return (r >> format->Rloss) << format->Rshift - | (g >> format->Gloss) << format->Gshift - | (b >> format->Bloss) << format->Bshift - | ((a >> format->Aloss) << format->Ashift & format->Amask); - } else { - return SDL_FindColor(format->palette, r, g, b); - } + if (format->palette == NULL) { + return (r >> format->Rloss) << format->Rshift + | (g >> format->Gloss) << format->Gshift + | (b >> format->Bloss) << format->Bshift + | ((a >> format->Aloss) << format->Ashift & format->Amask); + } else { + return SDL_FindColor (format->palette, r, g, b); + } } -void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, - Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) +void +SDL_GetRGBA (Uint32 pixel, SDL_PixelFormat * fmt, + Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) { - if ( fmt->palette == NULL ) { - /* - * This makes sure that the result is mapped to the - * interval [0..255], and the maximum value for each - * component is 255. This is important to make sure - * that white is indeed reported as (255, 255, 255), - * and that opaque alpha is 255. - * This only works for RGB bit fields at least 4 bit - * wide, which is almost always the case. - */ - unsigned v; - v = (pixel & fmt->Rmask) >> fmt->Rshift; - *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); - v = (pixel & fmt->Gmask) >> fmt->Gshift; - *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); - v = (pixel & fmt->Bmask) >> fmt->Bshift; - *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); - if(fmt->Amask) { - v = (pixel & fmt->Amask) >> fmt->Ashift; - *a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1))); - } else { - *a = SDL_ALPHA_OPAQUE; - } - } else { - *r = fmt->palette->colors[pixel].r; - *g = fmt->palette->colors[pixel].g; - *b = fmt->palette->colors[pixel].b; - *a = SDL_ALPHA_OPAQUE; - } + if (fmt->palette == NULL) { + /* + * This makes sure that the result is mapped to the + * interval [0..255], and the maximum value for each + * component is 255. This is important to make sure + * that white is indeed reported as (255, 255, 255), + * and that opaque alpha is 255. + * This only works for RGB bit fields at least 4 bit + * wide, which is almost always the case. + */ + unsigned v; + v = (pixel & fmt->Rmask) >> fmt->Rshift; + *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); + v = (pixel & fmt->Gmask) >> fmt->Gshift; + *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); + v = (pixel & fmt->Bmask) >> fmt->Bshift; + *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); + if (fmt->Amask) { + v = (pixel & fmt->Amask) >> fmt->Ashift; + *a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1))); + } else { + *a = SDL_ALPHA_OPAQUE; + } + } else { + *r = fmt->palette->colors[pixel].r; + *g = fmt->palette->colors[pixel].g; + *b = fmt->palette->colors[pixel].b; + *a = SDL_ALPHA_OPAQUE; + } } -void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r,Uint8 *g,Uint8 *b) +void +SDL_GetRGB (Uint32 pixel, SDL_PixelFormat * fmt, Uint8 * r, Uint8 * g, + Uint8 * b) { - if ( fmt->palette == NULL ) { - /* the note for SDL_GetRGBA above applies here too */ - unsigned v; - v = (pixel & fmt->Rmask) >> fmt->Rshift; - *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); - v = (pixel & fmt->Gmask) >> fmt->Gshift; - *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); - v = (pixel & fmt->Bmask) >> fmt->Bshift; - *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); - } else { - *r = fmt->palette->colors[pixel].r; - *g = fmt->palette->colors[pixel].g; - *b = fmt->palette->colors[pixel].b; - } + if (fmt->palette == NULL) { + /* the note for SDL_GetRGBA above applies here too */ + unsigned v; + v = (pixel & fmt->Rmask) >> fmt->Rshift; + *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); + v = (pixel & fmt->Gmask) >> fmt->Gshift; + *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); + v = (pixel & fmt->Bmask) >> fmt->Bshift; + *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); + } else { + *r = fmt->palette->colors[pixel].r; + *g = fmt->palette->colors[pixel].g; + *b = fmt->palette->colors[pixel].b; + } } /* Apply gamma to a set of colors - this is easy. :) */ -void SDL_ApplyGamma(Uint16 *gamma, SDL_Color *colors, SDL_Color *output, - int ncolors) +void +SDL_ApplyGamma (Uint16 * gamma, SDL_Color * colors, SDL_Color * output, + int ncolors) { - int i; + int i; - for ( i=0; i> 8; - output[i].g = gamma[1*256 + colors[i].g] >> 8; - output[i].b = gamma[2*256 + colors[i].b] >> 8; - } + for (i = 0; i < ncolors; ++i) { + output[i].r = gamma[0 * 256 + colors[i].r] >> 8; + output[i].g = gamma[1 * 256 + colors[i].g] >> 8; + output[i].b = gamma[2 * 256 + colors[i].b] >> 8; + } } /* Map from Palette to Palette */ -static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical) +static Uint8 * +Map1to1 (SDL_Palette * src, SDL_Palette * dst, int *identical) { - Uint8 *map; - int i; - - if ( identical ) { - if ( src->ncolors <= dst->ncolors ) { - /* If an identical palette, no need to map */ - if ( SDL_memcmp(src->colors, dst->colors, src->ncolors* - sizeof(SDL_Color)) == 0 ) { - *identical = 1; - return(NULL); - } - } - *identical = 0; - } - map = (Uint8 *)SDL_malloc(src->ncolors); - if ( map == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - for ( i=0; incolors; ++i ) { - map[i] = SDL_FindColor(dst, - src->colors[i].r, src->colors[i].g, src->colors[i].b); - } - return(map); + Uint8 *map; + int i; + + if (identical) { + if (src->ncolors <= dst->ncolors) { + /* If an identical palette, no need to map */ + if (SDL_memcmp (src->colors, dst->colors, src->ncolors * + sizeof (SDL_Color)) == 0) { + *identical = 1; + return (NULL); + } + } + *identical = 0; + } + map = (Uint8 *) SDL_malloc (src->ncolors); + if (map == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + for (i = 0; i < src->ncolors; ++i) { + map[i] = SDL_FindColor (dst, + src->colors[i].r, src->colors[i].g, + src->colors[i].b); + } + return (map); } + /* Map from Palette to BitField */ -static Uint8 *Map1toN(SDL_PixelFormat *src, SDL_PixelFormat *dst) +static Uint8 * +Map1toN (SDL_PixelFormat * src, SDL_PixelFormat * dst) { - Uint8 *map; - int i; - int bpp; - unsigned alpha; - SDL_Palette *pal = src->palette; - - bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); - map = (Uint8 *)SDL_malloc(pal->ncolors*bpp); - if ( map == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - - alpha = dst->Amask ? src->alpha : 0; - /* We memory copy to the pixel map so the endianness is preserved */ - for ( i=0; incolors; ++i ) { - ASSEMBLE_RGBA(&map[i*bpp], dst->BytesPerPixel, dst, - pal->colors[i].r, pal->colors[i].g, - pal->colors[i].b, alpha); - } - return(map); + Uint8 *map; + int i; + int bpp; + unsigned alpha; + SDL_Palette *pal = src->palette; + + bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); + map = (Uint8 *) SDL_malloc (pal->ncolors * bpp); + if (map == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + + alpha = dst->Amask ? src->alpha : 0; + /* We memory copy to the pixel map so the endianness is preserved */ + for (i = 0; i < pal->ncolors; ++i) { + ASSEMBLE_RGBA (&map[i * bpp], dst->BytesPerPixel, dst, + pal->colors[i].r, pal->colors[i].g, + pal->colors[i].b, alpha); + } + return (map); } + /* Map from BitField to Dithered-Palette to Palette */ -static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical) +static Uint8 * +MapNto1 (SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical) { - /* Generate a 256 color dither palette */ - SDL_Palette dithered; - SDL_Color colors[256]; - SDL_Palette *pal = dst->palette; - - /* SDL_DitherColors does not initialize the 'unused' component of colors, - but Map1to1 compares it against pal, so we should initialize it. */ - SDL_memset(colors, 0, sizeof(colors)); - - dithered.ncolors = 256; - SDL_DitherColors(colors, 8); - dithered.colors = colors; - return(Map1to1(&dithered, pal, identical)); + /* Generate a 256 color dither palette */ + SDL_Palette dithered; + SDL_Color colors[256]; + SDL_Palette *pal = dst->palette; + + /* SDL_DitherColors does not initialize the 'unused' component of colors, + but Map1to1 compares it against pal, so we should initialize it. */ + SDL_memset (colors, 0, sizeof (colors)); + + dithered.ncolors = 256; + SDL_DitherColors (colors, 8); + dithered.colors = colors; + return (Map1to1 (&dithered, pal, identical)); } -SDL_BlitMap *SDL_AllocBlitMap(void) +SDL_BlitMap * +SDL_AllocBlitMap (void) { - SDL_BlitMap *map; - - /* Allocate the empty map */ - map = (SDL_BlitMap *)SDL_malloc(sizeof(*map)); - if ( map == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - SDL_memset(map, 0, sizeof(*map)); - - /* Allocate the software blit data */ - map->sw_data = (struct private_swaccel *)SDL_malloc(sizeof(*map->sw_data)); - if ( map->sw_data == NULL ) { - SDL_FreeBlitMap(map); - SDL_OutOfMemory(); - return(NULL); - } - SDL_memset(map->sw_data, 0, sizeof(*map->sw_data)); - - /* It's ready to go */ - return(map); + SDL_BlitMap *map; + + /* Allocate the empty map */ + map = (SDL_BlitMap *) SDL_malloc (sizeof (*map)); + if (map == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + SDL_memset (map, 0, sizeof (*map)); + + /* Allocate the software blit data */ + map->sw_data = + (struct private_swaccel *) SDL_malloc (sizeof (*map->sw_data)); + if (map->sw_data == NULL) { + SDL_FreeBlitMap (map); + SDL_OutOfMemory (); + return (NULL); + } + SDL_memset (map->sw_data, 0, sizeof (*map->sw_data)); + + /* It's ready to go */ + return (map); } -void SDL_InvalidateMap(SDL_BlitMap *map) + +void +SDL_InvalidateMap (SDL_BlitMap * map) { - if ( ! map ) { - return; - } - map->dst = NULL; - map->format_version = (unsigned int)-1; - if ( map->table ) { - SDL_free(map->table); - map->table = NULL; - } + if (!map) { + return; + } + map->dst = NULL; + map->format_version = (unsigned int) -1; + if (map->table) { + SDL_free (map->table); + map->table = NULL; + } } -int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst) +int +SDL_MapSurface (SDL_Surface * src, SDL_Surface * dst) { - SDL_PixelFormat *srcfmt; - SDL_PixelFormat *dstfmt; - SDL_BlitMap *map; - - /* Clear out any previous mapping */ - map = src->map; - if ( (src->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { - SDL_UnRLESurface(src, 1); - } - SDL_InvalidateMap(map); - - /* Figure out what kind of mapping we're doing */ - map->identity = 0; - srcfmt = src->format; - dstfmt = dst->format; - switch (srcfmt->BytesPerPixel) { - case 1: - switch (dstfmt->BytesPerPixel) { - case 1: - /* Palette --> Palette */ - /* If both SDL_HWSURFACE, assume have same palette */ - if ( ((src->flags & SDL_HWSURFACE) == SDL_HWSURFACE) && - ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) ) { - map->identity = 1; - } else { - map->table = Map1to1(srcfmt->palette, - dstfmt->palette, &map->identity); - } - if ( ! map->identity ) { - if ( map->table == NULL ) { - return(-1); - } - } - if (srcfmt->BitsPerPixel!=dstfmt->BitsPerPixel) - map->identity = 0; - break; - - default: - /* Palette --> BitField */ - map->table = Map1toN(srcfmt, dstfmt); - if ( map->table == NULL ) { - return(-1); - } - break; - } - break; - default: - switch (dstfmt->BytesPerPixel) { - case 1: - /* BitField --> Palette */ - map->table = MapNto1(srcfmt, dstfmt, &map->identity); - if ( ! map->identity ) { - if ( map->table == NULL ) { - return(-1); - } - } - map->identity = 0; /* Don't optimize to copy */ - break; - default: - /* BitField --> BitField */ - if ( FORMAT_EQUAL(srcfmt, dstfmt) ) - map->identity = 1; - break; - } - break; - } - - map->dst = dst; - map->format_version = dst->format_version; - - /* Choose your blitters wisely */ - return(SDL_CalculateBlit(src)); + SDL_PixelFormat *srcfmt; + SDL_PixelFormat *dstfmt; + SDL_BlitMap *map; + + /* Clear out any previous mapping */ + map = src->map; + if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + SDL_UnRLESurface (src, 1); + } + SDL_InvalidateMap (map); + + /* Figure out what kind of mapping we're doing */ + map->identity = 0; + srcfmt = src->format; + dstfmt = dst->format; + switch (srcfmt->BytesPerPixel) { + case 1: + switch (dstfmt->BytesPerPixel) { + case 1: + /* Palette --> Palette */ + /* If both SDL_HWSURFACE, assume have same palette */ + if (((src->flags & SDL_HWSURFACE) == SDL_HWSURFACE) && + ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE)) { + map->identity = 1; + } else { + map->table = Map1to1 (srcfmt->palette, + dstfmt->palette, &map->identity); + } + if (!map->identity) { + if (map->table == NULL) { + return (-1); + } + } + if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel) + map->identity = 0; + break; + + default: + /* Palette --> BitField */ + map->table = Map1toN (srcfmt, dstfmt); + if (map->table == NULL) { + return (-1); + } + break; + } + break; + default: + switch (dstfmt->BytesPerPixel) { + case 1: + /* BitField --> Palette */ + map->table = MapNto1 (srcfmt, dstfmt, &map->identity); + if (!map->identity) { + if (map->table == NULL) { + return (-1); + } + } + map->identity = 0; /* Don't optimize to copy */ + break; + default: + /* BitField --> BitField */ + if (FORMAT_EQUAL (srcfmt, dstfmt)) + map->identity = 1; + break; + } + break; + } + + map->dst = dst; + map->format_version = dst->format_version; + + /* Choose your blitters wisely */ + return (SDL_CalculateBlit (src)); } -void SDL_FreeBlitMap(SDL_BlitMap *map) + +void +SDL_FreeBlitMap (SDL_BlitMap * map) { - if ( map ) { - SDL_InvalidateMap(map); - if ( map->sw_data != NULL ) { - SDL_free(map->sw_data); - } - SDL_free(map); - } + if (map) { + SDL_InvalidateMap (map); + if (map->sw_data != NULL) { + SDL_free (map->sw_data); + } + SDL_free (map); + } } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_pixels_c.h b/src/video/SDL_pixels_c.h index 6ab56b173..53314cab7 100644 --- a/src/video/SDL_pixels_c.h +++ b/src/video/SDL_pixels_c.h @@ -26,21 +26,25 @@ #include "SDL_blit.h" /* Pixel format functions */ -extern SDL_PixelFormat *SDL_AllocFormat(int bpp, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); -extern SDL_PixelFormat *SDL_ReallocFormat(SDL_Surface *surface, int bpp, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); -extern void SDL_FormatChanged(SDL_Surface *surface); -extern void SDL_FreeFormat(SDL_PixelFormat *format); +extern SDL_PixelFormat *SDL_AllocFormat (int bpp, + Uint32 Rmask, Uint32 Gmask, + Uint32 Bmask, Uint32 Amask); +extern SDL_PixelFormat *SDL_ReallocFormat (SDL_Surface * surface, int bpp, + Uint32 Rmask, Uint32 Gmask, + Uint32 Bmask, Uint32 Amask); +extern void SDL_FormatChanged (SDL_Surface * surface); +extern void SDL_FreeFormat (SDL_PixelFormat * format); /* Blit mapping functions */ -extern SDL_BlitMap *SDL_AllocBlitMap(void); -extern void SDL_InvalidateMap(SDL_BlitMap *map); -extern int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst); -extern void SDL_FreeBlitMap(SDL_BlitMap *map); +extern SDL_BlitMap *SDL_AllocBlitMap (void); +extern void SDL_InvalidateMap (SDL_BlitMap * map); +extern int SDL_MapSurface (SDL_Surface * src, SDL_Surface * dst); +extern void SDL_FreeBlitMap (SDL_BlitMap * map); /* Miscellaneous functions */ -extern Uint16 SDL_CalculatePitch(SDL_Surface *surface); -extern void SDL_DitherColors(SDL_Color *colors, int bpp); -extern Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b); -extern void SDL_ApplyGamma(Uint16 *gamma, SDL_Color *colors, SDL_Color *output, int ncolors); +extern Uint16 SDL_CalculatePitch (SDL_Surface * surface); +extern void SDL_DitherColors (SDL_Color * colors, int bpp); +extern Uint8 SDL_FindColor (SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b); +extern void SDL_ApplyGamma (Uint16 * gamma, SDL_Color * colors, + SDL_Color * output, int ncolors); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_stretch.c b/src/video/SDL_stretch.c index 843a0ab0e..e4b8a8449 100644 --- a/src/video/SDL_stretch.c +++ b/src/video/SDL_stretch.c @@ -55,67 +55,68 @@ static unsigned char copy_row[4096]; -static int generate_rowbytes(int src_w, int dst_w, int bpp) +static int +generate_rowbytes (int src_w, int dst_w, int bpp) { - static struct { - int bpp; - int src_w; - int dst_w; - } last; - - int i; - int pos, inc; - unsigned char *eip; - unsigned char load, store; - - /* See if we need to regenerate the copy buffer */ - if ( (src_w == last.src_w) && - (dst_w == last.dst_w) && (bpp == last.bpp) ) { - return(0); - } - last.bpp = bpp; - last.src_w = src_w; - last.dst_w = dst_w; - - switch (bpp) { - case 1: - load = LOAD_BYTE; - store = STORE_BYTE; - break; - case 2: - case 4: - load = LOAD_WORD; - store = STORE_WORD; - break; - default: - SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); - return(-1); - } - pos = 0x10000; - inc = (src_w << 16) / dst_w; - eip = copy_row; - for ( i=0; i= 0x10000L ) { - if ( bpp == 2 ) { - *eip++ = PREFIX16; - } - *eip++ = load; - pos -= 0x10000L; - } - if ( bpp == 2 ) { - *eip++ = PREFIX16; - } - *eip++ = store; - pos += inc; - } - *eip++ = RETURN; - - /* Verify that we didn't overflow (too late) */ - if ( eip > (copy_row+sizeof(copy_row)) ) { - SDL_SetError("Copy buffer overflow"); - return(-1); - } - return(0); + static struct + { + int bpp; + int src_w; + int dst_w; + } last; + + int i; + int pos, inc; + unsigned char *eip; + unsigned char load, store; + + /* See if we need to regenerate the copy buffer */ + if ((src_w == last.src_w) && (dst_w == last.dst_w) && (bpp == last.bpp)) { + return (0); + } + last.bpp = bpp; + last.src_w = src_w; + last.dst_w = dst_w; + + switch (bpp) { + case 1: + load = LOAD_BYTE; + store = STORE_BYTE; + break; + case 2: + case 4: + load = LOAD_WORD; + store = STORE_WORD; + break; + default: + SDL_SetError ("ASM stretch of %d bytes isn't supported\n", bpp); + return (-1); + } + pos = 0x10000; + inc = (src_w << 16) / dst_w; + eip = copy_row; + for (i = 0; i < dst_w; ++i) { + while (pos >= 0x10000L) { + if (bpp == 2) { + *eip++ = PREFIX16; + } + *eip++ = load; + pos -= 0x10000L; + } + if (bpp == 2) { + *eip++ = PREFIX16; + } + *eip++ = store; + pos += inc; + } + *eip++ = RETURN; + + /* Verify that we didn't overflow (too late) */ + if (eip > (copy_row + sizeof (copy_row))) { + SDL_SetError ("Copy buffer overflow"); + return (-1); + } + return (0); } #else @@ -138,197 +139,187 @@ void name(type *src, int src_w, type *dst, int dst_w) \ pos += inc; \ } \ } -DEFINE_COPY_ROW(copy_row1, Uint8) -DEFINE_COPY_ROW(copy_row2, Uint16) -DEFINE_COPY_ROW(copy_row4, Uint32) - +DEFINE_COPY_ROW (copy_row1, Uint8) + DEFINE_COPY_ROW (copy_row2, Uint16) DEFINE_COPY_ROW (copy_row4, Uint32) #endif /* USE_ASM_STRETCH */ - /* The ASM code doesn't handle 24-bpp stretch blits */ -void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w) + void + copy_row3 (Uint8 * src, int src_w, Uint8 * dst, int dst_w) { - int i; - int pos, inc; - Uint8 pixel[3]; - - pos = 0x10000; - inc = (src_w << 16) / dst_w; - for ( i=dst_w; i>0; --i ) { - while ( pos >= 0x10000L ) { - pixel[0] = *src++; - pixel[1] = *src++; - pixel[2] = *src++; - pos -= 0x10000L; - } - *dst++ = pixel[0]; - *dst++ = pixel[1]; - *dst++ = pixel[2]; - pos += inc; - } + int i; + int pos, inc; + Uint8 pixel[3]; + + pos = 0x10000; + inc = (src_w << 16) / dst_w; + for (i = dst_w; i > 0; --i) { + while (pos >= 0x10000L) { + pixel[0] = *src++; + pixel[1] = *src++; + pixel[2] = *src++; + pos -= 0x10000L; + } + *dst++ = pixel[0]; + *dst++ = pixel[1]; + *dst++ = pixel[2]; + pos += inc; + } } /* Perform a stretch blit between two surfaces of the same format. NOTE: This function is not safe to call from multiple threads! */ -int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) +int +SDL_SoftStretch (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect) { - int src_locked; - int dst_locked; - int pos, inc; - int dst_width; - int dst_maxrow; - int src_row, dst_row; - Uint8 *srcp = NULL; - Uint8 *dstp; - SDL_Rect full_src; - SDL_Rect full_dst; + int src_locked; + int dst_locked; + int pos, inc; + int dst_width; + int dst_maxrow; + int src_row, dst_row; + Uint8 *srcp = NULL; + Uint8 *dstp; + SDL_Rect full_src; + SDL_Rect full_dst; #if defined(USE_ASM_STRETCH) && defined(__GNUC__) - int u1, u2; + int u1, u2; #endif - const int bpp = dst->format->BytesPerPixel; - - if ( src->format->BitsPerPixel != dst->format->BitsPerPixel ) { - SDL_SetError("Only works with same format surfaces"); - return(-1); - } - - /* Verify the blit rectangles */ - if ( srcrect ) { - if ( (srcrect->x < 0) || (srcrect->y < 0) || - ((srcrect->x+srcrect->w) > src->w) || - ((srcrect->y+srcrect->h) > src->h) ) { - SDL_SetError("Invalid source blit rectangle"); - return(-1); - } - } else { - full_src.x = 0; - full_src.y = 0; - full_src.w = src->w; - full_src.h = src->h; - srcrect = &full_src; - } - if ( dstrect ) { - if ( (dstrect->x < 0) || (dstrect->y < 0) || - ((dstrect->x+dstrect->w) > dst->w) || - ((dstrect->y+dstrect->h) > dst->h) ) { - SDL_SetError("Invalid destination blit rectangle"); - return(-1); - } - } else { - full_dst.x = 0; - full_dst.y = 0; - full_dst.w = dst->w; - full_dst.h = dst->h; - dstrect = &full_dst; - } - - /* Lock the destination if it's in hardware */ - dst_locked = 0; - if ( SDL_MUSTLOCK(dst) ) { - if ( SDL_LockSurface(dst) < 0 ) { - SDL_SetError("Unable to lock destination surface"); - return(-1); - } - dst_locked = 1; - } - /* Lock the source if it's in hardware */ - src_locked = 0; - if ( SDL_MUSTLOCK(src) ) { - if ( SDL_LockSurface(src) < 0 ) { - if ( dst_locked ) { - SDL_UnlockSurface(dst); - } - SDL_SetError("Unable to lock source surface"); - return(-1); - } - src_locked = 1; - } - - /* Set up the data... */ - pos = 0x10000; - inc = (srcrect->h << 16) / dstrect->h; - src_row = srcrect->y; - dst_row = dstrect->y; - dst_width = dstrect->w*bpp; + const int bpp = dst->format->BytesPerPixel; + + if (src->format->BitsPerPixel != dst->format->BitsPerPixel) { + SDL_SetError ("Only works with same format surfaces"); + return (-1); + } + + /* Verify the blit rectangles */ + if (srcrect) { + if ((srcrect->x < 0) || (srcrect->y < 0) || + ((srcrect->x + srcrect->w) > src->w) || + ((srcrect->y + srcrect->h) > src->h)) { + SDL_SetError ("Invalid source blit rectangle"); + return (-1); + } + } else { + full_src.x = 0; + full_src.y = 0; + full_src.w = src->w; + full_src.h = src->h; + srcrect = &full_src; + } + if (dstrect) { + if ((dstrect->x < 0) || (dstrect->y < 0) || + ((dstrect->x + dstrect->w) > dst->w) || + ((dstrect->y + dstrect->h) > dst->h)) { + SDL_SetError ("Invalid destination blit rectangle"); + return (-1); + } + } else { + full_dst.x = 0; + full_dst.y = 0; + full_dst.w = dst->w; + full_dst.h = dst->h; + dstrect = &full_dst; + } + + /* Lock the destination if it's in hardware */ + dst_locked = 0; + if (SDL_MUSTLOCK (dst)) { + if (SDL_LockSurface (dst) < 0) { + SDL_SetError ("Unable to lock destination surface"); + return (-1); + } + dst_locked = 1; + } + /* Lock the source if it's in hardware */ + src_locked = 0; + if (SDL_MUSTLOCK (src)) { + if (SDL_LockSurface (src) < 0) { + if (dst_locked) { + SDL_UnlockSurface (dst); + } + SDL_SetError ("Unable to lock source surface"); + return (-1); + } + src_locked = 1; + } + + /* Set up the data... */ + pos = 0x10000; + inc = (srcrect->h << 16) / dstrect->h; + src_row = srcrect->y; + dst_row = dstrect->y; + dst_width = dstrect->w * bpp; #ifdef USE_ASM_STRETCH - /* Write the opcodes for this stretch */ - if ( (bpp != 3) && - (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0) ) { - return(-1); - } + /* Write the opcodes for this stretch */ + if ((bpp != 3) && (generate_rowbytes (srcrect->w, dstrect->w, bpp) < 0)) { + return (-1); + } #endif - /* Perform the stretch blit */ - for ( dst_maxrow = dst_row+dstrect->h; dst_rowpixels + (dst_row*dst->pitch) - + (dstrect->x*bpp); - while ( pos >= 0x10000L ) { - srcp = (Uint8 *)src->pixels + (src_row*src->pitch) - + (srcrect->x*bpp); - ++src_row; - pos -= 0x10000L; - } + /* Perform the stretch blit */ + for (dst_maxrow = dst_row + dstrect->h; dst_row < dst_maxrow; ++dst_row) { + dstp = (Uint8 *) dst->pixels + (dst_row * dst->pitch) + + (dstrect->x * bpp); + while (pos >= 0x10000L) { + srcp = (Uint8 *) src->pixels + (src_row * src->pitch) + + (srcrect->x * bpp); + ++src_row; + pos -= 0x10000L; + } #ifdef USE_ASM_STRETCH - switch (bpp) { - case 3: - copy_row3(srcp, srcrect->w, dstp, dstrect->w); - break; - default: + switch (bpp) { + case 3: + copy_row3 (srcp, srcrect->w, dstp, dstrect->w); + break; + default: #ifdef __GNUC__ - __asm__ __volatile__ ( - "call *%4" - : "=&D" (u1), "=&S" (u2) - : "0" (dstp), "1" (srcp), "r" (copy_row) - : "memory" ); + __asm__ __volatile__ ("call *%4": "=&D" (u1), "=&S" (u2): "0" (dstp), "1" (srcp), "r" (copy_row):"memory"); #elif defined(_MSC_VER) || defined(__WATCOMC__) - { void *code = copy_row; - __asm { - push edi - push esi - - mov edi, dstp - mov esi, srcp - call dword ptr code - - pop esi - pop edi - } - } + { + void *code = copy_row; + __asm { + push edi + push esi + mov edi, dstp + mov esi, srcp call dword ptr code pop esi pop edi} + } #else #error Need inline assembly for this compiler #endif - break; - } + break; + } #else - switch (bpp) { - case 1: - copy_row1(srcp, srcrect->w, dstp, dstrect->w); - break; - case 2: - copy_row2((Uint16 *)srcp, srcrect->w, - (Uint16 *)dstp, dstrect->w); - break; - case 3: - copy_row3(srcp, srcrect->w, dstp, dstrect->w); - break; - case 4: - copy_row4((Uint32 *)srcp, srcrect->w, - (Uint32 *)dstp, dstrect->w); - break; - } + switch (bpp) { + case 1: + copy_row1 (srcp, srcrect->w, dstp, dstrect->w); + break; + case 2: + copy_row2 ((Uint16 *) srcp, srcrect->w, + (Uint16 *) dstp, dstrect->w); + break; + case 3: + copy_row3 (srcp, srcrect->w, dstp, dstrect->w); + break; + case 4: + copy_row4 ((Uint32 *) srcp, srcrect->w, + (Uint32 *) dstp, dstrect->w); + break; + } #endif - pos += inc; - } - - /* We need to unlock the surfaces if they're locked */ - if ( dst_locked ) { - SDL_UnlockSurface(dst); - } - if ( src_locked ) { - SDL_UnlockSurface(src); - } - return(0); + pos += inc; + } + + /* We need to unlock the surfaces if they're locked */ + if (dst_locked) { + SDL_UnlockSurface (dst); + } + if (src_locked) { + SDL_UnlockSurface (src); + } + return (0); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_stretch_c.h b/src/video/SDL_stretch_c.h index ee06b264f..e20a1d0ac 100644 --- a/src/video/SDL_stretch_c.h +++ b/src/video/SDL_stretch_c.h @@ -24,6 +24,6 @@ /* Perform a stretch blit between two surfaces of the same format. NOTE: This function is not safe to call from multiple threads! */ -extern int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); - +extern int SDL_SoftStretch (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 7ef8565cb..f94891777 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -34,365 +34,373 @@ /* * Create an empty RGB surface of the appropriate depth */ -SDL_Surface * SDL_CreateRGBSurface (Uint32 flags, - int width, int height, int depth, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) +SDL_Surface * +SDL_CreateRGBSurface (Uint32 flags, + int width, int height, int depth, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - SDL_Surface *screen; - SDL_Surface *surface; - - /* Make sure the size requested doesn't overflow our datatypes */ - /* Next time I write a library like SDL, I'll use int for size. :) */ - if ( width >= 16384 || height >= 65536 ) { - SDL_SetError("Width or height is too large"); - return(NULL); - } - - /* Check to see if we desire the surface in video memory */ - if ( video ) { - screen = SDL_PublicSurface; - } else { - screen = NULL; - } - if ( screen && ((screen->flags&SDL_HWSURFACE) == SDL_HWSURFACE) ) { - if ( (flags&(SDL_SRCCOLORKEY|SDL_SRCALPHA)) != 0 ) { - flags |= SDL_HWSURFACE; - } - if ( (flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { - if ( ! current_video->info.blit_hw_CC ) { - flags &= ~SDL_HWSURFACE; - } - } - if ( (flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { - if ( ! current_video->info.blit_hw_A ) { - flags &= ~SDL_HWSURFACE; - } - } - } else { - flags &= ~SDL_HWSURFACE; - } - - /* Allocate the surface */ - surface = (SDL_Surface *)SDL_malloc(sizeof(*surface)); - if ( surface == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - surface->flags = SDL_SWSURFACE; - if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { - if ((Amask) && (video->displayformatalphapixel)) - { - depth = video->displayformatalphapixel->BitsPerPixel; - Rmask = video->displayformatalphapixel->Rmask; - Gmask = video->displayformatalphapixel->Gmask; - Bmask = video->displayformatalphapixel->Bmask; - Amask = video->displayformatalphapixel->Amask; - } - else - { - depth = screen->format->BitsPerPixel; - Rmask = screen->format->Rmask; - Gmask = screen->format->Gmask; - Bmask = screen->format->Bmask; - Amask = screen->format->Amask; - } - } - surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask); - if ( surface->format == NULL ) { - SDL_free(surface); - return(NULL); - } - if ( Amask ) { - surface->flags |= SDL_SRCALPHA; - } - surface->w = width; - surface->h = height; - surface->pitch = SDL_CalculatePitch(surface); - surface->pixels = NULL; - surface->offset = 0; - surface->hwdata = NULL; - surface->locked = 0; - surface->map = NULL; - surface->unused1 = 0; - SDL_SetClipRect(surface, NULL); - SDL_FormatChanged(surface); - - /* Get the pixels */ - if ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) || - (video->AllocHWSurface(this, surface) < 0) ) { - if ( surface->w && surface->h ) { - surface->pixels = SDL_malloc(surface->h*surface->pitch); - if ( surface->pixels == NULL ) { - SDL_FreeSurface(surface); - SDL_OutOfMemory(); - return(NULL); - } - /* This is important for bitmaps */ - SDL_memset(surface->pixels, 0, surface->h*surface->pitch); - } - } - - /* Allocate an empty mapping */ - surface->map = SDL_AllocBlitMap(); - if ( surface->map == NULL ) { - SDL_FreeSurface(surface); - return(NULL); - } - - /* The surface is ready to go */ - surface->refcount = 1; + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Surface *screen; + SDL_Surface *surface; + + /* Make sure the size requested doesn't overflow our datatypes */ + /* Next time I write a library like SDL, I'll use int for size. :) */ + if (width >= 16384 || height >= 65536) { + SDL_SetError ("Width or height is too large"); + return (NULL); + } + + /* Check to see if we desire the surface in video memory */ + if (_this) { + screen = SDL_PublicSurface; + } else { + screen = NULL; + } + if (screen && ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE)) { + if ((flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA)) != 0) { + flags |= SDL_HWSURFACE; + } + if ((flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { + if (!_this->info.blit_hw_CC) { + flags &= ~SDL_HWSURFACE; + } + } + if ((flags & SDL_SRCALPHA) == SDL_SRCALPHA) { + if (!_this->info.blit_hw_A) { + flags &= ~SDL_HWSURFACE; + } + } + } else { + flags &= ~SDL_HWSURFACE; + } + + /* Allocate the surface */ + surface = (SDL_Surface *) SDL_malloc (sizeof (*surface)); + if (surface == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + surface->flags = SDL_SWSURFACE; + if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) { + if ((Amask) && (_this->displayformatalphapixel)) { + depth = _this->displayformatalphapixel->BitsPerPixel; + Rmask = _this->displayformatalphapixel->Rmask; + Gmask = _this->displayformatalphapixel->Gmask; + Bmask = _this->displayformatalphapixel->Bmask; + Amask = _this->displayformatalphapixel->Amask; + } else { + depth = screen->format->BitsPerPixel; + Rmask = screen->format->Rmask; + Gmask = screen->format->Gmask; + Bmask = screen->format->Bmask; + Amask = screen->format->Amask; + } + } + surface->format = SDL_AllocFormat (depth, Rmask, Gmask, Bmask, Amask); + if (surface->format == NULL) { + SDL_free (surface); + return (NULL); + } + if (Amask) { + surface->flags |= SDL_SRCALPHA; + } + surface->w = width; + surface->h = height; + surface->pitch = SDL_CalculatePitch (surface); + surface->pixels = NULL; + surface->offset = 0; + surface->hwdata = NULL; + surface->locked = 0; + surface->map = NULL; + surface->unused1 = 0; + SDL_SetClipRect (surface, NULL); + SDL_FormatChanged (surface); + + /* Get the pixels */ + if (((flags & SDL_HWSURFACE) == SDL_SWSURFACE) || + (_this->AllocHWSurface (_this, surface) < 0)) { + if (surface->w && surface->h) { + surface->pixels = SDL_malloc (surface->h * surface->pitch); + if (surface->pixels == NULL) { + SDL_FreeSurface (surface); + SDL_OutOfMemory (); + return (NULL); + } + /* This is important for bitmaps */ + SDL_memset (surface->pixels, 0, surface->h * surface->pitch); + } + } + + /* Allocate an empty mapping */ + surface->map = SDL_AllocBlitMap (); + if (surface->map == NULL) { + SDL_FreeSurface (surface); + return (NULL); + } + + /* The surface is ready to go */ + surface->refcount = 1; #ifdef CHECK_LEAKS - ++surfaces_allocated; + ++surfaces_allocated; #endif - return(surface); + return (surface); } + /* * Create an RGB surface from an existing memory buffer */ -SDL_Surface * SDL_CreateRGBSurfaceFrom (void *pixels, - int width, int height, int depth, int pitch, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) +SDL_Surface * +SDL_CreateRGBSurfaceFrom (void *pixels, + int width, int height, int depth, int pitch, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, + Uint32 Amask) { - SDL_Surface *surface; - - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, depth, - Rmask, Gmask, Bmask, Amask); - if ( surface != NULL ) { - surface->flags |= SDL_PREALLOC; - surface->pixels = pixels; - surface->w = width; - surface->h = height; - surface->pitch = pitch; - SDL_SetClipRect(surface, NULL); - } - return(surface); + SDL_Surface *surface; + + surface = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0, depth, + Rmask, Gmask, Bmask, Amask); + if (surface != NULL) { + surface->flags |= SDL_PREALLOC; + surface->pixels = pixels; + surface->w = width; + surface->h = height; + surface->pitch = pitch; + SDL_SetClipRect (surface, NULL); + } + return (surface); } + /* * Set the color key in a blittable surface */ -int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key) +int +SDL_SetColorKey (SDL_Surface * surface, Uint32 flag, Uint32 key) { - /* Sanity check the flag as it gets passed in */ - if ( flag & SDL_SRCCOLORKEY ) { - if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) { - flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK); - } else { - flag = SDL_SRCCOLORKEY; - } - } else { - flag = 0; - } - - /* Optimize away operations that don't change anything */ - if ( (flag == (surface->flags & (SDL_SRCCOLORKEY|SDL_RLEACCELOK))) && - (key == surface->format->colorkey) ) { - return(0); - } - - /* UnRLE surfaces before we change the colorkey */ - if ( surface->flags & SDL_RLEACCEL ) { - SDL_UnRLESurface(surface, 1); - } - - if ( flag ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - - surface->flags |= SDL_SRCCOLORKEY; - surface->format->colorkey = key; - if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) { - if ( (video->SetHWColorKey == NULL) || - (video->SetHWColorKey(this, surface, key) < 0) ) { - surface->flags &= ~SDL_HWACCEL; - } - } - if ( flag & SDL_RLEACCELOK ) { - surface->flags |= SDL_RLEACCELOK; - } else { - surface->flags &= ~SDL_RLEACCELOK; - } - } else { - surface->flags &= ~(SDL_SRCCOLORKEY|SDL_RLEACCELOK); - surface->format->colorkey = 0; - } - SDL_InvalidateMap(surface->map); - return(0); + /* Sanity check the flag as it gets passed in */ + if (flag & SDL_SRCCOLORKEY) { + if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) { + flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK); + } else { + flag = SDL_SRCCOLORKEY; + } + } else { + flag = 0; + } + + /* Optimize away operations that don't change anything */ + if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) && + (key == surface->format->colorkey)) { + return (0); + } + + /* UnRLE surfaces before we change the colorkey */ + if (surface->flags & SDL_RLEACCEL) { + SDL_UnRLESurface (surface, 1); + } + + if (flag) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + surface->flags |= SDL_SRCCOLORKEY; + surface->format->colorkey = key; + if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) { + if ((_this->SetHWColorKey == NULL) || + (_this->SetHWColorKey (_this, surface, key) < 0)) { + surface->flags &= ~SDL_HWACCEL; + } + } + if (flag & SDL_RLEACCELOK) { + surface->flags |= SDL_RLEACCELOK; + } else { + surface->flags &= ~SDL_RLEACCELOK; + } + } else { + surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK); + surface->format->colorkey = 0; + } + SDL_InvalidateMap (surface->map); + return (0); } + /* This function sets the alpha channel of a surface */ -int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value) +int +SDL_SetAlpha (SDL_Surface * surface, Uint32 flag, Uint8 value) { - Uint32 oldflags = surface->flags; - Uint32 oldalpha = surface->format->alpha; - - /* Sanity check the flag as it gets passed in */ - if ( flag & SDL_SRCALPHA ) { - if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) { - flag = (SDL_SRCALPHA | SDL_RLEACCELOK); - } else { - flag = SDL_SRCALPHA; - } - } else { - flag = 0; - } - - /* Optimize away operations that don't change anything */ - if ( (flag == (surface->flags & (SDL_SRCALPHA|SDL_RLEACCELOK))) && - (!flag || value == oldalpha) ) { - return(0); - } - - if(!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL)) - SDL_UnRLESurface(surface, 1); - - if ( flag ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - surface->flags |= SDL_SRCALPHA; - surface->format->alpha = value; - if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) { - if ( (video->SetHWAlpha == NULL) || - (video->SetHWAlpha(this, surface, value) < 0) ) { - surface->flags &= ~SDL_HWACCEL; - } - } - if ( flag & SDL_RLEACCELOK ) { - surface->flags |= SDL_RLEACCELOK; - } else { - surface->flags &= ~SDL_RLEACCELOK; - } - } else { - surface->flags &= ~SDL_SRCALPHA; - surface->format->alpha = SDL_ALPHA_OPAQUE; - } - /* - * The representation for software surfaces is independent of - * per-surface alpha, so no need to invalidate the blit mapping - * if just the alpha value was changed. (If either is 255, we still - * need to invalidate.) - */ - if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL - || oldflags != surface->flags - || (((oldalpha + 1) ^ (value + 1)) & 0x100)) - SDL_InvalidateMap(surface->map); - return(0); + Uint32 oldflags = surface->flags; + Uint32 oldalpha = surface->format->alpha; + + /* Sanity check the flag as it gets passed in */ + if (flag & SDL_SRCALPHA) { + if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) { + flag = (SDL_SRCALPHA | SDL_RLEACCELOK); + } else { + flag = SDL_SRCALPHA; + } + } else { + flag = 0; + } + + /* Optimize away operations that don't change anything */ + if ((flag == (surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK))) && + (!flag || value == oldalpha)) { + return (0); + } + + if (!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL)) + SDL_UnRLESurface (surface, 1); + + if (flag) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + surface->flags |= SDL_SRCALPHA; + surface->format->alpha = value; + if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) { + if ((_this->SetHWAlpha == NULL) || + (_this->SetHWAlpha (_this, surface, value) < 0)) { + surface->flags &= ~SDL_HWACCEL; + } + } + if (flag & SDL_RLEACCELOK) { + surface->flags |= SDL_RLEACCELOK; + } else { + surface->flags &= ~SDL_RLEACCELOK; + } + } else { + surface->flags &= ~SDL_SRCALPHA; + surface->format->alpha = SDL_ALPHA_OPAQUE; + } + /* + * The representation for software surfaces is independent of + * per-surface alpha, so no need to invalidate the blit mapping + * if just the alpha value was changed. (If either is 255, we still + * need to invalidate.) + */ + if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL + || oldflags != surface->flags + || (((oldalpha + 1) ^ (value + 1)) & 0x100)) + SDL_InvalidateMap (surface->map); + return (0); } -int SDL_SetAlphaChannel(SDL_Surface *surface, Uint8 value) -{ - int row, col; - int offset; - Uint8 *buf; - - if ( (surface->format->Amask != 0xFF000000) && - (surface->format->Amask != 0x000000FF) ) { - SDL_SetError("Unsupported surface alpha mask format"); - return -1; - } +int +SDL_SetAlphaChannel (SDL_Surface * surface, Uint8 value) +{ + int row, col; + int offset; + Uint8 *buf; + + if ((surface->format->Amask != 0xFF000000) && + (surface->format->Amask != 0x000000FF)) { + SDL_SetError ("Unsupported surface alpha mask format"); + return -1; + } #if SDL_BYTEORDER == SDL_LIL_ENDIAN - if ( surface->format->Amask == 0xFF000000 ) { - offset = 3; - } else { - offset = 0; - } + if (surface->format->Amask == 0xFF000000) { + offset = 3; + } else { + offset = 0; + } #else - if ( surface->format->Amask == 0xFF000000 ) { - offset = 0; - } else { - offset = 3; - } + if (surface->format->Amask == 0xFF000000) { + offset = 0; + } else { + offset = 3; + } #endif /* Byte ordering */ - /* Quickly set the alpha channel of an RGBA or ARGB surface */ - if ( SDL_MUSTLOCK(surface) ) { - if ( SDL_LockSurface(surface) < 0 ) { - return -1; - } - } - row = surface->h; - while (row--) { - col = surface->w; - buf = (Uint8 *)surface->pixels + row * surface->pitch + offset; - while(col--) { - *buf = value; - buf += 4; - } - } - if ( SDL_MUSTLOCK(surface) ) { - SDL_UnlockSurface(surface); - } - return 0; + /* Quickly set the alpha channel of an RGBA or ARGB surface */ + if (SDL_MUSTLOCK (surface)) { + if (SDL_LockSurface (surface) < 0) { + return -1; + } + } + row = surface->h; + while (row--) { + col = surface->w; + buf = (Uint8 *) surface->pixels + row * surface->pitch + offset; + while (col--) { + *buf = value; + buf += 4; + } + } + if (SDL_MUSTLOCK (surface)) { + SDL_UnlockSurface (surface); + } + return 0; } /* * A function to calculate the intersection of two rectangles: * return true if the rectangles intersect, false otherwise */ -static __inline__ -SDL_bool SDL_IntersectRect(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *intersection) +static __inline__ SDL_bool +SDL_IntersectRect (const SDL_Rect * A, const SDL_Rect * B, + SDL_Rect * intersection) { - int Amin, Amax, Bmin, Bmax; - - /* Horizontal intersection */ - Amin = A->x; - Amax = Amin + A->w; - Bmin = B->x; - Bmax = Bmin + B->w; - if(Bmin > Amin) - Amin = Bmin; - intersection->x = Amin; - if(Bmax < Amax) - Amax = Bmax; - intersection->w = Amax - Amin > 0 ? Amax - Amin : 0; - - /* Vertical intersection */ - Amin = A->y; - Amax = Amin + A->h; - Bmin = B->y; - Bmax = Bmin + B->h; - if(Bmin > Amin) - Amin = Bmin; - intersection->y = Amin; - if(Bmax < Amax) - Amax = Bmax; - intersection->h = Amax - Amin > 0 ? Amax - Amin : 0; - - return (intersection->w && intersection->h); + int Amin, Amax, Bmin, Bmax; + + /* Horizontal intersection */ + Amin = A->x; + Amax = Amin + A->w; + Bmin = B->x; + Bmax = Bmin + B->w; + if (Bmin > Amin) + Amin = Bmin; + intersection->x = Amin; + if (Bmax < Amax) + Amax = Bmax; + intersection->w = Amax - Amin > 0 ? Amax - Amin : 0; + + /* Vertical intersection */ + Amin = A->y; + Amax = Amin + A->h; + Bmin = B->y; + Bmax = Bmin + B->h; + if (Bmin > Amin) + Amin = Bmin; + intersection->y = Amin; + if (Bmax < Amax) + Amax = Bmax; + intersection->h = Amax - Amin > 0 ? Amax - Amin : 0; + + return (intersection->w && intersection->h); } + /* * Set the clipping rectangle for a blittable surface */ -SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect) +SDL_bool +SDL_SetClipRect (SDL_Surface * surface, const SDL_Rect * rect) { - SDL_Rect full_rect; - - /* Don't do anything if there's no surface to act on */ - if ( ! surface ) { - return SDL_FALSE; - } - - /* Set up the full surface rectangle */ - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = surface->w; - full_rect.h = surface->h; - - /* Set the clipping rectangle */ - if ( ! rect ) { - surface->clip_rect = full_rect; - return 1; - } - return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect); + SDL_Rect full_rect; + + /* Don't do anything if there's no surface to act on */ + if (!surface) { + return SDL_FALSE; + } + + /* Set up the full surface rectangle */ + full_rect.x = 0; + full_rect.y = 0; + full_rect.w = surface->w; + full_rect.h = surface->h; + + /* Set the clipping rectangle */ + if (!rect) { + surface->clip_rect = full_rect; + return 1; + } + return SDL_IntersectRect (rect, &full_rect, &surface->clip_rect); } -void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect) + +void +SDL_GetClipRect (SDL_Surface * surface, SDL_Rect * rect) { - if ( surface && rect ) { - *rect = surface->clip_rect; - } + if (surface && rect) { + *rect = surface->clip_rect; + } } + /* * Set up a blit between two surfaces -- split into three parts: * The upper part, SDL_UpperBlit(), performs clipping and rectangle @@ -404,538 +412,526 @@ void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect) * you know exactly what you are doing, you can optimize your code * by calling the one(s) you need. */ -int SDL_LowerBlit (SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) +int +SDL_LowerBlit (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect) { - SDL_blit do_blit; - SDL_Rect hw_srcrect; - SDL_Rect hw_dstrect; - - /* Check to make sure the blit mapping is valid */ - if ( (src->map->dst != dst) || - (src->map->dst->format_version != src->map->format_version) ) { - if ( SDL_MapSurface(src, dst) < 0 ) { - return(-1); - } - } - - /* Figure out which blitter to use */ - if ( (src->flags & SDL_HWACCEL) == SDL_HWACCEL ) { - if ( src == SDL_VideoSurface ) { - hw_srcrect = *srcrect; - hw_srcrect.x += current_video->offset_x; - hw_srcrect.y += current_video->offset_y; - srcrect = &hw_srcrect; - } - if ( dst == SDL_VideoSurface ) { - hw_dstrect = *dstrect; - hw_dstrect.x += current_video->offset_x; - hw_dstrect.y += current_video->offset_y; - dstrect = &hw_dstrect; - } - do_blit = src->map->hw_blit; - } else { - do_blit = src->map->sw_blit; - } - return(do_blit(src, srcrect, dst, dstrect)); + SDL_blit do_blit; + + /* Check to make sure the blit mapping is valid */ + if ((src->map->dst != dst) || + (src->map->dst->format_version != src->map->format_version)) { + if (SDL_MapSurface (src, dst) < 0) { + return (-1); + } + } + + /* Figure out which blitter to use */ + if ((src->flags & SDL_HWACCEL) == SDL_HWACCEL) { + do_blit = src->map->hw_blit; + } else { + do_blit = src->map->sw_blit; + } + return (do_blit (src, srcrect, dst, dstrect)); } -int SDL_UpperBlit (SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) +int +SDL_UpperBlit (SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect) { - SDL_Rect fulldst; - int srcx, srcy, w, h; - - /* Make sure the surfaces aren't locked */ - if ( ! src || ! dst ) { - SDL_SetError("SDL_UpperBlit: passed a NULL surface"); - return(-1); - } - if ( src->locked || dst->locked ) { - SDL_SetError("Surfaces must not be locked during blit"); - return(-1); - } - - /* If the destination rectangle is NULL, use the entire dest surface */ - if ( dstrect == NULL ) { - fulldst.x = fulldst.y = 0; - dstrect = &fulldst; - } - - /* clip the source rectangle to the source surface */ - if(srcrect) { - int maxw, maxh; - - srcx = srcrect->x; - w = srcrect->w; - if(srcx < 0) { - w += srcx; - dstrect->x -= srcx; - srcx = 0; - } - maxw = src->w - srcx; - if(maxw < w) - w = maxw; - - srcy = srcrect->y; - h = srcrect->h; - if(srcy < 0) { - h += srcy; - dstrect->y -= srcy; - srcy = 0; - } - maxh = src->h - srcy; - if(maxh < h) - h = maxh; - - } else { - srcx = srcy = 0; - w = src->w; - h = src->h; - } - - /* clip the destination rectangle against the clip rectangle */ - { - SDL_Rect *clip = &dst->clip_rect; - int dx, dy; - - dx = clip->x - dstrect->x; - if(dx > 0) { - w -= dx; - dstrect->x += dx; - srcx += dx; - } - dx = dstrect->x + w - clip->x - clip->w; - if(dx > 0) - w -= dx; - - dy = clip->y - dstrect->y; - if(dy > 0) { - h -= dy; - dstrect->y += dy; - srcy += dy; - } - dy = dstrect->y + h - clip->y - clip->h; - if(dy > 0) - h -= dy; - } - - if(w > 0 && h > 0) { - SDL_Rect sr; - sr.x = srcx; - sr.y = srcy; - sr.w = dstrect->w = w; - sr.h = dstrect->h = h; - return SDL_LowerBlit(src, &sr, dst, dstrect); - } - dstrect->w = dstrect->h = 0; - return 0; + SDL_Rect fulldst; + int srcx, srcy, w, h; + + /* Make sure the surfaces aren't locked */ + if (!src || !dst) { + SDL_SetError ("SDL_UpperBlit: passed a NULL surface"); + return (-1); + } + if (src->locked || dst->locked) { + SDL_SetError ("Surfaces must not be locked during blit"); + return (-1); + } + + /* If the destination rectangle is NULL, use the entire dest surface */ + if (dstrect == NULL) { + fulldst.x = fulldst.y = 0; + dstrect = &fulldst; + } + + /* clip the source rectangle to the source surface */ + if (srcrect) { + int maxw, maxh; + + srcx = srcrect->x; + w = srcrect->w; + if (srcx < 0) { + w += srcx; + dstrect->x -= srcx; + srcx = 0; + } + maxw = src->w - srcx; + if (maxw < w) + w = maxw; + + srcy = srcrect->y; + h = srcrect->h; + if (srcy < 0) { + h += srcy; + dstrect->y -= srcy; + srcy = 0; + } + maxh = src->h - srcy; + if (maxh < h) + h = maxh; + + } else { + srcx = srcy = 0; + w = src->w; + h = src->h; + } + + /* clip the destination rectangle against the clip rectangle */ + { + SDL_Rect *clip = &dst->clip_rect; + int dx, dy; + + dx = clip->x - dstrect->x; + if (dx > 0) { + w -= dx; + dstrect->x += dx; + srcx += dx; + } + dx = dstrect->x + w - clip->x - clip->w; + if (dx > 0) + w -= dx; + + dy = clip->y - dstrect->y; + if (dy > 0) { + h -= dy; + dstrect->y += dy; + srcy += dy; + } + dy = dstrect->y + h - clip->y - clip->h; + if (dy > 0) + h -= dy; + } + + if (w > 0 && h > 0) { + SDL_Rect sr; + sr.x = srcx; + sr.y = srcy; + sr.w = dstrect->w = w; + sr.h = dstrect->h = h; + return SDL_LowerBlit (src, &sr, dst, dstrect); + } + dstrect->w = dstrect->h = 0; + return 0; } -static int SDL_FillRect1(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) +static int +SDL_FillRect1 (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) { - /* FIXME: We have to worry about packing order.. *sigh* */ - SDL_SetError("1-bpp rect fill not yet implemented"); - return -1; + /* FIXME: We have to worry about packing order.. *sigh* */ + SDL_SetError ("1-bpp rect fill not yet implemented"); + return -1; } -static int SDL_FillRect4(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) +static int +SDL_FillRect4 (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) { - /* FIXME: We have to worry about packing order.. *sigh* */ - SDL_SetError("4-bpp rect fill not yet implemented"); - return -1; + /* FIXME: We have to worry about packing order.. *sigh* */ + SDL_SetError ("4-bpp rect fill not yet implemented"); + return -1; } /* * This function performs a fast fill of the given rectangle with 'color' */ -int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) +int +SDL_FillRect (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - int x, y; - Uint8 *row; - - /* This function doesn't work on surfaces < 8 bpp */ - if ( dst->format->BitsPerPixel < 8 ) { - switch(dst->format->BitsPerPixel) { - case 1: - return SDL_FillRect1(dst, dstrect, color); - break; - case 4: - return SDL_FillRect4(dst, dstrect, color); - break; - default: - SDL_SetError("Fill rect on unsupported surface format"); - return(-1); - break; - } - } - - /* If 'dstrect' == NULL, then fill the whole surface */ - if ( dstrect ) { - /* Perform clipping */ - if ( !SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect) ) { - return(0); - } - } else { - dstrect = &dst->clip_rect; - } - - /* Check for hardware acceleration */ - if ( ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) && - video->info.blit_fill ) { - SDL_Rect hw_rect; - if ( dst == SDL_VideoSurface ) { - hw_rect = *dstrect; - hw_rect.x += current_video->offset_x; - hw_rect.y += current_video->offset_y; - dstrect = &hw_rect; - } - return(video->FillHWRect(this, dst, dstrect, color)); - } - - /* Perform software fill */ - if ( SDL_LockSurface(dst) != 0 ) { - return(-1); - } - row = (Uint8 *)dst->pixels+dstrect->y*dst->pitch+ - dstrect->x*dst->format->BytesPerPixel; - if ( dst->format->palette || (color == 0) ) { - x = dstrect->w*dst->format->BytesPerPixel; - if ( !color && !((uintptr_t)row&3) && !(x&3) && !(dst->pitch&3) ) { - int n = x >> 2; - for ( y=dstrect->h; y; --y ) { - SDL_memset4(row, 0, n); - row += dst->pitch; - } - } else { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + int x, y; + Uint8 *row; + + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + switch (dst->format->BitsPerPixel) { + case 1: + return SDL_FillRect1 (dst, dstrect, color); + break; + case 4: + return SDL_FillRect4 (dst, dstrect, color); + break; + default: + SDL_SetError ("Fill rect on unsupported surface format"); + return (-1); + break; + } + } + + /* If 'dstrect' == NULL, then fill the whole surface */ + if (dstrect) { + /* Perform clipping */ + if (!SDL_IntersectRect (dstrect, &dst->clip_rect, dstrect)) { + return (0); + } + } else { + dstrect = &dst->clip_rect; + } + + /* Check for hardware acceleration */ + if (((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) && + _this->info.blit_fill) { + return (_this->FillHWRect (_this, dst, dstrect, color)); + } + + /* Perform software fill */ + if (SDL_LockSurface (dst) != 0) { + return (-1); + } + row = (Uint8 *) dst->pixels + dstrect->y * dst->pitch + + dstrect->x * dst->format->BytesPerPixel; + if (dst->format->palette || (color == 0)) { + x = dstrect->w * dst->format->BytesPerPixel; + if (!color && !((uintptr_t) row & 3) && !(x & 3) + && !(dst->pitch & 3)) { + int n = x >> 2; + for (y = dstrect->h; y; --y) { + SDL_memset4 (row, 0, n); + row += dst->pitch; + } + } else { #ifdef __powerpc__ - /* - * SDL_memset() on PPC (both glibc and codewarrior) uses - * the dcbz (Data Cache Block Zero) instruction, which - * causes an alignment exception if the destination is - * uncachable, so only use it on software surfaces - */ - if((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { - if(dstrect->w >= 8) { - /* - * 64-bit stores are probably most - * efficient to uncached video memory - */ - double fill; - SDL_memset(&fill, color, (sizeof fill)); - for(y = dstrect->h; y; y--) { - Uint8 *d = row; - unsigned n = x; - unsigned nn; - Uint8 c = color; - double f = fill; - while((unsigned long)d - & (sizeof(double) - 1)) { - *d++ = c; - n--; - } - nn = n / (sizeof(double) * 4); - while(nn) { - ((double *)d)[0] = f; - ((double *)d)[1] = f; - ((double *)d)[2] = f; - ((double *)d)[3] = f; - d += 4*sizeof(double); - nn--; - } - n &= ~(sizeof(double) * 4 - 1); - nn = n / sizeof(double); - while(nn) { - *(double *)d = f; - d += sizeof(double); - nn--; - } - n &= ~(sizeof(double) - 1); - while(n) { - *d++ = c; - n--; - } - row += dst->pitch; - } - } else { - /* narrow boxes */ - for(y = dstrect->h; y; y--) { - Uint8 *d = row; - Uint8 c = color; - int n = x; - while(n) { - *d++ = c; - n--; - } - row += dst->pitch; - } - } - } else + /* + * SDL_memset() on PPC (both glibc and codewarrior) uses + * the dcbz (Data Cache Block Zero) instruction, which + * causes an alignment exception if the destination is + * uncachable, so only use it on software surfaces + */ + if ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { + if (dstrect->w >= 8) { + /* + * 64-bit stores are probably most + * efficient to uncached video memory + */ + double fill; + SDL_memset (&fill, color, (sizeof fill)); + for (y = dstrect->h; y; y--) { + Uint8 *d = row; + unsigned n = x; + unsigned nn; + Uint8 c = color; + double f = fill; + while ((unsigned long) d & (sizeof (double) - 1)) { + *d++ = c; + n--; + } + nn = n / (sizeof (double) * 4); + while (nn) { + ((double *) d)[0] = f; + ((double *) d)[1] = f; + ((double *) d)[2] = f; + ((double *) d)[3] = f; + d += 4 * sizeof (double); + nn--; + } + n &= ~(sizeof (double) * 4 - 1); + nn = n / sizeof (double); + while (nn) { + *(double *) d = f; + d += sizeof (double); + nn--; + } + n &= ~(sizeof (double) - 1); + while (n) { + *d++ = c; + n--; + } + row += dst->pitch; + } + } else { + /* narrow boxes */ + for (y = dstrect->h; y; y--) { + Uint8 *d = row; + Uint8 c = color; + int n = x; + while (n) { + *d++ = c; + n--; + } + row += dst->pitch; + } + } + } else #endif /* __powerpc__ */ - { - for(y = dstrect->h; y; y--) { - SDL_memset(row, color, x); - row += dst->pitch; - } - } - } - } else { - switch (dst->format->BytesPerPixel) { - case 2: - for ( y=dstrect->h; y; --y ) { - Uint16 *pixels = (Uint16 *)row; - Uint16 c = (Uint16)color; - Uint32 cc = (Uint32)c << 16 | c; - int n = dstrect->w; - if((uintptr_t)pixels & 3) { - *pixels++ = c; - n--; - } - if(n >> 1) - SDL_memset4(pixels, cc, n >> 1); - if(n & 1) - pixels[n - 1] = c; - row += dst->pitch; - } - break; - - case 3: - #if SDL_BYTEORDER == SDL_BIG_ENDIAN - color <<= 8; - #endif - for ( y=dstrect->h; y; --y ) { - Uint8 *pixels = row; - for ( x=dstrect->w; x; --x ) { - SDL_memcpy(pixels, &color, 3); - pixels += 3; - } - row += dst->pitch; - } - break; - - case 4: - for(y = dstrect->h; y; --y) { - SDL_memset4(row, color, dstrect->w); - row += dst->pitch; - } - break; - } - } - SDL_UnlockSurface(dst); - - /* We're done! */ - return(0); + { + for (y = dstrect->h; y; y--) { + SDL_memset (row, color, x); + row += dst->pitch; + } + } + } + } else { + switch (dst->format->BytesPerPixel) { + case 2: + for (y = dstrect->h; y; --y) { + Uint16 *pixels = (Uint16 *) row; + Uint16 c = (Uint16) color; + Uint32 cc = (Uint32) c << 16 | c; + int n = dstrect->w; + if ((uintptr_t) pixels & 3) { + *pixels++ = c; + n--; + } + if (n >> 1) + SDL_memset4 (pixels, cc, n >> 1); + if (n & 1) + pixels[n - 1] = c; + row += dst->pitch; + } + break; + + case 3: +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + color <<= 8; +#endif + for (y = dstrect->h; y; --y) { + Uint8 *pixels = row; + for (x = dstrect->w; x; --x) { + SDL_memcpy (pixels, &color, 3); + pixels += 3; + } + row += dst->pitch; + } + break; + + case 4: + for (y = dstrect->h; y; --y) { + SDL_memset4 (row, color, dstrect->w); + row += dst->pitch; + } + break; + } + } + SDL_UnlockSurface (dst); + + /* We're done! */ + return (0); } /* * Lock a surface to directly access the pixels */ -int SDL_LockSurface (SDL_Surface *surface) +int +SDL_LockSurface (SDL_Surface * surface) { - if ( ! surface->locked ) { - /* Perform the lock */ - if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - if ( video->LockHWSurface(this, surface) < 0 ) { - return(-1); - } - } - if ( surface->flags & SDL_RLEACCEL ) { - SDL_UnRLESurface(surface, 1); - surface->flags |= SDL_RLEACCEL; /* save accel'd state */ - } - /* This needs to be done here in case pixels changes value */ - surface->pixels = (Uint8 *)surface->pixels + surface->offset; - } - - /* Increment the surface lock count, for recursive locks */ - ++surface->locked; - - /* Ready to go.. */ - return(0); + if (!surface->locked) { + /* Perform the lock */ + if (surface->flags & SDL_HWSURFACE) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + if (_this->LockHWSurface (_this, surface) < 0) { + return (-1); + } + } + if (surface->flags & SDL_RLEACCEL) { + SDL_UnRLESurface (surface, 1); + surface->flags |= SDL_RLEACCEL; /* save accel'd state */ + } + /* This needs to be done here in case pixels changes value */ + surface->pixels = (Uint8 *) surface->pixels + surface->offset; + } + + /* Increment the surface lock count, for recursive locks */ + ++surface->locked; + + /* Ready to go.. */ + return (0); } + /* * Unlock a previously locked surface */ -void SDL_UnlockSurface (SDL_Surface *surface) +void +SDL_UnlockSurface (SDL_Surface * surface) { - /* Only perform an unlock if we are locked */ - if ( ! surface->locked || (--surface->locked > 0) ) { - return; - } - - /* Perform the unlock */ - surface->pixels = (Uint8 *)surface->pixels - surface->offset; - - /* Unlock hardware or accelerated surfaces */ - if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->UnlockHWSurface(this, surface); - } else { - /* Update RLE encoded surface with new data */ - if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { - surface->flags &= ~SDL_RLEACCEL; /* stop lying */ - SDL_RLESurface(surface); - } - } + /* Only perform an unlock if we are locked */ + if (!surface->locked || (--surface->locked > 0)) { + return; + } + + /* Perform the unlock */ + surface->pixels = (Uint8 *) surface->pixels - surface->offset; + + /* Unlock hardware or accelerated surfaces */ + if (surface->flags & SDL_HWSURFACE) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + _this->UnlockHWSurface (_this, surface); + } else { + /* Update RLE encoded surface with new data */ + if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + surface->flags &= ~SDL_RLEACCEL; /* stop lying */ + SDL_RLESurface (surface); + } + } } /* * Convert a surface into the specified pixel format. */ -SDL_Surface * SDL_ConvertSurface (SDL_Surface *surface, - SDL_PixelFormat *format, Uint32 flags) +SDL_Surface * +SDL_ConvertSurface (SDL_Surface * surface, + SDL_PixelFormat * format, Uint32 flags) { - SDL_Surface *convert; - Uint32 colorkey = 0; - Uint8 alpha = 0; - Uint32 surface_flags; - SDL_Rect bounds; - - /* Check for empty destination palette! (results in empty image) */ - if ( format->palette != NULL ) { - int i; - for ( i=0; ipalette->ncolors; ++i ) { - if ( (format->palette->colors[i].r != 0) || - (format->palette->colors[i].g != 0) || - (format->palette->colors[i].b != 0) ) - break; - } - if ( i == format->palette->ncolors ) { - SDL_SetError("Empty destination palette"); - return(NULL); - } - } - - /* Only create hw surfaces with alpha channel if hw alpha blits - are supported */ - if(format->Amask != 0 && (flags & SDL_HWSURFACE)) { - const SDL_VideoInfo *vi = SDL_GetVideoInfo(); - if(!vi || !vi->blit_hw_A) - flags &= ~SDL_HWSURFACE; - } - - /* Create a new surface with the desired format */ - convert = SDL_CreateRGBSurface(flags, - surface->w, surface->h, format->BitsPerPixel, - format->Rmask, format->Gmask, format->Bmask, format->Amask); - if ( convert == NULL ) { - return(NULL); - } - - /* Copy the palette if any */ - if ( format->palette && convert->format->palette ) { - SDL_memcpy(convert->format->palette->colors, - format->palette->colors, - format->palette->ncolors*sizeof(SDL_Color)); - convert->format->palette->ncolors = format->palette->ncolors; - } - - /* Save the original surface color key and alpha */ - surface_flags = surface->flags; - if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { - /* Convert colourkeyed surfaces to RGBA if requested */ - if((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY - && format->Amask) { - surface_flags &= ~SDL_SRCCOLORKEY; - } else { - colorkey = surface->format->colorkey; - SDL_SetColorKey(surface, 0, 0); - } - } - if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { - /* Copy over the alpha channel to RGBA if requested */ - if ( format->Amask ) { - surface->flags &= ~SDL_SRCALPHA; - } else { - alpha = surface->format->alpha; - SDL_SetAlpha(surface, 0, 0); - } - } - - /* Copy over the image data */ - bounds.x = 0; - bounds.y = 0; - bounds.w = surface->w; - bounds.h = surface->h; - SDL_LowerBlit(surface, &bounds, convert, &bounds); - - /* Clean up the original surface, and update converted surface */ - if ( convert != NULL ) { - SDL_SetClipRect(convert, &surface->clip_rect); - } - if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { - Uint32 cflags = surface_flags&(SDL_SRCCOLORKEY|SDL_RLEACCELOK); - if ( convert != NULL ) { - Uint8 keyR, keyG, keyB; - - SDL_GetRGB(colorkey,surface->format,&keyR,&keyG,&keyB); - SDL_SetColorKey(convert, cflags|(flags&SDL_RLEACCELOK), - SDL_MapRGB(convert->format, keyR, keyG, keyB)); - } - SDL_SetColorKey(surface, cflags, colorkey); - } - if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { - Uint32 aflags = surface_flags&(SDL_SRCALPHA|SDL_RLEACCELOK); - if ( convert != NULL ) { - SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK), - alpha); - } - if ( format->Amask ) { - surface->flags |= SDL_SRCALPHA; - } else { - SDL_SetAlpha(surface, aflags, alpha); - } - } - - /* We're ready to go! */ - return(convert); + SDL_Surface *convert; + Uint32 colorkey = 0; + Uint8 alpha = 0; + Uint32 surface_flags; + SDL_Rect bounds; + + /* Check for empty destination palette! (results in empty image) */ + if (format->palette != NULL) { + int i; + for (i = 0; i < format->palette->ncolors; ++i) { + if ((format->palette->colors[i].r != 0) || + (format->palette->colors[i].g != 0) || + (format->palette->colors[i].b != 0)) + break; + } + if (i == format->palette->ncolors) { + SDL_SetError ("Empty destination palette"); + return (NULL); + } + } + + /* Only create hw surfaces with alpha channel if hw alpha blits + are supported */ + if (format->Amask != 0 && (flags & SDL_HWSURFACE)) { + const SDL_VideoInfo *vi = SDL_GetVideoInfo (); + if (!vi || !vi->blit_hw_A) + flags &= ~SDL_HWSURFACE; + } + + /* Create a new surface with the desired format */ + convert = SDL_CreateRGBSurface (flags, + surface->w, surface->h, + format->BitsPerPixel, format->Rmask, + format->Gmask, format->Bmask, + format->Amask); + if (convert == NULL) { + return (NULL); + } + + /* Copy the palette if any */ + if (format->palette && convert->format->palette) { + SDL_memcpy (convert->format->palette->colors, + format->palette->colors, + format->palette->ncolors * sizeof (SDL_Color)); + convert->format->palette->ncolors = format->palette->ncolors; + } + + /* Save the original surface color key and alpha */ + surface_flags = surface->flags; + if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { + /* Convert colourkeyed surfaces to RGBA if requested */ + if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) { + surface_flags &= ~SDL_SRCCOLORKEY; + } else { + colorkey = surface->format->colorkey; + SDL_SetColorKey (surface, 0, 0); + } + } + if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { + /* Copy over the alpha channel to RGBA if requested */ + if (format->Amask) { + surface->flags &= ~SDL_SRCALPHA; + } else { + alpha = surface->format->alpha; + SDL_SetAlpha (surface, 0, 0); + } + } + + /* Copy over the image data */ + bounds.x = 0; + bounds.y = 0; + bounds.w = surface->w; + bounds.h = surface->h; + SDL_LowerBlit (surface, &bounds, convert, &bounds); + + /* Clean up the original surface, and update converted surface */ + if (convert != NULL) { + SDL_SetClipRect (convert, &surface->clip_rect); + } + if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { + Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK); + if (convert != NULL) { + Uint8 keyR, keyG, keyB; + + SDL_GetRGB (colorkey, surface->format, &keyR, &keyG, &keyB); + SDL_SetColorKey (convert, cflags | (flags & SDL_RLEACCELOK), + SDL_MapRGB (convert->format, keyR, keyG, keyB)); + } + SDL_SetColorKey (surface, cflags, colorkey); + } + if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { + Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK); + if (convert != NULL) { + SDL_SetAlpha (convert, aflags | (flags & SDL_RLEACCELOK), alpha); + } + if (format->Amask) { + surface->flags |= SDL_SRCALPHA; + } else { + SDL_SetAlpha (surface, aflags, alpha); + } + } + + /* We're ready to go! */ + return (convert); } /* * Free a surface created by the above function. */ -void SDL_FreeSurface (SDL_Surface *surface) +void +SDL_FreeSurface (SDL_Surface * surface) { - /* Free anything that's not NULL, and not the screen surface */ - if ((surface == NULL) || - (current_video && - ((surface == SDL_ShadowSurface)||(surface == SDL_VideoSurface)))) { - return; - } - if ( --surface->refcount > 0 ) { - return; - } - while ( surface->locked > 0 ) { - SDL_UnlockSurface(surface); - } - if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { - SDL_UnRLESurface(surface, 0); - } - if ( surface->format ) { - SDL_FreeFormat(surface->format); - surface->format = NULL; - } - if ( surface->map != NULL ) { - SDL_FreeBlitMap(surface->map); - surface->map = NULL; - } - if ( surface->hwdata ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->FreeHWSurface(this, surface); - } - if ( surface->pixels && - ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC) ) { - SDL_free(surface->pixels); - } - SDL_free(surface); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + + /* Free anything that's not NULL, and not the screen surface */ + if ((surface == NULL) || + (_this && + ((surface == SDL_ShadowSurface) || (surface == SDL_VideoSurface)))) { + return; + } + if (--surface->refcount > 0) { + return; + } + while (surface->locked > 0) { + SDL_UnlockSurface (surface); + } + if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + SDL_UnRLESurface (surface, 0); + } + if (surface->format) { + SDL_FreeFormat (surface->format); + surface->format = NULL; + } + if (surface->map != NULL) { + SDL_FreeBlitMap (surface->map); + surface->map = NULL; + } + if (surface->hwdata) { + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + _this->FreeHWSurface (_this, surface); + } + if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) { + SDL_free (surface->pixels); + } + SDL_free (surface); #ifdef CHECK_LEAKS - --surfaces_allocated; + --surfaces_allocated; #endif } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 3714ad172..2d6976814 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -38,151 +38,190 @@ #endif /* SDL_VIDEO_OPENGL */ /* The SDL video driver */ -typedef struct SDL_VideoDevice SDL_VideoDevice; - -/* Define the SDL video driver structure */ -#define _THIS SDL_VideoDevice *_this -#ifndef _STATUS -#define _STATUS SDL_status *status -#endif -struct SDL_VideoDevice { - /* * * */ - /* The name of this video driver */ - const char *name; - - /* * * */ - /* Initialization/Query functions */ - - /* Initialize the native video subsystem, filling 'vformat' with the - "best" display pixel format, returning 0 or -1 if there's an error. - */ - int (*VideoInit)(_THIS, SDL_PixelFormat *vformat); - - /* List the available video modes for the given pixel format, sorted - from largest to smallest. - */ - SDL_Rect **(*ListModes)(_THIS, SDL_PixelFormat *format, Uint32 flags); - - /* Set the requested video mode, returning a surface which will be - set to the SDL_VideoSurface. The width and height will already - be verified by ListModes(), and the video subsystem is free to - set the mode to a supported bit depth different from the one - specified -- the desired bpp will be emulated with a shadow - surface if necessary. If a new mode is returned, this function - should take care of cleaning up the current mode. - */ - SDL_Surface *(*SetVideoMode)(_THIS, SDL_Surface *current, - int width, int height, int bpp, Uint32 flags); - - /* Toggle the fullscreen mode */ - int (*ToggleFullScreen)(_THIS, int on); - - /* This is called after the video mode has been set, to get the - initial mouse state. It should queue events as necessary to - properly represent the current mouse focus and position. - */ - void (*UpdateMouse)(_THIS); - - /* Create a YUV video surface (possibly overlay) of the given - format. The hardware should be able to perform at least 2x - scaling on display. - */ - SDL_Overlay *(*CreateYUVOverlay)(_THIS, int width, int height, - Uint32 format, SDL_Surface *display); - - /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) } - of the physical palette to those in 'colors'. If the device is - using a software palette (SDL_HWPALETTE not set), then the - changes are reflected in the logical palette of the screen - as well. - The return value is 1 if all entries could be set properly - or 0 otherwise. - */ - int (*SetColors)(_THIS, int firstcolor, int ncolors, - SDL_Color *colors); - - /* This pointer should exist in the native video subsystem and should - point to an appropriate update function for the current video mode - */ - void (*UpdateRects)(_THIS, int numrects, SDL_Rect *rects); - - /* Reverse the effects VideoInit() -- called if VideoInit() fails - or if the application is shutting down the video subsystem. - */ - void (*VideoQuit)(_THIS); - - /* * * */ - /* Hardware acceleration functions */ - - /* Information about the video hardware */ - SDL_VideoInfo info; - - /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */ - SDL_PixelFormat* displayformatalphapixel; - /* Allocates a surface in video memory */ - int (*AllocHWSurface)(_THIS, SDL_Surface *surface); +/* Define the SDL window structure, corresponding to toplevel windows */ +typedef struct SDL_Window SDL_Window; - /* Sets the hardware accelerated blit function, if any, based - on the current flags of the surface (colorkey, alpha, etc.) - */ - int (*CheckHWBlit)(_THIS, SDL_Surface *src, SDL_Surface *dst); +struct SDL_Window +{ + Uint32 id; - /* Fills a surface rectangle with the given color */ - int (*FillHWRect)(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color); + char *title; + int x, y; + int w, h; + Uint32 flags; - /* Sets video mem colorkey and accelerated blit function */ - int (*SetHWColorKey)(_THIS, SDL_Surface *surface, Uint32 key); + SDL_Surface *surface; + SDL_Surface *shadow; + Uint16 *gamma; - /* Sets per surface hardware alpha value */ - int (*SetHWAlpha)(_THIS, SDL_Surface *surface, Uint8 value); - - /* Returns a readable/writable surface */ - int (*LockHWSurface)(_THIS, SDL_Surface *surface); - void (*UnlockHWSurface)(_THIS, SDL_Surface *surface); - - /* Performs hardware flipping */ - int (*FlipHWSurface)(_THIS, SDL_Surface *surface); - - /* Frees a previously allocated video surface */ - void (*FreeHWSurface)(_THIS, SDL_Surface *surface); - - /* * * */ - /* Gamma support */ - - Uint16 *gamma; - - /* Set the gamma correction directly (emulated with gamma ramps) */ - int (*SetGamma)(_THIS, float red, float green, float blue); + void *userdata; + void *driverdata; +}; - /* Get the gamma correction directly (emulated with gamma ramps) */ - int (*GetGamma)(_THIS, float *red, float *green, float *blue); +/* Define the SDL display structure + This corresponds to physical monitors attached to the system. + */ +typedef struct SDL_VideoDisplay +{ + int num_display_modes; + SDL_DisplayMode *display_modes; + SDL_DisplayMode desktop_mode; + SDL_DisplayMode current_mode; - /* Set the gamma ramp */ - int (*SetGammaRamp)(_THIS, Uint16 *ramp); + int max_windows; + int num_windows; + SDL_Window *windows; - /* Get the gamma ramp */ - int (*GetGammaRamp)(_THIS, Uint16 *ramp); + void *driverdata; +} SDL_VideoDisplay; - /* * * */ - /* OpenGL support */ +typedef struct SDL_VideoDevice SDL_VideoDevice; - /* Sets the dll to use for OpenGL and loads it */ - int (*GL_LoadLibrary)(_THIS, const char *path); +/* Define the SDL video driver structure */ +#define _THIS SDL_VideoDevice *_this - /* Retrieves the address of a function in the gl library */ - void* (*GL_GetProcAddress)(_THIS, const char *proc); +struct SDL_VideoDevice +{ + /* * * */ + /* The name of this video driver */ + const char *name; + + /* * * */ + /* Initialization/Query functions */ + + /* Initialize the native video subsystem, filling in the list + of displays for this driver, returning 0 or -1 if there's an error. + */ + int (*VideoInit) (_THIS); + + /* * * */ + /* Display functions + */ + /* Setting the display mode is independent of creating windows, + * so when the display mode is changed, all existing windows + * should have their data updated accordingly, including the + * display surfaces associated with them. + */ + int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode); + + /* * * */ + /* Window functions + */ + int (*CreateWindow) (_THIS, SDL_Window * window); + int (*CreateWindowFrom) (_THIS, SDL_Window * window, void *data); + void (*SetWindowTitle) (_THIS, SDL_Window * window); + void (*SetWindowPosition) (_THIS, SDL_Window * window); + void (*SetWindowSize) (_THIS, SDL_Window * window); + void (*ShowWindow) (_THIS, SDL_Window * window); + void (*HideWindow) (_THIS, SDL_Window * window); + void (*RaiseWindow) (_THIS, SDL_Window * window); + void (*MaximizeWindow) (_THIS, SDL_Window * window); + void (*MinimizeWindow) (_THIS, SDL_Window * window); + void (*RestoreWindow) (_THIS, SDL_Window * window); + void (*SetWindowGrab) (_THIS, SDL_Window * window); + void (*DestroyWindow) (_THIS, SDL_Window * window); + + SDL_Surface *(*CreateWindowSurface) (_THIS, SDL_Window * window); + void (*UpdateWindowSurface) (_THIS, SDL_Window * window, int numrects, + SDL_Rect * rects); + void (*FlipWindowSurface) (_THIS, SDL_Window * window); + + /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) } + of the physical palette to those in 'colors'. If the device is + using a software palette (SDL_HWPALETTE not set), then the + changes are reflected in the logical palette of the screen + as well. + The return value is 1 if all entries could be set properly + or 0 otherwise. + */ + int (*SetWindowColors) (_THIS, SDL_Window * window, + int firstcolor, int ncolors, SDL_Color * colors); + + /* Get some platform dependent window information */ + SDL_bool (*GetWindowWMInfo) (_THIS, SDL_Window * window, + SDL_SysWMinfo * info); + + /* Create a YUV video surface (possibly overlay) of the given + format. The hardware should be able to perform at least 2x + scaling on display. + */ + SDL_Overlay *(*CreateYUVOverlay) (_THIS, int width, int height, + Uint32 format, SDL_Surface * display); + + /* Reverse the effects VideoInit() -- called if VideoInit() fails + or if the application is shutting down the video subsystem. + */ + void (*VideoQuit) (_THIS); + + /* * * */ + /* Hardware acceleration functions */ + + /* Information about the video hardware */ + SDL_VideoInfo info; + + /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */ + SDL_PixelFormat *displayformatalphapixel; + + /* Allocates a surface in video memory */ + int (*AllocHWSurface) (_THIS, SDL_Surface * surface); + + /* Sets the hardware accelerated blit function, if any, based + on the current flags of the surface (colorkey, alpha, etc.) + */ + int (*CheckHWBlit) (_THIS, SDL_Surface * src, SDL_Surface * dst); + + /* Fills a surface rectangle with the given color */ + int (*FillHWRect) (_THIS, SDL_Surface * dst, SDL_Rect * rect, + Uint32 color); + + /* Sets video mem colorkey and accelerated blit function */ + int (*SetHWColorKey) (_THIS, SDL_Surface * surface, Uint32 key); + + /* Sets per surface hardware alpha value */ + int (*SetHWAlpha) (_THIS, SDL_Surface * surface, Uint8 value); + + /* Returns a readable/writable surface */ + int (*LockHWSurface) (_THIS, SDL_Surface * surface); + void (*UnlockHWSurface) (_THIS, SDL_Surface * surface); + + /* Frees a previously allocated video surface */ + void (*FreeHWSurface) (_THIS, SDL_Surface * surface); + + /* * * */ + /* Gamma support */ + + /* Set the gamma correction directly (emulated with gamma ramps) */ + int (*SetGamma) (_THIS, float red, float green, float blue); + + /* Get the gamma correction directly (emulated with gamma ramps) */ + int (*GetGamma) (_THIS, float *red, float *green, float *blue); + + /* Set the gamma ramp */ + int (*SetGammaRamp) (_THIS, Uint16 * ramp); + + /* Get the gamma ramp */ + int (*GetGammaRamp) (_THIS, Uint16 * ramp); + + /* * * */ + /* OpenGL support */ + + /* Sets the dll to use for OpenGL and loads it */ + int (*GL_LoadLibrary) (_THIS, const char *path); + + /* Retrieves the address of a function in the gl library */ + void *(*GL_GetProcAddress) (_THIS, const char *proc); - /* Get attribute information from the windowing system. */ - int (*GL_GetAttribute)(_THIS, SDL_GLattr attrib, int* value); + /* Get attribute information from the windowing system. */ + int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value); - /* Make the context associated with this driver current */ - int (*GL_MakeCurrent)(_THIS); + /* Make the context associated with this driver current */ + int (*GL_MakeCurrent) (_THIS); - /* Swap the current buffers in double buffer mode. */ - void (*GL_SwapBuffers)(_THIS); + /* Swap the current buffers in double buffer mode. */ + void (*GL_SwapBuffers) (_THIS); - /* OpenGL functions for SDL_OPENGLBLIT */ + /* OpenGL functions for glSDL */ #if SDL_VIDEO_OPENGL #if !defined(__WIN32__) #define WINAPI @@ -191,130 +230,106 @@ struct SDL_VideoDevice { #include "SDL_glfuncs.h" #undef SDL_PROC - /* Texture id */ - GLuint texture; -#endif - int is_32bit; - - /* * * */ - /* Window manager functions */ - - /* Set the title and icon text */ - void (*SetCaption)(_THIS, const char *title, const char *icon); - - /* Set the window icon image */ - void (*SetIcon)(_THIS, SDL_Surface *icon, Uint8 *mask); - - /* Iconify the window. - This function returns 1 if there is a window manager and the - window was actually iconified, it returns 0 otherwise. - */ - int (*IconifyWindow)(_THIS); - - /* Grab or ungrab keyboard and mouse input */ - SDL_GrabMode (*GrabInput)(_THIS, SDL_GrabMode mode); - - /* Get some platform dependent window information */ - int (*GetWMInfo)(_THIS, SDL_SysWMinfo *info); - - /* * * */ - /* Cursor manager functions */ - - /* Free a window manager cursor - This function can be NULL if CreateWMCursor is also NULL. - */ - void (*FreeWMCursor)(_THIS, WMcursor *cursor); - - /* If not NULL, create a black/white window manager cursor */ - WMcursor *(*CreateWMCursor)(_THIS, - Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); - - /* Show the specified cursor, or hide if cursor is NULL */ - int (*ShowWMCursor)(_THIS, WMcursor *cursor); - - /* Warp the window manager cursor to (x,y) - If NULL, a mouse motion event is posted internally. - */ - void (*WarpWMCursor)(_THIS, Uint16 x, Uint16 y); - - /* If not NULL, this is called when a mouse motion event occurs */ - void (*MoveWMCursor)(_THIS, int x, int y); - - /* Determine whether the mouse should be in relative mode or not. - This function is called when the input grab state or cursor - visibility state changes. - If the cursor is not visible, and the input is grabbed, the - driver can place the mouse in relative mode, which may result - in higher accuracy sampling of the pointer motion. - */ - void (*CheckMouseMode)(_THIS); - - /* * * */ - /* Event manager functions */ - - /* Initialize keyboard mapping for this driver */ - void (*InitOSKeymap)(_THIS); - - /* Handle any queued OS events */ - void (*PumpEvents)(_THIS); - - /* * * */ - /* Data common to all drivers */ - SDL_Surface *screen; - SDL_Surface *shadow; - SDL_Surface *visible; - SDL_Palette *physpal; /* physical palette, if != logical palette */ - SDL_Color *gammacols; /* gamma-corrected colours, or NULL */ - char *wm_title; - char *wm_icon; - int offset_x; - int offset_y; - SDL_GrabMode input_grab; - - /* Driver information flags */ - int handles_any_size; /* Driver handles any size video mode */ - - /* * * */ - /* Data used by the GL drivers */ - struct { - int red_size; - int green_size; - int blue_size; - int alpha_size; - int depth_size; - int buffer_size; - int stencil_size; - int double_buffer; - int accum_red_size; - int accum_green_size; - int accum_blue_size; - int accum_alpha_size; - int stereo; - int multisamplebuffers; - int multisamplesamples; - int accelerated; - int swap_control; - int driver_loaded; - char driver_path[256]; - void* dll_handle; - } gl_config; - - /* * * */ - /* Data private to this driver */ - struct SDL_PrivateVideoData *hidden; - struct SDL_PrivateGLData *gl_data; - - /* * * */ - /* The function used to dispose of this structure */ - void (*free)(_THIS); + /* Texture id */ + GLuint texture; + + int is_32bit; +#endif + + /* * * */ + /* Cursor manager functions */ + + /* Free a window manager cursor + This function can be NULL if CreateWMCursor is also NULL. + */ + void (*FreeWMCursor) (_THIS, WMcursor * cursor); + + /* If not NULL, create a black/white window manager cursor */ + WMcursor *(*CreateWMCursor) (_THIS, + Uint8 * data, Uint8 * mask, int w, int h, + int hot_x, int hot_y); + + /* Show the specified cursor, or hide if cursor is NULL */ + int (*ShowWMCursor) (_THIS, WMcursor * cursor); + + /* Warp the window manager cursor to (x,y) + If NULL, a mouse motion event is posted internally. + */ + void (*WarpWMCursor) (_THIS, Uint16 x, Uint16 y); + + /* If not NULL, this is called when a mouse motion event occurs */ + void (*MoveWMCursor) (_THIS, int x, int y); + + /* Determine whether the mouse should be in relative mode or not. + This function is called when the input grab state or cursor + visibility state changes. + If the cursor is not visible, and the input is grabbed, the + driver can place the mouse in relative mode, which may result + in higher accuracy sampling of the pointer motion. + */ + void (*CheckMouseMode) (_THIS); + + /* * * */ + /* Event manager functions */ + + /* Initialize keyboard mapping for this driver */ + void (*InitOSKeymap) (_THIS); + + /* Handle any queued OS events */ + void (*PumpEvents) (_THIS); + + /* * * */ + /* Data common to all drivers */ + int num_displays; + SDL_VideoDisplay *displays; + int current_display; + Uint32 next_window_id; + + /* Driver information flags */ + + /* * * */ + /* Data used by the GL drivers */ + struct + { + int red_size; + int green_size; + int blue_size; + int alpha_size; + int depth_size; + int buffer_size; + int stencil_size; + int double_buffer; + int accum_red_size; + int accum_green_size; + int accum_blue_size; + int accum_alpha_size; + int stereo; + int multisamplebuffers; + int multisamplesamples; + int accelerated; + int swap_control; + int driver_loaded; + char driver_path[256]; + void *dll_handle; + } gl_config; + + /* * * */ + /* Data private to this driver */ + struct SDL_PrivateVideoData *hidden; + struct SDL_PrivateGLData *gl_data; + + /* * * */ + /* The function used to dispose of this structure */ + void (*free) (_THIS); }; #undef _THIS -typedef struct VideoBootStrap { - const char *name; - const char *desc; - int (*available)(void); - SDL_VideoDevice *(*create)(int devindex); +typedef struct VideoBootStrap +{ + const char *name; + const char *desc; + int (*available) (void); + SDL_VideoDevice *(*create) (int devindex); } VideoBootStrap; #if SDL_VIDEO_DRIVER_QUARTZ @@ -411,11 +426,18 @@ extern VideoBootStrap DUMMY_bootstrap; extern VideoBootStrap glSDL_bootstrap; #endif -/* This is the current video device */ -extern SDL_VideoDevice *current_video; +#define SDL_CurrentDisplay (_this->displays[_this->current_display]) +#define SDL_CurrentWindow (SDL_CurrentDisplay.windows[0]) +#define SDL_VideoSurface ((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.surface : NULL) +#define SDL_ShadowSurface ((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.shadow : NULL) +#define SDL_PublicSurface (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface) -#define SDL_VideoSurface (current_video->screen) -#define SDL_ShadowSurface (current_video->shadow) -#define SDL_PublicSurface (current_video->visible) +extern SDL_VideoDevice *SDL_GetVideoDevice (); +extern void SDL_AddBasicVideoDisplay (const SDL_DisplayMode * desktop_mode); +extern void SDL_AddVideoDisplay (SDL_VideoDisplay * display); +extern void SDL_AddDisplayMode (int display, const SDL_DisplayMode * mode); +extern SDL_Window *SDL_GetWindowFromSurface (SDL_Surface * surface); #endif /* _SDL_sysvideo_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 418cedd6f..996d66dd4 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -34,1701 +34,1599 @@ /* Available video drivers */ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_QUARTZ - &QZ_bootstrap, + &QZ_bootstrap, #endif #if SDL_VIDEO_DRIVER_X11 - &X11_bootstrap, + &X11_bootstrap, #endif #if SDL_VIDEO_DRIVER_DGA - &DGA_bootstrap, + &DGA_bootstrap, #endif #if SDL_VIDEO_DRIVER_NANOX - &NX_bootstrap, + &NX_bootstrap, #endif #if SDL_VIDEO_DRIVER_IPOD - &iPod_bootstrap, + &iPod_bootstrap, #endif #if SDL_VIDEO_DRIVER_QTOPIA - &Qtopia_bootstrap, + &Qtopia_bootstrap, #endif #if SDL_VIDEO_DRIVER_WSCONS - &WSCONS_bootstrap, + &WSCONS_bootstrap, #endif #if SDL_VIDEO_DRIVER_FBCON - &FBCON_bootstrap, + &FBCON_bootstrap, #endif #if SDL_VIDEO_DRIVER_DIRECTFB - &DirectFB_bootstrap, + &DirectFB_bootstrap, #endif #if SDL_VIDEO_DRIVER_PS2GS - &PS2GS_bootstrap, + &PS2GS_bootstrap, #endif #if SDL_VIDEO_DRIVER_GGI - &GGI_bootstrap, + &GGI_bootstrap, #endif #if SDL_VIDEO_DRIVER_VGL - &VGL_bootstrap, + &VGL_bootstrap, #endif #if SDL_VIDEO_DRIVER_SVGALIB - &SVGALIB_bootstrap, + &SVGALIB_bootstrap, #endif #if SDL_VIDEO_DRIVER_GAPI - &GAPI_bootstrap, + &GAPI_bootstrap, #endif #if SDL_VIDEO_DRIVER_WINDIB - &WINDIB_bootstrap, + &WINDIB_bootstrap, #endif #if SDL_VIDEO_DRIVER_DDRAW - &DIRECTX_bootstrap, + &DIRECTX_bootstrap, #endif #if SDL_VIDEO_DRIVER_BWINDOW - &BWINDOW_bootstrap, + &BWINDOW_bootstrap, #endif #if SDL_VIDEO_DRIVER_TOOLBOX - &TOOLBOX_bootstrap, + &TOOLBOX_bootstrap, #endif #if SDL_VIDEO_DRIVER_DRAWSPROCKET - &DSp_bootstrap, + &DSp_bootstrap, #endif #if SDL_VIDEO_DRIVER_CYBERGRAPHICS - &CGX_bootstrap, + &CGX_bootstrap, #endif #if SDL_VIDEO_DRIVER_PHOTON - &ph_bootstrap, + &ph_bootstrap, #endif #if SDL_VIDEO_DRIVER_EPOC - &EPOC_bootstrap, + &EPOC_bootstrap, #endif #if SDL_VIDEO_DRIVER_XBIOS - &XBIOS_bootstrap, + &XBIOS_bootstrap, #endif #if SDL_VIDEO_DRIVER_GEM - &GEM_bootstrap, + &GEM_bootstrap, #endif #if SDL_VIDEO_DRIVER_PICOGUI - &PG_bootstrap, + &PG_bootstrap, #endif #if SDL_VIDEO_DRIVER_DC - &DC_bootstrap, + &DC_bootstrap, #endif #if SDL_VIDEO_DRIVER_RISCOS - &RISCOS_bootstrap, + &RISCOS_bootstrap, #endif #if SDL_VIDEO_DRIVER_OS2FS - &OS2FSLib_bootstrap, + &OS2FSLib_bootstrap, #endif #if SDL_VIDEO_DRIVER_AALIB - &AALIB_bootstrap, + &AALIB_bootstrap, #endif #if SDL_VIDEO_DRIVER_DUMMY - &DUMMY_bootstrap, + &DUMMY_bootstrap, #endif #if SDL_VIDEO_DRIVER_GLSDL - &glSDL_bootstrap, + &glSDL_bootstrap, #endif - NULL + NULL }; -SDL_VideoDevice *current_video = NULL; +static SDL_VideoDevice *_this = NULL; /* Various local functions */ -int SDL_VideoInit(const char *driver_name, Uint32 flags); -void SDL_VideoQuit(void); +int SDL_VideoInit (const char *driver_name, Uint32 flags); +void SDL_VideoQuit (void); -static SDL_GrabMode SDL_WM_GrabInputOff(void); +static int +cmpmodes (const void *A, const void *B) +{ + SDL_DisplayMode a = *(const SDL_DisplayMode *) A; + SDL_DisplayMode b = *(const SDL_DisplayMode *) B; + + if (a.w != b.w) { + return b.w - a.w; + } + if (a.h != b.h) { + return b.h - a.h; + } + if (SDL_BITSPERPIXEL (a.format) != SDL_BITSPERPIXEL (b.format)) { + return SDL_BITSPERPIXEL (b.format) - SDL_BITSPERPIXEL (a.format); + } + if (a.refresh_rate != b.refresh_rate) { + return b.refresh_rate - a.refresh_rate; + } + return 0; +} -int SDL_GetNumVideoDrivers(void) +int +SDL_GetNumVideoDrivers (void) { - return(SDL_arraysize(bootstrap)-1); + return SDL_arraysize (bootstrap) - 1; } -const char *SDL_GetVideoDriver(int index) +const char * +SDL_GetVideoDriver (int index) { - if ( index >= 0 && index < SDL_GetNumVideoDrivers() ) { - return(bootstrap[index]->name); - } - return(NULL); + if (index >= 0 && index < SDL_GetNumVideoDrivers ()) { + return bootstrap[index]->name; + } + return NULL; } /* * Initialize the video and event subsystems -- determine native pixel format */ -int SDL_VideoInit (const char *driver_name, Uint32 flags) +int +SDL_VideoInit (const char *driver_name, Uint32 flags) { - SDL_VideoDevice *video; - int index; - int i; - SDL_PixelFormat vformat; - Uint32 video_flags; + SDL_VideoDevice *video; + int index; + int i; + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; - /* Toggle the event thread flags, based on OS requirements */ + /* Toggle the event thread flags, based on OS requirements */ #if defined(MUST_THREAD_EVENTS) - flags |= SDL_INIT_EVENTTHREAD; + flags |= SDL_INIT_EVENTTHREAD; #elif defined(CANT_THREAD_EVENTS) - if ( (flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) { - SDL_SetError("OS doesn't support threaded events"); - return(-1); - } + if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { + SDL_SetError ("OS doesn't support threaded events"); + return -1; + } #endif - /* Check to make sure we don't overwrite 'current_video' */ - if ( current_video != NULL ) { - SDL_VideoQuit(); - } - - /* Select the proper video driver */ - index = 0; - video = NULL; - if ( driver_name != NULL ) { -#if 0 /* This will be replaced with a better driver selection API */ - if ( SDL_strrchr(driver_name, ':') != NULL ) { - index = atoi(SDL_strrchr(driver_name, ':')+1); - } -#endif - for ( i=0; bootstrap[i]; ++i ) { - if ( SDL_strncmp(bootstrap[i]->name, driver_name, - SDL_strlen(bootstrap[i]->name)) == 0 ) { - if ( bootstrap[i]->available() ) { - video = bootstrap[i]->create(index); - break; - } - } - } - } else { - for ( i=0; bootstrap[i]; ++i ) { - if ( bootstrap[i]->available() ) { - video = bootstrap[i]->create(index); - if ( video != NULL ) { - break; - } - } - } - } - if ( video == NULL ) { - SDL_SetError("No available video device"); - return(-1); - } - current_video = video; - current_video->name = bootstrap[i]->name; - - /* Do some basic variable initialization */ - video->screen = NULL; - video->shadow = NULL; - video->visible = NULL; - video->physpal = NULL; - video->gammacols = NULL; - video->gamma = NULL; - video->wm_title = NULL; - video->wm_icon = NULL; - video->offset_x = 0; - video->offset_y = 0; - SDL_memset(&video->info, 0, (sizeof video->info)); - - video->displayformatalphapixel = NULL; - - /* Set some very sane GL defaults */ - video->gl_config.driver_loaded = 0; - video->gl_config.dll_handle = NULL; - video->gl_config.red_size = 3; - video->gl_config.green_size = 3; - video->gl_config.blue_size = 2; - video->gl_config.alpha_size = 0; - video->gl_config.buffer_size = 0; - video->gl_config.depth_size = 16; - video->gl_config.stencil_size = 0; - video->gl_config.double_buffer = 1; - video->gl_config.accum_red_size = 0; - video->gl_config.accum_green_size = 0; - video->gl_config.accum_blue_size = 0; - video->gl_config.accum_alpha_size = 0; - video->gl_config.stereo = 0; - video->gl_config.multisamplebuffers = 0; - video->gl_config.multisamplesamples = 0; - video->gl_config.accelerated = -1; /* not known, don't set */ - video->gl_config.swap_control = -1; /* not known, don't set */ - - /* Initialize the video subsystem */ - SDL_memset(&vformat, 0, sizeof(vformat)); - if ( video->VideoInit(video, &vformat) < 0 ) { - SDL_VideoQuit(); - return(-1); - } - - /* Create a zero sized video surface of the appropriate format */ - video_flags = SDL_SWSURFACE; - SDL_VideoSurface = SDL_CreateRGBSurface(video_flags, 0, 0, - vformat.BitsPerPixel, - vformat.Rmask, vformat.Gmask, vformat.Bmask, 0); - if ( SDL_VideoSurface == NULL ) { - SDL_VideoQuit(); - return(-1); - } - SDL_PublicSurface = NULL; /* Until SDL_SetVideoMode() */ - -#if 0 /* Don't change the current palette - may be used by other programs. - * The application can't do anything with the display surface until - * a video mode has been set anyway. :) - */ - /* If we have a palettized surface, create a default palette */ - if ( SDL_VideoSurface->format->palette ) { - SDL_PixelFormat *vf = SDL_VideoSurface->format; - SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); - video->SetColors(video, - 0, vf->palette->ncolors, vf->palette->colors); - } -#endif - video->info.vfmt = SDL_VideoSurface->format; + /* Check to make sure we don't overwrite '_this' */ + if (_this != NULL) { + SDL_VideoQuit (); + } + + /* Select the proper video driver */ + index = 0; + video = NULL; + if (driver_name != NULL) { + for (i = 0; bootstrap[i]; ++i) { + if (SDL_strncmp (bootstrap[i]->name, driver_name, + SDL_strlen (bootstrap[i]->name)) == 0) { + if (bootstrap[i]->available ()) { + video = bootstrap[i]->create (index); + } + break; + } + } + } else { + for (i = 0; bootstrap[i]; ++i) { + if (bootstrap[i]->available ()) { + video = bootstrap[i]->create (index); + if (video != NULL) { + break; + } + } + } + } + if (video == NULL) { + if (driver_name) { + SDL_SetError ("%s not available", driver_name); + } else { + SDL_SetError ("No available video device"); + } + return -1; + } + _this = video; + _this->name = bootstrap[i]->name; + _this->next_window_id = 1; + + /* Set some very sane GL defaults */ + _this->gl_config.driver_loaded = 0; + _this->gl_config.dll_handle = NULL; + _this->gl_config.red_size = 3; + _this->gl_config.green_size = 3; + _this->gl_config.blue_size = 2; + _this->gl_config.alpha_size = 0; + _this->gl_config.buffer_size = 0; + _this->gl_config.depth_size = 16; + _this->gl_config.stencil_size = 0; + _this->gl_config.double_buffer = 1; + _this->gl_config.accum_red_size = 0; + _this->gl_config.accum_green_size = 0; + _this->gl_config.accum_blue_size = 0; + _this->gl_config.accum_alpha_size = 0; + _this->gl_config.stereo = 0; + _this->gl_config.multisamplebuffers = 0; + _this->gl_config.multisamplesamples = 0; + _this->gl_config.accelerated = -1; /* not known, don't set */ + _this->gl_config.swap_control = -1; /* not known, don't set */ + + /* Initialize the video subsystem */ + if (_this->VideoInit (_this) < 0) { + SDL_VideoQuit (); + return -1; + } + + /* Make sure some displays were added */ + if (_this->num_displays == 0) { + SDL_SetError ("The video driver did not add any displays"); + SDL_VideoQuit (); + return (-1); + } + + /* Sort the video modes */ + for (i = 0; i < _this->num_displays; ++i) { + SDL_qsort (_this->displays[i].display_modes, + _this->displays[i].num_display_modes, + sizeof (SDL_DisplayMode), cmpmodes); + } + + /* Start the event loop */ + if (SDL_StartEventLoop (flags) < 0) { + SDL_VideoQuit (); + return -1; + } + SDL_CursorInit (flags & SDL_INIT_EVENTTHREAD); + + /* We're ready to go! */ + return 0; +} - /* Start the event loop */ - if ( SDL_StartEventLoop(flags) < 0 ) { - SDL_VideoQuit(); - return(-1); - } - SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD); +const char * +SDL_GetCurrentVideoDriver () +{ + if (!_this) { + return NULL; + } + return _this->name; +} - /* We're ready to go! */ - return(0); +SDL_VideoDevice * +SDL_GetVideoDevice () +{ + return _this; } -const char *SDL_GetCurrentVideoDriver() +const SDL_VideoInfo * +SDL_GetVideoInfo (void) { - if ( current_video ) { - return current_video->name; - } - return(NULL); + if (!_this) { + return NULL; + } + return &_this->info; } -/* - * Get the current display surface - */ -SDL_Surface *SDL_GetVideoSurface(void) +void +SDL_AddBasicVideoDisplay (const SDL_DisplayMode * desktop_mode) { - SDL_Surface *visible; + SDL_VideoDisplay display; + + SDL_zero (display); + if (desktop_mode) { + display.desktop_mode = *desktop_mode; + } + display.current_mode = display.desktop_mode; + display.max_windows = 1; - visible = NULL; - if ( current_video ) { - visible = current_video->visible; - } - return(visible); + SDL_AddVideoDisplay (&display); } -/* - * Get the current information about the video hardware - */ -const SDL_VideoInfo *SDL_GetVideoInfo(void) +void +SDL_AddVideoDisplay (SDL_VideoDisplay * display) { - const SDL_VideoInfo *info; + SDL_VideoDisplay *displays; + + displays = + SDL_realloc (_this->displays, + (_this->num_displays + 1) * sizeof (*displays)); + if (displays) { + displays[_this->num_displays] = *display; + _this->displays = displays; + _this->num_displays++; + } +} - info = NULL; - if ( current_video ) { - info = ¤t_video->info; - } - return(info); +int +SDL_GetNumVideoDisplays (void) +{ + if (!_this) { + return 0; + } + return _this->num_displays; } -/* - * Return a pointer to an array of available screen dimensions for the - * given format, sorted largest to smallest. Returns NULL if there are - * no dimensions available for a particular format, or (SDL_Rect **)-1 - * if any dimension is okay for the given format. If 'format' is NULL, - * the mode list will be for the format given by SDL_GetVideoInfo()->vfmt - */ -SDL_Rect ** SDL_ListModes (SDL_PixelFormat *format, Uint32 flags) +int +SDL_SelectVideoDisplay (int index) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - SDL_Rect **modes; - - modes = NULL; - if ( SDL_VideoSurface ) { - if ( format == NULL ) { - format = SDL_VideoSurface->format; - } - modes = video->ListModes(this, format, flags); - } - return(modes); + if (!_this) { + SDL_SetError ("Video subsystem has not been initialized"); + return (-1); + } + if (index >= 0) { + if (index >= _this->num_displays) { + SDL_SetError ("index must be in the range 0 - %d", + _this->num_displays - 1); + return -1; + } + _this->current_display = index; + } + return _this->current_display; } -/* - * Check to see if a particular video mode is supported. - * It returns 0 if the requested mode is not supported under any bit depth, - * or returns the bits-per-pixel of the closest available mode with the - * given width and height. If this bits-per-pixel is different from the - * one used when setting the video mode, SDL_SetVideoMode() will succeed, - * but will emulate the requested bits-per-pixel with a shadow surface. - */ -static Uint8 SDL_closest_depths[4][8] = { - /* 8 bit closest depth ordering */ - { 0, 8, 16, 15, 32, 24, 0, 0 }, - /* 15,16 bit closest depth ordering */ - { 0, 16, 15, 32, 24, 8, 0, 0 }, - /* 24 bit closest depth ordering */ - { 0, 24, 32, 16, 15, 8, 0, 0 }, - /* 32 bit closest depth ordering */ - { 0, 32, 16, 15, 24, 8, 0, 0 } -}; +void +SDL_AddDisplayMode (int display, const SDL_DisplayMode * mode) +{ + SDL_DisplayMode *modes; + int i, nmodes; + + /* Make sure we don't already have the mode in the list */ + modes = SDL_CurrentDisplay.display_modes; + nmodes = SDL_CurrentDisplay.num_display_modes; + for (i = 0; i < nmodes; ++i) { + if (SDL_memcmp (mode, &modes[i], sizeof (*mode)) == 0) { + return; + } + } + + /* Go ahead and add the new mode */ + modes = SDL_realloc (modes, (nmodes + 1) * sizeof (*mode)); + if (modes) { + SDL_CurrentDisplay.display_modes = modes; + modes[nmodes] = *mode; + SDL_CurrentDisplay.num_display_modes++; + } +} +int +SDL_GetNumDisplayModes () +{ + if (_this) { + return SDL_CurrentDisplay.num_display_modes; + } + return 0; +} -#ifdef __MACOS__ /* MPW optimization bug? */ -#define NEGATIVE_ONE 0xFFFFFFFF -#else -#define NEGATIVE_ONE -1 -#endif +const SDL_DisplayMode * +SDL_GetDisplayMode (int index) +{ + if (index < 0 || index >= SDL_GetNumDisplayModes ()) { + SDL_SetError ("index must be in the range of 0 - %d", + SDL_GetNumDisplayModes ()); + return NULL; + } + return &SDL_CurrentDisplay.display_modes[index]; +} -int SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags) +const SDL_DisplayMode * +SDL_GetDesktopDisplayMode (void) { - int table, b, i; - int supported; - SDL_PixelFormat format; - SDL_Rect **sizes; - - /* Currently 1 and 4 bpp are not supported */ - if ( bpp < 8 || bpp > 32 ) { - return(0); - } - if ( (width <= 0) || (height <= 0) ) { - return(0); - } - - /* Search through the list valid of modes */ - SDL_memset(&format, 0, sizeof(format)); - supported = 0; - table = ((bpp+7)/8)-1; - SDL_closest_depths[table][0] = bpp; - SDL_closest_depths[table][7] = 0; - for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { - format.BitsPerPixel = SDL_closest_depths[table][b]; - sizes = SDL_ListModes(&format, flags); - if ( sizes == (SDL_Rect **)0 ) { - /* No sizes supported at this bit-depth */ - continue; - } else - if (sizes == (SDL_Rect **)NEGATIVE_ONE) { - /* Any size supported at this bit-depth */ - supported = 1; - continue; - } else if (current_video->handles_any_size) { - /* Driver can center a smaller surface to simulate fullscreen */ - for ( i=0; sizes[i]; ++i ) { - if ((sizes[i]->w >= width) && (sizes[i]->h >= height)) { - supported = 1; /* this mode can fit the centered window. */ - break; - } - } - } else - for ( i=0; sizes[i]; ++i ) { - if ((sizes[i]->w == width) && (sizes[i]->h == height)) { - supported = 1; - break; - } - } - } - if ( supported ) { - --b; - return(SDL_closest_depths[table][b]); - } else { - return(0); - } + if (_this) { + return &SDL_CurrentDisplay.desktop_mode; + } + return NULL; } -/* - * Get the closest non-emulated video mode to the one requested - */ -static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags) +const SDL_DisplayMode * +SDL_GetCurrentDisplayMode (void) { - int table, b, i; - int supported; - int native_bpp; - SDL_PixelFormat format; - SDL_Rect **sizes; - - /* Check parameters */ - if ( *BitsPerPixel < 8 || *BitsPerPixel > 32 ) { - SDL_SetError("Invalid bits per pixel (range is {8...32})"); - return(0); - } - if ((*w <= 0) || (*h <= 0)) { - SDL_SetError("Invalid width or height"); - return(0); - } - - /* Try the original video mode, get the closest depth */ - native_bpp = SDL_VideoModeOK(*w, *h, *BitsPerPixel, flags); - if ( native_bpp == *BitsPerPixel ) { - return(1); - } - if ( native_bpp > 0 ) { - *BitsPerPixel = native_bpp; - return(1); - } - - /* No exact size match at any depth, look for closest match */ - SDL_memset(&format, 0, sizeof(format)); - supported = 0; - table = ((*BitsPerPixel+7)/8)-1; - SDL_closest_depths[table][0] = *BitsPerPixel; - SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel; - for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { - int best; - - format.BitsPerPixel = SDL_closest_depths[table][b]; - sizes = SDL_ListModes(&format, flags); - if ( sizes == (SDL_Rect **)0 ) { - /* No sizes supported at this bit-depth */ - continue; - } - best=0; - for ( i=0; sizes[i]; ++i ) { - /* Mode with both dimensions bigger or equal than asked ? */ - if ((sizes[i]->w >= *w) && (sizes[i]->h >= *h)) { - /* Mode with any dimension smaller or equal than current best ? */ - if ((sizes[i]->w <= sizes[best]->w) || (sizes[i]->h <= sizes[best]->h)) { - /* Now choose the mode that has less pixels */ - if ((sizes[i]->w * sizes[i]->h) <= (sizes[best]->w * sizes[best]->h)) { - best=i; - supported = 1; - } - } - } - } - if (supported) { - *w=sizes[best]->w; - *h=sizes[best]->h; - *BitsPerPixel = SDL_closest_depths[table][b]; - } - } - if ( ! supported ) { - SDL_SetError("No video mode large enough for %dx%d", *w, *h); - } - return(supported); + if (_this) { + return &SDL_CurrentDisplay.current_mode; + } + return NULL; } -/* This should probably go somewhere else -- like SDL_surface.c */ -static void SDL_ClearSurface(SDL_Surface *surface) +SDL_DisplayMode * +SDL_GetClosestDisplayMode (const SDL_DisplayMode * mode, + SDL_DisplayMode * closest) { - Uint32 black; - - black = SDL_MapRGB(surface->format, 0, 0, 0); - SDL_FillRect(surface, NULL, black); - if ((surface->flags&SDL_HWSURFACE) && (surface->flags&SDL_DOUBLEBUF)) { - SDL_Flip(surface); - SDL_FillRect(surface, NULL, black); - } - SDL_Flip(surface); + Uint32 target_format; + int target_refresh_rate; + int i; + SDL_DisplayMode *current, *match; + + if (!_this || !mode || !closest) { + return NULL; + } + + /* Default to the desktop format */ + if (mode->format) { + target_format = mode->format; + } else { + target_format = SDL_CurrentDisplay.desktop_mode.format; + } + + /* Default to the desktop refresh rate */ + if (mode->refresh_rate) { + target_refresh_rate = mode->refresh_rate; + } else { + target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate; + } + + match = NULL; + for (i = 0; i < SDL_CurrentDisplay.num_display_modes; ++i) { + current = &SDL_CurrentDisplay.display_modes[i]; + + if ((current->w && current->h) && + (current->w < mode->w || current->h < mode->h)) { + /* Out of sorted modes large enough here */ + break; + } + if (!match || current->w < match->w || current->h < match->h) { + match = current; + continue; + } + if (current->format != match->format) { + /* Sorted highest depth to lowest */ + if (current->format == target_format || + (SDL_BITSPERPIXEL (current->format) >= + SDL_BITSPERPIXEL (target_format) + && SDL_PIXELTYPE (current->format) == + SDL_PIXELTYPE (target_format))) { + match = current; + } + continue; + } + if (current->refresh_rate != match->refresh_rate) { + /* Sorted highest refresh to lowest */ + if (current->refresh_rate >= target_refresh_rate) { + match = current; + } + } + } + if (match) { + if (match->format) { + closest->format = match->format; + } else { + closest->format = mode->format; + } + if (match->w && match->h) { + closest->w = match->w; + closest->h = match->h; + } else { + closest->w = mode->w; + closest->h = mode->h; + } + if (match->refresh_rate) { + closest->refresh_rate = match->refresh_rate; + } else { + closest->refresh_rate = mode->refresh_rate; + } + return closest; + } + return NULL; } -/* - * Create a shadow surface suitable for fooling the app. :-) - */ -static void SDL_CreateShadowSurface(int depth) +int +SDL_SetDisplayMode (const SDL_DisplayMode * mode) { - Uint32 Rmask, Gmask, Bmask; - - /* Allocate the shadow surface */ - if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { - Rmask = (SDL_VideoSurface->format)->Rmask; - Gmask = (SDL_VideoSurface->format)->Gmask; - Bmask = (SDL_VideoSurface->format)->Bmask; - } else { - Rmask = Gmask = Bmask = 0; - } - SDL_ShadowSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, - SDL_VideoSurface->w, SDL_VideoSurface->h, - depth, Rmask, Gmask, Bmask, 0); - if ( SDL_ShadowSurface == NULL ) { - return; - } - - /* 8-bit shadow surfaces report that they have exclusive palette */ - if ( SDL_ShadowSurface->format->palette ) { - SDL_ShadowSurface->flags |= SDL_HWPALETTE; - if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { - SDL_memcpy(SDL_ShadowSurface->format->palette->colors, - SDL_VideoSurface->format->palette->colors, - SDL_VideoSurface->format->palette->ncolors* - sizeof(SDL_Color)); - } else { - SDL_DitherColors( - SDL_ShadowSurface->format->palette->colors, depth); - } - } - - /* If the video surface is resizable, the shadow should say so */ - if ( (SDL_VideoSurface->flags & SDL_RESIZABLE) == SDL_RESIZABLE ) { - SDL_ShadowSurface->flags |= SDL_RESIZABLE; - } - /* If the video surface has no frame, the shadow should say so */ - if ( (SDL_VideoSurface->flags & SDL_NOFRAME) == SDL_NOFRAME ) { - SDL_ShadowSurface->flags |= SDL_NOFRAME; - } - /* If the video surface is fullscreen, the shadow should say so */ - if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { - SDL_ShadowSurface->flags |= SDL_FULLSCREEN; - } - /* If the video surface is flippable, the shadow should say so */ - if ( (SDL_VideoSurface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { - SDL_ShadowSurface->flags |= SDL_DOUBLEBUF; - } - return; + SDL_DisplayMode display_mode; + + if (!_this) { + SDL_SetError ("Video subsystem has not been initialized"); + return -1; + } + + /* Make sure there's an actual display mode to set */ + if (!mode) { + SDL_SetError ("No mode passed to SDL_SetDisplayMode"); + return -1; + } + display_mode = *mode; + + /* Default to the current mode */ + if (!display_mode.format) { + display_mode.format = SDL_CurrentDisplay.current_mode.format; + } + if (!display_mode.w) { + display_mode.w = SDL_CurrentDisplay.current_mode.w; + } + if (!display_mode.h) { + display_mode.h = SDL_CurrentDisplay.current_mode.h; + } + if (!display_mode.refresh_rate) { + display_mode.refresh_rate = + SDL_CurrentDisplay.current_mode.refresh_rate; + } + + /* Get a good video mode, the closest one possible */ + if (!SDL_GetClosestDisplayMode (&display_mode, &display_mode)) { + SDL_SetError ("No video mode large enough for %dx%d", + display_mode.w, display_mode.h); + return -1; + } + + /* See if there's anything left to do */ + if (SDL_memcmp + (&display_mode, SDL_GetCurrentDisplayMode (), + sizeof (display_mode)) == 0) { + return 0; + } + + return _this->SetDisplayMode (_this, &display_mode); } -#ifdef __QNXNTO__ - #include -#endif /* __QNXNTO__ */ +SDL_WindowID +SDL_CreateWindow (const char *title, int x, int y, int w, int h, Uint32 flags) +{ + const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | + SDL_WINDOW_BORDERLESS | + SDL_WINDOW_SHOWN | + SDL_WINDOW_OPENGL | + SDL_WINDOW_RESIZABLE | + SDL_WINDOW_MAXIMIZED | + SDL_WINDOW_MINIMIZED | + SDL_WINDOW_INPUT_GRABBED); + SDL_Window window; + int num_windows; + SDL_Window *windows; + + if (!_this) { + SDL_SetError ("Video subsystem has not been initialized"); + return 0; + } + + SDL_zero (window); + window.id = _this->next_window_id++; + window.title = SDL_strdup (title); + window.x = x; + window.y = y; + window.w = w; + window.h = h; + window.flags = (flags & allowed_flags); + + if (_this->CreateWindow && _this->CreateWindow (_this, &window) < 0) { + SDL_free (window.title); + return 0; + } + + num_windows = SDL_CurrentDisplay.num_windows; + windows = + SDL_realloc (SDL_CurrentDisplay.windows, + (num_windows + 1) * sizeof (*windows)); + if (!windows) { + if (_this->DestroyWindow) { + _this->DestroyWindow (_this, &window); + } + SDL_free (window.title); + return 0; + } + windows[num_windows] = window; + SDL_CurrentDisplay.windows = windows; + SDL_CurrentDisplay.num_windows++; + + return window.id; +} -/* - * Set the requested video mode, allocating a shadow buffer if necessary. - */ -SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) +SDL_WindowID +SDL_CreateWindowFrom (void *data) { - SDL_VideoDevice *video, *this; - SDL_Surface *prev_mode, *mode; - int video_w; - int video_h; - int video_bpp; - int is_opengl; - SDL_GrabMode saved_grab; - - /* Start up the video driver, if necessary.. - WARNING: This is the only function protected this way! - */ - if ( ! current_video ) { - if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) { - return(NULL); - } - } - this = video = current_video; - - /* Default to the current width and height */ - if ( width == 0 ) { - width = video->info.current_w; - } - if ( height == 0 ) { - height = video->info.current_h; - } - /* Default to the current video bpp */ - if ( bpp == 0 ) { - flags |= SDL_ANYFORMAT; - bpp = SDL_VideoSurface->format->BitsPerPixel; - } - - /* Get a good video mode, the closest one possible */ - video_w = width; - video_h = height; - video_bpp = bpp; - if ( ! SDL_GetVideoMode(&video_w, &video_h, &video_bpp, flags) ) { - return(NULL); - } - - /* Check the requested flags */ - if ( flags & SDL_INTERNALOPENGL ) { - SDL_SetError("SDL_INTERNALOPENGL is for internal use only"); - return(NULL); - } - if ( video_bpp > 8 ) { - /* There's no palette in > 8 bits-per-pixel mode */ - flags &= ~SDL_HWPALETTE; - } -#if 0 - if ( (flags&SDL_FULLSCREEN) != SDL_FULLSCREEN ) { - /* There's no windowed double-buffering */ - flags &= ~SDL_DOUBLEBUF; - } -#endif - if ( (flags&SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { - /* Use hardware surfaces when double-buffering */ - flags |= SDL_HWSURFACE; - } - - is_opengl = ( ( flags & SDL_OPENGL ) == SDL_OPENGL ); - if ( is_opengl ) { - /* These flags are for 2D video modes only */ - flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF); - /* This flag tells the backends to treat the surface accordingly */ - flags |= SDL_INTERNALOPENGL; - } - - /* Reset the keyboard here so event callbacks can run */ - SDL_ResetKeyboard(); - SDL_ResetMouse(); - SDL_cursorstate &= ~CURSOR_USINGSW; - - /* Clean up any previous video mode */ - if ( SDL_PublicSurface != NULL ) { - SDL_PublicSurface = NULL; - } - if ( SDL_ShadowSurface != NULL ) { - SDL_Surface *ready_to_go; - ready_to_go = SDL_ShadowSurface; - SDL_ShadowSurface = NULL; - SDL_FreeSurface(ready_to_go); - } - if ( video->physpal ) { - SDL_free(video->physpal->colors); - SDL_free(video->physpal); - video->physpal = NULL; - } - if( video->gammacols) { - SDL_free(video->gammacols); - video->gammacols = NULL; - } - - /* Save the previous grab state and turn off grab for mode switch */ - saved_grab = SDL_WM_GrabInputOff(); - - /* Try to set the video mode, along with offset and clipping */ - prev_mode = SDL_VideoSurface; - SDL_LockCursor(); - SDL_VideoSurface = NULL; /* In case it's freed by driver */ - mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags); - if ( mode ) { /* Prevent resize events from mode change */ - /* But not on OS/2 */ -#ifndef __OS2__ - SDL_PrivateResize(mode->w, mode->h); -#endif + SDL_Window window; + int num_windows; + SDL_Window *windows; + + if (!_this) { + SDL_SetError ("Video subsystem has not been initialized"); + return (0); + } + + SDL_zero (window); + window.id = _this->next_window_id++; + + if (!_this->CreateWindowFrom || + _this->CreateWindowFrom (_this, &window, data) < 0) { + return 0; + } + + num_windows = SDL_CurrentDisplay.num_windows; + windows = + SDL_realloc (SDL_CurrentDisplay.windows, + (num_windows + 1) * sizeof (*windows)); + if (!windows) { + if (_this->DestroyWindow) { + _this->DestroyWindow (_this, &window); + } + SDL_free (window.title); + return 0; + } + windows[num_windows] = window; + SDL_CurrentDisplay.windows = windows; + SDL_CurrentDisplay.num_windows++; + + return window.id; +} - /* Sam - If we asked for OpenGL mode, and didn't get it, fail */ - if ( is_opengl && !(mode->flags & SDL_INTERNALOPENGL) ) { - mode = NULL; - SDL_SetError("OpenGL not available"); - } - } - /* - * rcg11292000 - * If you try to set an SDL_OPENGL surface, and fail to find a - * matching visual, then the next call to SDL_SetVideoMode() - * will segfault, since we no longer point to a dummy surface, - * but rather NULL. - * Sam 11/29/00 - * WARNING, we need to make sure that the previous mode hasn't - * already been freed by the video driver. What do we do in - * that case? Should we call SDL_VideoInit() again? - */ - SDL_VideoSurface = (mode != NULL) ? mode : prev_mode; - - if ( (mode != NULL) && (!is_opengl) ) { - /* Sanity check */ - if ( (mode->w < width) || (mode->h < height) ) { - SDL_SetError("Video mode smaller than requested"); - return(NULL); - } - - /* If we have a palettized surface, create a default palette */ - if ( mode->format->palette ) { - SDL_PixelFormat *vf = mode->format; - SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); - video->SetColors(this, 0, vf->palette->ncolors, - vf->palette->colors); - } - - /* Clear the surface to black */ - video->offset_x = 0; - video->offset_y = 0; - mode->offset = 0; - SDL_SetClipRect(mode, NULL); - SDL_ClearSurface(mode); - - /* Now adjust the offsets to match the desired mode */ - video->offset_x = (mode->w-width)/2; - video->offset_y = (mode->h-height)/2; - mode->offset = video->offset_y*mode->pitch + - video->offset_x*mode->format->BytesPerPixel; -#ifdef DEBUG_VIDEO - fprintf(stderr, - "Requested mode: %dx%dx%d, obtained mode %dx%dx%d (offset %d)\n", - width, height, bpp, - mode->w, mode->h, mode->format->BitsPerPixel, mode->offset); -#endif - mode->w = width; - mode->h = height; - SDL_SetClipRect(mode, NULL); - } - SDL_ResetCursor(); - SDL_UnlockCursor(); - - /* If we failed setting a video mode, return NULL... (Uh Oh!) */ - if ( mode == NULL ) { - return(NULL); - } - - /* If there is no window manager, set the SDL_NOFRAME flag */ - if ( ! video->info.wm_available ) { - mode->flags |= SDL_NOFRAME; - } - - /* Reset the mouse cursor and grab for new video mode */ - SDL_SetCursor(NULL); - if ( video->UpdateMouse ) { - video->UpdateMouse(this); - } - SDL_WM_GrabInput(saved_grab); - SDL_GetRelativeMouseState(NULL, NULL); /* Clear first large delta */ - -#if SDL_VIDEO_OPENGL - /* Load GL symbols (before MakeCurrent, where we need glGetString). */ - if ( flags & SDL_INTERNALOPENGL ) { - -#if defined(__QNXNTO__) && (_NTO_VERSION < 630) -#define __SDL_NOGETPROCADDR__ -#elif defined(__MINT__) -#define __SDL_NOGETPROCADDR__ -#endif -#ifdef __SDL_NOGETPROCADDR__ - #define SDL_PROC(ret,func,params) video->func=func; -#else - #define SDL_PROC(ret,func,params) \ - do { \ - video->func = SDL_GL_GetProcAddress(#func); \ - if ( ! video->func ) { \ - SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ - return(NULL); \ - } \ - } while ( 0 ); - -#endif /* __SDL_NOGETPROCADDR__ */ - -#include "SDL_glfuncs.h" -#undef SDL_PROC - } -#endif /* SDL_VIDEO_OPENGL */ - - /* If we're running OpenGL, make the context current */ - if ( (video->screen->flags & SDL_INTERNALOPENGL) && - video->GL_MakeCurrent ) { - if ( video->GL_MakeCurrent(this) < 0 ) { - return(NULL); - } - } - - /* Create a shadow surface if necessary */ - /* There are three conditions under which we create a shadow surface: - 1. We need a particular bits-per-pixel that we didn't get. - 2. We need a hardware palette and didn't get one. - 3. We need a software surface and got a hardware surface. - */ - if ( !(SDL_VideoSurface->flags & SDL_OPENGL) && - ( - ( !(flags&SDL_ANYFORMAT) && - (SDL_VideoSurface->format->BitsPerPixel != bpp)) || - ( (flags&SDL_HWPALETTE) && - !(SDL_VideoSurface->flags&SDL_HWPALETTE)) || - /* If the surface is in hardware, video writes are visible - as soon as they are performed, so we need to buffer them - */ - ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) && - (SDL_VideoSurface->flags&SDL_HWSURFACE)) || - ( (flags&SDL_DOUBLEBUF) && - (SDL_VideoSurface->flags&SDL_HWSURFACE) && - !(SDL_VideoSurface->flags&SDL_DOUBLEBUF)) - ) ) { - SDL_CreateShadowSurface(bpp); - if ( SDL_ShadowSurface == NULL ) { - SDL_SetError("Couldn't create shadow surface"); - return(NULL); - } - SDL_PublicSurface = SDL_ShadowSurface; - } else { - SDL_PublicSurface = SDL_VideoSurface; - } - video->info.vfmt = SDL_VideoSurface->format; - video->info.current_w = SDL_VideoSurface->w; - video->info.current_h = SDL_VideoSurface->h; - - /* We're done! */ - return(SDL_PublicSurface); +static __inline__ SDL_Window * +SDL_GetWindowFromID (SDL_WindowID windowID) +{ + int i, j; + + if (!_this) { + return NULL; + } + + for (i = 0; i < _this->num_displays; ++i) { + SDL_VideoDisplay *display = &_this->displays[i]; + for (j = 0; j < display->num_windows; ++j) { + SDL_Window *window = &display->windows[j]; + if (window->id == windowID) { + return window; + } + } + } + return NULL; } -/* - * Convert a surface into the video pixel format. - */ -SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface) +SDL_Window * +SDL_GetWindowFromSurface (SDL_Surface * surface) { - Uint32 flags; - - if ( ! SDL_PublicSurface ) { - SDL_SetError("No video mode has been set"); - return(NULL); - } - /* Set the flags appropriate for copying to display surface */ - if (((SDL_PublicSurface->flags&SDL_HWSURFACE) == SDL_HWSURFACE) && current_video->info.blit_hw) - flags = SDL_HWSURFACE; - else - flags = SDL_SWSURFACE; -#ifdef AUTORLE_DISPLAYFORMAT - flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA)); - flags |= SDL_RLEACCELOK; -#else - flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK); -#endif - return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags)); + int i, j; + + if (!_this) { + return NULL; + } + + for (i = 0; i < _this->num_displays; ++i) { + SDL_VideoDisplay *display = &_this->displays[i]; + for (j = 0; j < display->num_windows; ++j) { + SDL_Window *window = &display->windows[j]; + if (surface == window->surface || surface == window->shadow) { + return window; + } + } + } + return NULL; } -/* - * Convert a surface into a format that's suitable for blitting to - * the screen, but including an alpha channel. - */ -SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface) + +Uint32 +SDL_GetWindowFlags (SDL_WindowID windowID) { - SDL_PixelFormat *vf; - SDL_PixelFormat *format; - SDL_Surface *converted; - Uint32 flags; - /* default to ARGB8888 */ - Uint32 amask = 0xff000000; - Uint32 rmask = 0x00ff0000; - Uint32 gmask = 0x0000ff00; - Uint32 bmask = 0x000000ff; - - if ( ! SDL_PublicSurface ) { - SDL_SetError("No video mode has been set"); - return(NULL); - } - vf = SDL_PublicSurface->format; - - switch(vf->BytesPerPixel) { - case 2: - /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}. - For anything else (like ARGB4444) it doesn't matter - since we have no special code for it anyway */ - if ( (vf->Rmask == 0x1f) && - (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) { - rmask = 0xff; - bmask = 0xff0000; - } - break; - - case 3: - case 4: - /* Keep the video format, as long as the high 8 bits are - unused or alpha */ - if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) { - rmask = 0xff; - bmask = 0xff0000; - } - break; - - default: - /* We have no other optimised formats right now. When/if a new - optimised alpha format is written, add the converter here */ - break; - } - format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); - flags = SDL_PublicSurface->flags & SDL_HWSURFACE; - flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); - converted = SDL_ConvertSurface(surface, format, flags); - SDL_FreeFormat(format); - return(converted); + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return 0; + } + return window->flags; } -/* - * Update a specific portion of the physical screen - */ -void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) +void +SDL_SetWindowTitle (SDL_WindowID windowID, const char *title) { - if ( screen ) { - SDL_Rect rect; - - /* Perform some checking */ - if ( w == 0 ) - w = screen->w; - if ( h == 0 ) - h = screen->h; - if ( (int)(x+w) > screen->w ) - return; - if ( (int)(y+h) > screen->h ) - return; - - /* Fill the rectangle */ - rect.x = (Sint16)x; - rect.y = (Sint16)y; - rect.w = (Uint16)w; - rect.h = (Uint16)h; - SDL_UpdateRects(screen, 1, &rect); - } + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return; + } + if (window->title) { + SDL_free (window->title); + } + window->title = SDL_strdup (title); + + if (_this->SetWindowTitle) { + _this->SetWindowTitle (_this, window); + } } -void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects) + +const char * +SDL_GetWindowTitle (SDL_WindowID windowID) { - int i; - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - if ( screen->flags & SDL_OPENGL ) { - SDL_SetError("OpenGL active, use SDL_GL_SwapBuffers()"); - return; - } - if ( screen == SDL_ShadowSurface ) { - /* Blit the shadow surface using saved mapping */ - SDL_Palette *pal = screen->format->palette; - SDL_Color *saved_colors = NULL; - if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { - /* simulated 8bpp, use correct physical palette */ - saved_colors = pal->colors; - if ( video->gammacols ) { - /* gamma-corrected palette */ - pal->colors = video->gammacols; - } else if ( video->physpal ) { - /* physical palette different from logical */ - pal->colors = video->physpal->colors; - } - } - if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { - SDL_LockCursor(); - SDL_DrawCursor(SDL_ShadowSurface); - for ( i=0; icolors = saved_colors; - } - - /* Fall through to video surface update */ - screen = SDL_VideoSurface; - } - if ( screen == SDL_VideoSurface ) { - /* Update the video surface */ - if ( screen->offset ) { - for ( i=0; ioffset_x; - rects[i].y += video->offset_y; - } - video->UpdateRects(this, numrects, rects); - for ( i=0; ioffset_x; - rects[i].y -= video->offset_y; - } - } else { - video->UpdateRects(this, numrects, rects); - } - } + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return NULL; + } + return window->title; } -/* - * Performs hardware double buffering, if possible, or a full update if not. - */ -int SDL_Flip(SDL_Surface *screen) +void +SDL_SetWindowData (SDL_WindowID windowID, void *userdata) { - SDL_VideoDevice *video = current_video; - /* Copy the shadow surface to the video surface */ - if ( screen == SDL_ShadowSurface ) { - SDL_Rect rect; - SDL_Palette *pal = screen->format->palette; - SDL_Color *saved_colors = NULL; - if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { - /* simulated 8bpp, use correct physical palette */ - saved_colors = pal->colors; - if ( video->gammacols ) { - /* gamma-corrected palette */ - pal->colors = video->gammacols; - } else if ( video->physpal ) { - /* physical palette different from logical */ - pal->colors = video->physpal->colors; - } - } - - rect.x = 0; - rect.y = 0; - rect.w = screen->w; - rect.h = screen->h; - if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { - SDL_LockCursor(); - SDL_DrawCursor(SDL_ShadowSurface); - SDL_LowerBlit(SDL_ShadowSurface, &rect, - SDL_VideoSurface, &rect); - SDL_EraseCursor(SDL_ShadowSurface); - SDL_UnlockCursor(); - } else { - SDL_LowerBlit(SDL_ShadowSurface, &rect, - SDL_VideoSurface, &rect); - } - if ( saved_colors ) { - pal->colors = saved_colors; - } - - /* Fall through to video surface update */ - screen = SDL_VideoSurface; - } - if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { - SDL_VideoDevice *this = current_video; - return(video->FlipHWSurface(this, SDL_VideoSurface)); - } else { - SDL_UpdateRect(screen, 0, 0, 0, 0); - } - return(0); + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return; + } + window->userdata = userdata; } -static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, - int firstcolor, int ncolors) +void * +SDL_GetWindowData (SDL_WindowID windowID) { - SDL_Palette *pal = screen->format->palette; - SDL_Palette *vidpal; - - if ( colors != (pal->colors + firstcolor) ) { - SDL_memcpy(pal->colors + firstcolor, colors, - ncolors * sizeof(*colors)); - } - - vidpal = SDL_VideoSurface->format->palette; - if ( (screen == SDL_ShadowSurface) && vidpal ) { - /* - * This is a shadow surface, and the physical - * framebuffer is also indexed. Propagate the - * changes to its logical palette so that - * updates are always identity blits - */ - SDL_memcpy(vidpal->colors + firstcolor, colors, - ncolors * sizeof(*colors)); - } - SDL_FormatChanged(screen); + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return NULL; + } + return window->userdata; } -static int SetPalette_physical(SDL_Surface *screen, - SDL_Color *colors, int firstcolor, int ncolors) +void +SDL_SetWindowPosition (SDL_WindowID windowID, int x, int y) { - SDL_VideoDevice *video = current_video; - int gotall = 1; - - if ( video->physpal ) { - /* We need to copy the new colors, since we haven't - * already done the copy in the logical set above. - */ - SDL_memcpy(video->physpal->colors + firstcolor, - colors, ncolors * sizeof(*colors)); - } - if ( screen == SDL_ShadowSurface ) { - if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) { - /* - * The real screen is also indexed - set its physical - * palette. The physical palette does not include the - * gamma modification, we apply it directly instead, - * but this only happens if we have hardware palette. - */ - screen = SDL_VideoSurface; - } else { - /* - * The video surface is not indexed - invalidate any - * active shadow-to-video blit mappings. - */ - if ( screen->map->dst == SDL_VideoSurface ) { - SDL_InvalidateMap(screen->map); - } - if ( video->gamma ) { - if( ! video->gammacols ) { - SDL_Palette *pp = video->physpal; - if(!pp) - pp = screen->format->palette; - video->gammacols = SDL_malloc(pp->ncolors - * sizeof(SDL_Color)); - SDL_ApplyGamma(video->gamma, - pp->colors, - video->gammacols, - pp->ncolors); - } else { - SDL_ApplyGamma(video->gamma, colors, - video->gammacols - + firstcolor, - ncolors); - } - } - SDL_UpdateRect(screen, 0, 0, 0, 0); - } - } - - if ( screen == SDL_VideoSurface ) { - SDL_Color gcolors[256]; - - if ( video->gamma ) { - SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors); - colors = gcolors; - } - gotall = video->SetColors(video, firstcolor, ncolors, colors); - if ( ! gotall ) { - /* The video flags shouldn't have SDL_HWPALETTE, and - the video driver is responsible for copying back the - correct colors into the video surface palette. - */ - ; - } - SDL_CursorPaletteChanged(); - } - return gotall; + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return; + } + + window->x = x; + window->y = y; + + if (_this->SetWindowPosition) { + _this->SetWindowPosition (_this, window); + } } -/* - * Set the physical and/or logical colormap of a surface: - * Only the screen has a physical colormap. It determines what is actually - * sent to the display. - * The logical colormap is used to map blits to/from the surface. - * 'which' is one or both of SDL_LOGPAL, SDL_PHYSPAL - * - * Return nonzero if all colours were set as requested, or 0 otherwise. - */ -int SDL_SetPalette(SDL_Surface *screen, int which, - SDL_Color *colors, int firstcolor, int ncolors) +void +SDL_GetWindowPosition (SDL_WindowID windowID, int *x, int *y) { - SDL_Palette *pal; - int gotall; - int palsize; - - if ( ! current_video ) { - return 0; - } - if ( screen != SDL_PublicSurface ) { - /* only screens have physical palettes */ - which &= ~SDL_PHYSPAL; - } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) { - /* hardware palettes required for split colormaps */ - which |= SDL_PHYSPAL | SDL_LOGPAL; - } - - /* Verify the parameters */ - pal = screen->format->palette; - if( !pal ) { - return 0; /* not a palettized surface */ - } - gotall = 1; - palsize = 1 << screen->format->BitsPerPixel; - if ( ncolors > (palsize - firstcolor) ) { - ncolors = (palsize - firstcolor); - gotall = 0; - } - - if ( which & SDL_LOGPAL ) { - /* - * Logical palette change: The actual screen isn't affected, - * but the internal colormap is altered so that the - * interpretation of the pixel values (for blits etc) is - * changed. - */ - SetPalette_logical(screen, colors, firstcolor, ncolors); - } - if ( which & SDL_PHYSPAL ) { - SDL_VideoDevice *video = current_video; - /* - * Physical palette change: This doesn't affect the - * program's idea of what the screen looks like, but changes - * its actual appearance. - */ - if(!video) - return gotall; /* video not yet initialized */ - if(!video->physpal && !(which & SDL_LOGPAL) ) { - /* Lazy physical palette allocation */ - int size; - SDL_Palette *pp = SDL_malloc(sizeof(*pp)); - if ( !pp ) { - return 0; - } - current_video->physpal = pp; - pp->ncolors = pal->ncolors; - size = pp->ncolors * sizeof(SDL_Color); - pp->colors = SDL_malloc(size); - if ( !pp->colors ) { - return 0; - } - SDL_memcpy(pp->colors, pal->colors, size); - } - if ( ! SetPalette_physical(screen, - colors, firstcolor, ncolors) ) { - gotall = 0; - } - } - return gotall; + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return; + } + if (x) { + *x = window->x; + } + if (y) { + *y = window->y; + } } -int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor, - int ncolors) +void +SDL_SetWindowSize (SDL_WindowID windowID, int w, int h) { - return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, - colors, firstcolor, ncolors); + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return; + } + + window->w = w; + window->h = h; + + if (_this->SetWindowSize) { + _this->SetWindowSize (_this, window); + } } -/* - * Clean up the video subsystem - */ -void SDL_VideoQuit (void) +void +SDL_GetWindowSize (SDL_WindowID windowID, int *w, int *h) { - SDL_Surface *ready_to_go; - - if ( current_video ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - /* Halt event processing before doing anything else */ - SDL_StopEventLoop(); - - /* Clean up allocated window manager items */ - if ( SDL_PublicSurface ) { - SDL_PublicSurface = NULL; - } - SDL_CursorQuit(); - - /* Just in case... */ - SDL_WM_GrabInputOff(); - - /* Clean up the system video */ - video->VideoQuit(this); - - /* Free any lingering surfaces */ - ready_to_go = SDL_ShadowSurface; - SDL_ShadowSurface = NULL; - SDL_FreeSurface(ready_to_go); - if ( SDL_VideoSurface != NULL ) { - ready_to_go = SDL_VideoSurface; - SDL_VideoSurface = NULL; - SDL_FreeSurface(ready_to_go); - } - SDL_PublicSurface = NULL; - - /* Clean up miscellaneous memory */ - if ( video->physpal ) { - SDL_free(video->physpal->colors); - SDL_free(video->physpal); - video->physpal = NULL; - } - if ( video->gammacols ) { - SDL_free(video->gammacols); - video->gammacols = NULL; - } - if ( video->gamma ) { - SDL_free(video->gamma); - video->gamma = NULL; - } - if ( video->wm_title != NULL ) { - SDL_free(video->wm_title); - video->wm_title = NULL; - } - if ( video->wm_icon != NULL ) { - SDL_free(video->wm_icon); - video->wm_icon = NULL; - } - - /* Finish cleaning up video subsystem */ - video->free(this); - current_video = NULL; - } - return; + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return; + } + if (w) { + *w = window->w; + } + if (h) { + *h = window->h; + } } -/* Load the GL driver library */ -int SDL_GL_LoadLibrary(const char *path) +void +SDL_ShowWindow (SDL_WindowID windowID) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - int retval; - - retval = -1; - if ( video == NULL ) { - SDL_SetError("Video subsystem has not been initialized"); - } else { - if ( video->GL_LoadLibrary ) { - retval = video->GL_LoadLibrary(this, path); - } else { - SDL_SetError("No dynamic GL support in video driver"); - } - } - return(retval); + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window || (window->flags & SDL_WINDOW_SHOWN)) { + return; + } + + window->flags |= SDL_WINDOW_SHOWN; + + if (_this->ShowWindow) { + _this->ShowWindow (_this, window); + } } -void *SDL_GL_GetProcAddress(const char* proc) +void +SDL_HideWindow (SDL_WindowID windowID) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - void *func; - - func = NULL; - if ( video->GL_GetProcAddress ) { - if ( video->gl_config.driver_loaded ) { - func = video->GL_GetProcAddress(this, proc); - } else { - SDL_SetError("No GL driver has been loaded"); - } - } else { - SDL_SetError("No dynamic GL support in video driver"); - } - return func; + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { + return; + } + + window->flags &= ~SDL_WINDOW_SHOWN; + + if (_this->HideWindow) { + _this->HideWindow (_this, window); + } } -/* Set the specified GL attribute for setting up a GL video mode */ -int SDL_GL_SetAttribute( SDL_GLattr attr, int value ) +void +SDL_RaiseWindow (SDL_WindowID windowID) { - int retval; - SDL_VideoDevice *video = current_video; - - retval = 0; - switch (attr) { - case SDL_GL_RED_SIZE: - video->gl_config.red_size = value; - break; - case SDL_GL_GREEN_SIZE: - video->gl_config.green_size = value; - break; - case SDL_GL_BLUE_SIZE: - video->gl_config.blue_size = value; - break; - case SDL_GL_ALPHA_SIZE: - video->gl_config.alpha_size = value; - break; - case SDL_GL_DOUBLEBUFFER: - video->gl_config.double_buffer = value; - break; - case SDL_GL_BUFFER_SIZE: - video->gl_config.buffer_size = value; - break; - case SDL_GL_DEPTH_SIZE: - video->gl_config.depth_size = value; - break; - case SDL_GL_STENCIL_SIZE: - video->gl_config.stencil_size = value; - break; - case SDL_GL_ACCUM_RED_SIZE: - video->gl_config.accum_red_size = value; - break; - case SDL_GL_ACCUM_GREEN_SIZE: - video->gl_config.accum_green_size = value; - break; - case SDL_GL_ACCUM_BLUE_SIZE: - video->gl_config.accum_blue_size = value; - break; - case SDL_GL_ACCUM_ALPHA_SIZE: - video->gl_config.accum_alpha_size = value; - break; - case SDL_GL_STEREO: - video->gl_config.stereo = value; - break; - case SDL_GL_MULTISAMPLEBUFFERS: - video->gl_config.multisamplebuffers = value; - break; - case SDL_GL_MULTISAMPLESAMPLES: - video->gl_config.multisamplesamples = value; - break; - case SDL_GL_ACCELERATED_VISUAL: - video->gl_config.accelerated = value; - break; - case SDL_GL_SWAP_CONTROL: - video->gl_config.swap_control = value; - break; - default: - SDL_SetError("Unknown OpenGL attribute"); - retval = -1; - break; - } - return(retval); + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return; + } + + if (_this->RaiseWindow) { + _this->RaiseWindow (_this, window); + } } -/* Retrieve an attribute value from the windowing system. */ -int SDL_GL_GetAttribute(SDL_GLattr attr, int* value) +void +SDL_MaximizeWindow (SDL_WindowID windowID) { - int retval = -1; - SDL_VideoDevice* video = current_video; - SDL_VideoDevice* this = current_video; - - if ( video->GL_GetAttribute ) { - retval = this->GL_GetAttribute(this, attr, value); - } else { - *value = 0; - SDL_SetError("GL_GetAttribute not supported"); - } - return retval; + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { + return; + } + + window->flags |= SDL_WINDOW_MAXIMIZED; + + if (_this->MaximizeWindow) { + _this->MaximizeWindow (_this, window); + } } -/* Perform a GL buffer swap on the current GL context */ -void SDL_GL_SwapBuffers(void) +void +SDL_MinimizeWindow (SDL_WindowID windowID) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - if ( video->screen->flags & SDL_INTERNALOPENGL ) { - video->GL_SwapBuffers(this); - } else { - SDL_SetError("OpenGL video mode has not been set"); - } + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { + return; + } + + window->flags |= SDL_WINDOW_MINIMIZED; + + if (_this->MinimizeWindow) { + _this->MinimizeWindow (_this, window); + } } -/* - * Sets/Gets the title and icon text of the display window, if any. - */ -void SDL_WM_SetCaption (const char *title, const char *icon) +void +SDL_RestoreWindow (SDL_WindowID windowID) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - if ( video ) { - if ( title ) { - if ( video->wm_title ) { - SDL_free(video->wm_title); - } - video->wm_title = SDL_strdup(title); - } - if ( icon ) { - if ( video->wm_icon ) { - SDL_free(video->wm_icon); - } - video->wm_icon = SDL_strdup(icon); - } - if ( (title || icon) && (video->SetCaption != NULL) ) { - video->SetCaption(this, video->wm_title,video->wm_icon); - } - } + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window + || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { + return; + } + + window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED); + + if (_this->RestoreWindow) { + _this->RestoreWindow (_this, window); + } } -void SDL_WM_GetCaption (char **title, char **icon) + +void +SDL_SetWindowGrab (SDL_WindowID windowID, int mode) { - SDL_VideoDevice *video = current_video; - - if ( video ) { - if ( title ) { - *title = video->wm_title; - } - if ( icon ) { - *icon = video->wm_icon; - } - } + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { + return; + } + + if (mode) { + window->flags |= SDL_WINDOW_INPUT_GRABBED; + } else { + window->flags &= ~SDL_WINDOW_INPUT_GRABBED; + } + + if (_this->SetWindowGrab) { + _this->SetWindowGrab (_this, window); + } } -/* Utility function used by SDL_WM_SetIcon(); - * flags & 1 for color key, flags & 2 for alpha channel. */ -static void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int flags) +int +SDL_GetWindowGrab (SDL_WindowID windowID) { - int x, y; - Uint32 colorkey; -#define SET_MASKBIT(icon, x, y, mask) \ - mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window) { + return 0; + } + + return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); +} + +void +SDL_DestroyWindow (SDL_WindowID windowID) +{ + int i, j; + + if (!_this) { + return; + } + + for (i = 0; i < _this->num_displays; ++i) { + SDL_VideoDisplay *display = &_this->displays[i]; + for (j = 0; j < display->num_windows; ++j) { + SDL_Window *window = &display->windows[j]; + if (window->id != windowID) { + continue; + } + if (window->flags & SDL_WINDOW_INPUT_GRABBED) { + window->flags &= ~SDL_WINDOW_INPUT_GRABBED; + _this->SetWindowGrab (_this, window); + } + if (window->shadow) { + SDL_FreeSurface (window->shadow); + } + if (window->surface) { + SDL_FreeSurface (window->surface); + } + if (_this->DestroyWindow) { + _this->DestroyWindow (_this, window); + } + if (window->title) { + SDL_free (window->title); + } + if (window->gamma) { + SDL_free (window->gamma); + } + if (j != display->num_windows - 1) { + SDL_memcpy (&display->windows[i], + &display->windows[i + 1], + (display->num_windows - i - + 1) * sizeof (*window)); + } + --display->num_windows; + return; + } + } +} + +SDL_Surface * +SDL_CreateWindowSurface (SDL_WindowID windowID, Uint32 format, Uint32 flags) +{ + SDL_Window *window = SDL_GetWindowFromID (windowID); + SDL_Surface *surface; + SDL_Surface *shadow; + Uint32 surface_format; + Uint32 black; + + if (!window) { + return NULL; + } + + if (!_this->CreateWindowSurface) { + return NULL; + } + + if (!window->surface) { + window->surface = _this->CreateWindowSurface (_this, window); + if (!window->surface) { + return NULL; + } + } + + if (window->shadow) { + SDL_FreeSurface (window->shadow); + window->shadow = NULL; + } + + surface = window->surface; + surface_format = + SDL_MasksToPixelFormatEnum (surface->format->BitsPerPixel, + surface->format->Rmask, + surface->format->Gmask, + surface->format->Bmask, + surface->format->Amask); + + /* Create a shadow surface if necessary */ + if ((!(flags & SDL_ANYFORMAT) && (surface_format != format)) || + ((flags & SDL_HWPALETTE) + && !(window->surface->flags & SDL_HWPALETTE))) { + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + SDL_PixelFormatEnumToMasks (format, &bpp, &Rmask, &Gmask, &Bmask, + &Amask); + shadow = + SDL_CreateRGBSurface (SDL_SWSURFACE, surface->w, surface->h, + bpp, Rmask, Gmask, Bmask, Amask); + if (shadow == NULL) { + return NULL; + } + + /* 8-bit shadow surfaces report that they have exclusive palette */ + if (shadow->format->palette) { + shadow->flags |= SDL_HWPALETTE; + if (format == surface_format) { + SDL_memcpy (shadow->format->palette->colors, + surface->format->palette->colors, + surface->format->palette->ncolors * + sizeof (SDL_Color)); + } else { + SDL_DitherColors (shadow->format->palette->colors, bpp); + } + } + surface = window->shadow = shadow; + } + + /* Clear the surface for display */ + { + Uint32 black = SDL_MapRGB (surface->format, 0, 0, 0); + SDL_FillRect (surface, NULL, black); + if (surface->flags & SDL_DOUBLEBUF) { + SDL_Flip (surface); + SDL_FillRect (surface, NULL, black); + } + SDL_Flip (surface); + } + + return surface; +} - colorkey = icon->format->colorkey; - switch (icon->format->BytesPerPixel) { - case 1: { Uint8 *pixels; - for ( y=0; yh; ++y ) { - pixels = (Uint8 *)icon->pixels + y*icon->pitch; - for ( x=0; xw; ++x ) { - if ( *pixels++ == colorkey ) { - SET_MASKBIT(icon, x, y, mask); - } - } - } - } - break; - - case 2: { Uint16 *pixels; - for ( y=0; yh; ++y ) { - pixels = (Uint16 *)icon->pixels + - y*icon->pitch/2; - for ( x=0; xw; ++x ) { - if ( (flags & 1) && *pixels == colorkey ) { - SET_MASKBIT(icon, x, y, mask); - } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) { - SET_MASKBIT(icon, x, y, mask); - } - pixels++; - } - } - } - break; - - case 4: { Uint32 *pixels; - for ( y=0; yh; ++y ) { - pixels = (Uint32 *)icon->pixels + - y*icon->pitch/4; - for ( x=0; xw; ++x ) { - if ( (flags & 1) && *pixels == colorkey ) { - SET_MASKBIT(icon, x, y, mask); - } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) { - SET_MASKBIT(icon, x, y, mask); - } - pixels++; - } - } - } - break; - } +/* + * Convert a surface into the video pixel format. + */ +SDL_Surface * +SDL_DisplayFormat (SDL_Surface * surface) +{ + Uint32 flags; + + if (!SDL_PublicSurface) { + SDL_SetError ("No video mode has been set"); + return (NULL); + } + /* Set the flags appropriate for copying to display surface */ + if (((SDL_PublicSurface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) + && _this->info.blit_hw) + flags = SDL_HWSURFACE; + else + flags = SDL_SWSURFACE; +#ifdef AUTORLE_DISPLAYFORMAT + flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA)); + flags |= SDL_RLEACCELOK; +#else + flags |= + surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK); +#endif + return (SDL_ConvertSurface (surface, SDL_PublicSurface->format, flags)); } /* - * Sets the window manager icon for the display window. + * Convert a surface into a format that's suitable for blitting to + * the screen, but including an alpha channel. */ -void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask) +SDL_Surface * +SDL_DisplayFormatAlpha (SDL_Surface * surface) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - if ( icon && video->SetIcon ) { - /* Generate a mask if necessary, and create the icon! */ - if ( mask == NULL ) { - int mask_len = icon->h*(icon->w+7)/8; - int flags = 0; - mask = (Uint8 *)SDL_malloc(mask_len); - if ( mask == NULL ) { - return; - } - SDL_memset(mask, ~0, mask_len); - if ( icon->flags & SDL_SRCCOLORKEY ) flags |= 1; - if ( icon->flags & SDL_SRCALPHA ) flags |= 2; - if( flags ) { - CreateMaskFromColorKeyOrAlpha(icon, mask, flags); - } - video->SetIcon(video, icon, mask); - SDL_free(mask); - } else { - video->SetIcon(this, icon, mask); - } - } + SDL_PixelFormat *vf; + SDL_PixelFormat *format; + SDL_Surface *converted; + Uint32 flags; + /* default to ARGB8888 */ + Uint32 amask = 0xff000000; + Uint32 rmask = 0x00ff0000; + Uint32 gmask = 0x0000ff00; + Uint32 bmask = 0x000000ff; + + if (!SDL_PublicSurface) { + SDL_SetError ("No video mode has been set"); + return (NULL); + } + vf = SDL_PublicSurface->format; + + switch (vf->BytesPerPixel) { + case 2: + /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}. + For anything else (like ARGB4444) it doesn't matter + since we have no special code for it anyway */ + if ((vf->Rmask == 0x1f) && + (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) { + rmask = 0xff; + bmask = 0xff0000; + } + break; + + case 3: + case 4: + /* Keep the video format, as long as the high 8 bits are + unused or alpha */ + if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) { + rmask = 0xff; + bmask = 0xff0000; + } + break; + + default: + /* We have no other optimised formats right now. When/if a new + optimised alpha format is written, add the converter here */ + break; + } + format = SDL_AllocFormat (32, rmask, gmask, bmask, amask); + flags = SDL_PublicSurface->flags & SDL_HWSURFACE; + flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); + converted = SDL_ConvertSurface (surface, format, flags); + SDL_FreeFormat (format); + return (converted); } /* - * Grab or ungrab the keyboard and mouse input. - * This function returns the final grab mode after calling the - * driver dependent function. + * Update a specific portion of the physical screen */ -static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode) +void +SDL_UpdateRect (SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) +{ + if (screen) { + SDL_Rect rect; + + /* Perform some checking */ + if (w == 0) + w = screen->w; + if (h == 0) + h = screen->h; + if ((int) (x + w) > screen->w) + return; + if ((int) (y + h) > screen->h) + return; + + /* Fill the rectangle */ + rect.x = (Sint16) x; + rect.y = (Sint16) y; + rect.w = (Uint16) w; + rect.h = (Uint16) h; + SDL_UpdateRects (screen, 1, &rect); + } +} +void +SDL_UpdateRects (SDL_Surface * screen, int numrects, SDL_Rect * rects) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; + int i; + SDL_Window *window; + + /* Find the window corresponding to this surface */ + window = SDL_GetWindowFromSurface (screen); + if (!window) { + SDL_SetError ("Couldn't find window associated with surface"); + return; + } + + if (screen->flags & SDL_SHADOW_SURFACE) { + if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { + SDL_LockCursor (); + SDL_DrawCursor (screen); + for (i = 0; i < numrects; ++i) { + SDL_LowerBlit (screen, &rects[i], window->surface, &rects[i]); + } + SDL_EraseCursor (screen); + SDL_UnlockCursor (); + } else { + for (i = 0; i < numrects; ++i) { + SDL_LowerBlit (screen, &rects[i], window->surface, &rects[i]); + } + } + + /* Fall through to video surface update */ + screen = window->surface; + } + if ((screen->flags & SDL_SCREEN_SURFACE) && _this->UpdateWindowSurface) { + /* Update the video surface */ + if (screen->offset) { + int offset_y = screen->offset / screen->pitch; + int offset_x = screen->offset % screen->pitch; + for (i = 0; i < numrects; ++i) { + rects[i].x += offset_x; + rects[i].y += offset_y; + } + _this->UpdateWindowSurface (_this, window, numrects, rects); + for (i = 0; i < numrects; ++i) { + rects[i].x -= offset_x; + rects[i].y -= offset_y; + } + } else { + _this->UpdateWindowSurface (_this, window, numrects, rects); + } + } +} - /* Only do something if we have support for grabs */ - if ( video->GrabInput == NULL ) { - return(video->input_grab); - } +/* + * Performs hardware double buffering, if possible, or a full update if not. + */ +int +SDL_Flip (SDL_Surface * screen) +{ + SDL_Window *window; + + /* Find the window corresponding to this surface */ + window = SDL_GetWindowFromSurface (screen); + if (!window) { + SDL_SetError ("Couldn't find window associated with surface"); + return; + } + + /* Copy the shadow surface to the video surface */ + if (screen->flags & SDL_SHADOW_SURFACE) { + SDL_Rect rect; + + rect.x = 0; + rect.y = 0; + rect.w = screen->w; + rect.h = screen->h; + if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { + SDL_LockCursor (); + SDL_DrawCursor (screen); + SDL_LowerBlit (screen, &rect, window->surface, &rect); + SDL_EraseCursor (screen); + SDL_UnlockCursor (); + } else { + SDL_LowerBlit (screen, &rect, window->surface, &rect); + } + + /* Fall through to video surface update */ + screen = window->surface; + } + if (screen->flags & SDL_DOUBLEBUF) { + _this->FlipWindowSurface (_this, window); + } else { + SDL_UpdateRect (screen, 0, 0, 0, 0); + } + return (0); +} - /* If the final grab mode if off, only then do we actually grab */ -#ifdef DEBUG_GRAB - printf("SDL_WM_GrabInputRaw(%d) ... ", mode); -#endif - if ( mode == SDL_GRAB_OFF ) { - if ( video->input_grab != SDL_GRAB_OFF ) { - mode = video->GrabInput(this, mode); - } - } else { - if ( video->input_grab == SDL_GRAB_OFF ) { - mode = video->GrabInput(this, mode); - } - } - if ( mode != video->input_grab ) { - video->input_grab = mode; - if ( video->CheckMouseMode ) { - video->CheckMouseMode(this); - } - } -#ifdef DEBUG_GRAB - printf("Final mode %d\n", video->input_grab); -#endif +int +SDL_SetColors (SDL_Surface * screen, SDL_Color * colors, int firstcolor, + int ncolors) +{ + SDL_Window *window = NULL; + SDL_Palette *pal; + int gotall; + int palsize; + + /* Verify the parameters */ + pal = screen->format->palette; + if (!pal) { + return 0; /* not a palettized surface */ + } + gotall = 1; + palsize = 1 << screen->format->BitsPerPixel; + if (ncolors > (palsize - firstcolor)) { + ncolors = (palsize - firstcolor); + gotall = 0; + } + + if (colors != (pal->colors + firstcolor)) { + SDL_memcpy (pal->colors + firstcolor, colors, + ncolors * sizeof (*colors)); + } + SDL_FormatChanged (screen); + + if (screen->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) { + window = SDL_GetWindowFromSurface (screen); + if (!window) { + return 0; + } + } + + if (screen->flags & SDL_SHADOW_SURFACE) { + SDL_Palette *vidpal; + + vidpal = window->surface->format->palette; + if (vidpal && vidpal->ncolors == pal->ncolors) { + /* This is a shadow surface, and the physical + * framebuffer is also indexed. Propagate the + * changes to its logical palette so that + * updates are always identity blits + */ + SDL_memcpy (vidpal->colors + firstcolor, colors, + ncolors * sizeof (*colors)); + } + if (window->surface->flags & SDL_HWPALETTE) { + /* Set the physical palette */ + screen = window->surface; + } else { + SDL_UpdateRect (screen, 0, 0, 0, 0); + } + } + + if (screen->flags & SDL_SCREEN_SURFACE) { + if (_this->SetWindowColors) { + gotall = + _this->SetWindowColors (_this, window, firstcolor, ncolors, + colors); + if (!gotall) { + /* The video flags shouldn't have SDL_HWPALETTE, and + the video driver is responsible for copying back the + correct colors into the video surface palette. + */ + ; + } + } + SDL_CursorPaletteChanged (); + } + + return gotall; +} - /* Return the final grab state */ - if ( mode >= SDL_GRAB_FULLSCREEN ) { - mode -= SDL_GRAB_FULLSCREEN; - } - return(mode); +void +SDL_VideoQuit (void) +{ + int i, j; + + if (!_this) { + return; + } + + /* Halt event processing before doing anything else */ + SDL_StopEventLoop (); + + /* Clean up allocated window manager items */ + SDL_CursorQuit (); + + /* Clean up the system video */ + for (i = _this->num_displays; i--;) { + SDL_VideoDisplay *display = &_this->displays[i]; + for (j = display->num_windows; j--;) { + SDL_DestroyWindow (display->windows[i].id); + } + if (display->windows) { + SDL_free (display->windows); + display->windows = NULL; + } + } + _this->VideoQuit (_this); + if (_this->displays) { + SDL_free (_this->displays); + } + _this->free (_this); + _this = NULL; } -SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) + +/* Load the GL driver library */ +int +SDL_GL_LoadLibrary (const char *path) { - SDL_VideoDevice *video = current_video; - - /* If the video isn't initialized yet, we can't do anything */ - if ( ! video ) { - return SDL_GRAB_OFF; - } - - /* Return the current mode on query */ - if ( mode == SDL_GRAB_QUERY ) { - mode = video->input_grab; - if ( mode >= SDL_GRAB_FULLSCREEN ) { - mode -= SDL_GRAB_FULLSCREEN; - } - return(mode); - } - -#ifdef DEBUG_GRAB - printf("SDL_WM_GrabInput(%d) ... ", mode); -#endif - /* If the video surface is fullscreen, we always grab */ - if ( mode >= SDL_GRAB_FULLSCREEN ) { - mode -= SDL_GRAB_FULLSCREEN; - } - if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) { - mode += SDL_GRAB_FULLSCREEN; - } - return(SDL_WM_GrabInputRaw(mode)); + int retval; + + retval = -1; + if (_this == NULL) { + SDL_SetError ("Video subsystem has not been initialized"); + } else { + if (_this->GL_LoadLibrary) { + retval = _this->GL_LoadLibrary (_this, path); + } else { + SDL_SetError ("No dynamic GL support in video driver"); + } + } + return (retval); } -static SDL_GrabMode SDL_WM_GrabInputOff(void) + +void * +SDL_GL_GetProcAddress (const char *proc) { - SDL_GrabMode mode; + void *func; + + func = NULL; + if (_this->GL_GetProcAddress) { + if (_this->gl_config.driver_loaded) { + func = _this->GL_GetProcAddress (_this, proc); + } else { + SDL_SetError ("No GL driver has been loaded"); + } + } else { + SDL_SetError ("No dynamic GL support in video driver"); + } + return func; +} - /* First query the current grab state */ - mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); +/* Set the specified GL attribute for setting up a GL video mode */ +int +SDL_GL_SetAttribute (SDL_GLattr attr, int value) +{ + int retval; + + retval = 0; + switch (attr) { + case SDL_GL_RED_SIZE: + _this->gl_config.red_size = value; + break; + case SDL_GL_GREEN_SIZE: + _this->gl_config.green_size = value; + break; + case SDL_GL_BLUE_SIZE: + _this->gl_config.blue_size = value; + break; + case SDL_GL_ALPHA_SIZE: + _this->gl_config.alpha_size = value; + break; + case SDL_GL_DOUBLEBUFFER: + _this->gl_config.double_buffer = value; + break; + case SDL_GL_BUFFER_SIZE: + _this->gl_config.buffer_size = value; + break; + case SDL_GL_DEPTH_SIZE: + _this->gl_config.depth_size = value; + break; + case SDL_GL_STENCIL_SIZE: + _this->gl_config.stencil_size = value; + break; + case SDL_GL_ACCUM_RED_SIZE: + _this->gl_config.accum_red_size = value; + break; + case SDL_GL_ACCUM_GREEN_SIZE: + _this->gl_config.accum_green_size = value; + break; + case SDL_GL_ACCUM_BLUE_SIZE: + _this->gl_config.accum_blue_size = value; + break; + case SDL_GL_ACCUM_ALPHA_SIZE: + _this->gl_config.accum_alpha_size = value; + break; + case SDL_GL_STEREO: + _this->gl_config.stereo = value; + break; + case SDL_GL_MULTISAMPLEBUFFERS: + _this->gl_config.multisamplebuffers = value; + break; + case SDL_GL_MULTISAMPLESAMPLES: + _this->gl_config.multisamplesamples = value; + break; + case SDL_GL_ACCELERATED_VISUAL: + _this->gl_config.accelerated = value; + break; + case SDL_GL_SWAP_CONTROL: + _this->gl_config.swap_control = value; + break; + default: + SDL_SetError ("Unknown OpenGL attribute"); + retval = -1; + break; + } + return (retval); +} - /* Now explicitly turn off input grab */ - SDL_WM_GrabInputRaw(SDL_GRAB_OFF); +/* Retrieve an attribute value from the windowing system. */ +int +SDL_GL_GetAttribute (SDL_GLattr attr, int *value) +{ + int retval = -1; + + if (_this->GL_GetAttribute) { + retval = _this->GL_GetAttribute (_this, attr, value); + } else { + *value = 0; + SDL_SetError ("GL_GetAttribute not supported"); + } + return retval; +} - /* Return the old state */ - return(mode); +/* Perform a GL buffer swap on the current GL context */ +void +SDL_GL_SwapBuffers (void) +{ + if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) { + _this->GL_SwapBuffers (_this); + } else { + SDL_SetError ("OpenGL video mode has not been set"); + } } -/* - * Iconify the window in window managed environments. - * A successful iconification will result in an SDL_APPACTIVE loss event. - */ -int SDL_WM_IconifyWindow(void) +#if 0 // FIXME +/* Utility function used by SDL_WM_SetIcon(); + * flags & 1 for color key, flags & 2 for alpha channel. */ +static void +CreateMaskFromColorKeyOrAlpha (SDL_Surface * icon, Uint8 * mask, int flags) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - int retval; - - retval = 0; - if ( video->IconifyWindow ) { - retval = video->IconifyWindow(this); - } - return(retval); + int x, y; + Uint32 colorkey; +#define SET_MASKBIT(icon, x, y, mask) \ + mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) + + colorkey = icon->format->colorkey; + switch (icon->format->BytesPerPixel) { + case 1: + { + Uint8 *pixels; + for (y = 0; y < icon->h; ++y) { + pixels = (Uint8 *) icon->pixels + y * icon->pitch; + for (x = 0; x < icon->w; ++x) { + if (*pixels++ == colorkey) { + SET_MASKBIT (icon, x, y, mask); + } + } + } + } + break; + + case 2: + { + Uint16 *pixels; + for (y = 0; y < icon->h; ++y) { + pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2; + for (x = 0; x < icon->w; ++x) { + if ((flags & 1) && *pixels == colorkey) { + SET_MASKBIT (icon, x, y, mask); + } else if ((flags & 2) + && (*pixels & icon->format->Amask) == 0) { + SET_MASKBIT (icon, x, y, mask); + } + pixels++; + } + } + } + break; + + case 4: + { + Uint32 *pixels; + for (y = 0; y < icon->h; ++y) { + pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4; + for (x = 0; x < icon->w; ++x) { + if ((flags & 1) && *pixels == colorkey) { + SET_MASKBIT (icon, x, y, mask); + } else if ((flags & 2) + && (*pixels & icon->format->Amask) == 0) { + SET_MASKBIT (icon, x, y, mask); + } + pixels++; + } + } + } + break; + } } /* - * Toggle fullscreen mode + * Sets the window manager icon for the display window. */ -int SDL_WM_ToggleFullScreen(SDL_Surface *surface) +void +SDL_WM_SetIcon (SDL_Surface * icon, Uint8 * mask) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - int toggled; - - toggled = 0; - if ( SDL_PublicSurface && (surface == SDL_PublicSurface) && - video->ToggleFullScreen ) { - if ( surface->flags & SDL_FULLSCREEN ) { - toggled = video->ToggleFullScreen(this, 0); - if ( toggled ) { - SDL_VideoSurface->flags &= ~SDL_FULLSCREEN; - SDL_PublicSurface->flags &= ~SDL_FULLSCREEN; - } - } else { - toggled = video->ToggleFullScreen(this, 1); - if ( toggled ) { - SDL_VideoSurface->flags |= SDL_FULLSCREEN; - SDL_PublicSurface->flags |= SDL_FULLSCREEN; - } - } - /* Double-check the grab state inside SDL_WM_GrabInput() */ - if ( toggled ) { - SDL_WM_GrabInput(video->input_grab); - } - } - return(toggled); + if (icon && _this->SetIcon) { + /* Generate a mask if necessary, and create the icon! */ + if (mask == NULL) { + int mask_len = icon->h * (icon->w + 7) / 8; + int flags = 0; + mask = (Uint8 *) SDL_malloc (mask_len); + if (mask == NULL) { + return; + } + SDL_memset (mask, ~0, mask_len); + if (icon->flags & SDL_SRCCOLORKEY) + flags |= 1; + if (icon->flags & SDL_SRCALPHA) + flags |= 2; + if (flags) { + CreateMaskFromColorKeyOrAlpha (icon, mask, flags); + } + _this->SetIcon (_this, icon, mask); + SDL_free (mask); + } else { + _this->SetIcon (_this, icon, mask); + } + } } +#endif -/* - * Get some platform dependent window manager information - */ -int SDL_GetWMInfo (SDL_SysWMinfo *info) +SDL_bool +SDL_GetWindowWMInfo (SDL_WindowID windowID, SDL_SysWMinfo * info) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - - if ( video && video->GetWMInfo ) { - return(video->GetWMInfo(this, info)); - } else { - return(0); - } + SDL_Window *window = SDL_GetWindowFromID (windowID); + + if (!window || !_this->GetWindowWMInfo) { + return SDL_FALSE; + } + return (_this->GetWindowWMInfo (_this, window, info)); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index 396b7c0f5..cd24c6ae1 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -29,109 +29,119 @@ #include "SDL_yuv_sw_c.h" -SDL_Overlay *SDL_CreateYUVOverlay(int w, int h, Uint32 format, - SDL_Surface *display) +SDL_Overlay * +SDL_CreateYUVOverlay (int w, int h, Uint32 format, SDL_Surface * display) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - const char *yuv_hwaccel; - SDL_Overlay *overlay; - - if ( (display->flags & SDL_OPENGL) == SDL_OPENGL ) { - SDL_SetError("YUV overlays are not supported in OpenGL mode"); - return NULL; - } - - /* Display directly on video surface, if possible */ - if ( SDL_getenv("SDL_VIDEO_YUV_DIRECT") ) { - if ( (display == SDL_PublicSurface) && - ((SDL_VideoSurface->format->BytesPerPixel == 2) || - (SDL_VideoSurface->format->BytesPerPixel == 4)) ) { - display = SDL_VideoSurface; - } - } - overlay = NULL; - yuv_hwaccel = SDL_getenv("SDL_VIDEO_YUV_HWACCEL"); - if ( ((display == SDL_VideoSurface) && video->CreateYUVOverlay) && - (!yuv_hwaccel || (SDL_atoi(yuv_hwaccel) > 0)) ) { - overlay = video->CreateYUVOverlay(this, w, h, format, display); - } - /* If hardware YUV overlay failed ... */ - if ( overlay == NULL ) { - overlay = SDL_CreateYUV_SW(this, w, h, format, display); - } - return overlay; + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Window *window; + const char *yuv_hwaccel; + SDL_Overlay *overlay; + + window = SDL_GetWindowFromSurface (display); + if (window && (window->flags & SDL_WINDOW_OPENGL)) { + SDL_SetError ("YUV overlays are not supported in OpenGL mode"); + return NULL; + } + + /* Display directly on video surface, if possible */ + if (SDL_getenv ("SDL_VIDEO_YUV_DIRECT")) { + if (window && + ((window->surface->format->BytesPerPixel == 2) || + (window->surface->format->BytesPerPixel == 4))) { + display = window->surface; + } + } + overlay = NULL; + yuv_hwaccel = SDL_getenv ("SDL_VIDEO_YUV_HWACCEL"); + if (((display->flags & SDL_SCREEN_SURFACE) && _this->CreateYUVOverlay) && + (!yuv_hwaccel || (SDL_atoi (yuv_hwaccel) > 0))) { + overlay = _this->CreateYUVOverlay (_this, w, h, format, display); + } + /* If hardware YUV overlay failed ... */ + if (overlay == NULL) { + overlay = SDL_CreateYUV_SW (_this, w, h, format, display); + } + return overlay; } -int SDL_LockYUVOverlay(SDL_Overlay *overlay) +int +SDL_LockYUVOverlay (SDL_Overlay * overlay) { - return overlay->hwfuncs->Lock(current_video, overlay); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + return overlay->hwfuncs->Lock (_this, overlay); } -void SDL_UnlockYUVOverlay(SDL_Overlay *overlay) +void +SDL_UnlockYUVOverlay (SDL_Overlay * overlay) { - overlay->hwfuncs->Unlock(current_video, overlay); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + overlay->hwfuncs->Unlock (_this, overlay); } -int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect) +int +SDL_DisplayYUVOverlay (SDL_Overlay * overlay, SDL_Rect * dstrect) { - SDL_Rect src, dst; - int srcx, srcy, srcw, srch; - int dstx, dsty, dstw, dsth; - - /* Clip the rectangle to the screen area */ - srcx = 0; - srcy = 0; - srcw = overlay->w; - srch = overlay->h; - dstx = dstrect->x; - dsty = dstrect->y; - dstw = dstrect->w; - dsth = dstrect->h; - if ( dstx < 0 ) { - srcw += (dstx * overlay->w) / dstrect->w; - dstw += dstx; - srcx -= (dstx * overlay->w) / dstrect->w; - dstx = 0; - } - if ( (dstx+dstw) > current_video->screen->w ) { - int extra = (dstx+dstw - current_video->screen->w); - srcw -= (extra * overlay->w) / dstrect->w; - dstw -= extra; - } - if ( dsty < 0 ) { - srch += (dsty * overlay->h) / dstrect->h; - dsth += dsty; - srcy -= (dsty * overlay->h) / dstrect->h; - dsty = 0; - } - if ( (dsty+dsth) > current_video->screen->h ) { - int extra = (dsty+dsth - current_video->screen->h); - srch -= (extra * overlay->h) / dstrect->h; - dsth -= extra; - } - if ( srcw <= 0 || srch <= 0 || - srch <= 0 || dsth <= 0 ) { - return 0; - } - /* Ugh, I can't wait for SDL_Rect to be int values */ - src.x = srcx; - src.y = srcy; - src.w = srcw; - src.h = srch; - dst.x = dstx; - dst.y = dsty; - dst.w = dstw; - dst.h = dsth; - return overlay->hwfuncs->Display(current_video, overlay, &src, &dst); + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + SDL_Rect src, dst; + int srcx, srcy, srcw, srch; + int dstx, dsty, dstw, dsth; + + /* Clip the rectangle to the screen area */ + srcx = 0; + srcy = 0; + srcw = overlay->w; + srch = overlay->h; + dstx = dstrect->x; + dsty = dstrect->y; + dstw = dstrect->w; + dsth = dstrect->h; + if (dstx < 0) { + srcw += (dstx * overlay->w) / dstrect->w; + dstw += dstx; + srcx -= (dstx * overlay->w) / dstrect->w; + dstx = 0; + } + if ((dstx + dstw) > SDL_VideoSurface->w) { + int extra = (dstx + dstw - SDL_VideoSurface->w); + srcw -= (extra * overlay->w) / dstrect->w; + dstw -= extra; + } + if (dsty < 0) { + srch += (dsty * overlay->h) / dstrect->h; + dsth += dsty; + srcy -= (dsty * overlay->h) / dstrect->h; + dsty = 0; + } + if ((dsty + dsth) > SDL_VideoSurface->h) { + int extra = (dsty + dsth - SDL_VideoSurface->h); + srch -= (extra * overlay->h) / dstrect->h; + dsth -= extra; + } + if (srcw <= 0 || srch <= 0 || srch <= 0 || dsth <= 0) { + return 0; + } + /* Ugh, I can't wait for SDL_Rect to be int values */ + src.x = srcx; + src.y = srcy; + src.w = srcw; + src.h = srch; + dst.x = dstx; + dst.y = dsty; + dst.w = dstw; + dst.h = dsth; + return overlay->hwfuncs->Display (_this, overlay, &src, &dst); } -void SDL_FreeYUVOverlay(SDL_Overlay *overlay) +void +SDL_FreeYUVOverlay (SDL_Overlay * overlay) { - if ( overlay ) { - if ( overlay->hwfuncs ) { - overlay->hwfuncs->FreeHW(current_video, overlay); - } - SDL_free(overlay); - } + SDL_VideoDevice *_this = SDL_GetVideoDevice (); + if (overlay) { + if (overlay->hwfuncs) { + overlay->hwfuncs->FreeHW (_this, overlay); + } + SDL_free (overlay); + } } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_yuv_mmx.c b/src/video/SDL_yuv_mmx.c index 4a9fb1d67..38bd5626c 100644 --- a/src/video/SDL_yuv_mmx.c +++ b/src/video/SDL_yuv_mmx.c @@ -21,36 +21,55 @@ */ #include "SDL_config.h" -#if 0 /* FIXME: This code needs to be rewritten to reference the static data using relocatable addresses (e.g. http://www.gentoo.org/proj/en/hardened/pic-fix-guide.xml or http://nasm.sourceforge.net/doc/html/nasmdoc8.html#section-8.2) This code currently breaks on systems with readonly text segments (hardened Linux / Intel Mac) */ +#if 0 /* FIXME: This code needs to be rewritten to reference the static data using relocatable addresses (e.g. http://www.gentoo.org/proj/en/hardened/pic-fix-guide.xml or http://nasm.sourceforge.net/doc/html/nasmdoc8.html#section-8.2) This code currently breaks on systems with readonly text segments (hardened Linux / Intel Mac) */ #if defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES #include "SDL_stdinc.h" #define ASM_ARRAY(x) x[] __asm__("_" #x) __attribute__((used)) - -static unsigned int ASM_ARRAY(MMX_0080w) = {0x00800080, 0x00800080}; -static unsigned int ASM_ARRAY(MMX_00FFw) = {0x00ff00ff, 0x00ff00ff}; -static unsigned int ASM_ARRAY(MMX_FF00w) = {0xff00ff00, 0xff00ff00}; -static unsigned short ASM_ARRAY(MMX_Ycoeff) = {0x004a, 0x004a, 0x004a, 0x004a}; - -static unsigned short ASM_ARRAY(MMX_UbluRGB) = {0x0072, 0x0072, 0x0072, 0x0072}; -static unsigned short ASM_ARRAY(MMX_VredRGB) = {0x0059, 0x0059, 0x0059, 0x0059}; -static unsigned short ASM_ARRAY(MMX_UgrnRGB) = {0xffea, 0xffea, 0xffea, 0xffea}; -static unsigned short ASM_ARRAY(MMX_VgrnRGB) = {0xffd2, 0xffd2, 0xffd2, 0xffd2}; - -static unsigned short ASM_ARRAY(MMX_Ublu5x5) = {0x0081, 0x0081, 0x0081, 0x0081}; -static unsigned short ASM_ARRAY(MMX_Vred5x5) = {0x0066, 0x0066, 0x0066, 0x0066}; -static unsigned short ASM_ARRAY(MMX_Ugrn555) = {0xffe7, 0xffe7, 0xffe7, 0xffe7}; -static unsigned short ASM_ARRAY(MMX_Vgrn555) = {0xffcc, 0xffcc, 0xffcc, 0xffcc}; -static unsigned short ASM_ARRAY(MMX_Ugrn565) = {0xffe8, 0xffe8, 0xffe8, 0xffe8}; -static unsigned short ASM_ARRAY(MMX_Vgrn565) = {0xffcd, 0xffcd, 0xffcd, 0xffcd}; - -static unsigned short ASM_ARRAY(MMX_red555) = {0x7c00, 0x7c00, 0x7c00, 0x7c00}; -static unsigned short ASM_ARRAY(MMX_red565) = {0xf800, 0xf800, 0xf800, 0xf800}; -static unsigned short ASM_ARRAY(MMX_grn555) = {0x03e0, 0x03e0, 0x03e0, 0x03e0}; -static unsigned short ASM_ARRAY(MMX_grn565) = {0x07e0, 0x07e0, 0x07e0, 0x07e0}; -static unsigned short ASM_ARRAY(MMX_blu5x5) = {0x001f, 0x001f, 0x001f, 0x001f}; +static unsigned int ASM_ARRAY (MMX_0080w) = { +0x00800080, 0x00800080}; +static unsigned int ASM_ARRAY (MMX_00FFw) = { +0x00ff00ff, 0x00ff00ff}; +static unsigned int ASM_ARRAY (MMX_FF00w) = { +0xff00ff00, 0xff00ff00}; + +static unsigned short ASM_ARRAY (MMX_Ycoeff) = { +0x004a, 0x004a, 0x004a, 0x004a}; + +static unsigned short ASM_ARRAY (MMX_UbluRGB) = { +0x0072, 0x0072, 0x0072, 0x0072}; +static unsigned short ASM_ARRAY (MMX_VredRGB) = { +0x0059, 0x0059, 0x0059, 0x0059}; +static unsigned short ASM_ARRAY (MMX_UgrnRGB) = { +0xffea, 0xffea, 0xffea, 0xffea}; +static unsigned short ASM_ARRAY (MMX_VgrnRGB) = { +0xffd2, 0xffd2, 0xffd2, 0xffd2}; + +static unsigned short ASM_ARRAY (MMX_Ublu5x5) = { +0x0081, 0x0081, 0x0081, 0x0081}; +static unsigned short ASM_ARRAY (MMX_Vred5x5) = { +0x0066, 0x0066, 0x0066, 0x0066}; +static unsigned short ASM_ARRAY (MMX_Ugrn555) = { +0xffe7, 0xffe7, 0xffe7, 0xffe7}; +static unsigned short ASM_ARRAY (MMX_Vgrn555) = { +0xffcc, 0xffcc, 0xffcc, 0xffcc}; +static unsigned short ASM_ARRAY (MMX_Ugrn565) = { +0xffe8, 0xffe8, 0xffe8, 0xffe8}; +static unsigned short ASM_ARRAY (MMX_Vgrn565) = { +0xffcd, 0xffcd, 0xffcd, 0xffcd}; + +static unsigned short ASM_ARRAY (MMX_red555) = { +0x7c00, 0x7c00, 0x7c00, 0x7c00}; +static unsigned short ASM_ARRAY (MMX_red565) = { +0xf800, 0xf800, 0xf800, 0xf800}; +static unsigned short ASM_ARRAY (MMX_grn555) = { +0x03e0, 0x03e0, 0x03e0, 0x03e0}; +static unsigned short ASM_ARRAY (MMX_grn565) = { +0x07e0, 0x07e0, 0x07e0, 0x07e0}; +static unsigned short ASM_ARRAY (MMX_blu5x5) = { +0x001f, 0x001f, 0x001f, 0x001f}; /** This MMX assembler is my first assembler/MMX program ever. @@ -81,330 +100,234 @@ static unsigned short ASM_ARRAY(MMX_blu5x5) = {0x001f, 0x001f, 0x001f, 0x001f}; */ -void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +void +ColorRGBDitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { Uint32 *row1; Uint32 *row2; - unsigned char* y = lum +cols*rows; // Pointer to the end - int x=0; - row1 = (Uint32 *)out; // 32 bit target - row2 = (Uint32 *)out+cols+mod; // start of second row - mod = (mod+cols+mod)*4; // increment for row1 in byte + unsigned char *y = lum + cols * rows; // Pointer to the end + int x = 0; + row1 = (Uint32 *) out; // 32 bit target + row2 = (Uint32 *) out + cols + mod; // start of second row + mod = (mod + cols + mod) * 4; // increment for row1 in byte __asm__ __volatile__ ( /* We don't really care about PIC - the code should be rewritten to use relative addressing for the static tables, so right now we take the COW hit on the pages this code resides. Big deal. This spill is just to reduce register pressure in the PIC case. */ - "pushl %%ebx\n" - "movl %0, %%ebx\n" - - ".align 8\n" - "1:\n" - - // create Cr (result in mm1) - "movd (%%ebx), %%mm1\n" // 0 0 0 0 v3 v2 v1 v0 - "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 - "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0 - "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0 - "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0 - "psubw _MMX_0080w,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 - - // create Cr_g (result in mm0) - "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0 - "pmullw _MMX_VgrnRGB,%%mm0\n"// red*-46dec=0.7136*64 - "pmullw _MMX_VredRGB,%%mm1\n"// red*89dec=1.4013*64 - "psraw $6, %%mm0\n" // red=red/64 - "psraw $6, %%mm1\n" // red=red/64 - - // create L1 L2 (result in mm2,mm4) - // L2=lum+cols - "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0 - "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0 - "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0 - "pand _MMX_FF00w,%%mm2\n" // L3 0 L1 0 l3 0 l1 0 - "pand _MMX_00FFw,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0 - "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1 - - // create R (result in mm6) - "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1 - "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0 - "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1 - "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0 - "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1 - "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0 - "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 - "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0 - - // create Cb (result in mm1) - "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0 - "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0 - "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0 - "psubw _MMX_0080w,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 - // create Cb_g (result in mm5) - "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0 - "pmullw _MMX_UgrnRGB,%%mm5\n" // blue*-109dec=1.7129*64 - "pmullw _MMX_UbluRGB,%%mm1\n" // blue*114dec=1.78125*64 - "psraw $6, %%mm5\n" // blue=red/64 - "psraw $6, %%mm1\n" // blue=blue/64 - - // create G (result in mm7) - "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 - "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1 - "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t - "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t - "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1 - "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0 - "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1 - "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0 - "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0 - - // create B (result in mm5) - "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 - "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1 - "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1 - "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0 - "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1 - "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0 - "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0 - - // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) - - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0 - "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0 - "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0 - // process lower lum - "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0 - "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0 - "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0 - "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0 - "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0 - "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2 - - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "movq %%mm7,%%mm1\n" // G3 G2 G1 G0 g3 g2 g1 g0 - "punpcklbw %%mm1,%%mm2\n" // g3 0 g2 0 g1 0 g0 0 - "punpcklwd %%mm4,%%mm2\n" // 0 0 g1 0 0 0 g0 0 - "por %%mm3, %%mm2\n" // 0 r1 g1 b1 0 r0 g0 b0 - "movq %%mm2,(%3)\n" // wrote out ! row1 - - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "punpcklbw %%mm1,%%mm4\n" // g3 0 g2 0 g1 0 g0 0 - "punpckhwd %%mm2,%%mm4\n" // 0 0 g3 0 0 0 g2 0 - "por %%mm0, %%mm4\n" // 0 r3 g3 b3 0 r2 g2 b2 - "movq %%mm4,8(%3)\n" // wrote out ! row1 - - // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) - // this can be done "destructive" - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "punpckhbw %%mm2,%%mm6\n" // 0 R3 0 R2 0 R1 0 R0 - "punpckhbw %%mm1,%%mm5\n" // G3 B3 G2 B2 G1 B1 G0 B0 - "movq %%mm5,%%mm1\n" // G3 B3 G2 B2 G1 B1 G0 B0 - "punpcklwd %%mm6,%%mm1\n" // 0 R1 G1 B1 0 R0 G0 B0 - "movq %%mm1,(%5)\n" // wrote out ! row2 - "punpckhwd %%mm6,%%mm5\n" // 0 R3 G3 B3 0 R2 G2 B2 - "movq %%mm5,8(%5)\n" // wrote out ! row2 - - "addl $4,%2\n" // lum+4 - "leal 16(%3),%3\n" // row1+16 - "leal 16(%5),%5\n" // row2+16 - "addl $2, %%ebx\n" // cr+2 - "addl $2, %1\n" // cb+2 - - "addl $4,%6\n" // x+4 - "cmpl %4,%6\n" - - "jl 1b\n" - "addl %4, %2\n" // lum += cols - "addl %8, %3\n" // row1+= mod - "addl %8, %5\n" // row2+= mod - "movl $0, %6\n" // x=0 - "cmpl %7, %2\n" - "jl 1b\n" - "emms\n" - "popl %%ebx\n" - : - : "m" (cr), "r"(cb),"r"(lum), - "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)); + "pushl %%ebx\n" + "movl %0, %%ebx\n" ".align 8\n" "1:\n" + // create Cr (result in mm1) + "movd (%%ebx), %%mm1\n" // 0 0 0 0 v3 v2 v1 v0 + "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 + "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0 + "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0 + "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0 + "psubw _MMX_0080w,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 + // create Cr_g (result in mm0) + "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0 + "pmullw _MMX_VgrnRGB,%%mm0\n" // red*-46dec=0.7136*64 + "pmullw _MMX_VredRGB,%%mm1\n" // red*89dec=1.4013*64 + "psraw $6, %%mm0\n" // red=red/64 + "psraw $6, %%mm1\n" // red=red/64 + // create L1 L2 (result in mm2,mm4) + // L2=lum+cols + "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0 + "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0 + "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0 + "pand _MMX_FF00w,%%mm2\n" // L3 0 L1 0 l3 0 l1 0 + "pand _MMX_00FFw,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0 + "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1 + // create R (result in mm6) + "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1 + "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0 + "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1 + "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0 + "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1 + "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0 + "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 + "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0 + // create Cb (result in mm1) + "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0 + "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0 + "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0 + "psubw _MMX_0080w,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 + // create Cb_g (result in mm5) + "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0 + "pmullw _MMX_UgrnRGB,%%mm5\n" // blue*-109dec=1.7129*64 + "pmullw _MMX_UbluRGB,%%mm1\n" // blue*114dec=1.78125*64 + "psraw $6, %%mm5\n" // blue=red/64 + "psraw $6, %%mm1\n" // blue=blue/64 + // create G (result in mm7) + "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 + "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1 + "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t + "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t + "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1 + "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0 + "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1 + "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0 + "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0 + // create B (result in mm5) + "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 + "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1 + "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1 + "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0 + "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1 + "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0 + "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0 + // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) + "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 + "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0 + "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0 + "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0 + // process lower lum + "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0 + "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0 + "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0 + "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0 + "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0 + "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2 + "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 + "movq %%mm7,%%mm1\n" // G3 G2 G1 G0 g3 g2 g1 g0 + "punpcklbw %%mm1,%%mm2\n" // g3 0 g2 0 g1 0 g0 0 + "punpcklwd %%mm4,%%mm2\n" // 0 0 g1 0 0 0 g0 0 + "por %%mm3, %%mm2\n" // 0 r1 g1 b1 0 r0 g0 b0 + "movq %%mm2,(%3)\n" // wrote out ! row1 + "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 + "punpcklbw %%mm1,%%mm4\n" // g3 0 g2 0 g1 0 g0 0 + "punpckhwd %%mm2,%%mm4\n" // 0 0 g3 0 0 0 g2 0 + "por %%mm0, %%mm4\n" // 0 r3 g3 b3 0 r2 g2 b2 + "movq %%mm4,8(%3)\n" // wrote out ! row1 + // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) + // this can be done "destructive" + "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 + "punpckhbw %%mm2,%%mm6\n" // 0 R3 0 R2 0 R1 0 R0 + "punpckhbw %%mm1,%%mm5\n" // G3 B3 G2 B2 G1 B1 G0 B0 + "movq %%mm5,%%mm1\n" // G3 B3 G2 B2 G1 B1 G0 B0 + "punpcklwd %%mm6,%%mm1\n" // 0 R1 G1 B1 0 R0 G0 B0 + "movq %%mm1,(%5)\n" // wrote out ! row2 + "punpckhwd %%mm6,%%mm5\n" // 0 R3 G3 B3 0 R2 G2 B2 + "movq %%mm5,8(%5)\n" // wrote out ! row2 + "addl $4,%2\n" // lum+4 + "leal 16(%3),%3\n" // row1+16 + "leal 16(%5),%5\n" // row2+16 + "addl $2, %%ebx\n" // cr+2 + "addl $2, %1\n" // cb+2 + "addl $4,%6\n" // x+4 + "cmpl %4,%6\n" "jl 1b\n" "addl %4, %2\n" // lum += cols + "addl %8, %3\n" // row1+= mod + "addl %8, %5\n" // row2+= mod + "movl $0, %6\n" // x=0 + "cmpl %7, %2\n" + "jl 1b\n" + "emms\n" + "popl %%ebx\n"::"m" (cr), "r" (cb), "r" (lum), + "r" (row1), "r" (cols), "r" (row2), "m" (x), + "m" (y), "m" (mod)); } -void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +void +Color565DitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { Uint16 *row1; Uint16 *row2; - unsigned char* y = lum +cols*rows; /* Pointer to the end */ - int x=0; - row1 = (Uint16 *)out; /* 16 bit target */ - row2 = (Uint16 *)out+cols+mod; /* start of second row */ - mod = (mod+cols+mod)*2; /* increment for row1 in byte */ - - - __asm__ __volatile__( - "pushl %%ebx\n" - "movl %0, %%ebx\n" - - ".align 8\n" - "1:\n" - "movd (%1), %%mm0\n" // 4 Cb 0 0 0 0 u3 u2 u1 u0 - "pxor %%mm7, %%mm7\n" - "movd (%%ebx), %%mm1\n" // 4 Cr 0 0 0 0 v3 v2 v1 v0 - "punpcklbw %%mm7, %%mm0\n" // 4 W cb 0 u3 0 u2 0 u1 0 u0 - "punpcklbw %%mm7, %%mm1\n" // 4 W cr 0 v3 0 v2 0 v1 0 v0 - "psubw _MMX_0080w, %%mm0\n" - "psubw _MMX_0080w, %%mm1\n" - "movq %%mm0, %%mm2\n" // Cb 0 u3 0 u2 0 u1 0 u0 - "movq %%mm1, %%mm3\n" // Cr - "pmullw _MMX_Ugrn565, %%mm2\n" // Cb2green 0 R3 0 R2 0 R1 0 R0 - "movq (%2), %%mm6\n" // L1 l7 L6 L5 L4 L3 L2 L1 L0 - "pmullw _MMX_Ublu5x5, %%mm0\n" // Cb2blue - "pand _MMX_00FFw, %%mm6\n" // L1 00 L6 00 L4 00 L2 00 L0 - "pmullw _MMX_Vgrn565, %%mm3\n" // Cr2green - "movq (%2), %%mm7\n" // L2 - "pmullw _MMX_Vred5x5, %%mm1\n" // Cr2red - "psrlw $8, %%mm7\n" // L2 00 L7 00 L5 00 L3 00 L1 - "pmullw _MMX_Ycoeff, %%mm6\n" // lum1 - "paddw %%mm3, %%mm2\n" // Cb2green + Cr2green == green - "pmullw _MMX_Ycoeff, %%mm7\n" // lum2 - - "movq %%mm6, %%mm4\n" // lum1 - "paddw %%mm0, %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0 - "movq %%mm4, %%mm5\n" // lum1 - "paddw %%mm1, %%mm4\n" // lum1 +red 00 R6 00 R4 00 R2 00 R0 - "paddw %%mm2, %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0 - "psraw $6, %%mm4\n" // R1 0 .. 64 - "movq %%mm7, %%mm3\n" // lum2 00 L7 00 L5 00 L3 00 L1 - "psraw $6, %%mm5\n" // G1 - .. + - "paddw %%mm0, %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1 - "psraw $6, %%mm6\n" // B1 0 .. 64 - "packuswb %%mm4, %%mm4\n" // R1 R1 - "packuswb %%mm5, %%mm5\n" // G1 G1 - "packuswb %%mm6, %%mm6\n" // B1 B1 - "punpcklbw %%mm4, %%mm4\n" - "punpcklbw %%mm5, %%mm5\n" - - "pand _MMX_red565, %%mm4\n" - "psllw $3, %%mm5\n" // GREEN 1 - "punpcklbw %%mm6, %%mm6\n" - "pand _MMX_grn565, %%mm5\n" - "pand _MMX_red565, %%mm6\n" - "por %%mm5, %%mm4\n" // - "psrlw $11, %%mm6\n" // BLUE 1 - "movq %%mm3, %%mm5\n" // lum2 - "paddw %%mm1, %%mm3\n" // lum2 +red 00 R7 00 R5 00 R3 00 R1 - "paddw %%mm2, %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1 - "psraw $6, %%mm3\n" // R2 - "por %%mm6, %%mm4\n" // MM4 - "psraw $6, %%mm5\n" // G2 - "movq (%2, %4), %%mm6\n" // L3 load lum2 - "psraw $6, %%mm7\n" - "packuswb %%mm3, %%mm3\n" - "packuswb %%mm5, %%mm5\n" - "packuswb %%mm7, %%mm7\n" - "pand _MMX_00FFw, %%mm6\n" // L3 - "punpcklbw %%mm3, %%mm3\n" - "punpcklbw %%mm5, %%mm5\n" - "pmullw _MMX_Ycoeff, %%mm6\n" // lum3 - "punpcklbw %%mm7, %%mm7\n" - "psllw $3, %%mm5\n" // GREEN 2 - "pand _MMX_red565, %%mm7\n" - "pand _MMX_red565, %%mm3\n" - "psrlw $11, %%mm7\n" // BLUE 2 - "pand _MMX_grn565, %%mm5\n" - "por %%mm7, %%mm3\n" - "movq (%2,%4), %%mm7\n" // L4 load lum2 - "por %%mm5, %%mm3\n" // - "psrlw $8, %%mm7\n" // L4 - "movq %%mm4, %%mm5\n" - "punpcklwd %%mm3, %%mm4\n" - "pmullw _MMX_Ycoeff, %%mm7\n" // lum4 - "punpckhwd %%mm3, %%mm5\n" - - "movq %%mm4, (%3)\n" // write row1 - "movq %%mm5, 8(%3)\n" // write row1 - - "movq %%mm6, %%mm4\n" // Lum3 - "paddw %%mm0, %%mm6\n" // Lum3 +blue - - "movq %%mm4, %%mm5\n" // Lum3 - "paddw %%mm1, %%mm4\n" // Lum3 +red - "paddw %%mm2, %%mm5\n" // Lum3 +green - "psraw $6, %%mm4\n" - "movq %%mm7, %%mm3\n" // Lum4 - "psraw $6, %%mm5\n" - "paddw %%mm0, %%mm7\n" // Lum4 +blue - "psraw $6, %%mm6\n" // Lum3 +blue - "movq %%mm3, %%mm0\n" // Lum4 - "packuswb %%mm4, %%mm4\n" - "paddw %%mm1, %%mm3\n" // Lum4 +red - "packuswb %%mm5, %%mm5\n" - "paddw %%mm2, %%mm0\n" // Lum4 +green - "packuswb %%mm6, %%mm6\n" - "punpcklbw %%mm4, %%mm4\n" - "punpcklbw %%mm5, %%mm5\n" - "punpcklbw %%mm6, %%mm6\n" - "psllw $3, %%mm5\n" // GREEN 3 - "pand _MMX_red565, %%mm4\n" - "psraw $6, %%mm3\n" // psr 6 - "psraw $6, %%mm0\n" - "pand _MMX_red565, %%mm6\n" // BLUE - "pand _MMX_grn565, %%mm5\n" - "psrlw $11, %%mm6\n" // BLUE 3 - "por %%mm5, %%mm4\n" - "psraw $6, %%mm7\n" - "por %%mm6, %%mm4\n" - "packuswb %%mm3, %%mm3\n" - "packuswb %%mm0, %%mm0\n" - "packuswb %%mm7, %%mm7\n" - "punpcklbw %%mm3, %%mm3\n" - "punpcklbw %%mm0, %%mm0\n" - "punpcklbw %%mm7, %%mm7\n" - "pand _MMX_red565, %%mm3\n" - "pand _MMX_red565, %%mm7\n" // BLUE - "psllw $3, %%mm0\n" // GREEN 4 - "psrlw $11, %%mm7\n" - "pand _MMX_grn565, %%mm0\n" - "por %%mm7, %%mm3\n" - "por %%mm0, %%mm3\n" - - "movq %%mm4, %%mm5\n" - - "punpcklwd %%mm3, %%mm4\n" - "punpckhwd %%mm3, %%mm5\n" - - "movq %%mm4, (%5)\n" - "movq %%mm5, 8(%5)\n" - - "addl $8, %6\n" - "addl $8, %2\n" - "addl $4, %%ebx\n" - "addl $4, %1\n" - "cmpl %4, %6\n" - "leal 16(%3), %3\n" - "leal 16(%5),%5\n" // row2+16 - - - "jl 1b\n" - "addl %4, %2\n" // lum += cols - "addl %8, %3\n" // row1+= mod - "addl %8, %5\n" // row2+= mod - "movl $0, %6\n" // x=0 - "cmpl %7, %2\n" - "jl 1b\n" - "emms\n" - "popl %%ebx\n" - : - :"m" (cr), "r"(cb),"r"(lum), - "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)); + unsigned char *y = lum + cols * rows; /* Pointer to the end */ + int x = 0; + row1 = (Uint16 *) out; /* 16 bit target */ + row2 = (Uint16 *) out + cols + mod; /* start of second row */ + mod = (mod + cols + mod) * 2; /* increment for row1 in byte */ + + + __asm__ __volatile__ ("pushl %%ebx\n" "movl %0, %%ebx\n" ".align 8\n" "1:\n" "movd (%1), %%mm0\n" // 4 Cb 0 0 0 0 u3 u2 u1 u0 + "pxor %%mm7, %%mm7\n" "movd (%%ebx), %%mm1\n" // 4 Cr 0 0 0 0 v3 v2 v1 v0 + "punpcklbw %%mm7, %%mm0\n" // 4 W cb 0 u3 0 u2 0 u1 0 u0 + "punpcklbw %%mm7, %%mm1\n" // 4 W cr 0 v3 0 v2 0 v1 0 v0 + "psubw _MMX_0080w, %%mm0\n" "psubw _MMX_0080w, %%mm1\n" "movq %%mm0, %%mm2\n" // Cb 0 u3 0 u2 0 u1 0 u0 + "movq %%mm1, %%mm3\n" // Cr + "pmullw _MMX_Ugrn565, %%mm2\n" // Cb2green 0 R3 0 R2 0 R1 0 R0 + "movq (%2), %%mm6\n" // L1 l7 L6 L5 L4 L3 L2 L1 L0 + "pmullw _MMX_Ublu5x5, %%mm0\n" // Cb2blue + "pand _MMX_00FFw, %%mm6\n" // L1 00 L6 00 L4 00 L2 00 L0 + "pmullw _MMX_Vgrn565, %%mm3\n" // Cr2green + "movq (%2), %%mm7\n" // L2 + "pmullw _MMX_Vred5x5, %%mm1\n" // Cr2red + "psrlw $8, %%mm7\n" // L2 00 L7 00 L5 00 L3 00 L1 + "pmullw _MMX_Ycoeff, %%mm6\n" // lum1 + "paddw %%mm3, %%mm2\n" // Cb2green + Cr2green == green + "pmullw _MMX_Ycoeff, %%mm7\n" // lum2 + "movq %%mm6, %%mm4\n" // lum1 + "paddw %%mm0, %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0 + "movq %%mm4, %%mm5\n" // lum1 + "paddw %%mm1, %%mm4\n" // lum1 +red 00 R6 00 R4 00 R2 00 R0 + "paddw %%mm2, %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0 + "psraw $6, %%mm4\n" // R1 0 .. 64 + "movq %%mm7, %%mm3\n" // lum2 00 L7 00 L5 00 L3 00 L1 + "psraw $6, %%mm5\n" // G1 - .. + + "paddw %%mm0, %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1 + "psraw $6, %%mm6\n" // B1 0 .. 64 + "packuswb %%mm4, %%mm4\n" // R1 R1 + "packuswb %%mm5, %%mm5\n" // G1 G1 + "packuswb %%mm6, %%mm6\n" // B1 B1 + "punpcklbw %%mm4, %%mm4\n" "punpcklbw %%mm5, %%mm5\n" "pand _MMX_red565, %%mm4\n" "psllw $3, %%mm5\n" // GREEN 1 + "punpcklbw %%mm6, %%mm6\n" "pand _MMX_grn565, %%mm5\n" "pand _MMX_red565, %%mm6\n" "por %%mm5, %%mm4\n" // + "psrlw $11, %%mm6\n" // BLUE 1 + "movq %%mm3, %%mm5\n" // lum2 + "paddw %%mm1, %%mm3\n" // lum2 +red 00 R7 00 R5 00 R3 00 R1 + "paddw %%mm2, %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1 + "psraw $6, %%mm3\n" // R2 + "por %%mm6, %%mm4\n" // MM4 + "psraw $6, %%mm5\n" // G2 + "movq (%2, %4), %%mm6\n" // L3 load lum2 + "psraw $6, %%mm7\n" "packuswb %%mm3, %%mm3\n" "packuswb %%mm5, %%mm5\n" "packuswb %%mm7, %%mm7\n" "pand _MMX_00FFw, %%mm6\n" // L3 + "punpcklbw %%mm3, %%mm3\n" "punpcklbw %%mm5, %%mm5\n" "pmullw _MMX_Ycoeff, %%mm6\n" // lum3 + "punpcklbw %%mm7, %%mm7\n" "psllw $3, %%mm5\n" // GREEN 2 + "pand _MMX_red565, %%mm7\n" "pand _MMX_red565, %%mm3\n" "psrlw $11, %%mm7\n" // BLUE 2 + "pand _MMX_grn565, %%mm5\n" "por %%mm7, %%mm3\n" "movq (%2,%4), %%mm7\n" // L4 load lum2 + "por %%mm5, %%mm3\n" // + "psrlw $8, %%mm7\n" // L4 + "movq %%mm4, %%mm5\n" "punpcklwd %%mm3, %%mm4\n" "pmullw _MMX_Ycoeff, %%mm7\n" // lum4 + "punpckhwd %%mm3, %%mm5\n" "movq %%mm4, (%3)\n" // write row1 + "movq %%mm5, 8(%3)\n" // write row1 + "movq %%mm6, %%mm4\n" // Lum3 + "paddw %%mm0, %%mm6\n" // Lum3 +blue + "movq %%mm4, %%mm5\n" // Lum3 + "paddw %%mm1, %%mm4\n" // Lum3 +red + "paddw %%mm2, %%mm5\n" // Lum3 +green + "psraw $6, %%mm4\n" "movq %%mm7, %%mm3\n" // Lum4 + "psraw $6, %%mm5\n" "paddw %%mm0, %%mm7\n" // Lum4 +blue + "psraw $6, %%mm6\n" // Lum3 +blue + "movq %%mm3, %%mm0\n" // Lum4 + "packuswb %%mm4, %%mm4\n" "paddw %%mm1, %%mm3\n" // Lum4 +red + "packuswb %%mm5, %%mm5\n" "paddw %%mm2, %%mm0\n" // Lum4 +green + "packuswb %%mm6, %%mm6\n" "punpcklbw %%mm4, %%mm4\n" "punpcklbw %%mm5, %%mm5\n" "punpcklbw %%mm6, %%mm6\n" "psllw $3, %%mm5\n" // GREEN 3 + "pand _MMX_red565, %%mm4\n" "psraw $6, %%mm3\n" // psr 6 + "psraw $6, %%mm0\n" "pand _MMX_red565, %%mm6\n" // BLUE + "pand _MMX_grn565, %%mm5\n" "psrlw $11, %%mm6\n" // BLUE 3 + "por %%mm5, %%mm4\n" "psraw $6, %%mm7\n" "por %%mm6, %%mm4\n" "packuswb %%mm3, %%mm3\n" "packuswb %%mm0, %%mm0\n" "packuswb %%mm7, %%mm7\n" "punpcklbw %%mm3, %%mm3\n" "punpcklbw %%mm0, %%mm0\n" "punpcklbw %%mm7, %%mm7\n" "pand _MMX_red565, %%mm3\n" "pand _MMX_red565, %%mm7\n" // BLUE + "psllw $3, %%mm0\n" // GREEN 4 + "psrlw $11, %%mm7\n" "pand _MMX_grn565, %%mm0\n" "por %%mm7, %%mm3\n" "por %%mm0, %%mm3\n" "movq %%mm4, %%mm5\n" "punpcklwd %%mm3, %%mm4\n" "punpckhwd %%mm3, %%mm5\n" "movq %%mm4, (%5)\n" "movq %%mm5, 8(%5)\n" "addl $8, %6\n" "addl $8, %2\n" "addl $4, %%ebx\n" "addl $4, %1\n" "cmpl %4, %6\n" "leal 16(%3), %3\n" "leal 16(%5),%5\n" // row2+16 + "jl 1b\n" "addl %4, %2\n" // lum += cols + "addl %8, %3\n" // row1+= mod + "addl %8, %5\n" // row2+= mod + "movl $0, %6\n" // x=0 + "cmpl %7, %2\n" + "jl 1b\n" + "emms\n" + "popl %%ebx\n"::"m" (cr), "r" (cb), "r" (lum), + "r" (row1), "r" (cols), "r" (row2), "m" (x), + "m" (y), "m" (mod)); } #endif /* GCC i386 inline assembly */ #endif /* 0 */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_yuv_sw.c b/src/video/SDL_yuv_sw.c index c67d59296..c02dc7d3e 100644 --- a/src/video/SDL_yuv_sw.c +++ b/src/video/SDL_yuv_sw.c @@ -91,103 +91,104 @@ /* The functions used to manipulate software video overlays */ static struct private_yuvhwfuncs sw_yuvfuncs = { - SDL_LockYUV_SW, - SDL_UnlockYUV_SW, - SDL_DisplayYUV_SW, - SDL_FreeYUV_SW + SDL_LockYUV_SW, + SDL_UnlockYUV_SW, + SDL_DisplayYUV_SW, + SDL_FreeYUV_SW }; /* RGB conversion lookup tables */ -struct private_yuvhwdata { - SDL_Surface *stretch; - SDL_Surface *display; - Uint8 *pixels; - int *colortab; - Uint32 *rgb_2_pix; - void (*Display1X)(int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ); - void (*Display2X)(int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ); - - /* These are just so we don't have to allocate them separately */ - Uint16 pitches[3]; - Uint8 *planes[3]; +struct private_yuvhwdata +{ + SDL_Surface *stretch; + SDL_Surface *display; + Uint8 *pixels; + int *colortab; + Uint32 *rgb_2_pix; + void (*Display1X) (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod); + void (*Display2X) (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod); + + /* These are just so we don't have to allocate them separately */ + Uint16 pitches[3]; + Uint8 *planes[3]; }; /* The colorspace conversion functions */ -#if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES*/ -extern void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, +#if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */ +extern void Color565DitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ); -extern void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, + int rows, int cols, int mod); +extern void ColorRGBDitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ); -#endif + int rows, int cols, int mod); +#endif -static void Color16DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color16DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned short* row1; - unsigned short* row2; - unsigned char* lum2; + unsigned short *row1; + unsigned short *row2; + unsigned char *lum2; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; - row1 = (unsigned short*) out; + row1 = (unsigned short *) out; row2 = row1 + cols + mod; lum2 = lum + cols; mod += cols + mod; y = rows / 2; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - ++cr; ++cb; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + ++cr; + ++cb; L = *lum++; - *row1++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); L = *lum++; - *row1++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); /* Now, do second row. */ L = *lum2++; - *row2++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); L = *lum2++; - *row2++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); } /* @@ -195,22 +196,23 @@ static void Color16DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, * to the ++'s above),but they need to be at the start * of the line after that. */ - lum += cols; + lum += cols; lum2 += cols; row1 += mod; row2 += mod; } } -static void Color24DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color24DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { unsigned int value; - unsigned char* row1; - unsigned char* row2; - unsigned char* lum2; + unsigned char *row1; + unsigned char *row2; + unsigned char *lum2; int x, y; int cr_r; int crb_g; @@ -218,59 +220,54 @@ static void Color24DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, int cols_2 = cols / 2; row1 = out; - row2 = row1 + cols*3 + mod*3; + row2 = row1 + cols * 3 + mod * 3; lum2 = lum + cols; mod += cols + mod; mod *= 3; y = rows / 2; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - ++cr; ++cb; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + ++cr; + ++cb; L = *lum++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - *row1++ = (value ) & 0xFF; - *row1++ = (value >> 8) & 0xFF; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + *row1++ = (value) & 0xFF; + *row1++ = (value >> 8) & 0xFF; *row1++ = (value >> 16) & 0xFF; L = *lum++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - *row1++ = (value ) & 0xFF; - *row1++ = (value >> 8) & 0xFF; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + *row1++ = (value) & 0xFF; + *row1++ = (value >> 8) & 0xFF; *row1++ = (value >> 16) & 0xFF; /* Now, do second row. */ L = *lum2++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - *row2++ = (value ) & 0xFF; - *row2++ = (value >> 8) & 0xFF; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + *row2++ = (value) & 0xFF; + *row2++ = (value >> 8) & 0xFF; *row2++ = (value >> 16) & 0xFF; L = *lum2++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - *row2++ = (value ) & 0xFF; - *row2++ = (value >> 8) & 0xFF; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + *row2++ = (value) & 0xFF; + *row2++ = (value >> 8) & 0xFF; *row2++ = (value >> 16) & 0xFF; } @@ -279,69 +276,65 @@ static void Color24DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, * to the ++'s above),but they need to be at the start * of the line after that. */ - lum += cols; + lum += cols; lum2 += cols; row1 += mod; row2 += mod; } } -static void Color32DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color32DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned int* row1; - unsigned int* row2; - unsigned char* lum2; + unsigned int *row1; + unsigned int *row2; + unsigned char *lum2; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; - row1 = (unsigned int*) out; + row1 = (unsigned int *) out; row2 = row1 + cols + mod; lum2 = lum + cols; mod += cols + mod; y = rows / 2; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - ++cr; ++cb; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + ++cr; + ++cb; L = *lum++; - *row1++ = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row1++ = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); L = *lum++; - *row1++ = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row1++ = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); /* Now, do second row. */ L = *lum2++; - *row2++ = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row2++ = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); L = *lum2++; - *row2++ = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + *row2++ = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); } /* @@ -349,7 +342,7 @@ static void Color32DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, * to the ++'s above),but they need to be at the start * of the line after that. */ - lum += cols; + lum += cols; lum2 += cols; row1 += mod; row2 += mod; @@ -361,15 +354,16 @@ static void Color32DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, * 16 bits replicated in the upper 16. This means I can write ints and get * the horisontal doubling for free (almost). */ -static void Color16DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color16DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned int* row1 = (unsigned int*) out; - const int next_row = cols+(mod/2); - unsigned int* row2 = row1 + 2*next_row; - unsigned char* lum2; + unsigned int *row1 = (unsigned int *) out; + const int next_row = cols + (mod / 2); + unsigned int *row2 = row1 + 2 * next_row; + unsigned char *lum2; int x, y; int cr_r; int crb_g; @@ -378,47 +372,46 @@ static void Color16DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, lum2 = lum + cols; - mod = (next_row * 3) + (mod/2); + mod = (next_row * 3) + (mod / 2); y = rows / 2; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - ++cr; ++cb; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + ++cr; + ++cb; L = *lum++; - row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); row1++; L = *lum++; - row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); row1++; /* Now, do second row. */ L = *lum2++; - row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); row2++; L = *lum2++; - row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); row2++; } @@ -427,23 +420,24 @@ static void Color16DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, * to the ++'s above),but they need to be at the start * of the line after that. */ - lum += cols; + lum += cols; lum2 += cols; row1 += mod; row2 += mod; } } -static void Color24DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color24DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { unsigned int value; - unsigned char* row1 = out; - const int next_row = (cols*2 + mod) * 3; - unsigned char* row2 = row1 + 2*next_row; - unsigned char* lum2; + unsigned char *row1 = out; + const int next_row = (cols * 2 + mod) * 3; + unsigned char *row2 = row1 + 2 * next_row; + unsigned char *lum2; int x, y; int cr_r; int crb_g; @@ -452,72 +446,67 @@ static void Color24DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, lum2 = lum + cols; - mod = next_row*3 + mod*3; + mod = next_row * 3 + mod * 3; y = rows / 2; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - ++cr; ++cb; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + ++cr; + ++cb; L = *lum++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] = - (value ) & 0xFF; - row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] = - (value >> 8) & 0xFF; - row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] = - (value >> 16) & 0xFF; - row1 += 2*3; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] = + row1[next_row + 3 + 0] = (value) & 0xFF; + row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] = + row1[next_row + 3 + 1] = (value >> 8) & 0xFF; + row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] = + row1[next_row + 3 + 2] = (value >> 16) & 0xFF; + row1 += 2 * 3; L = *lum++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] = - (value ) & 0xFF; - row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] = - (value >> 8) & 0xFF; - row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] = - (value >> 16) & 0xFF; - row1 += 2*3; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] = + row1[next_row + 3 + 0] = (value) & 0xFF; + row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] = + row1[next_row + 3 + 1] = (value >> 8) & 0xFF; + row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] = + row1[next_row + 3 + 2] = (value >> 16) & 0xFF; + row1 += 2 * 3; /* Now, do second row. */ L = *lum2++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] = - (value ) & 0xFF; - row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] = - (value >> 8) & 0xFF; - row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] = - (value >> 16) & 0xFF; - row2 += 2*3; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] = + row2[next_row + 3 + 0] = (value) & 0xFF; + row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] = + row2[next_row + 3 + 1] = (value >> 8) & 0xFF; + row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] = + row2[next_row + 3 + 2] = (value >> 16) & 0xFF; + row2 += 2 * 3; L = *lum2++; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] = - (value ) & 0xFF; - row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] = - (value >> 8) & 0xFF; - row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] = - (value >> 16) & 0xFF; - row2 += 2*3; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] = + row2[next_row + 3 + 0] = (value) & 0xFF; + row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] = + row2[next_row + 3 + 1] = (value >> 8) & 0xFF; + row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] = + row2[next_row + 3 + 2] = (value >> 16) & 0xFF; + row2 += 2 * 3; } /* @@ -525,22 +514,23 @@ static void Color24DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, * to the ++'s above),but they need to be at the start * of the line after that. */ - lum += cols; + lum += cols; lum2 += cols; row1 += mod; row2 += mod; } } -static void Color32DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color32DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned int* row1 = (unsigned int*) out; - const int next_row = cols*2+mod; - unsigned int* row2 = row1 + 2*next_row; - unsigned char* lum2; + unsigned int *row1 = (unsigned int *) out; + const int next_row = cols * 2 + mod; + unsigned int *row2 = row1 + 2 * next_row; + unsigned char *lum2; int x, y; int cr_r; int crb_g; @@ -552,48 +542,43 @@ static void Color32DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, mod = (next_row * 3) + mod; y = rows / 2; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - ++cr; ++cb; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + ++cr; + ++cb; L = *lum++; - row1[0] = row1[1] = row1[next_row] = row1[next_row+1] = - (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] = + (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); row1 += 2; L = *lum++; - row1[0] = row1[1] = row1[next_row] = row1[next_row+1] = - (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] = + (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); row1 += 2; /* Now, do second row. */ L = *lum2++; - row2[0] = row2[1] = row2[next_row] = row2[next_row+1] = - (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] = + (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); row2 += 2; L = *lum2++; - row2[0] = row2[1] = row2[next_row] = row2[next_row+1] = - (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] = + (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); row2 += 2; } @@ -602,50 +587,52 @@ static void Color32DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, * to the ++'s above),but they need to be at the start * of the line after that. */ - lum += cols; + lum += cols; lum2 += cols; row1 += mod; row2 += mod; } } -static void Color16DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color16DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned short* row; + unsigned short *row; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; - row = (unsigned short*) out; + row = (unsigned short *) out; y = rows; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - cr += 4; cb += 4; - - L = *lum; lum += 2; - *row++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - - L = *lum; lum += 2; - *row++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + cr += 4; + cb += 4; + + L = *lum; + lum += 2; + *row++ = (unsigned short) (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); + + L = *lum; + lum += 2; + *row++ = (unsigned short) (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); } @@ -653,49 +640,49 @@ static void Color16DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, } } -static void Color24DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color24DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { unsigned int value; - unsigned char* row; + unsigned char *row; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; - row = (unsigned char*) out; + row = (unsigned char *) out; mod *= 3; y = rows; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - cr += 4; cb += 4; - - L = *lum; lum += 2; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - *row++ = (value ) & 0xFF; - *row++ = (value >> 8) & 0xFF; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + cr += 4; + cb += 4; + + L = *lum; + lum += 2; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + *row++ = (value) & 0xFF; + *row++ = (value >> 8) & 0xFF; *row++ = (value >> 16) & 0xFF; - L = *lum; lum += 2; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - *row++ = (value ) & 0xFF; - *row++ = (value >> 8) & 0xFF; + L = *lum; + lum += 2; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + *row++ = (value) & 0xFF; + *row++ = (value >> 8) & 0xFF; *row++ = (value >> 16) & 0xFF; } @@ -703,42 +690,42 @@ static void Color24DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, } } -static void Color32DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color32DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned int* row; + unsigned int *row; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; - row = (unsigned int*) out; + row = (unsigned int *) out; y = rows; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - cr += 4; cb += 4; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + cr += 4; + cb += 4; - L = *lum; lum += 2; - *row++ = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + L = *lum; + lum += 2; + *row++ = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - L = *lum; lum += 2; - *row++ = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + L = *lum; + lum += 2; + *row++ = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); } @@ -751,13 +738,14 @@ static void Color32DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, * 16 bits replicated in the upper 16. This means I can write ints and get * the horisontal doubling for free (almost). */ -static void Color16DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color16DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned int* row = (unsigned int*) out; - const int next_row = cols+(mod/2); + unsigned int *row = (unsigned int *) out; + const int next_row = cols + (mod / 2); int x, y; int cr_r; int crb_g; @@ -765,29 +753,30 @@ static void Color16DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, int cols_2 = cols / 2; y = rows; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - cr += 4; cb += 4; - - L = *lum; lum += 2; - row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + cr += 4; + cb += 4; + + L = *lum; + lum += 2; + row[0] = row[next_row] = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); row++; - L = *lum; lum += 2; - row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + L = *lum; + lum += 2; + row[0] = row[next_row] = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | + rgb_2_pix[L + cb_b]); row++; } @@ -795,101 +784,101 @@ static void Color16DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, } } -static void Color24DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color24DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { unsigned int value; - unsigned char* row = out; - const int next_row = (cols*2 + mod) * 3; + unsigned char *row = out; + const int next_row = (cols * 2 + mod) * 3; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; y = rows; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - cr += 4; cb += 4; - - L = *lum; lum += 2; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] = - (value ) & 0xFF; - row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] = - (value >> 8) & 0xFF; - row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] = - (value >> 16) & 0xFF; - row += 2*3; - - L = *lum; lum += 2; - value = (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); - row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] = - (value ) & 0xFF; - row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] = - (value >> 8) & 0xFF; - row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] = - (value >> 16) & 0xFF; - row += 2*3; + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + cr += 4; + cb += 4; + + L = *lum; + lum += 2; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + row[0 + 0] = row[3 + 0] = row[next_row + 0] = + row[next_row + 3 + 0] = (value) & 0xFF; + row[0 + 1] = row[3 + 1] = row[next_row + 1] = + row[next_row + 3 + 1] = (value >> 8) & 0xFF; + row[0 + 2] = row[3 + 2] = row[next_row + 2] = + row[next_row + 3 + 2] = (value >> 16) & 0xFF; + row += 2 * 3; + + L = *lum; + lum += 2; + value = (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); + row[0 + 0] = row[3 + 0] = row[next_row + 0] = + row[next_row + 3 + 0] = (value) & 0xFF; + row[0 + 1] = row[3 + 1] = row[next_row + 1] = + row[next_row + 3 + 1] = (value >> 8) & 0xFF; + row[0 + 2] = row[3 + 2] = row[next_row + 2] = + row[next_row + 3 + 2] = (value >> 16) & 0xFF; + row += 2 * 3; } row += next_row; } } -static void Color32DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) +static void +Color32DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix, + unsigned char *lum, unsigned char *cr, + unsigned char *cb, unsigned char *out, + int rows, int cols, int mod) { - unsigned int* row = (unsigned int*) out; - const int next_row = cols*2+mod; + unsigned int *row = (unsigned int *) out; + const int next_row = cols * 2 + mod; int x, y; int cr_r; int crb_g; int cb_b; int cols_2 = cols / 2; - mod+=mod; + mod += mod; y = rows; - while( y-- ) - { + while (y--) { x = cols_2; - while( x-- ) - { + while (x--) { register int L; - cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; - crb_g = 1*768+256 + colortab[ *cr + 1*256 ] - + colortab[ *cb + 2*256 ]; - cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; - cr += 4; cb += 4; - - L = *lum; lum += 2; - row[0] = row[1] = row[next_row] = row[next_row+1] = - (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; + crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] + + colortab[*cb + 2 * 256]; + cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; + cr += 4; + cb += 4; + + L = *lum; + lum += 2; + row[0] = row[1] = row[next_row] = row[next_row + 1] = + (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); row += 2; - L = *lum; lum += 2; - row[0] = row[1] = row[next_row] = row[next_row+1] = - (rgb_2_pix[ L + cr_r ] | - rgb_2_pix[ L + crb_g ] | - rgb_2_pix[ L + cb_b ]); + L = *lum; + lum += 2; + row[0] = row[1] = row[next_row] = row[next_row + 1] = + (rgb_2_pix[L + cr_r] | + rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); row += 2; @@ -903,396 +892,411 @@ static void Color32DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, * How many 1 bits are there in the Uint32. * Low performance, do not call often. */ -static int number_of_bits_set( Uint32 a ) +static int +number_of_bits_set (Uint32 a) { - if(!a) return 0; - if(a & 1) return 1 + number_of_bits_set(a >> 1); - return(number_of_bits_set(a >> 1)); + if (!a) + return 0; + if (a & 1) + return 1 + number_of_bits_set (a >> 1); + return (number_of_bits_set (a >> 1)); } /* * How many 0 bits are there at least significant end of Uint32. * Low performance, do not call often. */ -static int free_bits_at_bottom( Uint32 a ) +static int +free_bits_at_bottom (Uint32 a) { - /* assume char is 8 bits */ - if(!a) return sizeof(Uint32) * 8; - if(((Sint32)a) & 1l) return 0; - return 1 + free_bits_at_bottom ( a >> 1); + /* assume char is 8 bits */ + if (!a) + return sizeof (Uint32) * 8; + if (((Sint32) a) & 1l) + return 0; + return 1 + free_bits_at_bottom (a >> 1); } -SDL_Overlay *SDL_CreateYUV_SW(_THIS, int width, int height, Uint32 format, SDL_Surface *display) +SDL_Overlay * +SDL_CreateYUV_SW (_THIS, int width, int height, Uint32 format, + SDL_Surface * display) { - SDL_Overlay *overlay; - struct private_yuvhwdata *swdata; - int *Cr_r_tab; - int *Cr_g_tab; - int *Cb_g_tab; - int *Cb_b_tab; - Uint32 *r_2_pix_alloc; - Uint32 *g_2_pix_alloc; - Uint32 *b_2_pix_alloc; - int i; - int CR, CB; - Uint32 Rmask, Gmask, Bmask; - - /* Only RGB packed pixel conversion supported */ - if ( (display->format->BytesPerPixel != 2) && - (display->format->BytesPerPixel != 3) && - (display->format->BytesPerPixel != 4) ) { - SDL_SetError("Can't use YUV data on non 16/24/32 bit surfaces"); - return(NULL); - } - - /* Verify that we support the format */ - switch (format) { - case SDL_YV12_OVERLAY: - case SDL_IYUV_OVERLAY: - case SDL_YUY2_OVERLAY: - case SDL_UYVY_OVERLAY: - case SDL_YVYU_OVERLAY: - break; - default: - SDL_SetError("Unsupported YUV format"); - return(NULL); - } - - /* Create the overlay structure */ - overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay); - if ( overlay == NULL ) { - SDL_OutOfMemory(); - return(NULL); - } - SDL_memset(overlay, 0, (sizeof *overlay)); - - /* Fill in the basic members */ - overlay->format = format; - overlay->w = width; - overlay->h = height; - - /* Set up the YUV surface function structure */ - overlay->hwfuncs = &sw_yuvfuncs; - - /* Create the pixel data and lookup tables */ - swdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *swdata); - overlay->hwdata = swdata; - if ( swdata == NULL ) { - SDL_OutOfMemory(); - SDL_FreeYUVOverlay(overlay); - return(NULL); - } - swdata->stretch = NULL; - swdata->display = display; - swdata->pixels = (Uint8 *) SDL_malloc(width*height*2); - swdata->colortab = (int *)SDL_malloc(4*256*sizeof(int)); - Cr_r_tab = &swdata->colortab[0*256]; - Cr_g_tab = &swdata->colortab[1*256]; - Cb_g_tab = &swdata->colortab[2*256]; - Cb_b_tab = &swdata->colortab[3*256]; - swdata->rgb_2_pix = (Uint32 *)SDL_malloc(3*768*sizeof(Uint32)); - r_2_pix_alloc = &swdata->rgb_2_pix[0*768]; - g_2_pix_alloc = &swdata->rgb_2_pix[1*768]; - b_2_pix_alloc = &swdata->rgb_2_pix[2*768]; - if ( ! swdata->pixels || ! swdata->colortab || ! swdata->rgb_2_pix ) { - SDL_OutOfMemory(); - SDL_FreeYUVOverlay(overlay); - return(NULL); - } - - /* Generate the tables for the display surface */ - for (i=0; i<256; i++) { - /* Gamma correction (luminescence table) and chroma correction - would be done here. See the Berkeley mpeg_play sources. - */ - CB = CR = (i-128); - Cr_r_tab[i] = (int) ( (0.419/0.299) * CR); - Cr_g_tab[i] = (int) (-(0.299/0.419) * CR); - Cb_g_tab[i] = (int) (-(0.114/0.331) * CB); - Cb_b_tab[i] = (int) ( (0.587/0.331) * CB); - } - - /* - * Set up entries 0-255 in rgb-to-pixel value tables. - */ - Rmask = display->format->Rmask; - Gmask = display->format->Gmask; - Bmask = display->format->Bmask; - for ( i=0; i<256; ++i ) { - r_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Rmask)); - r_2_pix_alloc[i+256] <<= free_bits_at_bottom(Rmask); - g_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Gmask)); - g_2_pix_alloc[i+256] <<= free_bits_at_bottom(Gmask); - b_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Bmask)); - b_2_pix_alloc[i+256] <<= free_bits_at_bottom(Bmask); - } - - /* - * If we have 16-bit output depth, then we double the value - * in the top word. This means that we can write out both - * pixels in the pixel doubling mode with one op. It is - * harmless in the normal case as storing a 32-bit value - * through a short pointer will lose the top bits anyway. - */ - if( display->format->BytesPerPixel == 2 ) { - for ( i=0; i<256; ++i ) { - r_2_pix_alloc[i+256] |= (r_2_pix_alloc[i+256]) << 16; - g_2_pix_alloc[i+256] |= (g_2_pix_alloc[i+256]) << 16; - b_2_pix_alloc[i+256] |= (b_2_pix_alloc[i+256]) << 16; - } - } - - /* - * Spread out the values we have to the rest of the array so that - * we do not need to check for overflow. - */ - for ( i=0; i<256; ++i ) { - r_2_pix_alloc[i] = r_2_pix_alloc[256]; - r_2_pix_alloc[i+512] = r_2_pix_alloc[511]; - g_2_pix_alloc[i] = g_2_pix_alloc[256]; - g_2_pix_alloc[i+512] = g_2_pix_alloc[511]; - b_2_pix_alloc[i] = b_2_pix_alloc[256]; - b_2_pix_alloc[i+512] = b_2_pix_alloc[511]; - } - - /* You have chosen wisely... */ - switch (format) { - case SDL_YV12_OVERLAY: - case SDL_IYUV_OVERLAY: - if ( display->format->BytesPerPixel == 2 ) { -#if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES*/ - /* inline assembly functions */ - if ( SDL_HasMMX() && (Rmask == 0xF800) && - (Gmask == 0x07E0) && - (Bmask == 0x001F) && - (width & 15) == 0) { + SDL_Overlay *overlay; + struct private_yuvhwdata *swdata; + int *Cr_r_tab; + int *Cr_g_tab; + int *Cb_g_tab; + int *Cb_b_tab; + Uint32 *r_2_pix_alloc; + Uint32 *g_2_pix_alloc; + Uint32 *b_2_pix_alloc; + int i; + int CR, CB; + Uint32 Rmask, Gmask, Bmask; + + /* Only RGB packed pixel conversion supported */ + if ((display->format->BytesPerPixel != 2) && + (display->format->BytesPerPixel != 3) && + (display->format->BytesPerPixel != 4)) { + SDL_SetError ("Can't use YUV data on non 16/24/32 bit surfaces"); + return (NULL); + } + + /* Verify that we support the format */ + switch (format) { + case SDL_YV12_OVERLAY: + case SDL_IYUV_OVERLAY: + case SDL_YUY2_OVERLAY: + case SDL_UYVY_OVERLAY: + case SDL_YVYU_OVERLAY: + break; + default: + SDL_SetError ("Unsupported YUV format"); + return (NULL); + } + + /* Create the overlay structure */ + overlay = (SDL_Overlay *) SDL_malloc (sizeof *overlay); + if (overlay == NULL) { + SDL_OutOfMemory (); + return (NULL); + } + SDL_memset (overlay, 0, (sizeof *overlay)); + + /* Fill in the basic members */ + overlay->format = format; + overlay->w = width; + overlay->h = height; + + /* Set up the YUV surface function structure */ + overlay->hwfuncs = &sw_yuvfuncs; + + /* Create the pixel data and lookup tables */ + swdata = (struct private_yuvhwdata *) SDL_malloc (sizeof *swdata); + overlay->hwdata = swdata; + if (swdata == NULL) { + SDL_OutOfMemory (); + SDL_FreeYUVOverlay (overlay); + return (NULL); + } + swdata->stretch = NULL; + swdata->display = display; + swdata->pixels = (Uint8 *) SDL_malloc (width * height * 2); + swdata->colortab = (int *) SDL_malloc (4 * 256 * sizeof (int)); + Cr_r_tab = &swdata->colortab[0 * 256]; + Cr_g_tab = &swdata->colortab[1 * 256]; + Cb_g_tab = &swdata->colortab[2 * 256]; + Cb_b_tab = &swdata->colortab[3 * 256]; + swdata->rgb_2_pix = (Uint32 *) SDL_malloc (3 * 768 * sizeof (Uint32)); + r_2_pix_alloc = &swdata->rgb_2_pix[0 * 768]; + g_2_pix_alloc = &swdata->rgb_2_pix[1 * 768]; + b_2_pix_alloc = &swdata->rgb_2_pix[2 * 768]; + if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) { + SDL_OutOfMemory (); + SDL_FreeYUVOverlay (overlay); + return (NULL); + } + + /* Generate the tables for the display surface */ + for (i = 0; i < 256; i++) { + /* Gamma correction (luminescence table) and chroma correction + would be done here. See the Berkeley mpeg_play sources. + */ + CB = CR = (i - 128); + Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR); + Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR); + Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB); + Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB); + } + + /* + * Set up entries 0-255 in rgb-to-pixel value tables. + */ + Rmask = display->format->Rmask; + Gmask = display->format->Gmask; + Bmask = display->format->Bmask; + for (i = 0; i < 256; ++i) { + r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Rmask)); + r_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Rmask); + g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Gmask)); + g_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Gmask); + b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Bmask)); + b_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Bmask); + } + + /* + * If we have 16-bit output depth, then we double the value + * in the top word. This means that we can write out both + * pixels in the pixel doubling mode with one op. It is + * harmless in the normal case as storing a 32-bit value + * through a short pointer will lose the top bits anyway. + */ + if (display->format->BytesPerPixel == 2) { + for (i = 0; i < 256; ++i) { + r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 16; + g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 16; + b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 16; + } + } + + /* + * Spread out the values we have to the rest of the array so that + * we do not need to check for overflow. + */ + for (i = 0; i < 256; ++i) { + r_2_pix_alloc[i] = r_2_pix_alloc[256]; + r_2_pix_alloc[i + 512] = r_2_pix_alloc[511]; + g_2_pix_alloc[i] = g_2_pix_alloc[256]; + g_2_pix_alloc[i + 512] = g_2_pix_alloc[511]; + b_2_pix_alloc[i] = b_2_pix_alloc[256]; + b_2_pix_alloc[i + 512] = b_2_pix_alloc[511]; + } + + /* You have chosen wisely... */ + switch (format) { + case SDL_YV12_OVERLAY: + case SDL_IYUV_OVERLAY: + if (display->format->BytesPerPixel == 2) { +#if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */ + /* inline assembly functions */ + if (SDL_HasMMX () && (Rmask == 0xF800) && + (Gmask == 0x07E0) && (Bmask == 0x001F) && (width & 15) == 0) { /*printf("Using MMX 16-bit 565 dither\n");*/ - swdata->Display1X = Color565DitherYV12MMX1X; - } else { + swdata->Display1X = Color565DitherYV12MMX1X; + } else { /*printf("Using C 16-bit dither\n");*/ - swdata->Display1X = Color16DitherYV12Mod1X; - } + swdata->Display1X = Color16DitherYV12Mod1X; + } #else - swdata->Display1X = Color16DitherYV12Mod1X; + swdata->Display1X = Color16DitherYV12Mod1X; #endif - swdata->Display2X = Color16DitherYV12Mod2X; - } - if ( display->format->BytesPerPixel == 3 ) { - swdata->Display1X = Color24DitherYV12Mod1X; - swdata->Display2X = Color24DitherYV12Mod2X; - } - if ( display->format->BytesPerPixel == 4 ) { -#if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES*/ - /* inline assembly functions */ - if ( SDL_HasMMX() && (Rmask == 0x00FF0000) && - (Gmask == 0x0000FF00) && - (Bmask == 0x000000FF) && - (width & 15) == 0) { + swdata->Display2X = Color16DitherYV12Mod2X; + } + if (display->format->BytesPerPixel == 3) { + swdata->Display1X = Color24DitherYV12Mod1X; + swdata->Display2X = Color24DitherYV12Mod2X; + } + if (display->format->BytesPerPixel == 4) { +#if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */ + /* inline assembly functions */ + if (SDL_HasMMX () && (Rmask == 0x00FF0000) && + (Gmask == 0x0000FF00) && + (Bmask == 0x000000FF) && (width & 15) == 0) { /*printf("Using MMX 32-bit dither\n");*/ - swdata->Display1X = ColorRGBDitherYV12MMX1X; - } else { + swdata->Display1X = ColorRGBDitherYV12MMX1X; + } else { /*printf("Using C 32-bit dither\n");*/ - swdata->Display1X = Color32DitherYV12Mod1X; - } + swdata->Display1X = Color32DitherYV12Mod1X; + } #else - swdata->Display1X = Color32DitherYV12Mod1X; + swdata->Display1X = Color32DitherYV12Mod1X; #endif - swdata->Display2X = Color32DitherYV12Mod2X; - } - break; - case SDL_YUY2_OVERLAY: - case SDL_UYVY_OVERLAY: - case SDL_YVYU_OVERLAY: - if ( display->format->BytesPerPixel == 2 ) { - swdata->Display1X = Color16DitherYUY2Mod1X; - swdata->Display2X = Color16DitherYUY2Mod2X; - } - if ( display->format->BytesPerPixel == 3 ) { - swdata->Display1X = Color24DitherYUY2Mod1X; - swdata->Display2X = Color24DitherYUY2Mod2X; - } - if ( display->format->BytesPerPixel == 4 ) { - swdata->Display1X = Color32DitherYUY2Mod1X; - swdata->Display2X = Color32DitherYUY2Mod2X; - } - break; - default: - /* We should never get here (caught above) */ - break; - } - - /* Find the pitch and offset values for the overlay */ - overlay->pitches = swdata->pitches; - overlay->pixels = swdata->planes; - switch (format) { - case SDL_YV12_OVERLAY: - case SDL_IYUV_OVERLAY: - overlay->pitches[0] = overlay->w; - overlay->pitches[1] = overlay->pitches[0] / 2; - overlay->pitches[2] = overlay->pitches[0] / 2; - overlay->pixels[0] = swdata->pixels; - overlay->pixels[1] = overlay->pixels[0] + - overlay->pitches[0] * overlay->h; - overlay->pixels[2] = overlay->pixels[1] + - overlay->pitches[1] * overlay->h / 2; - overlay->planes = 3; - break; - case SDL_YUY2_OVERLAY: - case SDL_UYVY_OVERLAY: - case SDL_YVYU_OVERLAY: - overlay->pitches[0] = overlay->w*2; - overlay->pixels[0] = swdata->pixels; - overlay->planes = 1; - break; - default: - /* We should never get here (caught above) */ - break; - } - - /* We're all done.. */ - return(overlay); + swdata->Display2X = Color32DitherYV12Mod2X; + } + break; + case SDL_YUY2_OVERLAY: + case SDL_UYVY_OVERLAY: + case SDL_YVYU_OVERLAY: + if (display->format->BytesPerPixel == 2) { + swdata->Display1X = Color16DitherYUY2Mod1X; + swdata->Display2X = Color16DitherYUY2Mod2X; + } + if (display->format->BytesPerPixel == 3) { + swdata->Display1X = Color24DitherYUY2Mod1X; + swdata->Display2X = Color24DitherYUY2Mod2X; + } + if (display->format->BytesPerPixel == 4) { + swdata->Display1X = Color32DitherYUY2Mod1X; + swdata->Display2X = Color32DitherYUY2Mod2X; + } + break; + default: + /* We should never get here (caught above) */ + break; + } + + /* Find the pitch and offset values for the overlay */ + overlay->pitches = swdata->pitches; + overlay->pixels = swdata->planes; + switch (format) { + case SDL_YV12_OVERLAY: + case SDL_IYUV_OVERLAY: + overlay->pitches[0] = overlay->w; + overlay->pitches[1] = overlay->pitches[0] / 2; + overlay->pitches[2] = overlay->pitches[0] / 2; + overlay->pixels[0] = swdata->pixels; + overlay->pixels[1] = overlay->pixels[0] + + overlay->pitches[0] * overlay->h; + overlay->pixels[2] = overlay->pixels[1] + + overlay->pitches[1] * overlay->h / 2; + overlay->planes = 3; + break; + case SDL_YUY2_OVERLAY: + case SDL_UYVY_OVERLAY: + case SDL_YVYU_OVERLAY: + overlay->pitches[0] = overlay->w * 2; + overlay->pixels[0] = swdata->pixels; + overlay->planes = 1; + break; + default: + /* We should never get here (caught above) */ + break; + } + + /* We're all done.. */ + return (overlay); } -int SDL_LockYUV_SW(_THIS, SDL_Overlay *overlay) +int +SDL_LockYUV_SW (_THIS, SDL_Overlay * overlay) { - return(0); + return (0); } -void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay) +void +SDL_UnlockYUV_SW (_THIS, SDL_Overlay * overlay) { - return; + return; } -int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) +int +SDL_DisplayYUV_SW (_THIS, SDL_Overlay * overlay, SDL_Rect * src, + SDL_Rect * dst) { - struct private_yuvhwdata *swdata; - int stretch; - int scale_2x; - SDL_Surface *display; - Uint8 *lum, *Cr, *Cb; - Uint8 *dstp; - int mod; - - swdata = overlay->hwdata; - stretch = 0; - scale_2x = 0; - if ( src->x || src->y || src->w < overlay->w || src->h < overlay->h ) { - /* The source rectangle has been clipped. - Using a scratch surface is easier than adding clipped - source support to all the blitters, plus that would - slow them down in the general unclipped case. - */ - stretch = 1; - } else if ( (src->w != dst->w) || (src->h != dst->h) ) { - if ( (dst->w == 2*src->w) && - (dst->h == 2*src->h) ) { - scale_2x = 1; - } else { - stretch = 1; - } - } - if ( stretch ) { - if ( ! swdata->stretch ) { - display = swdata->display; - swdata->stretch = SDL_CreateRGBSurface( - SDL_SWSURFACE, - overlay->w, overlay->h, - display->format->BitsPerPixel, - display->format->Rmask, - display->format->Gmask, - display->format->Bmask, 0); - if ( ! swdata->stretch ) { - return(-1); - } - } - display = swdata->stretch; - } else { - display = swdata->display; - } - switch (overlay->format) { - case SDL_YV12_OVERLAY: - lum = overlay->pixels[0]; - Cr = overlay->pixels[1]; - Cb = overlay->pixels[2]; - break; - case SDL_IYUV_OVERLAY: - lum = overlay->pixels[0]; - Cr = overlay->pixels[2]; - Cb = overlay->pixels[1]; - break; - case SDL_YUY2_OVERLAY: - lum = overlay->pixels[0]; - Cr = lum + 3; - Cb = lum + 1; - break; - case SDL_UYVY_OVERLAY: - lum = overlay->pixels[0]+1; - Cr = lum + 1; - Cb = lum - 1; - break; - case SDL_YVYU_OVERLAY: - lum = overlay->pixels[0]; - Cr = lum + 1; - Cb = lum + 3; - break; - default: - SDL_SetError("Unsupported YUV format in blit"); - return(-1); - } - if ( SDL_MUSTLOCK(display) ) { - if ( SDL_LockSurface(display) < 0 ) { - return(-1); - } - } - if ( stretch ) { - dstp = (Uint8 *)swdata->stretch->pixels; - } else { - dstp = (Uint8 *)display->pixels - + dst->x * display->format->BytesPerPixel - + dst->y * display->pitch; - } - mod = (display->pitch / display->format->BytesPerPixel); - - if ( scale_2x ) { - mod -= (overlay->w * 2); - swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); - } else { - mod -= overlay->w; - swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); - } - if ( SDL_MUSTLOCK(display) ) { - SDL_UnlockSurface(display); - } - if ( stretch ) { - display = swdata->display; - SDL_SoftStretch(swdata->stretch, src, display, dst); - } - SDL_UpdateRects(display, 1, dst); - - return(0); + struct private_yuvhwdata *swdata; + int stretch; + int scale_2x; + SDL_Surface *display; + Uint8 *lum, *Cr, *Cb; + Uint8 *dstp; + int mod; + + swdata = overlay->hwdata; + stretch = 0; + scale_2x = 0; + if (src->x || src->y || src->w < overlay->w || src->h < overlay->h) { + /* The source rectangle has been clipped. + Using a scratch surface is easier than adding clipped + source support to all the blitters, plus that would + slow them down in the general unclipped case. + */ + stretch = 1; + } else if ((src->w != dst->w) || (src->h != dst->h)) { + if ((dst->w == 2 * src->w) && (dst->h == 2 * src->h)) { + scale_2x = 1; + } else { + stretch = 1; + } + } + if (stretch) { + if (!swdata->stretch) { + display = swdata->display; + swdata->stretch = SDL_CreateRGBSurface (SDL_SWSURFACE, + overlay->w, + overlay->h, + display->format-> + BitsPerPixel, + display->format-> + Rmask, + display->format-> + Gmask, + display->format-> + Bmask, 0); + if (!swdata->stretch) { + return (-1); + } + } + display = swdata->stretch; + } else { + display = swdata->display; + } + switch (overlay->format) { + case SDL_YV12_OVERLAY: + lum = overlay->pixels[0]; + Cr = overlay->pixels[1]; + Cb = overlay->pixels[2]; + break; + case SDL_IYUV_OVERLAY: + lum = overlay->pixels[0]; + Cr = overlay->pixels[2]; + Cb = overlay->pixels[1]; + break; + case SDL_YUY2_OVERLAY: + lum = overlay->pixels[0]; + Cr = lum + 3; + Cb = lum + 1; + break; + case SDL_UYVY_OVERLAY: + lum = overlay->pixels[0] + 1; + Cr = lum + 1; + Cb = lum - 1; + break; + case SDL_YVYU_OVERLAY: + lum = overlay->pixels[0]; + Cr = lum + 1; + Cb = lum + 3; + break; + default: + SDL_SetError ("Unsupported YUV format in blit"); + return (-1); + } + if (SDL_MUSTLOCK (display)) { + if (SDL_LockSurface (display) < 0) { + return (-1); + } + } + if (stretch) { + dstp = (Uint8 *) swdata->stretch->pixels; + } else { + dstp = (Uint8 *) display->pixels + + dst->x * display->format->BytesPerPixel + + dst->y * display->pitch; + } + mod = (display->pitch / display->format->BytesPerPixel); + + if (scale_2x) { + mod -= (overlay->w * 2); + swdata->Display2X (swdata->colortab, swdata->rgb_2_pix, + lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); + } else { + mod -= overlay->w; + swdata->Display1X (swdata->colortab, swdata->rgb_2_pix, + lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); + } + if (SDL_MUSTLOCK (display)) { + SDL_UnlockSurface (display); + } + if (stretch) { + display = swdata->display; + SDL_SoftStretch (swdata->stretch, src, display, dst); + } + SDL_UpdateRects (display, 1, dst); + + return (0); } -void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay) +void +SDL_FreeYUV_SW (_THIS, SDL_Overlay * overlay) { - struct private_yuvhwdata *swdata; - - swdata = overlay->hwdata; - if ( swdata ) { - if ( swdata->stretch ) { - SDL_FreeSurface(swdata->stretch); - } - if ( swdata->pixels ) { - SDL_free(swdata->pixels); - } - if ( swdata->colortab ) { - SDL_free(swdata->colortab); - } - if ( swdata->rgb_2_pix ) { - SDL_free(swdata->rgb_2_pix); - } - SDL_free(swdata); - } + struct private_yuvhwdata *swdata; + + swdata = overlay->hwdata; + if (swdata) { + if (swdata->stretch) { + SDL_FreeSurface (swdata->stretch); + } + if (swdata->pixels) { + SDL_free (swdata->pixels); + } + if (swdata->colortab) { + SDL_free (swdata->colortab); + } + if (swdata->rgb_2_pix) { + SDL_free (swdata->rgb_2_pix); + } + SDL_free (swdata); + } } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_yuv_sw_c.h b/src/video/SDL_yuv_sw_c.h index 39df51d7f..88a995079 100644 --- a/src/video/SDL_yuv_sw_c.h +++ b/src/video/SDL_yuv_sw_c.h @@ -26,12 +26,15 @@ /* This is the software implementation of the YUV video overlay support */ -extern SDL_Overlay *SDL_CreateYUV_SW(_THIS, int width, int height, Uint32 format, SDL_Surface *display); +extern SDL_Overlay *SDL_CreateYUV_SW (_THIS, int width, int height, + Uint32 format, SDL_Surface * display); -extern int SDL_LockYUV_SW(_THIS, SDL_Overlay *overlay); +extern int SDL_LockYUV_SW (_THIS, SDL_Overlay * overlay); -extern void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay); +extern void SDL_UnlockYUV_SW (_THIS, SDL_Overlay * overlay); -extern int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); +extern int SDL_DisplayYUV_SW (_THIS, SDL_Overlay * overlay, SDL_Rect * src, + SDL_Rect * dst); -extern void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay); +extern void SDL_FreeYUV_SW (_THIS, SDL_Overlay * overlay); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_yuvfuncs.h b/src/video/SDL_yuvfuncs.h index a48af3f0d..26ad1aaea 100644 --- a/src/video/SDL_yuvfuncs.h +++ b/src/video/SDL_yuvfuncs.h @@ -29,9 +29,12 @@ #ifndef _THIS #define _THIS SDL_VideoDevice *_this #endif -struct private_yuvhwfuncs { - int (*Lock)(_THIS, SDL_Overlay *overlay); - void (*Unlock)(_THIS, SDL_Overlay *overlay); - int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); - void (*FreeHW)(_THIS, SDL_Overlay *overlay); +struct private_yuvhwfuncs +{ + int (*Lock) (_THIS, SDL_Overlay * overlay); + void (*Unlock) (_THIS, SDL_Overlay * overlay); + int (*Display) (_THIS, SDL_Overlay * overlay, SDL_Rect * src, + SDL_Rect * dst); + void (*FreeHW) (_THIS, SDL_Overlay * overlay); }; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/XME/xme.c b/src/video/Xext/XME/xme.c index 0a7379642..54e37e21f 100644 --- a/src/video/Xext/XME/xme.c +++ b/src/video/Xext/XME/xme.c @@ -49,124 +49,135 @@ /*******************************************************************/ -typedef struct { - CARD8 reqType; /* always codes->major_opcode */ - CARD8 xigmiscReqType; /* always X_XiGMiscQueryVersion */ - CARD16 length; - CARD16 major; - CARD16 minor; +typedef struct +{ + CARD8 reqType; /* always codes->major_opcode */ + CARD8 xigmiscReqType; /* always X_XiGMiscQueryVersion */ + CARD16 length; + CARD16 major; + CARD16 minor; } xXiGMiscQueryVersionReq; -typedef struct { - CARD8 reqType; /* always codes->major_opcode */ - CARD8 xigmiscReqType; /* always X_XiGMiscQueryViews */ - CARD16 length; - CARD8 screen; - CARD8 pad0; - CARD16 pad1; +typedef struct +{ + CARD8 reqType; /* always codes->major_opcode */ + CARD8 xigmiscReqType; /* always X_XiGMiscQueryViews */ + CARD16 length; + CARD8 screen; + CARD8 pad0; + CARD16 pad1; } xXiGMiscQueryViewsReq; -typedef struct { - CARD8 reqType; /* always codes->major_opcode */ - CARD8 xigmiscReqType; /* always X_XiGMiscQueryResolutions */ - CARD16 length; - CARD8 screen; - CARD8 view; - CARD16 pad0; +typedef struct +{ + CARD8 reqType; /* always codes->major_opcode */ + CARD8 xigmiscReqType; /* always X_XiGMiscQueryResolutions */ + CARD16 length; + CARD8 screen; + CARD8 view; + CARD16 pad0; } xXiGMiscQueryResolutionsReq; -typedef struct { - CARD8 reqType; /* always codes->major_opcode */ - CARD8 xigmiscReqType; /* always X_XiGMiscChangeResolution */ - CARD16 length; - CARD8 screen; - CARD8 view; - CARD16 pad0; - CARD16 width; - CARD16 height; - INT32 refresh; +typedef struct +{ + CARD8 reqType; /* always codes->major_opcode */ + CARD8 xigmiscReqType; /* always X_XiGMiscChangeResolution */ + CARD16 length; + CARD8 screen; + CARD8 view; + CARD16 pad0; + CARD16 width; + CARD16 height; + INT32 refresh; } xXiGMiscChangeResolutionReq; -typedef struct { - CARD8 reqType; /* always codes->major_opcode */ - CARD8 xigmiscReqType; /* always X_XiGMiscFullScreen */ - CARD16 length; - CARD8 screen; - CARD8 pad0; - CARD16 pad1; - CARD32 window; - CARD32 cmap; +typedef struct +{ + CARD8 reqType; /* always codes->major_opcode */ + CARD8 xigmiscReqType; /* always X_XiGMiscFullScreen */ + CARD16 length; + CARD8 screen; + CARD8 pad0; + CARD16 pad1; + CARD32 window; + CARD32 cmap; } xXiGMiscFullScreenReq; /*******************************************************************/ -typedef struct { - BYTE type; /* X_Reply */ - CARD8 pad0; - CARD16 sequenceNumber; - CARD32 length; - CARD16 major; - CARD16 minor; - CARD32 pad1; - CARD32 pad2; - CARD32 pad3; - CARD32 pad4; - CARD32 pad5; +typedef struct +{ + BYTE type; /* X_Reply */ + CARD8 pad0; + CARD16 sequenceNumber; + CARD32 length; + CARD16 major; + CARD16 minor; + CARD32 pad1; + CARD32 pad2; + CARD32 pad3; + CARD32 pad4; + CARD32 pad5; } xXiGMiscQueryVersionReply; -typedef struct { - BYTE type; /* X_Reply */ - CARD8 pad0; - CARD16 sequenceNumber; - CARD32 length; - CARD32 nviews; - CARD32 pad1; - CARD32 pad2; - CARD32 pad3; - CARD32 pad4; - CARD32 pad5; +typedef struct +{ + BYTE type; /* X_Reply */ + CARD8 pad0; + CARD16 sequenceNumber; + CARD32 length; + CARD32 nviews; + CARD32 pad1; + CARD32 pad2; + CARD32 pad3; + CARD32 pad4; + CARD32 pad5; } xXiGMiscQueryViewsReply; -typedef struct { - BYTE type; /* X_Reply */ - CARD8 pad0; - CARD16 sequenceNumber; - CARD32 length; - CARD16 active; - CARD16 nresolutions; - CARD32 pad1; - CARD32 pad2; - CARD32 pad3; - CARD32 pad4; - CARD32 pad5; +typedef struct +{ + BYTE type; /* X_Reply */ + CARD8 pad0; + CARD16 sequenceNumber; + CARD32 length; + CARD16 active; + CARD16 nresolutions; + CARD32 pad1; + CARD32 pad2; + CARD32 pad3; + CARD32 pad4; + CARD32 pad5; } xXiGMiscQueryResolutionsReply; -typedef struct { - BYTE type; /* X_Reply */ - BOOL success; - CARD16 sequenceNumber; - CARD32 length; - CARD32 pad1; - CARD32 pad2; - CARD32 pad3; - CARD32 pad4; - CARD32 pad5; - CARD32 pad6; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL success; + CARD16 sequenceNumber; + CARD32 length; + CARD32 pad1; + CARD32 pad2; + CARD32 pad3; + CARD32 pad4; + CARD32 pad5; + CARD32 pad6; } xXiGMiscFullScreenReply; /*******************************************************************/ -typedef struct { - INT16 x; - INT16 y; - CARD16 w; - CARD16 h; +typedef struct +{ + INT16 x; + INT16 y; + CARD16 w; + CARD16 h; } XiGMiscViewInfo; -typedef struct { - CARD16 width; - CARD16 height; - INT32 refresh; +typedef struct +{ + CARD16 width; + CARD16 height; + INT32 refresh; } XiGMiscResolutionInfo; /*****************************************************************************/ @@ -201,195 +212,201 @@ static char *xigmisc_extension_name = XIGMISC_PROTOCOL_NAME; /* * find_display - locate the display info block */ -static int XiGMiscCloseDisplay(); +static int XiGMiscCloseDisplay (); static XExtensionHooks xigmisc_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - XiGMiscCloseDisplay, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + XiGMiscCloseDisplay, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ }; -static XEXT_GENERATE_CLOSE_DISPLAY (XiGMiscCloseDisplay, xigmisc_info) - -static XEXT_GENERATE_FIND_DISPLAY (XiGMiscFindDisplay, xigmisc_info, - xigmisc_extension_name, - &xigmisc_extension_hooks, XiGMiscNumberEvents, NULL) - - +static +XEXT_GENERATE_CLOSE_DISPLAY (XiGMiscCloseDisplay, xigmisc_info) + static XEXT_GENERATE_FIND_DISPLAY (XiGMiscFindDisplay, xigmisc_info, + xigmisc_extension_name, + &xigmisc_extension_hooks, + XiGMiscNumberEvents, NULL) /*****************************************************************************/ - -Bool XiGMiscQueryVersion(Display *dpy, int *major, int *minor) + Bool XiGMiscQueryVersion (Display * dpy, int *major, int *minor) { - int opcode, event, error; - xXiGMiscQueryVersionReq *req; - xXiGMiscQueryVersionReply rep; - XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); + int opcode, event, error; + xXiGMiscQueryVersionReq *req; + xXiGMiscQueryVersionReply rep; + XExtDisplayInfo *info = XiGMiscFindDisplay (dpy); - if (!XQueryExtension(dpy, XIGMISC_PROTOCOL_NAME, &opcode, &event, &error)) - return xFalse; + if (!XQueryExtension + (dpy, XIGMISC_PROTOCOL_NAME, &opcode, &event, &error)) + return xFalse; - XiGMiscCheckExtension(dpy, info, xFalse); + XiGMiscCheckExtension (dpy, info, xFalse); - LockDisplay (dpy); - XiGMiscGetReq (XiGMiscQueryVersion, req, info); + LockDisplay (dpy); + XiGMiscGetReq (XiGMiscQueryVersion, req, info); - req->major = XIGMISC_MAJOR_VERSION; - req->minor = XIGMISC_MINOR_VERSION; + req->major = XIGMISC_MAJOR_VERSION; + req->minor = XIGMISC_MINOR_VERSION; - if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) { - UnlockDisplay(dpy); - SyncHandle(); - return xFalse; - } + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return xFalse; + } - *major = rep.major; - *minor = rep.minor; - UnlockDisplay(dpy); - SyncHandle(); + *major = rep.major; + *minor = rep.minor; + UnlockDisplay (dpy); + SyncHandle (); - return xTrue; + return xTrue; } -int XiGMiscQueryViews(Display *dpy, int screen, XiGMiscViewInfo **pviews) +int +XiGMiscQueryViews (Display * dpy, int screen, XiGMiscViewInfo ** pviews) { - int n, size; - XiGMiscViewInfo *views; - xXiGMiscQueryViewsReq *req; - xXiGMiscQueryViewsReply rep; - XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); - XiGMiscCheckExtension(dpy, info, 0); - - LockDisplay (dpy); - XiGMiscGetReq (XiGMiscQueryViews, req, info); - req->screen = screen; - - if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return 0; - } - - n = rep.nviews; - - if (n > 0) { - size = sizeof(XiGMiscViewInfo) * n; - views = (XiGMiscViewInfo*)Xmalloc(size); - if (!views) { - _XEatData(dpy, (unsigned long)size); - UnlockDisplay(dpy); - SyncHandle(); - return 0; + int n, size; + XiGMiscViewInfo *views; + xXiGMiscQueryViewsReq *req; + xXiGMiscQueryViewsReply rep; + XExtDisplayInfo *info = XiGMiscFindDisplay (dpy); + XiGMiscCheckExtension (dpy, info, 0); + + LockDisplay (dpy); + XiGMiscGetReq (XiGMiscQueryViews, req, info); + req->screen = screen; + + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return 0; } - _XReadPad(dpy, (void*)views, size); + n = rep.nviews; - *pviews = views; - } + if (n > 0) { + size = sizeof (XiGMiscViewInfo) * n; + views = (XiGMiscViewInfo *) Xmalloc (size); + if (!views) { + _XEatData (dpy, (unsigned long) size); + UnlockDisplay (dpy); + SyncHandle (); + return 0; + } + + _XReadPad (dpy, (void *) views, size); + + *pviews = views; + } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return n; + return n; } -int XiGMiscQueryResolutions(Display *dpy, int screen, int view, int *pactive, XiGMiscResolutionInfo **presolutions) +int +XiGMiscQueryResolutions (Display * dpy, int screen, int view, int *pactive, + XiGMiscResolutionInfo ** presolutions) { - int n, size; - XiGMiscResolutionInfo *resolutions; - xXiGMiscQueryResolutionsReq *req; - xXiGMiscQueryResolutionsReply rep; - XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); - XiGMiscCheckExtension(dpy, info, 0); - - LockDisplay (dpy); - XiGMiscGetReq (XiGMiscQueryResolutions, req, info); - req->screen = screen; - req->view = view; - - if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return 0; - } - - n = rep.nresolutions; - - if (n > 0) { - size = sizeof(XiGMiscResolutionInfo) * n; - resolutions = (XiGMiscResolutionInfo*)Xmalloc(size); - if (!resolutions) { - _XEatData(dpy, (unsigned long)size); - UnlockDisplay(dpy); - SyncHandle(); - return 0; + int n, size; + XiGMiscResolutionInfo *resolutions; + xXiGMiscQueryResolutionsReq *req; + xXiGMiscQueryResolutionsReply rep; + XExtDisplayInfo *info = XiGMiscFindDisplay (dpy); + XiGMiscCheckExtension (dpy, info, 0); + + LockDisplay (dpy); + XiGMiscGetReq (XiGMiscQueryResolutions, req, info); + req->screen = screen; + req->view = view; + + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return 0; } - _XReadPad(dpy, (void*)resolutions, size); + n = rep.nresolutions; - *presolutions = resolutions; - *pactive = rep.active; - } + if (n > 0) { + size = sizeof (XiGMiscResolutionInfo) * n; + resolutions = (XiGMiscResolutionInfo *) Xmalloc (size); + if (!resolutions) { + _XEatData (dpy, (unsigned long) size); + UnlockDisplay (dpy); + SyncHandle (); + return 0; + } - UnlockDisplay(dpy); - SyncHandle(); + _XReadPad (dpy, (void *) resolutions, size); - return n; + *presolutions = resolutions; + *pactive = rep.active; + } + + UnlockDisplay (dpy); + SyncHandle (); + + return n; } -void XiGMiscChangeResolution(Display *dpy, int screen, int view, int width, int height, int refresh) +void +XiGMiscChangeResolution (Display * dpy, int screen, int view, int width, + int height, int refresh) { - xXiGMiscChangeResolutionReq *req; - XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); + xXiGMiscChangeResolutionReq *req; + XExtDisplayInfo *info = XiGMiscFindDisplay (dpy); - XiGMiscSimpleCheckExtension(dpy, info); + XiGMiscSimpleCheckExtension (dpy, info); - LockDisplay (dpy); - XiGMiscGetReq (XiGMiscChangeResolution, req, info); - req->screen = screen; - req->view = view; - req->width = width; - req->height = height; - req->refresh = refresh; + LockDisplay (dpy); + XiGMiscGetReq (XiGMiscChangeResolution, req, info); + req->screen = screen; + req->view = view; + req->width = width; + req->height = height; + req->refresh = refresh; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -Bool XiGMiscFullScreen(Display *dpy, int screen, XID window, XID cmap) +Bool +XiGMiscFullScreen (Display * dpy, int screen, XID window, XID cmap) { - xXiGMiscFullScreenReq *req; - xXiGMiscFullScreenReply rep; - XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); - - XiGMiscCheckExtension(dpy, info, xFalse); - - LockDisplay (dpy); - XiGMiscGetReq (XiGMiscFullScreen, req, info); - req->screen = screen; - req->pad0 = 0; - req->pad1 = 0; - req->window = window; - req->cmap = cmap; - - if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) { - UnlockDisplay(dpy); - SyncHandle(); - return xFalse; - } - - UnlockDisplay(dpy); - SyncHandle(); - - return (rep.success ? xTrue : xFalse); + xXiGMiscFullScreenReq *req; + xXiGMiscFullScreenReply rep; + XExtDisplayInfo *info = XiGMiscFindDisplay (dpy); + + XiGMiscCheckExtension (dpy, info, xFalse); + + LockDisplay (dpy); + XiGMiscGetReq (XiGMiscFullScreen, req, info); + req->screen = screen; + req->pad0 = 0; + req->pad1 = 0; + req->window = window; + req->cmap = cmap; + + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return xFalse; + } + + UnlockDisplay (dpy); + SyncHandle (); + + return (rep.success ? xTrue : xFalse); } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/Xinerama/Xinerama.c b/src/video/Xext/Xinerama/Xinerama.c index 049be45c2..a130fc2c7 100644 --- a/src/video/Xext/Xinerama/Xinerama.c +++ b/src/video/Xext/Xinerama/Xinerama.c @@ -31,9 +31,9 @@ Equipment Corporation. #include #include #include "../extensions/Xext.h" -#include "../extensions/extutil.h" /* in ../include */ +#include "../extensions/extutil.h" /* in ../include */ #include "../extensions/panoramiXext.h" -#include "../extensions/panoramiXproto.h" /* in ../include */ +#include "../extensions/panoramiXproto.h" /* in ../include */ #include "../extensions/Xinerama.h" static XExtensionInfo _panoramiX_ext_info_data; @@ -45,63 +45,54 @@ static /* const */ char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME; #define PanoramiXSimpleCheckExtension(dpy,i) \ XextSimpleCheckExtension (dpy, i, panoramiX_extension_name) -static int close_display(); +static int close_display (); static /* const */ XExtensionHooks panoramiX_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - close_display, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + close_display, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ }; -static XEXT_GENERATE_FIND_DISPLAY (find_display, panoramiX_ext_info, - panoramiX_extension_name, - &panoramiX_extension_hooks, - 0, NULL) - -static XEXT_GENERATE_CLOSE_DISPLAY (close_display, panoramiX_ext_info) - - - +static +XEXT_GENERATE_FIND_DISPLAY (find_display, panoramiX_ext_info, + panoramiX_extension_name, + &panoramiX_extension_hooks, 0, NULL) + static XEXT_GENERATE_CLOSE_DISPLAY (close_display, panoramiX_ext_info) /**************************************************************************** * * * PanoramiX public interfaces * * * ****************************************************************************/ - -Bool SDL_NAME(XPanoramiXQueryExtension) ( - Display *dpy, - int *event_basep, - int *error_basep -) + Bool SDL_NAME (XPanoramiXQueryExtension) (Display * dpy, + int *event_basep, + int *error_basep) { XExtDisplayInfo *info = find_display (dpy); - if (XextHasExtension(info)) { - *event_basep = info->codes->first_event; - *error_basep = info->codes->first_error; - return True; + if (XextHasExtension (info)) { + *event_basep = info->codes->first_event; + *error_basep = info->codes->first_error; + return True; } else { - return False; + return False; } } -Status SDL_NAME(XPanoramiXQueryVersion)( - Display *dpy, - int *major_versionp, - int *minor_versionp -) +Status SDL_NAME (XPanoramiXQueryVersion) (Display * dpy, + int *major_versionp, + int *minor_versionp) { XExtDisplayInfo *info = find_display (dpy); - xPanoramiXQueryVersionReply rep; - register xPanoramiXQueryVersionReq *req; + xPanoramiXQueryVersionReply rep; + register xPanoramiXQueryVersionReq *req; PanoramiXCheckExtension (dpy, info, 0); @@ -111,10 +102,10 @@ Status SDL_NAME(XPanoramiXQueryVersion)( req->panoramiXReqType = X_PanoramiXQueryVersion; req->clientMajor = PANORAMIX_MAJOR_VERSION; req->clientMinor = PANORAMIX_MINOR_VERSION; - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { - UnlockDisplay (dpy); - SyncHandle (); - return 0; + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return 0; } *major_versionp = rep.majorVersion; *minor_versionp = rep.minorVersion; @@ -123,20 +114,20 @@ Status SDL_NAME(XPanoramiXQueryVersion)( return 1; } -SDL_NAME(XPanoramiXInfo) *SDL_NAME(XPanoramiXAllocInfo)(void) +SDL_NAME (XPanoramiXInfo) * SDL_NAME (XPanoramiXAllocInfo) (void) { - return (SDL_NAME(XPanoramiXInfo) *) Xmalloc (sizeof (SDL_NAME(XPanoramiXInfo))); + return (SDL_NAME (XPanoramiXInfo) *) + Xmalloc (sizeof (SDL_NAME (XPanoramiXInfo))); } -Status SDL_NAME(XPanoramiXGetState) ( - Display *dpy, - Drawable drawable, - SDL_NAME(XPanoramiXInfo) *panoramiX_info -) +Status SDL_NAME (XPanoramiXGetState) (Display * dpy, + Drawable drawable, + SDL_NAME (XPanoramiXInfo) * + panoramiX_info) { - XExtDisplayInfo *info = find_display (dpy); - xPanoramiXGetStateReply rep; - register xPanoramiXGetStateReq *req; + XExtDisplayInfo *info = find_display (dpy); + xPanoramiXGetStateReply rep; + register xPanoramiXGetStateReq *req; PanoramiXCheckExtension (dpy, info, 0); @@ -145,10 +136,10 @@ Status SDL_NAME(XPanoramiXGetState) ( req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_PanoramiXGetState; req->window = drawable; - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { - UnlockDisplay (dpy); - SyncHandle (); - return 0; + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return 0; } UnlockDisplay (dpy); SyncHandle (); @@ -157,15 +148,14 @@ Status SDL_NAME(XPanoramiXGetState) ( return 1; } -Status SDL_NAME(XPanoramiXGetScreenCount) ( - Display *dpy, - Drawable drawable, - SDL_NAME(XPanoramiXInfo) *panoramiX_info -) +Status SDL_NAME (XPanoramiXGetScreenCount) (Display * dpy, + Drawable drawable, + SDL_NAME (XPanoramiXInfo) * + panoramiX_info) { - XExtDisplayInfo *info = find_display (dpy); - xPanoramiXGetScreenCountReply rep; - register xPanoramiXGetScreenCountReq *req; + XExtDisplayInfo *info = find_display (dpy); + xPanoramiXGetScreenCountReply rep; + register xPanoramiXGetScreenCountReq *req; PanoramiXCheckExtension (dpy, info, 0); @@ -174,10 +164,10 @@ Status SDL_NAME(XPanoramiXGetScreenCount) ( req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_PanoramiXGetScreenCount; req->window = drawable; - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { - UnlockDisplay (dpy); - SyncHandle (); - return 0; + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return 0; } UnlockDisplay (dpy); SyncHandle (); @@ -186,16 +176,15 @@ Status SDL_NAME(XPanoramiXGetScreenCount) ( return 1; } -Status SDL_NAME(XPanoramiXGetScreenSize) ( - Display *dpy, - Drawable drawable, - int screen_num, - SDL_NAME(XPanoramiXInfo) *panoramiX_info -) +Status SDL_NAME (XPanoramiXGetScreenSize) (Display * dpy, + Drawable drawable, + int screen_num, + SDL_NAME (XPanoramiXInfo) * + panoramiX_info) { - XExtDisplayInfo *info = find_display (dpy); - xPanoramiXGetScreenSizeReply rep; - register xPanoramiXGetScreenSizeReq *req; + XExtDisplayInfo *info = find_display (dpy); + xPanoramiXGetScreenSizeReply rep; + register xPanoramiXGetScreenSizeReq *req; PanoramiXCheckExtension (dpy, info, 0); @@ -204,17 +193,17 @@ Status SDL_NAME(XPanoramiXGetScreenSize) ( req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_PanoramiXGetScreenSize; req->window = drawable; - req->screen = screen_num; /* need to define */ - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { - UnlockDisplay (dpy); - SyncHandle (); - return 0; + req->screen = screen_num; /* need to define */ + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return 0; } UnlockDisplay (dpy); SyncHandle (); panoramiX_info->window = rep.window; panoramiX_info->screen = rep.screen; - panoramiX_info->width = rep.width; + panoramiX_info->width = rep.width; panoramiX_info->height = rep.height; return 1; } @@ -225,41 +214,34 @@ Status SDL_NAME(XPanoramiXGetScreenSize) ( in the "Xinerama" namespace instead of "PanoramiX". \*******************************************************************/ -Bool SDL_NAME(XineramaQueryExtension) ( - Display *dpy, - int *event_base, - int *error_base -) +Bool SDL_NAME (XineramaQueryExtension) (Display * dpy, + int *event_base, int *error_base) { - return SDL_NAME(XPanoramiXQueryExtension)(dpy, event_base, error_base); + return SDL_NAME (XPanoramiXQueryExtension) (dpy, event_base, error_base); } -Status SDL_NAME(XineramaQueryVersion)( - Display *dpy, - int *major, - int *minor -) +Status SDL_NAME (XineramaQueryVersion) (Display * dpy, int *major, int *minor) { - return SDL_NAME(XPanoramiXQueryVersion)(dpy, major, minor); + return SDL_NAME (XPanoramiXQueryVersion) (dpy, major, minor); } -Bool SDL_NAME(XineramaIsActive)(Display *dpy) +Bool SDL_NAME (XineramaIsActive) (Display * dpy) { - xXineramaIsActiveReply rep; - xXineramaIsActiveReq *req; - XExtDisplayInfo *info = find_display (dpy); + xXineramaIsActiveReply rep; + xXineramaIsActiveReq *req; + XExtDisplayInfo *info = find_display (dpy); - if(!XextHasExtension(info)) - return False; /* server doesn't even have the extension */ + if (!XextHasExtension (info)) + return False; /* server doesn't even have the extension */ LockDisplay (dpy); GetReq (XineramaIsActive, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_XineramaIsActive; - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { - UnlockDisplay (dpy); - SyncHandle (); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } UnlockDisplay (dpy); SyncHandle (); @@ -268,16 +250,13 @@ Bool SDL_NAME(XineramaIsActive)(Display *dpy) #include -SDL_NAME(XineramaScreenInfo) * -SDL_NAME(XineramaQueryScreens)( - Display *dpy, - int *number -) +SDL_NAME (XineramaScreenInfo) * +SDL_NAME (XineramaQueryScreens) (Display * dpy, int *number) { - XExtDisplayInfo *info = find_display (dpy); - xXineramaQueryScreensReply rep; - xXineramaQueryScreensReq *req; - SDL_NAME(XineramaScreenInfo) *scrnInfo = NULL; + XExtDisplayInfo *info = find_display (dpy); + xXineramaQueryScreensReply rep; + xXineramaQueryScreensReq *req; + SDL_NAME (XineramaScreenInfo) * scrnInfo = NULL; PanoramiXCheckExtension (dpy, info, 0); @@ -285,29 +264,30 @@ SDL_NAME(XineramaQueryScreens)( GetReq (XineramaQueryScreens, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_XineramaQueryScreens; - if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay (dpy); - SyncHandle (); - return NULL; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return NULL; } - if(rep.number) { - if((scrnInfo = Xmalloc(sizeof(SDL_NAME(XineramaScreenInfo)) * rep.number))) { - xXineramaScreenInfo scratch; - int i; - - for(i = 0; i < rep.number; i++) { - _XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo); - scrnInfo[i].screen_number = i; - scrnInfo[i].x_org = scratch.x_org; - scrnInfo[i].y_org = scratch.y_org; - scrnInfo[i].width = scratch.width; - scrnInfo[i].height = scratch.height; - } - - *number = rep.number; - } else - _XEatData(dpy, rep.length << 2); + if (rep.number) { + if ((scrnInfo = + Xmalloc (sizeof (SDL_NAME (XineramaScreenInfo)) * rep.number))) { + xXineramaScreenInfo scratch; + int i; + + for (i = 0; i < rep.number; i++) { + _XRead (dpy, (char *) (&scratch), sz_XineramaScreenInfo); + scrnInfo[i].screen_number = i; + scrnInfo[i].x_org = scratch.x_org; + scrnInfo[i].y_org = scratch.y_org; + scrnInfo[i].width = scratch.width; + scrnInfo[i].height = scratch.height; + } + + *number = rep.number; + } else + _XEatData (dpy, rep.length << 2); } UnlockDisplay (dpy); @@ -315,5 +295,4 @@ SDL_NAME(XineramaQueryScreens)( return scrnInfo; } - - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/Xv/Xv.c b/src/video/Xext/Xv/Xv.c index 7147b9e8c..55fec24f8 100644 --- a/src/video/Xext/Xv/Xv.c +++ b/src/video/Xext/Xv/Xv.c @@ -63,1089 +63,1037 @@ static char *xv_extension_name = XvName; #define XvCheckExtension(dpy, i, val) \ XextCheckExtension(dpy, i, xv_extension_name, val) -static char *xv_error_string(); -static int xv_close_display(); -static Bool xv_wire_to_event(); +static char *xv_error_string (); +static int xv_close_display (); +static Bool xv_wire_to_event (); static XExtensionHooks xv_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - xv_close_display, /* close_display */ - xv_wire_to_event, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - xv_error_string /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + xv_close_display, /* close_display */ + xv_wire_to_event, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + xv_error_string /* error_string */ }; -static char *xv_error_list[] = -{ - "BadPort", /* XvBadPort */ - "BadEncoding", /* XvBadEncoding */ - "BadControl" /* XvBadControl */ +static char *xv_error_list[] = { + "BadPort", /* XvBadPort */ + "BadEncoding", /* XvBadEncoding */ + "BadControl" /* XvBadControl */ }; -static XEXT_GENERATE_CLOSE_DISPLAY (xv_close_display, xv_info) +static +XEXT_GENERATE_CLOSE_DISPLAY (xv_close_display, xv_info) + static XEXT_GENERATE_FIND_DISPLAY (xv_find_display, xv_info, + xv_extension_name, + &xv_extension_hooks, + XvNumEvents, NULL) + static XEXT_GENERATE_ERROR_STRING (xv_error_string, xv_extension_name, + XvNumErrors, xv_error_list) + int SDL_NAME (XvQueryExtension) (Display * dpy, + unsigned int *p_version, + unsigned int *p_revision, + unsigned int *p_requestBase, + unsigned int *p_eventBase, + unsigned int *p_errorBase) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvQueryExtensionReq *req; + xvQueryExtensionReply rep; + + XvCheckExtension (dpy, info, XvBadExtension); + LockDisplay (dpy); -static XEXT_GENERATE_FIND_DISPLAY (xv_find_display, xv_info, - xv_extension_name, - &xv_extension_hooks, - XvNumEvents, NULL) - + XvGetReq (QueryExtension, req); -static XEXT_GENERATE_ERROR_STRING (xv_error_string, xv_extension_name, - XvNumErrors, xv_error_list) + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return XvBadExtension; + } + *p_version = rep.version; + *p_revision = rep.revision; + *p_requestBase = info->codes->major_opcode; + *p_eventBase = info->codes->first_event; + *p_errorBase = info->codes->first_error; -int -SDL_NAME(XvQueryExtension)( - Display *dpy, - unsigned int *p_version, - unsigned int *p_revision, - unsigned int *p_requestBase, - unsigned int *p_eventBase, - unsigned int *p_errorBase -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvQueryExtensionReq *req; - xvQueryExtensionReply rep; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - XvGetReq(QueryExtension, req); - - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return XvBadExtension; - } - - *p_version = rep.version; - *p_revision = rep.revision; - *p_requestBase = info->codes->major_opcode; - *p_eventBase = info->codes->first_event; - *p_errorBase = info->codes->first_error; - - UnlockDisplay(dpy); - SyncHandle(); - - return Success; + UnlockDisplay (dpy); + SyncHandle (); + + return Success; } int -SDL_NAME(XvQueryAdaptors)( - Display *dpy, - Window window, - unsigned int *p_nAdaptors, - SDL_NAME(XvAdaptorInfo) **p_pAdaptors -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvQueryAdaptorsReq *req; - xvQueryAdaptorsReply rep; - int size,ii,jj; - char *name; - SDL_NAME(XvAdaptorInfo) *pas, *pa; - SDL_NAME(XvFormat) *pfs, *pf; - char *buffer; - union +SDL_NAME (XvQueryAdaptors) (Display * dpy, + Window window, + unsigned int *p_nAdaptors, + SDL_NAME (XvAdaptorInfo) ** p_pAdaptors) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvQueryAdaptorsReq *req; + xvQueryAdaptorsReply rep; + int size, ii, jj; + char *name; + SDL_NAME (XvAdaptorInfo) * pas, *pa; + SDL_NAME (XvFormat) * pfs, *pf; + char *buffer; + union { - char *buffer; - char *string; - xvAdaptorInfo *pa; - xvFormat *pf; + char *buffer; + char *string; + xvAdaptorInfo *pa; + xvFormat *pf; } u; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - XvGetReq(QueryAdaptors, req); - req->window = window; - - /* READ THE REPLY */ - - if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadReply); - } - - size = rep.length << 2; - if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadAlloc); - } - _XRead (dpy, buffer, size); - - u.buffer = buffer; - - /* GET INPUT ADAPTORS */ - - if (rep.num_adaptors == 0) { - pas = NULL; - } else { - size = rep.num_adaptors*sizeof(SDL_NAME(XvAdaptorInfo)); - if ((pas=(SDL_NAME(XvAdaptorInfo) *)Xmalloc(size))==NULL) { - Xfree(buffer); - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadAlloc); - } - } - - /* INIT ADAPTOR FIELDS */ - - pa = pas; - for (ii=0; iinum_adaptors = 0; - pa->name = (char *)NULL; - pa->formats = (SDL_NAME(XvFormat) *)NULL; - pa++; - } - - pa = pas; - for (ii=0; iitype = u.pa->type; - pa->base_id = u.pa->base_id; - pa->num_ports = u.pa->num_ports; - pa->num_formats = u.pa->num_formats; - pa->num_adaptors = rep.num_adaptors - ii; - - /* GET ADAPTOR NAME */ - - size = u.pa->name_size; - u.buffer += (sz_xvAdaptorInfo + 3) & ~3; - - if ( (name = (char *)Xmalloc(size+1)) == NULL) - { - SDL_NAME(XvFreeAdaptorInfo)(pas); - Xfree(buffer); - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadAlloc); - } - SDL_strlcpy(name, u.string, size); - pa->name = name; - - u.buffer += (size + 3) & ~3; - - /* GET FORMATS */ - - size = pa->num_formats*sizeof(SDL_NAME(XvFormat)); - if ((pfs=(SDL_NAME(XvFormat) *)Xmalloc(size))==NULL) { - SDL_NAME(XvFreeAdaptorInfo)(pas); - Xfree(buffer); - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadAlloc); - } - - pf = pfs; - for (jj=0; jjnum_formats; jj++) { - pf->depth = u.pf->depth; - pf->visual_id = u.pf->visual; - pf++; - - u.buffer += (sz_xvFormat + 3) & ~3; - } - - pa->formats = pfs; - - pa++; - - } - - *p_nAdaptors = rep.num_adaptors; - *p_pAdaptors = pas; - - Xfree(buffer); - UnlockDisplay(dpy); - SyncHandle(); - - return (Success); + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + XvGetReq (QueryAdaptors, req); + req->window = window; + + /* READ THE REPLY */ + + if (_XReply (dpy, (xReply *) & rep, 0, xFalse) == 0) { + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadReply); + } + + size = rep.length << 2; + if ((buffer = (char *) Xmalloc ((unsigned) size)) == NULL) { + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadAlloc); + } + _XRead (dpy, buffer, size); + + u.buffer = buffer; + + /* GET INPUT ADAPTORS */ + + if (rep.num_adaptors == 0) { + pas = NULL; + } else { + size = rep.num_adaptors * sizeof (SDL_NAME (XvAdaptorInfo)); + if ((pas = (SDL_NAME (XvAdaptorInfo) *) Xmalloc (size)) == NULL) { + Xfree (buffer); + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadAlloc); + } + } + + /* INIT ADAPTOR FIELDS */ + + pa = pas; + for (ii = 0; ii < rep.num_adaptors; ii++) { + pa->num_adaptors = 0; + pa->name = (char *) NULL; + pa->formats = (SDL_NAME (XvFormat) *) NULL; + pa++; + } + + pa = pas; + for (ii = 0; ii < rep.num_adaptors; ii++) { + pa->type = u.pa->type; + pa->base_id = u.pa->base_id; + pa->num_ports = u.pa->num_ports; + pa->num_formats = u.pa->num_formats; + pa->num_adaptors = rep.num_adaptors - ii; + + /* GET ADAPTOR NAME */ + + size = u.pa->name_size; + u.buffer += (sz_xvAdaptorInfo + 3) & ~3; + + if ((name = (char *) Xmalloc (size + 1)) == NULL) { + SDL_NAME (XvFreeAdaptorInfo) (pas); + Xfree (buffer); + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadAlloc); + } + SDL_strlcpy (name, u.string, size); + pa->name = name; + + u.buffer += (size + 3) & ~3; + + /* GET FORMATS */ + + size = pa->num_formats * sizeof (SDL_NAME (XvFormat)); + if ((pfs = (SDL_NAME (XvFormat) *) Xmalloc (size)) == NULL) { + SDL_NAME (XvFreeAdaptorInfo) (pas); + Xfree (buffer); + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadAlloc); + } + + pf = pfs; + for (jj = 0; jj < pa->num_formats; jj++) { + pf->depth = u.pf->depth; + pf->visual_id = u.pf->visual; + pf++; + + u.buffer += (sz_xvFormat + 3) & ~3; + } + + pa->formats = pfs; + + pa++; + + } + + *p_nAdaptors = rep.num_adaptors; + *p_pAdaptors = pas; + + Xfree (buffer); + UnlockDisplay (dpy); + SyncHandle (); + + return (Success); } -void -SDL_NAME(XvFreeAdaptorInfo)(SDL_NAME(XvAdaptorInfo) *pAdaptors) +void SDL_NAME (XvFreeAdaptorInfo) (SDL_NAME (XvAdaptorInfo) * pAdaptors) { - SDL_NAME(XvAdaptorInfo) *pa; - int ii; + SDL_NAME (XvAdaptorInfo) * pa; + int ii; - if (!pAdaptors) return; + if (!pAdaptors) + return; - pa = pAdaptors; + pa = pAdaptors; - for (ii=0; iinum_adaptors; ii++, pa++) - { - if (pa->name) - { - Xfree(pa->name); - } - if (pa->formats) - { - Xfree(pa->formats); - } - } - - Xfree(pAdaptors); + for (ii = 0; ii < pAdaptors->num_adaptors; ii++, pa++) { + if (pa->name) { + Xfree (pa->name); + } + if (pa->formats) { + Xfree (pa->formats); + } + } + + Xfree (pAdaptors); } int -SDL_NAME(XvQueryEncodings)( - Display *dpy, - XvPortID port, - unsigned int *p_nEncodings, - SDL_NAME(XvEncodingInfo) **p_pEncodings -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvQueryEncodingsReq *req; - xvQueryEncodingsReply rep; - int size, jj; - char *name; - SDL_NAME(XvEncodingInfo) *pes, *pe; - char *buffer; - union +SDL_NAME (XvQueryEncodings) (Display * dpy, + XvPortID port, + unsigned int *p_nEncodings, + SDL_NAME (XvEncodingInfo) ** p_pEncodings) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvQueryEncodingsReq *req; + xvQueryEncodingsReply rep; + int size, jj; + char *name; + SDL_NAME (XvEncodingInfo) * pes, *pe; + char *buffer; + union { - char *buffer; - char *string; - xvEncodingInfo *pe; + char *buffer; + char *string; + xvEncodingInfo *pe; } u; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - XvGetReq(QueryEncodings, req); - req->port = port; - - /* READ THE REPLY */ - - if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadReply); - } - - size = rep.length << 2; - if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadAlloc); - } - _XRead (dpy, buffer, size); - - u.buffer = buffer; - - /* GET ENCODINGS */ - - size = rep.num_encodings*sizeof(SDL_NAME(XvEncodingInfo)); - if ( (pes = (SDL_NAME(XvEncodingInfo) *)Xmalloc(size)) == NULL) { - Xfree(buffer); - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadAlloc); - } - - /* INITIALIZE THE ENCODING POINTER */ - - pe = pes; - for (jj=0; jjname = (char *)NULL; - pe->num_encodings = 0; - pe++; - } - - pe = pes; - for (jj=0; jjencoding_id = u.pe->encoding; - pe->width = u.pe->width; - pe->height = u.pe->height; - pe->rate.numerator = u.pe->rate.numerator; - pe->rate.denominator = u.pe->rate.denominator; - pe->num_encodings = rep.num_encodings - jj; - - size = u.pe->name_size; - u.buffer += (sz_xvEncodingInfo + 3) & ~3; - - if ( (name = (char *)Xmalloc(size+1)) == NULL) { - Xfree(buffer); - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadAlloc); - } - SDL_strlcpy(name, u.string, size); - pe->name = name; - pe++; - - u.buffer += (size + 3) & ~3; - } - - *p_nEncodings = rep.num_encodings; - *p_pEncodings = pes; - - Xfree(buffer); - UnlockDisplay(dpy); - SyncHandle(); - - return (Success); + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + XvGetReq (QueryEncodings, req); + req->port = port; + + /* READ THE REPLY */ + + if (_XReply (dpy, (xReply *) & rep, 0, xFalse) == 0) { + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadReply); + } + + size = rep.length << 2; + if ((buffer = (char *) Xmalloc ((unsigned) size)) == NULL) { + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadAlloc); + } + _XRead (dpy, buffer, size); + + u.buffer = buffer; + + /* GET ENCODINGS */ + + size = rep.num_encodings * sizeof (SDL_NAME (XvEncodingInfo)); + if ((pes = (SDL_NAME (XvEncodingInfo) *) Xmalloc (size)) == NULL) { + Xfree (buffer); + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadAlloc); + } + + /* INITIALIZE THE ENCODING POINTER */ + + pe = pes; + for (jj = 0; jj < rep.num_encodings; jj++) { + pe->name = (char *) NULL; + pe->num_encodings = 0; + pe++; + } + + pe = pes; + for (jj = 0; jj < rep.num_encodings; jj++) { + pe->encoding_id = u.pe->encoding; + pe->width = u.pe->width; + pe->height = u.pe->height; + pe->rate.numerator = u.pe->rate.numerator; + pe->rate.denominator = u.pe->rate.denominator; + pe->num_encodings = rep.num_encodings - jj; + + size = u.pe->name_size; + u.buffer += (sz_xvEncodingInfo + 3) & ~3; + + if ((name = (char *) Xmalloc (size + 1)) == NULL) { + Xfree (buffer); + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadAlloc); + } + SDL_strlcpy (name, u.string, size); + pe->name = name; + pe++; + + u.buffer += (size + 3) & ~3; + } + + *p_nEncodings = rep.num_encodings; + *p_pEncodings = pes; + + Xfree (buffer); + UnlockDisplay (dpy); + SyncHandle (); + + return (Success); } -void -SDL_NAME(XvFreeEncodingInfo)(SDL_NAME(XvEncodingInfo) *pEncodings) +void SDL_NAME (XvFreeEncodingInfo) (SDL_NAME (XvEncodingInfo) * pEncodings) { - SDL_NAME(XvEncodingInfo) *pe; - int ii; + SDL_NAME (XvEncodingInfo) * pe; + int ii; - if (!pEncodings) return; + if (!pEncodings) + return; - pe = pEncodings; + pe = pEncodings; - for (ii=0; iinum_encodings; ii++, pe++) { - if (pe->name) Xfree(pe->name); - } + for (ii = 0; ii < pEncodings->num_encodings; ii++, pe++) { + if (pe->name) + Xfree (pe->name); + } - Xfree(pEncodings); + Xfree (pEncodings); } int -SDL_NAME(XvPutVideo)( - Display *dpy, - XvPortID port, - Drawable d, - GC gc, - int vx, int vy, - unsigned int vw, unsigned int vh, - int dx, int dy, - unsigned int dw, unsigned int dh -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvPutVideoReq *req; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - FlushGC(dpy, gc); - - XvGetReq(PutVideo, req); - - req->port = port; - req->drawable = d; - req->gc = gc->gid; - req->vid_x = vx; - req->vid_y = vy; - req->vid_w = vw; - req->vid_h = vh; - req->drw_x = dx; - req->drw_y = dy; - req->drw_w = dw; - req->drw_h = dh; - - UnlockDisplay(dpy); - SyncHandle(); - - return Success; +SDL_NAME (XvPutVideo) (Display * dpy, + XvPortID port, + Drawable d, + GC gc, + int vx, int vy, + unsigned int vw, unsigned int vh, + int dx, int dy, unsigned int dw, unsigned int dh) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvPutVideoReq *req; + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + FlushGC (dpy, gc); + + XvGetReq (PutVideo, req); + + req->port = port; + req->drawable = d; + req->gc = gc->gid; + req->vid_x = vx; + req->vid_y = vy; + req->vid_w = vw; + req->vid_h = vh; + req->drw_x = dx; + req->drw_y = dy; + req->drw_w = dw; + req->drw_h = dh; + + UnlockDisplay (dpy); + SyncHandle (); + + return Success; } int -SDL_NAME(XvPutStill)( - Display *dpy, - XvPortID port, - Drawable d, - GC gc, - int vx, int vy, - unsigned int vw, unsigned int vh, - int dx, int dy, - unsigned int dw, unsigned int dh -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvPutStillReq *req; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - FlushGC(dpy, gc); - - XvGetReq(PutStill, req); - req->port = port; - req->drawable = d; - req->gc = gc->gid; - req->vid_x = vx; - req->vid_y = vy; - req->vid_w = vw; - req->vid_h = vh; - req->drw_x = dx; - req->drw_y = dy; - req->drw_w = dw; - req->drw_h = dh; - - UnlockDisplay(dpy); - SyncHandle(); - - return Success; +SDL_NAME (XvPutStill) (Display * dpy, + XvPortID port, + Drawable d, + GC gc, + int vx, int vy, + unsigned int vw, unsigned int vh, + int dx, int dy, unsigned int dw, unsigned int dh) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvPutStillReq *req; + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + FlushGC (dpy, gc); + + XvGetReq (PutStill, req); + req->port = port; + req->drawable = d; + req->gc = gc->gid; + req->vid_x = vx; + req->vid_y = vy; + req->vid_w = vw; + req->vid_h = vh; + req->drw_x = dx; + req->drw_y = dy; + req->drw_w = dw; + req->drw_h = dh; + + UnlockDisplay (dpy); + SyncHandle (); + + return Success; } int -SDL_NAME(XvGetVideo)( - Display *dpy, - XvPortID port, - Drawable d, - GC gc, - int vx, int vy, - unsigned int vw, unsigned int vh, - int dx, int dy, - unsigned int dw, unsigned int dh -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvGetVideoReq *req; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - FlushGC(dpy, gc); - - XvGetReq(GetVideo, req); - req->port = port; - req->drawable = d; - req->gc = gc->gid; - req->vid_x = vx; - req->vid_y = vy; - req->vid_w = vw; - req->vid_h = vh; - req->drw_x = dx; - req->drw_y = dy; - req->drw_w = dw; - req->drw_h = dh; - - UnlockDisplay(dpy); - SyncHandle(); - - return Success; +SDL_NAME (XvGetVideo) (Display * dpy, + XvPortID port, + Drawable d, + GC gc, + int vx, int vy, + unsigned int vw, unsigned int vh, + int dx, int dy, unsigned int dw, unsigned int dh) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvGetVideoReq *req; + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + FlushGC (dpy, gc); + + XvGetReq (GetVideo, req); + req->port = port; + req->drawable = d; + req->gc = gc->gid; + req->vid_x = vx; + req->vid_y = vy; + req->vid_w = vw; + req->vid_h = vh; + req->drw_x = dx; + req->drw_y = dy; + req->drw_w = dw; + req->drw_h = dh; + + UnlockDisplay (dpy); + SyncHandle (); + + return Success; } int -SDL_NAME(XvGetStill)( - Display *dpy, - XvPortID port, - Drawable d, - GC gc, - int vx, int vy, - unsigned int vw, unsigned int vh, - int dx, int dy, - unsigned int dw, unsigned int dh -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvGetStillReq *req; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - FlushGC(dpy, gc); - - XvGetReq(GetStill, req); - req->port = port; - req->drawable = d; - req->gc = gc->gid; - req->vid_x = vx; - req->vid_y = vy; - req->vid_w = vw; - req->vid_h = vh; - req->drw_x = dx; - req->drw_y = dy; - req->drw_w = dw; - req->drw_h = dh; - - UnlockDisplay(dpy); - SyncHandle(); - - return Success; +SDL_NAME (XvGetStill) (Display * dpy, + XvPortID port, + Drawable d, + GC gc, + int vx, int vy, + unsigned int vw, unsigned int vh, + int dx, int dy, unsigned int dw, unsigned int dh) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvGetStillReq *req; + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + FlushGC (dpy, gc); + + XvGetReq (GetStill, req); + req->port = port; + req->drawable = d; + req->gc = gc->gid; + req->vid_x = vx; + req->vid_y = vy; + req->vid_w = vw; + req->vid_h = vh; + req->drw_x = dx; + req->drw_y = dy; + req->drw_w = dw; + req->drw_h = dh; + + UnlockDisplay (dpy); + SyncHandle (); + + return Success; } -int -SDL_NAME(XvStopVideo)( - Display *dpy, - XvPortID port, - Drawable draw -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvStopVideoReq *req; +int SDL_NAME (XvStopVideo) (Display * dpy, XvPortID port, Drawable draw) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvStopVideoReq *req; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(StopVideo, req); - req->port = port; - req->drawable = draw; + XvGetReq (StopVideo, req); + req->port = port; + req->drawable = draw; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return Success; + return Success; } -int -SDL_NAME(XvGrabPort)( - Display *dpy, - XvPortID port, - Time time -){ - XExtDisplayInfo *info = xv_find_display(dpy); - int result; - xvGrabPortReply rep; - xvGrabPortReq *req; +int SDL_NAME (XvGrabPort) (Display * dpy, XvPortID port, Time time) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + int result; + xvGrabPortReply rep; + xvGrabPortReq *req; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(GrabPort, req); - req->port = port; - req->time = time; + XvGetReq (GrabPort, req); + req->port = port; + req->time = time; - if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0) - rep.result = GrabSuccess; + if (_XReply (dpy, (xReply *) & rep, 0, xTrue) == 0) + rep.result = GrabSuccess; - result = rep.result; + result = rep.result; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return result; + return result; } -int -SDL_NAME(XvUngrabPort)( - Display *dpy, - XvPortID port, - Time time -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvUngrabPortReq *req; +int SDL_NAME (XvUngrabPort) (Display * dpy, XvPortID port, Time time) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvUngrabPortReq *req; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(UngrabPort, req); - req->port = port; - req->time = time; + XvGetReq (UngrabPort, req); + req->port = port; + req->time = time; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return Success; + return Success; } int -SDL_NAME(XvSelectVideoNotify)( - Display *dpy, - Drawable drawable, - Bool onoff -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvSelectVideoNotifyReq *req; +SDL_NAME (XvSelectVideoNotify) (Display * dpy, Drawable drawable, Bool onoff) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvSelectVideoNotifyReq *req; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(SelectVideoNotify, req); - req->drawable = drawable; - req->onoff = onoff; + XvGetReq (SelectVideoNotify, req); + req->drawable = drawable; + req->onoff = onoff; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return Success; + return Success; } -int -SDL_NAME(XvSelectPortNotify)( - Display *dpy, - XvPortID port, - Bool onoff -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvSelectPortNotifyReq *req; +int SDL_NAME (XvSelectPortNotify) (Display * dpy, XvPortID port, Bool onoff) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvSelectPortNotifyReq *req; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(SelectPortNotify, req); - req->port = port; - req->onoff = onoff; + XvGetReq (SelectPortNotify, req); + req->port = port; + req->onoff = onoff; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return Success; + return Success; } int -SDL_NAME(XvSetPortAttribute) ( - Display *dpy, - XvPortID port, - Atom attribute, - int value -) +SDL_NAME (XvSetPortAttribute) (Display * dpy, + XvPortID port, Atom attribute, int value) { - XExtDisplayInfo *info = xv_find_display(dpy); - xvSetPortAttributeReq *req; + XExtDisplayInfo *info = xv_find_display (dpy); + xvSetPortAttributeReq *req; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(SetPortAttribute, req); - req->port = port; - req->attribute = attribute; - req->value = value; + XvGetReq (SetPortAttribute, req); + req->port = port; + req->attribute = attribute; + req->value = value; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return (Success); + return (Success); } int -SDL_NAME(XvGetPortAttribute) ( - Display *dpy, - XvPortID port, - Atom attribute, - int *p_value -) +SDL_NAME (XvGetPortAttribute) (Display * dpy, + XvPortID port, Atom attribute, int *p_value) { - XExtDisplayInfo *info = xv_find_display(dpy); - xvGetPortAttributeReq *req; - xvGetPortAttributeReply rep; + XExtDisplayInfo *info = xv_find_display (dpy); + xvGetPortAttributeReq *req; + xvGetPortAttributeReply rep; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(GetPortAttribute, req); - req->port = port; - req->attribute = attribute; + XvGetReq (GetPortAttribute, req); + req->port = port; + req->attribute = attribute; - /* READ THE REPLY */ + /* READ THE REPLY */ - if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadReply); - } + if (_XReply (dpy, (xReply *) & rep, 0, xFalse) == 0) { + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadReply); + } - *p_value = rep.value; - - UnlockDisplay(dpy); - SyncHandle(); + *p_value = rep.value; - return (Success); + UnlockDisplay (dpy); + SyncHandle (); + + return (Success); } int -SDL_NAME(XvQueryBestSize)( - Display *dpy, - XvPortID port, - Bool motion, - unsigned int vid_w, - unsigned int vid_h, - unsigned int drw_w, - unsigned int drw_h, - unsigned int *p_actual_width, - unsigned int *p_actual_height -) +SDL_NAME (XvQueryBestSize) (Display * dpy, + XvPortID port, + Bool motion, + unsigned int vid_w, + unsigned int vid_h, + unsigned int drw_w, + unsigned int drw_h, + unsigned int *p_actual_width, + unsigned int *p_actual_height) { - XExtDisplayInfo *info = xv_find_display(dpy); - xvQueryBestSizeReq *req; - xvQueryBestSizeReply rep; + XExtDisplayInfo *info = xv_find_display (dpy); + xvQueryBestSizeReq *req; + xvQueryBestSizeReply rep; - XvCheckExtension(dpy, info, XvBadExtension); + XvCheckExtension (dpy, info, XvBadExtension); - LockDisplay(dpy); + LockDisplay (dpy); - XvGetReq(QueryBestSize, req); - req->port = port; - req->motion = motion; - req->vid_w = vid_w; - req->vid_h = vid_h; - req->drw_w = drw_w; - req->drw_h = drw_h; + XvGetReq (QueryBestSize, req); + req->port = port; + req->motion = motion; + req->vid_w = vid_w; + req->vid_h = vid_h; + req->drw_w = drw_w; + req->drw_h = drw_h; - /* READ THE REPLY */ + /* READ THE REPLY */ - if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { - UnlockDisplay(dpy); - SyncHandle(); - return(XvBadReply); - } + if (_XReply (dpy, (xReply *) & rep, 0, xFalse) == 0) { + UnlockDisplay (dpy); + SyncHandle (); + return (XvBadReply); + } - *p_actual_width = rep.actual_width; - *p_actual_height = rep.actual_height; + *p_actual_width = rep.actual_width; + *p_actual_height = rep.actual_height; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); - return (Success); + return (Success); } -SDL_NAME(XvAttribute)* -SDL_NAME(XvQueryPortAttributes)(Display *dpy, XvPortID port, int *num) +SDL_NAME (XvAttribute) * +SDL_NAME (XvQueryPortAttributes) (Display * dpy, XvPortID port, int *num) { - XExtDisplayInfo *info = xv_find_display(dpy); - xvQueryPortAttributesReq *req; - xvQueryPortAttributesReply rep; - SDL_NAME(XvAttribute) *ret = NULL; - - *num = 0; - - XvCheckExtension(dpy, info, NULL); - - LockDisplay(dpy); - - XvGetReq(QueryPortAttributes, req); - req->port = port; - - /* READ THE REPLY */ - - if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { - UnlockDisplay(dpy); - SyncHandle(); - return ret; - } - - if(rep.num_attributes) { - int size = (rep.num_attributes * sizeof(SDL_NAME(XvAttribute))) + rep.text_size; - - if((ret = Xmalloc(size))) { - char* marker = (char*)(&ret[rep.num_attributes]); - xvAttributeInfo Info; - int i; - - for(i = 0; i < rep.num_attributes; i++) { - _XRead(dpy, (char*)(&Info), sz_xvAttributeInfo); - ret[i].flags = (int)Info.flags; - ret[i].min_value = Info.min; - ret[i].max_value = Info.max; - ret[i].name = marker; - _XRead(dpy, marker, Info.size); - marker += Info.size; - (*num)++; - } - } else - _XEatData(dpy, rep.length << 2); - } - - UnlockDisplay(dpy); - SyncHandle(); - - return ret; + XExtDisplayInfo *info = xv_find_display (dpy); + xvQueryPortAttributesReq *req; + xvQueryPortAttributesReply rep; + SDL_NAME (XvAttribute) * ret = NULL; + + *num = 0; + + XvCheckExtension (dpy, info, NULL); + + LockDisplay (dpy); + + XvGetReq (QueryPortAttributes, req); + req->port = port; + + /* READ THE REPLY */ + + if (_XReply (dpy, (xReply *) & rep, 0, xFalse) == 0) { + UnlockDisplay (dpy); + SyncHandle (); + return ret; + } + + if (rep.num_attributes) { + int size = + (rep.num_attributes * sizeof (SDL_NAME (XvAttribute))) + + rep.text_size; + + if ((ret = Xmalloc (size))) { + char *marker = (char *) (&ret[rep.num_attributes]); + xvAttributeInfo Info; + int i; + + for (i = 0; i < rep.num_attributes; i++) { + _XRead (dpy, (char *) (&Info), sz_xvAttributeInfo); + ret[i].flags = (int) Info.flags; + ret[i].min_value = Info.min; + ret[i].max_value = Info.max; + ret[i].name = marker; + _XRead (dpy, marker, Info.size); + marker += Info.size; + (*num)++; + } + } else + _XEatData (dpy, rep.length << 2); + } + + UnlockDisplay (dpy); + SyncHandle (); + + return ret; } -SDL_NAME(XvImageFormatValues) * SDL_NAME(XvListImageFormats) ( - Display *dpy, - XvPortID port, - int *num -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvListImageFormatsReq *req; - xvListImageFormatsReply rep; - SDL_NAME(XvImageFormatValues) *ret = NULL; - - *num = 0; - - XvCheckExtension(dpy, info, NULL); - - LockDisplay(dpy); - - XvGetReq(ListImageFormats, req); - req->port = port; - - /* READ THE REPLY */ - - if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { - UnlockDisplay(dpy); - SyncHandle(); - return NULL; - } - - if(rep.num_formats) { - int size = (rep.num_formats * sizeof(SDL_NAME(XvImageFormatValues))); - - if((ret = Xmalloc(size))) { - xvImageFormatInfo Info; - int i; - - for(i = 0; i < rep.num_formats; i++) { - _XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo); - ret[i].id = Info.id; - ret[i].type = Info.type; - ret[i].byte_order = Info.byte_order; - memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16); - ret[i].bits_per_pixel = Info.bpp; - ret[i].format = Info.format; - ret[i].num_planes = Info.num_planes; - ret[i].depth = Info.depth; - ret[i].red_mask = Info.red_mask; - ret[i].green_mask = Info.green_mask; - ret[i].blue_mask = Info.blue_mask; - ret[i].y_sample_bits = Info.y_sample_bits; - ret[i].u_sample_bits = Info.u_sample_bits; - ret[i].v_sample_bits = Info.v_sample_bits; - ret[i].horz_y_period = Info.horz_y_period; - ret[i].horz_u_period = Info.horz_u_period; - ret[i].horz_v_period = Info.horz_v_period; - ret[i].vert_y_period = Info.vert_y_period; - ret[i].vert_u_period = Info.vert_u_period; - ret[i].vert_v_period = Info.vert_v_period; - memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32); - ret[i].scanline_order = Info.scanline_order; - (*num)++; - } - } else - _XEatData(dpy, rep.length << 2); - } - - UnlockDisplay(dpy); - SyncHandle(); - - return ret; +SDL_NAME (XvImageFormatValues) * SDL_NAME (XvListImageFormats) (Display * dpy, + XvPortID port, + int *num) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvListImageFormatsReq *req; + xvListImageFormatsReply rep; + SDL_NAME (XvImageFormatValues) * ret = NULL; + + *num = 0; + + XvCheckExtension (dpy, info, NULL); + + LockDisplay (dpy); + + XvGetReq (ListImageFormats, req); + req->port = port; + + /* READ THE REPLY */ + + if (_XReply (dpy, (xReply *) & rep, 0, xFalse) == 0) { + UnlockDisplay (dpy); + SyncHandle (); + return NULL; + } + + if (rep.num_formats) { + int size = + (rep.num_formats * sizeof (SDL_NAME (XvImageFormatValues))); + + if ((ret = Xmalloc (size))) { + xvImageFormatInfo Info; + int i; + + for (i = 0; i < rep.num_formats; i++) { + _XRead (dpy, (char *) (&Info), sz_xvImageFormatInfo); + ret[i].id = Info.id; + ret[i].type = Info.type; + ret[i].byte_order = Info.byte_order; + memcpy (&(ret[i].guid[0]), &(Info.guid[0]), 16); + ret[i].bits_per_pixel = Info.bpp; + ret[i].format = Info.format; + ret[i].num_planes = Info.num_planes; + ret[i].depth = Info.depth; + ret[i].red_mask = Info.red_mask; + ret[i].green_mask = Info.green_mask; + ret[i].blue_mask = Info.blue_mask; + ret[i].y_sample_bits = Info.y_sample_bits; + ret[i].u_sample_bits = Info.u_sample_bits; + ret[i].v_sample_bits = Info.v_sample_bits; + ret[i].horz_y_period = Info.horz_y_period; + ret[i].horz_u_period = Info.horz_u_period; + ret[i].horz_v_period = Info.horz_v_period; + ret[i].vert_y_period = Info.vert_y_period; + ret[i].vert_u_period = Info.vert_u_period; + ret[i].vert_v_period = Info.vert_v_period; + memcpy (&(ret[i].component_order[0]), + &(Info.comp_order[0]), 32); + ret[i].scanline_order = Info.scanline_order; + (*num)++; + } + } else + _XEatData (dpy, rep.length << 2); + } + + UnlockDisplay (dpy); + SyncHandle (); + + return ret; } -SDL_NAME(XvImage) * SDL_NAME(XvCreateImage) ( - Display *dpy, - XvPortID port, - int id, - char *data, - int width, - int height -) { - XExtDisplayInfo *info = xv_find_display(dpy); - xvQueryImageAttributesReq *req; - xvQueryImageAttributesReply rep; - SDL_NAME(XvImage) *ret = NULL; - - XvCheckExtension(dpy, info, NULL); - - LockDisplay(dpy); - - XvGetReq(QueryImageAttributes, req); - req->id = id; - req->port = port; - req->width = width; - req->height = height; - - /* READ THE REPLY */ - - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return NULL; - } - - if((ret = (SDL_NAME(XvImage)*)Xmalloc(sizeof(SDL_NAME(XvImage)) + (rep.num_planes << 3)))) { - ret->id = id; - ret->width = rep.width; - ret->height = rep.height; - ret->data_size = rep.data_size; - ret->num_planes = rep.num_planes; - ret->pitches = (int*)(&ret[1]); - ret->offsets = ret->pitches + rep.num_planes; - ret->data = data; - ret->obdata = NULL; - _XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2); - _XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2); - } else - _XEatData(dpy, rep.length << 2); - - UnlockDisplay(dpy); - SyncHandle(); - return ret; +SDL_NAME (XvImage) * SDL_NAME (XvCreateImage) (Display * dpy, + XvPortID port, + int id, + char *data, + int width, int height) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvQueryImageAttributesReq *req; + xvQueryImageAttributesReply rep; + SDL_NAME (XvImage) * ret = NULL; + + XvCheckExtension (dpy, info, NULL); + + LockDisplay (dpy); + + XvGetReq (QueryImageAttributes, req); + req->id = id; + req->port = port; + req->width = width; + req->height = height; + + /* READ THE REPLY */ + + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return NULL; + } + + if ((ret = + (SDL_NAME (XvImage) *) Xmalloc (sizeof (SDL_NAME (XvImage)) + + (rep.num_planes << 3)))) { + ret->id = id; + ret->width = rep.width; + ret->height = rep.height; + ret->data_size = rep.data_size; + ret->num_planes = rep.num_planes; + ret->pitches = (int *) (&ret[1]); + ret->offsets = ret->pitches + rep.num_planes; + ret->data = data; + ret->obdata = NULL; + _XRead (dpy, (char *) (ret->pitches), rep.num_planes << 2); + _XRead (dpy, (char *) (ret->offsets), rep.num_planes << 2); + } else + _XEatData (dpy, rep.length << 2); + + UnlockDisplay (dpy); + SyncHandle (); + return ret; } -SDL_NAME(XvImage) * SDL_NAME(XvShmCreateImage) ( - Display *dpy, - XvPortID port, - int id, - char *data, - int width, - int height, - XShmSegmentInfo *shminfo -){ - SDL_NAME(XvImage) *ret; +SDL_NAME (XvImage) * SDL_NAME (XvShmCreateImage) (Display * dpy, + XvPortID port, + int id, + char *data, + int width, + int height, + XShmSegmentInfo * shminfo) +{ + SDL_NAME (XvImage) * ret; - ret = SDL_NAME(XvCreateImage)(dpy, port, id, data, width, height); + ret = SDL_NAME (XvCreateImage) (dpy, port, id, data, width, height); - if(ret) ret->obdata = (XPointer)shminfo; + if (ret) + ret->obdata = (XPointer) shminfo; - return ret; + return ret; } -int SDL_NAME(XvPutImage) ( - Display *dpy, - XvPortID port, - Drawable d, - GC gc, - SDL_NAME(XvImage) *image, - int src_x, - int src_y, - unsigned int src_w, - unsigned int src_h, - int dest_x, - int dest_y, - unsigned int dest_w, - unsigned int dest_h -){ - XExtDisplayInfo *info = xv_find_display(dpy); - xvPutImageReq *req; - int len; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - FlushGC(dpy, gc); - - XvGetReq(PutImage, req); - - req->port = port; - req->drawable = d; - req->gc = gc->gid; - req->id = image->id; - req->src_x = src_x; - req->src_y = src_y; - req->src_w = src_w; - req->src_h = src_h; - req->drw_x = dest_x; - req->drw_y = dest_y; - req->drw_w = dest_w; - req->drw_h = dest_h; - req->width = image->width; - req->height = image->height; - - len = (image->data_size + 3) >> 2; - SetReqLen(req, len, len); - - /* Yes it's kindof lame that we are sending the whole thing, - but for video all of it may be needed even if displaying - only a subsection, and I don't want to go through the - trouble of creating subregions to send */ - Data(dpy, (char *)image->data, image->data_size); - - UnlockDisplay(dpy); - SyncHandle(); - - return Success; +int SDL_NAME (XvPutImage) (Display * dpy, + XvPortID port, + Drawable d, + GC gc, + SDL_NAME (XvImage) * image, + int src_x, + int src_y, + unsigned int src_w, + unsigned int src_h, + int dest_x, + int dest_y, + unsigned int dest_w, unsigned int dest_h) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + xvPutImageReq *req; + int len; + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + FlushGC (dpy, gc); + + XvGetReq (PutImage, req); + + req->port = port; + req->drawable = d; + req->gc = gc->gid; + req->id = image->id; + req->src_x = src_x; + req->src_y = src_y; + req->src_w = src_w; + req->src_h = src_h; + req->drw_x = dest_x; + req->drw_y = dest_y; + req->drw_w = dest_w; + req->drw_h = dest_h; + req->width = image->width; + req->height = image->height; + + len = (image->data_size + 3) >> 2; + SetReqLen (req, len, len); + + /* Yes it's kindof lame that we are sending the whole thing, + but for video all of it may be needed even if displaying + only a subsection, and I don't want to go through the + trouble of creating subregions to send */ + Data (dpy, (char *) image->data, image->data_size); + + UnlockDisplay (dpy); + SyncHandle (); + + return Success; } -int SDL_NAME(XvShmPutImage) ( - Display *dpy, - XvPortID port, - Drawable d, - GC gc, - SDL_NAME(XvImage) *image, - int src_x, - int src_y, - unsigned int src_w, - unsigned int src_h, - int dest_x, - int dest_y, - unsigned int dest_w, - unsigned int dest_h, - Bool send_event -){ - XExtDisplayInfo *info = xv_find_display(dpy); - XShmSegmentInfo *shminfo = (XShmSegmentInfo *)image->obdata; - xvShmPutImageReq *req; - - XvCheckExtension(dpy, info, XvBadExtension); - - LockDisplay(dpy); - - FlushGC(dpy, gc); - - XvGetReq(ShmPutImage, req); - - req->port = port; - req->drawable = d; - req->gc = gc->gid; - req->shmseg = shminfo->shmseg; - req->id = image->id; - req->src_x = src_x; - req->src_y = src_y; - req->src_w = src_w; - req->src_h = src_h; - req->drw_x = dest_x; - req->drw_y = dest_y; - req->drw_w = dest_w; - req->drw_h = dest_h; - req->offset = image->data - shminfo->shmaddr; - req->width = image->width; - req->height = image->height; - req->send_event = send_event; - - UnlockDisplay(dpy); - SyncHandle(); - - return Success; +int SDL_NAME (XvShmPutImage) (Display * dpy, + XvPortID port, + Drawable d, + GC gc, + SDL_NAME (XvImage) * image, + int src_x, + int src_y, + unsigned int src_w, + unsigned int src_h, + int dest_x, + int dest_y, + unsigned int dest_w, + unsigned int dest_h, Bool send_event) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + XShmSegmentInfo *shminfo = (XShmSegmentInfo *) image->obdata; + xvShmPutImageReq *req; + + XvCheckExtension (dpy, info, XvBadExtension); + + LockDisplay (dpy); + + FlushGC (dpy, gc); + + XvGetReq (ShmPutImage, req); + + req->port = port; + req->drawable = d; + req->gc = gc->gid; + req->shmseg = shminfo->shmseg; + req->id = image->id; + req->src_x = src_x; + req->src_y = src_y; + req->src_w = src_w; + req->src_h = src_h; + req->drw_x = dest_x; + req->drw_y = dest_y; + req->drw_w = dest_w; + req->drw_h = dest_h; + req->offset = image->data - shminfo->shmaddr; + req->width = image->width; + req->height = image->height; + req->send_event = send_event; + + UnlockDisplay (dpy); + SyncHandle (); + + return Success; } static Bool -xv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire) +xv_wire_to_event (Display * dpy, XEvent * host, xEvent * wire) { - XExtDisplayInfo *info = xv_find_display(dpy); - SDL_NAME(XvEvent) *re = (SDL_NAME(XvEvent) *)host; - xvEvent *event = (xvEvent *)wire; + XExtDisplayInfo *info = xv_find_display (dpy); + SDL_NAME (XvEvent) * re = (SDL_NAME (XvEvent) *) host; + xvEvent *event = (xvEvent *) wire; - XvCheckExtension(dpy, info, False); + XvCheckExtension (dpy, info, False); - switch((event->u.u.type & 0x7F) - info->codes->first_event) - { + switch ((event->u.u.type & 0x7F) - info->codes->first_event) { case XvVideoNotify: - re->xvvideo.type = event->u.u.type & 0x7f; - re->xvvideo.serial = - _XSetLastRequestRead(dpy, (xGenericReply *)event); - re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0); - re->xvvideo.display = dpy; - re->xvvideo.time = event->u.videoNotify.time; - re->xvvideo.reason = event->u.videoNotify.reason; - re->xvvideo.drawable = event->u.videoNotify.drawable; - re->xvvideo.port_id = event->u.videoNotify.port; - break; + re->xvvideo.type = event->u.u.type & 0x7f; + re->xvvideo.serial = + _XSetLastRequestRead (dpy, (xGenericReply *) event); + re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0); + re->xvvideo.display = dpy; + re->xvvideo.time = event->u.videoNotify.time; + re->xvvideo.reason = event->u.videoNotify.reason; + re->xvvideo.drawable = event->u.videoNotify.drawable; + re->xvvideo.port_id = event->u.videoNotify.port; + break; case XvPortNotify: - re->xvport.type = event->u.u.type & 0x7f; - re->xvport.serial = - _XSetLastRequestRead(dpy, (xGenericReply *)event); - re->xvport.send_event = ((event->u.u.type & 0x80) != 0); - re->xvport.display = dpy; - re->xvport.time = event->u.portNotify.time; - re->xvport.port_id = event->u.portNotify.port; - re->xvport.attribute = event->u.portNotify.attribute; - re->xvport.value = event->u.portNotify.value; - break; + re->xvport.type = event->u.u.type & 0x7f; + re->xvport.serial = + _XSetLastRequestRead (dpy, (xGenericReply *) event); + re->xvport.send_event = ((event->u.u.type & 0x80) != 0); + re->xvport.display = dpy; + re->xvport.time = event->u.portNotify.time; + re->xvport.port_id = event->u.portNotify.port; + re->xvport.attribute = event->u.portNotify.attribute; + re->xvport.value = event->u.portNotify.value; + break; default: - return False; - } + return False; + } - return (True); + return (True); } - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/Xv/Xvlibint.h b/src/video/Xext/Xv/Xvlibint.h index d0bb70836..61bb66dba 100644 --- a/src/video/Xext/Xv/Xvlibint.h +++ b/src/video/Xext/Xv/Xvlibint.h @@ -59,7 +59,7 @@ SOFTWARE. dpy->bufptr += SIZEOF(xv##name##Req);\ dpy->request++ -#else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ +#else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ #define XvGetReq(name, req) \ WORD64ALIGN\ if ((dpy->bufptr + SIZEOF(xv/**/name/**/Req)) > dpy->bufmax)\ @@ -74,3 +74,4 @@ SOFTWARE. #endif /* XVLIBINT_H */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/Xxf86dga/XF86DGA.c b/src/video/Xext/Xxf86dga/XF86DGA.c index 4e3d662ff..fc9bb5f5d 100644 --- a/src/video/Xext/Xxf86dga/XF86DGA.c +++ b/src/video/Xext/Xxf86dga/XF86DGA.c @@ -8,7 +8,7 @@ Copyright (c) 1995,1996 The XFree86 Project, Inc /* THIS IS NOT AN X CONSORTIUM STANDARD */ -#ifdef __EMX__ /* needed here to override certain constants in X headers */ +#ifdef __EMX__ /* needed here to override certain constants in X headers */ #define INCL_DOS #define INCL_DOSIOCTL #include @@ -18,8 +18,8 @@ Copyright (c) 1995,1996 The XFree86 Project, Inc #define HAS_MMAP_ANON #include #include -#include /* PAGE_SIZE */ -#define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */ +#include /* PAGE_SIZE */ +#define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */ #define HAS_GETPAGESIZE #endif /* linux */ @@ -45,8 +45,8 @@ Copyright (c) 1995,1996 The XFree86 Project, Inc #include #endif /* SVR4 && !DGUX */ -#if defined(sun) && !defined(SVR4) /* SunOS */ -#define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */ +#if defined(sun) && !defined(SVR4) /* SunOS */ +#define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */ #define HAS_GETPAGESIZE #include #include @@ -65,8 +65,8 @@ Copyright (c) 1995,1996 The XFree86 Project, Inc #include "../extensions/Xext.h" #include "../extensions/extutil.h" -extern XExtDisplayInfo* SDL_NAME(xdga_find_display)(Display*); -extern char *SDL_NAME(xdga_extension_name); +extern XExtDisplayInfo *SDL_NAME (xdga_find_display) (Display *); +extern char *SDL_NAME (xdga_extension_name); #define XF86DGACheckExtension(dpy,i,val) \ XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val) @@ -77,261 +77,231 @@ extern char *SDL_NAME(xdga_extension_name); * * *****************************************************************************/ -Bool SDL_NAME(XF86DGAQueryExtension) ( - Display *dpy, - int *event_basep, - int *error_basep -){ - return SDL_NAME(XDGAQueryExtension)(dpy, event_basep, error_basep); +Bool SDL_NAME (XF86DGAQueryExtension) (Display * dpy, + int *event_basep, int *error_basep) +{ + return SDL_NAME (XDGAQueryExtension) (dpy, event_basep, error_basep); } -Bool SDL_NAME(XF86DGAQueryVersion)( - Display* dpy, - int* majorVersion, - int* minorVersion -){ - return SDL_NAME(XDGAQueryVersion)(dpy, majorVersion, minorVersion); +Bool SDL_NAME (XF86DGAQueryVersion) (Display * dpy, + int *majorVersion, int *minorVersion) +{ + return SDL_NAME (XDGAQueryVersion) (dpy, majorVersion, minorVersion); } -Bool SDL_NAME(XF86DGAGetVideoLL)( - Display* dpy, - int screen, - int *offset, - int *width, - int *bank_size, - int *ram_size -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XF86DGAGetVideoLL) (Display * dpy, + int screen, + int *offset, + int *width, int *bank_size, int *ram_size) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGAGetVideoLLReply rep; xXF86DGAGetVideoLLReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGAGetVideoLL, req); + LockDisplay (dpy); + GetReq (XF86DGAGetVideoLL, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAGetVideoLL; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } - *offset = /*(char *)*/rep.offset; + *offset = /*(char *) */ rep.offset; *width = rep.width; *bank_size = rep.bank_size; *ram_size = rep.ram_size; - - UnlockDisplay(dpy); - SyncHandle(); + + UnlockDisplay (dpy); + SyncHandle (); return True; } - -Bool SDL_NAME(XF86DGADirectVideoLL)( - Display* dpy, - int screen, - int enable -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); + +Bool SDL_NAME (XF86DGADirectVideoLL) (Display * dpy, int screen, int enable) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGADirectVideoReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGADirectVideo, req); + LockDisplay (dpy); + GetReq (XF86DGADirectVideo, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGADirectVideo; req->screen = screen; req->enable = enable; - UnlockDisplay(dpy); - SyncHandle(); - XSync(dpy,False); + UnlockDisplay (dpy); + SyncHandle (); + XSync (dpy, False); return True; } -Bool SDL_NAME(XF86DGAGetViewPortSize)( - Display* dpy, - int screen, - int *width, - int *height -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XF86DGAGetViewPortSize) (Display * dpy, + int screen, int *width, int *height) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGAGetViewPortSizeReply rep; xXF86DGAGetViewPortSizeReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGAGetViewPortSize, req); + LockDisplay (dpy); + GetReq (XF86DGAGetViewPortSize, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAGetViewPortSize; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } *width = rep.width; *height = rep.height; - - UnlockDisplay(dpy); - SyncHandle(); + + UnlockDisplay (dpy); + SyncHandle (); return True; } - - -Bool SDL_NAME(XF86DGASetViewPort)( - Display* dpy, - int screen, - int x, - int y -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); + + +Bool SDL_NAME (XF86DGASetViewPort) (Display * dpy, int screen, int x, int y) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGASetViewPortReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGASetViewPort, req); + LockDisplay (dpy); + GetReq (XF86DGASetViewPort, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGASetViewPort; req->screen = screen; req->x = x; req->y = y; - UnlockDisplay(dpy); - SyncHandle(); - XSync(dpy,False); + UnlockDisplay (dpy); + SyncHandle (); + XSync (dpy, False); return True; } - -Bool SDL_NAME(XF86DGAGetVidPage)( - Display* dpy, - int screen, - int *vpage -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); + +Bool SDL_NAME (XF86DGAGetVidPage) (Display * dpy, int screen, int *vpage) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGAGetVidPageReply rep; xXF86DGAGetVidPageReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGAGetVidPage, req); + LockDisplay (dpy); + GetReq (XF86DGAGetVidPage, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAGetVidPage; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } *vpage = rep.vpage; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } - -Bool SDL_NAME(XF86DGASetVidPage)( - Display* dpy, - int screen, - int vpage -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); + +Bool SDL_NAME (XF86DGASetVidPage) (Display * dpy, int screen, int vpage) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGASetVidPageReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGASetVidPage, req); + LockDisplay (dpy); + GetReq (XF86DGASetVidPage, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGASetVidPage; req->screen = screen; req->vpage = vpage; - UnlockDisplay(dpy); - SyncHandle(); - XSync(dpy,False); + UnlockDisplay (dpy); + SyncHandle (); + XSync (dpy, False); return True; } -Bool SDL_NAME(XF86DGAInstallColormap)( - Display* dpy, - int screen, - Colormap cmap -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XF86DGAInstallColormap) (Display * dpy, + int screen, Colormap cmap) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGAInstallColormapReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGAInstallColormap, req); + LockDisplay (dpy); + GetReq (XF86DGAInstallColormap, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAInstallColormap; req->screen = screen; req->id = cmap; - UnlockDisplay(dpy); - SyncHandle(); - XSync(dpy,False); + UnlockDisplay (dpy); + SyncHandle (); + XSync (dpy, False); return True; } -Bool SDL_NAME(XF86DGAQueryDirectVideo)( - Display *dpy, - int screen, - int *flags -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XF86DGAQueryDirectVideo) (Display * dpy, + int screen, int *flags) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGAQueryDirectVideoReply rep; xXF86DGAQueryDirectVideoReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGAQueryDirectVideo, req); + LockDisplay (dpy); + GetReq (XF86DGAQueryDirectVideo, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAQueryDirectVideo; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } *flags = rep.flags; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool SDL_NAME(XF86DGAViewPortChanged)( - Display *dpy, - int screen, - int n -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XF86DGAViewPortChanged) (Display * dpy, int screen, int n) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXF86DGAViewPortChangedReply rep; xXF86DGAViewPortChangedReq *req; XF86DGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86DGAViewPortChanged, req); + LockDisplay (dpy); + GetReq (XF86DGAViewPortChanged, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAViewPortChanged; req->screen = screen; req->n = n; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return rep.result; } @@ -344,7 +314,7 @@ Bool SDL_NAME(XF86DGAViewPortChanged)( #include #include #include -#if defined(ISC) +#if defined(ISC) # define HAS_SVR3_MMAP # include # include @@ -380,18 +350,20 @@ Bool SDL_NAME(XF86DGAViewPortChanged)( #define DEV_MEM "/dev/mem" #endif -typedef struct { - unsigned long physaddr; /* actual requested physical address */ - unsigned long size; /* actual requested map size */ - unsigned long delta; /* delta to account for page alignment */ - void * vaddr; /* mapped address, without the delta */ - int refcount; /* reference count */ +typedef struct +{ + unsigned long physaddr; /* actual requested physical address */ + unsigned long size; /* actual requested map size */ + unsigned long delta; /* delta to account for page alignment */ + void *vaddr; /* mapped address, without the delta */ + int refcount; /* reference count */ } MapRec, *MapPtr; -typedef struct { - Display * display; - int screen; - MapPtr map; +typedef struct +{ + Display *display; + int screen; + MapPtr map; } ScrRec, *ScrPtr; static int mapFd = -1; @@ -401,67 +373,65 @@ static MapPtr *mapList = NULL; static ScrPtr *scrList = NULL; static MapPtr -AddMap(void) +AddMap (void) { MapPtr *old; old = mapList; - mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1)); + mapList = realloc (mapList, sizeof (MapPtr) * (numMaps + 1)); if (!mapList) { - mapList = old; - return NULL; + mapList = old; + return NULL; } - mapList[numMaps] = malloc(sizeof(MapRec)); + mapList[numMaps] = malloc (sizeof (MapRec)); if (!mapList[numMaps]) - return NULL; + return NULL; return mapList[numMaps++]; } static ScrPtr -AddScr(void) +AddScr (void) { ScrPtr *old; old = scrList; - scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1)); + scrList = realloc (scrList, sizeof (ScrPtr) * (numScrs + 1)); if (!scrList) { - scrList = old; - return NULL; + scrList = old; + return NULL; } - scrList[numScrs] = malloc(sizeof(ScrRec)); + scrList[numScrs] = malloc (sizeof (ScrRec)); if (!scrList[numScrs]) - return NULL; + return NULL; return scrList[numScrs++]; } static MapPtr -FindMap(unsigned long address, unsigned long size) +FindMap (unsigned long address, unsigned long size) { int i; for (i = 0; i < numMaps; i++) { - if (mapList[i]->physaddr == address && - mapList[i]->size == size) - return mapList[i]; + if (mapList[i]->physaddr == address && mapList[i]->size == size) + return mapList[i]; } return NULL; } static ScrPtr -FindScr(Display *display, int screen) +FindScr (Display * display, int screen) { int i; for (i = 0; i < numScrs; i++) { - if (scrList[i]->display == display && - scrList[i]->screen == screen) - return scrList[i]; + if (scrList[i]->display == display && scrList[i]->screen == screen) + return scrList[i]; } return NULL; } static void * -MapPhysAddress(unsigned long address, unsigned long size) +MapPhysAddress (unsigned long address, unsigned long size) { unsigned long offset, delta; int pagesize = -1; @@ -475,44 +445,43 @@ MapPhysAddress(unsigned long address, unsigned long size) HFILE hfd; #endif - if ((mp = FindMap(address, size))) { - mp->refcount++; - return (void *)((unsigned long)mp->vaddr + mp->delta); + if ((mp = FindMap (address, size))) { + mp->refcount++; + return (void *) ((unsigned long) mp->vaddr + mp->delta); } - #if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE) - pagesize = sysconf(_SC_PAGESIZE); + pagesize = sysconf (_SC_PAGESIZE); #endif #ifdef _SC_PAGE_SIZE if (pagesize == -1) - pagesize = sysconf(_SC_PAGE_SIZE); + pagesize = sysconf (_SC_PAGE_SIZE); #endif #ifdef HAS_GETPAGESIZE if (pagesize == -1) - pagesize = getpagesize(); + pagesize = getpagesize (); #endif #ifdef PAGE_SIZE if (pagesize == -1) - pagesize = PAGE_SIZE; + pagesize = PAGE_SIZE; #endif if (pagesize == -1) - pagesize = 4096; + pagesize = 4096; - delta = address % pagesize; - offset = address - delta; + delta = address % pagesize; + offset = address - delta; #if defined(ISC) && defined(HAS_SVR3_MMAP) if (mapFd < 0) { - if ((mapFd = open("/dev/mmap", O_RDWR)) < 0) - return NULL; + if ((mapFd = open ("/dev/mmap", O_RDWR)) < 0) + return NULL; } - mloc.vaddr = (char *)0; - mloc.physaddr = (char *)offset; + mloc.vaddr = (char *) 0; + mloc.physaddr = (char *) offset; mloc.length = size + delta; - mloc.ioflg=1; + mloc.ioflg = 1; - if ((vaddr = (void *)ioctl(mapFd, MAP, &mloc)) == (void *)-1) - return NULL; + if ((vaddr = (void *) ioctl (mapFd, MAP, &mloc)) == (void *) -1) + return NULL; #elif defined (__EMX__) /* * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. @@ -520,60 +489,62 @@ MapPhysAddress(unsigned long address, unsigned long size) * of memory handles. Some umap/close mechanism should be provided */ - rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, - OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL); + rc = DosOpen ("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, + OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL); if (rc != 0) - return NULL; + return NULL; { - struct map_ioctl { - union { - ULONG phys; - void* user; - } a; - ULONG size; - } pmap,dmap; - ULONG plen,dlen; + struct map_ioctl + { + union + { + ULONG phys; + void *user; + } a; + ULONG size; + } pmap, dmap; + ULONG plen, dlen; #define XFREE86_PMAP 0x76 #define PMAP_MAP 0x44 - pmap.a.phys = offset; - pmap.size = size + delta; - rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP, - (PULONG)&pmap, sizeof(pmap), &plen, - (PULONG)&dmap, sizeof(dmap), &dlen); - if (rc == 0) { - vaddr = dmap.a.user; - } - } - if (rc != 0) - return NULL; + pmap.a.phys = offset; + pmap.size = size + delta; + rc = DosDevIOCtl (hfd, XFREE86_PMAP, PMAP_MAP, + (PULONG) & pmap, sizeof (pmap), &plen, + (PULONG) & dmap, sizeof (dmap), &dlen); + if (rc == 0) { + vaddr = dmap.a.user; + } + } + if (rc != 0) + return NULL; #elif defined (Lynx) - vaddr = (void *)smem_create("XF86DGA", (char *)offset, - size + delta, SM_READ|SM_WRITE); + vaddr = (void *) smem_create ("XF86DGA", (char *) offset, + size + delta, SM_READ | SM_WRITE); #else #ifndef MAP_FILE #define MAP_FILE 0 #endif if (mapFd < 0) { - if ((mapFd = open(DEV_MEM, O_RDWR)) < 0) - return NULL; + if ((mapFd = open (DEV_MEM, O_RDWR)) < 0) + return NULL; } - vaddr = (void *)mmap(NULL, size + delta, PROT_READ | PROT_WRITE, - MAP_FILE | MAP_SHARED, mapFd, (off_t)offset); - if (vaddr == (void *)-1) - return NULL; + vaddr = (void *) mmap (NULL, size + delta, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, mapFd, (off_t) offset); + if (vaddr == (void *) -1) + return NULL; #endif if (!vaddr) { - if (!(mp = AddMap())) - return NULL; - mp->physaddr = address; - mp->size = size; - mp->delta = delta; - mp->vaddr = vaddr; - mp->refcount = 1; + if (!(mp = AddMap ())) + return NULL; + mp->physaddr = address; + mp->size = size; + mp->delta = delta; + mp->vaddr = vaddr; + mp->refcount = 1; } - return (void *)((unsigned long)vaddr + delta); + return (void *) ((unsigned long) vaddr + delta); } /* @@ -583,134 +554,128 @@ MapPhysAddress(unsigned long address, unsigned long size) * should restore text mode. */ -int -SDL_NAME(XF86DGAForkApp)(int screen) +int SDL_NAME (XF86DGAForkApp) (int screen) { pid_t pid; int status; int i; - /* fork the app, parent hangs around to clean up */ - if ((pid = fork()) > 0) { - ScrPtr sp; - - waitpid(pid, &status, 0); - for (i = 0; i < numScrs; i++) { - sp = scrList[i]; - SDL_NAME(XF86DGADirectVideoLL)(sp->display, sp->screen, 0); - XSync(sp->display, False); - } - if (WIFEXITED(status)) - _exit(0); - else - _exit(-1); + /* fork the app, parent hangs around to clean up */ + if ((pid = fork ()) > 0) { + ScrPtr sp; + + waitpid (pid, &status, 0); + for (i = 0; i < numScrs; i++) { + sp = scrList[i]; + SDL_NAME (XF86DGADirectVideoLL) (sp->display, sp->screen, 0); + XSync (sp->display, False); + } + if (WIFEXITED (status)) + _exit (0); + else + _exit (-1); } return pid; } -Bool -SDL_NAME(XF86DGADirectVideo)( - Display *dis, - int screen, - int enable -){ +Bool SDL_NAME (XF86DGADirectVideo) (Display * dis, int screen, int enable) +{ ScrPtr sp; MapPtr mp = NULL; - if ((sp = FindScr(dis, screen))) - mp = sp->map; + if ((sp = FindScr (dis, screen))) + mp = sp->map; if (enable & XF86DGADirectGraphics) { #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ && !defined(__EMX__) - if (mp && mp->vaddr) - mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ | PROT_WRITE); + if (mp && mp->vaddr) + mprotect (mp->vaddr, mp->size + mp->delta, + PROT_READ | PROT_WRITE); #endif } else { #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ && !defined(__EMX__) - if (mp && mp->vaddr) - mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ); + if (mp && mp->vaddr) + mprotect (mp->vaddr, mp->size + mp->delta, PROT_READ); #elif defined(Lynx) - /* XXX this doesn't allow enable after disable */ - smem_create(NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH); - smem_remove("XF86DGA"); + /* XXX this doesn't allow enable after disable */ + smem_create (NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH); + smem_remove ("XF86DGA"); #endif } - SDL_NAME(XF86DGADirectVideoLL)(dis, screen, enable); + SDL_NAME (XF86DGADirectVideoLL) (dis, screen, enable); return 1; } static void -XF86cleanup(int sig) +XF86cleanup (int sig) { ScrPtr sp; int i; static char beenhere = 0; if (beenhere) - _exit(3); + _exit (3); beenhere = 1; for (i = 0; i < numScrs; i++) { - sp = scrList[i]; - SDL_NAME(XF86DGADirectVideo)(sp->display, sp->screen, 0); - XSync(sp->display, False); + sp = scrList[i]; + SDL_NAME (XF86DGADirectVideo) (sp->display, sp->screen, 0); + XSync (sp->display, False); } - _exit(3); + _exit (3); } Bool -SDL_NAME(XF86DGAGetVideo)( - Display *dis, - int screen, - char **addr, - int *width, - int *bank, - int *ram -){ - /*unsigned long*/ int offset; +SDL_NAME (XF86DGAGetVideo) (Display * dis, + int screen, + char **addr, int *width, int *bank, int *ram) +{ + /*unsigned long */ int offset; static int beenHere = 0; ScrPtr sp; MapPtr mp; - if (!(sp = FindScr(dis, screen))) { - if (!(sp = AddScr())) { - fprintf(stderr, "XF86DGAGetVideo: malloc failure\n"); - exit(-2); - } - sp->display = dis; - sp->screen = screen; - sp->map = NULL; + if (!(sp = FindScr (dis, screen))) { + if (!(sp = AddScr ())) { + fprintf (stderr, "XF86DGAGetVideo: malloc failure\n"); + exit (-2); + } + sp->display = dis; + sp->screen = screen; + sp->map = NULL; } - SDL_NAME(XF86DGAGetVideoLL)(dis, screen , &offset, width, bank, ram); + SDL_NAME (XF86DGAGetVideoLL) (dis, screen, &offset, width, bank, ram); - *addr = MapPhysAddress(offset, *bank); + *addr = MapPhysAddress (offset, *bank); if (*addr == NULL) { - fprintf(stderr, "XF86DGAGetVideo: failed to map video memory (%s)\n", - strerror(errno)); - exit(-2); + fprintf (stderr, + "XF86DGAGetVideo: failed to map video memory (%s)\n", + strerror (errno)); + exit (-2); } - if ((mp = FindMap(offset, *bank))) - sp->map = mp; + if ((mp = FindMap (offset, *bank))) + sp->map = mp; if (!beenHere) { - beenHere = 1; - atexit((void(*)(void))XF86cleanup); - /* one shot XF86cleanup attempts */ - signal(SIGSEGV, XF86cleanup); + beenHere = 1; + atexit ((void (*)(void)) XF86cleanup); + /* one shot XF86cleanup attempts */ + signal (SIGSEGV, XF86cleanup); #ifdef SIGBUS - signal(SIGBUS, XF86cleanup); + signal (SIGBUS, XF86cleanup); #endif - signal(SIGHUP, XF86cleanup); - signal(SIGFPE, XF86cleanup); + signal (SIGHUP, XF86cleanup); + signal (SIGFPE, XF86cleanup); } return 1; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/Xxf86dga/XF86DGA2.c b/src/video/Xext/Xxf86dga/XF86DGA2.c index 3acf9f8e7..387744778 100644 --- a/src/video/Xext/Xxf86dga/XF86DGA2.c +++ b/src/video/Xext/Xxf86dga/XF86DGA2.c @@ -8,7 +8,7 @@ Copyright (c) 1995,1996 The XFree86 Project, Inc /* THIS IS NOT AN X CONSORTIUM STANDARD */ -#ifdef __EMX__ /* needed here to override certain constants in X headers */ +#ifdef __EMX__ /* needed here to override certain constants in X headers */ #define INCL_DOS #define INCL_DOSIOCTL #include @@ -24,7 +24,7 @@ Copyright (c) 1995,1996 The XFree86 Project, Inc #include "../extensions/extutil.h" #include -#if defined(ENABLE_FBCON) /* Needed for framebuffer console support */ +#if defined(ENABLE_FBCON) /* Needed for framebuffer console support */ #include #include #endif @@ -32,15 +32,16 @@ Copyright (c) 1995,1996 The XFree86 Project, Inc /* If you change this, change the Bases[] array below as well */ #define MAX_HEADS 16 -char *SDL_NAME(xdga_extension_name) = XF86DGANAME; +char *SDL_NAME (xdga_extension_name) = XF86DGANAME; static XExtensionInfo _xdga_info_data; static XExtensionInfo *xdga_info = &_xdga_info_data; - -Bool SDL_NAME(XDGAMapFramebuffer)(int, char *, unsigned char*, CARD32, CARD32, CARD32); -void SDL_NAME(XDGAUnmapFramebuffer)(int); -unsigned char* SDL_NAME(XDGAGetMappedMemory)(int); + +Bool SDL_NAME (XDGAMapFramebuffer) (int, char *, unsigned char *, CARD32, + CARD32, CARD32); +void SDL_NAME (XDGAUnmapFramebuffer) (int); +unsigned char *SDL_NAME (XDGAGetMappedMemory) (int); #define XDGACheckExtension(dpy,i,val) \ XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val) @@ -51,177 +52,158 @@ unsigned char* SDL_NAME(XDGAGetMappedMemory)(int); * * *****************************************************************************/ -static int xdga_close_display(Display *dpy, XExtCodes *codes); -static Bool xdga_wire_to_event(Display *dpy, XEvent *event, xEvent *wire_ev); -static Status xdga_event_to_wire(Display *dpy, XEvent *event, xEvent *wire_ev); +static int xdga_close_display (Display * dpy, XExtCodes * codes); +static Bool xdga_wire_to_event (Display * dpy, XEvent * event, + xEvent * wire_ev); +static Status xdga_event_to_wire (Display * dpy, XEvent * event, + xEvent * wire_ev); static XExtensionHooks xdga_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - xdga_close_display, /* close_display */ - xdga_wire_to_event, /* wire_to_event */ - xdga_event_to_wire, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + xdga_close_display, /* close_display */ + xdga_wire_to_event, /* wire_to_event */ + xdga_event_to_wire, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ }; -static XEXT_GENERATE_CLOSE_DISPLAY (xdga_close_display, xdga_info) - - -XEXT_GENERATE_FIND_DISPLAY (SDL_NAME(xdga_find_display), xdga_info, - "XFree86-DGA", - &xdga_extension_hooks, - 0, NULL) - - -static Status -xdga_event_to_wire( - Display *dpy, - XEvent *event, - xEvent *wire_ev -){ +static +XEXT_GENERATE_CLOSE_DISPLAY (xdga_close_display, xdga_info) +XEXT_GENERATE_FIND_DISPLAY (SDL_NAME (xdga_find_display), xdga_info, + "XFree86-DGA", &xdga_extension_hooks, 0, NULL) + static Status + xdga_event_to_wire (Display * dpy, XEvent * event, xEvent * wire_ev) +{ return True; } static Bool -xdga_wire_to_event( - Display *dpy, - XEvent *event, - xEvent *wire_ev -){ - dgaEvent *wire = (dgaEvent *) wire_ev; - SDL_NAME(XDGAButtonEvent) *bevent; - SDL_NAME(XDGAKeyEvent) *kevent; - SDL_NAME(XDGAMotionEvent) *mevent; - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); - - XDGACheckExtension (dpy, info, False); - - switch((wire->u.u.type & 0x7f) - info->codes->first_event) { - case MotionNotify: - mevent = (SDL_NAME(XDGAMotionEvent)*)event; - mevent->type = wire->u.u.type & 0x7F; - mevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); - mevent->display = dpy; - mevent->screen = wire->u.event.screen; - mevent->time = wire->u.event.time; - mevent->state = wire->u.event.state; - mevent->dx = wire->u.event.dx; - mevent->dy = wire->u.event.dy; - return True; - case ButtonPress: - case ButtonRelease: - bevent = (SDL_NAME(XDGAButtonEvent)*)event; - bevent->type = wire->u.u.type & 0x7F; - bevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); - bevent->display = dpy; - bevent->screen = wire->u.event.screen; - bevent->time = wire->u.event.time; - bevent->state = wire->u.event.state; - bevent->button = wire->u.u.detail; - return True; - case KeyPress: - case KeyRelease: - kevent = (SDL_NAME(XDGAKeyEvent)*)event; - kevent->type = wire->u.u.type & 0x7F; - kevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); - kevent->display = dpy; - kevent->screen = wire->u.event.screen; - kevent->time = wire->u.event.time; - kevent->state = wire->u.event.state; - kevent->keycode = wire->u.u.detail; - return True; - } - - return False; +xdga_wire_to_event (Display * dpy, XEvent * event, xEvent * wire_ev) +{ + dgaEvent *wire = (dgaEvent *) wire_ev; + SDL_NAME (XDGAButtonEvent) * bevent; + SDL_NAME (XDGAKeyEvent) * kevent; + SDL_NAME (XDGAMotionEvent) * mevent; + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); + + XDGACheckExtension (dpy, info, False); + + switch ((wire->u.u.type & 0x7f) - info->codes->first_event) { + case MotionNotify: + mevent = (SDL_NAME (XDGAMotionEvent) *) event; + mevent->type = wire->u.u.type & 0x7F; + mevent->serial = _XSetLastRequestRead (dpy, (xGenericReply *) wire); + mevent->display = dpy; + mevent->screen = wire->u.event.screen; + mevent->time = wire->u.event.time; + mevent->state = wire->u.event.state; + mevent->dx = wire->u.event.dx; + mevent->dy = wire->u.event.dy; + return True; + case ButtonPress: + case ButtonRelease: + bevent = (SDL_NAME (XDGAButtonEvent) *) event; + bevent->type = wire->u.u.type & 0x7F; + bevent->serial = _XSetLastRequestRead (dpy, (xGenericReply *) wire); + bevent->display = dpy; + bevent->screen = wire->u.event.screen; + bevent->time = wire->u.event.time; + bevent->state = wire->u.event.state; + bevent->button = wire->u.u.detail; + return True; + case KeyPress: + case KeyRelease: + kevent = (SDL_NAME (XDGAKeyEvent) *) event; + kevent->type = wire->u.u.type & 0x7F; + kevent->serial = _XSetLastRequestRead (dpy, (xGenericReply *) wire); + kevent->display = dpy; + kevent->screen = wire->u.event.screen; + kevent->time = wire->u.event.time; + kevent->state = wire->u.event.state; + kevent->keycode = wire->u.u.detail; + return True; + } + + return False; } -Bool SDL_NAME(XDGAQueryExtension) ( - Display *dpy, - int *event_basep, - int *error_basep -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XDGAQueryExtension) (Display * dpy, + int *event_basep, int *error_basep) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); - if (XextHasExtension(info)) { - *event_basep = info->codes->first_event; - *error_basep = info->codes->first_error; - return True; + if (XextHasExtension (info)) { + *event_basep = info->codes->first_event; + *error_basep = info->codes->first_error; + return True; } else { - return False; + return False; } } -Bool SDL_NAME(XDGAQueryVersion)( - Display *dpy, - int *majorVersion, - int *minorVersion -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XDGAQueryVersion) (Display * dpy, + int *majorVersion, int *minorVersion) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGAQueryVersionReply rep; xXDGAQueryVersionReq *req; XDGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XDGAQueryVersion, req); + LockDisplay (dpy); + GetReq (XDGAQueryVersion, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGAQueryVersion; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } *majorVersion = rep.majorVersion; *minorVersion = rep.minorVersion; - UnlockDisplay(dpy); - SyncHandle(); - if (*majorVersion >= 2) - { - int i, j; - - for (i = 0, j = info->codes->first_event; - i < XF86DGANumberEvents; - i++, j++) - { - XESetWireToEvent(dpy, j, xdga_wire_to_event); - XESetEventToWire(dpy, j, xdga_event_to_wire); - } - SDL_NAME(XDGASetClientVersion)(dpy); + UnlockDisplay (dpy); + SyncHandle (); + if (*majorVersion >= 2) { + int i, j; + + for (i = 0, j = info->codes->first_event; + i < XF86DGANumberEvents; i++, j++) { + XESetWireToEvent (dpy, j, xdga_wire_to_event); + XESetEventToWire (dpy, j, xdga_event_to_wire); + } + SDL_NAME (XDGASetClientVersion) (dpy); } return True; } -Bool SDL_NAME(XDGASetClientVersion)( - Display *dpy -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XDGASetClientVersion) (Display * dpy) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGASetClientVersionReq *req; XDGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XDGASetClientVersion, req); + LockDisplay (dpy); + GetReq (XDGASetClientVersion, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGASetClientVersion; req->major = XDGA_MAJOR_VERSION; req->minor = XDGA_MINOR_VERSION; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool SDL_NAME(XDGAOpenFramebuffer)( - Display *dpy, - int screen -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Bool SDL_NAME (XDGAOpenFramebuffer) (Display * dpy, int screen) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGAOpenFramebufferReply rep; xXDGAOpenFramebufferReq *req; char *deviceName = NULL; @@ -229,297 +211,280 @@ Bool SDL_NAME(XDGAOpenFramebuffer)( XDGACheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XDGAOpenFramebuffer, req); + LockDisplay (dpy); + GetReq (XDGAOpenFramebuffer, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGAOpenFramebuffer; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } - if(rep.length) { - deviceName = Xmalloc(rep.length << 2); - _XRead(dpy, deviceName, rep.length << 2); + if (rep.length) { + deviceName = Xmalloc (rep.length << 2); + _XRead (dpy, deviceName, rep.length << 2); } - ret = SDL_NAME(XDGAMapFramebuffer)(screen, deviceName, - (unsigned char*)(long)rep.mem1, - rep.size, rep.offset, rep.extra); + ret = SDL_NAME (XDGAMapFramebuffer) (screen, deviceName, + (unsigned char *) (long) rep.mem1, + rep.size, rep.offset, rep.extra); - if(deviceName) - Xfree(deviceName); + if (deviceName) + Xfree (deviceName); - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return ret; } -void SDL_NAME(XDGACloseFramebuffer)( - Display *dpy, - int screen -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGACloseFramebuffer) (Display * dpy, int screen) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGACloseFramebufferReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - SDL_NAME(XDGAUnmapFramebuffer)(screen); + SDL_NAME (XDGAUnmapFramebuffer) (screen); - LockDisplay(dpy); - GetReq(XDGACloseFramebuffer, req); + LockDisplay (dpy); + GetReq (XDGACloseFramebuffer, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGACloseFramebuffer; req->screen = screen; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -SDL_NAME(XDGAMode)* SDL_NAME(XDGAQueryModes)( - Display *dpy, - int screen, - int *num -){ - XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy); +SDL_NAME (XDGAMode) * SDL_NAME (XDGAQueryModes) (Display * dpy, + int screen, int *num) +{ + XExtDisplayInfo *dinfo = SDL_NAME (xdga_find_display) (dpy); xXDGAQueryModesReply rep; xXDGAQueryModesReq *req; - SDL_NAME(XDGAMode) *modes = NULL; + SDL_NAME (XDGAMode) * modes = NULL; *num = 0; XDGACheckExtension (dpy, dinfo, NULL); - LockDisplay(dpy); - GetReq(XDGAQueryModes, req); + LockDisplay (dpy); + GetReq (XDGAQueryModes, req); req->reqType = dinfo->codes->major_opcode; req->dgaReqType = X_XDGAQueryModes; req->screen = screen; - if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - if(rep.length) { - xXDGAModeInfo info; - int i, size; - char *offset; - - size = rep.length << 2; - size -= rep.number * sz_xXDGAModeInfo; /* find text size */ - modes = (SDL_NAME(XDGAMode)*)Xmalloc((rep.number * sizeof(SDL_NAME(XDGAMode))) + size); - offset = (char*)(&modes[rep.number]); /* start of text */ - - - if(modes) { - for(i = 0; i < rep.number; i++) { - _XRead(dpy, (char*)(&info), sz_xXDGAModeInfo); - - modes[i].num = info.num; - modes[i].verticalRefresh = - (float)info.vsync_num / (float)info.vsync_den; - modes[i].flags = info.flags; - modes[i].imageWidth = info.image_width; - modes[i].imageHeight = info.image_height; - modes[i].pixmapWidth = info.pixmap_width; - modes[i].pixmapHeight = info.pixmap_height; - modes[i].bytesPerScanline = info.bytes_per_scanline; - modes[i].byteOrder = info.byte_order; - modes[i].depth = info.depth; - modes[i].bitsPerPixel = info.bpp; - modes[i].redMask = info.red_mask; - modes[i].greenMask = info.green_mask; - modes[i].blueMask = info.blue_mask; - modes[i].visualClass = info.visual_class; - modes[i].viewportWidth = info.viewport_width; - modes[i].viewportHeight = info.viewport_height; - modes[i].xViewportStep = info.viewport_xstep; - modes[i].yViewportStep = info.viewport_ystep; - modes[i].maxViewportX = info.viewport_xmax; - modes[i].maxViewportY = info.viewport_ymax; - modes[i].viewportFlags = info.viewport_flags; - modes[i].reserved1 = info.reserved1; - modes[i].reserved2 = info.reserved2; - - _XRead(dpy, offset, info.name_size); - modes[i].name = offset; - offset += info.name_size; - } - *num = rep.number; - } else - _XEatData(dpy, rep.length << 2); - } + if (_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + if (rep.length) { + xXDGAModeInfo info; + int i, size; + char *offset; + + size = rep.length << 2; + size -= rep.number * sz_xXDGAModeInfo; /* find text size */ + modes = (SDL_NAME (XDGAMode) *) + Xmalloc ((rep.number * sizeof (SDL_NAME (XDGAMode))) + size); + offset = (char *) (&modes[rep.number]); /* start of text */ + + + if (modes) { + for (i = 0; i < rep.number; i++) { + _XRead (dpy, (char *) (&info), sz_xXDGAModeInfo); + + modes[i].num = info.num; + modes[i].verticalRefresh = + (float) info.vsync_num / (float) info.vsync_den; + modes[i].flags = info.flags; + modes[i].imageWidth = info.image_width; + modes[i].imageHeight = info.image_height; + modes[i].pixmapWidth = info.pixmap_width; + modes[i].pixmapHeight = info.pixmap_height; + modes[i].bytesPerScanline = info.bytes_per_scanline; + modes[i].byteOrder = info.byte_order; + modes[i].depth = info.depth; + modes[i].bitsPerPixel = info.bpp; + modes[i].redMask = info.red_mask; + modes[i].greenMask = info.green_mask; + modes[i].blueMask = info.blue_mask; + modes[i].visualClass = info.visual_class; + modes[i].viewportWidth = info.viewport_width; + modes[i].viewportHeight = info.viewport_height; + modes[i].xViewportStep = info.viewport_xstep; + modes[i].yViewportStep = info.viewport_ystep; + modes[i].maxViewportX = info.viewport_xmax; + modes[i].maxViewportY = info.viewport_ymax; + modes[i].viewportFlags = info.viewport_flags; + modes[i].reserved1 = info.reserved1; + modes[i].reserved2 = info.reserved2; + + _XRead (dpy, offset, info.name_size); + modes[i].name = offset; + offset += info.name_size; + } + *num = rep.number; + } else + _XEatData (dpy, rep.length << 2); + } } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return modes; } -SDL_NAME(XDGADevice) * -SDL_NAME(XDGASetMode)( - Display *dpy, - int screen, - int mode -){ - XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy); +SDL_NAME (XDGADevice) * +SDL_NAME (XDGASetMode) (Display * dpy, int screen, int mode) +{ + XExtDisplayInfo *dinfo = SDL_NAME (xdga_find_display) (dpy); xXDGASetModeReply rep; xXDGASetModeReq *req; - SDL_NAME(XDGADevice) *dev = NULL; + SDL_NAME (XDGADevice) * dev = NULL; Pixmap pid; XDGACheckExtension (dpy, dinfo, NULL); - LockDisplay(dpy); - GetReq(XDGASetMode, req); + LockDisplay (dpy); + GetReq (XDGASetMode, req); req->reqType = dinfo->codes->major_opcode; req->dgaReqType = X_XDGASetMode; req->screen = screen; req->mode = mode; - req->pid = pid = XAllocID(dpy); - - if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - if(rep.length) { - xXDGAModeInfo info; - int size; - - size = rep.length << 2; - size -= sz_xXDGAModeInfo; /* get text size */ - - dev = (SDL_NAME(XDGADevice)*)Xmalloc(sizeof(SDL_NAME(XDGADevice)) + size); - - if(dev) { - _XRead(dpy, (char*)(&info), sz_xXDGAModeInfo); - - dev->mode.num = info.num; - dev->mode.verticalRefresh = - (float)info.vsync_num / (float)info.vsync_den; - dev->mode.flags = info.flags; - dev->mode.imageWidth = info.image_width; - dev->mode.imageHeight = info.image_height; - dev->mode.pixmapWidth = info.pixmap_width; - dev->mode.pixmapHeight = info.pixmap_height; - dev->mode.bytesPerScanline = info.bytes_per_scanline; - dev->mode.byteOrder = info.byte_order; - dev->mode.depth = info.depth; - dev->mode.bitsPerPixel = info.bpp; - dev->mode.redMask = info.red_mask; - dev->mode.greenMask = info.green_mask; - dev->mode.blueMask = info.blue_mask; - dev->mode.visualClass = info.visual_class; - dev->mode.viewportWidth = info.viewport_width; - dev->mode.viewportHeight = info.viewport_height; - dev->mode.xViewportStep = info.viewport_xstep; - dev->mode.yViewportStep = info.viewport_ystep; - dev->mode.maxViewportX = info.viewport_xmax; - dev->mode.maxViewportY = info.viewport_ymax; - dev->mode.viewportFlags = info.viewport_flags; - dev->mode.reserved1 = info.reserved1; - dev->mode.reserved2 = info.reserved2; - - dev->mode.name = (char*)(&dev[1]); - _XRead(dpy, dev->mode.name, info.name_size); - - dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0; - dev->data = SDL_NAME(XDGAGetMappedMemory)(screen); - - if(dev->data) - dev->data += rep.offset; - } - /* not sure what to do if the allocation fails */ - } + req->pid = pid = XAllocID (dpy); + + if (_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + if (rep.length) { + xXDGAModeInfo info; + int size; + + size = rep.length << 2; + size -= sz_xXDGAModeInfo; /* get text size */ + + dev = (SDL_NAME (XDGADevice) *) + Xmalloc (sizeof (SDL_NAME (XDGADevice)) + size); + + if (dev) { + _XRead (dpy, (char *) (&info), sz_xXDGAModeInfo); + + dev->mode.num = info.num; + dev->mode.verticalRefresh = + (float) info.vsync_num / (float) info.vsync_den; + dev->mode.flags = info.flags; + dev->mode.imageWidth = info.image_width; + dev->mode.imageHeight = info.image_height; + dev->mode.pixmapWidth = info.pixmap_width; + dev->mode.pixmapHeight = info.pixmap_height; + dev->mode.bytesPerScanline = info.bytes_per_scanline; + dev->mode.byteOrder = info.byte_order; + dev->mode.depth = info.depth; + dev->mode.bitsPerPixel = info.bpp; + dev->mode.redMask = info.red_mask; + dev->mode.greenMask = info.green_mask; + dev->mode.blueMask = info.blue_mask; + dev->mode.visualClass = info.visual_class; + dev->mode.viewportWidth = info.viewport_width; + dev->mode.viewportHeight = info.viewport_height; + dev->mode.xViewportStep = info.viewport_xstep; + dev->mode.yViewportStep = info.viewport_ystep; + dev->mode.maxViewportX = info.viewport_xmax; + dev->mode.maxViewportY = info.viewport_ymax; + dev->mode.viewportFlags = info.viewport_flags; + dev->mode.reserved1 = info.reserved1; + dev->mode.reserved2 = info.reserved2; + + dev->mode.name = (char *) (&dev[1]); + _XRead (dpy, dev->mode.name, info.name_size); + + dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0; + dev->data = SDL_NAME (XDGAGetMappedMemory) (screen); + + if (dev->data) + dev->data += rep.offset; + } + /* not sure what to do if the allocation fails */ + } } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return dev; } -void SDL_NAME(XDGASetViewport)( - Display *dpy, - int screen, - int x, - int y, - int flags -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGASetViewport) (Display * dpy, + int screen, int x, int y, int flags) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGASetViewportReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGASetViewport, req); + LockDisplay (dpy); + GetReq (XDGASetViewport, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGASetViewport; req->screen = screen; req->x = x; req->y = y; req->flags = flags; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -void SDL_NAME(XDGAInstallColormap)( - Display *dpy, - int screen, - Colormap cmap -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGAInstallColormap) (Display * dpy, int screen, Colormap cmap) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGAInstallColormapReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGAInstallColormap, req); + LockDisplay (dpy); + GetReq (XDGAInstallColormap, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGAInstallColormap; req->screen = screen; req->cmap = cmap; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -void SDL_NAME(XDGASelectInput)( - Display *dpy, - int screen, - long mask -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGASelectInput) (Display * dpy, int screen, long mask) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGASelectInputReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGASelectInput, req); + LockDisplay (dpy); + GetReq (XDGASelectInput, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGASelectInput; req->screen = screen; req->mask = mask; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -void SDL_NAME(XDGAFillRectangle)( - Display *dpy, - int screen, - int x, - int y, - unsigned int width, - unsigned int height, - unsigned long color -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGAFillRectangle) (Display * dpy, + int screen, + int x, + int y, + unsigned int width, + unsigned int height, unsigned long color) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGAFillRectangleReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGAFillRectangle, req); + LockDisplay (dpy); + GetReq (XDGAFillRectangle, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGAFillRectangle; req->screen = screen; @@ -528,27 +493,24 @@ void SDL_NAME(XDGAFillRectangle)( req->width = width; req->height = height; req->color = color; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -void SDL_NAME(XDGACopyArea)( - Display *dpy, - int screen, - int srcx, - int srcy, - unsigned int width, - unsigned int height, - int dstx, - int dsty -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGACopyArea) (Display * dpy, + int screen, + int srcx, + int srcy, + unsigned int width, + unsigned int height, int dstx, int dsty) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGACopyAreaReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGACopyArea, req); + LockDisplay (dpy); + GetReq (XDGACopyArea, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGACopyArea; req->screen = screen; @@ -558,28 +520,26 @@ void SDL_NAME(XDGACopyArea)( req->height = height; req->dstx = dstx; req->dsty = dsty; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -void SDL_NAME(XDGACopyTransparentArea)( - Display *dpy, - int screen, - int srcx, - int srcy, - unsigned int width, - unsigned int height, - int dstx, - int dsty, - unsigned long key -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGACopyTransparentArea) (Display * dpy, + int screen, + int srcx, + int srcy, + unsigned int width, + unsigned int height, + int dstx, + int dsty, unsigned long key) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGACopyTransparentAreaReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGACopyTransparentArea, req); + LockDisplay (dpy); + GetReq (XDGACopyTransparentArea, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGACopyTransparentArea; req->screen = screen; @@ -590,119 +550,109 @@ void SDL_NAME(XDGACopyTransparentArea)( req->dstx = dstx; req->dsty = dsty; req->key = key; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -int SDL_NAME(XDGAGetViewportStatus)( - Display *dpy, - int screen -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +int SDL_NAME (XDGAGetViewportStatus) (Display * dpy, int screen) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGAGetViewportStatusReply rep; xXDGAGetViewportStatusReq *req; int status = 0; XDGACheckExtension (dpy, info, 0); - LockDisplay(dpy); - GetReq(XDGAGetViewportStatus, req); + LockDisplay (dpy); + GetReq (XDGAGetViewportStatus, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGAGetViewportStatus; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) - status = rep.status; - UnlockDisplay(dpy); - SyncHandle(); + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) + status = rep.status; + UnlockDisplay (dpy); + SyncHandle (); return status; } -void SDL_NAME(XDGASync)( - Display *dpy, - int screen -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGASync) (Display * dpy, int screen) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGASyncReply rep; xXDGASyncReq *req; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGASync, req); + LockDisplay (dpy); + GetReq (XDGASync, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGASync; req->screen = screen; - _XReply(dpy, (xReply *)&rep, 0, xFalse); - UnlockDisplay(dpy); - SyncHandle(); + _XReply (dpy, (xReply *) & rep, 0, xFalse); + UnlockDisplay (dpy); + SyncHandle (); } -void SDL_NAME(XDGAChangePixmapMode)( - Display *dpy, - int screen, - int *x, - int *y, - int mode -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +void SDL_NAME (XDGAChangePixmapMode) (Display * dpy, + int screen, int *x, int *y, int mode) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGAChangePixmapModeReq *req; xXDGAChangePixmapModeReply rep; - XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); + XextSimpleCheckExtension (dpy, info, SDL_NAME (xdga_extension_name)); - LockDisplay(dpy); - GetReq(XDGAChangePixmapMode, req); + LockDisplay (dpy); + GetReq (XDGAChangePixmapMode, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGAChangePixmapMode; req->screen = screen; req->x = *x; req->y = *y; req->flags = mode; - _XReply(dpy, (xReply *)&rep, 0, xFalse); + _XReply (dpy, (xReply *) & rep, 0, xFalse); *x = rep.x; *y = rep.y; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); } -Colormap SDL_NAME(XDGACreateColormap)( - Display *dpy, - int screen, - SDL_NAME(XDGADevice) *dev, - int alloc -){ - XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); +Colormap SDL_NAME (XDGACreateColormap) (Display * dpy, + int screen, + SDL_NAME (XDGADevice) * dev, + int alloc) +{ + XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); xXDGACreateColormapReq *req; Colormap cid; XDGACheckExtension (dpy, info, -1); - LockDisplay(dpy); - GetReq(XDGACreateColormap, req); + LockDisplay (dpy); + GetReq (XDGACreateColormap, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XDGACreateColormap; req->screen = screen; req->mode = dev->mode.num; req->alloc = alloc; - cid = req->id = XAllocID(dpy); - UnlockDisplay(dpy); - SyncHandle(); + cid = req->id = XAllocID (dpy); + UnlockDisplay (dpy); + SyncHandle (); return cid; } -void SDL_NAME(XDGAKeyEventToXKeyEvent)( - SDL_NAME(XDGAKeyEvent)* dk, - XKeyEvent* xk -){ +void SDL_NAME (XDGAKeyEventToXKeyEvent) (SDL_NAME (XDGAKeyEvent) * dk, + XKeyEvent * xk) +{ xk->type = dk->type; xk->serial = dk->serial; xk->send_event = False; xk->display = dk->display; - xk->window = RootWindow(dk->display, dk->screen); + xk->window = RootWindow (dk->display, dk->screen); xk->root = xk->window; xk->subwindow = None; xk->time = dk->time; @@ -716,7 +666,7 @@ void SDL_NAME(XDGAKeyEventToXKeyEvent)( #include #include #include -#if defined(ISC) +#if defined(ISC) # define HAS_SVR3_MMAP # include # include @@ -754,115 +704,111 @@ void SDL_NAME(XDGAKeyEventToXKeyEvent)( -typedef struct _DGAMapRec{ - unsigned char *physical; - unsigned char *virtual; - CARD32 size; - int fd; - int screen; - struct _DGAMapRec *next; +typedef struct _DGAMapRec +{ + unsigned char *physical; + unsigned char *virtual; + CARD32 size; + int fd; + int screen; + struct _DGAMapRec *next; } DGAMapRec, *DGAMapPtr; static Bool -DGAMapPhysical(int, char*, unsigned char*, CARD32, CARD32, CARD32, DGAMapPtr); -static void DGAUnmapPhysical(DGAMapPtr); +DGAMapPhysical (int, char *, unsigned char *, CARD32, CARD32, CARD32, + DGAMapPtr); +static void DGAUnmapPhysical (DGAMapPtr); static DGAMapPtr _Maps = NULL; -unsigned char* -SDL_NAME(XDGAGetMappedMemory)(int screen) +unsigned char *SDL_NAME (XDGAGetMappedMemory) (int screen) { DGAMapPtr pMap = _Maps; unsigned char *pntr = NULL; - while(pMap != NULL) { - if(pMap->screen == screen) { - pntr = pMap->virtual; - break; - } - pMap = pMap->next; + while (pMap != NULL) { + if (pMap->screen == screen) { + pntr = pMap->virtual; + break; + } + pMap = pMap->next; } return pntr; } -Bool -SDL_NAME(XDGAMapFramebuffer)( - int screen, - char *name, /* optional device name */ - unsigned char* base, /* physical memory */ - CARD32 size, /* size */ - CARD32 offset, /* optional offset */ - CARD32 extra /* optional extra data */ -){ - DGAMapPtr pMap = _Maps; - Bool result; - - /* is it already mapped ? */ - while(pMap != NULL) { - if(pMap->screen == screen) - return True; - pMap = pMap->next; - } - - if(extra & XDGANeedRoot) { - /* we should probably check if we have root permissions and - return False here */ - - } - - pMap = (DGAMapPtr)Xmalloc(sizeof(DGAMapRec)); - - result = DGAMapPhysical(screen, name, base, size, offset, extra, pMap); - - if(result) { - pMap->next = _Maps; - _Maps = pMap; - } else - Xfree(pMap); - - return result; +Bool SDL_NAME (XDGAMapFramebuffer) (int screen, char *name, /* optional device name */ + unsigned char *base, /* physical memory */ + CARD32 size, /* size */ + CARD32 offset, /* optional offset */ + CARD32 extra /* optional extra data */ + ) +{ + DGAMapPtr pMap = _Maps; + Bool result; + + /* is it already mapped ? */ + while (pMap != NULL) { + if (pMap->screen == screen) + return True; + pMap = pMap->next; + } + + if (extra & XDGANeedRoot) { + /* we should probably check if we have root permissions and + return False here */ + + } + + pMap = (DGAMapPtr) Xmalloc (sizeof (DGAMapRec)); + + result = DGAMapPhysical (screen, name, base, size, offset, extra, pMap); + + if (result) { + pMap->next = _Maps; + _Maps = pMap; + } else + Xfree (pMap); + + return result; } -void -SDL_NAME(XDGAUnmapFramebuffer)(int screen) +void SDL_NAME (XDGAUnmapFramebuffer) (int screen) { - DGAMapPtr pMap = _Maps; - DGAMapPtr pPrev = NULL; - - /* is it already mapped */ - while(pMap != NULL) { - if(pMap->screen == screen) - break; - pPrev = pMap; - pMap = pMap->next; + DGAMapPtr pMap = _Maps; + DGAMapPtr pPrev = NULL; + + /* is it already mapped */ + while (pMap != NULL) { + if (pMap->screen == screen) + break; + pPrev = pMap; + pMap = pMap->next; } - if(!pMap) - return; + if (!pMap) + return; - DGAUnmapPhysical(pMap); + DGAUnmapPhysical (pMap); - if(!pPrev) - _Maps = pMap->next; + if (!pPrev) + _Maps = pMap->next; else - pPrev->next = pMap->next; + pPrev->next = pMap->next; - Xfree(pMap); + Xfree (pMap); } static Bool -DGAMapPhysical( - int screen, - char *name, /* optional device name */ - unsigned char* base, /* physical memory */ - CARD32 size, /* size */ - CARD32 offset, /* optional offset */ - CARD32 extra, /* optional extra data */ - DGAMapPtr pMap -) { +DGAMapPhysical (int screen, char *name, /* optional device name */ + unsigned char *base, /* physical memory */ + CARD32 size, /* size */ + CARD32 offset, /* optional offset */ + CARD32 extra, /* optional extra data */ + DGAMapPtr pMap) +{ #if defined(ISC) && defined(HAS_SVR3_MMAP) struct kd_memloc mloc; #elif defined(__EMX__) @@ -870,7 +816,7 @@ DGAMapPhysical( ULONG action; HFILE hfd; #endif - + base += offset; pMap->screen = screen; @@ -878,15 +824,16 @@ DGAMapPhysical( pMap->size = size; #if defined(ISC) && defined(HAS_SVR3_MMAP) - if ((pMap->fd = open("/dev/mmap", O_RDWR)) < 0) - return False; - mloc.vaddr = (char *)0; - mloc.physaddr = (char *)base; + if ((pMap->fd = open ("/dev/mmap", O_RDWR)) < 0) + return False; + mloc.vaddr = (char *) 0; + mloc.physaddr = (char *) base; mloc.length = size; - mloc.ioflg=1; + mloc.ioflg = 1; - if ((pMap->virtual = (void *)ioctl(pMap->fd, MAP, &mloc)) == (void *)-1) - return False; + if ((pMap->virtual = + (void *) ioctl (pMap->fd, MAP, &mloc)) == (void *) -1) + return False; #elif defined (__EMX__) /* * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. @@ -894,55 +841,58 @@ DGAMapPhysical( * of memory handles. Some umap/close mechanism should be provided */ - rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, - OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL); + rc = DosOpen ("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, + OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL); if (rc != 0) - return False; + return False; { - struct map_ioctl { - union { - ULONG phys; - void* user; - } a; - ULONG size; - } pmap,dmap; - ULONG plen,dlen; + struct map_ioctl + { + union + { + ULONG phys; + void *user; + } a; + ULONG size; + } pmap, dmap; + ULONG plen, dlen; #define XFREE86_PMAP 0x76 #define PMAP_MAP 0x44 - pmap.a.phys = base; - pmap.size = size; - rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP, - (PULONG)&pmap, sizeof(pmap), &plen, - (PULONG)&dmap, sizeof(dmap), &dlen); - if (rc == 0) { - pMap->virtual = dmap.a.user; - } - } - if (rc != 0) - return False; + pmap.a.phys = base; + pmap.size = size; + rc = DosDevIOCtl (hfd, XFREE86_PMAP, PMAP_MAP, + (PULONG) & pmap, sizeof (pmap), &plen, + (PULONG) & dmap, sizeof (dmap), &dlen); + if (rc == 0) { + pMap->virtual = dmap.a.user; + } + } + if (rc != 0) + return False; #elif defined (Lynx) - pMap->virtual = smem_create("XF86DGA", (char*)base, size, SM_READ|SM_WRITE); + pMap->virtual = + smem_create ("XF86DGA", (char *) base, size, SM_READ | SM_WRITE); #else #ifndef MAP_FILE #define MAP_FILE 0 #endif if (!name) - name = DEV_MEM; - if ((pMap->fd = open(name, O_RDWR)) < 0) + name = DEV_MEM; + if ((pMap->fd = open (name, O_RDWR)) < 0) #if defined(ENABLE_FBCON) - { /* /dev/fb0 fallback added by Sam Lantinga */ + { /* /dev/fb0 fallback added by Sam Lantinga */ /* Try to fall back to /dev/fb on Linux - FIXME: verify the device */ struct fb_fix_screeninfo finfo; - if ((pMap->fd = open("/dev/fb0", O_RDWR)) < 0) { + if ((pMap->fd = open ("/dev/fb0", O_RDWR)) < 0) { return False; } /* The useable framebuffer console memory may not be the whole framebuffer that X has access to. :-( */ - if ( ioctl(pMap->fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { - close(pMap->fd); + if (ioctl (pMap->fd, FBIOGET_FSCREENINFO, &finfo) < 0) { + close (pMap->fd); return False; } /* Warning: On PPC, the size and virtual need to be offset by: @@ -953,17 +903,17 @@ DGAMapPhysical( size = pMap->size = finfo.smem_len; } #else - return False; + return False; #endif - pMap->virtual = mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_FILE | MAP_SHARED, pMap->fd, (off_t)base); - if (pMap->virtual == (void *)-1) - return False; + pMap->virtual = mmap (NULL, size, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, pMap->fd, (off_t) base); + if (pMap->virtual == (void *) -1) + return False; #endif #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ && !defined(__EMX__) - mprotect(pMap->virtual, size, PROT_READ | PROT_WRITE); + mprotect (pMap->virtual, size, PROT_READ | PROT_WRITE); #endif return True; @@ -972,17 +922,19 @@ DGAMapPhysical( static void -DGAUnmapPhysical(DGAMapPtr pMap) +DGAUnmapPhysical (DGAMapPtr pMap) { #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ && !defined(__EMX__) - mprotect(pMap->virtual,pMap->size, PROT_READ); + mprotect (pMap->virtual, pMap->size, PROT_READ); #elif defined(Lynx) - /* XXX this doesn't allow enable after disable */ - smem_create(NULL, pMap->virtual, pMap->size, SM_DETACH); - smem_remove("XF86DGA"); + /* XXX this doesn't allow enable after disable */ + smem_create (NULL, pMap->virtual, pMap->size, SM_DETACH); + smem_remove ("XF86DGA"); #endif - /* We need to unmap and close too !!!!!!!!!!*/ + /* We need to unmap and close too !!!!!!!!!! */ } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/Xxf86vm/XF86VMode.c b/src/video/Xext/Xxf86vm/XF86VMode.c index 7901991fb..d89bdd7d6 100644 --- a/src/video/Xext/Xxf86vm/XF86VMode.c +++ b/src/video/Xext/Xxf86vm/XF86VMode.c @@ -69,56 +69,54 @@ static char *xf86vidmode_extension_name = XF86VIDMODENAME; * * *****************************************************************************/ -static XEXT_CLOSE_DISPLAY_PROTO(close_display); +static XEXT_CLOSE_DISPLAY_PROTO (close_display); static /* const */ XExtensionHooks xf86vidmode_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - close_display, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + close_display, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ }; -static XEXT_GENERATE_FIND_DISPLAY (find_display, xf86vidmode_info, - xf86vidmode_extension_name, - &xf86vidmode_extension_hooks, - 0, NULL) - -static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xf86vidmode_info) - - +static +XEXT_GENERATE_FIND_DISPLAY (find_display, xf86vidmode_info, + xf86vidmode_extension_name, + &xf86vidmode_extension_hooks, 0, NULL) + static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xf86vidmode_info) /***************************************************************************** * * * public XFree86-VidMode Extension routines * * * *****************************************************************************/ - -Bool -SDL_NAME(XF86VidModeQueryExtension) (dpy, event_basep, error_basep) - Display *dpy; - int *event_basep, *error_basep; + Bool +SDL_NAME (XF86VidModeQueryExtension) (dpy, event_basep, error_basep) + Display *dpy; + int *event_basep, *error_basep; { XExtDisplayInfo *info = find_display (dpy); - if (XextHasExtension(info)) { - *event_basep = info->codes->first_event; - *error_basep = info->codes->first_error; - return True; + if (XextHasExtension (info)) { + *event_basep = info->codes->first_event; + *error_basep = info->codes->first_error; + return True; } else { - return False; + return False; } } -Bool -SDL_NAME(XF86VidModeQueryVersion)(dpy, majorVersion, minorVersion) - Display* dpy; - int* majorVersion; - int* minorVersion; +Bool SDL_NAME (XF86VidModeQueryVersion) (dpy, majorVersion, minorVersion) + Display * + dpy; + int * + majorVersion; + int * + minorVersion; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeQueryVersionReply rep; @@ -126,66 +124,67 @@ SDL_NAME(XF86VidModeQueryVersion)(dpy, majorVersion, minorVersion) XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeQueryVersion, req); + LockDisplay (dpy); + GetReq (XF86VidModeQueryVersion, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeQueryVersion; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } *majorVersion = rep.majorVersion; *minorVersion = rep.minorVersion; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); if (*majorVersion >= 2) - SDL_NAME(XF86VidModeSetClientVersion)(dpy); + SDL_NAME (XF86VidModeSetClientVersion) (dpy); return True; } -Bool -SDL_NAME(XF86VidModeSetClientVersion)(Display *dpy) +Bool SDL_NAME (XF86VidModeSetClientVersion) (Display * dpy) { - XExtDisplayInfo *info = find_display(dpy); + XExtDisplayInfo *info = find_display (dpy); xXF86VidModeSetClientVersionReq *req; - XF86VidModeCheckExtension(dpy, info, False); + XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeSetClientVersion, req); + LockDisplay (dpy); + GetReq (XF86VidModeSetClientVersion, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeSetClientVersion; req->major = XF86VIDMODE_MAJOR_VERSION; req->minor = XF86VIDMODE_MINOR_VERSION; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } Bool -SDL_NAME(XF86VidModeSetGamma)(Display *dpy, int screen, SDL_NAME(XF86VidModeGamma) *Gamma) +SDL_NAME (XF86VidModeSetGamma) (Display * dpy, int screen, + SDL_NAME (XF86VidModeGamma) * Gamma) { - XExtDisplayInfo *info = find_display(dpy); + XExtDisplayInfo *info = find_display (dpy); xXF86VidModeSetGammaReq *req; - XF86VidModeCheckExtension(dpy, info, False); + XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeSetGamma, req); + LockDisplay (dpy); + GetReq (XF86VidModeSetGamma, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeSetGamma; req->screen = screen; - req->red = (CARD32)(Gamma->red * 10000.); - req->green = (CARD32)(Gamma->green * 10000.); - req->blue = (CARD32)(Gamma->blue * 10000.); - UnlockDisplay(dpy); - SyncHandle(); + req->red = (CARD32) (Gamma->red * 10000.); + req->green = (CARD32) (Gamma->green * 10000.); + req->blue = (CARD32) (Gamma->blue * 10000.); + UnlockDisplay (dpy); + SyncHandle (); return True; } Bool -SDL_NAME(XF86VidModeGetGamma)(Display *dpy, int screen, SDL_NAME(XF86VidModeGamma) *Gamma) +SDL_NAME (XF86VidModeGetGamma) (Display * dpy, int screen, + SDL_NAME (XF86VidModeGamma) * Gamma) { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetGammaReply rep; @@ -193,30 +192,32 @@ SDL_NAME(XF86VidModeGetGamma)(Display *dpy, int screen, SDL_NAME(XF86VidModeGamm XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeGetGamma, req); + LockDisplay (dpy); + GetReq (XF86VidModeGetGamma, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetGamma; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } - Gamma->red = ((float)rep.red) / 10000.; - Gamma->green = ((float)rep.green) / 10000.; - Gamma->blue = ((float)rep.blue) / 10000.; - UnlockDisplay(dpy); - SyncHandle(); + Gamma->red = ((float) rep.red) / 10000.; + Gamma->green = ((float) rep.green) / 10000.; + Gamma->blue = ((float) rep.blue) / 10000.; + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool -SDL_NAME(XF86VidModeGetModeLine)(dpy, screen, dotclock, modeline) - Display* dpy; - int screen; - int* dotclock; - SDL_NAME(XF86VidModeModeLine)* modeline; +Bool SDL_NAME (XF86VidModeGetModeLine) (dpy, screen, dotclock, modeline) + Display * + dpy; + int + screen; + int * + dotclock; +SDL_NAME (XF86VidModeModeLine) * modeline; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetModeLineReply rep; @@ -225,80 +226,85 @@ SDL_NAME(XF86VidModeGetModeLine)(dpy, screen, dotclock, modeline) int majorVersion, minorVersion; XF86VidModeCheckExtension (dpy, info, False); - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); - LockDisplay(dpy); - GetReq(XF86VidModeGetModeLine, req); + LockDisplay (dpy); + GetReq (XF86VidModeGetModeLine, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetModeLine; req->screen = screen; - + if (majorVersion < 2) { - if (!_XReply(dpy, (xReply *)&oldrep, - (SIZEOF(xXF86OldVidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - *dotclock = oldrep.dotclock; - modeline->hdisplay = oldrep.hdisplay; - modeline->hsyncstart = oldrep.hsyncstart; - modeline->hsyncend = oldrep.hsyncend; - modeline->htotal = oldrep.htotal; - modeline->hskew = 0; - modeline->vdisplay = oldrep.vdisplay; - modeline->vsyncstart = oldrep.vsyncstart; - modeline->vsyncend = oldrep.vsyncend; - modeline->vtotal = oldrep.vtotal; - modeline->flags = oldrep.flags; - modeline->privsize = oldrep.privsize; + if (!_XReply (dpy, (xReply *) & oldrep, + (SIZEOF (xXF86OldVidModeGetModeLineReply) - + SIZEOF (xReply)) >> 2, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + *dotclock = oldrep.dotclock; + modeline->hdisplay = oldrep.hdisplay; + modeline->hsyncstart = oldrep.hsyncstart; + modeline->hsyncend = oldrep.hsyncend; + modeline->htotal = oldrep.htotal; + modeline->hskew = 0; + modeline->vdisplay = oldrep.vdisplay; + modeline->vsyncstart = oldrep.vsyncstart; + modeline->vsyncend = oldrep.vsyncend; + modeline->vtotal = oldrep.vtotal; + modeline->flags = oldrep.flags; + modeline->privsize = oldrep.privsize; } else { - if (!_XReply(dpy, (xReply *)&rep, - (SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - *dotclock = rep.dotclock; - modeline->hdisplay = rep.hdisplay; - modeline->hsyncstart = rep.hsyncstart; - modeline->hsyncend = rep.hsyncend; - modeline->htotal = rep.htotal; - modeline->hskew = rep.hskew; - modeline->vdisplay = rep.vdisplay; - modeline->vsyncstart = rep.vsyncstart; - modeline->vsyncend = rep.vsyncend; - modeline->vtotal = rep.vtotal; - modeline->flags = rep.flags; - modeline->privsize = rep.privsize; + if (!_XReply (dpy, (xReply *) & rep, + (SIZEOF (xXF86VidModeGetModeLineReply) - + SIZEOF (xReply)) >> 2, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + *dotclock = rep.dotclock; + modeline->hdisplay = rep.hdisplay; + modeline->hsyncstart = rep.hsyncstart; + modeline->hsyncend = rep.hsyncend; + modeline->htotal = rep.htotal; + modeline->hskew = rep.hskew; + modeline->vdisplay = rep.vdisplay; + modeline->vsyncstart = rep.vsyncstart; + modeline->vsyncend = rep.vsyncend; + modeline->vtotal = rep.vtotal; + modeline->flags = rep.flags; + modeline->privsize = rep.privsize; } - + if (modeline->privsize > 0) { - if (!(modeline->private = Xcalloc(modeline->privsize, sizeof(INT32)))) { - _XEatData(dpy, (modeline->privsize) * sizeof(INT32)); - Xfree(modeline->private); - return False; - } - _XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32)); + if (! + (modeline->private = + Xcalloc (modeline->privsize, sizeof (INT32)))) { + _XEatData (dpy, (modeline->privsize) * sizeof (INT32)); + Xfree (modeline->private); + return False; + } + _XRead (dpy, (char *) modeline->private, + modeline->privsize * sizeof (INT32)); } else { - modeline->private = NULL; + modeline->private = NULL; } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } Bool -SDL_NAME(XF86VidModeGetAllModeLines)(dpy, screen, modecount, modelinesPtr) - Display* dpy; - int screen; - int* modecount; - SDL_NAME(XF86VidModeModeInfo) ***modelinesPtr; +SDL_NAME (XF86VidModeGetAllModeLines) (dpy, screen, modecount, modelinesPtr) + Display *dpy; + int screen; + int *modecount; +SDL_NAME (XF86VidModeModeInfo) *** modelinesPtr; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetAllModeLinesReply rep; xXF86VidModeGetAllModeLinesReq *req; - SDL_NAME(XF86VidModeModeInfo) *mdinfptr, **modelines; + SDL_NAME (XF86VidModeModeInfo) * mdinfptr, **modelines; xXF86VidModeModeInfo xmdline; xXF86OldVidModeModeInfo oldxmdline; int i; @@ -313,116 +319,128 @@ SDL_NAME(XF86VidModeGetAllModeLines)(dpy, screen, modecount, modelinesPtr) * Check the server's version, and accept the old format if appropriate. */ - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); if (majorVersion == 0 && minorVersion < 8) { - protocolBug = True; + protocolBug = True; #ifdef DEBUG - fprintf(stderr, "XF86VidModeGetAllModeLines: Warning: Xserver is" - "running an old version (%d.%d)\n", majorVersion, - minorVersion); + fprintf (stderr, "XF86VidModeGetAllModeLines: Warning: Xserver is" + "running an old version (%d.%d)\n", majorVersion, + minorVersion); #endif } - - LockDisplay(dpy); - GetReq(XF86VidModeGetAllModeLines, req); + + LockDisplay (dpy); + GetReq (XF86VidModeGetAllModeLines, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetAllModeLines; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, - (SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xReply)) >> 2, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, + (SIZEOF (xXF86VidModeGetAllModeLinesReply) - + SIZEOF (xReply)) >> 2, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } *modecount = rep.modecount; - if (!(modelines = (SDL_NAME(XF86VidModeModeInfo) **) Xcalloc(rep.modecount, - sizeof(SDL_NAME(XF86VidModeModeInfo) *) - +sizeof(SDL_NAME(XF86VidModeModeInfo))))) { - if (majorVersion < 2) - _XEatData(dpy, (rep.modecount) * sizeof(xXF86OldVidModeModeInfo)); - else - _XEatData(dpy, (rep.modecount) * sizeof(xXF86VidModeModeInfo)); - Xfree(modelines); - UnlockDisplay(dpy); - SyncHandle(); + if (! + (modelines = + (SDL_NAME (XF86VidModeModeInfo) **) Xcalloc (rep.modecount, + sizeof (SDL_NAME + (XF86VidModeModeInfo) + *) + + sizeof (SDL_NAME + (XF86VidModeModeInfo))))) + { + if (majorVersion < 2) + _XEatData (dpy, + (rep.modecount) * sizeof (xXF86OldVidModeModeInfo)); + else + _XEatData (dpy, (rep.modecount) * sizeof (xXF86VidModeModeInfo)); + Xfree (modelines); + UnlockDisplay (dpy); + SyncHandle (); return False; } - mdinfptr = (SDL_NAME(XF86VidModeModeInfo) *) ( - (char *) modelines - + rep.modecount*sizeof(SDL_NAME(XF86VidModeModeInfo) *) - ); + mdinfptr = (SDL_NAME (XF86VidModeModeInfo) *) ((char *) modelines + + + rep.modecount * + sizeof (SDL_NAME + (XF86VidModeModeInfo) + *)); for (i = 0; i < rep.modecount; i++) { modelines[i] = mdinfptr++; - if (majorVersion < 2) { - _XRead(dpy, (char*)&oldxmdline, sizeof(xXF86OldVidModeModeInfo)); - modelines[i]->dotclock = oldxmdline.dotclock; - modelines[i]->hdisplay = oldxmdline.hdisplay; - modelines[i]->hsyncstart = oldxmdline.hsyncstart; - modelines[i]->hsyncend = oldxmdline.hsyncend; - modelines[i]->htotal = oldxmdline.htotal; - modelines[i]->hskew = 0; - modelines[i]->vdisplay = oldxmdline.vdisplay; - modelines[i]->vsyncstart = oldxmdline.vsyncstart; - modelines[i]->vsyncend = oldxmdline.vsyncend; - modelines[i]->vtotal = oldxmdline.vtotal; - modelines[i]->flags = oldxmdline.flags; - if (protocolBug) { - modelines[i]->privsize = 0; - modelines[i]->private = NULL; - } else { - modelines[i]->privsize = oldxmdline.privsize; - if (oldxmdline.privsize > 0) { - if (!(modelines[i]->private = - Xcalloc(oldxmdline.privsize, sizeof(INT32)))) { - _XEatData(dpy, (oldxmdline.privsize) * sizeof(INT32)); - Xfree(modelines[i]->private); - } else { - _XRead(dpy, (char*)modelines[i]->private, - oldxmdline.privsize * sizeof(INT32)); - } - } else { - modelines[i]->private = NULL; - } - } - } else { - _XRead(dpy, (char*)&xmdline, sizeof(xXF86VidModeModeInfo)); - modelines[i]->dotclock = xmdline.dotclock; - modelines[i]->hdisplay = xmdline.hdisplay; - modelines[i]->hsyncstart = xmdline.hsyncstart; - modelines[i]->hsyncend = xmdline.hsyncend; - modelines[i]->htotal = xmdline.htotal; - modelines[i]->hskew = xmdline.hskew; - modelines[i]->vdisplay = xmdline.vdisplay; - modelines[i]->vsyncstart = xmdline.vsyncstart; - modelines[i]->vsyncend = xmdline.vsyncend; - modelines[i]->vtotal = xmdline.vtotal; - modelines[i]->flags = xmdline.flags; - if (protocolBug) { - modelines[i]->privsize = 0; - modelines[i]->private = NULL; - } else { - modelines[i]->privsize = xmdline.privsize; - if (xmdline.privsize > 0) { - if (!(modelines[i]->private = - Xcalloc(xmdline.privsize, sizeof(INT32)))) { - _XEatData(dpy, (xmdline.privsize) * sizeof(INT32)); - Xfree(modelines[i]->private); - } else { - _XRead(dpy, (char*)modelines[i]->private, - xmdline.privsize * sizeof(INT32)); - } - } else { - modelines[i]->private = NULL; - } - } - } + if (majorVersion < 2) { + _XRead (dpy, (char *) &oldxmdline, + sizeof (xXF86OldVidModeModeInfo)); + modelines[i]->dotclock = oldxmdline.dotclock; + modelines[i]->hdisplay = oldxmdline.hdisplay; + modelines[i]->hsyncstart = oldxmdline.hsyncstart; + modelines[i]->hsyncend = oldxmdline.hsyncend; + modelines[i]->htotal = oldxmdline.htotal; + modelines[i]->hskew = 0; + modelines[i]->vdisplay = oldxmdline.vdisplay; + modelines[i]->vsyncstart = oldxmdline.vsyncstart; + modelines[i]->vsyncend = oldxmdline.vsyncend; + modelines[i]->vtotal = oldxmdline.vtotal; + modelines[i]->flags = oldxmdline.flags; + if (protocolBug) { + modelines[i]->privsize = 0; + modelines[i]->private = NULL; + } else { + modelines[i]->privsize = oldxmdline.privsize; + if (oldxmdline.privsize > 0) { + if (!(modelines[i]->private = + Xcalloc (oldxmdline.privsize, sizeof (INT32)))) { + _XEatData (dpy, + (oldxmdline.privsize) * sizeof (INT32)); + Xfree (modelines[i]->private); + } else { + _XRead (dpy, (char *) modelines[i]->private, + oldxmdline.privsize * sizeof (INT32)); + } + } else { + modelines[i]->private = NULL; + } + } + } else { + _XRead (dpy, (char *) &xmdline, sizeof (xXF86VidModeModeInfo)); + modelines[i]->dotclock = xmdline.dotclock; + modelines[i]->hdisplay = xmdline.hdisplay; + modelines[i]->hsyncstart = xmdline.hsyncstart; + modelines[i]->hsyncend = xmdline.hsyncend; + modelines[i]->htotal = xmdline.htotal; + modelines[i]->hskew = xmdline.hskew; + modelines[i]->vdisplay = xmdline.vdisplay; + modelines[i]->vsyncstart = xmdline.vsyncstart; + modelines[i]->vsyncend = xmdline.vsyncend; + modelines[i]->vtotal = xmdline.vtotal; + modelines[i]->flags = xmdline.flags; + if (protocolBug) { + modelines[i]->privsize = 0; + modelines[i]->private = NULL; + } else { + modelines[i]->privsize = xmdline.privsize; + if (xmdline.privsize > 0) { + if (!(modelines[i]->private = + Xcalloc (xmdline.privsize, sizeof (INT32)))) { + _XEatData (dpy, (xmdline.privsize) * sizeof (INT32)); + Xfree (modelines[i]->private); + } else { + _XRead (dpy, (char *) modelines[i]->private, + xmdline.privsize * sizeof (INT32)); + } + } else { + modelines[i]->private = NULL; + } + } + } } *modelinesPtr = modelines; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } @@ -440,7 +458,7 @@ SDL_NAME(XF86VidModeGetAllModeLines)(dpy, screen, modecount, modelinesPtr) dpy->bufptr += SIZEOF(x##oldname##Req);\ dpy->request++ -#else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ +#else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ #define GetOldReq(name, oldname, req) \ WORD64ALIGN\ if ((dpy->bufptr + SIZEOF(x/**/oldname/**/Req)) > dpy->bufmax)\ @@ -453,11 +471,11 @@ SDL_NAME(XF86VidModeGetAllModeLines)(dpy, screen, modecount, modelinesPtr) #endif Bool -SDL_NAME(XF86VidModeAddModeLine) (dpy, screen, newmodeline, aftermodeline) - Display *dpy; - int screen; - SDL_NAME(XF86VidModeModeInfo)* newmodeline; - SDL_NAME(XF86VidModeModeInfo)* aftermodeline; +SDL_NAME (XF86VidModeAddModeLine) (dpy, screen, newmodeline, aftermodeline) + Display *dpy; + int screen; +SDL_NAME (XF86VidModeModeInfo) * newmodeline; +SDL_NAME (XF86VidModeModeInfo) * aftermodeline; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeAddModeLineReq *req; @@ -465,111 +483,112 @@ SDL_NAME(XF86VidModeAddModeLine) (dpy, screen, newmodeline, aftermodeline) int majorVersion, minorVersion; XF86VidModeCheckExtension (dpy, info, False); - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); - LockDisplay(dpy); + LockDisplay (dpy); if (majorVersion < 2) { - GetOldReq(XF86VidModeAddModeLine, XF86OldVidModeAddModeLine, oldreq); - oldreq->reqType = info->codes->major_opcode; - oldreq->xf86vidmodeReqType = X_XF86VidModeAddModeLine; - oldreq->screen = screen; - oldreq->dotclock = newmodeline->dotclock; - oldreq->hdisplay = newmodeline->hdisplay; - oldreq->hsyncstart = newmodeline->hsyncstart; - oldreq->hsyncend = newmodeline->hsyncend; - oldreq->htotal = newmodeline->htotal; - oldreq->vdisplay = newmodeline->vdisplay; - oldreq->vsyncstart = newmodeline->vsyncstart; - oldreq->vsyncend = newmodeline->vsyncend; - oldreq->vtotal = newmodeline->vtotal; - oldreq->flags = newmodeline->flags; - oldreq->privsize = newmodeline->privsize; - if (aftermodeline != NULL) { - oldreq->after_dotclock = aftermodeline->dotclock; - oldreq->after_hdisplay = aftermodeline->hdisplay; - oldreq->after_hsyncstart = aftermodeline->hsyncstart; - oldreq->after_hsyncend = aftermodeline->hsyncend; - oldreq->after_htotal = aftermodeline->htotal; - oldreq->after_vdisplay = aftermodeline->vdisplay; - oldreq->after_vsyncstart = aftermodeline->vsyncstart; - oldreq->after_vsyncend = aftermodeline->vsyncend; - oldreq->after_vtotal = aftermodeline->vtotal; - oldreq->after_flags = aftermodeline->flags; - } else { - oldreq->after_dotclock = 0; - oldreq->after_hdisplay = 0; - oldreq->after_hsyncstart = 0; - oldreq->after_hsyncend = 0; - oldreq->after_htotal = 0; - oldreq->after_vdisplay = 0; - oldreq->after_vsyncstart = 0; - oldreq->after_vsyncend = 0; - oldreq->after_vtotal = 0; - oldreq->after_flags = 0; - } - if (newmodeline->privsize) { - oldreq->length += newmodeline->privsize; - Data32(dpy, (long *) newmodeline->private, - newmodeline->privsize * sizeof(INT32)); - } + GetOldReq (XF86VidModeAddModeLine, XF86OldVidModeAddModeLine, oldreq); + oldreq->reqType = info->codes->major_opcode; + oldreq->xf86vidmodeReqType = X_XF86VidModeAddModeLine; + oldreq->screen = screen; + oldreq->dotclock = newmodeline->dotclock; + oldreq->hdisplay = newmodeline->hdisplay; + oldreq->hsyncstart = newmodeline->hsyncstart; + oldreq->hsyncend = newmodeline->hsyncend; + oldreq->htotal = newmodeline->htotal; + oldreq->vdisplay = newmodeline->vdisplay; + oldreq->vsyncstart = newmodeline->vsyncstart; + oldreq->vsyncend = newmodeline->vsyncend; + oldreq->vtotal = newmodeline->vtotal; + oldreq->flags = newmodeline->flags; + oldreq->privsize = newmodeline->privsize; + if (aftermodeline != NULL) { + oldreq->after_dotclock = aftermodeline->dotclock; + oldreq->after_hdisplay = aftermodeline->hdisplay; + oldreq->after_hsyncstart = aftermodeline->hsyncstart; + oldreq->after_hsyncend = aftermodeline->hsyncend; + oldreq->after_htotal = aftermodeline->htotal; + oldreq->after_vdisplay = aftermodeline->vdisplay; + oldreq->after_vsyncstart = aftermodeline->vsyncstart; + oldreq->after_vsyncend = aftermodeline->vsyncend; + oldreq->after_vtotal = aftermodeline->vtotal; + oldreq->after_flags = aftermodeline->flags; + } else { + oldreq->after_dotclock = 0; + oldreq->after_hdisplay = 0; + oldreq->after_hsyncstart = 0; + oldreq->after_hsyncend = 0; + oldreq->after_htotal = 0; + oldreq->after_vdisplay = 0; + oldreq->after_vsyncstart = 0; + oldreq->after_vsyncend = 0; + oldreq->after_vtotal = 0; + oldreq->after_flags = 0; + } + if (newmodeline->privsize) { + oldreq->length += newmodeline->privsize; + Data32 (dpy, (long *) newmodeline->private, + newmodeline->privsize * sizeof (INT32)); + } } else { - GetReq(XF86VidModeAddModeLine, req); - req->reqType = info->codes->major_opcode; - req->xf86vidmodeReqType = X_XF86VidModeAddModeLine; - req->screen = screen; - req->dotclock = newmodeline->dotclock; - req->hdisplay = newmodeline->hdisplay; - req->hsyncstart = newmodeline->hsyncstart; - req->hsyncend = newmodeline->hsyncend; - req->htotal = newmodeline->htotal; - req->hskew = newmodeline->hskew; - req->vdisplay = newmodeline->vdisplay; - req->vsyncstart = newmodeline->vsyncstart; - req->vsyncend = newmodeline->vsyncend; - req->vtotal = newmodeline->vtotal; - req->flags = newmodeline->flags; - req->privsize = newmodeline->privsize; - if (aftermodeline != NULL) { - req->after_dotclock = aftermodeline->dotclock; - req->after_hdisplay = aftermodeline->hdisplay; - req->after_hsyncstart = aftermodeline->hsyncstart; - req->after_hsyncend = aftermodeline->hsyncend; - req->after_htotal = aftermodeline->htotal; - req->after_hskew = aftermodeline->hskew; - req->after_vdisplay = aftermodeline->vdisplay; - req->after_vsyncstart = aftermodeline->vsyncstart; - req->after_vsyncend = aftermodeline->vsyncend; - req->after_vtotal = aftermodeline->vtotal; - req->after_flags = aftermodeline->flags; - } else { - req->after_dotclock = 0; - req->after_hdisplay = 0; - req->after_hsyncstart = 0; - req->after_hsyncend = 0; - req->after_htotal = 0; - req->after_hskew = 0; - req->after_vdisplay = 0; - req->after_vsyncstart = 0; - req->after_vsyncend = 0; - req->after_vtotal = 0; - req->after_flags = 0; - } - if (newmodeline->privsize) { - req->length += newmodeline->privsize; - Data32(dpy, (long *) newmodeline->private, - newmodeline->privsize * sizeof(INT32)); - } + GetReq (XF86VidModeAddModeLine, req); + req->reqType = info->codes->major_opcode; + req->xf86vidmodeReqType = X_XF86VidModeAddModeLine; + req->screen = screen; + req->dotclock = newmodeline->dotclock; + req->hdisplay = newmodeline->hdisplay; + req->hsyncstart = newmodeline->hsyncstart; + req->hsyncend = newmodeline->hsyncend; + req->htotal = newmodeline->htotal; + req->hskew = newmodeline->hskew; + req->vdisplay = newmodeline->vdisplay; + req->vsyncstart = newmodeline->vsyncstart; + req->vsyncend = newmodeline->vsyncend; + req->vtotal = newmodeline->vtotal; + req->flags = newmodeline->flags; + req->privsize = newmodeline->privsize; + if (aftermodeline != NULL) { + req->after_dotclock = aftermodeline->dotclock; + req->after_hdisplay = aftermodeline->hdisplay; + req->after_hsyncstart = aftermodeline->hsyncstart; + req->after_hsyncend = aftermodeline->hsyncend; + req->after_htotal = aftermodeline->htotal; + req->after_hskew = aftermodeline->hskew; + req->after_vdisplay = aftermodeline->vdisplay; + req->after_vsyncstart = aftermodeline->vsyncstart; + req->after_vsyncend = aftermodeline->vsyncend; + req->after_vtotal = aftermodeline->vtotal; + req->after_flags = aftermodeline->flags; + } else { + req->after_dotclock = 0; + req->after_hdisplay = 0; + req->after_hsyncstart = 0; + req->after_hsyncend = 0; + req->after_htotal = 0; + req->after_hskew = 0; + req->after_vdisplay = 0; + req->after_vsyncstart = 0; + req->after_vsyncend = 0; + req->after_vtotal = 0; + req->after_flags = 0; + } + if (newmodeline->privsize) { + req->length += newmodeline->privsize; + Data32 (dpy, (long *) newmodeline->private, + newmodeline->privsize * sizeof (INT32)); + } } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool -SDL_NAME(XF86VidModeDeleteModeLine) (dpy, screen, modeline) - Display *dpy; - int screen; - SDL_NAME(XF86VidModeModeInfo)* modeline; +Bool SDL_NAME (XF86VidModeDeleteModeLine) (dpy, screen, modeline) + Display * + dpy; + int + screen; +SDL_NAME (XF86VidModeModeInfo) * modeline; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeDeleteModeLineReq *req; @@ -577,63 +596,65 @@ SDL_NAME(XF86VidModeDeleteModeLine) (dpy, screen, modeline) int majorVersion, minorVersion; XF86VidModeCheckExtension (dpy, info, 0); - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); - LockDisplay(dpy); + LockDisplay (dpy); if (majorVersion < 2) { - GetOldReq(XF86VidModeDeleteModeLine, XF86OldVidModeDeleteModeLine, oldreq); - oldreq->reqType = info->codes->major_opcode; - oldreq->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine; - oldreq->screen = screen; - oldreq->dotclock = modeline->dotclock; - oldreq->hdisplay = modeline->hdisplay; - oldreq->hsyncstart = modeline->hsyncstart; - oldreq->hsyncend = modeline->hsyncend; - oldreq->htotal = modeline->htotal; - oldreq->vdisplay = modeline->vdisplay; - oldreq->vsyncstart = modeline->vsyncstart; - oldreq->vsyncend = modeline->vsyncend; - oldreq->vtotal = modeline->vtotal; - oldreq->flags = modeline->flags; - oldreq->privsize = modeline->privsize; - if (modeline->privsize) { - oldreq->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } + GetOldReq (XF86VidModeDeleteModeLine, XF86OldVidModeDeleteModeLine, + oldreq); + oldreq->reqType = info->codes->major_opcode; + oldreq->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine; + oldreq->screen = screen; + oldreq->dotclock = modeline->dotclock; + oldreq->hdisplay = modeline->hdisplay; + oldreq->hsyncstart = modeline->hsyncstart; + oldreq->hsyncend = modeline->hsyncend; + oldreq->htotal = modeline->htotal; + oldreq->vdisplay = modeline->vdisplay; + oldreq->vsyncstart = modeline->vsyncstart; + oldreq->vsyncend = modeline->vsyncend; + oldreq->vtotal = modeline->vtotal; + oldreq->flags = modeline->flags; + oldreq->privsize = modeline->privsize; + if (modeline->privsize) { + oldreq->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } } else { - GetReq(XF86VidModeDeleteModeLine, req); - req->reqType = info->codes->major_opcode; - req->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine; - req->screen = screen; - req->dotclock = modeline->dotclock; - req->hdisplay = modeline->hdisplay; - req->hsyncstart = modeline->hsyncstart; - req->hsyncend = modeline->hsyncend; - req->htotal = modeline->htotal; - req->hskew = modeline->hskew; - req->vdisplay = modeline->vdisplay; - req->vsyncstart = modeline->vsyncstart; - req->vsyncend = modeline->vsyncend; - req->vtotal = modeline->vtotal; - req->flags = modeline->flags; - req->privsize = modeline->privsize; - if (modeline->privsize) { - req->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } + GetReq (XF86VidModeDeleteModeLine, req); + req->reqType = info->codes->major_opcode; + req->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine; + req->screen = screen; + req->dotclock = modeline->dotclock; + req->hdisplay = modeline->hdisplay; + req->hsyncstart = modeline->hsyncstart; + req->hsyncend = modeline->hsyncend; + req->htotal = modeline->htotal; + req->hskew = modeline->hskew; + req->vdisplay = modeline->vdisplay; + req->vsyncstart = modeline->vsyncstart; + req->vsyncend = modeline->vsyncend; + req->vtotal = modeline->vtotal; + req->flags = modeline->flags; + req->privsize = modeline->privsize; + if (modeline->privsize) { + req->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool -SDL_NAME(XF86VidModeModModeLine) (dpy, screen, modeline) - Display *dpy; - int screen; - SDL_NAME(XF86VidModeModeLine)* modeline; +Bool SDL_NAME (XF86VidModeModModeLine) (dpy, screen, modeline) + Display * + dpy; + int + screen; +SDL_NAME (XF86VidModeModeLine) * modeline; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeModModeLineReq *req; @@ -641,61 +662,62 @@ SDL_NAME(XF86VidModeModModeLine) (dpy, screen, modeline) int majorVersion, minorVersion; XF86VidModeCheckExtension (dpy, info, 0); - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); - LockDisplay(dpy); + LockDisplay (dpy); if (majorVersion < 2) { - GetOldReq(XF86VidModeModModeLine, XF86OldVidModeModModeLine, oldreq); - oldreq->reqType = info->codes->major_opcode; - oldreq->xf86vidmodeReqType = X_XF86VidModeModModeLine; - oldreq->screen = screen; - oldreq->hdisplay = modeline->hdisplay; - oldreq->hsyncstart = modeline->hsyncstart; - oldreq->hsyncend = modeline->hsyncend; - oldreq->htotal = modeline->htotal; - oldreq->vdisplay = modeline->vdisplay; - oldreq->vsyncstart = modeline->vsyncstart; - oldreq->vsyncend = modeline->vsyncend; - oldreq->vtotal = modeline->vtotal; - oldreq->flags = modeline->flags; - oldreq->privsize = modeline->privsize; - if (modeline->privsize) { - oldreq->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } + GetOldReq (XF86VidModeModModeLine, XF86OldVidModeModModeLine, oldreq); + oldreq->reqType = info->codes->major_opcode; + oldreq->xf86vidmodeReqType = X_XF86VidModeModModeLine; + oldreq->screen = screen; + oldreq->hdisplay = modeline->hdisplay; + oldreq->hsyncstart = modeline->hsyncstart; + oldreq->hsyncend = modeline->hsyncend; + oldreq->htotal = modeline->htotal; + oldreq->vdisplay = modeline->vdisplay; + oldreq->vsyncstart = modeline->vsyncstart; + oldreq->vsyncend = modeline->vsyncend; + oldreq->vtotal = modeline->vtotal; + oldreq->flags = modeline->flags; + oldreq->privsize = modeline->privsize; + if (modeline->privsize) { + oldreq->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } } else { - GetReq(XF86VidModeModModeLine, req); - req->reqType = info->codes->major_opcode; - req->xf86vidmodeReqType = X_XF86VidModeModModeLine; - req->screen = screen; - req->hdisplay = modeline->hdisplay; - req->hsyncstart = modeline->hsyncstart; - req->hsyncend = modeline->hsyncend; - req->htotal = modeline->htotal; - req->hskew = modeline->hskew; - req->vdisplay = modeline->vdisplay; - req->vsyncstart = modeline->vsyncstart; - req->vsyncend = modeline->vsyncend; - req->vtotal = modeline->vtotal; - req->flags = modeline->flags; - req->privsize = modeline->privsize; - if (modeline->privsize) { - req->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } + GetReq (XF86VidModeModModeLine, req); + req->reqType = info->codes->major_opcode; + req->xf86vidmodeReqType = X_XF86VidModeModModeLine; + req->screen = screen; + req->hdisplay = modeline->hdisplay; + req->hsyncstart = modeline->hsyncstart; + req->hsyncend = modeline->hsyncend; + req->htotal = modeline->htotal; + req->hskew = modeline->hskew; + req->vdisplay = modeline->vdisplay; + req->vsyncstart = modeline->vsyncstart; + req->vsyncend = modeline->vsyncend; + req->vtotal = modeline->vtotal; + req->flags = modeline->flags; + req->privsize = modeline->privsize; + if (modeline->privsize) { + req->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } -Status -SDL_NAME(XF86VidModeValidateModeLine) (dpy, screen, modeline) - Display *dpy; - int screen; - SDL_NAME(XF86VidModeModeInfo)* modeline; +Status SDL_NAME (XF86VidModeValidateModeLine) (dpy, screen, modeline) + Display * + dpy; + int + screen; +SDL_NAME (XF86VidModeModeInfo) * modeline; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeValidateModeLineReq *req; @@ -704,91 +726,95 @@ SDL_NAME(XF86VidModeValidateModeLine) (dpy, screen, modeline) int majorVersion, minorVersion; XF86VidModeCheckExtension (dpy, info, 0); - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); - LockDisplay(dpy); + LockDisplay (dpy); if (majorVersion < 2) { - GetOldReq(XF86VidModeValidateModeLine, XF86OldVidModeValidateModeLine, oldreq); - oldreq->reqType = info->codes->major_opcode; - oldreq->xf86vidmodeReqType = X_XF86VidModeValidateModeLine; - oldreq->screen = screen; - oldreq->dotclock = modeline->dotclock; - oldreq->hdisplay = modeline->hdisplay; - oldreq->hsyncstart = modeline->hsyncstart; - oldreq->hsyncend = modeline->hsyncend; - oldreq->htotal = modeline->htotal; - oldreq->vdisplay = modeline->vdisplay; - oldreq->vsyncstart = modeline->vsyncstart; - oldreq->vsyncend = modeline->vsyncend; - oldreq->vtotal = modeline->vtotal; - oldreq->flags = modeline->flags; - oldreq->privsize = modeline->privsize; - if (modeline->privsize) { - oldreq->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } + GetOldReq (XF86VidModeValidateModeLine, + XF86OldVidModeValidateModeLine, oldreq); + oldreq->reqType = info->codes->major_opcode; + oldreq->xf86vidmodeReqType = X_XF86VidModeValidateModeLine; + oldreq->screen = screen; + oldreq->dotclock = modeline->dotclock; + oldreq->hdisplay = modeline->hdisplay; + oldreq->hsyncstart = modeline->hsyncstart; + oldreq->hsyncend = modeline->hsyncend; + oldreq->htotal = modeline->htotal; + oldreq->vdisplay = modeline->vdisplay; + oldreq->vsyncstart = modeline->vsyncstart; + oldreq->vsyncend = modeline->vsyncend; + oldreq->vtotal = modeline->vtotal; + oldreq->flags = modeline->flags; + oldreq->privsize = modeline->privsize; + if (modeline->privsize) { + oldreq->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } } else { - GetReq(XF86VidModeValidateModeLine, req); - req->reqType = info->codes->major_opcode; - req->xf86vidmodeReqType = X_XF86VidModeValidateModeLine; - req->screen = screen; - req->dotclock = modeline->dotclock; - req->hdisplay = modeline->hdisplay; - req->hsyncstart = modeline->hsyncstart; - req->hsyncend = modeline->hsyncend; - req->htotal = modeline->htotal; - req->hskew = modeline->hskew; - req->vdisplay = modeline->vdisplay; - req->vsyncstart = modeline->vsyncstart; - req->vsyncend = modeline->vsyncend; - req->vtotal = modeline->vtotal; - req->flags = modeline->flags; - req->privsize = modeline->privsize; - if (modeline->privsize) { - req->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } + GetReq (XF86VidModeValidateModeLine, req); + req->reqType = info->codes->major_opcode; + req->xf86vidmodeReqType = X_XF86VidModeValidateModeLine; + req->screen = screen; + req->dotclock = modeline->dotclock; + req->hdisplay = modeline->hdisplay; + req->hsyncstart = modeline->hsyncstart; + req->hsyncend = modeline->hsyncend; + req->htotal = modeline->htotal; + req->hskew = modeline->hskew; + req->vdisplay = modeline->vdisplay; + req->vsyncstart = modeline->vsyncstart; + req->vsyncend = modeline->vsyncend; + req->vtotal = modeline->vtotal; + req->flags = modeline->flags; + req->privsize = modeline->privsize; + if (modeline->privsize) { + req->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } } - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return MODE_BAD; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return MODE_BAD; } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return rep.status; } -Bool -SDL_NAME(XF86VidModeSwitchMode)(dpy, screen, zoom) - Display* dpy; - int screen; - int zoom; +Bool SDL_NAME (XF86VidModeSwitchMode) (dpy, screen, zoom) + Display * + dpy; + int + screen; + int + zoom; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeSwitchModeReq *req; XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeSwitchMode, req); + LockDisplay (dpy); + GetReq (XF86VidModeSwitchMode, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeSwitchMode; req->screen = screen; req->zoom = zoom; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } - -Bool -SDL_NAME(XF86VidModeSwitchToMode)(dpy, screen, modeline) - Display* dpy; - int screen; - SDL_NAME(XF86VidModeModeInfo)* modeline; + +Bool SDL_NAME (XF86VidModeSwitchToMode) (dpy, screen, modeline) + Display * + dpy; + int + screen; +SDL_NAME (XF86VidModeModeInfo) * modeline; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeSwitchToModeReq *req; @@ -805,101 +831,105 @@ SDL_NAME(XF86VidModeSwitchToMode)(dpy, screen, modeline) * if appropriate. */ - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); if (majorVersion == 0 && minorVersion < 8) { - protocolBug = True; + protocolBug = True; #ifdef DEBUG - fprintf(stderr, "XF86VidModeSwitchToMode: Warning: Xserver is" - "running an old version (%d.%d)\n", majorVersion, - minorVersion); + fprintf (stderr, "XF86VidModeSwitchToMode: Warning: Xserver is" + "running an old version (%d.%d)\n", majorVersion, + minorVersion); #endif } - - LockDisplay(dpy); + + LockDisplay (dpy); if (majorVersion < 2) { - GetOldReq(XF86VidModeSwitchToMode, XF86OldVidModeSwitchToMode, oldreq); - oldreq->reqType = info->codes->major_opcode; - oldreq->xf86vidmodeReqType = X_XF86VidModeSwitchToMode; - oldreq->screen = screen; - oldreq->dotclock = modeline->dotclock; - oldreq->hdisplay = modeline->hdisplay; - oldreq->hsyncstart = modeline->hsyncstart; - oldreq->hsyncend = modeline->hsyncend; - oldreq->htotal = modeline->htotal; - oldreq->vdisplay = modeline->vdisplay; - oldreq->vsyncstart = modeline->vsyncstart; - oldreq->vsyncend = modeline->vsyncend; - oldreq->vtotal = modeline->vtotal; - oldreq->flags = modeline->flags; - if (protocolBug) { - oldreq->privsize = 0; - } else { - oldreq->privsize = modeline->privsize; - if (modeline->privsize) { - oldreq->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } - } + GetOldReq (XF86VidModeSwitchToMode, XF86OldVidModeSwitchToMode, + oldreq); + oldreq->reqType = info->codes->major_opcode; + oldreq->xf86vidmodeReqType = X_XF86VidModeSwitchToMode; + oldreq->screen = screen; + oldreq->dotclock = modeline->dotclock; + oldreq->hdisplay = modeline->hdisplay; + oldreq->hsyncstart = modeline->hsyncstart; + oldreq->hsyncend = modeline->hsyncend; + oldreq->htotal = modeline->htotal; + oldreq->vdisplay = modeline->vdisplay; + oldreq->vsyncstart = modeline->vsyncstart; + oldreq->vsyncend = modeline->vsyncend; + oldreq->vtotal = modeline->vtotal; + oldreq->flags = modeline->flags; + if (protocolBug) { + oldreq->privsize = 0; + } else { + oldreq->privsize = modeline->privsize; + if (modeline->privsize) { + oldreq->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } + } } else { - GetReq(XF86VidModeSwitchToMode, req); - req->reqType = info->codes->major_opcode; - req->xf86vidmodeReqType = X_XF86VidModeSwitchToMode; - req->screen = screen; - req->dotclock = modeline->dotclock; - req->hdisplay = modeline->hdisplay; - req->hsyncstart = modeline->hsyncstart; - req->hsyncend = modeline->hsyncend; - req->htotal = modeline->htotal; - req->hskew = modeline->hskew; - req->vdisplay = modeline->vdisplay; - req->vsyncstart = modeline->vsyncstart; - req->vsyncend = modeline->vsyncend; - req->vtotal = modeline->vtotal; - req->flags = modeline->flags; - if (protocolBug) { - req->privsize = 0; - } else { - req->privsize = modeline->privsize; - if (modeline->privsize) { - req->length += modeline->privsize; - Data32(dpy, (long *) modeline->private, - modeline->privsize * sizeof(INT32)); - } - } + GetReq (XF86VidModeSwitchToMode, req); + req->reqType = info->codes->major_opcode; + req->xf86vidmodeReqType = X_XF86VidModeSwitchToMode; + req->screen = screen; + req->dotclock = modeline->dotclock; + req->hdisplay = modeline->hdisplay; + req->hsyncstart = modeline->hsyncstart; + req->hsyncend = modeline->hsyncend; + req->htotal = modeline->htotal; + req->hskew = modeline->hskew; + req->vdisplay = modeline->vdisplay; + req->vsyncstart = modeline->vsyncstart; + req->vsyncend = modeline->vsyncend; + req->vtotal = modeline->vtotal; + req->flags = modeline->flags; + if (protocolBug) { + req->privsize = 0; + } else { + req->privsize = modeline->privsize; + if (modeline->privsize) { + req->length += modeline->privsize; + Data32 (dpy, (long *) modeline->private, + modeline->privsize * sizeof (INT32)); + } + } } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } - -Bool -SDL_NAME(XF86VidModeLockModeSwitch)(dpy, screen, lock) - Display* dpy; - int screen; - int lock; + +Bool SDL_NAME (XF86VidModeLockModeSwitch) (dpy, screen, lock) + Display * + dpy; + int + screen; + int + lock; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeLockModeSwitchReq *req; XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeLockModeSwitch, req); + LockDisplay (dpy); + GetReq (XF86VidModeLockModeSwitch, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeLockModeSwitch; req->screen = screen; req->lock = lock; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } - -Bool -SDL_NAME(XF86VidModeGetMonitor)(dpy, screen, monitor) - Display* dpy; - int screen; - SDL_NAME(XF86VidModeMonitor)* monitor; + +Bool SDL_NAME (XF86VidModeGetMonitor) (dpy, screen, monitor) + Display * + dpy; + int + screen; +SDL_NAME (XF86VidModeMonitor) * monitor; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetMonitorReply rep; @@ -909,98 +939,109 @@ SDL_NAME(XF86VidModeGetMonitor)(dpy, screen, monitor) XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeGetMonitor, req); + LockDisplay (dpy); + GetReq (XF86VidModeGetMonitor, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetMonitor; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; } monitor->nhsync = rep.nhsync; monitor->nvsync = rep.nvsync; #if 0 - monitor->bandwidth = (float)rep.bandwidth / 1e6; + monitor->bandwidth = (float) rep.bandwidth / 1e6; #endif if (rep.vendorLength) { - if (!(monitor->vendor = (char *)Xcalloc(rep.vendorLength + 1, 1))) { - _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 + - ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3)); - UnlockDisplay(dpy); - SyncHandle(); - return False; - } + if (!(monitor->vendor = (char *) Xcalloc (rep.vendorLength + 1, 1))) { + _XEatData (dpy, (rep.nhsync + rep.nvsync) * 4 + + ((rep.vendorLength + 3) & ~3) + + ((rep.modelLength + 3) & ~3)); + UnlockDisplay (dpy); + SyncHandle (); + return False; + } } else { - monitor->vendor = NULL; + monitor->vendor = NULL; } if (rep.modelLength) { - if (!(monitor->model = Xcalloc(rep.modelLength + 1, 1))) { - _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 + - ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3)); - if (monitor->vendor) - Xfree(monitor->vendor); - UnlockDisplay(dpy); - SyncHandle(); - return False; - } + if (!(monitor->model = Xcalloc (rep.modelLength + 1, 1))) { + _XEatData (dpy, (rep.nhsync + rep.nvsync) * 4 + + ((rep.vendorLength + 3) & ~3) + + ((rep.modelLength + 3) & ~3)); + if (monitor->vendor) + Xfree (monitor->vendor); + UnlockDisplay (dpy); + SyncHandle (); + return False; + } } else { - monitor->model = NULL; + monitor->model = NULL; } - if (!(monitor->hsync = Xcalloc(rep.nhsync, sizeof(SDL_NAME(XF86VidModeSyncRange))))) { - _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 + - ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3)); - - if (monitor->vendor) - Xfree(monitor->vendor); - if (monitor->model) - Xfree(monitor->model); - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (! + (monitor->hsync = + Xcalloc (rep.nhsync, sizeof (SDL_NAME (XF86VidModeSyncRange))))) { + _XEatData (dpy, (rep.nhsync + rep.nvsync) * 4 + + ((rep.vendorLength + 3) & ~3) + + ((rep.modelLength + 3) & ~3)); + + if (monitor->vendor) + Xfree (monitor->vendor); + if (monitor->model) + Xfree (monitor->model); + UnlockDisplay (dpy); + SyncHandle (); + return False; } - if (!(monitor->vsync = Xcalloc(rep.nvsync, sizeof(SDL_NAME(XF86VidModeSyncRange))))) { - _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 + - ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3)); - if (monitor->vendor) - Xfree(monitor->vendor); - if (monitor->model) - Xfree(monitor->model); - Xfree(monitor->hsync); - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (! + (monitor->vsync = + Xcalloc (rep.nvsync, sizeof (SDL_NAME (XF86VidModeSyncRange))))) { + _XEatData (dpy, (rep.nhsync + rep.nvsync) * 4 + + ((rep.vendorLength + 3) & ~3) + + ((rep.modelLength + 3) & ~3)); + if (monitor->vendor) + Xfree (monitor->vendor); + if (monitor->model) + Xfree (monitor->model); + Xfree (monitor->hsync); + UnlockDisplay (dpy); + SyncHandle (); + return False; } for (i = 0; i < rep.nhsync; i++) { - _XRead(dpy, (char *)&syncrange, 4); - monitor->hsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0; - monitor->hsync[i].hi = (float)(syncrange >> 16) / 100.0; + _XRead (dpy, (char *) &syncrange, 4); + monitor->hsync[i].lo = (float) (syncrange & 0xFFFF) / 100.0; + monitor->hsync[i].hi = (float) (syncrange >> 16) / 100.0; } for (i = 0; i < rep.nvsync; i++) { - _XRead(dpy, (char *)&syncrange, 4); - monitor->vsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0; - monitor->vsync[i].hi = (float)(syncrange >> 16) / 100.0; + _XRead (dpy, (char *) &syncrange, 4); + monitor->vsync[i].lo = (float) (syncrange & 0xFFFF) / 100.0; + monitor->vsync[i].hi = (float) (syncrange >> 16) / 100.0; } if (rep.vendorLength) - _XReadPad(dpy, monitor->vendor, rep.vendorLength); + _XReadPad (dpy, monitor->vendor, rep.vendorLength); else - monitor->vendor = ""; + monitor->vendor = ""; if (rep.modelLength) - _XReadPad(dpy, monitor->model, rep.modelLength); + _XReadPad (dpy, monitor->model, rep.modelLength); else - monitor->model = ""; - - UnlockDisplay(dpy); - SyncHandle(); + monitor->model = ""; + + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool -SDL_NAME(XF86VidModeGetViewPort)(dpy, screen, x, y) - Display* dpy; - int screen; - int *x, *y; +Bool SDL_NAME (XF86VidModeGetViewPort) (dpy, screen, x, y) + Display * + dpy; + int + screen; + int * + x, * + y; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetViewPortReply rep; @@ -1017,68 +1058,72 @@ SDL_NAME(XF86VidModeGetViewPort)(dpy, screen, x, y) * versions. */ - SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); + SDL_NAME (XF86VidModeQueryVersion) (dpy, &majorVersion, &minorVersion); if (majorVersion == 0 && minorVersion < 8) { - protocolBug = True; + protocolBug = True; #ifdef DEBUG - fprintf(stderr, "XF86VidModeGetViewPort: Warning: Xserver is" - "running an old version (%d.%d)\n", majorVersion, - minorVersion); + fprintf (stderr, "XF86VidModeGetViewPort: Warning: Xserver is" + "running an old version (%d.%d)\n", majorVersion, + minorVersion); #endif } - LockDisplay(dpy); - GetReq(XF86VidModeGetViewPort, req); + LockDisplay (dpy); + GetReq (XF86VidModeGetViewPort, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetViewPort; req->screen = screen; if (protocolBug) { - *x = 0; - *y = 0; + *x = 0; + *y = 0; } else { - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - *x = rep.x; - *y = rep.y; + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + *x = rep.x; + *y = rep.y; } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool -SDL_NAME(XF86VidModeSetViewPort)(dpy, screen, x, y) - Display* dpy; - int screen; - int x, y; +Bool SDL_NAME (XF86VidModeSetViewPort) (dpy, screen, x, y) + Display * + dpy; + int + screen; + int + x, + y; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeSetViewPortReq *req; XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeSetViewPort, req); + LockDisplay (dpy); + GetReq (XF86VidModeSetViewPort, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeSetViewPort; req->screen = screen; req->x = x; req->y = y; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } Bool -SDL_NAME(XF86VidModeGetDotClocks)(dpy, screen, - flagsPtr, numclocksPtr, maxclocksPtr, clocksPtr) - Display* dpy; - int screen; - int *flagsPtr, *numclocksPtr, *maxclocksPtr, *clocksPtr[]; +SDL_NAME (XF86VidModeGetDotClocks) (dpy, screen, + flagsPtr, numclocksPtr, maxclocksPtr, + clocksPtr) + Display *dpy; + int screen; + int *flagsPtr, *numclocksPtr, *maxclocksPtr, *clocksPtr[]; { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetDotClocksReply rep; @@ -1088,136 +1133,130 @@ SDL_NAME(XF86VidModeGetDotClocks)(dpy, screen, XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeGetDotClocks, req); + LockDisplay (dpy); + GetReq (XF86VidModeGetDotClocks, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetDotClocks; req->screen = screen; - if (!_XReply(dpy, (xReply *)&rep, - (SIZEOF(xXF86VidModeGetDotClocksReply) - SIZEOF(xReply)) >> 2, xFalse)) - { - UnlockDisplay(dpy); - SyncHandle(); + if (!_XReply (dpy, (xReply *) & rep, + (SIZEOF (xXF86VidModeGetDotClocksReply) - + SIZEOF (xReply)) >> 2, xFalse)) { + UnlockDisplay (dpy); + SyncHandle (); return False; } *numclocksPtr = rep.clocks; *maxclocksPtr = rep.maxclocks; - *flagsPtr = rep.flags; + *flagsPtr = rep.flags; - if (!(dotclocks = (int*) Xcalloc(rep.clocks, sizeof(int)))) { - _XEatData(dpy, (rep.clocks) * 4); - Xfree(dotclocks); - UnlockDisplay(dpy); - SyncHandle(); + if (!(dotclocks = (int *) Xcalloc (rep.clocks, sizeof (int)))) { + _XEatData (dpy, (rep.clocks) * 4); + Xfree (dotclocks); + UnlockDisplay (dpy); + SyncHandle (); return False; } for (i = 0; i < rep.clocks; i++) { - _XRead(dpy, (char*)&dotclk, 4); - dotclocks[i] = dotclk; + _XRead (dpy, (char *) &dotclk, 4); + dotclocks[i] = dotclk; } *clocksPtr = dotclocks; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } Bool -SDL_NAME(XF86VidModeSetGammaRamp) ( - Display *dpy, - int screen, - int size, - unsigned short *red, - unsigned short *green, - unsigned short *blue -) +SDL_NAME (XF86VidModeSetGammaRamp) (Display * dpy, + int screen, + int size, + unsigned short *red, + unsigned short *green, + unsigned short *blue) { int length = (size + 1) & ~1; XExtDisplayInfo *info = find_display (dpy); xXF86VidModeSetGammaRampReq *req; XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeSetGammaRamp, req); + LockDisplay (dpy); + GetReq (XF86VidModeSetGammaRamp, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeSetGammaRamp; req->screen = screen; req->length += (length >> 1) * 3; req->size = size; - _XSend(dpy, (char*)red, size * 2); - _XSend(dpy, (char*)green, size * 2); - _XSend(dpy, (char*)blue, size * 2); - UnlockDisplay(dpy); - SyncHandle(); + _XSend (dpy, (char *) red, size * 2); + _XSend (dpy, (char *) green, size * 2); + _XSend (dpy, (char *) blue, size * 2); + UnlockDisplay (dpy); + SyncHandle (); return True; } Bool -SDL_NAME(XF86VidModeGetGammaRamp) ( - Display *dpy, - int screen, - int size, - unsigned short *red, - unsigned short *green, - unsigned short *blue -) +SDL_NAME (XF86VidModeGetGammaRamp) (Display * dpy, + int screen, + int size, + unsigned short *red, + unsigned short *green, + unsigned short *blue) { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetGammaRampReq *req; xXF86VidModeGetGammaRampReply rep; - + XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeGetGammaRamp, req); + LockDisplay (dpy); + GetReq (XF86VidModeGetGammaRamp, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetGammaRamp; req->screen = screen; req->size = size; - if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { + if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay (dpy); SyncHandle (); return False; } - if(rep.size) { - _XRead(dpy, (char*)red, rep.size << 1); - _XRead(dpy, (char*)green, rep.size << 1); - _XRead(dpy, (char*)blue, rep.size << 1); + if (rep.size) { + _XRead (dpy, (char *) red, rep.size << 1); + _XRead (dpy, (char *) green, rep.size << 1); + _XRead (dpy, (char *) blue, rep.size << 1); } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } -Bool SDL_NAME(XF86VidModeGetGammaRampSize)( - Display *dpy, - int screen, - int *size -) +Bool SDL_NAME (XF86VidModeGetGammaRampSize) (Display * dpy, + int screen, int *size) { XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetGammaRampSizeReq *req; xXF86VidModeGetGammaRampSizeReply rep; - + *size = 0; XF86VidModeCheckExtension (dpy, info, False); - LockDisplay(dpy); - GetReq(XF86VidModeGetGammaRampSize, req); + LockDisplay (dpy); + GetReq (XF86VidModeGetGammaRampSize, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetGammaRampSize; req->screen = screen; - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { + if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) { UnlockDisplay (dpy); SyncHandle (); - return False; + return False; } *size = rep.size; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay (dpy); + SyncHandle (); return True; } +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/Xext.h b/src/video/Xext/extensions/Xext.h index 9edf3194b..a663d7c28 100644 --- a/src/video/Xext/extensions/Xext.h +++ b/src/video/Xext/extensions/Xext.h @@ -29,22 +29,18 @@ in this Software without prior written authorization from The Open Group. #include _XFUNCPROTOBEGIN + typedef int (*XExtensionErrorHandler) (Display *, _Xconst char *, + _Xconst char *); -typedef int (*XExtensionErrorHandler)(Display *, _Xconst char *, - _Xconst char *); +extern XExtensionErrorHandler +XSetExtensionErrorHandler (XExtensionErrorHandler handler); -extern XExtensionErrorHandler XSetExtensionErrorHandler( - XExtensionErrorHandler handler -); - -extern int XMissingExtension( - Display* /* dpy */, - _Xconst char* /* ext_name */ -); +extern int XMissingExtension (Display * /* dpy */ , + _Xconst char * /* ext_name */ + ); _XFUNCPROTOEND - #define X_EXTENSION_UNKNOWN "unknown" #define X_EXTENSION_MISSING "missing" - #endif /* _XEXT_H_ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/Xinerama.h b/src/video/Xext/extensions/Xinerama.h index 54f2fe17d..38130c69e 100644 --- a/src/video/Xext/extensions/Xinerama.h +++ b/src/video/Xext/extensions/Xinerama.h @@ -5,27 +5,22 @@ #include "SDL_name.h" -typedef struct { - int screen_number; - short x_org; - short y_org; - short width; - short height; -} SDL_NAME(XineramaScreenInfo); +typedef struct +{ + int screen_number; + short x_org; + short y_org; + short width; + short height; +} SDL_NAME (XineramaScreenInfo); -Bool SDL_NAME(XineramaQueryExtension) ( - Display *dpy, - int *event_base, - int *error_base -); +Bool SDL_NAME (XineramaQueryExtension) (Display * dpy, + int *event_base, int *error_base); -Status SDL_NAME(XineramaQueryVersion)( - Display *dpy, - int *major, - int *minor -); +Status SDL_NAME (XineramaQueryVersion) (Display * dpy, + int *major, int *minor); -Bool SDL_NAME(XineramaIsActive)(Display *dpy); +Bool SDL_NAME (XineramaIsActive) (Display * dpy); /* @@ -36,11 +31,8 @@ Bool SDL_NAME(XineramaIsActive)(Display *dpy); Returned array should be freed with XFree(). */ -SDL_NAME(XineramaScreenInfo) * -SDL_NAME(XineramaQueryScreens)( - Display *dpy, - int *number -); +SDL_NAME (XineramaScreenInfo) * +SDL_NAME (XineramaQueryScreens) (Display * dpy, int *number); #endif /* _Xinerama_h */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/Xv.h b/src/video/Xext/extensions/Xv.h index a6a027195..ecbc7a3b6 100644 --- a/src/video/Xext/extensions/Xv.h +++ b/src/video/Xext/extensions/Xv.h @@ -126,4 +126,4 @@ typedef XID XvEncodingID; #define XvBadAlloc 5 #endif /* XV_H */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/Xvlib.h b/src/video/Xext/extensions/Xvlib.h index 0d0a55da4..493151a15 100644 --- a/src/video/Xext/extensions/Xvlib.h +++ b/src/video/Xext/extensions/Xvlib.h @@ -57,377 +57,399 @@ SOFTWARE. #include "Xv.h" #include "SDL_name.h" -typedef struct { - int numerator; - int denominator; -} SDL_NAME(XvRational); - -typedef struct { - int flags; /* XvGettable, XvSettable */ - int min_value; - int max_value; - char *name; -} SDL_NAME(XvAttribute); - -typedef struct { - XvEncodingID encoding_id; - char *name; - unsigned long width; - unsigned long height; - SDL_NAME(XvRational) rate; - unsigned long num_encodings; -} SDL_NAME(XvEncodingInfo); - -typedef struct { - char depth; - unsigned long visual_id; -} SDL_NAME(XvFormat); - -typedef struct { - XvPortID base_id; - unsigned long num_ports; - char type; - char *name; - unsigned long num_formats; - SDL_NAME(XvFormat) *formats; - unsigned long num_adaptors; -} SDL_NAME(XvAdaptorInfo); - -typedef struct { - int type; - unsigned long serial; /* # of last request processed by server */ - Bool send_event; /* true if this came from a SendEvent request */ - Display *display; /* Display the event was read from */ - Drawable drawable; /* drawable */ - unsigned long reason; /* what generated this event */ - XvPortID port_id; /* what port */ - Time time; /* milliseconds */ -} SDL_NAME(XvVideoNotifyEvent); - -typedef struct { - int type; - unsigned long serial; /* # of last request processed by server */ - Bool send_event; /* true if this came from a SendEvent request */ - Display *display; /* Display the event was read from */ - XvPortID port_id; /* what port */ - Time time; /* milliseconds */ - Atom attribute; /* atom that identifies attribute */ - long value; /* value of attribute */ -} SDL_NAME(XvPortNotifyEvent); - -typedef union { - int type; - SDL_NAME(XvVideoNotifyEvent) xvvideo; - SDL_NAME(XvPortNotifyEvent) xvport; - long pad[24]; -} SDL_NAME(XvEvent); - -typedef struct { - int id; /* Unique descriptor for the format */ - int type; /* XvRGB, XvYUV */ - int byte_order; /* LSBFirst, MSBFirst */ - char guid[16]; /* Globally Unique IDentifier */ - int bits_per_pixel; - int format; /* XvPacked, XvPlanar */ - int num_planes; - - /* for RGB formats only */ - int depth; - unsigned int red_mask; - unsigned int green_mask; - unsigned int blue_mask; - - /* for YUV formats only */ - unsigned int y_sample_bits; - unsigned int u_sample_bits; - unsigned int v_sample_bits; - unsigned int horz_y_period; - unsigned int horz_u_period; - unsigned int horz_v_period; - unsigned int vert_y_period; - unsigned int vert_u_period; - unsigned int vert_v_period; - char component_order[32]; /* eg. UYVY */ - int scanline_order; /* XvTopToBottom, XvBottomToTop */ -} SDL_NAME(XvImageFormatValues); - -typedef struct { - int id; - int width, height; - int data_size; /* bytes */ - int num_planes; - int *pitches; /* bytes */ - int *offsets; /* bytes */ - char *data; - XPointer obdata; -} SDL_NAME(XvImage); - -_XFUNCPROTOBEGIN - -extern int SDL_NAME(XvQueryExtension)( +typedef struct +{ + int numerator; + int denominator; +} SDL_NAME (XvRational); + +typedef struct +{ + int flags; /* XvGettable, XvSettable */ + int min_value; + int max_value; + char *name; +} SDL_NAME (XvAttribute); + +typedef struct +{ + XvEncodingID encoding_id; + char *name; + unsigned long width; + unsigned long height; + SDL_NAME (XvRational) rate; + unsigned long num_encodings; +} SDL_NAME (XvEncodingInfo); + +typedef struct +{ + char depth; + unsigned long visual_id; +} SDL_NAME (XvFormat); + +typedef struct +{ + XvPortID base_id; + unsigned long num_ports; + char type; + char *name; + unsigned long num_formats; + SDL_NAME (XvFormat) * formats; + unsigned long num_adaptors; +} SDL_NAME (XvAdaptorInfo); + +typedef struct +{ + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came from a SendEvent request */ + Display *display; /* Display the event was read from */ + Drawable drawable; /* drawable */ + unsigned long reason; /* what generated this event */ + XvPortID port_id; /* what port */ + Time time; /* milliseconds */ +} SDL_NAME (XvVideoNotifyEvent); + +typedef struct +{ + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came from a SendEvent request */ + Display *display; /* Display the event was read from */ + XvPortID port_id; /* what port */ + Time time; /* milliseconds */ + Atom attribute; /* atom that identifies attribute */ + long value; /* value of attribute */ +} SDL_NAME (XvPortNotifyEvent); + +typedef union +{ + int type; + SDL_NAME (XvVideoNotifyEvent) xvvideo; + SDL_NAME (XvPortNotifyEvent) xvport; + long pad[24]; +} SDL_NAME (XvEvent); + +typedef struct +{ + int id; /* Unique descriptor for the format */ + int type; /* XvRGB, XvYUV */ + int byte_order; /* LSBFirst, MSBFirst */ + char guid[16]; /* Globally Unique IDentifier */ + int bits_per_pixel; + int format; /* XvPacked, XvPlanar */ + int num_planes; + + /* for RGB formats only */ + int depth; + unsigned int red_mask; + unsigned int green_mask; + unsigned int blue_mask; + + /* for YUV formats only */ + unsigned int y_sample_bits; + unsigned int u_sample_bits; + unsigned int v_sample_bits; + unsigned int horz_y_period; + unsigned int horz_u_period; + unsigned int horz_v_period; + unsigned int vert_y_period; + unsigned int vert_u_period; + unsigned int vert_v_period; + char component_order[32]; /* eg. UYVY */ + int scanline_order; /* XvTopToBottom, XvBottomToTop */ +} SDL_NAME (XvImageFormatValues); + +typedef struct +{ + int id; + int width, height; + int data_size; /* bytes */ + int num_planes; + int *pitches; /* bytes */ + int *offsets; /* bytes */ + char *data; + XPointer obdata; +} SDL_NAME (XvImage); + +_XFUNCPROTOBEGIN extern int SDL_NAME (XvQueryExtension) ( #if NeedFunctionPrototypes - Display* /* display */, - unsigned int* /* p_version */, - unsigned int* /* p_revision */, - unsigned int* /* p_requestBase */, - unsigned int* /* p_eventBase */, - unsigned int* /* p_errorBase */ + Display * + /* display */ , + unsigned int * + /* p_version */ , + unsigned int * + /* p_revision */ , + unsigned int * + /* p_requestBase */ + , unsigned int * + /* p_eventBase */ + , unsigned int * /* p_errorBase */ #endif -); + ); -extern int SDL_NAME(XvQueryAdaptors)( +extern int SDL_NAME (XvQueryAdaptors) ( #if NeedFunctionPrototypes - Display* /* display */, - Window /* window */, - unsigned int* /* p_nAdaptors */, - SDL_NAME(XvAdaptorInfo)** /* p_pAdaptors */ + Display * /* display */ , + Window /* window */ , + unsigned int * /* p_nAdaptors */ , + SDL_NAME (XvAdaptorInfo) ** /* p_pAdaptors */ #endif -); + ); -extern int SDL_NAME(XvQueryEncodings)( +extern int SDL_NAME (XvQueryEncodings) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - unsigned int* /* p_nEncoding */, - SDL_NAME(XvEncodingInfo)** /* p_pEncoding */ + Display * /* display */ , + XvPortID /* port */ , + unsigned int * /* p_nEncoding */ , + SDL_NAME (XvEncodingInfo) ** /* p_pEncoding */ #endif -); + ); -extern int SDL_NAME(XvPutVideo)( +extern int SDL_NAME (XvPutVideo) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Drawable /* d */, - GC /* gc */, - int /* vx */, - int /* vy */, - unsigned int /* vw */, - unsigned int /* vh */, - int /* dx */, - int /* dy */, - unsigned int /* dw */, - unsigned int /* dh */ + Display * /* display */ , + XvPortID /* port */ , + Drawable /* d */ , + GC /* gc */ , + int /* vx */ , + int /* vy */ , + unsigned int /* vw */ , + unsigned int /* vh */ , + int /* dx */ , + int /* dy */ , + unsigned int /* dw */ , + unsigned int /* dh */ #endif -); + ); -extern int SDL_NAME(XvPutStill)( +extern int SDL_NAME (XvPutStill) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Drawable /* d */, - GC /* gc */, - int /* vx */, - int /* vy */, - unsigned int /* vw */, - unsigned int /* vh */, - int /* dx */, - int /* dy */, - unsigned int /* dw */, - unsigned int /* dh */ + Display * /* display */ , + XvPortID /* port */ , + Drawable /* d */ , + GC /* gc */ , + int /* vx */ , + int /* vy */ , + unsigned int /* vw */ , + unsigned int /* vh */ , + int /* dx */ , + int /* dy */ , + unsigned int /* dw */ , + unsigned int /* dh */ #endif -); + ); -extern int SDL_NAME(XvGetVideo)( +extern int SDL_NAME (XvGetVideo) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Drawable /* d */, - GC /* gc */, - int /* vx */, - int /* vy */, - unsigned int /* vw */, - unsigned int /* vh */, - int /* dx */, - int /* dy */, - unsigned int /* dw */, - unsigned int /* dh */ + Display * /* display */ , + XvPortID /* port */ , + Drawable /* d */ , + GC /* gc */ , + int /* vx */ , + int /* vy */ , + unsigned int /* vw */ , + unsigned int /* vh */ , + int /* dx */ , + int /* dy */ , + unsigned int /* dw */ , + unsigned int /* dh */ #endif -); + ); -extern int SDL_NAME(XvGetStill)( +extern int SDL_NAME (XvGetStill) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Drawable /* d */, - GC /* gc */, - int /* vx */, - int /* vy */, - unsigned int /* vw */, - unsigned int /* vh */, - int /* dx */, - int /* dy */, - unsigned int /* dw */, - unsigned int /* dh */ + Display * /* display */ , + XvPortID /* port */ , + Drawable /* d */ , + GC /* gc */ , + int /* vx */ , + int /* vy */ , + unsigned int /* vw */ , + unsigned int /* vh */ , + int /* dx */ , + int /* dy */ , + unsigned int /* dw */ , + unsigned int /* dh */ #endif -); + ); -extern int SDL_NAME(XvStopVideo)( +extern int SDL_NAME (XvStopVideo) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Drawable /* drawable */ + Display * /* display */ , + XvPortID /* port */ , + Drawable /* drawable */ #endif -); + ); -extern int SDL_NAME(XvGrabPort)( +extern int SDL_NAME (XvGrabPort) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Time /* time */ + Display * /* display */ , + XvPortID /* port */ , + Time /* time */ #endif -); + ); -extern int SDL_NAME(XvUngrabPort)( +extern int SDL_NAME (XvUngrabPort) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Time /* time */ + Display * /* display */ , + XvPortID /* port */ , + Time /* time */ #endif -); + ); -extern int SDL_NAME(XvSelectVideoNotify)( +extern int SDL_NAME (XvSelectVideoNotify) ( #if NeedFunctionPrototypes - Display* /* display */, - Drawable /* drawable */, - Bool /* onoff */ + Display * /* display */ , + Drawable /* drawable */ , + Bool /* onoff */ #endif -); + ); -extern int SDL_NAME(XvSelectPortNotify)( +extern int SDL_NAME (XvSelectPortNotify) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Bool /* onoff */ + Display * /* display */ , + XvPortID /* port */ , + Bool /* onoff */ #endif -); + ); -extern int SDL_NAME(XvSetPortAttribute)( +extern int SDL_NAME (XvSetPortAttribute) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Atom /* attribute */, - int /* value */ + Display * /* display */ , + XvPortID /* port */ , + Atom /* attribute */ , + int /* value */ #endif -); + ); -extern int SDL_NAME(XvGetPortAttribute)( +extern int SDL_NAME (XvGetPortAttribute) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Atom /* attribute */, - int* /* p_value */ + Display * /* display */ , + XvPortID /* port */ , + Atom /* attribute */ , + int * /* p_value */ #endif -); + ); -extern int SDL_NAME(XvQueryBestSize)( +extern int SDL_NAME (XvQueryBestSize) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - Bool /* motion */, - unsigned int /* vid_w */, - unsigned int /* vid_h */, - unsigned int /* drw_w */, - unsigned int /* drw_h */, - unsigned int* /* p_actual_width */, - unsigned int* /* p_actual_width */ + Display * /* display */ , + XvPortID /* port */ , + Bool /* motion */ , + unsigned int /* vid_w */ , + unsigned int /* vid_h */ , + unsigned int /* drw_w */ , + unsigned int /* drw_h */ , + unsigned int * /* p_actual_width */ + , unsigned int * /* p_actual_width */ #endif -); + ); -extern SDL_NAME(XvAttribute)* SDL_NAME(XvQueryPortAttributes)( +extern +SDL_NAME (XvAttribute) * +SDL_NAME (XvQueryPortAttributes) ( #if NeedFunctionPrototypes - Display* /* display */, - XvPortID /* port */, - int* /* number */ + Display * /* display */ , + XvPortID /* port */ , + int * /* number */ #endif -); + ); -extern void SDL_NAME(XvFreeAdaptorInfo)( + extern void SDL_NAME (XvFreeAdaptorInfo) ( #if NeedFunctionPrototypes - SDL_NAME(XvAdaptorInfo)* /* adaptors */ + SDL_NAME (XvAdaptorInfo) * /* adaptors */ #endif -); + ); -extern void SDL_NAME(XvFreeEncodingInfo)( + extern void SDL_NAME (XvFreeEncodingInfo) ( #if NeedFunctionPrototypes - SDL_NAME(XvEncodingInfo)* /* encodings */ + SDL_NAME (XvEncodingInfo) * /* encodings */ #endif -); + ); -extern SDL_NAME(XvImageFormatValues) * SDL_NAME(XvListImageFormats) ( + extern SDL_NAME (XvImageFormatValues) * SDL_NAME (XvListImageFormats) ( #if NeedFunctionPrototypes - Display *display, - XvPortID port_id, - int *count_return + Display + * + display, + XvPortID + port_id, + int + *count_return #endif -); + ); -extern SDL_NAME(XvImage) * SDL_NAME(XvCreateImage) ( + extern SDL_NAME (XvImage) * SDL_NAME (XvCreateImage) ( #if NeedFunctionPrototypes - Display *display, - XvPortID port, - int id, - char *data, - int width, - int height + Display * + display, + XvPortID port, + int id, + char *data, + int width, + int height #endif -); + ); -extern int SDL_NAME(XvPutImage) ( + extern int SDL_NAME (XvPutImage) ( #if NeedFunctionPrototypes - Display *display, - XvPortID id, - Drawable d, - GC gc, - SDL_NAME(XvImage) *image, - int src_x, - int src_y, - unsigned int src_w, - unsigned int src_h, - int dest_x, - int dest_y, - unsigned int dest_w, - unsigned int dest_h + Display * display, + XvPortID id, + Drawable d, + GC gc, + SDL_NAME (XvImage) * image, + int src_x, + int src_y, + unsigned int src_w, + unsigned int src_h, + int dest_x, + int dest_y, + unsigned int dest_w, + unsigned int dest_h #endif -); + ); -extern int SDL_NAME(XvShmPutImage) ( + extern int SDL_NAME (XvShmPutImage) ( #if NeedFunctionPrototypes - Display *display, - XvPortID id, - Drawable d, - GC gc, - SDL_NAME(XvImage) *image, - int src_x, - int src_y, - unsigned int src_w, - unsigned int src_h, - int dest_x, - int dest_y, - unsigned int dest_w, - unsigned int dest_h, - Bool send_event + Display * display, + XvPortID id, + Drawable d, + GC gc, + SDL_NAME (XvImage) * image, + int src_x, + int src_y, + unsigned int src_w, + unsigned int src_h, + int dest_x, + int dest_y, + unsigned int dest_w, + unsigned int dest_h, + Bool send_event #endif -); + ); #ifdef _XSHM_H_ -extern SDL_NAME(XvImage) * SDL_NAME(XvShmCreateImage) ( + extern SDL_NAME (XvImage) * SDL_NAME (XvShmCreateImage) ( #if NeedFunctionPrototypes - Display *display, - XvPortID port, - int id, - char* data, - int width, - int height, - XShmSegmentInfo *shminfo + Display * + display, + XvPortID + port, int id, + char *data, + int width, + int height, + XShmSegmentInfo + * shminfo #endif -); + ); #endif _XFUNCPROTOEND - #endif /* XVLIB_H */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/Xvproto.h b/src/video/Xext/extensions/Xvproto.h index b4d8f22cd..985aa8535 100644 --- a/src/video/Xext/extensions/Xvproto.h +++ b/src/video/Xext/extensions/Xvproto.h @@ -65,80 +65,86 @@ SOFTWARE. /* Structures */ -typedef struct { - INT32 numerator B32; - INT32 denominator B32; +typedef struct +{ + INT32 numerator B32; + INT32 denominator B32; } xvRational; #define sz_xvRational 8 -typedef struct { - XvPortID base_id B32; - CARD16 name_size B16; - CARD16 num_ports B16; - CARD16 num_formats B16; - CARD8 type; - CARD8 pad; +typedef struct +{ + XvPortID base_id B32; + CARD16 name_size B16; + CARD16 num_ports B16; + CARD16 num_formats B16; + CARD8 type; + CARD8 pad; } xvAdaptorInfo; #define sz_xvAdaptorInfo 12 -typedef struct { - XvEncodingID encoding B32; - CARD16 name_size B16; - CARD16 width B16, height B16; - xvRational rate; - CARD16 pad B16; +typedef struct +{ + XvEncodingID encoding B32; + CARD16 name_size B16; + CARD16 width B16, height B16; + xvRational rate; + CARD16 pad B16; } xvEncodingInfo; #define sz_xvEncodingInfo (12 + sz_xvRational) -typedef struct { - VisualID visual B32; - CARD8 depth; - CARD8 pad1; - CARD16 pad2 B16; +typedef struct +{ + VisualID visual B32; + CARD8 depth; + CARD8 pad1; + CARD16 pad2 B16; } xvFormat; #define sz_xvFormat 8 -typedef struct { - CARD32 flags B32; - INT32 min B32; - INT32 max B32; - CARD32 size B32; +typedef struct +{ + CARD32 flags B32; + INT32 min B32; + INT32 max B32; + CARD32 size B32; } xvAttributeInfo; #define sz_xvAttributeInfo 16 -typedef struct { - CARD32 id B32; - CARD8 type; - CARD8 byte_order; - CARD16 pad1 B16; - CARD8 guid[16]; - CARD8 bpp; - CARD8 num_planes; - CARD16 pad2 B16; - CARD8 depth; - CARD8 pad3; - CARD16 pad4 B16; - CARD32 red_mask B32; - CARD32 green_mask B32; - CARD32 blue_mask B32; - CARD8 format; - CARD8 pad5; - CARD16 pad6 B16; - CARD32 y_sample_bits B32; - CARD32 u_sample_bits B32; - CARD32 v_sample_bits B32; - CARD32 horz_y_period B32; - CARD32 horz_u_period B32; - CARD32 horz_v_period B32; - CARD32 vert_y_period B32; - CARD32 vert_u_period B32; - CARD32 vert_v_period B32; - CARD8 comp_order[32]; - CARD8 scanline_order; - CARD8 pad7; - CARD16 pad8 B16; - CARD32 pad9 B32; - CARD32 pad10 B32; +typedef struct +{ + CARD32 id B32; + CARD8 type; + CARD8 byte_order; + CARD16 pad1 B16; + CARD8 guid[16]; + CARD8 bpp; + CARD8 num_planes; + CARD16 pad2 B16; + CARD8 depth; + CARD8 pad3; + CARD16 pad4 B16; + CARD32 red_mask B32; + CARD32 green_mask B32; + CARD32 blue_mask B32; + CARD8 format; + CARD8 pad5; + CARD16 pad6 B16; + CARD32 y_sample_bits B32; + CARD32 u_sample_bits B32; + CARD32 v_sample_bits B32; + CARD32 horz_y_period B32; + CARD32 horz_u_period B32; + CARD32 horz_v_period B32; + CARD32 vert_y_period B32; + CARD32 vert_u_period B32; + CARD32 vert_v_period B32; + CARD8 comp_order[32]; + CARD8 scanline_order; + CARD8 pad7; + CARD16 pad8 B16; + CARD32 pad9 B32; + CARD32 pad10 B32; } xvImageFormatInfo; #define sz_xvImageFormatInfo 128 @@ -169,426 +175,460 @@ typedef struct { #define xvNumRequests (xv_LastRequest + 1) -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; } xvQueryExtensionReq; #define sz_xvQueryExtensionReq 4 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - CARD32 window B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + CARD32 window B32; } xvQueryAdaptorsReq; #define sz_xvQueryAdaptorsReq 8 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - CARD32 port B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + CARD32 port B32; } xvQueryEncodingsReq; #define sz_xvQueryEncodingsReq 8 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Drawable drawable B32; - GContext gc B32; - INT16 vid_x B16; - INT16 vid_y B16; - CARD16 vid_w B16; - CARD16 vid_h B16; - INT16 drw_x B16; - INT16 drw_y B16; - CARD16 drw_w B16; - CARD16 drw_h B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Drawable drawable B32; + GContext gc B32; + INT16 vid_x B16; + INT16 vid_y B16; + CARD16 vid_w B16; + CARD16 vid_h B16; + INT16 drw_x B16; + INT16 drw_y B16; + CARD16 drw_w B16; + CARD16 drw_h B16; } xvPutVideoReq; #define sz_xvPutVideoReq 32 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Drawable drawable B32; - GContext gc B32; - INT16 vid_x B16; - INT16 vid_y B16; - CARD16 vid_w B16; - CARD16 vid_h B16; - INT16 drw_x B16; - INT16 drw_y B16; - CARD16 drw_w B16; - CARD16 drw_h B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Drawable drawable B32; + GContext gc B32; + INT16 vid_x B16; + INT16 vid_y B16; + CARD16 vid_w B16; + CARD16 vid_h B16; + INT16 drw_x B16; + INT16 drw_y B16; + CARD16 drw_w B16; + CARD16 drw_h B16; } xvPutStillReq; #define sz_xvPutStillReq 32 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Drawable drawable B32; - GContext gc B32; - INT16 vid_x B16; - INT16 vid_y B16; - CARD16 vid_w B16; - CARD16 vid_h B16; - INT16 drw_x B16; - INT16 drw_y B16; - CARD16 drw_w B16; - CARD16 drw_h B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Drawable drawable B32; + GContext gc B32; + INT16 vid_x B16; + INT16 vid_y B16; + CARD16 vid_w B16; + CARD16 vid_h B16; + INT16 drw_x B16; + INT16 drw_y B16; + CARD16 drw_w B16; + CARD16 drw_h B16; } xvGetVideoReq; #define sz_xvGetVideoReq 32 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Drawable drawable B32; - GContext gc B32; - INT16 vid_x B16; - INT16 vid_y B16; - CARD16 vid_w B16; - CARD16 vid_h B16; - INT16 drw_x B16; - INT16 drw_y B16; - CARD16 drw_w B16; - CARD16 drw_h B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Drawable drawable B32; + GContext gc B32; + INT16 vid_x B16; + INT16 vid_y B16; + CARD16 vid_w B16; + CARD16 vid_h B16; + INT16 drw_x B16; + INT16 drw_y B16; + CARD16 drw_w B16; + CARD16 drw_h B16; } xvGetStillReq; #define sz_xvGetStillReq 32 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Time time B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Time time B32; } xvGrabPortReq; #define sz_xvGrabPortReq 12 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Time time B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Time time B32; } xvUngrabPortReq; #define sz_xvUngrabPortReq 12 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - Drawable drawable B32; - BOOL onoff; - CARD8 pad1; - CARD16 pad2; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + Drawable drawable B32; + BOOL onoff; + CARD8 pad1; + CARD16 pad2; } xvSelectVideoNotifyReq; #define sz_xvSelectVideoNotifyReq 12 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - BOOL onoff; - CARD8 pad1; - CARD16 pad2; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + BOOL onoff; + CARD8 pad1; + CARD16 pad2; } xvSelectPortNotifyReq; #define sz_xvSelectPortNotifyReq 12 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Drawable drawable B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Drawable drawable B32; } xvStopVideoReq; #define sz_xvStopVideoReq 12 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Atom attribute B32; - INT32 value B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Atom attribute B32; + INT32 value B32; } xvSetPortAttributeReq; #define sz_xvSetPortAttributeReq 16 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Atom attribute B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Atom attribute B32; } xvGetPortAttributeReq; #define sz_xvGetPortAttributeReq 12 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - CARD16 vid_w B16; - CARD16 vid_h B16; - CARD16 drw_w B16; - CARD16 drw_h B16; - CARD8 motion; - CARD8 pad1; - CARD16 pad2 B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + CARD16 vid_w B16; + CARD16 vid_h B16; + CARD16 drw_w B16; + CARD16 drw_h B16; + CARD8 motion; + CARD8 pad1; + CARD16 pad2 B16; } xvQueryBestSizeReq; #define sz_xvQueryBestSizeReq 20 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; } xvQueryPortAttributesReq; #define sz_xvQueryPortAttributesReq 8 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Drawable drawable B32; - GContext gc B32; - CARD32 id B32; - INT16 src_x B16; - INT16 src_y B16; - CARD16 src_w B16; - CARD16 src_h B16; - INT16 drw_x B16; - INT16 drw_y B16; - CARD16 drw_w B16; - CARD16 drw_h B16; - CARD16 width B16; - CARD16 height B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Drawable drawable B32; + GContext gc B32; + CARD32 id B32; + INT16 src_x B16; + INT16 src_y B16; + CARD16 src_w B16; + CARD16 src_h B16; + INT16 drw_x B16; + INT16 drw_y B16; + CARD16 drw_w B16; + CARD16 drw_h B16; + CARD16 width B16; + CARD16 height B16; } xvPutImageReq; #define sz_xvPutImageReq 40 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; - Drawable drawable B32; - GContext gc B32; - ShmSeg shmseg B32; - CARD32 id B32; - CARD32 offset B32; - INT16 src_x B16; - INT16 src_y B16; - CARD16 src_w B16; - CARD16 src_h B16; - INT16 drw_x B16; - INT16 drw_y B16; - CARD16 drw_w B16; - CARD16 drw_h B16; - CARD16 width B16; - CARD16 height B16; - CARD8 send_event; - CARD8 pad1; - CARD16 pad2 B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; + Drawable drawable B32; + GContext gc B32; + ShmSeg shmseg B32; + CARD32 id B32; + CARD32 offset B32; + INT16 src_x B16; + INT16 src_y B16; + CARD16 src_w B16; + CARD16 src_h B16; + INT16 drw_x B16; + INT16 drw_y B16; + CARD16 drw_w B16; + CARD16 drw_h B16; + CARD16 width B16; + CARD16 height B16; + CARD8 send_event; + CARD8 pad1; + CARD16 pad2 B16; } xvShmPutImageReq; #define sz_xvShmPutImageReq 52 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - XvPortID port B32; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + XvPortID port B32; } xvListImageFormatsReq; #define sz_xvListImageFormatsReq 8 -typedef struct { - CARD8 reqType; - CARD8 xvReqType; - CARD16 length B16; - CARD32 port B32; - CARD32 id B32; - CARD16 width B16; - CARD16 height B16; +typedef struct +{ + CARD8 reqType; + CARD8 xvReqType; + CARD16 length B16; + CARD32 port B32; + CARD32 id B32; + CARD16 width B16; + CARD16 height B16; } xvQueryImageAttributesReq; #define sz_xvQueryImageAttributesReq 16 /* Replies */ -typedef struct _QueryExtensionReply { - BYTE type; /* X_Reply */ - CARD8 padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 version B16; - CARD16 revision B16; - CARD32 padl4 B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct _QueryExtensionReply +{ + BYTE type; /* X_Reply */ + CARD8 padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 version B16; + CARD16 revision B16; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvQueryExtensionReply; #define sz_xvQueryExtensionReply 32 -typedef struct _QueryAdaptorsReply { - BYTE type; /* X_Reply */ - CARD8 padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 num_adaptors B16; - CARD16 pads3 B16; - CARD32 padl4 B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct _QueryAdaptorsReply +{ + BYTE type; /* X_Reply */ + CARD8 padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 num_adaptors B16; + CARD16 pads3 B16; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvQueryAdaptorsReply; #define sz_xvQueryAdaptorsReply 32 -typedef struct _QueryEncodingsReply { - BYTE type; /* X_Reply */ - CARD8 padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 num_encodings B16; - CARD32 padl3 B32; - CARD32 padl4 B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct _QueryEncodingsReply +{ + BYTE type; /* X_Reply */ + CARD8 padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 num_encodings B16; + CARD32 padl3 B32; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvQueryEncodingsReply; #define sz_xvQueryEncodingsReply 32 -typedef struct { - BYTE type; /* X_Reply */ - BYTE result; - CARD16 sequenceNumber B16; - CARD32 length B32; /* 0 */ - CARD32 padl3 B32; - CARD32 padl4 B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BYTE result; + CARD16 sequenceNumber B16; + CARD32 length B32; /* 0 */ + CARD32 padl3 B32; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvGrabPortReply; #define sz_xvGrabPortReply 32 -typedef struct { - BYTE type; /* X_Reply */ - BYTE padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; /* 0 */ - INT32 value B32; - CARD32 padl4 B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BYTE padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; /* 0 */ + INT32 value B32; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvGetPortAttributeReply; #define sz_xvGetPortAttributeReply 32 -typedef struct { - BYTE type; /* X_Reply */ - BYTE padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; /* 0 */ - CARD16 actual_width B16; - CARD16 actual_height B16; - CARD32 padl4 B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BYTE padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; /* 0 */ + CARD16 actual_width B16; + CARD16 actual_height B16; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvQueryBestSizeReply; #define sz_xvQueryBestSizeReply 32 -typedef struct { - BYTE type; /* X_Reply */ - BYTE padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; /* 0 */ - CARD32 num_attributes B32; - CARD32 text_size B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BYTE padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; /* 0 */ + CARD32 num_attributes B32; + CARD32 text_size B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvQueryPortAttributesReply; #define sz_xvQueryPortAttributesReply 32 -typedef struct { - BYTE type; /* X_Reply */ - BYTE padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 num_formats B32; - CARD32 padl4 B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BYTE padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 num_formats B32; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvListImageFormatsReply; #define sz_xvListImageFormatsReply 32 -typedef struct { - BYTE type; /* X_Reply */ - BYTE padb1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 num_planes B32; - CARD32 data_size B32; - CARD16 width B16; - CARD16 height B16; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BYTE padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 num_planes B32; + CARD32 data_size B32; + CARD16 width B16; + CARD16 height B16; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; } xvQueryImageAttributesReply; #define sz_xvQueryImageAttributesReply 32 /* DEFINE EVENT STRUCTURE */ -typedef struct { - union { - struct { - BYTE type; - BYTE detail; - CARD16 sequenceNumber B16; +typedef struct +{ + union + { + struct + { + BYTE type; + BYTE detail; + CARD16 sequenceNumber B16; + } u; + struct + { + BYTE type; + BYTE reason; + CARD16 sequenceNumber B16; + Time time B32; + Drawable drawable B32; + XvPortID port B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; + } videoNotify; + struct + { + BYTE type; + BYTE padb1; + CARD16 sequenceNumber B16; + Time time B32; + XvPortID port B32; + Atom attribute B32; + INT32 value B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; + } portNotify; } u; - struct { - BYTE type; - BYTE reason; - CARD16 sequenceNumber B16; - Time time B32; - Drawable drawable B32; - XvPortID port B32; - CARD32 padl5 B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; - } videoNotify; - struct { - BYTE type; - BYTE padb1; - CARD16 sequenceNumber B16; - Time time B32; - XvPortID port B32; - Atom attribute B32; - INT32 value B32; - CARD32 padl6 B32; - CARD32 padl7 B32; - CARD32 padl8 B32; - } portNotify; - } u; } xvEvent; #undef XvPortID @@ -601,4 +641,4 @@ typedef struct { #undef Atom #endif /* XVPROTO_H */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/extutil.h b/src/video/Xext/extensions/extutil.h index f3a741ea2..04cc6c086 100644 --- a/src/video/Xext/extensions/extutil.h +++ b/src/video/Xext/extensions/extutil.h @@ -36,7 +36,7 @@ in this Software without prior written authorization from The Open Group. #ifndef _EXTUTIL_H_ #define _EXTUTIL_H_ -#include "SDL_stdinc.h" /* For portable string functions */ +#include "SDL_stdinc.h" /* For portable string functions */ #include "./Xext.h" @@ -45,133 +45,136 @@ in this Software without prior written authorization from The Open Group. * public. We also have to per-display info in a separate block since it isn't * stored directly in the Display structure. */ -typedef struct _XExtDisplayInfo { - struct _XExtDisplayInfo *next; /* keep a linked list */ - Display *display; /* which display this is */ - XExtCodes *codes; /* the extension protocol codes */ - XPointer data; /* extra data for extension to use */ +typedef struct _XExtDisplayInfo +{ + struct _XExtDisplayInfo *next; /* keep a linked list */ + Display *display; /* which display this is */ + XExtCodes *codes; /* the extension protocol codes */ + XPointer data; /* extra data for extension to use */ } XExtDisplayInfo; -typedef struct _XExtensionInfo { - XExtDisplayInfo *head; /* start of list */ - XExtDisplayInfo *cur; /* most recently used */ - int ndisplays; /* number of displays */ +typedef struct _XExtensionInfo +{ + XExtDisplayInfo *head; /* start of list */ + XExtDisplayInfo *cur; /* most recently used */ + int ndisplays; /* number of displays */ } XExtensionInfo; -typedef struct _XExtensionHooks { - int (*create_gc)( +typedef struct _XExtensionHooks +{ + int (*create_gc) ( #if NeedNestedPrototypes - Display* /* display */, - GC /* gc */, - XExtCodes* /* codes */ + Display * /* display */ , + GC /* gc */ , + XExtCodes * /* codes */ #endif -); - int (*copy_gc)( + ); + int (*copy_gc) ( #if NeedNestedPrototypes - Display* /* display */, - GC /* gc */, - XExtCodes* /* codes */ + Display * /* display */ , + GC /* gc */ , + XExtCodes * /* codes */ #endif -); - int (*flush_gc)( + ); + int (*flush_gc) ( #if NeedNestedPrototypes - Display* /* display */, - GC /* gc */, - XExtCodes* /* codes */ + Display * /* display */ , + GC /* gc */ , + XExtCodes * /* codes */ #endif -); - int (*free_gc)( + ); + int (*free_gc) ( #if NeedNestedPrototypes - Display* /* display */, - GC /* gc */, - XExtCodes* /* codes */ + Display * /* display */ , + GC /* gc */ , + XExtCodes * /* codes */ #endif -); - int (*create_font)( + ); + int (*create_font) ( #if NeedNestedPrototypes - Display* /* display */, - XFontStruct* /* fs */, - XExtCodes* /* codes */ + Display * /* display */ , + XFontStruct * /* fs */ , + XExtCodes * /* codes */ #endif -); - int (*free_font)( + ); + int (*free_font) ( #if NeedNestedPrototypes - Display* /* display */, - XFontStruct* /* fs */, - XExtCodes* /* codes */ + Display * /* display */ , + XFontStruct * /* fs */ , + XExtCodes * /* codes */ #endif -); - int (*close_display)( + ); + int (*close_display) ( #if NeedNestedPrototypes - Display* /* display */, - XExtCodes* /* codes */ + Display * /* display */ , + XExtCodes * /* codes */ #endif -); - Bool (*wire_to_event)( + ); + Bool (*wire_to_event) ( #if NeedNestedPrototypes - Display* /* display */, - XEvent* /* re */, - xEvent* /* event */ + Display * /* display */ , + XEvent * /* re */ , + xEvent * /* event */ #endif -); - Status (*event_to_wire)( + ); + Status (*event_to_wire) ( #if NeedNestedPrototypes - Display* /* display */, - XEvent* /* re */, - xEvent* /* event */ + Display * /* display */ , + XEvent * /* re */ , + xEvent * /* event */ #endif -); - int (*error)( + ); + int (*error) ( #if NeedNestedPrototypes - Display* /* display */, - xError* /* err */, - XExtCodes* /* codes */, - int* /* ret_code */ + Display * /* display */ , + xError * /* err */ , + XExtCodes * /* codes */ , + int * /* ret_code */ #endif -); - char *(*error_string)( + ); + char *(*error_string) ( #if NeedNestedPrototypes - Display* /* display */, - int /* code */, - XExtCodes* /* codes */, - char* /* buffer */, - int /* nbytes */ + Display * /* display */ , + int /* code */ , + XExtCodes * /* codes */ , + char * /* buffer */ , + int /* nbytes */ #endif -); + ); } XExtensionHooks; -extern XExtensionInfo *XextCreateExtension( +extern XExtensionInfo *XextCreateExtension ( #if NeedFunctionPrototypes - void + void #endif -); -extern void XextDestroyExtension( + ); +extern void XextDestroyExtension ( #if NeedFunctionPrototypes - XExtensionInfo* /* info */ + XExtensionInfo * /* info */ #endif -); -extern XExtDisplayInfo *XextAddDisplay( + ); +extern XExtDisplayInfo *XextAddDisplay ( #if NeedFunctionPrototypes - XExtensionInfo* /* extinfo */, - Display* /* dpy */, - char* /* ext_name */, - XExtensionHooks* /* hooks */, - int /* nevents */, - XPointer /* data */ -#endif -); -extern int XextRemoveDisplay( + XExtensionInfo * /* extinfo */ , + Display * /* dpy */ , + char * /* ext_name */ , + XExtensionHooks * /* hooks */ , + int /* nevents */ , + XPointer /* data */ +#endif + ); +extern int XextRemoveDisplay ( #if NeedFunctionPrototypes - XExtensionInfo* /* extinfo */, - Display* /* dpy */ + XExtensionInfo * /* extinfo */ , + Display * /* dpy */ #endif -); -extern XExtDisplayInfo *XextFindDisplay( + ); +extern XExtDisplayInfo *XextFindDisplay ( #if NeedFunctionPrototypes - XExtensionInfo* /* extinfo */, - Display* /* dpy */ + XExtensionInfo * /* extinfo */ , + Display * /* dpy */ #endif -); + ); #define XextHasExtension(i) ((i) && ((i)->codes)) #define XextCheckExtension(dpy,i,name,val) \ @@ -224,3 +227,4 @@ char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \ #define XEXT_ERROR_STRING_PROTO(proc) \ char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n) #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/panoramiXext.h b/src/video/Xext/extensions/panoramiXext.h index e89d8917b..45c69a014 100644 --- a/src/video/Xext/extensions/panoramiXext.h +++ b/src/video/Xext/extensions/panoramiXext.h @@ -35,18 +35,22 @@ Equipment Corporation. #define PANORAMIX_MAJOR_VERSION 1 /* current version number */ #define PANORAMIX_MINOR_VERSION 1 -typedef struct { - Window window; /* PanoramiX window - may not exist */ - int screen; - int State; /* PanroamiXOff, PanoramiXOn */ - int width; /* width of this screen */ - int height; /* height of this screen */ - int ScreenCount; /* real physical number of screens */ - XID eventMask; /* selected events for this client */ -} SDL_NAME(XPanoramiXInfo); - -extern SDL_NAME(XPanoramiXInfo) *SDL_NAME(XPanoramiXAllocInfo) ( +typedef struct +{ + Window window; /* PanoramiX window - may not exist */ + int screen; + int State; /* PanroamiXOff, PanoramiXOn */ + int width; /* width of this screen */ + int height; /* height of this screen */ + int ScreenCount; /* real physical number of screens */ + XID eventMask; /* selected events for this client */ +} SDL_NAME (XPanoramiXInfo); + +extern +SDL_NAME (XPanoramiXInfo) * +SDL_NAME (XPanoramiXAllocInfo) ( #if NeedFunctionPrototypes - void + void #endif -); + ); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/panoramiXproto.h b/src/video/Xext/extensions/panoramiXproto.h index fe3826eb3..69a0ce3f5 100644 --- a/src/video/Xext/extensions/panoramiXproto.h +++ b/src/video/Xext/extensions/panoramiXproto.h @@ -40,153 +40,167 @@ Equipment Corporation. #define X_XineramaIsActive 4 #define X_XineramaQueryScreens 5 -typedef struct _PanoramiXQueryVersion { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXQueryVersion */ - CARD16 length B16; - CARD8 clientMajor; - CARD8 clientMinor; - CARD16 unused B16; +typedef struct _PanoramiXQueryVersion +{ + CARD8 reqType; /* always PanoramiXReqCode */ + CARD8 panoramiXReqType; /* always X_PanoramiXQueryVersion */ + CARD16 length B16; + CARD8 clientMajor; + CARD8 clientMinor; + CARD16 unused B16; } xPanoramiXQueryVersionReq; #define sz_xPanoramiXQueryVersionReq 8 -typedef struct { - CARD8 type; /* must be X_Reply */ - CARD8 pad1; /* unused */ - CARD16 sequenceNumber B16; /* last sequence number */ - CARD32 length B32; /* 0 */ - CARD16 majorVersion B16; - CARD16 minorVersion B16; - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ - CARD32 pad4 B32; /* unused */ - CARD32 pad5 B32; /* unused */ - CARD32 pad6 B32; /* unused */ +typedef struct +{ + CARD8 type; /* must be X_Reply */ + CARD8 pad1; /* unused */ + CARD16 sequenceNumber B16; /* last sequence number */ + CARD32 length B32; /* 0 */ + CARD16 majorVersion B16; + CARD16 minorVersion B16; + CARD32 pad2 B32; /* unused */ + CARD32 pad3 B32; /* unused */ + CARD32 pad4 B32; /* unused */ + CARD32 pad5 B32; /* unused */ + CARD32 pad6 B32; /* unused */ } xPanoramiXQueryVersionReply; #define sz_xPanoramiXQueryVersionReply 32 -typedef struct _PanoramiXGetState { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXGetState */ - CARD16 length B16; - CARD32 window B32; +typedef struct _PanoramiXGetState +{ + CARD8 reqType; /* always PanoramiXReqCode */ + CARD8 panoramiXReqType; /* always X_PanoramiXGetState */ + CARD16 length B16; + CARD32 window B32; } xPanoramiXGetStateReq; -#define sz_xPanoramiXGetStateReq 8 - -typedef struct { - BYTE type; - BYTE state; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 window B32; - CARD32 pad1 B32; /* unused */ - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ - CARD32 pad4 B32; /* unused */ - CARD32 pad5 B32; /* unused */ +#define sz_xPanoramiXGetStateReq 8 + +typedef struct +{ + BYTE type; + BYTE state; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 window B32; + CARD32 pad1 B32; /* unused */ + CARD32 pad2 B32; /* unused */ + CARD32 pad3 B32; /* unused */ + CARD32 pad4 B32; /* unused */ + CARD32 pad5 B32; /* unused */ } xPanoramiXGetStateReply; #define sz_panoramiXGetStateReply 32 -typedef struct _PanoramiXGetScreenCount { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXGetScreenCount */ - CARD16 length B16; - CARD32 window B32; +typedef struct _PanoramiXGetScreenCount +{ + CARD8 reqType; /* always PanoramiXReqCode */ + CARD8 panoramiXReqType; /* always X_PanoramiXGetScreenCount */ + CARD16 length B16; + CARD32 window B32; } xPanoramiXGetScreenCountReq; #define sz_xPanoramiXGetScreenCountReq 8 -typedef struct { - BYTE type; - BYTE ScreenCount; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 window B32; - CARD32 pad1 B32; /* unused */ - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ - CARD32 pad4 B32; /* unused */ - CARD32 pad5 B32; /* unused */ +typedef struct +{ + BYTE type; + BYTE ScreenCount; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 window B32; + CARD32 pad1 B32; /* unused */ + CARD32 pad2 B32; /* unused */ + CARD32 pad3 B32; /* unused */ + CARD32 pad4 B32; /* unused */ + CARD32 pad5 B32; /* unused */ } xPanoramiXGetScreenCountReply; #define sz_panoramiXGetScreenCountReply 32 -typedef struct _PanoramiXGetScreenSize { - CARD8 reqType; /* always PanoramiXReqCode */ - CARD8 panoramiXReqType; /* always X_PanoramiXGetState */ - CARD16 length B16; - CARD32 window B32; - CARD32 screen B32; +typedef struct _PanoramiXGetScreenSize +{ + CARD8 reqType; /* always PanoramiXReqCode */ + CARD8 panoramiXReqType; /* always X_PanoramiXGetState */ + CARD16 length B16; + CARD32 window B32; + CARD32 screen B32; } xPanoramiXGetScreenSizeReq; -#define sz_xPanoramiXGetScreenSizeReq 12 - -typedef struct { - BYTE type; - CARD8 pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 width B32; - CARD32 height B32; - CARD32 window B32; - CARD32 screen B32; - CARD32 pad2 B32; /* unused */ - CARD32 pad3 B32; /* unused */ +#define sz_xPanoramiXGetScreenSizeReq 12 + +typedef struct +{ + BYTE type; + CARD8 pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 width B32; + CARD32 height B32; + CARD32 window B32; + CARD32 screen B32; + CARD32 pad2 B32; /* unused */ + CARD32 pad3 B32; /* unused */ } xPanoramiXGetScreenSizeReply; -#define sz_panoramiXGetScreenSizeReply 32 +#define sz_panoramiXGetScreenSizeReply 32 /************ Alternate protocol ******************/ -typedef struct { - CARD8 reqType; - CARD8 panoramiXReqType; - CARD16 length B16; +typedef struct +{ + CARD8 reqType; + CARD8 panoramiXReqType; + CARD16 length B16; } xXineramaIsActiveReq; #define sz_xXineramaIsActiveReq 4 -typedef struct { - BYTE type; - CARD8 pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 state B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; + CARD8 pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 state B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXineramaIsActiveReply; -#define sz_XineramaIsActiveReply 32 +#define sz_XineramaIsActiveReply 32 -typedef struct { - CARD8 reqType; - CARD8 panoramiXReqType; - CARD16 length B16; +typedef struct +{ + CARD8 reqType; + CARD8 panoramiXReqType; + CARD16 length B16; } xXineramaQueryScreensReq; #define sz_xXineramaQueryScreensReq 4 -typedef struct { - BYTE type; - CARD8 pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 number B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; + CARD8 pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 number B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXineramaQueryScreensReply; -#define sz_XineramaQueryScreensReply 32 - -typedef struct { - INT16 x_org B16; - INT16 y_org B16; - CARD16 width B16; - CARD16 height B16; +#define sz_XineramaQueryScreensReply 32 + +typedef struct +{ + INT16 x_org B16; + INT16 y_org B16; + CARD16 width B16; + CARD16 height B16; } xXineramaScreenInfo; #define sz_XineramaScreenInfo 8 -#endif +#endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/xf86dga.h b/src/video/Xext/extensions/xf86dga.h index c71ef4b14..c440d0983 100644 --- a/src/video/Xext/extensions/xf86dga.h +++ b/src/video/Xext/extensions/xf86dga.h @@ -60,206 +60,162 @@ #define XF86DGANumberErrors (XF86DGAOperationNotSupported + 1) -typedef struct { - int num; /* A unique identifier for the mode (num > 0) */ - char *name; /* name of mode given in the XF86Config */ - float verticalRefresh; - int flags; /* DGA_CONCURRENT_ACCESS, etc... */ - int imageWidth; /* linear accessible portion (pixels) */ - int imageHeight; - int pixmapWidth; /* Xlib accessible portion (pixels) */ - int pixmapHeight; /* both fields ignored if no concurrent access */ - int bytesPerScanline; - int byteOrder; /* MSBFirst, LSBFirst */ - int depth; - int bitsPerPixel; - unsigned long redMask; - unsigned long greenMask; - unsigned long blueMask; - short visualClass; - int viewportWidth; - int viewportHeight; - int xViewportStep; /* viewport position granularity */ - int yViewportStep; - int maxViewportX; /* max viewport origin */ - int maxViewportY; - int viewportFlags; /* types of page flipping possible */ - int reserved1; - int reserved2; -} SDL_NAME(XDGAMode); - - -typedef struct { - SDL_NAME(XDGAMode) mode; - unsigned char *data; - Pixmap pixmap; -} SDL_NAME(XDGADevice); +typedef struct +{ + int num; /* A unique identifier for the mode (num > 0) */ + char *name; /* name of mode given in the XF86Config */ + float verticalRefresh; + int flags; /* DGA_CONCURRENT_ACCESS, etc... */ + int imageWidth; /* linear accessible portion (pixels) */ + int imageHeight; + int pixmapWidth; /* Xlib accessible portion (pixels) */ + int pixmapHeight; /* both fields ignored if no concurrent access */ + int bytesPerScanline; + int byteOrder; /* MSBFirst, LSBFirst */ + int depth; + int bitsPerPixel; + unsigned long redMask; + unsigned long greenMask; + unsigned long blueMask; + short visualClass; + int viewportWidth; + int viewportHeight; + int xViewportStep; /* viewport position granularity */ + int yViewportStep; + int maxViewportX; /* max viewport origin */ + int maxViewportY; + int viewportFlags; /* types of page flipping possible */ + int reserved1; + int reserved2; +} SDL_NAME (XDGAMode); + + +typedef struct +{ + SDL_NAME (XDGAMode) mode; + unsigned char *data; + Pixmap pixmap; +} SDL_NAME (XDGADevice); #ifndef _XF86DGA_SERVER_ -_XFUNCPROTOBEGIN - -typedef struct { - int type; - unsigned long serial; - Display *display; - int screen; - Time time; - unsigned int state; - unsigned int button; -} SDL_NAME(XDGAButtonEvent); - -typedef struct { - int type; - unsigned long serial; - Display *display; - int screen; - Time time; - unsigned int state; - unsigned int keycode; -} SDL_NAME(XDGAKeyEvent); - -typedef struct { - int type; - unsigned long serial; - Display *display; - int screen; - Time time; - unsigned int state; - int dx; - int dy; -} SDL_NAME(XDGAMotionEvent); - -typedef union { - int type; - SDL_NAME(XDGAButtonEvent) xbutton; - SDL_NAME(XDGAKeyEvent) xkey; - SDL_NAME(XDGAMotionEvent) xmotion; - long pad[24]; -} SDL_NAME(XDGAEvent); - -Bool SDL_NAME(XDGAQueryExtension)( - Display *dpy, - int *eventBase, - int *erroBase -); - -Bool SDL_NAME(XDGAQueryVersion)( - Display *dpy, - int *majorVersion, - int *minorVersion -); - -SDL_NAME(XDGAMode)* SDL_NAME(XDGAQueryModes)( - Display *dpy, - int screen, - int *num -); - -SDL_NAME(XDGADevice)* SDL_NAME(XDGASetMode)( - Display *dpy, - int screen, - int mode -); - -Bool SDL_NAME(XDGAOpenFramebuffer)( - Display *dpy, - int screen -); - -void SDL_NAME(XDGACloseFramebuffer)( - Display *dpy, - int screen -); - -void SDL_NAME(XDGASetViewport)( - Display *dpy, - int screen, - int x, - int y, - int flags -); - -void SDL_NAME(XDGAInstallColormap)( - Display *dpy, - int screen, - Colormap cmap -); - -Colormap SDL_NAME(XDGACreateColormap)( - Display *dpy, - int screen, - SDL_NAME(XDGADevice) *device, - int alloc -); - -void SDL_NAME(XDGASelectInput)( - Display *dpy, - int screen, - long event_mask -); - -void SDL_NAME(XDGAFillRectangle)( - Display *dpy, - int screen, - int x, - int y, - unsigned int width, - unsigned int height, - unsigned long color -); - - -void SDL_NAME(XDGACopyArea)( - Display *dpy, - int screen, - int srcx, - int srcy, - unsigned int width, - unsigned int height, - int dstx, - int dsty -); - - -void SDL_NAME(XDGACopyTransparentArea)( - Display *dpy, - int screen, - int srcx, - int srcy, - unsigned int width, - unsigned int height, - int dstx, - int dsty, - unsigned long key -); - -int SDL_NAME(XDGAGetViewportStatus)( - Display *dpy, - int screen -); - -void SDL_NAME(XDGASync)( - Display *dpy, - int screen -); - -Bool SDL_NAME(XDGASetClientVersion)( - Display *dpy -); - -void SDL_NAME(XDGAChangePixmapMode)( - Display *dpy, - int screen, - int *x, - int *y, - int mode -); - - -void SDL_NAME(XDGAKeyEventToXKeyEvent)(SDL_NAME(XDGAKeyEvent)* dk, XKeyEvent* xk); +_XFUNCPROTOBEGIN typedef struct +{ + int type; + unsigned long serial; + Display *display; + int screen; + Time time; + unsigned int state; + unsigned int button; +} SDL_NAME (XDGAButtonEvent); + +typedef struct +{ + int type; + unsigned long serial; + Display *display; + int screen; + Time time; + unsigned int state; + unsigned int keycode; +} SDL_NAME (XDGAKeyEvent); + +typedef struct +{ + int type; + unsigned long serial; + Display *display; + int screen; + Time time; + unsigned int state; + int dx; + int dy; +} SDL_NAME (XDGAMotionEvent); + +typedef union +{ + int type; + SDL_NAME (XDGAButtonEvent) xbutton; + SDL_NAME (XDGAKeyEvent) xkey; + SDL_NAME (XDGAMotionEvent) xmotion; + long pad[24]; +} SDL_NAME (XDGAEvent); + +Bool SDL_NAME (XDGAQueryExtension) (Display * dpy, + int *eventBase, int *erroBase); + +Bool SDL_NAME (XDGAQueryVersion) (Display * dpy, + int *majorVersion, int *minorVersion); + +SDL_NAME (XDGAMode) * SDL_NAME (XDGAQueryModes) (Display * dpy, + int screen, int *num); + +SDL_NAME (XDGADevice) * SDL_NAME (XDGASetMode) (Display * dpy, + int screen, int mode); + +Bool +SDL_NAME (XDGAOpenFramebuffer) (Display * dpy, int screen); + + void SDL_NAME (XDGACloseFramebuffer) (Display * dpy, int screen); + + void SDL_NAME (XDGASetViewport) (Display * dpy, + int screen, int x, int y, int flags); + + void SDL_NAME (XDGAInstallColormap) (Display * dpy, + int screen, Colormap cmap); + +Colormap +SDL_NAME (XDGACreateColormap) (Display * dpy, + int screen, + SDL_NAME (XDGADevice) * device, int alloc); + + void SDL_NAME (XDGASelectInput) (Display * dpy, int screen, + long event_mask); + + void SDL_NAME (XDGAFillRectangle) (Display * dpy, + int screen, + int x, + int y, + unsigned int width, + unsigned int height, + unsigned long color); + + + void SDL_NAME (XDGACopyArea) (Display * dpy, + int screen, + int srcx, + int srcy, + unsigned int width, + unsigned int height, int dstx, int dsty); + + + void SDL_NAME (XDGACopyTransparentArea) (Display * dpy, + int screen, + int srcx, + int srcy, + unsigned int width, + unsigned int height, + int dstx, + int dsty, unsigned long key); + + int SDL_NAME (XDGAGetViewportStatus) (Display * dpy, int screen); + + void SDL_NAME (XDGASync) (Display * dpy, int screen); + +Bool +SDL_NAME (XDGASetClientVersion) (Display * dpy); + + void SDL_NAME (XDGAChangePixmapMode) (Display * dpy, + int screen, int *x, int *y, + int mode); + + + void SDL_NAME (XDGAKeyEventToXKeyEvent) (SDL_NAME (XDGAKeyEvent) * dk, + XKeyEvent * xk); _XFUNCPROTOEND #endif /* _XF86DGA_SERVER_ */ #endif /* _XF86DGA_H_ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/xf86dga1.h b/src/video/Xext/extensions/xf86dga1.h index 4a49e9f38..6d87d761f 100644 --- a/src/video/Xext/extensions/xf86dga1.h +++ b/src/video/Xext/extensions/xf86dga1.h @@ -41,129 +41,127 @@ Copyright (c) 1995 XFree86 Inc #ifndef _XF86DGA_SERVER_ -_XFUNCPROTOBEGIN - -Bool SDL_NAME(XF86DGAQueryVersion)( +_XFUNCPROTOBEGIN Bool SDL_NAME (XF86DGAQueryVersion) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int* /* majorVersion */, - int* /* minorVersion */ + Display * /* dpy */ , + int * + /* majorVersion */ , + int * /* minorVersion */ #endif -); + ); -Bool SDL_NAME(XF86DGAQueryExtension)( +Bool SDL_NAME (XF86DGAQueryExtension) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int* /* event_base */, - int* /* error_base */ + Display * /* dpy */ , + int * /* event_base */ , + int * /* error_base */ #endif -); + ); -Status SDL_NAME(XF86DGAGetVideoLL)( +Status SDL_NAME (XF86DGAGetVideoLL) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - int * /* base addr */, - int * /* width */, - int * /* bank_size */, - int * /* ram_size */ + Display * /* dpy */ , + int /* screen */ , + int * /* base addr */ , + int * /* width */ , + int * /* bank_size */ , + int * /* ram_size */ #endif -); + ); -Status SDL_NAME(XF86DGAGetVideo)( +Status SDL_NAME (XF86DGAGetVideo) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - char ** /* base addr */, - int * /* width */, - int * /* bank_size */, - int * /* ram_size */ + Display * /* dpy */ , + int /* screen */ , + char ** /* base addr */ , + int * /* width */ , + int * /* bank_size */ , + int * /* ram_size */ #endif -); + ); -Status SDL_NAME(XF86DGADirectVideo)( +Status SDL_NAME (XF86DGADirectVideo) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - int /* enable */ + Display * /* dpy */ , + int /* screen */ , + int /* enable */ #endif -); + ); -Status SDL_NAME(XF86DGADirectVideoLL)( +Status SDL_NAME (XF86DGADirectVideoLL) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - int /* enable */ + Display * /* dpy */ , + int /* screen */ , + int /* enable */ #endif -); + ); -Status SDL_NAME(XF86DGAGetViewPortSize)( +Status SDL_NAME (XF86DGAGetViewPortSize) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - int * /* width */, - int * /* height */ + Display * /* dpy */ , + int /* screen */ , + int * /* width */ , + int * /* height */ #endif -); + ); -Status SDL_NAME(XF86DGASetViewPort)( +Status SDL_NAME (XF86DGASetViewPort) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - int x /* X */, - int y /* Y */ + Display * /* dpy */ , + int /* screen */ , + int x /* X */ , + int y /* Y */ #endif -); + ); -Status SDL_NAME(XF86DGAGetVidPage)( +Status SDL_NAME (XF86DGAGetVidPage) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - int * /* vid page */ + Display * /* dpy */ , + int /* screen */ , + int * /* vid page */ #endif -); + ); -Status SDL_NAME(XF86DGASetVidPage)( +Status SDL_NAME (XF86DGASetVidPage) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - int /* vid page */ + Display * /* dpy */ , + int /* screen */ , + int /* vid page */ #endif -); + ); -Status SDL_NAME(XF86DGAInstallColormap)( +Status SDL_NAME (XF86DGAInstallColormap) ( #if NeedFunctionPrototypes - Display* /* dpy */, - int /* screen */, - Colormap /*Colormap */ + Display * /* dpy */ , + int /* screen */ , + Colormap /*Colormap */ #endif -); + ); -int SDL_NAME(XF86DGAForkApp)( +int SDL_NAME (XF86DGAForkApp) ( #if NeedFunctionPrototypes - int screen + int screen #endif -); + ); -Status SDL_NAME(XF86DGAQueryDirectVideo)( +Status SDL_NAME (XF86DGAQueryDirectVideo) ( #if NeedFunctionPrototypes - Display * /* dpy */, - int /* screen */, - int * /* flags */ + Display * /* dpy */ , + int /* screen */ , + int * /* flags */ #endif -); + ); -Bool SDL_NAME(XF86DGAViewPortChanged)( +Bool SDL_NAME (XF86DGAViewPortChanged) ( #if NeedFunctionPrototypes - Display * /* dpy */, - int /* screen */, - int /* n */ + Display * /* dpy */ , + int /* screen */ , + int /* n */ #endif -); + ); _XFUNCPROTOEND - #endif /* _XF86DGA_SERVER_ */ - #endif /* _XF86DGA1_H_ */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/xf86dga1str.h b/src/video/Xext/extensions/xf86dga1str.h index 5695fbd13..5ad889efc 100644 --- a/src/video/Xext/extensions/xf86dga1str.h +++ b/src/video/Xext/extensions/xf86dga1str.h @@ -9,186 +9,202 @@ Copyright (c) 1995 XFree86 Inc. #ifndef _XF86DGASTR1_H_ #define _XF86DGASTR1_H_ -typedef struct _XF86DGAQueryVersion { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_DGAQueryVersion */ - CARD16 length B16; +typedef struct _XF86DGAQueryVersion +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_DGAQueryVersion */ + CARD16 length B16; } xXF86DGAQueryVersionReq; #define sz_xXF86DGAQueryVersionReq 4 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 majorVersion B16; /* major version of DGA protocol */ - CARD16 minorVersion B16; /* minor version of DGA protocol */ - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 majorVersion B16; /* major version of DGA protocol */ + CARD16 minorVersion B16; /* minor version of DGA protocol */ + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXF86DGAQueryVersionReply; #define sz_xXF86DGAQueryVersionReply 32 -typedef struct _XF86DGAGetVideoLL { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_XF86DGAGetVideoLL */ - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; +typedef struct _XF86DGAGetVideoLL +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_XF86DGAGetVideoLL */ + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; } xXF86DGAGetVideoLLReq; #define sz_xXF86DGAGetVideoLLReq 8 -typedef struct _XF86DGAInstallColormap{ - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD16 screen B16; - CARD16 pad2; - CARD32 id B32; /* colormap. */ +typedef struct _XF86DGAInstallColormap +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD16 screen B16; + CARD16 pad2; + CARD32 id B32; /* colormap. */ } xXF86DGAInstallColormapReq; #define sz_xXF86DGAInstallColormapReq 12 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 offset B32; - CARD32 width B32; - CARD32 bank_size B32; - CARD32 ram_size B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 offset B32; + CARD32 width B32; + CARD32 bank_size B32; + CARD32 ram_size B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86DGAGetVideoLLReply; #define sz_xXF86DGAGetVideoLLReply 32 -typedef struct _XF86DGADirectVideo { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_XF86DGADirectVideo */ - CARD16 length B16; - CARD16 screen B16; - CARD16 enable B16; +typedef struct _XF86DGADirectVideo +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_XF86DGADirectVideo */ + CARD16 length B16; + CARD16 screen B16; + CARD16 enable B16; } xXF86DGADirectVideoReq; #define sz_xXF86DGADirectVideoReq 8 -typedef struct _XF86DGAGetViewPortSize { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_XF86DGAGetViewPort */ - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; +typedef struct _XF86DGAGetViewPortSize +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_XF86DGAGetViewPort */ + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; } xXF86DGAGetViewPortSizeReq; #define sz_xXF86DGAGetViewPortSizeReq 8 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 width B32; - CARD32 height B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 width B32; + CARD32 height B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86DGAGetViewPortSizeReply; #define sz_xXF86DGAGetViewPortSizeReply 32 -typedef struct _XF86DGASetViewPort { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_XF86DGASetViewPort */ - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; - CARD32 x B32; - CARD32 y B32; +typedef struct _XF86DGASetViewPort +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_XF86DGASetViewPort */ + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; + CARD32 x B32; + CARD32 y B32; } xXF86DGASetViewPortReq; #define sz_xXF86DGASetViewPortReq 16 -typedef struct _XF86DGAGetVidPage { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_XF86DGAGetVidPage */ - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; +typedef struct _XF86DGAGetVidPage +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_XF86DGAGetVidPage */ + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; } xXF86DGAGetVidPageReq; #define sz_xXF86DGAGetVidPageReq 8 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 vpage B32; - CARD32 pad B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 vpage B32; + CARD32 pad B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86DGAGetVidPageReply; #define sz_xXF86DGAGetVidPageReply 32 -typedef struct _XF86DGASetVidPage { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_XF86DGASetVidPage */ - CARD16 length B16; - CARD16 screen B16; - CARD16 vpage B16; +typedef struct _XF86DGASetVidPage +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_XF86DGASetVidPage */ + CARD16 length B16; + CARD16 screen B16; + CARD16 vpage B16; } xXF86DGASetVidPageReq; #define sz_xXF86DGASetVidPageReq 8 -typedef struct _XF86DGAQueryDirectVideo { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_DGAQueryVersion */ - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; +typedef struct _XF86DGAQueryDirectVideo +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_DGAQueryVersion */ + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; } xXF86DGAQueryDirectVideoReq; #define sz_xXF86DGAQueryDirectVideoReq 8 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 flags B32; - CARD32 pad B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 flags B32; + CARD32 pad B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86DGAQueryDirectVideoReply; #define sz_xXF86DGAQueryDirectVideoReply 32 -typedef struct _XF86DGAViewPortChanged { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_DGAQueryVersion */ - CARD16 length B16; - CARD16 screen B16; - CARD16 n B16; +typedef struct _XF86DGAViewPortChanged +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_DGAQueryVersion */ + CARD16 length B16; + CARD16 screen B16; + CARD16 n B16; } xXF86DGAViewPortChangedReq; #define sz_xXF86DGAViewPortChangedReq 8 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 result B32; - CARD32 pad B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 result B32; + CARD32 pad B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86DGAViewPortChangedReply; #define sz_xXF86DGAViewPortChangedReply 32 #endif /* _XF86DGASTR1_H_ */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/xf86dgastr.h b/src/video/Xext/extensions/xf86dgastr.h index b249feb3c..9546b4f8d 100644 --- a/src/video/Xext/extensions/xf86dgastr.h +++ b/src/video/Xext/extensions/xf86dgastr.h @@ -13,332 +13,360 @@ Copyright (c) 1995 XFree86 Inc. #define XF86DGANAME "XFree86-DGA" -#define XDGA_MAJOR_VERSION 2 /* current version numbers */ +#define XDGA_MAJOR_VERSION 2 /* current version numbers */ #define XDGA_MINOR_VERSION 0 -typedef struct _XDGAQueryVersion { - CARD8 reqType; /* always DGAReqCode */ - CARD8 dgaReqType; /* always X_DGAQueryVersion */ - CARD16 length B16; +typedef struct _XDGAQueryVersion +{ + CARD8 reqType; /* always DGAReqCode */ + CARD8 dgaReqType; /* always X_DGAQueryVersion */ + CARD16 length B16; } xXDGAQueryVersionReq; #define sz_xXDGAQueryVersionReq 4 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 majorVersion B16; /* major version of DGA protocol */ - CARD16 minorVersion B16; /* minor version of DGA protocol */ - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 majorVersion B16; /* major version of DGA protocol */ + CARD16 minorVersion B16; /* minor version of DGA protocol */ + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXDGAQueryVersionReply; #define sz_xXDGAQueryVersionReply 32 -typedef struct _XDGAQueryModes { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; +typedef struct _XDGAQueryModes +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; } xXDGAQueryModesReq; #define sz_xXDGAQueryModesReq 8 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 number B32; /* number of modes available */ - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 number B32; /* number of modes available */ + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXDGAQueryModesReply; #define sz_xXDGAQueryModesReply 32 -typedef struct _XDGASetMode { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD32 mode B32; /* mode number to init */ - CARD32 pid B32; /* Pixmap descriptor */ +typedef struct _XDGASetMode +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 mode B32; /* mode number to init */ + CARD32 pid B32; /* Pixmap descriptor */ } xXDGASetModeReq; #define sz_xXDGASetModeReq 16 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 offset B32; /* offset into framebuffer map */ - CARD32 flags B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 offset B32; /* offset into framebuffer map */ + CARD32 flags B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXDGASetModeReply; #define sz_xXDGASetModeReply 32 -typedef struct { - CARD8 byte_order; - CARD8 depth; - CARD16 num B16; - CARD16 bpp B16; - CARD16 name_size B16; - CARD32 vsync_num B32; - CARD32 vsync_den B32; - CARD32 flags B32; - CARD16 image_width B16; - CARD16 image_height B16; - CARD16 pixmap_width B16; - CARD16 pixmap_height B16; - CARD32 bytes_per_scanline B32; - CARD32 red_mask B32; - CARD32 green_mask B32; - CARD32 blue_mask B32; - CARD16 visual_class B16; - CARD16 pad1 B16; - CARD16 viewport_width B16; - CARD16 viewport_height B16; - CARD16 viewport_xstep B16; - CARD16 viewport_ystep B16; - CARD16 viewport_xmax B16; - CARD16 viewport_ymax B16; - CARD32 viewport_flags B32; - CARD32 reserved1 B32; - CARD32 reserved2 B32; +typedef struct +{ + CARD8 byte_order; + CARD8 depth; + CARD16 num B16; + CARD16 bpp B16; + CARD16 name_size B16; + CARD32 vsync_num B32; + CARD32 vsync_den B32; + CARD32 flags B32; + CARD16 image_width B16; + CARD16 image_height B16; + CARD16 pixmap_width B16; + CARD16 pixmap_height B16; + CARD32 bytes_per_scanline B32; + CARD32 red_mask B32; + CARD32 green_mask B32; + CARD32 blue_mask B32; + CARD16 visual_class B16; + CARD16 pad1 B16; + CARD16 viewport_width B16; + CARD16 viewport_height B16; + CARD16 viewport_xstep B16; + CARD16 viewport_ystep B16; + CARD16 viewport_xmax B16; + CARD16 viewport_ymax B16; + CARD32 viewport_flags B32; + CARD32 reserved1 B32; + CARD32 reserved2 B32; } xXDGAModeInfo; #define sz_xXDGAModeInfo 72 -typedef struct _XDGAOpenFramebuffer { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; +typedef struct _XDGAOpenFramebuffer +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; } xXDGAOpenFramebufferReq; #define sz_xXDGAOpenFramebufferReq 8 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; /* device name size if there is one */ - CARD32 mem1 B32; /* physical memory */ - CARD32 mem2 B32; /* spillover for _alpha_ */ - CARD32 size B32; /* size of map in bytes */ - CARD32 offset B32; /* optional offset into device */ - CARD32 extra B32; /* extra info associated with the map */ - CARD32 pad2 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; /* device name size if there is one */ + CARD32 mem1 B32; /* physical memory */ + CARD32 mem2 B32; /* spillover for _alpha_ */ + CARD32 size B32; /* size of map in bytes */ + CARD32 offset B32; /* optional offset into device */ + CARD32 extra B32; /* extra info associated with the map */ + CARD32 pad2 B32; } xXDGAOpenFramebufferReply; #define sz_xXDGAOpenFramebufferReply 32 -typedef struct _XDGACloseFramebuffer { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; +typedef struct _XDGACloseFramebuffer +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; } xXDGACloseFramebufferReq; #define sz_xXDGACloseFramebufferReq 8 -typedef struct _XDGASetViewport { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD16 x B16; - CARD16 y B16; - CARD32 flags B32; +typedef struct _XDGASetViewport +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD16 x B16; + CARD16 y B16; + CARD32 flags B32; } xXDGASetViewportReq; #define sz_xXDGASetViewportReq 16 -typedef struct _XDGAInstallColormap { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD32 cmap B32; +typedef struct _XDGAInstallColormap +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 cmap B32; } xXDGAInstallColormapReq; #define sz_xXDGAInstallColormapReq 12 -typedef struct _XDGASelectInput { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD32 mask B32; +typedef struct _XDGASelectInput +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 mask B32; } xXDGASelectInputReq; #define sz_xXDGASelectInputReq 12 -typedef struct _XDGAFillRectangle { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD16 x B16; - CARD16 y B16; - CARD16 width B16; - CARD16 height B16; - CARD32 color B32; +typedef struct _XDGAFillRectangle +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD16 x B16; + CARD16 y B16; + CARD16 width B16; + CARD16 height B16; + CARD32 color B32; } xXDGAFillRectangleReq; #define sz_xXDGAFillRectangleReq 20 -typedef struct _XDGACopyArea { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD16 srcx B16; - CARD16 srcy B16; - CARD16 width B16; - CARD16 height B16; - CARD16 dstx B16; - CARD16 dsty B16; +typedef struct _XDGACopyArea +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD16 srcx B16; + CARD16 srcy B16; + CARD16 width B16; + CARD16 height B16; + CARD16 dstx B16; + CARD16 dsty B16; } xXDGACopyAreaReq; #define sz_xXDGACopyAreaReq 20 -typedef struct _XDGACopyTransparentArea { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD16 srcx B16; - CARD16 srcy B16; - CARD16 width B16; - CARD16 height B16; - CARD16 dstx B16; - CARD16 dsty B16; - CARD32 key B32; +typedef struct _XDGACopyTransparentArea +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD16 srcx B16; + CARD16 srcy B16; + CARD16 width B16; + CARD16 height B16; + CARD16 dstx B16; + CARD16 dsty B16; + CARD32 key B32; } xXDGACopyTransparentAreaReq; #define sz_xXDGACopyTransparentAreaReq 24 -typedef struct _XDGAGetViewportStatus { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; +typedef struct _XDGAGetViewportStatus +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; } xXDGAGetViewportStatusReq; #define sz_xXDGAGetViewportStatusReq 8 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 status B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 status B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXDGAGetViewportStatusReply; #define sz_xXDGAGetViewportStatusReply 32 -typedef struct _XDGASync { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; +typedef struct _XDGASync +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; } xXDGASyncReq; #define sz_xXDGASyncReq 8 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; - CARD32 pad7 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; } xXDGASyncReply; #define sz_xXDGASyncReply 32 -typedef struct _XDGASetClientVersion { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD16 major B16; - CARD16 minor B16; +typedef struct _XDGASetClientVersion +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD16 major B16; + CARD16 minor B16; } xXDGASetClientVersionReq; #define sz_xXDGASetClientVersionReq 8 -typedef struct { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD16 x B16; - CARD16 y B16; - CARD32 flags B32; +typedef struct +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD16 x B16; + CARD16 y B16; + CARD32 flags B32; } xXDGAChangePixmapModeReq; #define sz_xXDGAChangePixmapModeReq 16 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 x B16; - CARD16 y B16; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; - CARD32 pad7 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 x B16; + CARD16 y B16; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; } xXDGAChangePixmapModeReply; #define sz_xXDGAChangePixmapModeReply 32 -typedef struct _XDGACreateColormap { - CARD8 reqType; - CARD8 dgaReqType; - CARD16 length B16; - CARD32 screen B32; - CARD32 id B32; - CARD32 mode B32; - CARD8 alloc; - CARD8 pad1; - CARD16 pad2; +typedef struct _XDGACreateColormap +{ + CARD8 reqType; + CARD8 dgaReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 id B32; + CARD32 mode B32; + CARD8 alloc; + CARD8 pad1; + CARD16 pad2; } xXDGACreateColormapReq; #define sz_xXDGACreateColormapReq 20 -typedef struct { - union { - struct { - BYTE type; - BYTE detail; - CARD16 sequenceNumber B16; +typedef struct +{ + union + { + struct + { + BYTE type; + BYTE detail; + CARD16 sequenceNumber B16; + } u; + struct + { + CARD32 pad0 B32; + CARD32 time B32; + INT16 dx B16; + INT16 dy B16; + INT16 screen B16; + CARD16 state B16; + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + } event; } u; - struct { - CARD32 pad0 B32; - CARD32 time B32; - INT16 dx B16; - INT16 dy B16; - INT16 screen B16; - CARD16 state B16; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - } event; - } u; } dgaEvent; #endif /* _XF86DGASTR_H_ */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/xf86vmode.h b/src/video/Xext/extensions/xf86vmode.h index eb56c0e8d..9a8219f39 100644 --- a/src/video/Xext/extensions/xf86vmode.h +++ b/src/video/Xext/extensions/xf86vmode.h @@ -86,79 +86,85 @@ from Kaleb S. KEITHLEY #ifndef _XF86VIDMODE_SERVER_ -typedef struct { - unsigned short hdisplay; - unsigned short hsyncstart; - unsigned short hsyncend; - unsigned short htotal; - unsigned short hskew; - unsigned short vdisplay; - unsigned short vsyncstart; - unsigned short vsyncend; - unsigned short vtotal; - unsigned int flags; - int privsize; +typedef struct +{ + unsigned short hdisplay; + unsigned short hsyncstart; + unsigned short hsyncend; + unsigned short htotal; + unsigned short hskew; + unsigned short vdisplay; + unsigned short vsyncstart; + unsigned short vsyncend; + unsigned short vtotal; + unsigned int flags; + int privsize; #if defined(__cplusplus) || defined(c_plusplus) /* private is a C++ reserved word */ - INT32 *c_private; + INT32 *c_private; #else - INT32 *private; + INT32 *private; #endif -} SDL_NAME(XF86VidModeModeLine); - -typedef struct { - unsigned int dotclock; - unsigned short hdisplay; - unsigned short hsyncstart; - unsigned short hsyncend; - unsigned short htotal; - unsigned short hskew; - unsigned short vdisplay; - unsigned short vsyncstart; - unsigned short vsyncend; - unsigned short vtotal; - unsigned int flags; - int privsize; +} SDL_NAME (XF86VidModeModeLine); + +typedef struct +{ + unsigned int dotclock; + unsigned short hdisplay; + unsigned short hsyncstart; + unsigned short hsyncend; + unsigned short htotal; + unsigned short hskew; + unsigned short vdisplay; + unsigned short vsyncstart; + unsigned short vsyncend; + unsigned short vtotal; + unsigned int flags; + int privsize; #if defined(__cplusplus) || defined(c_plusplus) /* private is a C++ reserved word */ - INT32 *c_private; + INT32 *c_private; #else - INT32 *private; + INT32 *private; #endif -} SDL_NAME(XF86VidModeModeInfo); - -typedef struct { - float hi; - float lo; -} SDL_NAME(XF86VidModeSyncRange); - -typedef struct { - char* vendor; - char* model; - float EMPTY; - unsigned char nhsync; - SDL_NAME(XF86VidModeSyncRange)* hsync; - unsigned char nvsync; - SDL_NAME(XF86VidModeSyncRange)* vsync; -} SDL_NAME(XF86VidModeMonitor); - -typedef struct { - int type; /* of event */ - unsigned long serial; /* # of last request processed by server */ - Bool send_event; /* true if this came from a SendEvent req */ - Display *display; /* Display the event was read from */ - Window root; /* root window of event screen */ - int state; /* What happened */ - int kind; /* What happened */ - Bool forced; /* extents of new region */ - Time time; /* event timestamp */ -} SDL_NAME(XF86VidModeNotifyEvent); - -typedef struct { - float red; /* Red Gamma value */ - float green; /* Green Gamma value */ - float blue; /* Blue Gamma value */ -} SDL_NAME(XF86VidModeGamma); +} SDL_NAME (XF86VidModeModeInfo); + +typedef struct +{ + float hi; + float lo; +} SDL_NAME (XF86VidModeSyncRange); + +typedef struct +{ + char *vendor; + char *model; + float EMPTY; + unsigned char nhsync; + SDL_NAME (XF86VidModeSyncRange) * hsync; + unsigned char nvsync; + SDL_NAME (XF86VidModeSyncRange) * vsync; +} SDL_NAME (XF86VidModeMonitor); + +typedef struct +{ + int type; /* of event */ + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came from a SendEvent req */ + Display *display; /* Display the event was read from */ + Window root; /* root window of event screen */ + int state; /* What happened */ + int kind; /* What happened */ + Bool forced; /* extents of new region */ + Time time; /* event timestamp */ +} SDL_NAME (XF86VidModeNotifyEvent); + +typedef struct +{ + float red; /* Red Gamma value */ + float green; /* Green Gamma value */ + float blue; /* Blue Gamma value */ +} SDL_NAME (XF86VidModeGamma); #define SDL_XF86VidModeSelectNextMode(disp, scr) \ @@ -167,148 +173,126 @@ typedef struct { SDL_NAME(XF86VidModeSwitchMode)(disp, scr, -1) _XFUNCPROTOBEGIN - -Bool SDL_NAME(XF86VidModeQueryVersion)( - Display* /* dpy */, - int* /* majorVersion */, - int* /* minorVersion */ -); - -Bool SDL_NAME(XF86VidModeQueryExtension)( - Display* /* dpy */, - int* /* event_base */, - int* /* error_base */ -); - -Bool SDL_NAME(XF86VidModeSetClientVersion)( - Display* /* dpy */ -); - -Bool SDL_NAME(XF86VidModeGetModeLine)( - Display* /* dpy */, - int /* screen */, - int* /* dotclock */, - SDL_NAME(XF86VidModeModeLine)* /* modeline */ -); - -Bool SDL_NAME(XF86VidModeGetAllModeLines)( - Display* /* dpy */, - int /* screen */, - int* /* modecount */, - SDL_NAME(XF86VidModeModeInfo)*** /* modelinesPtr */ -); - -Bool SDL_NAME(XF86VidModeAddModeLine)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeModeInfo)* /* new modeline */, - SDL_NAME(XF86VidModeModeInfo)* /* after modeline */ -); - -Bool SDL_NAME(XF86VidModeDeleteModeLine)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeModeInfo)* /* modeline */ -); - -Bool SDL_NAME(XF86VidModeModModeLine)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeModeLine)* /* modeline */ -); - -Status SDL_NAME(XF86VidModeValidateModeLine)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeModeInfo)* /* modeline */ -); - -Bool SDL_NAME(XF86VidModeSwitchMode)( - Display* /* dpy */, - int /* screen */, - int /* zoom */ -); - -Bool SDL_NAME(XF86VidModeSwitchToMode)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeModeInfo)* /* modeline */ -); - -Bool SDL_NAME(XF86VidModeLockModeSwitch)( - Display* /* dpy */, - int /* screen */, - int /* lock */ -); - -Bool SDL_NAME(XF86VidModeGetMonitor)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeMonitor)* /* monitor */ -); - -Bool SDL_NAME(XF86VidModeGetViewPort)( - Display* /* dpy */, - int /* screen */, - int* /* x return */, - int* /* y return */ -); - -Bool SDL_NAME(XF86VidModeSetViewPort)( - Display* /* dpy */, - int /* screen */, - int /* x */, - int /* y */ -); - -Bool SDL_NAME(XF86VidModeGetDotClocks)( - Display* /* dpy */, - int /* screen */, - int* /* flags return */, - int* /* number of clocks return */, - int* /* max dot clock return */, - int** /* clocks return */ -); - -Bool SDL_NAME(XF86VidModeGetGamma)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeGamma)* /* Gamma */ -); - -Bool SDL_NAME(XF86VidModeSetGamma)( - Display* /* dpy */, - int /* screen */, - SDL_NAME(XF86VidModeGamma)* /* Gamma */ -); - -Bool SDL_NAME(XF86VidModeSetGammaRamp)( - Display* /* dpy */, - int /* screen */, - int /* size */, - unsigned short* /* red array */, - unsigned short* /* green array */, - unsigned short* /* blue array */ -); - -Bool SDL_NAME(XF86VidModeGetGammaRamp)( - Display* /* dpy */, - int /* screen */, - int /* size */, - unsigned short* /* red array */, - unsigned short* /* green array */, - unsigned short* /* blue array */ -); - -Bool SDL_NAME(XF86VidModeGetGammaRampSize)( - Display* /* dpy */, - int /* screen */, - int* /* size */ -); + Bool SDL_NAME (XF86VidModeQueryVersion) (Display * /* dpy */ , + int * /* majorVersion */ , + int * /* minorVersion */ + ); + +Bool SDL_NAME (XF86VidModeQueryExtension) (Display * /* dpy */ , + int * /* event_base */ , + int * /* error_base */ + ); + +Bool SDL_NAME (XF86VidModeSetClientVersion) (Display * /* dpy */ + ); + +Bool SDL_NAME (XF86VidModeGetModeLine) (Display * /* dpy */ , + int /* screen */ , + int * /* dotclock */ , + SDL_NAME (XF86VidModeModeLine) * /* modeline */ + ); + +Bool SDL_NAME (XF86VidModeGetAllModeLines) (Display * /* dpy */ , + int /* screen */ , + int * /* modecount */ , + SDL_NAME (XF86VidModeModeInfo) *** /* modelinesPtr */ + ); + +Bool SDL_NAME (XF86VidModeAddModeLine) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeModeInfo) * + /* new modeline */ , + SDL_NAME (XF86VidModeModeInfo) * /* after modeline */ + ); + +Bool SDL_NAME (XF86VidModeDeleteModeLine) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeModeInfo) * /* modeline */ + ); + +Bool SDL_NAME (XF86VidModeModModeLine) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeModeLine) * /* modeline */ + ); + +Status SDL_NAME (XF86VidModeValidateModeLine) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeModeInfo) * /* modeline */ + ); + +Bool SDL_NAME (XF86VidModeSwitchMode) (Display * /* dpy */ , + int /* screen */ , + int /* zoom */ + ); + +Bool SDL_NAME (XF86VidModeSwitchToMode) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeModeInfo) * /* modeline */ + ); + +Bool SDL_NAME (XF86VidModeLockModeSwitch) (Display * /* dpy */ , + int /* screen */ , + int /* lock */ + ); + +Bool SDL_NAME (XF86VidModeGetMonitor) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeMonitor) * /* monitor */ + ); + +Bool SDL_NAME (XF86VidModeGetViewPort) (Display * /* dpy */ , + int /* screen */ , + int * /* x return */ , + int * /* y return */ + ); + +Bool SDL_NAME (XF86VidModeSetViewPort) (Display * /* dpy */ , + int /* screen */ , + int /* x */ , + int /* y */ + ); + +Bool SDL_NAME (XF86VidModeGetDotClocks) (Display * /* dpy */ , + int /* screen */ , + int * /* flags return */ , + int * /* number of clocks return */ , + int * /* max dot clock return */ , + int ** /* clocks return */ + ); + +Bool SDL_NAME (XF86VidModeGetGamma) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeGamma) * /* Gamma */ + ); + +Bool SDL_NAME (XF86VidModeSetGamma) (Display * /* dpy */ , + int /* screen */ , + SDL_NAME (XF86VidModeGamma) * /* Gamma */ + ); + +Bool SDL_NAME (XF86VidModeSetGammaRamp) (Display * /* dpy */ , + int /* screen */ , + int /* size */ , + unsigned short * /* red array */ , + unsigned short * /* green array */ , + unsigned short * /* blue array */ + ); + +Bool SDL_NAME (XF86VidModeGetGammaRamp) (Display * /* dpy */ , + int /* screen */ , + int /* size */ , + unsigned short * /* red array */ , + unsigned short * /* green array */ , + unsigned short * /* blue array */ + ); + +Bool SDL_NAME (XF86VidModeGetGammaRampSize) (Display * /* dpy */ , + int /* screen */ , + int * /* size */ + ); _XFUNCPROTOEND - #endif - #endif +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/xf86vmstr.h b/src/video/Xext/extensions/xf86vmstr.h index 0c3078d5a..b1f476d51 100644 --- a/src/video/Xext/extensions/xf86vmstr.h +++ b/src/video/Xext/extensions/xf86vmstr.h @@ -39,7 +39,7 @@ from Kaleb S. KEITHLEY #define XF86VIDMODENAME "XFree86-VidModeExtension" -#define XF86VIDMODE_MAJOR_VERSION 2 /* current version numbers */ +#define XF86VIDMODE_MAJOR_VERSION 2 /* current version numbers */ #define XF86VIDMODE_MINOR_VERSION 1 /* * major version 0 == uses parameter-to-wire functions in XFree86 libXxf86vm. @@ -48,499 +48,526 @@ from Kaleb S. KEITHLEY * major version 2 == uses new protocol version in XFree86 4.0. */ -typedef struct _XF86VidModeQueryVersion { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86VidModeQueryVersion */ - CARD16 length B16; +typedef struct _XF86VidModeQueryVersion +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86VidModeQueryVersion */ + CARD16 length B16; } xXF86VidModeQueryVersionReq; #define sz_xXF86VidModeQueryVersionReq 4 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 majorVersion B16; /* major version of XF86VidMode */ - CARD16 minorVersion B16; /* minor version of XF86VidMode */ - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 majorVersion B16; /* major version of XF86VidMode */ + CARD16 minorVersion B16; /* minor version of XF86VidMode */ + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXF86VidModeQueryVersionReply; #define sz_xXF86VidModeQueryVersionReply 32 -typedef struct _XF86VidModeGetModeLine { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; +typedef struct _XF86VidModeGetModeLine +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; } xXF86VidModeGetModeLineReq, - xXF86VidModeGetAllModeLinesReq, - xXF86VidModeGetMonitorReq, - xXF86VidModeGetViewPortReq, - xXF86VidModeGetDotClocksReq; + xXF86VidModeGetAllModeLinesReq, + xXF86VidModeGetMonitorReq, + xXF86VidModeGetViewPortReq, xXF86VidModeGetDotClocksReq; #define sz_xXF86VidModeGetModeLineReq 8 #define sz_xXF86VidModeGetAllModeLinesReq 8 #define sz_xXF86VidModeGetMonitorReq 8 #define sz_xXF86VidModeGetViewPortReq 8 #define sz_xXF86VidModeGetDotClocksReq 8 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 hskew B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD16 pad2 B16; - CARD32 flags B32; - CARD32 reserved1 B32; - CARD32 reserved2 B32; - CARD32 reserved3 B32; - CARD32 privsize B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 hskew B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD16 pad2 B16; + CARD32 flags B32; + CARD32 reserved1 B32; + CARD32 reserved2 B32; + CARD32 reserved3 B32; + CARD32 privsize B32; } xXF86VidModeGetModeLineReply; #define sz_xXF86VidModeGetModeLineReply 52 /* 0.x version */ -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD32 flags B32; - CARD32 privsize B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD32 flags B32; + CARD32 privsize B32; } xXF86OldVidModeGetModeLineReply; #define sz_xXF86OldVidModeGetModeLineReply 36 -typedef struct { - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD32 hskew B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD16 pad1 B16; - CARD32 flags B32; - CARD32 reserved1 B32; - CARD32 reserved2 B32; - CARD32 reserved3 B32; - CARD32 privsize B32; +typedef struct +{ + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD32 hskew B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD16 pad1 B16; + CARD32 flags B32; + CARD32 reserved1 B32; + CARD32 reserved2 B32; + CARD32 reserved3 B32; + CARD32 privsize B32; } xXF86VidModeModeInfo; /* 0.x version */ -typedef struct { - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD32 flags B32; - CARD32 privsize B32; +typedef struct +{ + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD32 flags B32; + CARD32 privsize B32; } xXF86OldVidModeModeInfo; -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 modecount B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 modecount B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXF86VidModeGetAllModeLinesReply; #define sz_xXF86VidModeGetAllModeLinesReply 32 -typedef struct _XF86VidModeAddModeLine { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86VidModeAddMode */ - CARD16 length B16; - CARD32 screen B32; /* could be CARD16 but need the pad */ - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 hskew B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD16 pad1 B16; - CARD32 flags B32; - CARD32 reserved1 B32; - CARD32 reserved2 B32; - CARD32 reserved3 B32; - CARD32 privsize B32; - CARD32 after_dotclock B32; - CARD16 after_hdisplay B16; - CARD16 after_hsyncstart B16; - CARD16 after_hsyncend B16; - CARD16 after_htotal B16; - CARD16 after_hskew B16; - CARD16 after_vdisplay B16; - CARD16 after_vsyncstart B16; - CARD16 after_vsyncend B16; - CARD16 after_vtotal B16; - CARD16 pad2 B16; - CARD32 after_flags B32; - CARD32 reserved4 B32; - CARD32 reserved5 B32; - CARD32 reserved6 B32; +typedef struct _XF86VidModeAddModeLine +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86VidModeAddMode */ + CARD16 length B16; + CARD32 screen B32; /* could be CARD16 but need the pad */ + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 hskew B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD16 pad1 B16; + CARD32 flags B32; + CARD32 reserved1 B32; + CARD32 reserved2 B32; + CARD32 reserved3 B32; + CARD32 privsize B32; + CARD32 after_dotclock B32; + CARD16 after_hdisplay B16; + CARD16 after_hsyncstart B16; + CARD16 after_hsyncend B16; + CARD16 after_htotal B16; + CARD16 after_hskew B16; + CARD16 after_vdisplay B16; + CARD16 after_vsyncstart B16; + CARD16 after_vsyncend B16; + CARD16 after_vtotal B16; + CARD16 pad2 B16; + CARD32 after_flags B32; + CARD32 reserved4 B32; + CARD32 reserved5 B32; + CARD32 reserved6 B32; } xXF86VidModeAddModeLineReq; #define sz_xXF86VidModeAddModeLineReq 92 /* 0.x version */ -typedef struct _XF86OldVidModeAddModeLine { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86VidModeAddMode */ - CARD16 length B16; - CARD32 screen B32; /* could be CARD16 but need the pad */ - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD32 flags B32; - CARD32 privsize B32; - CARD32 after_dotclock B32; - CARD16 after_hdisplay B16; - CARD16 after_hsyncstart B16; - CARD16 after_hsyncend B16; - CARD16 after_htotal B16; - CARD16 after_vdisplay B16; - CARD16 after_vsyncstart B16; - CARD16 after_vsyncend B16; - CARD16 after_vtotal B16; - CARD32 after_flags B32; +typedef struct _XF86OldVidModeAddModeLine +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86VidModeAddMode */ + CARD16 length B16; + CARD32 screen B32; /* could be CARD16 but need the pad */ + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD32 flags B32; + CARD32 privsize B32; + CARD32 after_dotclock B32; + CARD16 after_hdisplay B16; + CARD16 after_hsyncstart B16; + CARD16 after_hsyncend B16; + CARD16 after_htotal B16; + CARD16 after_vdisplay B16; + CARD16 after_vsyncstart B16; + CARD16 after_vsyncend B16; + CARD16 after_vtotal B16; + CARD32 after_flags B32; } xXF86OldVidModeAddModeLineReq; #define sz_xXF86OldVidModeAddModeLineReq 60 -typedef struct _XF86VidModeModModeLine { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86VidModeModModeLine */ - CARD16 length B16; - CARD32 screen B32; /* could be CARD16 but need the pad */ - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 hskew B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD16 pad1 B16; - CARD32 flags B32; - CARD32 reserved1 B32; - CARD32 reserved2 B32; - CARD32 reserved3 B32; - CARD32 privsize B32; +typedef struct _XF86VidModeModModeLine +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86VidModeModModeLine */ + CARD16 length B16; + CARD32 screen B32; /* could be CARD16 but need the pad */ + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 hskew B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD16 pad1 B16; + CARD32 flags B32; + CARD32 reserved1 B32; + CARD32 reserved2 B32; + CARD32 reserved3 B32; + CARD32 privsize B32; } xXF86VidModeModModeLineReq; #define sz_xXF86VidModeModModeLineReq 48 /* 0.x version */ -typedef struct _XF86OldVidModeModModeLine { - CARD8 reqType; /* always XF86OldVidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86OldVidModeModModeLine */ - CARD16 length B16; - CARD32 screen B32; /* could be CARD16 but need the pad */ - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD32 flags B32; - CARD32 privsize B32; +typedef struct _XF86OldVidModeModModeLine +{ + CARD8 reqType; /* always XF86OldVidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86OldVidModeModModeLine */ + CARD16 length B16; + CARD32 screen B32; /* could be CARD16 but need the pad */ + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD32 flags B32; + CARD32 privsize B32; } xXF86OldVidModeModModeLineReq; #define sz_xXF86OldVidModeModModeLineReq 32 -typedef struct _XF86VidModeValidateModeLine { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD32 screen B32; /* could be CARD16 but need the pad */ - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 hskew B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD16 pad1 B16; - CARD32 flags B32; - CARD32 reserved1 B32; - CARD32 reserved2 B32; - CARD32 reserved3 B32; - CARD32 privsize B32; +typedef struct _XF86VidModeValidateModeLine +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD32 screen B32; /* could be CARD16 but need the pad */ + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 hskew B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD16 pad1 B16; + CARD32 flags B32; + CARD32 reserved1 B32; + CARD32 reserved2 B32; + CARD32 reserved3 B32; + CARD32 privsize B32; } xXF86VidModeDeleteModeLineReq, - xXF86VidModeValidateModeLineReq, - xXF86VidModeSwitchToModeReq; + xXF86VidModeValidateModeLineReq, xXF86VidModeSwitchToModeReq; #define sz_xXF86VidModeDeleteModeLineReq 52 #define sz_xXF86VidModeValidateModeLineReq 52 #define sz_xXF86VidModeSwitchToModeReq 52 /* 0.x version */ -typedef struct _XF86OldVidModeValidateModeLine { - CARD8 reqType; /* always XF86OldVidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD32 screen B32; /* could be CARD16 but need the pad */ - CARD32 dotclock B32; - CARD16 hdisplay B16; - CARD16 hsyncstart B16; - CARD16 hsyncend B16; - CARD16 htotal B16; - CARD16 vdisplay B16; - CARD16 vsyncstart B16; - CARD16 vsyncend B16; - CARD16 vtotal B16; - CARD32 flags B32; - CARD32 privsize B32; +typedef struct _XF86OldVidModeValidateModeLine +{ + CARD8 reqType; /* always XF86OldVidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD32 screen B32; /* could be CARD16 but need the pad */ + CARD32 dotclock B32; + CARD16 hdisplay B16; + CARD16 hsyncstart B16; + CARD16 hsyncend B16; + CARD16 htotal B16; + CARD16 vdisplay B16; + CARD16 vsyncstart B16; + CARD16 vsyncend B16; + CARD16 vtotal B16; + CARD32 flags B32; + CARD32 privsize B32; } xXF86OldVidModeDeleteModeLineReq, - xXF86OldVidModeValidateModeLineReq, - xXF86OldVidModeSwitchToModeReq; + xXF86OldVidModeValidateModeLineReq, xXF86OldVidModeSwitchToModeReq; #define sz_xXF86OldVidModeDeleteModeLineReq 36 #define sz_xXF86OldVidModeValidateModeLineReq 36 #define sz_xXF86OldVidModeSwitchToModeReq 36 -typedef struct _XF86VidModeSwitchMode { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86VidModeSwitchMode */ - CARD16 length B16; - CARD16 screen B16; - CARD16 zoom B16; +typedef struct _XF86VidModeSwitchMode +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86VidModeSwitchMode */ + CARD16 length B16; + CARD16 screen B16; + CARD16 zoom B16; } xXF86VidModeSwitchModeReq; #define sz_xXF86VidModeSwitchModeReq 8 -typedef struct _XF86VidModeLockModeSwitch { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86VidModeLockModeSwitch */ - CARD16 length B16; - CARD16 screen B16; - CARD16 lock B16; +typedef struct _XF86VidModeLockModeSwitch +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86VidModeLockModeSwitch */ + CARD16 length B16; + CARD16 screen B16; + CARD16 lock B16; } xXF86VidModeLockModeSwitchReq; #define sz_xXF86VidModeLockModeSwitchReq 8 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 status B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 status B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXF86VidModeValidateModeLineReply; #define sz_xXF86VidModeValidateModeLineReply 32 -typedef struct { - BYTE type; /* X_Reply */ - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD8 vendorLength; - CARD8 modelLength; - CARD8 nhsync; - CARD8 nvsync; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD8 vendorLength; + CARD8 modelLength; + CARD8 nhsync; + CARD8 nvsync; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXF86VidModeGetMonitorReply; #define sz_xXF86VidModeGetMonitorReply 32 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 x B32; - CARD32 y B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 x B32; + CARD32 y B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86VidModeGetViewPortReply; #define sz_xXF86VidModeGetViewPortReply 32 -typedef struct _XF86VidModeSetViewPort { - CARD8 reqType; /* always VidModeReqCode */ - CARD8 xf86vidmodeReqType; /* always X_XF86VidModeSetViewPort */ - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; - CARD32 x B32; - CARD32 y B32; +typedef struct _XF86VidModeSetViewPort +{ + CARD8 reqType; /* always VidModeReqCode */ + CARD8 xf86vidmodeReqType; /* always X_XF86VidModeSetViewPort */ + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; + CARD32 x B32; + CARD32 y B32; } xXF86VidModeSetViewPortReq; #define sz_xXF86VidModeSetViewPortReq 16 -typedef struct { - BYTE type; - BOOL pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 flags B32; - CARD32 clocks B32; - CARD32 maxclocks B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 flags B32; + CARD32 clocks B32; + CARD32 maxclocks B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; } xXF86VidModeGetDotClocksReply; #define sz_xXF86VidModeGetDotClocksReply 32 -typedef struct _XF86VidModeSetClientVersion { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD16 major B16; - CARD16 minor B16; +typedef struct _XF86VidModeSetClientVersion +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD16 major B16; + CARD16 minor B16; } xXF86VidModeSetClientVersionReq; #define sz_xXF86VidModeSetClientVersionReq 8 -typedef struct _XF86VidModeGetGamma { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; +typedef struct _XF86VidModeGetGamma +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; } xXF86VidModeGetGammaReq; #define sz_xXF86VidModeGetGammaReq 32 -typedef struct { - BYTE type; - BOOL pad; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 red B32; - CARD32 green B32; - CARD32 blue B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; +typedef struct +{ + BYTE type; + BOOL pad; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 red B32; + CARD32 green B32; + CARD32 blue B32; + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; } xXF86VidModeGetGammaReply; #define sz_xXF86VidModeGetGammaReply 32 -typedef struct _XF86VidModeSetGamma { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; - CARD32 red B32; - CARD32 green B32; - CARD32 blue B32; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; +typedef struct _XF86VidModeSetGamma +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; + CARD32 red B32; + CARD32 green B32; + CARD32 blue B32; + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; } xXF86VidModeSetGammaReq; #define sz_xXF86VidModeSetGammaReq 32 -typedef struct _XF86VidModeSetGammaRamp { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD16 screen B16; - CARD16 size B16; +typedef struct _XF86VidModeSetGammaRamp +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD16 screen B16; + CARD16 size B16; } xXF86VidModeSetGammaRampReq; -#define sz_xXF86VidModeSetGammaRampReq 8 - -typedef struct _XF86VidModeGetGammaRamp { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD16 screen B16; - CARD16 size B16; +#define sz_xXF86VidModeSetGammaRampReq 8 + +typedef struct _XF86VidModeGetGammaRamp +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD16 screen B16; + CARD16 size B16; } xXF86VidModeGetGammaRampReq; #define sz_xXF86VidModeGetGammaRampReq 8 -typedef struct { - BYTE type; - BOOL pad; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 size B16; - CARD16 pad0 B16; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 size B16; + CARD16 pad0 B16; + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86VidModeGetGammaRampReply; #define sz_xXF86VidModeGetGammaRampReply 32 -typedef struct _XF86VidModeGetGammaRampSize { - CARD8 reqType; /* always XF86VidModeReqCode */ - CARD8 xf86vidmodeReqType; - CARD16 length B16; - CARD16 screen B16; - CARD16 pad B16; +typedef struct _XF86VidModeGetGammaRampSize +{ + CARD8 reqType; /* always XF86VidModeReqCode */ + CARD8 xf86vidmodeReqType; + CARD16 length B16; + CARD16 screen B16; + CARD16 pad B16; } xXF86VidModeGetGammaRampSizeReq; #define sz_xXF86VidModeGetGammaRampSizeReq 8 -typedef struct { - BYTE type; - BOOL pad; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD16 size B16; - CARD16 pad0 B16; - CARD32 pad1 B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; +typedef struct +{ + BYTE type; + BOOL pad; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 size B16; + CARD16 pad0 B16; + CARD32 pad1 B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; } xXF86VidModeGetGammaRampSizeReply; #define sz_xXF86VidModeGetGammaRampSizeReply 32 #endif /* _XF86VIDMODESTR_H_ */ - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/Xext/extensions/xme.h b/src/video/Xext/extensions/xme.h index 41bb416ad..4dc14f1d5 100644 --- a/src/video/Xext/extensions/xme.h +++ b/src/video/Xext/extensions/xme.h @@ -12,30 +12,31 @@ */ -#ifndef _XME_H_INCLUDED +#ifndef _XME_H_INCLUDED #define _XME_H_INCLUDED -typedef struct { - short x; - short y; - unsigned short w; - unsigned short h; +typedef struct +{ + short x; + short y; + unsigned short w; + unsigned short h; } XiGMiscViewInfo; -typedef struct { - unsigned short width; - unsigned short height; - int refresh; +typedef struct +{ + unsigned short width; + unsigned short height; + int refresh; } XiGMiscResolutionInfo; -extern Bool XiGMiscQueryVersion(Display *dpy, int *major, int *minor); -extern int XiGMiscQueryViews(Display *dpy, int screen, - XiGMiscViewInfo **pviews); -extern int XiGMiscQueryResolutions(Display *dpy, int screen, int view, - int *pactive, - XiGMiscResolutionInfo **presolutions); -extern void XiGMiscChangeResolution(Display *dpy, int screen, int view, - int width, int height, int refresh); +extern Bool XiGMiscQueryVersion (Display * dpy, int *major, int *minor); +extern int XiGMiscQueryViews (Display * dpy, int screen, + XiGMiscViewInfo ** pviews); +extern int XiGMiscQueryResolutions (Display * dpy, int screen, int view, + int *pactive, + XiGMiscResolutionInfo ** presolutions); +extern void XiGMiscChangeResolution (Display * dpy, int screen, int view, + int width, int height, int refresh); #endif /* _XME_H_INCLUDED */ - - +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/aalib/SDL_aaevents.c b/src/video/aalib/SDL_aaevents.c index 7811f1932..28ff8c8c3 100644 --- a/src/video/aalib/SDL_aaevents.c +++ b/src/video/aalib/SDL_aaevents.c @@ -36,167 +36,180 @@ /* The translation tables from a console scancode to a SDL keysym */ static SDLKey keymap[401]; -static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); +static SDL_keysym *TranslateKey (int scancode, SDL_keysym * keysym); -void AA_PumpEvents(_THIS) +void +AA_PumpEvents (_THIS) { - int posted = 0; - int mouse_button, mouse_x, mouse_y; - int evt; - SDL_keysym keysym; - - static int prev_button = -1, prev_x = -1, prev_y = -1; - - if( ! this->screen ) /* Wait till we got the screen initialized */ - return; - - do { - posted = 0; - /* Gather events */ - - /* Get mouse status */ - SDL_mutexP(AA_mutex); - aa_getmouse (AA_context, &mouse_x, &mouse_y, &mouse_button); - SDL_mutexV(AA_mutex); - mouse_x = mouse_x * this->screen->w / aa_scrwidth (AA_context); - mouse_y = mouse_y * this->screen->h / aa_scrheight (AA_context); - - /* Compare against previous state and generate events */ - if( prev_button != mouse_button ) { - if( mouse_button & AA_BUTTON1 ) { - if ( ! (prev_button & AA_BUTTON1) ) { - posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0); - } - } else { - if ( prev_button & AA_BUTTON1 ) { - posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0); - } - } - if( mouse_button & AA_BUTTON2 ) { - if ( ! (prev_button & AA_BUTTON2) ) { - posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0); - } - } else { - if ( prev_button & AA_BUTTON2 ) { - posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0); - } - } - if( mouse_button & AA_BUTTON3 ) { - if ( ! (prev_button & AA_BUTTON3) ) { - posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0); - } - } else { - if ( prev_button & AA_BUTTON3 ) { - posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0); - } - } - } - if ( prev_x != mouse_x || prev_y != mouse_y ) { - posted += SDL_PrivateMouseMotion(0, 0, mouse_x, mouse_y); - } - - prev_button = mouse_button; - prev_x = mouse_x; prev_y = mouse_y; - - /* Get keyboard event */ - SDL_mutexP(AA_mutex); - evt = aa_getevent(AA_context, 0); - SDL_mutexV(AA_mutex); - if ( (evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) && (evt != AA_RESIZE) ) { - /* Key pressed */ + int posted = 0; + int mouse_button, mouse_x, mouse_y; + int evt; + SDL_keysym keysym; + + static int prev_button = -1, prev_x = -1, prev_y = -1; + + if (!this->screen) /* Wait till we got the screen initialized */ + return; + + do { + posted = 0; + /* Gather events */ + + /* Get mouse status */ + SDL_mutexP (AA_mutex); + aa_getmouse (AA_context, &mouse_x, &mouse_y, &mouse_button); + SDL_mutexV (AA_mutex); + mouse_x = mouse_x * this->screen->w / aa_scrwidth (AA_context); + mouse_y = mouse_y * this->screen->h / aa_scrheight (AA_context); + + /* Compare against previous state and generate events */ + if (prev_button != mouse_button) { + if (mouse_button & AA_BUTTON1) { + if (!(prev_button & AA_BUTTON1)) { + posted += SDL_PrivateMouseButton (SDL_PRESSED, 1, 0, 0); + } + } else { + if (prev_button & AA_BUTTON1) { + posted += SDL_PrivateMouseButton (SDL_RELEASED, 1, 0, 0); + } + } + if (mouse_button & AA_BUTTON2) { + if (!(prev_button & AA_BUTTON2)) { + posted += SDL_PrivateMouseButton (SDL_PRESSED, 2, 0, 0); + } + } else { + if (prev_button & AA_BUTTON2) { + posted += SDL_PrivateMouseButton (SDL_RELEASED, 2, 0, 0); + } + } + if (mouse_button & AA_BUTTON3) { + if (!(prev_button & AA_BUTTON3)) { + posted += SDL_PrivateMouseButton (SDL_PRESSED, 3, 0, 0); + } + } else { + if (prev_button & AA_BUTTON3) { + posted += SDL_PrivateMouseButton (SDL_RELEASED, 3, 0, 0); + } + } + } + if (prev_x != mouse_x || prev_y != mouse_y) { + posted += SDL_PrivateMouseMotion (0, 0, mouse_x, mouse_y); + } + + prev_button = mouse_button; + prev_x = mouse_x; + prev_y = mouse_y; + + /* Get keyboard event */ + SDL_mutexP (AA_mutex); + evt = aa_getevent (AA_context, 0); + SDL_mutexV (AA_mutex); + if ((evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) + && (evt != AA_RESIZE)) { + /* Key pressed */ /* printf("Key pressed: %d (%c)\n", evt, evt); */ - posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(evt, &keysym)); - } else if ( evt >= AA_RELEASE ) { - /* Key released */ - evt &= ~AA_RELEASE; + posted += + SDL_PrivateKeyboard (SDL_PRESSED, + TranslateKey (evt, &keysym)); + } else if (evt >= AA_RELEASE) { + /* Key released */ + evt &= ~AA_RELEASE; /* printf("Key released: %d (%c)\n", evt, evt); */ - posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(evt, &keysym)); - } - } while ( posted ); + posted += + SDL_PrivateKeyboard (SDL_RELEASED, + TranslateKey (evt, &keysym)); + } + } + while (posted); } -void AA_InitOSKeymap(_THIS) +void +AA_InitOSKeymap (_THIS) { - int i; - static const char *std_keys = " 01234567890&#'()_-|$*+-=/\\:;.,!?<>{}[]@~%^\x9"; - const char *std; - - /* Initialize the AAlib key translation table */ - for ( i=0; i{}[]@~%^\x9"; + const char *std; + + /* Initialize the AAlib key translation table */ + for (i = 0; i < SDL_arraysize (keymap); ++i) + keymap[i] = SDLK_UNKNOWN; + + /* Alphabet keys */ + for (i = 0; i < 26; ++i) { + keymap['a' + i] = SDLK_a + i; + keymap['A' + i] = SDLK_a + i; + } + /* Function keys */ + for (i = 0; i < 12; ++i) { + keymap[334 + i] = SDLK_F1 + i; + } + /* Keys that have the same symbols and don't have to be translated */ + for (std = std_keys; *std; std++) { + keymap[*std] = *std; + } + + keymap[13] = SDLK_RETURN; + keymap[AA_BACKSPACE] = SDLK_BACKSPACE; + + keymap[369] = SDLK_LSHIFT; + keymap[370] = SDLK_RSHIFT; + keymap[371] = SDLK_LCTRL; + keymap[372] = SDLK_RCTRL; + keymap[377] = SDLK_LALT; + keymap[270] = SDLK_RALT; + keymap[271] = SDLK_NUMLOCK; + keymap[373] = SDLK_CAPSLOCK; + keymap[164] = SDLK_SCROLLOCK; + + keymap[243] = SDLK_INSERT; + keymap[304] = SDLK_DELETE; + keymap[224] = SDLK_HOME; + keymap[231] = SDLK_END; + keymap[229] = SDLK_PAGEUP; + keymap[230] = SDLK_PAGEDOWN; + + keymap[241] = SDLK_PRINT; + keymap[163] = SDLK_BREAK; + + keymap[302] = SDLK_KP0; + keymap[300] = SDLK_KP1; + keymap[297] = SDLK_KP2; + keymap[299] = SDLK_KP3; + keymap[294] = SDLK_KP4; + keymap[301] = SDLK_KP5; + keymap[296] = SDLK_KP6; + keymap[293] = SDLK_KP7; + keymap[295] = SDLK_KP8; + keymap[298] = SDLK_KP9; + + keymap[AA_ESC] = SDLK_ESCAPE; + keymap[AA_UP] = SDLK_UP; + keymap[AA_DOWN] = SDLK_DOWN; + keymap[AA_LEFT] = SDLK_LEFT; + keymap[AA_RIGHT] = SDLK_RIGHT; } -static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) +static SDL_keysym * +TranslateKey (int scancode, SDL_keysym * keysym) { - /* Sanity check */ - if ( scancode >= SDL_arraysize(keymap) ) - scancode = AA_UNKNOWN; - - /* Set the keysym information */ - keysym->scancode = scancode; - keysym->sym = keymap[scancode]; - keysym->mod = KMOD_NONE; - - /* If UNICODE is on, get the UNICODE value for the key */ - keysym->unicode = 0; - if ( SDL_TranslateUNICODE ) { - /* Populate the unicode field with the ASCII value */ - keysym->unicode = scancode; - } - return(keysym); + /* Sanity check */ + if (scancode >= SDL_arraysize (keymap)) + scancode = AA_UNKNOWN; + + /* Set the keysym information */ + keysym->scancode = scancode; + keysym->sym = keymap[scancode]; + keysym->mod = KMOD_NONE; + + /* If UNICODE is on, get the UNICODE value for the key */ + keysym->unicode = 0; + if (SDL_TranslateUNICODE) { + /* Populate the unicode field with the ASCII value */ + keysym->unicode = scancode; + } + return (keysym); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/aalib/SDL_aaevents_c.h b/src/video/aalib/SDL_aaevents_c.h index 37a1c2e30..8b084ca5f 100644 --- a/src/video/aalib/SDL_aaevents_c.h +++ b/src/video/aalib/SDL_aaevents_c.h @@ -26,10 +26,11 @@ /* Variables and functions exported by SDL_sysevents.c to other parts of the native video subsystem (SDL_sysvideo.c) */ -extern void AA_initkeymaps(int fd); -extern void AA_mousecallback(int button, int dx, int dy, - int u1,int u2,int u3, int u4); -extern void AA_keyboardcallback(int scancode, int pressed); +extern void AA_initkeymaps (int fd); +extern void AA_mousecallback (int button, int dx, int dy, + int u1, int u2, int u3, int u4); +extern void AA_keyboardcallback (int scancode, int pressed); -extern void AA_InitOSKeymap(_THIS); -extern void AA_PumpEvents(_THIS); +extern void AA_InitOSKeymap (_THIS); +extern void AA_PumpEvents (_THIS); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/aalib/SDL_aamouse.c b/src/video/aalib/SDL_aamouse.c index eed197d44..8a1a72d09 100644 --- a/src/video/aalib/SDL_aamouse.c +++ b/src/video/aalib/SDL_aamouse.c @@ -30,6 +30,8 @@ /* The implementation dependent data for the window manager cursor */ -struct WMcursor { - int unused; +struct WMcursor +{ + int unused; }; +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/aalib/SDL_aamouse_c.h b/src/video/aalib/SDL_aamouse_c.h index 8e06cf2ff..00752bea2 100644 --- a/src/video/aalib/SDL_aamouse_c.h +++ b/src/video/aalib/SDL_aamouse_c.h @@ -24,3 +24,4 @@ #include "SDL_aavideo.h" /* Functions to be exported */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/aalib/SDL_aavideo.c b/src/video/aalib/SDL_aavideo.c index 3ec322eab..72e11fc5c 100644 --- a/src/video/aalib/SDL_aavideo.c +++ b/src/video/aalib/SDL_aavideo.c @@ -41,348 +41,386 @@ #include /* Initialization/Query functions */ -static int AA_VideoInit(_THIS, SDL_PixelFormat *vformat); -static SDL_Rect **AA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); -static SDL_Surface *AA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); -static int AA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); -static void AA_VideoQuit(_THIS); +static int AA_VideoInit (_THIS, SDL_PixelFormat * vformat); +static SDL_Rect **AA_ListModes (_THIS, SDL_PixelFormat * format, + Uint32 flags); +static SDL_Surface *AA_SetVideoMode (_THIS, SDL_Surface * current, int width, + int height, int bpp, Uint32 flags); +static int AA_SetColors (_THIS, int firstcolor, int ncolors, + SDL_Color * colors); +static void AA_VideoQuit (_THIS); /* Hardware surface functions */ -static int AA_AllocHWSurface(_THIS, SDL_Surface *surface); -static int AA_LockHWSurface(_THIS, SDL_Surface *surface); -static int AA_FlipHWSurface(_THIS, SDL_Surface *surface); -static void AA_UnlockHWSurface(_THIS, SDL_Surface *surface); -static void AA_FreeHWSurface(_THIS, SDL_Surface *surface); +static int AA_AllocHWSurface (_THIS, SDL_Surface * surface); +static int AA_LockHWSurface (_THIS, SDL_Surface * surface); +static int AA_FlipHWSurface (_THIS, SDL_Surface * surface); +static void AA_UnlockHWSurface (_THIS, SDL_Surface * surface); +static void AA_FreeHWSurface (_THIS, SDL_Surface * surface); /* Cache the VideoDevice struct */ static struct SDL_VideoDevice *local_this; /* AAlib driver bootstrap functions */ -static int AA_Available(void) +static int +AA_Available (void) { - return 1; /* Always available ! */ + return 1; /* Always available ! */ } -static void AA_DeleteDevice(SDL_VideoDevice *device) +static void +AA_DeleteDevice (SDL_VideoDevice * device) { - SDL_free(device->hidden); - SDL_free(device); + SDL_free (device->hidden); + SDL_free (device); } -static SDL_VideoDevice *AA_CreateDevice(int devindex) +static SDL_VideoDevice * +AA_CreateDevice (int devindex) { - SDL_VideoDevice *device; - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); - if ( device ) { - SDL_memset(device, 0, (sizeof *device)); - device->hidden = (struct SDL_PrivateVideoData *) - SDL_malloc((sizeof *device->hidden)); - } - if ( (device == NULL) || (device->hidden == NULL) ) { - SDL_OutOfMemory(); - if ( device ) { - SDL_free(device); - } - return(0); - } - SDL_memset(device->hidden, 0, (sizeof *device->hidden)); - - /* Set the function pointers */ - device->VideoInit = AA_VideoInit; - device->ListModes = AA_ListModes; - device->SetVideoMode = AA_SetVideoMode; - device->CreateYUVOverlay = NULL; - device->SetColors = AA_SetColors; - device->UpdateRects = NULL; - device->VideoQuit = AA_VideoQuit; - device->AllocHWSurface = AA_AllocHWSurface; - device->CheckHWBlit = NULL; - device->FillHWRect = NULL; - device->SetHWColorKey = NULL; - device->SetHWAlpha = NULL; - device->LockHWSurface = AA_LockHWSurface; - device->UnlockHWSurface = AA_UnlockHWSurface; - device->FlipHWSurface = NULL; - device->FreeHWSurface = AA_FreeHWSurface; - device->SetCaption = NULL; - device->SetIcon = NULL; - device->IconifyWindow = NULL; - device->GrabInput = NULL; - device->GetWMInfo = NULL; - device->InitOSKeymap = AA_InitOSKeymap; - device->PumpEvents = AA_PumpEvents; - - device->free = AA_DeleteDevice; - - return device; + SDL_VideoDevice *device; + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); + if (device) { + SDL_memset (device, 0, (sizeof *device)); + device->hidden = (struct SDL_PrivateVideoData *) + SDL_malloc ((sizeof *device->hidden)); + } + if ((device == NULL) || (device->hidden == NULL)) { + SDL_OutOfMemory (); + if (device) { + SDL_free (device); + } + return (0); + } + SDL_memset (device->hidden, 0, (sizeof *device->hidden)); + + /* Set the function pointers */ + device->VideoInit = AA_VideoInit; + device->ListModes = AA_ListModes; + device->SetVideoMode = AA_SetVideoMode; + device->CreateYUVOverlay = NULL; + device->SetColors = AA_SetColors; + device->UpdateRects = NULL; + device->VideoQuit = AA_VideoQuit; + device->AllocHWSurface = AA_AllocHWSurface; + device->CheckHWBlit = NULL; + device->FillHWRect = NULL; + device->SetHWColorKey = NULL; + device->SetHWAlpha = NULL; + device->LockHWSurface = AA_LockHWSurface; + device->UnlockHWSurface = AA_UnlockHWSurface; + device->FlipHWSurface = NULL; + device->FreeHWSurface = AA_FreeHWSurface; + device->SetCaption = NULL; + device->SetIcon = NULL; + device->IconifyWindow = NULL; + device->GrabInput = NULL; + device->GetWMInfo = NULL; + device->InitOSKeymap = AA_InitOSKeymap; + device->PumpEvents = AA_PumpEvents; + + device->free = AA_DeleteDevice; + + return device; } VideoBootStrap AALIB_bootstrap = { - "aalib", "ASCII Art Library", - AA_Available, AA_CreateDevice + "aalib", "ASCII Art Library", + AA_Available, AA_CreateDevice }; -static void AA_ResizeHandler(aa_context *); +static void AA_ResizeHandler (aa_context *); -int AA_VideoInit(_THIS, SDL_PixelFormat *vformat) +int +AA_VideoInit (_THIS, SDL_PixelFormat * vformat) { - int keyboard; - int i; - - /* Initialize all variables that we clean on shutdown */ - for ( i=0; ix = SDL_modelist[i]->y = 0; - } - /* Modes sorted largest to smallest */ - SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768; - SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600; - SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480; - SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400; - SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240; - SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200; - SDL_modelist[6] = NULL; - - /* Initialize the library */ - - AA_mutex = SDL_CreateMutex(); - - aa_parseoptions (NULL, NULL, NULL, NULL); - - AA_context = aa_autoinit(&aa_defparams); - if ( ! AA_context ) { - SDL_SetError("Unable to initialize AAlib"); - return(-1); - } - - /* Enable mouse and keyboard support */ - - if ( ! aa_autoinitkbd (AA_context, AA_SENDRELEASE) ) { - SDL_SetError("Unable to initialize AAlib keyboard"); - return(-1); - } - if ( ! aa_autoinitmouse (AA_context, AA_SENDRELEASE) ) { - fprintf(stderr,"Warning: Unable to initialize AAlib mouse"); - } - AA_rparams = aa_getrenderparams(); - - local_this = this; - - aa_resizehandler(AA_context, AA_ResizeHandler); - - fprintf(stderr,"Using AAlib driver: %s (%s)\n", AA_context->driver->name, AA_context->driver->shortname); - - AA_in_x11 = (SDL_strcmp(AA_context->driver->shortname,"X11") == 0); - /* Determine the screen depth (use default 8-bit depth) */ - vformat->BitsPerPixel = 8; - vformat->BytesPerPixel = 1; - - /* We're done! */ - return(0); + int keyboard; + int i; + + /* Initialize all variables that we clean on shutdown */ + for (i = 0; i < SDL_NUMMODES; ++i) { + SDL_modelist[i] = SDL_malloc (sizeof (SDL_Rect)); + SDL_modelist[i]->x = SDL_modelist[i]->y = 0; + } + /* Modes sorted largest to smallest */ + SDL_modelist[0]->w = 1024; + SDL_modelist[0]->h = 768; + SDL_modelist[1]->w = 800; + SDL_modelist[1]->h = 600; + SDL_modelist[2]->w = 640; + SDL_modelist[2]->h = 480; + SDL_modelist[3]->w = 320; + SDL_modelist[3]->h = 400; + SDL_modelist[4]->w = 320; + SDL_modelist[4]->h = 240; + SDL_modelist[5]->w = 320; + SDL_modelist[5]->h = 200; + SDL_modelist[6] = NULL; + + /* Initialize the library */ + + AA_mutex = SDL_CreateMutex (); + + aa_parseoptions (NULL, NULL, NULL, NULL); + + AA_context = aa_autoinit (&aa_defparams); + if (!AA_context) { + SDL_SetError ("Unable to initialize AAlib"); + return (-1); + } + + /* Enable mouse and keyboard support */ + + if (!aa_autoinitkbd (AA_context, AA_SENDRELEASE)) { + SDL_SetError ("Unable to initialize AAlib keyboard"); + return (-1); + } + if (!aa_autoinitmouse (AA_context, AA_SENDRELEASE)) { + fprintf (stderr, "Warning: Unable to initialize AAlib mouse"); + } + AA_rparams = aa_getrenderparams (); + + local_this = this; + + aa_resizehandler (AA_context, AA_ResizeHandler); + + fprintf (stderr, "Using AAlib driver: %s (%s)\n", + AA_context->driver->name, AA_context->driver->shortname); + + AA_in_x11 = (SDL_strcmp (AA_context->driver->shortname, "X11") == 0); + /* Determine the screen depth (use default 8-bit depth) */ + vformat->BitsPerPixel = 8; + vformat->BytesPerPixel = 1; + + /* We're done! */ + return (0); } -SDL_Rect **AA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) +SDL_Rect ** +AA_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) { - if(format->BitsPerPixel != 8) - return NULL; - - if ( flags & SDL_FULLSCREEN ) { - return SDL_modelist; - } else { - return (SDL_Rect **) -1; - } + if (format->BitsPerPixel != 8) + return NULL; + + if (flags & SDL_FULLSCREEN) { + return SDL_modelist; + } else { + return (SDL_Rect **) - 1; + } } /* From aavga.c AAlib does not give us the choice of the actual resolution, thus we have to simulate additional resolution by scaling down manually each frame */ -static void fastscale (register char *b1, register char *b2, int x1, int x2, int y1, int y2) +static void +fastscale (register char *b1, register char *b2, int x1, int x2, int y1, + int y2) { - register int ex, spx = 0, ddx, ddx1; - int ddy1, ddy, spy = 0, ey; - int x; - char *bb1 = b1; - if (!x1 || !x2 || !y1 || !y2) - return; - ddx = x1 + x1; - ddx1 = x2 + x2; - if (ddx1 < ddx) - spx = ddx / ddx1, ddx %= ddx1; - ddy = y1 + y1; - ddy1 = y2 + y2; - if (ddy1 < ddy) - spy = (ddy / ddy1) * x1, ddy %= ddy1; - ey = -ddy1; - for (; y2; y2--) { - ex = -ddx1; - for (x = x2; x; x--) { - *b2 = *b1; - b2++; - b1 += spx; - ex += ddx; - if (ex > 0) { - b1++; - ex -= ddx1; - } - } - bb1 += spy; - ey += ddy; - if (ey > 0) { - bb1 += x1; - ey -= ddy1; - } - b1 = bb1; - } + register int ex, spx = 0, ddx, ddx1; + int ddy1, ddy, spy = 0, ey; + int x; + char *bb1 = b1; + if (!x1 || !x2 || !y1 || !y2) + return; + ddx = x1 + x1; + ddx1 = x2 + x2; + if (ddx1 < ddx) + spx = ddx / ddx1, ddx %= ddx1; + ddy = y1 + y1; + ddy1 = y2 + y2; + if (ddy1 < ddy) + spy = (ddy / ddy1) * x1, ddy %= ddy1; + ey = -ddy1; + for (; y2; y2--) { + ex = -ddx1; + for (x = x2; x; x--) { + *b2 = *b1; + b2++; + b1 += spx; + ex += ddx; + if (ex > 0) { + b1++; + ex -= ddx1; + } + } + bb1 += spy; + ey += ddy; + if (ey > 0) { + bb1 += x1; + ey -= ddy1; + } + b1 = bb1; + } } /* Various screen update functions available */ -static void AA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); +static void AA_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); -SDL_Surface *AA_SetVideoMode(_THIS, SDL_Surface *current, - int width, int height, int bpp, Uint32 flags) +SDL_Surface * +AA_SetVideoMode (_THIS, SDL_Surface * current, + int width, int height, int bpp, Uint32 flags) { - int mode; + int mode; - if ( AA_buffer ) { - SDL_free( AA_buffer ); - } + if (AA_buffer) { + SDL_free (AA_buffer); + } - AA_buffer = SDL_malloc(width * height); - if ( ! AA_buffer ) { - SDL_SetError("Couldn't allocate buffer for requested mode"); - return(NULL); - } + AA_buffer = SDL_malloc (width * height); + if (!AA_buffer) { + SDL_SetError ("Couldn't allocate buffer for requested mode"); + return (NULL); + } /* printf("Setting mode %dx%d\n", width, height); */ - SDL_memset(aa_image(AA_context), 0, aa_imgwidth(AA_context) * aa_imgheight(AA_context)); - SDL_memset(AA_buffer, 0, width * height); + SDL_memset (aa_image (AA_context), 0, + aa_imgwidth (AA_context) * aa_imgheight (AA_context)); + SDL_memset (AA_buffer, 0, width * height); - /* Allocate the new pixel format for the screen */ - if ( ! SDL_ReallocFormat(current, 8, 0, 0, 0, 0) ) { - return(NULL); - } + /* Allocate the new pixel format for the screen */ + if (!SDL_ReallocFormat (current, 8, 0, 0, 0, 0)) { + return (NULL); + } - /* Set up the new mode framebuffer */ - current->flags = SDL_FULLSCREEN; - AA_w = current->w = width; - AA_h = current->h = height; - current->pitch = current->w; - current->pixels = AA_buffer; + /* Set up the new mode framebuffer */ + current->flags = SDL_FULLSCREEN; + AA_w = current->w = width; + AA_h = current->h = height; + current->pitch = current->w; + current->pixels = AA_buffer; - AA_x_ratio = ((double)aa_imgwidth(AA_context)) / ((double)width); - AA_y_ratio = ((double)aa_imgheight(AA_context)) / ((double)height); + AA_x_ratio = ((double) aa_imgwidth (AA_context)) / ((double) width); + AA_y_ratio = ((double) aa_imgheight (AA_context)) / ((double) height); - /* Set the blit function */ - this->UpdateRects = AA_DirectUpdate; + /* Set the blit function */ + this->UpdateRects = AA_DirectUpdate; - /* We're done */ - return(current); + /* We're done */ + return (current); } -static void AA_ResizeHandler(aa_context *context) +static void +AA_ResizeHandler (aa_context * context) { - aa_resize(context); - local_this->hidden->x_ratio = ((double)aa_imgwidth(context)) / ((double)local_this->screen->w); - local_this->hidden->y_ratio = ((double)aa_imgheight(context)) / ((double)local_this->screen->h); - - fastscale (local_this->hidden->buffer, aa_image(context), local_this->hidden->w, aa_imgwidth (context), local_this->hidden->h, aa_imgheight (context)); - aa_renderpalette(context, local_this->hidden->palette, local_this->hidden->rparams, 0, 0, aa_scrwidth(context), aa_scrheight(context)); - aa_flush(context); + aa_resize (context); + local_this->hidden->x_ratio = + ((double) aa_imgwidth (context)) / ((double) local_this->screen->w); + local_this->hidden->y_ratio = + ((double) aa_imgheight (context)) / ((double) local_this->screen->h); + + fastscale (local_this->hidden->buffer, aa_image (context), + local_this->hidden->w, aa_imgwidth (context), + local_this->hidden->h, aa_imgheight (context)); + aa_renderpalette (context, local_this->hidden->palette, + local_this->hidden->rparams, 0, 0, + aa_scrwidth (context), aa_scrheight (context)); + aa_flush (context); } /* We don't actually allow hardware surfaces other than the main one */ -static int AA_AllocHWSurface(_THIS, SDL_Surface *surface) +static int +AA_AllocHWSurface (_THIS, SDL_Surface * surface) { - return(-1); + return (-1); } -static void AA_FreeHWSurface(_THIS, SDL_Surface *surface) +static void +AA_FreeHWSurface (_THIS, SDL_Surface * surface) { - return; + return; } /* We need to wait for vertical retrace on page flipped displays */ -static int AA_LockHWSurface(_THIS, SDL_Surface *surface) +static int +AA_LockHWSurface (_THIS, SDL_Surface * surface) { - /* TODO ? */ - return(0); + /* TODO ? */ + return (0); } -static void AA_UnlockHWSurface(_THIS, SDL_Surface *surface) +static void +AA_UnlockHWSurface (_THIS, SDL_Surface * surface) { - return; + return; } /* FIXME: How is this done with AAlib? */ -static int AA_FlipHWSurface(_THIS, SDL_Surface *surface) +static int +AA_FlipHWSurface (_THIS, SDL_Surface * surface) { - SDL_mutexP(AA_mutex); - aa_flush(AA_context); - SDL_mutexV(AA_mutex); - return(0); + SDL_mutexP (AA_mutex); + aa_flush (AA_context); + SDL_mutexV (AA_mutex); + return (0); } -static void AA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) +static void +AA_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) { - int i; - SDL_Rect *rect; + int i; + SDL_Rect *rect; - fastscale (AA_buffer, aa_image(AA_context), AA_w, aa_imgwidth (AA_context), AA_h, aa_imgheight (AA_context)); + fastscale (AA_buffer, aa_image (AA_context), AA_w, + aa_imgwidth (AA_context), AA_h, aa_imgheight (AA_context)); #if 1 - aa_renderpalette(AA_context, AA_palette, AA_rparams, 0, 0, aa_scrwidth(AA_context), aa_scrheight(AA_context)); + aa_renderpalette (AA_context, AA_palette, AA_rparams, 0, 0, + aa_scrwidth (AA_context), aa_scrheight (AA_context)); #else - /* Render only the rectangles in the list */ - printf("Update rects : "); - for ( i=0; i < numrects; ++i ) { - rect = &rects[i]; - printf("(%d,%d-%d,%d)", rect->x, rect->y, rect->w, rect->h); - aa_renderpalette(AA_context, AA_palette, AA_rparams, rect->x * AA_x_ratio, rect->y * AA_y_ratio, rect->w * AA_x_ratio, rect->h * AA_y_ratio); - } - printf("\n"); + /* Render only the rectangles in the list */ + printf ("Update rects : "); + for (i = 0; i < numrects; ++i) { + rect = &rects[i]; + printf ("(%d,%d-%d,%d)", rect->x, rect->y, rect->w, rect->h); + aa_renderpalette (AA_context, AA_palette, AA_rparams, + rect->x * AA_x_ratio, rect->y * AA_y_ratio, + rect->w * AA_x_ratio, rect->h * AA_y_ratio); + } + printf ("\n"); #endif - SDL_mutexP(AA_mutex); - aa_flush(AA_context); - SDL_mutexV(AA_mutex); - return; + SDL_mutexP (AA_mutex); + aa_flush (AA_context); + SDL_mutexV (AA_mutex); + return; } -int AA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) +int +AA_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) { - int i; - - for ( i=0; i < ncolors; i++ ) { - aa_setpalette(AA_palette, firstcolor + i, - colors[i].r>>2, - colors[i].g>>2, - colors[i].b>>2); - } - return(1); + int i; + + for (i = 0; i < ncolors; i++) { + aa_setpalette (AA_palette, firstcolor + i, + colors[i].r >> 2, colors[i].g >> 2, colors[i].b >> 2); + } + return (1); } /* Note: If we are terminated, this could be called in the middle of another SDL video routine -- notably UpdateRects. */ -void AA_VideoQuit(_THIS) +void +AA_VideoQuit (_THIS) { - int i; + int i; - aa_uninitkbd(AA_context); - aa_uninitmouse(AA_context); + aa_uninitkbd (AA_context); + aa_uninitmouse (AA_context); - /* Free video mode lists */ - for ( i=0; iscreen->pixels = NULL; + SDL_DestroyMutex (AA_mutex); + + this->screen->pixels = NULL; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/aalib/SDL_aavideo.h b/src/video/aalib/SDL_aavideo.h index cd70c9f16..07f9d84af 100644 --- a/src/video/aalib/SDL_aavideo.h +++ b/src/video/aalib/SDL_aavideo.h @@ -36,12 +36,13 @@ #define SDL_NUMMODES 6 /* Private display data */ -struct SDL_PrivateVideoData { - SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; - aa_context *context; - aa_palette palette; - aa_renderparams *rparams; - double x_ratio, y_ratio; +struct SDL_PrivateVideoData +{ + SDL_Rect *SDL_modelist[SDL_NUMMODES + 1]; + aa_context *context; + aa_palette palette; + aa_renderparams *rparams; + double x_ratio, y_ratio; int w, h; SDL_mutex *mutex; int in_x11; @@ -64,3 +65,4 @@ struct SDL_PrivateVideoData { #define AA_h (this->hidden->h) #endif /* _SDL_aavideo_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ataricommon/SDL_ataric2p_s.h b/src/video/ataricommon/SDL_ataric2p_s.h index a8f97e2ef..af5daf999 100644 --- a/src/video/ataricommon/SDL_ataric2p_s.h +++ b/src/video/ataricommon/SDL_ataric2p_s.h @@ -30,46 +30,41 @@ /* Convert a chunky screen to bitplane screen */ -extern void (*SDL_Atari_C2pConvert)( - Uint8 *src, /* Source screen (one byte=one pixel) */ - Uint8 *dest, /* Destination (4/8 bits planes) */ - Uint32 width, /* Dimensions of screen to convert */ - Uint32 height, - Uint32 dblligne, /* Double the lines when converting ? */ - Uint32 srcpitch, /* Length of one source line in bytes */ - Uint32 dstpitch /* Length of one destination line in bytes */ -); +extern void (*SDL_Atari_C2pConvert) (Uint8 * src, /* Source screen (one byte=one pixel) */ + Uint8 * dest, /* Destination (4/8 bits planes) */ + Uint32 width, /* Dimensions of screen to convert */ + Uint32 height, Uint32 dblligne, /* Double the lines when converting ? */ + Uint32 srcpitch, /* Length of one source line in bytes */ + Uint32 dstpitch /* Length of one destination line in bytes */ + ); /*--- 8 bits functions ---*/ /* Convert a chunky screen to bitplane screen */ -void SDL_Atari_C2pConvert8( - Uint8 *src, /* Source screen (one byte=one pixel) */ - Uint8 *dest, /* Destination (8 bits planes) */ - Uint32 width, /* Dimensions of screen to convert */ - Uint32 height, - Uint32 dblligne, /* Double the lines when converting ? */ - Uint32 srcpitch, /* Length of one source line in bytes */ - Uint32 dstpitch /* Length of one destination line in bytes */ -); +void SDL_Atari_C2pConvert8 (Uint8 * src, /* Source screen (one byte=one pixel) */ + Uint8 * dest, /* Destination (8 bits planes) */ + Uint32 width, /* Dimensions of screen to convert */ + Uint32 height, Uint32 dblligne, /* Double the lines when converting ? */ + Uint32 srcpitch, /* Length of one source line in bytes */ + Uint32 dstpitch /* Length of one destination line in bytes */ + ); /*--- 4 bits functions ---*/ /* Convert a chunky screen to bitplane screen */ -void SDL_Atari_C2pConvert4( - Uint8 *src, /* Source screen (one byte=one pixel) */ - Uint8 *dest, /* Destination (4 bits planes) */ - Uint32 width, /* Dimensions of screen to convert */ - Uint32 height, - Uint32 dblligne, /* Double the lines when converting ? */ - Uint32 srcpitch, /* Length of one source line in bytes */ - Uint32 dstpitch /* Length of one destination line in bytes */ -); +void SDL_Atari_C2pConvert4 (Uint8 * src, /* Source screen (one byte=one pixel) */ + Uint8 * dest, /* Destination (4 bits planes) */ + Uint32 width, /* Dimensions of screen to convert */ + Uint32 height, Uint32 dblligne, /* Double the lines when converting ? */ + Uint32 srcpitch, /* Length of one source line in bytes */ + Uint32 dstpitch /* Length of one destination line in bytes */ + ); /* Conversion palette */ -void SDL_Atari_C2pConvert4_pal(Uint16 *lightpalette); +void SDL_Atari_C2pConvert4_pal (Uint16 * lightpalette); #endif /* _ATARI_C2P_h */ +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ataricommon/SDL_ataridevmouse.c b/src/video/ataricommon/SDL_ataridevmouse.c index b1e735727..324bea85b 100644 --- a/src/video/ataricommon/SDL_ataridevmouse.c +++ b/src/video/ataricommon/SDL_ataridevmouse.c @@ -44,116 +44,123 @@ static int mouseb, prev_mouseb; /* Functions */ -int SDL_AtariDevMouse_Open(void) +int +SDL_AtariDevMouse_Open (void) { - int r; - const char *mousedev; - - /* - TODO: Fix the MiNT device driver, that locks mouse for other - applications, so this is disabled till fixed - */ - return 0; - - /* First, try SDL_MOUSEDEV device */ - mousedev = SDL_getenv("SDL_MOUSEDEV"); - if (!mousedev) { - handle = open(mousedev, 0); - } - - /* Failed, try default device */ - if (handle<0) { - handle = open(DEVICE_NAME, 0); - } - - if (handle<0) { - handle = -1; - return 0; - } - - /* Set non blocking mode */ - r = fcntl(handle, F_GETFL, 0); - if (r<0) { - close(handle); - handle = -1; - return 0; - } - - r |= O_NDELAY; - - r = fcntl(handle, F_SETFL, r); - if (r<0) { - close(handle); - handle = -1; - return 0; - } - - prev_mouseb = 7; - return 1; + int r; + const char *mousedev; + + /* + TODO: Fix the MiNT device driver, that locks mouse for other + applications, so this is disabled till fixed + */ + return 0; + + /* First, try SDL_MOUSEDEV device */ + mousedev = SDL_getenv ("SDL_MOUSEDEV"); + if (!mousedev) { + handle = open (mousedev, 0); + } + + /* Failed, try default device */ + if (handle < 0) { + handle = open (DEVICE_NAME, 0); + } + + if (handle < 0) { + handle = -1; + return 0; + } + + /* Set non blocking mode */ + r = fcntl (handle, F_GETFL, 0); + if (r < 0) { + close (handle); + handle = -1; + return 0; + } + + r |= O_NDELAY; + + r = fcntl (handle, F_SETFL, r); + if (r < 0) { + close (handle); + handle = -1; + return 0; + } + + prev_mouseb = 7; + return 1; } -void SDL_AtariDevMouse_Close(void) +void +SDL_AtariDevMouse_Close (void) { - if (handle>0) { - close(handle); - handle = -1; - } + if (handle > 0) { + close (handle); + handle = -1; + } } -static int atari_GetButton(int button) +static int +atari_GetButton (int button) { - switch(button) - { - case 0: - return SDL_BUTTON_RIGHT; - case 1: - return SDL_BUTTON_MIDDLE; - default: - break; - } - - return SDL_BUTTON_LEFT; + switch (button) { + case 0: + return SDL_BUTTON_RIGHT; + case 1: + return SDL_BUTTON_MIDDLE; + default: + break; + } + + return SDL_BUTTON_LEFT; } -void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents) +void +SDL_AtariDevMouse_PostMouseEvents (_THIS, SDL_bool buttonEvents) { - unsigned char buffer[3]; - int mousex, mousey; - - if (handle<0) { - return; - } - - mousex = mousey = 0; - while (read(handle, buffer, sizeof(buffer))==sizeof(buffer)) { - mouseb = buffer[0] & 7; - mousex += (char) buffer[1]; - mousey += (char) buffer[2]; - - /* Mouse button events */ - if (buttonEvents && (mouseb != prev_mouseb)) { - int i; - - for (i=0;i<3;i++) { - int curbutton, prevbutton; - - curbutton = mouseb & (1<