mirror of
https://github.com/InvisibleUp/uvmac.git
synced 2024-11-21 15:34:08 +00:00
SDL2 now compiles, with a segfault
This commit is contained in:
parent
b5d3c3ef05
commit
5c930e348e
@ -34,7 +34,7 @@
|
||||
|
||||
#define EnableMouseMotion 0
|
||||
|
||||
#define IncludeHostTextClipExchange 1
|
||||
#define IncludeHostTextClipExchange 0
|
||||
#define EmLocalTalk 0
|
||||
#define AutoLocation 1
|
||||
#define AutoTimeZone 1
|
||||
|
@ -43,7 +43,8 @@
|
||||
|
||||
#define MaxATTListN 32
|
||||
#define IncludeExtnPbufs 1
|
||||
#define IncludeExtnHostTextClipExchange 1
|
||||
// temporary
|
||||
#define IncludeExtnHostTextClipExchange 0
|
||||
|
||||
#define Sony_SupportDC42 1
|
||||
#define Sony_SupportTags 0
|
||||
|
35
meson.build
35
meson.build
@ -120,6 +120,8 @@ MAC_SRC = {
|
||||
'Plus':
|
||||
MAC_SRC_COMMON +
|
||||
HW_SRC['SCREEN'] +
|
||||
HW_SRC['SCC'] +
|
||||
HW_SRC['SCSI'] +
|
||||
HW_SRC['MOUSE'] +
|
||||
HW_SRC['KBRD'],
|
||||
'II':
|
||||
@ -144,7 +146,17 @@ UI_SRC = {
|
||||
'SDL2': [
|
||||
'src/UI/COMOSGLU.c',
|
||||
'src/UI/CONTROLM.c',
|
||||
'src/UI/SDL2/OSGLUSD2.c'
|
||||
'src/UI/SDL2/OSGLUSD2.c',
|
||||
#'src/UI/SDL2/CLIPBRD.c',
|
||||
'src/UI/SDL2/DBGLOG.c',
|
||||
'src/UI/SDL2/DRIVES.c',
|
||||
'src/UI/SDL2/INTL.c',
|
||||
'src/UI/SDL2/KEYBOARD.c',
|
||||
'src/UI/SDL2/MOUSE.c',
|
||||
'src/UI/SDL2/ROM.c',
|
||||
'src/UI/SDL2/SOUND.c',
|
||||
'src/UI/SDL2/TIMEDATE.c',
|
||||
'src/UI/SDL2/VIDEO.c',
|
||||
]
|
||||
}
|
||||
|
||||
@ -153,31 +165,12 @@ EMU_SRC = [
|
||||
'src/GLOBGLUE.c',
|
||||
'src/PATCHES/ROMEMDEV.c',
|
||||
'src/UTIL/DATE2SEC.c',
|
||||
'src/incbin/incbin.c',
|
||||
'src/LANG/INTLCHAR.c',
|
||||
]
|
||||
|
||||
EMU_INC = include_directories([
|
||||
'cfg/',
|
||||
'src/',
|
||||
'src/HW/ADB',
|
||||
'src/HW/DISK',
|
||||
'src/HW/KBRD',
|
||||
'src/HW/M68K',
|
||||
'src/HW/MOUSE',
|
||||
'src/HW/POWERMAN',
|
||||
'src/HW/RTC',
|
||||
'src/HW/SCC',
|
||||
'src/HW/SCREEN',
|
||||
'src/HW/SCSI',
|
||||
'src/HW/SOUND',
|
||||
'src/HW/VIA',
|
||||
'src/HW/VIDCARD',
|
||||
'src/LANG',
|
||||
'src/UI',
|
||||
'src/UI/SDL2',
|
||||
# 'src/UI/WIN32',
|
||||
'src/UTIL',
|
||||
'src/incbin',
|
||||
])
|
||||
|
||||
## Final compiled program definition
|
||||
|
1881
src/LANG/INTLCHAR.c
Normal file
1881
src/LANG/INTLCHAR.c
Normal file
File diff suppressed because it is too large
Load Diff
1904
src/LANG/INTLCHAR.h
1904
src/LANG/INTLCHAR.h
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@
|
||||
COMmon code for Operating System GLUe
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "SYSDEPNS.h"
|
||||
#include "GLOBGLUE.h"
|
||||
#include "MYOSGLUE.h"
|
||||
|
@ -49,6 +49,14 @@ typedef void (*SpclModeBody) (void);
|
||||
#define Keyboard_UpdateKeyMap1 Keyboard_UpdateKeyMap
|
||||
#define DisconnectKeyCodes1 DisconnectKeyCodes
|
||||
|
||||
bool SpeedStopped = false;
|
||||
bool RunInBackground = (WantInitRunInBackground != 0);
|
||||
bool WantFullScreen = (WantInitFullScreen != 0);
|
||||
bool WantMagnify = (WantInitMagnify != 0);
|
||||
bool RequestInsertDisk = false;
|
||||
uint8_t RequestIthDisk = 0;
|
||||
bool ControlKeyPressed = false;
|
||||
|
||||
/* Cell drawing */
|
||||
|
||||
LOCALPROC DrawCell(unsigned int h, unsigned int v, int x)
|
||||
|
@ -12,11 +12,21 @@
|
||||
#define CheckRomCheckSum 1
|
||||
#endif
|
||||
|
||||
#ifndef NeedRequestIthDisk
|
||||
#define NeedRequestIthDisk 0
|
||||
#endif
|
||||
|
||||
/* Globals */
|
||||
|
||||
extern uimr SpecialModes;
|
||||
extern bool NeedWholeScreenDraw;
|
||||
extern uint8_t * CntrlDisplayBuff;
|
||||
extern bool ControlKeyPressed;
|
||||
extern bool RequestInsertDisk;
|
||||
extern bool WantMagnify;
|
||||
extern bool RunInBackground;
|
||||
extern bool SpeedStopped;
|
||||
extern bool WantFullScreen;
|
||||
|
||||
/* Macros and such */
|
||||
|
||||
|
1060
src/UI/SDL2/CLIPBRD.c
Normal file
1060
src/UI/SDL2/CLIPBRD.c
Normal file
File diff suppressed because it is too large
Load Diff
73
src/UI/SDL2/DBGLOG.c
Normal file
73
src/UI/SDL2/DBGLOG.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* --- sending debugging info to file --- */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
|
||||
#if dbglog_HAVE
|
||||
|
||||
#ifndef dbglog_ToStdErr
|
||||
#define dbglog_ToStdErr 0
|
||||
#endif
|
||||
#ifndef dbglog_ToSDL_Log
|
||||
#define dbglog_ToSDL_Log 0
|
||||
#endif
|
||||
|
||||
#if ! dbglog_ToStdErr
|
||||
LOCALVAR FILE *dbglog_File = NULL;
|
||||
#endif
|
||||
|
||||
LOCALFUNC bool dbglog_open0(void)
|
||||
{
|
||||
#if dbglog_ToStdErr || dbglog_ToSDL_Log
|
||||
return true;
|
||||
#else
|
||||
if (NULL == app_parent) {
|
||||
dbglog_File = fopen("dbglog.txt", "w");
|
||||
} else {
|
||||
char *t;
|
||||
|
||||
if (mnvm_noErr == ChildPath(app_parent, "dbglog.txt", &t)) {
|
||||
dbglog_File = fopen(t, "w");
|
||||
free(t);
|
||||
}
|
||||
}
|
||||
|
||||
return (NULL != dbglog_File);
|
||||
#endif
|
||||
}
|
||||
|
||||
LOCALPROC dbglog_write0(char *s, uimr L)
|
||||
{
|
||||
#if dbglog_ToStdErr
|
||||
(void) fwrite(s, 1, L, stderr);
|
||||
#elif dbglog_ToSDL_Log
|
||||
char t[256 + 1];
|
||||
|
||||
if (L > 256) {
|
||||
L = 256;
|
||||
}
|
||||
(void) memcpy(t, s, L);
|
||||
t[L] = 1;
|
||||
|
||||
SDL_Log("%s", t);
|
||||
#else
|
||||
if (dbglog_File != NULL) {
|
||||
(void) fwrite(s, 1, L, dbglog_File);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
LOCALPROC dbglog_close0(void)
|
||||
{
|
||||
#if ! dbglog_ToStdErr
|
||||
if (dbglog_File != NULL) {
|
||||
fclose(dbglog_File);
|
||||
dbglog_File = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
275
src/UI/SDL2/DRIVES.c
Normal file
275
src/UI/SDL2/DRIVES.c
Normal file
@ -0,0 +1,275 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "CNFGRAPI.h"
|
||||
#include "EMCONFIG.h"
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "UI/COMOSGLU.h"
|
||||
#include "STRCONST.h"
|
||||
|
||||
/* --- drives --- */
|
||||
|
||||
#define NotAfileRef NULL
|
||||
|
||||
#ifndef UseRWops
|
||||
#define UseRWops 0
|
||||
#endif
|
||||
|
||||
#if UseRWops
|
||||
#define FilePtr SDL_RWops *
|
||||
#define Seek SDL_RWseek
|
||||
#define SeekSet RW_SEEK_SET
|
||||
#define SeekCur RW_SEEK_CUR
|
||||
#define SeekEnd RW_SEEK_END
|
||||
#define FileRead(ptr, size, nmemb, stream) \
|
||||
SDL_RWread(stream, ptr, size, nmemb)
|
||||
#define FileWrite(ptr, size, nmemb, stream) \
|
||||
SDL_RWwrite(stream, ptr, size, nmemb)
|
||||
#define FileTell SDL_RWtell
|
||||
#define FileClose SDL_RWclose
|
||||
#define FileOpen SDL_RWFromFile
|
||||
#else
|
||||
#define FilePtr FILE *
|
||||
#define Seek fseek
|
||||
#define SeekSet SEEK_SET
|
||||
#define SeekCur SEEK_CUR
|
||||
#define SeekEnd SEEK_END
|
||||
#define FileRead fread
|
||||
#define FileWrite fwrite
|
||||
#define FileTell ftell
|
||||
#define FileClose fclose
|
||||
#define FileOpen fopen
|
||||
#define FileEof feof
|
||||
#endif
|
||||
|
||||
FilePtr Drives[NumDrives]; /* open disk image files */
|
||||
|
||||
void InitDrives(void)
|
||||
{
|
||||
/*
|
||||
This isn't really needed, Drives[i] and DriveNames[i]
|
||||
need not have valid values when not vSonyIsInserted[i].
|
||||
*/
|
||||
tDrive i;
|
||||
|
||||
for (i = 0; i < NumDrives; ++i) {
|
||||
Drives[i] = NotAfileRef;
|
||||
}
|
||||
}
|
||||
|
||||
MacErr_t vSonyTransfer(bool IsWrite, uint8_t * Buffer,
|
||||
tDrive Drive_No, uint32_t Sony_Start, uint32_t Sony_Count,
|
||||
uint32_t *Sony_ActCount)
|
||||
{
|
||||
MacErr_t err = mnvm_miscErr;
|
||||
FilePtr refnum = Drives[Drive_No];
|
||||
uint32_t NewSony_Count = 0;
|
||||
|
||||
if (Seek(refnum, Sony_Start, SeekSet) >= 0) {
|
||||
if (IsWrite) {
|
||||
NewSony_Count = FileWrite(Buffer, 1, Sony_Count, refnum);
|
||||
} else {
|
||||
NewSony_Count = FileRead(Buffer, 1, Sony_Count, refnum);
|
||||
}
|
||||
|
||||
if (NewSony_Count == Sony_Count) {
|
||||
err = mnvm_noErr;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullpr != Sony_ActCount) {
|
||||
*Sony_ActCount = NewSony_Count;
|
||||
}
|
||||
|
||||
return err; /*& figure out what really to return &*/
|
||||
}
|
||||
|
||||
MacErr_t vSonyGetSize(tDrive Drive_No, uint32_t *Sony_Count)
|
||||
{
|
||||
MacErr_t err = mnvm_miscErr;
|
||||
FilePtr refnum = Drives[Drive_No];
|
||||
long v;
|
||||
|
||||
if (Seek(refnum, 0, SeekEnd) >= 0) {
|
||||
v = FileTell(refnum);
|
||||
if (v >= 0) {
|
||||
*Sony_Count = v;
|
||||
err = mnvm_noErr;
|
||||
}
|
||||
}
|
||||
|
||||
return err; /*& figure out what really to return &*/
|
||||
}
|
||||
|
||||
MacErr_t vSonyEject0(tDrive Drive_No, bool deleteit)
|
||||
{
|
||||
FilePtr refnum = Drives[Drive_No];
|
||||
|
||||
DiskEjectedNotify(Drive_No);
|
||||
|
||||
FileClose(refnum);
|
||||
Drives[Drive_No] = NotAfileRef; /* not really needed */
|
||||
|
||||
return mnvm_noErr;
|
||||
}
|
||||
|
||||
MacErr_t vSonyEject(tDrive Drive_No)
|
||||
{
|
||||
return vSonyEject0(Drive_No, false);
|
||||
}
|
||||
|
||||
MacErr_t vSonyEjectDelete(tDrive Drive_No)
|
||||
{
|
||||
return vSonyEject0(Drive_No, true);
|
||||
}
|
||||
|
||||
// TODO: complete the stub
|
||||
MacErr_t vSonyGetName (uint16_t Drive_No, uint16_t* r)
|
||||
{
|
||||
memcpy("TEST\0", r, 5);
|
||||
return mnvm_noErr;
|
||||
}
|
||||
|
||||
|
||||
void UnInitDrives(void)
|
||||
{
|
||||
tDrive i;
|
||||
|
||||
for (i = 0; i < NumDrives; ++i) {
|
||||
if (vSonyIsInserted(i)) {
|
||||
(void) vSonyEject(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Sony_Insert0(FilePtr refnum, bool locked, char *drivepath)
|
||||
{
|
||||
tDrive Drive_No;
|
||||
bool IsOk = false;
|
||||
|
||||
if (! FirstFreeDisk(&Drive_No)) {
|
||||
MacMsg(kStrTooManyImagesTitle, kStrTooManyImagesMessage,
|
||||
false);
|
||||
} else {
|
||||
/* printf("Sony_Insert0 %d\n", (int)Drive_No); */
|
||||
|
||||
{
|
||||
Drives[Drive_No] = refnum;
|
||||
DiskInsertNotify(Drive_No, locked);
|
||||
|
||||
IsOk = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (! IsOk) {
|
||||
FileClose(refnum);
|
||||
}
|
||||
|
||||
return IsOk;
|
||||
}
|
||||
|
||||
bool Sony_Insert1(char *drivepath, bool silentfail)
|
||||
{
|
||||
bool locked = false;
|
||||
/* printf("Sony_Insert1 %s\n", drivepath); */
|
||||
FilePtr refnum = FileOpen(drivepath, "rb+");
|
||||
if (NULL == refnum) {
|
||||
locked = true;
|
||||
refnum = FileOpen(drivepath, "rb");
|
||||
}
|
||||
if (NULL == refnum) {
|
||||
if (! silentfail) {
|
||||
MacMsg(kStrOpenFailTitle, kStrOpenFailMessage, false);
|
||||
}
|
||||
} else {
|
||||
return Sony_Insert0(refnum, locked, drivepath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
MacErr_t LoadMacRomFrom(char *path)
|
||||
{
|
||||
MacErr_t err;
|
||||
FilePtr ROM_File;
|
||||
int File_Size;
|
||||
|
||||
ROM_File = FileOpen(path, "rb");
|
||||
if (NULL == ROM_File) {
|
||||
err = mnvm_fnfErr;
|
||||
} else {
|
||||
File_Size = FileRead(ROM, 1, kROM_Size, ROM_File);
|
||||
if (File_Size != kROM_Size) {
|
||||
#ifdef FileEof
|
||||
if (FileEof(ROM_File))
|
||||
#else
|
||||
if (File_Size > 0)
|
||||
#endif
|
||||
{
|
||||
MacMsgOverride(kStrShortROMTitle,
|
||||
kStrShortROMMessage);
|
||||
err = mnvm_eofErr;
|
||||
} else {
|
||||
MacMsgOverride(kStrNoReadROMTitle,
|
||||
kStrNoReadROMMessage);
|
||||
err = mnvm_miscErr;
|
||||
}
|
||||
} else {
|
||||
err = ROM_IsValid();
|
||||
}
|
||||
FileClose(ROM_File);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
bool Sony_Insert1a(char *drivepath, bool silentfail)
|
||||
{
|
||||
bool v;
|
||||
|
||||
if (! ROM_loaded) {
|
||||
v = (mnvm_noErr == LoadMacRomFrom(drivepath));
|
||||
} else {
|
||||
v = Sony_Insert1(drivepath, silentfail);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
// TODO: implement stub function (or don't, lol)
|
||||
bool Sony_Insert2(char *s)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Sony_InsertIth(int i)
|
||||
{
|
||||
bool v;
|
||||
|
||||
if ((i > 9) || ! FirstFreeDisk(nullpr)) {
|
||||
v = false;
|
||||
} else {
|
||||
char s[] = "disk?.dsk";
|
||||
|
||||
s[4] = '0' + i;
|
||||
|
||||
v = Sony_Insert2(s);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
bool LoadInitialImages(void)
|
||||
{
|
||||
if (! AnyDiskInserted()) {
|
||||
int i;
|
||||
|
||||
for (i = 1; Sony_InsertIth(i); ++i) {
|
||||
/* stop on first error (including file not found) */
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
85
src/UI/SDL2/INTL.c
Normal file
85
src/UI/SDL2/INTL.c
Normal file
@ -0,0 +1,85 @@
|
||||
|
||||
/* --- control mode and internationalization --- */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "CNFGRAPI.h"
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "STRCONST.h"
|
||||
#include "LANG/INTLCHAR.h"
|
||||
|
||||
#ifndef CanGetAppPath
|
||||
#define CanGetAppPath 1
|
||||
#endif
|
||||
|
||||
LOCALVAR char *d_arg = NULL;
|
||||
LOCALVAR char *n_arg = NULL;
|
||||
|
||||
#if CanGetAppPath
|
||||
LOCALVAR char *app_parent = NULL;
|
||||
LOCALVAR char *pref_dir = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PathSep '\\'
|
||||
#else
|
||||
#define PathSep '/'
|
||||
#endif
|
||||
|
||||
MacErr_t ChildPath(char *x, char *y, char **r)
|
||||
{
|
||||
MacErr_t err = mnvm_miscErr;
|
||||
int nx = strlen(x);
|
||||
int ny = strlen(y);
|
||||
{
|
||||
if ((nx > 0) && (PathSep == x[nx - 1])) {
|
||||
--nx;
|
||||
}
|
||||
{
|
||||
int nr = nx + 1 + ny;
|
||||
char *p = malloc(nr + 1);
|
||||
if (p != NULL) {
|
||||
char *p2 = p;
|
||||
(void) memcpy(p2, x, nx);
|
||||
p2 += nx;
|
||||
*p2++ = PathSep;
|
||||
(void) memcpy(p2, y, ny);
|
||||
p2 += ny;
|
||||
*p2 = 0;
|
||||
*r = p;
|
||||
err = mnvm_noErr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void MayFree(char *p)
|
||||
{
|
||||
if (NULL != p) {
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* --- text translation --- */
|
||||
|
||||
void NativeStrFromCStr(char *r, char *s)
|
||||
{
|
||||
uint8_t ps[ClStrMaxLength];
|
||||
int i;
|
||||
int L;
|
||||
|
||||
ClStrFromSubstCStr(&L, ps, s);
|
||||
|
||||
for (i = 0; i < L; ++i) {
|
||||
r[i] = Cell2PlainAsciiMap[ps[i]];
|
||||
}
|
||||
|
||||
r[L] = 0;
|
||||
}
|
186
src/UI/SDL2/KEYBOARD.c
Normal file
186
src/UI/SDL2/KEYBOARD.c
Normal file
@ -0,0 +1,186 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "CNFGRAPI.h"
|
||||
#include "EMCONFIG.h"
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "STRCONST.h"
|
||||
|
||||
/* --- keyboard input --- */
|
||||
|
||||
uint8_t SDLScan2MacKeyCode(SDL_Scancode i)
|
||||
{
|
||||
uint8_t v = MKC_None;
|
||||
|
||||
switch (i) {
|
||||
case SDL_SCANCODE_BACKSPACE: v = MKC_BackSpace; break;
|
||||
case SDL_SCANCODE_TAB: v = MKC_Tab; break;
|
||||
case SDL_SCANCODE_CLEAR: v = MKC_Clear; break;
|
||||
case SDL_SCANCODE_RETURN: v = MKC_Return; break;
|
||||
case SDL_SCANCODE_PAUSE: v = MKC_Pause; break;
|
||||
case SDL_SCANCODE_ESCAPE: v = MKC_formac_Escape; break;
|
||||
case SDL_SCANCODE_SPACE: v = MKC_Space; break;
|
||||
case SDL_SCANCODE_APOSTROPHE: v = MKC_SingleQuote; break;
|
||||
case SDL_SCANCODE_COMMA: v = MKC_Comma; break;
|
||||
case SDL_SCANCODE_MINUS: v = MKC_Minus; break;
|
||||
case SDL_SCANCODE_PERIOD: v = MKC_Period; break;
|
||||
case SDL_SCANCODE_SLASH: v = MKC_formac_Slash; break;
|
||||
case SDL_SCANCODE_0: v = MKC_0; break;
|
||||
case SDL_SCANCODE_1: v = MKC_1; break;
|
||||
case SDL_SCANCODE_2: v = MKC_2; break;
|
||||
case SDL_SCANCODE_3: v = MKC_3; break;
|
||||
case SDL_SCANCODE_4: v = MKC_4; break;
|
||||
case SDL_SCANCODE_5: v = MKC_5; break;
|
||||
case SDL_SCANCODE_6: v = MKC_6; break;
|
||||
case SDL_SCANCODE_7: v = MKC_7; break;
|
||||
case SDL_SCANCODE_8: v = MKC_8; break;
|
||||
case SDL_SCANCODE_9: v = MKC_9; break;
|
||||
case SDL_SCANCODE_SEMICOLON: v = MKC_SemiColon; break;
|
||||
case SDL_SCANCODE_EQUALS: v = MKC_Equal; break;
|
||||
|
||||
case SDL_SCANCODE_LEFTBRACKET: v = MKC_LeftBracket; break;
|
||||
case SDL_SCANCODE_BACKSLASH: v = MKC_formac_BackSlash; break;
|
||||
case SDL_SCANCODE_RIGHTBRACKET: v = MKC_RightBracket; break;
|
||||
case SDL_SCANCODE_GRAVE: v = MKC_formac_Grave; break;
|
||||
|
||||
case SDL_SCANCODE_A: v = MKC_A; break;
|
||||
case SDL_SCANCODE_B: v = MKC_B; break;
|
||||
case SDL_SCANCODE_C: v = MKC_C; break;
|
||||
case SDL_SCANCODE_D: v = MKC_D; break;
|
||||
case SDL_SCANCODE_E: v = MKC_E; break;
|
||||
case SDL_SCANCODE_F: v = MKC_F; break;
|
||||
case SDL_SCANCODE_G: v = MKC_G; break;
|
||||
case SDL_SCANCODE_H: v = MKC_H; break;
|
||||
case SDL_SCANCODE_I: v = MKC_I; break;
|
||||
case SDL_SCANCODE_J: v = MKC_J; break;
|
||||
case SDL_SCANCODE_K: v = MKC_K; break;
|
||||
case SDL_SCANCODE_L: v = MKC_L; break;
|
||||
case SDL_SCANCODE_M: v = MKC_M; break;
|
||||
case SDL_SCANCODE_N: v = MKC_N; break;
|
||||
case SDL_SCANCODE_O: v = MKC_O; break;
|
||||
case SDL_SCANCODE_P: v = MKC_P; break;
|
||||
case SDL_SCANCODE_Q: v = MKC_Q; break;
|
||||
case SDL_SCANCODE_R: v = MKC_R; break;
|
||||
case SDL_SCANCODE_S: v = MKC_S; break;
|
||||
case SDL_SCANCODE_T: v = MKC_T; break;
|
||||
case SDL_SCANCODE_U: v = MKC_U; break;
|
||||
case SDL_SCANCODE_V: v = MKC_V; break;
|
||||
case SDL_SCANCODE_W: v = MKC_W; break;
|
||||
case SDL_SCANCODE_X: v = MKC_X; break;
|
||||
case SDL_SCANCODE_Y: v = MKC_Y; break;
|
||||
case SDL_SCANCODE_Z: v = MKC_Z; break;
|
||||
|
||||
case SDL_SCANCODE_KP_0: v = MKC_KP0; break;
|
||||
case SDL_SCANCODE_KP_1: v = MKC_KP1; break;
|
||||
case SDL_SCANCODE_KP_2: v = MKC_KP2; break;
|
||||
case SDL_SCANCODE_KP_3: v = MKC_KP3; break;
|
||||
case SDL_SCANCODE_KP_4: v = MKC_KP4; break;
|
||||
case SDL_SCANCODE_KP_5: v = MKC_KP5; break;
|
||||
case SDL_SCANCODE_KP_6: v = MKC_KP6; break;
|
||||
case SDL_SCANCODE_KP_7: v = MKC_KP7; break;
|
||||
case SDL_SCANCODE_KP_8: v = MKC_KP8; break;
|
||||
case SDL_SCANCODE_KP_9: v = MKC_KP9; break;
|
||||
|
||||
case SDL_SCANCODE_KP_PERIOD: v = MKC_Decimal; break;
|
||||
case SDL_SCANCODE_KP_DIVIDE: v = MKC_KPDevide; break;
|
||||
case SDL_SCANCODE_KP_MULTIPLY: v = MKC_KPMultiply; break;
|
||||
case SDL_SCANCODE_KP_MINUS: v = MKC_KPSubtract; break;
|
||||
case SDL_SCANCODE_KP_PLUS: v = MKC_KPAdd; break;
|
||||
case SDL_SCANCODE_KP_ENTER: v = MKC_formac_Enter; break;
|
||||
case SDL_SCANCODE_KP_EQUALS: v = MKC_KPEqual; break;
|
||||
|
||||
case SDL_SCANCODE_UP: v = MKC_Up; break;
|
||||
case SDL_SCANCODE_DOWN: v = MKC_Down; break;
|
||||
case SDL_SCANCODE_RIGHT: v = MKC_Right; break;
|
||||
case SDL_SCANCODE_LEFT: v = MKC_Left; break;
|
||||
case SDL_SCANCODE_INSERT: v = MKC_formac_Help; break;
|
||||
case SDL_SCANCODE_HOME: v = MKC_formac_Home; break;
|
||||
case SDL_SCANCODE_END: v = MKC_formac_End; break;
|
||||
case SDL_SCANCODE_PAGEUP: v = MKC_formac_PageUp; break;
|
||||
case SDL_SCANCODE_PAGEDOWN: v = MKC_formac_PageDown; break;
|
||||
|
||||
case SDL_SCANCODE_F1: v = MKC_formac_F1; break;
|
||||
case SDL_SCANCODE_F2: v = MKC_formac_F2; break;
|
||||
case SDL_SCANCODE_F3: v = MKC_formac_F3; break;
|
||||
case SDL_SCANCODE_F4: v = MKC_formac_F4; break;
|
||||
case SDL_SCANCODE_F5: v = MKC_formac_F5; break;
|
||||
case SDL_SCANCODE_F6: v = MKC_F6; break;
|
||||
case SDL_SCANCODE_F7: v = MKC_F7; break;
|
||||
case SDL_SCANCODE_F8: v = MKC_F8; break;
|
||||
case SDL_SCANCODE_F9: v = MKC_F9; break;
|
||||
case SDL_SCANCODE_F10: v = MKC_F10; break;
|
||||
case SDL_SCANCODE_F11: v = MKC_F11; break;
|
||||
case SDL_SCANCODE_F12: v = MKC_F12; break;
|
||||
|
||||
case SDL_SCANCODE_NUMLOCKCLEAR:
|
||||
v = MKC_formac_ForwardDel; break;
|
||||
case SDL_SCANCODE_CAPSLOCK: v = MKC_formac_CapsLock; break;
|
||||
case SDL_SCANCODE_SCROLLLOCK: v = MKC_ScrollLock; break;
|
||||
case SDL_SCANCODE_RSHIFT: v = MKC_formac_RShift; break;
|
||||
case SDL_SCANCODE_LSHIFT: v = MKC_formac_Shift; break;
|
||||
case SDL_SCANCODE_RCTRL: v = MKC_formac_RControl; break;
|
||||
case SDL_SCANCODE_LCTRL: v = MKC_formac_Control; break;
|
||||
case SDL_SCANCODE_RALT: v = MKC_formac_ROption; break;
|
||||
case SDL_SCANCODE_LALT: v = MKC_formac_Option; break;
|
||||
case SDL_SCANCODE_RGUI: v = MKC_formac_RCommand; break;
|
||||
case SDL_SCANCODE_LGUI: v = MKC_formac_Command; break;
|
||||
/* case SDLK_LSUPER: v = MKC_formac_Option; break; */
|
||||
/* case SDLK_RSUPER: v = MKC_formac_ROption; break; */
|
||||
|
||||
case SDL_SCANCODE_HELP: v = MKC_formac_Help; break;
|
||||
case SDL_SCANCODE_PRINTSCREEN: v = MKC_Print; break;
|
||||
|
||||
case SDL_SCANCODE_UNDO: v = MKC_formac_F1; break;
|
||||
case SDL_SCANCODE_CUT: v = MKC_formac_F2; break;
|
||||
case SDL_SCANCODE_COPY: v = MKC_formac_F3; break;
|
||||
case SDL_SCANCODE_PASTE: v = MKC_formac_F4; break;
|
||||
|
||||
case SDL_SCANCODE_AC_HOME: v = MKC_formac_Home; break;
|
||||
|
||||
case SDL_SCANCODE_KP_A: v = MKC_A; break;
|
||||
case SDL_SCANCODE_KP_B: v = MKC_B; break;
|
||||
case SDL_SCANCODE_KP_C: v = MKC_C; break;
|
||||
case SDL_SCANCODE_KP_D: v = MKC_D; break;
|
||||
case SDL_SCANCODE_KP_E: v = MKC_E; break;
|
||||
case SDL_SCANCODE_KP_F: v = MKC_F; break;
|
||||
|
||||
case SDL_SCANCODE_KP_BACKSPACE: v = MKC_BackSpace; break;
|
||||
case SDL_SCANCODE_KP_CLEAR: v = MKC_Clear; break;
|
||||
case SDL_SCANCODE_KP_COMMA: v = MKC_Comma; break;
|
||||
case SDL_SCANCODE_KP_DECIMAL: v = MKC_Decimal; break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void DoKeyCode(SDL_Keysym *r, bool down)
|
||||
{
|
||||
uint8_t v = SDLScan2MacKeyCode(r->scancode);
|
||||
if (MKC_None != v) {
|
||||
Keyboard_UpdateKeyMap2(v, down);
|
||||
}
|
||||
}
|
||||
|
||||
void DisableKeyRepeat(void)
|
||||
{
|
||||
}
|
||||
|
||||
void RestoreKeyRepeat(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ReconnectKeyCodes3(void)
|
||||
{
|
||||
}
|
||||
|
||||
void DisconnectKeyCodes3(void)
|
||||
{
|
||||
DisconnectKeyCodes2();
|
||||
MouseButtonSet(false);
|
||||
}
|
181
src/UI/SDL2/MOUSE.c
Normal file
181
src/UI/SDL2/MOUSE.c
Normal file
@ -0,0 +1,181 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "CNFGRAPI.h"
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "UI/COMOSGLU.h"
|
||||
#include "STRCONST.h"
|
||||
#include "OSGLUSD2.h"
|
||||
|
||||
/* --- mouse --- */
|
||||
|
||||
/* cursor hiding */
|
||||
|
||||
bool HaveCursorHidden = false;
|
||||
bool WantCursorHidden = false;
|
||||
|
||||
void ForceShowCursor(void)
|
||||
{
|
||||
if (HaveCursorHidden) {
|
||||
HaveCursorHidden = false;
|
||||
(void) SDL_ShowCursor(SDL_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
/* cursor moving */
|
||||
|
||||
#ifndef HaveWorkingWarp
|
||||
#define HaveWorkingWarp 1
|
||||
#endif
|
||||
|
||||
#if EnableMoveMouse && HaveWorkingWarp
|
||||
bool MoveMouse(int16_t h, int16_t v)
|
||||
{
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
h -= ViewHStart;
|
||||
v -= ViewVStart;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (UseMagnify) {
|
||||
h *= WindowScale;
|
||||
v *= WindowScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
h += hOffset;
|
||||
v += vOffset;
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_WarpMouseInWindow(main_wind, h, v);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* cursor state */
|
||||
|
||||
void MousePositionNotify(int NewMousePosh, int NewMousePosv)
|
||||
{
|
||||
bool ShouldHaveCursorHidden = true;
|
||||
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
NewMousePosh -= hOffset;
|
||||
NewMousePosv -= vOffset;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (UseMagnify) {
|
||||
NewMousePosh /= WindowScale;
|
||||
NewMousePosv /= WindowScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
NewMousePosh += ViewHStart;
|
||||
NewMousePosv += ViewVStart;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if EnableFSMouseMotion
|
||||
if (HaveMouseMotion) {
|
||||
MousePositionSetDelta(NewMousePosh - SavedMouseH,
|
||||
NewMousePosv - SavedMouseV);
|
||||
SavedMouseH = NewMousePosh;
|
||||
SavedMouseV = NewMousePosv;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (NewMousePosh < 0) {
|
||||
NewMousePosh = 0;
|
||||
ShouldHaveCursorHidden = false;
|
||||
} else if (NewMousePosh >= vMacScreenWidth) {
|
||||
NewMousePosh = vMacScreenWidth - 1;
|
||||
ShouldHaveCursorHidden = false;
|
||||
}
|
||||
if (NewMousePosv < 0) {
|
||||
NewMousePosv = 0;
|
||||
ShouldHaveCursorHidden = false;
|
||||
} else if (NewMousePosv >= vMacScreenHeight) {
|
||||
NewMousePosv = vMacScreenHeight - 1;
|
||||
ShouldHaveCursorHidden = false;
|
||||
}
|
||||
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
ShouldHaveCursorHidden = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if (ShouldHaveCursorHidden || CurMouseButton) */
|
||||
/*
|
||||
for a game like arkanoid, would like mouse to still
|
||||
move even when outside window in one direction
|
||||
*/
|
||||
MousePositionSet(NewMousePosh, NewMousePosv);
|
||||
}
|
||||
|
||||
WantCursorHidden = ShouldHaveCursorHidden;
|
||||
}
|
||||
|
||||
#if EnableFSMouseMotion && ! HaveWorkingWarp
|
||||
void MousePositionNotifyRelative(int deltah, int deltav)
|
||||
{
|
||||
bool ShouldHaveCursorHidden = true;
|
||||
|
||||
#if 1
|
||||
if (UseMagnify) {
|
||||
/*
|
||||
This is not really right. If only move one pixel
|
||||
each time, emulated mouse doesn't move at all.
|
||||
*/
|
||||
deltah /= WindowScale;
|
||||
deltav /= WindowScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
MousePositionSetDelta(deltah,
|
||||
deltav);
|
||||
|
||||
WantCursorHidden = ShouldHaveCursorHidden;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CheckMouseState(void)
|
||||
{
|
||||
/*
|
||||
this doesn't work as desired, doesn't get mouse movements
|
||||
when outside of our window.
|
||||
*/
|
||||
int x;
|
||||
int y;
|
||||
|
||||
(void) SDL_GetMouseState(&x, &y);
|
||||
MousePositionNotify(x, y);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
79
src/UI/SDL2/OSGLUSD2.h
Normal file
79
src/UI/SDL2/OSGLUSD2.h
Normal file
@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <SDL.h>
|
||||
#include "UI/MYOSGLUE.h"
|
||||
|
||||
/* --- defines and macros and such --- */
|
||||
|
||||
// video defines
|
||||
#ifndef UseSDLscaling
|
||||
#define UseSDLscaling 0
|
||||
#endif
|
||||
|
||||
#if 1 && ! UseSDLscaling
|
||||
#define MaxScale WindowScale
|
||||
#else
|
||||
#define MaxScale 1
|
||||
#endif
|
||||
|
||||
#define CLUT_finalsz (256 * 8 * 4 * MaxScale)
|
||||
|
||||
// sound defines
|
||||
#define kLn2SoundBuffers 4 /* kSoundBuffers must be a power of two */
|
||||
#define kSoundBuffers (1 << kLn2SoundBuffers)
|
||||
#define kSoundBuffMask (kSoundBuffers - 1)
|
||||
|
||||
#define DesiredMinFilledSoundBuffs 3
|
||||
/*
|
||||
if too big then sound lags behind emulation.
|
||||
if too small then sound will have pauses.
|
||||
*/
|
||||
|
||||
#define kLnOneBuffLen 9
|
||||
#define kLnAllBuffLen (kLn2SoundBuffers + kLnOneBuffLen)
|
||||
#define kOneBuffLen (1UL << kLnOneBuffLen)
|
||||
#define kAllBuffLen (1UL << kLnAllBuffLen)
|
||||
#define kLnOneBuffSz (kLnOneBuffLen + kLn2SoundSampSz - 3)
|
||||
#define kLnAllBuffSz (kLnAllBuffLen + kLn2SoundSampSz - 3)
|
||||
#define kOneBuffSz (1UL << kLnOneBuffSz)
|
||||
#define kAllBuffSz (1UL << kLnAllBuffSz)
|
||||
#define kOneBuffMask (kOneBuffLen - 1)
|
||||
#define kAllBuffMask (kAllBuffLen - 1)
|
||||
#define dbhBufferSize (kAllBuffSz + kOneBuffSz)
|
||||
|
||||
#define dbglog_SoundStuff (0 && dbglog_HAVE)
|
||||
#define dbglog_SoundBuffStats (0 && dbglog_HAVE)
|
||||
|
||||
|
||||
/* --- globals --- */
|
||||
|
||||
#if MayFullScreen
|
||||
extern int hOffset;
|
||||
extern int vOffset;
|
||||
#endif
|
||||
extern bool UseFullScreen;
|
||||
extern bool UseMagnify;
|
||||
|
||||
extern uint32_t TrueEmulatedTime;
|
||||
extern uint32_t LastTime;
|
||||
extern uint32_t NextIntTime;
|
||||
extern uint32_t NextFracTime;
|
||||
|
||||
extern bool gBackgroundFlag;
|
||||
extern bool gTrueBackgroundFlag;
|
||||
extern bool CurSpeedStopped;
|
||||
|
||||
extern SDL_Window *main_wind;
|
||||
extern SDL_Renderer *renderer;
|
||||
extern SDL_Texture *texture;
|
||||
extern SDL_PixelFormat *format;
|
||||
|
||||
extern uint8_t * ScalingBuff;
|
||||
extern uint8_t * CLUT_final;
|
||||
|
||||
extern bool HaveCursorHidden;
|
||||
extern bool WantCursorHidden;
|
||||
|
||||
extern tpSoundSamp TheSoundBuffer;
|
83
src/UI/SDL2/ROM.c
Normal file
83
src/UI/SDL2/ROM.c
Normal file
@ -0,0 +1,83 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "UI/COMOSGLU.h"
|
||||
|
||||
/* --- ROM --- */
|
||||
|
||||
LOCALVAR char *rom_path = NULL;
|
||||
|
||||
#if CanGetAppPath
|
||||
LOCALFUNC MacErr_t LoadMacRomFromPrefDir(void)
|
||||
{
|
||||
MacErr_t err;
|
||||
char *t = NULL;
|
||||
char *t2 = NULL;
|
||||
|
||||
if (NULL == pref_dir) {
|
||||
err = mnvm_fnfErr;
|
||||
} else
|
||||
if (mnvm_noErr != (err =
|
||||
ChildPath(pref_dir, "mnvm_rom", &t)))
|
||||
{
|
||||
/* fail */
|
||||
} else
|
||||
if (mnvm_noErr != (err =
|
||||
ChildPath(t, RomFileName, &t2)))
|
||||
{
|
||||
/* fail */
|
||||
} else
|
||||
{
|
||||
err = LoadMacRomFrom(t2);
|
||||
}
|
||||
|
||||
MayFree(t2);
|
||||
MayFree(t);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CanGetAppPath
|
||||
LOCALFUNC MacErr_t LoadMacRomFromAppPar(void)
|
||||
{
|
||||
MacErr_t err;
|
||||
char *d = (NULL == d_arg) ? app_parent : d_arg;
|
||||
char *t = NULL;
|
||||
|
||||
if (NULL == d) {
|
||||
err = mnvm_fnfErr;
|
||||
} else
|
||||
if (mnvm_noErr != (err =
|
||||
ChildPath(d, RomFileName, &t)))
|
||||
{
|
||||
/* fail */
|
||||
} else
|
||||
{
|
||||
err = LoadMacRomFrom(t);
|
||||
}
|
||||
|
||||
MayFree(t);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool LoadMacRom(void)
|
||||
{
|
||||
MacErr_t err;
|
||||
|
||||
if ((NULL == rom_path)
|
||||
|| (mnvm_fnfErr == (err = LoadMacRomFrom(rom_path))))
|
||||
#if CanGetAppPath
|
||||
if (mnvm_fnfErr == (err = LoadMacRomFromAppPar()))
|
||||
if (mnvm_fnfErr == (err = LoadMacRomFromPrefDir()))
|
||||
#endif
|
||||
if (mnvm_fnfErr == (err = LoadMacRomFrom(RomFileName)))
|
||||
{
|
||||
}
|
||||
|
||||
return true; /* keep launching Mini vMac, regardless */
|
||||
}
|
453
src/UI/SDL2/SOUND.c
Normal file
453
src/UI/SDL2/SOUND.c
Normal file
@ -0,0 +1,453 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "CNFGRAPI.h"
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "UI/COMOSGLU.h"
|
||||
#include "STRCONST.h"
|
||||
#include "OSGLUSD2.h"
|
||||
|
||||
/* --- sound --- */
|
||||
|
||||
#if SoundEnabled
|
||||
|
||||
|
||||
tpSoundSamp TheSoundBuffer = nullpr;
|
||||
volatile static uint16_t ThePlayOffset;
|
||||
volatile static uint16_t TheFillOffset;
|
||||
volatile static uint16_t MinFilledSoundBuffs;
|
||||
#if dbglog_SoundBuffStats
|
||||
LOCALVAR uint16_t MaxFilledSoundBuffs;
|
||||
#endif
|
||||
LOCALVAR uint16_t TheWriteOffset;
|
||||
|
||||
void Sound_Init0(void)
|
||||
{
|
||||
ThePlayOffset = 0;
|
||||
TheFillOffset = 0;
|
||||
TheWriteOffset = 0;
|
||||
}
|
||||
|
||||
void Sound_Start0(void)
|
||||
{
|
||||
/* Reset variables */
|
||||
MinFilledSoundBuffs = kSoundBuffers + 1;
|
||||
#if dbglog_SoundBuffStats
|
||||
MaxFilledSoundBuffs = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
GLOBALOSGLUFUNC tpSoundSamp Sound_BeginWrite(uint16_t n, uint16_t *actL)
|
||||
{
|
||||
uint16_t ToFillLen = kAllBuffLen - (TheWriteOffset - ThePlayOffset);
|
||||
uint16_t WriteBuffContig =
|
||||
kOneBuffLen - (TheWriteOffset & kOneBuffMask);
|
||||
|
||||
if (WriteBuffContig < n) {
|
||||
n = WriteBuffContig;
|
||||
}
|
||||
if (ToFillLen < n) {
|
||||
/* overwrite previous buffer */
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("sound buffer over flow");
|
||||
#endif
|
||||
TheWriteOffset -= kOneBuffLen;
|
||||
}
|
||||
|
||||
*actL = n;
|
||||
return TheSoundBuffer + (TheWriteOffset & kAllBuffMask);
|
||||
}
|
||||
|
||||
#if 4 == kLn2SoundSampSz
|
||||
void ConvertSoundBlockToNative(tpSoundSamp p)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = kOneBuffLen; --i >= 0; ) {
|
||||
*p++ -= 0x8000;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define ConvertSoundBlockToNative(p)
|
||||
#endif
|
||||
|
||||
void Sound_WroteABlock(void)
|
||||
{
|
||||
#if (4 == kLn2SoundSampSz)
|
||||
uint16_t PrevWriteOffset = TheWriteOffset - kOneBuffLen;
|
||||
tpSoundSamp p = TheSoundBuffer + (PrevWriteOffset & kAllBuffMask);
|
||||
#endif
|
||||
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("enter Sound_WroteABlock");
|
||||
#endif
|
||||
|
||||
ConvertSoundBlockToNative(p);
|
||||
|
||||
TheFillOffset = TheWriteOffset;
|
||||
|
||||
#if dbglog_SoundBuffStats
|
||||
{
|
||||
uint16_t ToPlayLen = TheFillOffset
|
||||
- ThePlayOffset;
|
||||
uint16_t ToPlayBuffs = ToPlayLen >> kLnOneBuffLen;
|
||||
|
||||
if (ToPlayBuffs > MaxFilledSoundBuffs) {
|
||||
MaxFilledSoundBuffs = ToPlayBuffs;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Sound_EndWrite0(uint16_t actL)
|
||||
{
|
||||
bool v;
|
||||
|
||||
TheWriteOffset += actL;
|
||||
|
||||
if (0 != (TheWriteOffset & kOneBuffMask)) {
|
||||
v = false;
|
||||
} else {
|
||||
/* just finished a block */
|
||||
|
||||
Sound_WroteABlock();
|
||||
|
||||
v = true;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void Sound_SecondNotify0(void)
|
||||
{
|
||||
if (MinFilledSoundBuffs <= kSoundBuffers) {
|
||||
if (MinFilledSoundBuffs > DesiredMinFilledSoundBuffs) {
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("MinFilledSoundBuffs too high");
|
||||
#endif
|
||||
IncrNextTime();
|
||||
} else if (MinFilledSoundBuffs < DesiredMinFilledSoundBuffs) {
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("MinFilledSoundBuffs too low");
|
||||
#endif
|
||||
++TrueEmulatedTime;
|
||||
}
|
||||
#if dbglog_SoundBuffStats
|
||||
dbglog_writelnNum("MinFilledSoundBuffs",
|
||||
MinFilledSoundBuffs);
|
||||
dbglog_writelnNum("MaxFilledSoundBuffs",
|
||||
MaxFilledSoundBuffs);
|
||||
MaxFilledSoundBuffs = 0;
|
||||
#endif
|
||||
MinFilledSoundBuffs = kSoundBuffers + 1;
|
||||
}
|
||||
}
|
||||
|
||||
typedef uint16_t trSoundTemp;
|
||||
|
||||
#define kCenterTempSound 0x8000
|
||||
|
||||
#define AudioStepVal 0x0040
|
||||
|
||||
#if 3 == kLn2SoundSampSz
|
||||
#define ConvertTempSoundSampleFromNative(v) ((v) << 8)
|
||||
#elif 4 == kLn2SoundSampSz
|
||||
#define ConvertTempSoundSampleFromNative(v) ((v) + kCenterSound)
|
||||
#else
|
||||
#error "unsupported kLn2SoundSampSz"
|
||||
#endif
|
||||
|
||||
#if 3 == kLn2SoundSampSz
|
||||
#define ConvertTempSoundSampleToNative(v) ((v) >> 8)
|
||||
#elif 4 == kLn2SoundSampSz
|
||||
#define ConvertTempSoundSampleToNative(v) ((v) - kCenterSound)
|
||||
#else
|
||||
#error "unsupported kLn2SoundSampSz"
|
||||
#endif
|
||||
|
||||
void SoundRampTo(trSoundTemp *last_val, trSoundTemp dst_val,
|
||||
tpSoundSamp *stream, int *len)
|
||||
{
|
||||
trSoundTemp diff;
|
||||
tpSoundSamp p = *stream;
|
||||
int n = *len;
|
||||
trSoundTemp v1 = *last_val;
|
||||
|
||||
while ((v1 != dst_val) && (0 != n)) {
|
||||
if (v1 > dst_val) {
|
||||
diff = v1 - dst_val;
|
||||
if (diff > AudioStepVal) {
|
||||
v1 -= AudioStepVal;
|
||||
} else {
|
||||
v1 = dst_val;
|
||||
}
|
||||
} else {
|
||||
diff = dst_val - v1;
|
||||
if (diff > AudioStepVal) {
|
||||
v1 += AudioStepVal;
|
||||
} else {
|
||||
v1 = dst_val;
|
||||
}
|
||||
}
|
||||
|
||||
--n;
|
||||
*p++ = ConvertTempSoundSampleToNative(v1);
|
||||
}
|
||||
|
||||
*stream = p;
|
||||
*len = n;
|
||||
*last_val = v1;
|
||||
}
|
||||
|
||||
struct SoundR {
|
||||
tpSoundSamp fTheSoundBuffer;
|
||||
volatile uint16_t (*fPlayOffset);
|
||||
volatile uint16_t (*fFillOffset);
|
||||
volatile uint16_t (*fMinFilledSoundBuffs);
|
||||
|
||||
volatile trSoundTemp lastv;
|
||||
|
||||
bool wantplaying;
|
||||
bool HaveStartedPlaying;
|
||||
};
|
||||
typedef struct SoundR SoundR;
|
||||
|
||||
static void audio_callback(void *udata, Uint8 *stream, int len)
|
||||
{
|
||||
uint16_t ToPlayLen;
|
||||
uint16_t FilledSoundBuffs;
|
||||
int i;
|
||||
SoundR *datp = (SoundR *)udata;
|
||||
tpSoundSamp CurSoundBuffer = datp->fTheSoundBuffer;
|
||||
uint16_t CurPlayOffset = *datp->fPlayOffset;
|
||||
trSoundTemp v0 = datp->lastv;
|
||||
trSoundTemp v1 = v0;
|
||||
tpSoundSamp dst = (tpSoundSamp)stream;
|
||||
|
||||
#if kLn2SoundSampSz > 3
|
||||
len >>= (kLn2SoundSampSz - 3);
|
||||
#endif
|
||||
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("Enter audio_callback");
|
||||
dbglog_writelnNum("len", len);
|
||||
#endif
|
||||
|
||||
label_retry:
|
||||
ToPlayLen = *datp->fFillOffset - CurPlayOffset;
|
||||
FilledSoundBuffs = ToPlayLen >> kLnOneBuffLen;
|
||||
|
||||
if (! datp->wantplaying) {
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("playing end transistion");
|
||||
#endif
|
||||
|
||||
SoundRampTo(&v1, kCenterTempSound, &dst, &len);
|
||||
|
||||
ToPlayLen = 0;
|
||||
} else if (! datp->HaveStartedPlaying) {
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("playing start block");
|
||||
#endif
|
||||
|
||||
if ((ToPlayLen >> kLnOneBuffLen) < 8) {
|
||||
ToPlayLen = 0;
|
||||
} else {
|
||||
tpSoundSamp p = datp->fTheSoundBuffer
|
||||
+ (CurPlayOffset & kAllBuffMask);
|
||||
trSoundTemp v2 = ConvertTempSoundSampleFromNative(*p);
|
||||
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("have enough samples to start");
|
||||
#endif
|
||||
|
||||
SoundRampTo(&v1, v2, &dst, &len);
|
||||
|
||||
if (v1 == v2) {
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("finished start transition");
|
||||
#endif
|
||||
|
||||
datp->HaveStartedPlaying = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == len) {
|
||||
/* done */
|
||||
|
||||
if (FilledSoundBuffs < *datp->fMinFilledSoundBuffs) {
|
||||
*datp->fMinFilledSoundBuffs = FilledSoundBuffs;
|
||||
}
|
||||
} else if (0 == ToPlayLen) {
|
||||
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("under run");
|
||||
#endif
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
*dst++ = ConvertTempSoundSampleToNative(v1);
|
||||
}
|
||||
*datp->fMinFilledSoundBuffs = 0;
|
||||
} else {
|
||||
uint16_t PlayBuffContig = kAllBuffLen
|
||||
- (CurPlayOffset & kAllBuffMask);
|
||||
tpSoundSamp p = CurSoundBuffer
|
||||
+ (CurPlayOffset & kAllBuffMask);
|
||||
|
||||
if (ToPlayLen > PlayBuffContig) {
|
||||
ToPlayLen = PlayBuffContig;
|
||||
}
|
||||
if (ToPlayLen > len) {
|
||||
ToPlayLen = len;
|
||||
}
|
||||
|
||||
for (i = 0; i < ToPlayLen; ++i) {
|
||||
*dst++ = *p++;
|
||||
}
|
||||
v1 = ConvertTempSoundSampleFromNative(p[-1]);
|
||||
|
||||
CurPlayOffset += ToPlayLen;
|
||||
len -= ToPlayLen;
|
||||
|
||||
*datp->fPlayOffset = CurPlayOffset;
|
||||
|
||||
goto label_retry;
|
||||
}
|
||||
|
||||
datp->lastv = v1;
|
||||
}
|
||||
|
||||
LOCALVAR SoundR cur_audio;
|
||||
|
||||
LOCALVAR bool HaveSoundOut = false;
|
||||
|
||||
void Sound_Stop(void)
|
||||
{
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("enter Sound_Stop");
|
||||
#endif
|
||||
|
||||
if (cur_audio.wantplaying && HaveSoundOut) {
|
||||
uint16_t retry_limit = 50; /* half of a second */
|
||||
|
||||
cur_audio.wantplaying = false;
|
||||
|
||||
label_retry:
|
||||
if (kCenterTempSound == cur_audio.lastv) {
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("reached kCenterTempSound");
|
||||
#endif
|
||||
|
||||
/* done */
|
||||
} else if (0 == --retry_limit) {
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("retry limit reached");
|
||||
#endif
|
||||
/* done */
|
||||
} else
|
||||
{
|
||||
/*
|
||||
give time back, particularly important
|
||||
if got here on a suspend event.
|
||||
*/
|
||||
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("busy, so sleep");
|
||||
#endif
|
||||
|
||||
(void) SDL_Delay(10);
|
||||
|
||||
goto label_retry;
|
||||
}
|
||||
|
||||
SDL_PauseAudio(1);
|
||||
}
|
||||
|
||||
#if dbglog_SoundStuff
|
||||
dbglog_writeln("leave Sound_Stop");
|
||||
#endif
|
||||
}
|
||||
|
||||
void Sound_Start(void)
|
||||
{
|
||||
if ((! cur_audio.wantplaying) && HaveSoundOut) {
|
||||
Sound_Start0();
|
||||
cur_audio.lastv = kCenterTempSound;
|
||||
cur_audio.HaveStartedPlaying = false;
|
||||
cur_audio.wantplaying = true;
|
||||
|
||||
SDL_PauseAudio(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Sound_UnInit(void)
|
||||
{
|
||||
if (HaveSoundOut) {
|
||||
SDL_CloseAudio();
|
||||
}
|
||||
}
|
||||
|
||||
#define SOUND_SAMPLERATE 22255 /* = round(7833600 * 2 / 704) */
|
||||
|
||||
bool Sound_Init(void)
|
||||
{
|
||||
SDL_AudioSpec desired;
|
||||
|
||||
Sound_Init0();
|
||||
|
||||
cur_audio.fTheSoundBuffer = TheSoundBuffer;
|
||||
cur_audio.fPlayOffset = &ThePlayOffset;
|
||||
cur_audio.fFillOffset = &TheFillOffset;
|
||||
cur_audio.fMinFilledSoundBuffs = &MinFilledSoundBuffs;
|
||||
cur_audio.wantplaying = false;
|
||||
|
||||
desired.freq = SOUND_SAMPLERATE;
|
||||
|
||||
#if 3 == kLn2SoundSampSz
|
||||
desired.format = AUDIO_U8;
|
||||
#elif 4 == kLn2SoundSampSz
|
||||
desired.format = AUDIO_S16SYS;
|
||||
#else
|
||||
#error "unsupported audio format"
|
||||
#endif
|
||||
|
||||
desired.channels = 1;
|
||||
desired.samples = 1024;
|
||||
desired.callback = audio_callback;
|
||||
desired.userdata = (void *)&cur_audio;
|
||||
|
||||
/* Open the audio device */
|
||||
if (SDL_OpenAudio(&desired, NULL) < 0) {
|
||||
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
} else {
|
||||
HaveSoundOut = true;
|
||||
|
||||
Sound_Start();
|
||||
/*
|
||||
This should be taken care of by LeaveSpeedStopped,
|
||||
but since takes a while to get going properly,
|
||||
start early.
|
||||
*/
|
||||
}
|
||||
|
||||
return true; /* keep going, even if no sound */
|
||||
}
|
||||
|
||||
GLOBALOSGLUPROC Sound_EndWrite(uint16_t actL)
|
||||
{
|
||||
if (Sound_EndWrite0(actL)) {
|
||||
}
|
||||
}
|
||||
|
||||
void Sound_SecondNotify(void)
|
||||
{
|
||||
if (HaveSoundOut) {
|
||||
Sound_SecondNotify0();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
112
src/UI/SDL2/TIMEDATE.c
Normal file
112
src/UI/SDL2/TIMEDATE.c
Normal file
@ -0,0 +1,112 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "CNFGRAPI.h"
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "STRCONST.h"
|
||||
|
||||
/* --- time, date, location --- */
|
||||
|
||||
#define dbglog_TimeStuff (0 && dbglog_HAVE)
|
||||
|
||||
uint32_t TrueEmulatedTime = 0;
|
||||
|
||||
#define InvTimeDivPow 16
|
||||
#define InvTimeDiv (1 << InvTimeDivPow)
|
||||
#define InvTimeDivMask (InvTimeDiv - 1)
|
||||
#define InvTimeStep 1089590 /* 1000 / 60.14742 * InvTimeDiv */
|
||||
|
||||
uint32_t LastTime;
|
||||
uint32_t NextIntTime;
|
||||
uint32_t NextFracTime;
|
||||
|
||||
void IncrNextTime(void)
|
||||
{
|
||||
NextFracTime += InvTimeStep;
|
||||
NextIntTime += (NextFracTime >> InvTimeDivPow);
|
||||
NextFracTime &= InvTimeDivMask;
|
||||
}
|
||||
|
||||
void InitNextTime(void)
|
||||
{
|
||||
NextIntTime = LastTime;
|
||||
NextFracTime = 0;
|
||||
IncrNextTime();
|
||||
}
|
||||
|
||||
LOCALVAR uint32_t NewMacDateInSeconds;
|
||||
|
||||
bool UpdateTrueEmulatedTime(void)
|
||||
{
|
||||
Uint32 LatestTime;
|
||||
int32_t TimeDiff;
|
||||
|
||||
LatestTime = SDL_GetTicks();
|
||||
if (LatestTime != LastTime) {
|
||||
|
||||
NewMacDateInSeconds = LatestTime / 1000;
|
||||
/* no date and time api in SDL */
|
||||
|
||||
LastTime = LatestTime;
|
||||
TimeDiff = (LatestTime - NextIntTime);
|
||||
/* this should work even when time wraps */
|
||||
if (TimeDiff >= 0) {
|
||||
if (TimeDiff > 256) {
|
||||
/* emulation interrupted, forget it */
|
||||
++TrueEmulatedTime;
|
||||
InitNextTime();
|
||||
|
||||
#if dbglog_TimeStuff
|
||||
dbglog_writelnNum("emulation interrupted",
|
||||
TrueEmulatedTime);
|
||||
#endif
|
||||
} else {
|
||||
do {
|
||||
++TrueEmulatedTime;
|
||||
IncrNextTime();
|
||||
TimeDiff = (LatestTime - NextIntTime);
|
||||
} while (TimeDiff >= 0);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (TimeDiff < -256) {
|
||||
#if dbglog_TimeStuff
|
||||
dbglog_writeln("clock set back");
|
||||
#endif
|
||||
/* clock goofed if ever get here, reset */
|
||||
InitNextTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CheckDateTime(void)
|
||||
{
|
||||
if (CurMacDateInSeconds != NewMacDateInSeconds) {
|
||||
CurMacDateInSeconds = NewMacDateInSeconds;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void StartUpTimeAdjust(void)
|
||||
{
|
||||
LastTime = SDL_GetTicks();
|
||||
InitNextTime();
|
||||
}
|
||||
|
||||
bool InitLocationDat(void)
|
||||
{
|
||||
LastTime = SDL_GetTicks();
|
||||
InitNextTime();
|
||||
NewMacDateInSeconds = LastTime / 1000;
|
||||
CurMacDateInSeconds = NewMacDateInSeconds;
|
||||
|
||||
return true;
|
||||
}
|
552
src/UI/SDL2/VIDEO.c
Normal file
552
src/UI/SDL2/VIDEO.c
Normal file
@ -0,0 +1,552 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "CNFGRAPI.h"
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "UI/COMOSGLU.h"
|
||||
#include "STRCONST.h"
|
||||
#include "OSGLUSD2.h"
|
||||
|
||||
/* --- video out --- */
|
||||
|
||||
#if MayFullScreen
|
||||
int hOffset;
|
||||
int vOffset;
|
||||
#endif
|
||||
bool UseFullScreen = (WantInitFullScreen != 0);
|
||||
bool UseMagnify = (WantInitMagnify != 0);
|
||||
|
||||
bool gBackgroundFlag = false;
|
||||
bool gTrueBackgroundFlag = false;
|
||||
bool CurSpeedStopped = true;
|
||||
SDL_Window *main_wind = NULL;
|
||||
SDL_Renderer *renderer = NULL;
|
||||
SDL_Texture *texture = NULL;
|
||||
SDL_PixelFormat *format = NULL;
|
||||
|
||||
uint8_t * ScalingBuff = nullpr;
|
||||
uint8_t * CLUT_final;
|
||||
/*
|
||||
256 possible values of one byte
|
||||
8 pixels per byte maximum (when black and white)
|
||||
4 bytes per destination pixel maximum
|
||||
multiplied by WindowScale if 1
|
||||
*/
|
||||
|
||||
#define ScrnMapr_DoMap UpdateBWDepth3Copy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth 0
|
||||
#define ScrnMapr_DstDepth 3
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateBWDepth4Copy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth 0
|
||||
#define ScrnMapr_DstDepth 4
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateBWDepth5Copy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth 0
|
||||
#define ScrnMapr_DstDepth 5
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#if 1 && ! UseSDLscaling
|
||||
|
||||
#define ScrnMapr_DoMap UpdateBWDepth3ScaledCopy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth 0
|
||||
#define ScrnMapr_DstDepth 3
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
#define ScrnMapr_Scale WindowScale
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateBWDepth4ScaledCopy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth 0
|
||||
#define ScrnMapr_DstDepth 4
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
#define ScrnMapr_Scale WindowScale
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateBWDepth5ScaledCopy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth 0
|
||||
#define ScrnMapr_DstDepth 5
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
#define ScrnMapr_Scale WindowScale
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#endif /* 1 && ! UseSDLscaling */
|
||||
|
||||
|
||||
#if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)
|
||||
|
||||
#define ScrnMapr_DoMap UpdateColorDepth3Copy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth vMacScreenDepth
|
||||
#define ScrnMapr_DstDepth 3
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateColorDepth4Copy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth vMacScreenDepth
|
||||
#define ScrnMapr_DstDepth 4
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateColorDepth5Copy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth vMacScreenDepth
|
||||
#define ScrnMapr_DstDepth 5
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#if 1 && ! UseSDLscaling
|
||||
|
||||
#define ScrnMapr_DoMap UpdateColorDepth3ScaledCopy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth vMacScreenDepth
|
||||
#define ScrnMapr_DstDepth 3
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
#define ScrnMapr_Scale WindowScale
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateColorDepth4ScaledCopy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth vMacScreenDepth
|
||||
#define ScrnMapr_DstDepth 4
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
#define ScrnMapr_Scale WindowScale
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#define ScrnMapr_DoMap UpdateColorDepth5ScaledCopy
|
||||
#define ScrnMapr_Src GetCurDrawBuff()
|
||||
#define ScrnMapr_Dst ScalingBuff
|
||||
#define ScrnMapr_SrcDepth vMacScreenDepth
|
||||
#define ScrnMapr_DstDepth 5
|
||||
#define ScrnMapr_Map CLUT_final
|
||||
#define ScrnMapr_Scale WindowScale
|
||||
|
||||
#include "HW/SCREEN/SCRNMAPR.h"
|
||||
|
||||
#endif /* 1 && ! UseSDLscaling */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
LOCALPROC HaveChangedScreenBuff(uint16_t top, uint16_t left,
|
||||
uint16_t bottom, uint16_t right)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
uint8_t *p;
|
||||
Uint32 pixel;
|
||||
#if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)
|
||||
Uint32 CLUT_pixel[CLUT_size];
|
||||
#endif
|
||||
Uint32 BWLUT_pixel[2];
|
||||
uint32_t top2;
|
||||
uint32_t left2;
|
||||
uint32_t bottom2;
|
||||
uint32_t right2;
|
||||
void *pixels;
|
||||
int pitch;
|
||||
SDL_Rect src_rect;
|
||||
SDL_Rect dst_rect;
|
||||
int XDest;
|
||||
int YDest;
|
||||
int DestWidth;
|
||||
int DestHeight;
|
||||
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
if (top < ViewVStart) {
|
||||
top = ViewVStart;
|
||||
}
|
||||
if (left < ViewHStart) {
|
||||
left = ViewHStart;
|
||||
}
|
||||
if (bottom > ViewVStart + ViewVSize) {
|
||||
bottom = ViewVStart + ViewVSize;
|
||||
}
|
||||
if (right > ViewHStart + ViewHSize) {
|
||||
right = ViewHStart + ViewHSize;
|
||||
}
|
||||
|
||||
if ((top >= bottom) || (left >= right)) {
|
||||
goto label_exit;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
XDest = left;
|
||||
YDest = top;
|
||||
DestWidth = (right - left);
|
||||
DestHeight = (bottom - top);
|
||||
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
XDest -= ViewHStart;
|
||||
YDest -= ViewVStart;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (UseMagnify) {
|
||||
XDest *= WindowScale;
|
||||
YDest *= WindowScale;
|
||||
DestWidth *= WindowScale;
|
||||
DestHeight *= WindowScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (UseFullScreen)
|
||||
#endif
|
||||
#if MayFullScreen
|
||||
{
|
||||
XDest += hOffset;
|
||||
YDest += vOffset;
|
||||
}
|
||||
#endif
|
||||
|
||||
top2 = top;
|
||||
left2 = left;
|
||||
bottom2 = bottom;
|
||||
right2 = right;
|
||||
|
||||
#if 1 && ! UseSDLscaling
|
||||
if (UseMagnify) {
|
||||
top2 *= WindowScale;
|
||||
left2 *= WindowScale;
|
||||
bottom2 *= WindowScale;
|
||||
right2 *= WindowScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (0 != SDL_LockTexture(texture, NULL, &pixels, &pitch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
int bpp = format->BytesPerPixel;
|
||||
uint32_t ExpectedPitch = vMacScreenWidth * bpp;
|
||||
|
||||
#if 1 && ! UseSDLscaling
|
||||
if (UseMagnify) {
|
||||
ExpectedPitch *= WindowScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 != vMacScreenDepth
|
||||
if (UseColorMode) {
|
||||
#if vMacScreenDepth < 4
|
||||
for (i = 0; i < CLUT_size; ++i) {
|
||||
CLUT_pixel[i] = SDL_MapRGB(format,
|
||||
CLUT_reds[i] >> 8,
|
||||
CLUT_greens[i] >> 8,
|
||||
CLUT_blues[i] >> 8);
|
||||
}
|
||||
#endif
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
BWLUT_pixel[1] = SDL_MapRGB(format, 0, 0, 0);
|
||||
/* black */
|
||||
BWLUT_pixel[0] = SDL_MapRGB(format, 255, 255, 255);
|
||||
/* white */
|
||||
}
|
||||
|
||||
if ((0 == ((bpp - 1) & bpp)) /* a power of 2 */
|
||||
&& (pitch == ExpectedPitch)
|
||||
#if (vMacScreenDepth > 3)
|
||||
&& ! UseColorMode
|
||||
#endif
|
||||
)
|
||||
{
|
||||
int k;
|
||||
Uint32 v;
|
||||
#if 1 && ! UseSDLscaling
|
||||
int a;
|
||||
#endif
|
||||
int PixPerByte =
|
||||
#if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)
|
||||
UseColorMode ? (1 << (3 - vMacScreenDepth)) :
|
||||
#endif
|
||||
8;
|
||||
Uint8 *p4 = (Uint8 *)CLUT_final;
|
||||
|
||||
for (i = 0; i < 256; ++i) {
|
||||
for (k = PixPerByte; --k >= 0; ) {
|
||||
|
||||
#if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)
|
||||
if (UseColorMode) {
|
||||
v = CLUT_pixel[
|
||||
#if 3 == vMacScreenDepth
|
||||
i
|
||||
#else
|
||||
(i >> (k << vMacScreenDepth))
|
||||
& (CLUT_size - 1)
|
||||
#endif
|
||||
];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
v = BWLUT_pixel[(i >> k) & 1];
|
||||
}
|
||||
|
||||
#if 1 && ! UseSDLscaling
|
||||
for (a = UseMagnify ? WindowScale : 1; --a >= 0; )
|
||||
#endif
|
||||
{
|
||||
switch (bpp) {
|
||||
case 1: /* Assuming 8-bpp */
|
||||
*p4++ = v;
|
||||
break;
|
||||
case 2: /* Probably 15-bpp or 16-bpp */
|
||||
*(Uint16 *)p4 = v;
|
||||
p4 += 2;
|
||||
break;
|
||||
case 4: /* Probably 32-bpp */
|
||||
*(Uint32 *)p4 = v;
|
||||
p4 += 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScalingBuff = (uint8_t *)pixels;
|
||||
|
||||
#if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)
|
||||
if (UseColorMode) {
|
||||
#if 1 && ! UseSDLscaling
|
||||
if (UseMagnify) {
|
||||
switch (bpp) {
|
||||
case 1:
|
||||
UpdateColorDepth3ScaledCopy(
|
||||
top, left, bottom, right);
|
||||
break;
|
||||
case 2:
|
||||
UpdateColorDepth4ScaledCopy(
|
||||
top, left, bottom, right);
|
||||
break;
|
||||
case 4:
|
||||
UpdateColorDepth5ScaledCopy(
|
||||
top, left, bottom, right);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
switch (bpp) {
|
||||
case 1:
|
||||
UpdateColorDepth3Copy(top, left, bottom, right);
|
||||
break;
|
||||
case 2:
|
||||
UpdateColorDepth4Copy(top, left, bottom, right);
|
||||
break;
|
||||
case 4:
|
||||
UpdateColorDepth5Copy(top, left, bottom, right);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#if 1 && ! UseSDLscaling
|
||||
if (UseMagnify) {
|
||||
switch (bpp) {
|
||||
case 1:
|
||||
UpdateBWDepth3ScaledCopy(
|
||||
top, left, bottom, right);
|
||||
break;
|
||||
case 2:
|
||||
UpdateBWDepth4ScaledCopy(
|
||||
top, left, bottom, right);
|
||||
break;
|
||||
case 4:
|
||||
UpdateBWDepth5ScaledCopy(
|
||||
top, left, bottom, right);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
switch (bpp) {
|
||||
case 1:
|
||||
UpdateBWDepth3Copy(top, left, bottom, right);
|
||||
break;
|
||||
case 2:
|
||||
UpdateBWDepth4Copy(top, left, bottom, right);
|
||||
break;
|
||||
case 4:
|
||||
UpdateBWDepth5Copy(top, left, bottom, right);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
uint8_t *the_data = (uint8_t *)GetCurDrawBuff();
|
||||
|
||||
/* adapted from putpixel in SDL documentation */
|
||||
|
||||
for (i = top2; i < bottom2; ++i) {
|
||||
for (j = left2; j < right2; ++j) {
|
||||
int i0 = i;
|
||||
int j0 = j;
|
||||
Uint8 *bufp = (Uint8 *)pixels
|
||||
+ i * pitch + j * bpp;
|
||||
|
||||
#if 1 && ! UseSDLscaling
|
||||
if (UseMagnify) {
|
||||
i0 /= WindowScale;
|
||||
j0 /= WindowScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 != vMacScreenDepth
|
||||
if (UseColorMode) {
|
||||
#if vMacScreenDepth < 4
|
||||
p = the_data + ((i0 * vMacScreenWidth + j0)
|
||||
>> (3 - vMacScreenDepth));
|
||||
{
|
||||
uint8_t k = (*p >> (((~ j0)
|
||||
& ((1 << (3 - vMacScreenDepth)) - 1))
|
||||
<< vMacScreenDepth))
|
||||
& (CLUT_size - 1);
|
||||
pixel = CLUT_pixel[k];
|
||||
}
|
||||
#elif 4 == vMacScreenDepth
|
||||
p = the_data + ((i0 * vMacScreenWidth + j0) << 1);
|
||||
{
|
||||
uint16_t t0 = do_get_mem_word(p);
|
||||
pixel = SDL_MapRGB(format,
|
||||
((t0 & 0x7C00) >> 7)
|
||||
| ((t0 & 0x7000) >> 12),
|
||||
((t0 & 0x03E0) >> 2)
|
||||
| ((t0 & 0x0380) >> 7),
|
||||
((t0 & 0x001F) << 3)
|
||||
| ((t0 & 0x001C) >> 2));
|
||||
}
|
||||
#elif 5 == vMacScreenDepth
|
||||
p = the_data + ((i0 * vMacScreenWidth + j0) << 2);
|
||||
pixel = SDL_MapRGB(format,
|
||||
p[1],
|
||||
p[2],
|
||||
p[3]);
|
||||
#endif
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
p = the_data + ((i0 * vMacScreenWidth + j0) / 8);
|
||||
pixel = BWLUT_pixel[(*p >> ((~ j0) & 0x7)) & 1];
|
||||
}
|
||||
|
||||
switch (bpp) {
|
||||
case 1: /* Assuming 8-bpp */
|
||||
*bufp = pixel;
|
||||
break;
|
||||
case 2: /* Probably 15-bpp or 16-bpp */
|
||||
*(Uint16 *)bufp = pixel;
|
||||
break;
|
||||
case 3:
|
||||
/* Slow 24-bpp mode, usually not used */
|
||||
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
|
||||
bufp[0] = (pixel >> 16) & 0xff;
|
||||
bufp[1] = (pixel >> 8) & 0xff;
|
||||
bufp[2] = pixel & 0xff;
|
||||
} else {
|
||||
bufp[0] = pixel & 0xff;
|
||||
bufp[1] = (pixel >> 8) & 0xff;
|
||||
bufp[2] = (pixel >> 16) & 0xff;
|
||||
}
|
||||
break;
|
||||
case 4: /* Probably 32-bpp */
|
||||
*(Uint32 *)bufp = pixel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SDL_UnlockTexture(texture);
|
||||
|
||||
src_rect.x = left2;
|
||||
src_rect.y = top2;
|
||||
src_rect.w = right2 - left2;
|
||||
src_rect.h = bottom2 - top2;
|
||||
|
||||
dst_rect.x = XDest;
|
||||
dst_rect.y = YDest;
|
||||
dst_rect.w = DestWidth;
|
||||
dst_rect.h = DestHeight;
|
||||
|
||||
/* SDL_RenderClear(renderer); */
|
||||
SDL_RenderCopy(renderer, texture, &src_rect, &dst_rect);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
#if MayFullScreen
|
||||
label_exit:
|
||||
;
|
||||
#endif
|
||||
}
|
||||
|
||||
LOCALPROC DrawChangesAndClear(void)
|
||||
{
|
||||
if (ScreenChangedBottom > ScreenChangedTop) {
|
||||
HaveChangedScreenBuff(ScreenChangedTop, ScreenChangedLeft,
|
||||
ScreenChangedBottom, ScreenChangedRight);
|
||||
ScreenClearChanges();
|
||||
}
|
||||
}
|
||||
|
||||
GLOBALOSGLUPROC DoneWithDrawingForTick(void)
|
||||
{
|
||||
#if EnableFSMouseMotion
|
||||
if (HaveMouseMotion) {
|
||||
AutoScrollScreen();
|
||||
}
|
||||
#endif
|
||||
DrawChangesAndClear();
|
||||
}
|
Loading…
Reference in New Issue
Block a user