Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add prototypical SDL support. #403

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f58abe3
Add prototypical SDL support.
ecraven Oct 19, 2021
f73b4d1
Merge remote-tracking branch 'upstream/master'
ecraven Nov 7, 2021
78e42b7
Change SDL backend to accelerated renderer, support pixel scaling.
ecraven Oct 20, 2021
87ede7c
Only bitblt on damage.
ecraven Oct 20, 2021
333c132
Refactor, don't update texture on every bitblt.
ecraven Oct 21, 2021
7b7db9a
Refactor, only bitblt once per "frame".
ecraven Oct 21, 2021
28931ac
Remove extra directory from includes for SDL.
ecraven Oct 21, 2021
4821dac
Add more #ifdef XWINDOW
ecraven Oct 21, 2021
f198204
Update CMakeLists.txt for cross-compiling.
ecraven Oct 21, 2021
2092a74
Add command line parameters -sc WxH and -pixelscale n for SDL.
ecraven Oct 21, 2021
8f70679
Try to get CI running again ;)
ecraven Oct 21, 2021
5c22546
Also install SDL2 on ubuntu runners.
ecraven Oct 21, 2021
0d47030
Also *correctly* install SDL2 on ubuntu runners.
ecraven Oct 21, 2021
f8fea0b
Revert CMakeLists.txt change until better understanding.
ecraven Oct 21, 2021
ab94538
Add support for -t / -title.
ecraven Oct 21, 2021
4ee904f
Run apt-get update before trying to install.
ecraven Oct 21, 2021
ccfacb2
Try to make builds pass again.
ecraven Oct 21, 2021
56d5639
Show cmake version before building.
ecraven Oct 21, 2021
f769dba
Add SDL2 dependency to macos build.
ecraven Oct 21, 2021
e346db4
Apparently there is no sdl2 cask for macos :-/
ecraven Oct 21, 2021
e9968a2
Try to placate the macos build.
ecraven Oct 21, 2021
572b94d
Try SDL2::SDL2 instead of SDL2 in CMakeLists.txt.
ecraven Oct 21, 2021
bab54bc
Try to unify cmake file for different versions of SDL2.
ecraven Oct 21, 2021
9bb7fab
Fix Caso.
ecraven Oct 21, 2021
bab9213
Remove SDL2 directory from include SDL2/SDL.h.
ecraven Oct 21, 2021
00c4d65
Maybe fix cmake for SDL2.
ecraven Oct 21, 2021
784d9f6
For now, some more extern functions declarations.
ecraven Oct 21, 2021
5413934
Add support for key repeating.
ecraven Oct 21, 2021
8a872d7
Only update texture on damage.
ecraven Oct 22, 2021
a3fdf18
Add mouse wheel diagnostics.
ecraven Oct 22, 2021
ecfd404
Add support for inverting video and setting mouse position.
ecraven Oct 25, 2021
37aed57
Add support for setting the mouse cursor. Not finished!
ecraven Nov 7, 2021
ba6e365
Fix "error: implicit declaration of function" from dspsubrs
nbriggs Nov 7, 2021
c64f853
Merge pull request #408 from Interlisp/sdl-fix-implicit-decls
ecraven Nov 8, 2021
f9d1e51
Change Pixelformat to 332 (one byte) instead of 8888 (four bytes).
ecraven Nov 8, 2021
241e5fe
Cache cursors for SDL.
ecraven Nov 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ jobs:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
- name: Show CMake version
run: cmake --version
- name: Install X11 dependencies on MacOS
if: ${{ runner.os == 'macOS'}}
run: brew install --cask xquartz
- name: Install SDL2 dependencies on MacOS
if: ${{ runner.os == 'macOS'}}
run: brew install sdl2
- name: Install SDL dependency on Ubuntu
if: ${{ runner.os == 'Linux'}}
run: sudo apt-get update && sudo apt-get install -y libsdl2-dev
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: Configure CMake
Expand Down
41 changes: 39 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.15)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)

SET(CMAKE_C_STANDARD 99)
# SET(CMAKE_C_EXTENSIONS OFF) # actually use c99, *not* gnu99

