First draft of the SDL2 port.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
c299920fc1
commit
f3bff96968
8 changed files with 344 additions and 14 deletions
|
@ -21,4 +21,5 @@ include_directories(source)
|
|||
add_subdirectory(source)
|
||||
add_subdirectory(source/frontends/ncurses)
|
||||
add_subdirectory(source/frontends/qapple)
|
||||
add_subdirectory(source/frontends/sa2)
|
||||
add_subdirectory(test/TestCPU6502)
|
||||
|
|
|
@ -9,6 +9,7 @@ add_executable(applen
|
|||
asciiart.cpp
|
||||
resources.cpp
|
||||
configuration.cpp
|
||||
bitmaps.cpp
|
||||
)
|
||||
|
||||
pkg_search_module(NCURSESW REQUIRED ncursesw)
|
||||
|
|
14
source/frontends/ncurses/bitmaps.cpp
Normal file
14
source/frontends/ncurses/bitmaps.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "StdAfx.h"
|
||||
#include "Log.h"
|
||||
|
||||
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename)
|
||||
{
|
||||
LogFileOutput("LoadBitmap: not loading resource %s\n", filename.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits)
|
||||
{
|
||||
memset(lpvBits, 0, cb);
|
||||
return cb;
|
||||
}
|
|
@ -345,8 +345,11 @@ namespace
|
|||
g_CardMgr.GetDisk2CardMgr().Destroy();
|
||||
ImageDestroy();
|
||||
|
||||
fclose(g_fh);
|
||||
g_fh = NULL;
|
||||
if (g_fh)
|
||||
{
|
||||
fclose(g_fh);
|
||||
g_fh = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,15 +36,3 @@ HRSRC FindResource(void *, const std::string & filename, const char *)
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename)
|
||||
{
|
||||
LogFileOutput("LoadBitmap: not loading resource %s\n", filename.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits)
|
||||
{
|
||||
memset(lpvBits, 0, cb);
|
||||
return cb;
|
||||
}
|
||||
|
|
27
source/frontends/sa2/CMakeLists.txt
Normal file
27
source/frontends/sa2/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
include(FindPkgConfig)
|
||||
|
||||
add_executable(sa2
|
||||
main.cpp
|
||||
bitmaps.cpp
|
||||
../ncurses/configuration.cpp
|
||||
../ncurses/resources.cpp
|
||||
)
|
||||
|
||||
find_package(Boost REQUIRED
|
||||
COMPONENTS program_options
|
||||
)
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
|
||||
target_compile_features(sa2 PUBLIC cxx_std_17)
|
||||
|
||||
target_include_directories(sa2 PRIVATE
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(sa2 PRIVATE
|
||||
Boost::program_options
|
||||
${SDL2_LIBRARIES}
|
||||
appleii
|
||||
)
|
71
source/frontends/sa2/bitmaps.cpp
Normal file
71
source/frontends/sa2/bitmaps.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include <SDL.h>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include <linux/interface.h>
|
||||
#include <linux/windows/misc.h>
|
||||
|
||||
struct CBITMAP : public CHANDLE
|
||||
{
|
||||
std::shared_ptr<SDL_Surface> surface;
|
||||
};
|
||||
|
||||
std::string getPath(const std::string & resource)
|
||||
{
|
||||
if (resource == "CHARSET40") return "resource/CHARSET4.BMP";
|
||||
if (resource == "CHARSET82") return "resource/CHARSET82.bmp";
|
||||
if (resource == "CHARSET8M") return "resource/CHARSET8M.bmp";
|
||||
if (resource == "CHARSET8C") return "resource/CHARSET8C.bmp";
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & resource)
|
||||
{
|
||||
const std::string path = getPath(resource);
|
||||
std::shared_ptr<SDL_Surface> surface(SDL_LoadBMP(path.c_str()), SDL_FreeSurface);
|
||||
if (surface)
|
||||
{
|
||||
CBITMAP * bitmap = new CBITMAP;
|
||||
bitmap->surface = surface;
|
||||
return bitmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Cannot load: " << resource << " with path: " << path << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits)
|
||||
{
|
||||
const CBITMAP & bitmap = dynamic_cast<CBITMAP&>(*hbit);
|
||||
|
||||
SDL_LockSurface(bitmap.surface.get());
|
||||
|
||||
const SDL_Surface * surface = bitmap.surface.get();
|
||||
|
||||
const char * source = static_cast<char *>(surface->pixels);
|
||||
const size_t size = surface->h * surface->w / 8;
|
||||
const size_t requested = cb;
|
||||
|
||||
const size_t copied = std::min(requested, size);
|
||||
|
||||
char * dest = static_cast<char *>(lpvBits);
|
||||
|
||||
for (size_t i = 0; i < copied; ++i)
|
||||
{
|
||||
const size_t offset = i * 8;
|
||||
char val = 0;
|
||||
for (size_t j = 0; j < 8; ++j)
|
||||
{
|
||||
const char pixel = *(source + offset + j);
|
||||
val = (val << 1) | pixel;
|
||||
}
|
||||
dest[i] = val;
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(bitmap.surface.get());
|
||||
|
||||
return copied;
|
||||
}
|
225
source/frontends/sa2/main.cpp
Normal file
225
source/frontends/sa2/main.cpp
Normal file
|
@ -0,0 +1,225 @@
|
|||
#include <iostream>
|
||||
#include <SDL.h>
|
||||
#include <memory>
|
||||
|
||||
#include "linux/interface.h"
|
||||
#include "linux/windows/misc.h"
|
||||
#include "linux/data.h"
|
||||
#include "frontends/ncurses/configuration.h"
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "Common.h"
|
||||
#include "Applewin.h"
|
||||
#include "Disk.h"
|
||||
#include "Harddisk.h"
|
||||
#include "Log.h"
|
||||
#include "CPU.h"
|
||||
#include "Frame.h"
|
||||
#include "Memory.h"
|
||||
#include "LanguageCard.h"
|
||||
#include "MouseInterface.h"
|
||||
#include "ParallelPrinter.h"
|
||||
#include "Video.h"
|
||||
#include "NTSC.h"
|
||||
#include "SaveState.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void initialiseEmulator()
|
||||
{
|
||||
g_fh = fopen("/tmp/applewin.txt", "w");
|
||||
setbuf(g_fh, nullptr);
|
||||
|
||||
LogFileOutput("Initialisation\n");
|
||||
|
||||
ImageInitialize();
|
||||
g_bFullSpeed = false;
|
||||
}
|
||||
|
||||
void loadEmulator()
|
||||
{
|
||||
LoadConfiguration();
|
||||
CheckCpu();
|
||||
SetWindowTitle();
|
||||
FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES);
|
||||
ResetDefaultMachineMemTypes();
|
||||
|
||||
MemInitialize();
|
||||
VideoInitialize();
|
||||
|
||||
sg_Disk2Card.Reset();
|
||||
HD_Reset();
|
||||
}
|
||||
|
||||
void stopEmulator()
|
||||
{
|
||||
sg_Mouse.Uninitialize();
|
||||
sg_Mouse.Reset();
|
||||
MemDestroy();
|
||||
}
|
||||
|
||||
void uninitialiseEmulator()
|
||||
{
|
||||
HD_Destroy();
|
||||
PrintDestroy();
|
||||
CpuDestroy();
|
||||
|
||||
sg_Disk2Card.Destroy();
|
||||
ImageDestroy();
|
||||
fclose(g_fh);
|
||||
g_fh = nullptr;
|
||||
}
|
||||
|
||||
SDL_Rect refreshTexture(const std::shared_ptr<SDL_Texture> & tex)
|
||||
{
|
||||
uint8_t * data;
|
||||
int width;
|
||||
int height;
|
||||
int sx, sy;
|
||||
int sw, sh;
|
||||
|
||||
getScreenData(data, width, height, sx, sy, sw, sh);
|
||||
|
||||
void * pixels;
|
||||
int pitch;
|
||||
SDL_LockTexture(tex.get(), nullptr, &pixels, &pitch);
|
||||
|
||||
memcpy(pixels, data, width * height * 4);
|
||||
|
||||
SDL_UnlockTexture(tex.get());
|
||||
|
||||
SDL_Rect srect;
|
||||
srect.x = sx;
|
||||
srect.y = sy;
|
||||
srect.w = sw;
|
||||
srect.h = sh;
|
||||
|
||||
return srect;
|
||||
}
|
||||
|
||||
void renderScreen(const std::shared_ptr<SDL_Renderer> & ren, const std::shared_ptr<SDL_Texture> & tex, const SDL_Rect & srect)
|
||||
{
|
||||
SDL_RenderCopyEx(ren.get(), tex.get(), &srect, nullptr, 0.0, nullptr, SDL_FLIP_VERTICAL);
|
||||
SDL_RenderPresent(ren.get());
|
||||
}
|
||||
}
|
||||
|
||||
int MessageBox(HWND, const char * text, const char * caption, UINT type)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, caption, text, nullptr);
|
||||
return IDOK;
|
||||
}
|
||||
|
||||
void FrameDrawDiskLEDS(HDC x)
|
||||
{
|
||||
}
|
||||
|
||||
void FrameDrawDiskStatus(HDC x)
|
||||
{
|
||||
}
|
||||
|
||||
void FrameRefreshStatus(int x, bool)
|
||||
{
|
||||
}
|
||||
|
||||
BYTE SpkrToggle (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG uExecutedCycles)
|
||||
{
|
||||
return MemReadFloatingBus(uExecutedCycles);
|
||||
}
|
||||
|
||||
void run_sdl()
|
||||
{
|
||||
InitializeRegistry("applen.conf");
|
||||
|
||||
initialiseEmulator();
|
||||
loadEmulator();
|
||||
|
||||
const int width = GetFrameBufferWidth();
|
||||
const int height = GetFrameBufferHeight();
|
||||
const int sx = GetFrameBufferBorderWidth();
|
||||
const int sy = GetFrameBufferBorderHeight();
|
||||
const int sw = GetFrameBufferBorderlessWidth();
|
||||
const int sh = GetFrameBufferBorderlessHeight();
|
||||
|
||||
std::shared_ptr<SDL_Window> win(SDL_CreateWindow(g_pAppTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, sw, sh, SDL_WINDOW_SHOWN), SDL_DestroyWindow);
|
||||
if (!win)
|
||||
{
|
||||
std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<SDL_Renderer> ren(SDL_CreateRenderer(win.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), SDL_DestroyRenderer);
|
||||
if (!ren)
|
||||
{
|
||||
std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const Uint32 format = SDL_PIXELFORMAT_BGRA32;
|
||||
std::shared_ptr<SDL_Texture> tex(SDL_CreateTexture(ren.get(), format, SDL_TEXTUREACCESS_STREAMING, width, height), SDL_DestroyTexture);
|
||||
|
||||
bool quit = false;
|
||||
do
|
||||
{
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e) != 0)
|
||||
{
|
||||
if (e.type == SDL_QUIT)
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
else if (e.type == SDL_KEYDOWN)
|
||||
{
|
||||
std::cerr << e.key.keysym.scancode << "," << e.key.keysym.sym << "," << e.key.keysym.mod << "," << bool(e.key.repeat) << ",AAA" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const bool bVideoUpdate = true;
|
||||
DWORD uCyclesToExecute = 1000;
|
||||
const DWORD uActualCyclesExecuted = CpuExecute(uCyclesToExecute, bVideoUpdate);
|
||||
g_dwCyclesThisFrame += uActualCyclesExecuted;
|
||||
|
||||
sg_Disk2Card.UpdateDriveState(uActualCyclesExecuted);
|
||||
|
||||
const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame();
|
||||
if (g_dwCyclesThisFrame >= dwClksPerFrame)
|
||||
{
|
||||
if (g_dwCyclesThisFrame >= dwClksPerFrame)
|
||||
{
|
||||
const SDL_Rect srect = refreshTexture(tex);
|
||||
renderScreen(ren, tex, srect);
|
||||
}
|
||||
g_dwCyclesThisFrame -= dwClksPerFrame;
|
||||
}
|
||||
} while (!quit);
|
||||
|
||||
stopEmulator();
|
||||
uninitialiseEmulator();
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
//First we need to start up SDL, and make sure it went ok
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int exit = 0;
|
||||
|
||||
try
|
||||
{
|
||||
run_sdl();
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
exit = 2;
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return exit;
|
||||
}
|
Loading…
Add table
Reference in a new issue