From ed750d2e31615702f9c230ef4aabe890ea55abab Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Tue, 29 Jan 2019 14:50:17 +0300 Subject: [PATCH] more implemented functions for allegro port --- src/lib/allegro4/allegro.pas | 70 +++++++++++ src/nogl/noGLALSW.inc | 192 +++++++++++++++++++++++------- src/wrappers/sdl2/sdl2allegro.inc | 138 +++++++++++++++------ 3 files changed, 320 insertions(+), 80 deletions(-) diff --git a/src/lib/allegro4/allegro.pas b/src/lib/allegro4/allegro.pas index ae5adb5..0a1affe 100644 --- a/src/lib/allegro4/allegro.pas +++ b/src/lib/allegro4/allegro.pas @@ -47,6 +47,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 +200,7 @@ interface KB_ACCENT4_FLAG = $8000; ALLEGRO_ERROR_SIZE = 256; + PAL_SIZE = 256; type PBITMAP = ^BITMAP; @@ -223,14 +231,28 @@ interface mode: PGFX_MODE; end; + RGB = record + r, g, b, filler: cuchar; + end; + + PALETTE = array [0..PAL_SIZE - 1] of RGB; + PPALETTE = ^PALETTE; + KeyboardCallback = procedure (scancode: cint); LibraryLibAllegroDecl; AtExitCallback = procedure; LibraryLibAllegroDecl; AtExitFunction = function (func: AtExitCallback): cint; LibraryLibAllegroDecl; + TimerIntCallback = procedure; 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; function get_desktop_resolution (width, height: Pcint): cint; LibraryLibAllegroImp; function get_gfx_mode_list (card: cint): PGFX_MODE_LIST; LibraryLibAllegroImp; @@ -255,16 +277,37 @@ 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 _install_allegro (system_id: cint; errno_prt: Pcint; AtExitFunction): cint; LibraryLibAllegroImp; + (* MACRO *) + 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 function install_allegro (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction): cint; inline; @@ -279,4 +322,31 @@ implementation allegro_init := _install_allegro_version_check(SYSTEM_AUTODETECT, nil, nil, (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; + end. diff --git a/src/nogl/noGLALSW.inc b/src/nogl/noGLALSW.inc index 60b2072..55ee112 100644 --- a/src/nogl/noGLALSW.inc +++ b/src/nogl/noGLALSW.inc @@ -7,15 +7,19 @@ implementation const ValPerVertex = 2; - ValPerColor = 4; + ValPerColor = 1; (* colors stored in one integer *) ValPerCoord = 2; + StackSize = 16; type - TArrayFloat = array of Integer; + TArrayFloat = array of GLfloat; + TArrayInteger = array of Integer; TCmds = record mode: GLenum; - v, c, t: TArrayFloat; + v: TArrayInteger; + c: TArrayInteger; + t: TArrayFloat; end; TArrayTexture = array of record @@ -28,6 +32,11 @@ implementation tex: TArrayTexture; ctex: Integer; ccol: Integer; + clearColor: cint; + stack: array [0..StackSize - 1] of record + x, y: Integer; + end; + stack_ptr: Integer; function AddTexture: Integer; var i: Integer; @@ -54,10 +63,19 @@ implementation assert(tex[i].used); tex[i].used := false; if tex[i].bmp <> nil then - destroy_bitmap(tex[i].bmp) + destroy_bitmap(tex[i].bmp); + tex[i].bmp := nil end; - procedure Add (var x: TArrayFloat; f: Integer); + procedure Addi (var x: TArrayInteger; f: Integer); + var i: Integer; + begin + i := Length(x); + SetLength(x, i + 1); + x[i] := f; + end; + + procedure Addf (var x: TArrayFloat; f: GLfloat); var i: Integer; begin i := Length(x); @@ -86,14 +104,14 @@ implementation end; procedure glClearColor(red, green, blue, alpha: GLclampf); - var color: Integer; begin - color := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255)); - clear_to_color(sdl2allegro_screen, color) + clearColor := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255)); end; procedure glClear(mask: GLbitfield); begin + if (mask and GL_COLOR_BUFFER_BIT) <> 0 then + clear_to_color(sdl2allegro_screen, clearColor) end; procedure glAlphaFunc(func: GLenum; ref: GLclampf); @@ -136,13 +154,20 @@ implementation end; procedure glEnd; - var i, x, y, w, h: Integer; + var + i, j, k, w, h, x0, y0, x1, y1, offx, offy, tmp, s0, t0, s1, t1: Integer; + oldx0, oldy0, oldx1, oldy1: cint; + flipv, fliph: Boolean; + draw_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint); cdecl; begin assert(cmds.mode <> GL_INVALID_ENUM); assert(Length(cmds.v) mod ValPerVertex = 0); assert(Length(cmds.c) mod ValPerColor = 0); assert(Length(cmds.t) mod ValPerCoord = 0); + offx := stack[stack_ptr].x; + offy := stack[stack_ptr].y; + case cmds.mode of GL_POINTS: begin @@ -151,12 +176,12 @@ implementation begin assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *) for i := 0 to Length(cmds.v) div 2 - 1 do - putpixel(sdl2allegro_screen, cmds.v[i * 2], cmds.v[i * 2 + 1], cmds.c[i]) + putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], cmds.c[i]) end else begin for i := 0 to Length(cmds.v) div 2 - 1 do - putpixel(sdl2allegro_screen, cmds.v[i * 2], cmds.v[i * 2 + 1], ccol) + putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], ccol) end end; GL_LINES: @@ -167,43 +192,104 @@ implementation begin assert(Length(cmds.c) * 2 = Length(cmds.v)); for i := 0 to Length(cmds.v) div 4 - 1 do - fastline(sdl2allegro_screen, cmds.v[i * 4], cmds.v[i * 4 + 1], cmds.v[i * 4 + 2], cmds.v[i * 4 + 3], cmds.c[i * 2]) + fastline(sdl2allegro_screen, offx + cmds.v[i * 4], offy + cmds.v[i * 4 + 1], offx + cmds.v[i * 4 + 2], offy + cmds.v[i * 4 + 3], cmds.c[i * 2]) end else begin for i := 0 to Length(cmds.v) div 4 - 1 do - fastline(sdl2allegro_screen, cmds.v[i * 4], cmds.v[i * 4 + 1], cmds.v[i * 4 + 2], cmds.v[i * 4 + 3], ccol) + fastline(sdl2allegro_screen, offx + cmds.v[i * 4], offy + cmds.v[i * 4 + 1], offx + cmds.v[i * 4 + 2], offy + cmds.v[i * 4 + 3], ccol) end end; GL_QUADS: begin - assert(Length(cmds.v) mod 8 = 0); (* broken quad *) + ASSERT(Length(cmds.v) mod 8 = 0); (* broken quad *) if Length(cmds.t) <> 0 then begin - assert(Length(cmds.t) = Length(cmds.v)); (* not enough texture coords *) - assert(ctex >= 0); - assert(ctex <= High(tex)); + ASSERT(Length(cmds.t) = Length(cmds.v)); (* not enough texture coords *) + ASSERT(ctex >= 0); + ASSERT(ctex <= High(tex)); + ASSERT(tex[ctex].bmp <> nil); for i := 0 to Length(cmds.v) div 8 - 1 do begin - x := cmds.v[i * 8]; - y := cmds.v[i * 8 + 1]; - w := abs(cmds.v[i * 4 + 5] - x); - h := abs(cmds.v[i * 4 + 6] - y); - //e_LogWriteFLn('Textured Quad %s %s', [w, h]); - draw_sprite(sdl2allegro_screen, tex[ctex].bmp, x, y); - //rect(sdl2allegro_screen, x, y, w, h, makecol(255, 0, 0)) + flipv := False; fliph := False; + x0 := cmds.v[i * 8 + 0]; y0 := cmds.v[i * 8 + 1]; + x1 := cmds.v[i * 8 + 4]; y1 := cmds.v[i * 8 + 5]; + if x1 < x0 then + begin + tmp := x0; + x0 := x1; + x1 := tmp; + fliph := not fliph + end; + if y1 < y0 then + begin + tmp := y0; + y0 := y1; + y1 := tmp; + flipv := not flipv + end; + + w := tex[ctex].bmp.w; + h := tex[ctex].bmp.h; + s0 := Trunc(cmds.t[i * 8 + 0] * w); + t0 := Trunc(cmds.t[i * 8 + 1] * h); + s1 := Trunc(cmds.t[i * 8 + 4] * w); + t1 := Trunc(cmds.t[i * 8 + 5] * h); + + if s1 < s0 then + begin + tmp := s0; + s0 := s1; + s1 := tmp; + fliph := not fliph + end; + if t1 < t0 then + begin + tmp := t0; + t0 := t1; + t1 := tmp; + flipv := not flipv + end; + + s0 := s0 mod w; + t0 := t0 mod h; + s1 := s1 mod w; + t1 := t1 mod h; + + if flipv and fliph then + draw_sprite_proc := Allegro.draw_sprite_vh_flip + else if flipv then + draw_sprite_proc := Allegro.draw_sprite_v_flip + else if fliph then + draw_sprite_proc := Allegro.draw_sprite_h_flip + else + draw_sprite_proc := Allegro.draw_sprite; + + oldx0 := 0; oldy0 := 0; oldx1 := 0; oldy1 := 0; + get_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1); + set_clip_rect(sdl2allegro_screen, max(oldx0, offx + x0), max(oldy0, offy + y0), min(oldx1, offx + x1), min(oldy1, offy + y1)); + + for j := 0 to (y1 - y0 + h - 1) div h - 1 do + for k := 0 to (x1 - x0 + w - 1) div w - 1 do + draw_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0); + //blit(tex[ctex].bmp, sdl2allegro_screen, 0, 0, offx + x0 + k * w - s0, offy + y0 + j * h - t0, w, h); + + set_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1); + + //rect(sdl2allegro_screen, offx + x0, offy + y0, offx + x1, offy + y1, makecol(255, 0, 0)); + //rect(sdl2allegro_screen, offx + oldx0, offy + oldy0, offx + oldx1, offy + oldx1, makecol(0, 255, 0)); end end else if Length(cmds.c) <> 0 then begin assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *) for i := 0 to Length(cmds.v) div 8 - 1 do - rectfill(sdl2allegro_screen, cmds.v[i * 8], cmds.v[i * 8 + 1], cmds.v[i * 4 + 5], cmds.v[i * 4 + 6], cmds.c[i * 4]) + rectfill(sdl2allegro_screen, offx + cmds.v[i * 8], offy + cmds.v[i * 8 + 1], offx + cmds.v[i * 8 + 4], offy + cmds.v[i * 8 + 5], cmds.c[i * 4]) end else begin for i := 0 to Length(cmds.v) div 8 - 1 do - rectfill(sdl2allegro_screen, cmds.v[i * 8], cmds.v[i * 8 + 1], cmds.v[i * 4 + 5], cmds.v[i * 4 + 6], ccol) + rectfill(sdl2allegro_screen, offx + cmds.v[i * 8], offy + cmds.v[i * 8 + 1], offx + cmds.v[i * 8 + 4], offy + cmds.v[i * 8 + 5], ccol) end end; else @@ -218,44 +304,44 @@ implementation procedure glVertex2f(x, y: GLfloat); begin - Add(cmds.v, ceil(x)); - Add(cmds.v, ceil(y)) + Addi(cmds.v, ceil(x)); + Addi(cmds.v, ceil(y)) end; procedure glVertex2i(x, y: GLint); begin - Add(cmds.v, x); - Add(cmds.v, y) + Addi(cmds.v, x); + Addi(cmds.v, y) end; procedure glColor4f(red, green, blue, alpha: GLfloat); begin ccol := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255)); - Add(cmds.c, ccol) + Addi(cmds.c, ccol) end; procedure glColor4ub(red, green, blue, alpha: GLubyte); begin ccol := makeacol(red, green, blue, alpha); - Add(cmds.c, ccol) + Addi(cmds.c, ccol) end; procedure glColor3ub(red, green, blue: GLubyte); begin ccol := makecol(red, green, blue); - Add(cmds.c, ccol) + Addi(cmds.c, ccol) end; procedure glTexCoord2f(s, t: GLfloat); begin - Add(cmds.t, floor(s)); - Add(cmds.t, floor(t)); + Addf(cmds.t, s); + Addf(cmds.t, t); end; procedure glTexCoord2i(s, t: GLint); begin - Add(cmds.t, s); - Add(cmds.t, t); + Addf(cmds.t, s); + Addf(cmds.t, t); end; procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer); @@ -264,6 +350,11 @@ implementation procedure glLoadIdentity; begin + with stack[stack_ptr] do + begin + x := 0; + y := 0; + end end; procedure glMatrixMode(mode: GLenum); @@ -277,22 +368,32 @@ implementation procedure glPushMatrix; begin + stack[stack_ptr + 1] := stack[stack_ptr]; + INC(stack_ptr); end; procedure glPopMatrix; begin + DEC(stack_ptr) end; procedure glTranslatef(x, y, z: GLfloat); begin + ASSERT(z = 0); (* 3D not supported *) + stack[stack_ptr].x := Trunc(x); + stack[stack_ptr].y := Trunc(y); end; procedure glRotatef(angle, x, y, z: GLfloat); begin + //ASSERT(z = 0); (* 3D not supported *) + (* TODO Rotation *) end; procedure glScalef(x, y, z: GLfloat); begin + //ASSERT(z = 1); (* 3D not supported *) + (* TODO Scale *) end; procedure glViewport(x, y: GLint; width, height: GLsizei); @@ -345,7 +446,7 @@ implementation end; procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer); - var i, j, adr: Integer; p: PByte; + var i, j, adr: Integer; p: PByte; color: cint; begin assert(target = GL_TEXTURE_2D); assert(level = 0); @@ -360,6 +461,7 @@ implementation if tex[ctex].bmp <> nil then destroy_bitmap(tex[ctex].bmp); + // Video bitmap can lead to bad textures under dos //tex[ctex].bmp := create_video_bitmap(width, height); //if tex[ctex].bmp = nil then tex[ctex].bmp := create_system_bitmap(width, height); @@ -376,7 +478,11 @@ implementation for i := 0 to width - 1 do begin adr := j * width * 4 + i * 4; - putpixel(tex[ctex].bmp, i, height - j, makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3])) + if p[adr + 3] <> $FF then + color := 0 + else + color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]); + putpixel(tex[ctex].bmp, i, j, color) end end else @@ -391,7 +497,7 @@ implementation end; procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer); - var i, j, adr: Integer; p: PByte; + var i, j, adr: Integer; p: PByte; color: Cint; begin assert(target = GL_TEXTURE_2D); assert(level = 0); @@ -414,7 +520,11 @@ implementation for i := 0 to width - 1 do begin adr := j * width * 4 + i * 4; - putpixel(tex[ctex].bmp, i, height - j, makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3])) + if p[adr + 3] <> $FF then + color := 0 + else + color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]); + putpixel(tex[ctex].bmp, i, j, color) end end else diff --git a/src/wrappers/sdl2/sdl2allegro.inc b/src/wrappers/sdl2/sdl2allegro.inc index cb5ea6f..78c6f41 100644 --- a/src/wrappers/sdl2/sdl2allegro.inc +++ b/src/wrappers/sdl2/sdl2allegro.inc @@ -9,6 +9,9 @@ interface {$I sdlpixels.inc} {$I sdlscancode.inc} + const + DEFAULT_DEPTH = 8; + const SDL_HAT_CENTERED = $00; SDL_HAT_UP = $01; @@ -362,7 +365,11 @@ interface implementation - uses e_Log, SysUtils; + uses + {$IFDEF GO32V2} + go32, + {$ENDIF} + e_Log, SysUtils, ctypes; const maxKeyBuffer = 64; @@ -373,6 +380,8 @@ implementation keyring: array [0..maxKeyBuffer - 1] of Integer; keybeg, keyend: Integer; + ticks: UInt32; (* !!! VOLATILE !!! *) + function IsEmptyKeyboard: Boolean; begin result := keybeg = keyend @@ -395,12 +404,15 @@ implementation procedure KeyboardWatcher (scancode: Integer); cdecl; begin - if not IsFullKeyboard then + if (keybeg - 1) mod maxKeyBuffer <> keyend then (* not IsFullKeyboard *) begin keyring[keyend] := scancode; keyend := (keyend + 1) mod maxKeyBuffer end end; + procedure KeyboardWatcherEND; + begin + end; /// MACRO /// @@ -534,28 +546,38 @@ implementation (********** TIMERS **********) + procedure AllegroTimerCallback; cdecl; + begin + inc(ticks) + end; + procedure AllegroTimerCallbackEND; + begin + end; + + + function SDL_GetPerformanceCounter: UInt64; begin - e_LogWriteln('SDL_GetPerformanceCounter'); - result := 1 + //e_LogWriteln('SDL_GetPerformanceCounter'); + result := ticks; end; function SDL_GetPerformanceFrequency: UInt64; begin - e_LogWriteln('SDL_GetPerformanceFrequency'); + //e_LogWriteln('SDL_GetPerformanceFrequency'); result := 1 end; procedure SDL_Delay(ms: UInt32); begin - e_LogWriteln('SDL_Delay'); - //allegro_rest(ms) + //e_LogWriteln('SDL_Delay'); + //rest(ms) end; function SDL_GetTicks: UInt32; begin - e_LogWriteln('SDL_GetTicks'); - result := 1 + //e_LogWriteln('SDL_GetTicks'); + result := ticks; end; (********** DISPLAY MODES **********) @@ -621,24 +643,33 @@ implementation e_LogWritefln('SDL_CreateWindow %s %s %s %s %s %u', [title, x, y, w, h, flags]); result := nil; +{$IF DEFINED(AL_TEXT)} + mode := GFX_TEXT; + w := 0; h := 0; +{$ELSEIF DEFINED(GO32V2)} + mode := GFX_AUTODETECT; +{$ELSE} if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then mode := GFX_AUTODETECT_FULLSCREEN else mode := GFX_AUTODETECT_WINDOWED; - mode := GFX_SAFE; +{$ENDIF} + set_color_depth(DEFAULT_DEPTH); if set_gfx_mode(mode, w, h, 0, 0) = 0 then begin new(window); +{$IF NOT DEFINED(AL_TEXT)} set_window_title(title); if sdl2allegro_screen <> nil then destroy_bitmap(sdl2allegro_screen); - sdl2allegro_screen := create_video_bitmap(w, h); - if sdl2allegro_screen = nil then + //sdl2allegro_screen := create_video_bitmap(w, h); + //if sdl2allegro_screen = nil then sdl2allegro_screen := create_system_bitmap(w, h); if sdl2allegro_screen = nil then sdl2allegro_screen := create_bitmap(w, h); - assert(sdl2allegro_screen <> nil); + ASSERT(sdl2allegro_screen <> nil); +{$ENDIF} window.w := w; window.h := h; window.mode := mode; @@ -653,24 +684,34 @@ implementation result := -1; if window = nil then exit; +{$IF DEFINED(AL_TEXT)} + mode := GFX_TEXT; + window.w := 0; window.h := 0; +{$ELSEIF DEFINED(GO32V2)} + mode := GFX_AUTODETECT; +{$ELSE} if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then mode := GFX_AUTODETECT_FULLSCREEN else mode := GFX_AUTODETECT_WINDOWED; - mode := GFX_SAFE; +{$ENDIF} + set_color_depth(DEFAULT_DEPTH); if set_gfx_mode(mode, window.w, window.h, 0, 0) = 0 then begin +{$IF NOT DEFINED(AL_TEXT)} (* if sdl2allegro_screen <> nil then destroy_bitmap(sdl2allegro_screen); *) - sdl2allegro_screen := create_video_bitmap(window.w, window.h); - if sdl2allegro_screen = nil then + //sdl2allegro_screen := create_video_bitmap(window.w, window.h); + //if sdl2allegro_screen = nil then sdl2allegro_screen := create_system_bitmap(window.w, window.h); if sdl2allegro_screen = nil then sdl2allegro_screen := create_bitmap(window.w, window.h); - assert(sdl2allegro_screen <> nil); + ASSERT(sdl2allegro_screen <> nil); + set_palette(desktop_palette); +{$ENDIF} window.mode := mode; result := 0 end @@ -680,16 +721,24 @@ implementation begin e_LogWritefln('SDL_SetWindowSize %s %s', [w, h]); if window = nil then exit; +{$IF DEFINED(AL_TEXT)} + window.mode := GFX_TEXT; + w := 0; h := 0; +{$ENDIF} + set_color_depth(DEFAULT_DEPTH); if set_gfx_mode(window.mode, w, h, 0, 0) = 0 then begin +{$IF NOT DEFINED(AL_TEXT)} if sdl2allegro_screen <> nil then destroy_bitmap(sdl2allegro_screen); - if sdl2allegro_screen = nil then + //sdl2allegro_screen := create_video_bitmap(w, h); + //if sdl2allegro_screen = nil then sdl2allegro_screen := create_system_bitmap(w, h); if sdl2allegro_screen = nil then sdl2allegro_screen := create_bitmap(w, h); - sdl2allegro_screen := create_video_bitmap(w, h); - assert(sdl2allegro_screen <> nil); + ASSERT(sdl2allegro_screen <> nil); + set_palette(desktop_palette); +{$ENDIF} window.w := w; window.h := h; end @@ -752,10 +801,15 @@ implementation end; procedure SDL_GL_SwapWindow(window: PSDL_Window); + var res: cint; begin - e_LogWriteln('SDL_GL_SwapWindow'); - assert(sdl2allegro_screen <> nil); - show_video_bitmap(sdl2allegro_screen); + //e_LogWriteln('SDL_GL_SwapWindow'); +{$IF NOT DEFINED(AL_TEXT)} + ASSERT(sdl2allegro_screen <> nil); + blit(sdl2allegro_screen, screen, 0, 0, 0, 0, sdl2allegro_screen.w, sdl2allegro_screen.h); + res := show_video_bitmap(screen); + //ASSERT(res = 0); +{$ENDIF} end; function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext; @@ -874,7 +928,7 @@ implementation function SDL_PollEvent(event: PSDL_Event): SInt32; var alscan: Integer; begin - e_LogWriteln('SDL_PollEvent'); + //e_LogWriteln('SDL_PollEvent'); poll_keyboard; result := 0; if not IsEmptyKeyboard then @@ -883,7 +937,7 @@ implementation if alscan and $80 = 0 then event.type_ := SDL_KEYDOWN else - event.type_ := SDL_KEYDOWN; + event.type_ := SDL_KEYUP; event.key.timestamp := 0; event.key.windowID := 0; (* df not use it? @@ -921,21 +975,8 @@ implementation result := allegro_error; end; - function TestGet: AnsiString; - begin - result := '+++ Test concat qwertyiop!' - end; - - procedure Test; - begin - // WTF? when 'Test concat qwertyio! ' it not messed! - //e_LogWriteln('Test concat qwertyiop! ' + ParamStr(0)); - e_LogWriteln('Test concat qwertyiop! ' + TestGet); - end; - function SDL_Init(flags: UInt32): SInt32; begin - Test; e_LogWritefln('SDL_Init %u', [flags]); result := -1; __crt0_argv := @myargv[0]; @@ -943,11 +984,21 @@ implementation e_LogWritefln('argv[0] = %s', [myargv[0]]); if allegro_init = 0 then begin - e_LogWriteln('SDL_Init inited! ' + ParamStr(0) + ' '); + e_LogWriteln('SDL_Init inited! ' + ParamStr(0) + ' tickssize=' + IntToStr(sizeof(keyring)) ); + {$IFDEF GO32V2} + (* without this df dies with fire when swapped *) + lock_data(ticks, sizeof(ticks)); + lock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback)); + lock_data(keybeg, sizeof(keybeg)); + lock_data(keyend, sizeof(keyend)); + lock_data(keyring, sizeof(keyring)); + lock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher)); + {$ENDIF} install_timer; install_keyboard; keyboard_lowlevel_callback := KeyboardWatcher; set_keyboard_rate(0, 0); + install_int_ex(AllegroTimerCallback, MSEC_TO_TIMER(1)); result := 0 end end; @@ -957,5 +1008,14 @@ implementation e_LogWriteln('SDL_Quit'); remove_keyboard; remove_timer; + {$IFDEF GO32V2} + unlock_data(ticks, sizeof(ticks)); + unlock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback)); + unlock_data(keybeg, sizeof(keybeg)); + unlock_data(keyend, sizeof(keyend)); + unlock_data(keyring, sizeof(keyring)); + unlock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher)); + {$ENDIF} allegro_exit end; + -- 2.29.2