IF(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_COMPILER_ID MATCHES "GNU")
IF(UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
Expand All @@ -23,10 +24,12 @@ find_program(
)

IF (CLANG_TIDY_EXE)
IF (NOT CMAKE_CROSSCOMPILING)
# There are many many warnings for strcpy instances to deal with,
# but suppress it for now so that other issues are more obvious
#
SET(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXE} -checks=-*,cert-*,clang-analyzer-security.*,-clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-security.insecureAPI.bzero -header-filter=.*)
SET(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXE} -checks=-*,cert-*,clang-analyzer-security.*,-clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-security.insecureAPI.bzero -header-filter=.*)
ENDIF()
ENDIF()

INCLUDE(CheckLibraryExists)
Expand All @@ -39,7 +42,7 @@ SET(MAIKO_DEFINITIONS
"-DRELEASE=351"
)

OPTION(MAIKO_DISPLAY_X11 "Use X11 for display." ON)
OPTION(MAIKO_DISPLAY_X11 "Use X11 for display." OFF)
IF(MAIKO_DISPLAY_X11)
FIND_PACKAGE(X11 REQUIRED)
SET(MAIKO_DISPLAY_X11_DEFINITIONS
Expand Down Expand Up @@ -72,6 +75,20 @@ IF(MAIKO_DISPLAY_X11)
)
ENDIF()

OPTION(MAIKO_DISPLAY_SDL "Use SDL for display." ON)
IF(MAIKO_DISPLAY_SDL)
FIND_PACKAGE(SDL2 REQUIRED)
SET(MAIKO_DISPLAY_SDL_DEFINITIONS
"-DSDL"
)
SET(MAIKO_DISPLAY_SDL_LIBRARIES ${SDL2_LIBRARIES})
SET(MAIKO_DISPLAY_SDL_SRCS
src/sdl.c
)
SET(MAIKO_DISPLAY_SDL_HDRS
)
ENDIF()

IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
LIST(APPEND MAIKO_DEFINITIONS
"-DOS5"
Expand Down Expand Up @@ -404,6 +421,11 @@ IF(MAIKO_DISPLAY_X11)
TARGET_LINK_LIBRARIES(lde X11::X11)
ENDIF()

IF(MAIKO_DISPLAY_SDL)
# Tell it that the SDL launcher is available.
TARGET_COMPILE_DEFINITIONS(lde PUBLIC ${MAIKO_DISPLAY_SDL_DEFINITIONS})
ENDIF()

ADD_EXECUTABLE(ldeether src/ldeether.c src/dlpi.c)
TARGET_COMPILE_DEFINITIONS(ldeether PUBLIC ${MAIKO_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES(ldeether PUBLIC inc)
Expand All @@ -422,6 +444,21 @@ IF(MAIKO_DISPLAY_X11)
TARGET_LINK_LIBRARIES(ldex ${MAIKO_LIBRARIES} ${MAIKO_DISPLAY_X11_LIBRARIES})
ENDIF()

IF(MAIKO_DISPLAY_SDL)
ADD_EXECUTABLE(ldesdl
src/main.c
vdate.c
${MAIKO_SRCS}
${MAIKO_HDRS}
${MAIKO_DISPLAY_SDL_SRCS}
${MAIKO_DISPLAY_SDL_HDRS}
)
TARGET_COMPILE_DEFINITIONS(ldesdl PUBLIC ${MAIKO_DEFINITIONS} ${MAIKO_DISPLAY_SDL_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES(ldesdl PUBLIC inc)
TARGET_INCLUDE_DIRECTORIES(ldesdl PRIVATE ${SDL2_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(ldesdl ${MAIKO_LIBRARIES} ${MAIKO_DISPLAY_SDL_LIBRARIES})
ENDIF()

ADD_EXECUTABLE(mkvdate src/mkvdate.c)
TARGET_COMPILE_DEFINITIONS(mkvdate PUBLIC ${MAIKO_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES(mkvdate PUBLIC inc)
Expand Down
3 changes: 3 additions & 0 deletions bin/makefile-tail
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ $(OBJECTDIR)xwinman.o: $(SRCDIR)xwinman.c $(REQUIRED-INCS) \
$(INCDIR)xlspwindefs.h $(INCDIR)xscrolldefs.h
$(CC) $(RFLAGS) $(SRCDIR)xwinman.c -o $(OBJECTDIR)xwinman.o

$(OBJECTDIR)sdl.o: $(SRCDIR)sdl.c $(REQUIRED-INCS)
$(CC) $(RFLAGS) $(SRCDIR)sdl.c -o $(OBJECTDIR)sdl.o

$(OBJECTDIR)foreign.o: $(SRCDIR)foreign.c $(REQUIRED-INCS) \
$(INCDIR)/foreigndefs.h
$(CC) $(RFLAGS) $(SRCDIR)foreign.c -o $(OBJECTDIR)foreign.o
Expand Down
4 changes: 4 additions & 0 deletions inc/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extern DLword *DISP_MAX_Address;
#define DISPLAYBUFFER
#endif /* XWINDOW */

#ifdef SDL
#define DISPLAYBUFFER
#endif /* SDL */

#ifdef DOS
#define DISPLAYBUFFER
#endif /* DOS */
Expand Down
11 changes: 11 additions & 0 deletions inc/sdldefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef SDLDEFS_H
#define SDLDEFS_H 1

void sdl_notify_damage(int x, int y, int w, int h);
void sdl_setCursor(int hot_x, int hot_y);
void sdl_bitblt_to_screen(int x, int y, int w, int h);
void sdl_set_invert(int flag);
void sdl_setMousePosition(int x, int y);
void process_SDLevents();
int init_SDL(char *windowtitle, int w, int h, int s);
#endif
19 changes: 19 additions & 0 deletions src/bbtsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ void bitbltsub(LispPTR *argv) {
if (in_display_segment(dstbase)) flush_display_region(dx, dty, w, h);
#endif /* XWINDOW */

#ifdef SDL
if (in_display_segment(dstbase)) flush_display_region(dx, dty, w, h);
#endif /* XWINDOW */

#ifdef DOS
/* Copy the changed section of display bank to the frame buffer */
if (in_display_segment(dstbase)) {
Expand Down Expand Up @@ -834,6 +838,10 @@ LispPTR bitblt_bitmap(LispPTR *args) {
if (in_display_segment(dstbase)) flush_display_region(dlx, dty, width, height);
#endif /* XWINDOW */

#ifdef SDL
if (in_display_segment(dstbase)) flush_display_region(dlx, dty, width, height);
#endif /* SDL */

#ifdef DOS
/* Copy the changed section of display bank to the frame buffer */
if (in_display_segment(dstbase)) {
Expand Down Expand Up @@ -1081,6 +1089,10 @@ LispPTR bitshade_bitmap(LispPTR *args) {
if (in_display_segment(dstbase)) flush_display_region(left, dty, width, height);
#endif /* XWINDOW */

#ifdef SDL
if (in_display_segment(dstbase)) flush_display_region(left, dty, width, height);
#endif /* SDL */

#ifdef DOS
/* Copy the changed section of display bank to the frame buffer */
if (in_display_segment(dstbase)) {
Expand Down Expand Up @@ -1210,6 +1222,10 @@ void bltchar(LispPTR *args)
if (in_display_segment(dstbase)) flush_display_lineregion(dx, dstbase, w, h);
#endif /* XWINDOW */

#ifdef SDL
if (in_display_segment(dstbase)) flush_display_lineregion(dx, dstbase, w, h);
#endif /* SDL */

#ifdef DOS
if (in_display_segment(dstbase)) flush_display_lineregion(dx, dstbase, w, h);
#endif /* DOS */
Expand Down Expand Up @@ -1423,6 +1439,9 @@ void newbltchar(LispPTR *args) {
#ifdef XWINDOW
if (in_display_segment(dstbase)) flush_display_lineregion(dx, dstbase, w, h);
#endif /* XWINDOW */
#ifdef SDL
if (in_display_segment(dstbase)) flush_display_lineregion(dx, dstbase, w, h);
#endif /* SDL */
#ifdef DOS
if (in_display_segment(dstbase)) flush_display_lineregion(dx, dstbase, w, h);
#endif /* DOS */
Expand Down
24 changes: 21 additions & 3 deletions src/dspsubrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

#include "dspsubrsdefs.h"
#include "commondefs.h"
#ifdef XWINDOW
#if defined(XWINDOW)
#include "xcursordefs.h"
#include "xlspwindefs.h"
#elif defined(SDL)
#include "sdldefs.h"
#endif

extern int DebugDSP;
Expand Down Expand Up @@ -72,6 +74,13 @@ LispPTR DSP_VideoColor(LispPTR *args) /* args[0] : black flag */
return ATOM_T;
else
return NIL;
#elif defined(SDL)
invert = args[0] & 0xFFFF;
sdl_set_invert(invert);
if (invert)
return ATOM_T;
else
return NIL;
#else
return NIL;
#endif
Expand All @@ -96,9 +105,11 @@ void DSP_Cursor(LispPTR *args, int argnum)
extern int LastCursorX, LastCursorY;


#ifdef XWINDOW
#if defined(XWINDOW)
/* For X-Windows, set the cursor to the given location. */
Set_XCursor((int)(args[0] & 0xFFFF), (int)(args[1] & 0xFFFF));
#elif defined(SDL)
sdl_setCursor((int)(args[0] & 0xFFFF), (int)(args[1] & 0xFFFF));
#endif /* XWINDOW */
}

Expand All @@ -118,6 +129,11 @@ void DSP_SetMousePos(register LispPTR *args)
if (Mouse_Included)
set_Xmouseposition((int)(GetSmalldata(args[0])), (int)(GetSmalldata(args[1])));
#endif /* XWINDOW */
#ifdef SDL
int x = (int)(GetSmalldata(args[0]));
int y = (int)(GetSmalldata(args[1]));
sdl_setMousePosition(x, y);
#endif /* SDL */
}

/****************************************************
Expand Down Expand Up @@ -178,8 +194,10 @@ void flip_cursor() {
#endif


#ifdef XWINDOW
#if defined(XWINDOW)
/* JDS 011213: 15- cur y, as function does same! */
Set_XCursor(Current_Hot_X, 15 - Current_Hot_Y);
#elif defined(SDL)
sdl_setCursor(0, 0); // TODO: keep track of the current hot_x and hot_y
#endif /* XWINDOW */
}
34 changes: 28 additions & 6 deletions src/initdsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extern DspInterface currentdsp;
int LispWindowFd = -1;
int FrameBufferFd = -1;

extern int sdl_displaywidth, sdl_displayheight, sdl_pixelscale;
int displaywidth, displayheight, DisplayRasterWidth, DisplayType;
int DisplayByteSize;
DLword *DisplayRegion68k; /* 68k addr of #{}22,0 */
Expand All @@ -89,6 +90,10 @@ extern DLword *ColorDisplayRegion68k;
extern int MonoOrColor;
#endif /* COLOR */

#ifdef SDL
extern void sdl_notify_damage(int, int, int, int);
#endif /* SDL */

#ifdef XWINDOW
DLword *DisplayRegion68k_end_addr;
extern int *Xdisplay; /* DAANGER -jarl nilsson 27-apr-92 */
Expand Down Expand Up @@ -180,7 +185,10 @@ void init_display2(DLword *display_addr, int display_max)
displaywidth = currentdsp->Display.width;
displayheight = currentdsp->Display.height;
#endif /* XWINDOW */

#if (defined(SDL))
displaywidth = sdl_displaywidth;
displayheight = sdl_displayheight;
#endif /* SDL */
DisplayRasterWidth = displaywidth / BITSPER_DLWORD;

if ((displaywidth * displayheight) > display_max) { displayheight = display_max / displaywidth; }
Expand All @@ -194,7 +202,9 @@ void init_display2(DLword *display_addr, int display_max)
DisplayType = SUN2BW;
DisplayRegion68k_end_addr = DisplayRegion68k + DisplayRasterWidth * displayheight;
#endif /* XWINDOW */

#ifdef SDL
DisplayType = SUN2BW;
#endif /* SDL */
init_cursor();
DisplayByteSize = ((displaywidth * displayheight / 8 + (getpagesize() - 1)) & -getpagesize());

Expand Down Expand Up @@ -266,7 +276,10 @@ in_display_segment(baseaddr)
/************************************************************************/

void flush_display_buffer() {

// printf("flush_display_buffer\n");
#ifdef SDL
sdl_notify_damage(0, 0, sdl_displaywidth, sdl_displayheight);
#endif
#ifdef XWINDOW
(currentdsp->bitblt_to_screen)(currentdsp, DisplayRegion68k, currentdsp->Visible.x,
currentdsp->Visible.y, currentdsp->Visible.width,
Expand Down Expand Up @@ -297,7 +310,10 @@ void flush_display_buffer() {

void flush_display_region(int x, int y, int w, int h)
{

// printf("flush_display_region %d %d %d %d\n", x, y, w, h);
#ifdef SDL
sdl_notify_damage(x, y, w, h);
#endif
#if (defined(XWINDOW) || defined(DOS))
TPRINT(("Enter flush_display_region x=%d, y=%d, w=%d, h=%d\n", x, y, w, h));
(currentdsp->bitblt_to_screen)(currentdsp, DisplayRegion68k, x, y, w, h);
Expand Down Expand Up @@ -340,7 +356,10 @@ void flush_display_lineregion(UNSIGNED x, DLword *ybase, UNSIGNED w, UNSIGNED h)
{
int y;
y = ((DLword *)ybase - DisplayRegion68k) / DLWORD_PERLINE;

// printf("flush_display_lineregion %d %d %d %d\n", x, y, w, h);
#ifdef SDL
sdl_notify_damage(x, y, w, h);
#endif
#if (defined(XWINDOW) || defined(DOS))
TPRINT(("Enter flush_display_lineregion x=%d, y=%d, w=%d, h=%d\n", x, y, w, h));
(currentdsp->bitblt_to_screen)(currentdsp, DisplayRegion68k, x, y, w, h);
Expand Down Expand Up @@ -371,7 +390,10 @@ void flush_display_ptrregion(DLword *ybase, UNSIGNED bitoffset, UNSIGNED w, UNSI
baseoffset = (((DLword *)ybase) - DisplayRegion68k);
y = baseoffset / DLWORD_PERLINE;
x = bitoffset + (BITSPERWORD * (baseoffset - (DLWORD_PERLINE * y)));

// printf("flush_display_ptrregion %d %d %d %d\n", x, y, w, h);
#ifdef SDL
sdl_notify_damage(x, y, w, h);
#endif
#if (defined(XWINDOW) || defined(DOS))
TPRINT(("Enter flush_display_ptrregion\n x=%d, y=%d, w=%d, h=%d\n", x, y, w, h));
(currentdsp->bitblt_to_screen)(currentdsp, DisplayRegion68k, x, y, w, h);
Expand Down
11 changes: 10 additions & 1 deletion src/initkbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ void set_kbd_iopointers() {
#define KB_HP9000 (10 + MIN_KEYTYPE) /* TODO: Can we remove this? */
#define KB_X (11 + MIN_KEYTYPE)
#define KB_DOS (12 + MIN_KEYTYPE)
#define KB_SDL (13 + MIN_KEYTYPE)

/* KB_SUN4 not defined in older OS versions */
#ifndef KB_SUN4
Expand Down Expand Up @@ -432,6 +433,8 @@ void keyboardtype(int fd)
type = KB_X;
#elif DOS
type = KB_DOS;
#elif SDL
type = KB_SDL;
#endif /* XWINDOW */
} /* if end */
else {
Expand All @@ -447,6 +450,8 @@ void keyboardtype(int fd)
type = KB_X;
else if (strcmp("x", key) == 0)
type = KB_X;
else if (strcmp("sdl", key) == 0)
type = KB_SDL;
else
type = KB_SUN3; /* default */
}
Expand Down Expand Up @@ -483,7 +488,11 @@ void keyboardtype(int fd)
InterfacePage->devconfig |= KB_SUN3 - MIN_KEYTYPE; /* 10 */
break;
#endif /* XWINDOW */

#ifdef SDL
case KB_SDL:
InterfacePage->devconfig |= KB_SUN3 - MIN_KEYTYPE; /* 10 */
break;
#endif /* SDL */
#ifdef DOS
case KB_DOS:
SUNLispKeyMap = DOSLispKeyMap_101;
Expand Down
2 changes: 2 additions & 0 deletions src/keyevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ void Mouse_hndlr(void); /* Fields mouse events from driver */

#include "keyeventdefs.h"
#include "osmsgdefs.h"
#ifdef XWINDOW
#include "xwinmandefs.h"
#endif

#ifdef MAIKO_ENABLE_ETHERNET
#include "etherdefs.h"
Expand Down