X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Flib%2Fallegro4%2Fallegro.pas;h=0560035d927097633e50020754300fea258a49ca;hb=23c3f9ee3fc3837cd1d0380496a2e1b0f87833d8;hp=ae5adb593452a0411cffba3bd404cf2bdac94f3f;hpb=1d24275aa4b72cac9efc1e14ba377307f89d7728;p=d2df-sdl.git diff --git a/src/lib/allegro4/allegro.pas b/src/lib/allegro4/allegro.pas index ae5adb5..0560035 100644 --- a/src/lib/allegro4/allegro.pas +++ b/src/lib/allegro4/allegro.pas @@ -8,13 +8,14 @@ {$DEFINE LibraryLibAllegroDecl := cdecl} {$DEFINE LibraryLibAllegroImp := cdecl; external} {$DEFINE LibraryLibAllegroVar := cvar; external} -{$ELSEIF DEFINED(UNIX)} - {$LINKLIB liballeg.so} +{$ELSEIF DEFINED(WINDOWS)} + {$DEFINE LibraryLibAllegroDecl := cdecl} + {$DEFINE LibraryLibAllegroImp := cdecl; external 'alleg42.dll'} + {$DEFINE LibraryLibAllegroVar := external 'alleg42.dll'} +{$ELSE} {$DEFINE LibraryLibAllegroDecl := cdecl} {$DEFINE LibraryLibAllegroImp := cdecl; external 'alleg'} {$DEFINE LibraryLibAllegroVar := cvar; external 'alleg'} -{$ELSE} - {$ERROR unsupported platform!} {$ENDIF} unit allegro; @@ -24,18 +25,16 @@ interface uses ctypes; const -{$IF DEFINED(GO32V2)} +{$IF DEFINED(GO32V2) OR DEFINED(WINDOWS)} ALLEGRO_VERSION = 4; ALEGRO_SUB_VERSION = 2; ALLEGRO_WIP_VERSION = 3; ALLEGRO_VERSION_STR = '4.2.3'; -{$ELSEIF DEFINED(UNIX)} +{$ELSE} ALLEGRO_VERSION = 4; ALEGRO_SUB_VERSION = 4; ALLEGRO_WIP_VERSION = 2; ALLEGRO_VERSION_STR = '4.4.2'; -{$ELSE} - {$ERROR unsupported platform!} {$ENDIF} SYSTEM_AUTODETECT = 0; @@ -47,6 +46,13 @@ interface GFX_AUTODETECT_WINDOWED = 2; GFX_SAFE = $53414645; + DRAW_MODE_SOLID = 0; + DRAW_MODE_XOR = 1; + DRAW_MODE_COPY_PATTERN = 2; + DRAW_MODE_SOLID_PATTERN = 3; + DRAW_MODE_MASKED_PATTERN = 4; + DRAW_MODE_TRANS = 5; + KEY_A = 1; KEY_B = 2; KEY_C = 3; @@ -193,6 +199,7 @@ interface KB_ACCENT4_FLAG = $8000; ALLEGRO_ERROR_SIZE = 256; + PAL_SIZE = 256; type PBITMAP = ^BITMAP; @@ -223,14 +230,76 @@ interface mode: PGFX_MODE; end; + PGFX_DRIVER_T = ^GFX_DRIVER_T; + GFX_DRIVER_T = record + id: cint; + name: PChar; + desc: PChar; + ascii_name: PChar; + + init: Pointer; + exit: Pointer; + scroll: Pointer; + vsync: Pointer; + set_palette: Pointer; + request_scroll: Pointer; + poll_scroll: Pointer; + enable_triple_buffer: Pointer; + create_video_bitmap: Pointer; + destroy_video_bitmap: Pointer; + show_video_bitmap: Pointer; + request_video_bitmap: Pointer; + create_system_bitmap: Pointer; + destroy_system_bitmap: Pointer; + set_mouse_sprite: Pointer; + show_mouse: Pointer; + hide_mouse: Pointer; + move_mouse: Pointer; + drawing_mode: Pointer; + save_video_state: Pointer; + restore_video_state: Pointer; + set_blender_mode: Pointer; + fetch_mode_list: function (): PGFX_MODE_LIST; cdecl; + w, h: cint; + linear: cint; + bank_size: clong; + bank_gran: clong; + vid_mem: clong; + vid_phys_base: clong; + windowed: cint; + end; + + RGB = record + r, g, b, filler: cuchar; + end; + + PALETTE = array [0..PAL_SIZE - 1] of RGB; + PPALETTE = ^PALETTE; + + COLOR_MAP_T = record + data: array [0..PAL_SIZE - 1, 0..PAL_SIZE - 1] of cuchar; + end; + PCOLOR_MAP_T = ^COLOR_MAP_T; + KeyboardCallback = procedure (scancode: cint); LibraryLibAllegroDecl; AtExitCallback = procedure; LibraryLibAllegroDecl; AtExitFunction = function (func: AtExitCallback): cint; LibraryLibAllegroDecl; + TimerIntCallback = procedure; LibraryLibAllegroDecl; + QuitCallback = procedure; LibraryLibAllegroDecl; + CreateTableCallback = procedure (pos: cint); LibraryLibAllegroDecl; var allegro_id: array [0..ALLEGRO_ERROR_SIZE] of char; LibraryLibAllegroVar; allegro_error: array [0..ALLEGRO_ERROR_SIZE] of char; LibraryLibAllegroVar; keyboard_lowlevel_callback: KeyboardCallback; LibraryLibAllegroVar; + screen: PBITMAP; LibraryLibAllegroVar; + black_palette: PALETTE; LibraryLibAllegroVar; + desktop_palette: PALETTE; LibraryLibAllegroVar; + default_palette: PALETTE; LibraryLibAllegroVar; + _current_palette: PALETTE; LibraryLibAllegroVar; + key_shifts: cint; LibraryLibAllegroVar; + color_map: PCOLOR_MAP_T; LibraryLibAllegroVar; + gfx_driver: PGFX_DRIVER_T; LibraryLibAllegroVar; function get_desktop_resolution (width, height: Pcint): cint; LibraryLibAllegroImp; function get_gfx_mode_list (card: cint): PGFX_MODE_LIST; LibraryLibAllegroImp; @@ -245,9 +314,6 @@ interface procedure remove_keyboard; LibraryLibAllegroImp; function _install_allegro_version_check (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction; version: cint): cint; LibraryLibAllegroImp; - function install_allegro (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction): cint; inline; (* macros *) - function allegro_init: cint; inline; (* macros *) - function install_timer: cint; LibraryLibAllegroImp; procedure remove_timer; LibraryLibAllegroImp; procedure set_keyboard_rate (delay, _repeat: cint); LibraryLibAllegroImp; @@ -255,18 +321,92 @@ interface function makecol (r, g, b: cint): cint; LibraryLibAllegroImp; procedure clear_to_color (source: PBITMAP; color: cint); LibraryLibAllegroImp; procedure putpixel (bmp: PBITMAP; x, y, color: cint); LibraryLibAllegroImp; + function getpixel (bmp: PBITMAP; x, y: cint): cint; LibraryLibAllegroImp; procedure fastline (bmp: PBITMAP; x1, y_1, x2, y2, color: cint); LibraryLibAllegroImp; procedure draw_sprite (bmp, sprite: PBITMAP; x, y: cint); LibraryLibAllegroImp; + procedure draw_sprite_v_flip (bmp, sprite: PBITMAP; x, y: cint); LibraryLibAllegroImp; + procedure draw_sprite_h_flip (bmp, sprite: PBITMAP; x, y: cint); LibraryLibAllegroImp; + procedure draw_sprite_vh_flip (bmp, sprite: PBITMAP; x, y: cint); LibraryLibAllegroImp; procedure rect (bmp: PBITMAP; x1, y_1, x2, y2, color: cint); LibraryLibAllegroImp; procedure rectfill (bmp: PBITMAP; x1, y_1, x2, y2, color: cint); LibraryLibAllegroImp; function create_bitmap (width, height: cint): PBITMAP; LibraryLibAllegroImp; function create_system_bitmap (width, height: cint): PBITMAP; LibraryLibAllegroImp; procedure allegro_exit; LibraryLibAllegroImp; + procedure rest (time: cuint); LibraryLibAllegroImp; + function install_int_ex (proc: TimerIntCallback; speed: clong): cint; LibraryLibAllegroImp; + procedure blit (source, dest: PBITMAP; source_x, source_y, dest_x, dest_y, width, height: cint); LibraryLibAllegroImp; + procedure masked_blit (source, dest: PBITMAP; source_x, source_y, dest_x, dest_y, width, height: cint); LibraryLibAllegroImp; + procedure set_clip_rect (bitmap: PBITMAP; x1, y1, x2, y2: cint); LibraryLibAllegroImp; + procedure get_clip_rect (bitmap: PBITMAP; var x1, y1, x2, y2: cint); LibraryLibAllegroImp; + + procedure set_palette (const p: PALETTE); LibraryLibAllegroImp; + procedure set_color_depth (depth: cint); LibraryLibAllegroImp; + function set_close_button_callback (proc: QuitCallback): cint; LibraryLibAllegroImp; + // function _install_allegro (system_id: cint; errno_prt: Pcint; AtExitFunction): cint; LibraryLibAllegroImp; + procedure acquire_bitmap (bmp: PBITMAP); LibraryLibAllegroImp; + procedure release_bitmap (bmp: PBITMAP); LibraryLibAllegroImp; + procedure acquire_screen; LibraryLibAllegroImp; + procedure release_screen; LibraryLibAllegroImp; + + procedure rotate_sprite (bmp, sprite: PBITMAP; x, y: cint; a: cint32); LibraryLibAllegroImp; + procedure rotate_sprite_v_flip (bmp, sprite: PBITMAP; x, y: cint; a: cint32); LibraryLibAllegroImp; + + function scancode_to_ascii (scancode: cint): cint; LibraryLibAllegroImp; + function scancode_to_name (scancode: cint): PChar; LibraryLibAllegroImp; + + procedure drawing_mode (mode: cint; pattern: PBITMAP; x_anchor, y_anchor: cint); LibraryLibAllegroImp; + + procedure set_trans_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_alpha_blender; LibraryLibAllegroImp; + procedure set_write_alpha_blender; LibraryLibAllegroImp; + procedure set_add_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_burn_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_color_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_difference_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_dissolve_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_dodge_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_hue_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_invert_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_luminance_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_multiply_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_saturation_blender (r, g, b, a: cint); LibraryLibAllegroImp; + procedure set_screen_blender (r, g, b, a: cint); LibraryLibAllegroImp; + + function getr (col: cint): cint; LibraryLibAllegroImp; + function getg (col: cint): cint; LibraryLibAllegroImp; + function getb (col: cint): cint; LibraryLibAllegroImp; + function geta (col: cint): cint; LibraryLibAllegroImp; + + procedure create_light_table (table: PCOLOR_MAP_T; const pal: PALETTE; r, g, b: cint; callback: CreateTableCallback); LibraryLibAllegroImp; + procedure create_trans_table (table: PCOLOR_MAP_T; const pal: PALETTE; r, g, b: cint; callback: CreateTableCallback); LibraryLibAllegroImp; + + procedure vsync; LibraryLibAllegroImp; + function desktop_color_depth: cint; LibraryLibAllegroImp; + + (* MACRO *) + function install_allegro (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction): cint; inline; + function allegro_init: cint; inline; + + function TIMERS_PER_SECOND: clong; inline; + function SECS_TO_TIMER (x: clong): clong; inline; + function MSEC_TO_TIMER (x: clong): clong; inline; + function BPS_TO_TIMER (x: clong): clong; inline; + function BPM_TO_TIMER (x: clong): clong; inline; + + implementation + {$IF DEFINED(GO32V2)} + function atexit (func: AtexitCallback): cint; cdecl; external; + {$ELSEIF DEFINED(WINDOWS)} + function atexit (func: AtexitCallback): cint; cdecl; external 'msvcrt.dll'; + {$ELSE} + function atexit (func: AtexitCallback): cint; cdecl; external 'c'; + {$ENDIF} + function install_allegro (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction): cint; inline; begin install_allegro := _install_allegro_version_check(system_id, errno_ptr, atexit_ptr, (ALLEGRO_VERSION shl 16) OR (ALEGRO_SUB_VERSION shl 8) OR ALLEGRO_WIP_VERSION) @@ -274,9 +414,42 @@ implementation function allegro_init: cint; inline; begin - (* original macros sets atexit_ptr *) (* original macros sets libc errno? *) - allegro_init := _install_allegro_version_check(SYSTEM_AUTODETECT, nil, nil, (ALLEGRO_VERSION shl 16) OR (ALEGRO_SUB_VERSION shl 8) OR ALLEGRO_WIP_VERSION) + allegro_init := _install_allegro_version_check(SYSTEM_AUTODETECT, nil, @atexit, (ALLEGRO_VERSION shl 16) OR (ALEGRO_SUB_VERSION shl 8) OR ALLEGRO_WIP_VERSION) + end; + + function TIMERS_PER_SECOND: clong; inline; + begin + TIMERS_PER_SECOND := 1193181 + end; + + function SECS_TO_TIMER (x: clong): clong; inline; + begin + SECS_TO_TIMER := x * TIMERS_PER_SECOND + end; + + function MSEC_TO_TIMER (x: clong): clong; inline; + begin + MSEC_TO_TIMER := x * TIMERS_PER_SECOND div 1000 + end; + + function BPS_TO_TIMER (x: clong): clong; inline; + begin + BPS_TO_TIMER := TIMERS_PER_SECOND div x + end; + + function BPM_TO_TIMER (x: clong): clong; inline; + begin + BPM_TO_TIMER := 60 * TIMERS_PER_SECOND div x + end; + +(* + function acquire_bitmap (bmp: PBITMAP); inline; + begin + ASSERT(bmp <> nil); + if bmp.vtable.acquire <> nil then + bmp.vtable.acquire(bmp) end; +*) end.