Skip to content

Commit

Permalink
WinCE 用に書き換え
Browse files Browse the repository at this point in the history
  • Loading branch information
HO-0520-IT committed Mar 17, 2021
1 parent cf4e650 commit 8cedb26
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 76 deletions.
24 changes: 14 additions & 10 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
# make tool ... pcmtool作成


CXX = g++
CC = gcc
PREF = /home/cygwin/cegcc/arm-mingw32ce
CXX = /home/cygwin/cegcc/bin/arm-mingw32ce-g++
CC = /home/cygwin/cegcc/bin/arm-mingw32ce-gcc
CFLAGS =
CXXFLAGS =
# CXXFLAGS += -Wno-write-strings
COMMON_FLAGS = -Wall -O3
COMMON_FLAGS = -Wall -O3
# -fexceptions -fno-rtti -fno-check-new -fomit-frame-pointer -fno-stack-protector -pipe -fpermissive
# COMMON_FLAGS += -Wall -Werror
LDFLAGS =
DEFINES =
Expand Down Expand Up @@ -110,34 +112,36 @@ LIBS += -mconsole

# SDL
else ifeq ($(OS_SDL),1)
DEFINES += -DNO_STDIO_REDIRECT -USDL_STDIO_REDIRECT
DIRS += sdl
DEP_SRCS += sdl/osdep_sdl.cpp
DEP_SRCS += sdl/audiobuffer.cpp
DEP_SRCS += sdl/audiotime.cpp

SDL_CFLAGS = `sdl-config --cflags` -DUSE_SDL
SDL_CFLAGS = `$(PREF)/bin/sdl-config --cflags` -DUSE_SDL
COMMON_FLAGS += $(SDL_CFLAGS)

ifeq ($(STATIC),1)
ifeq ($(OS_LINUX),1)
SDL_LIBS = `sdl-config --static-libs` -static-libgcc -static-libstdc++
SDL_LIBS = `$(PREF)/bin/sdl-config --static-libs` -static-libgcc -static-libstdc++
LDFLAGS += -Wl,-rpath,/usr/local/lib,-rpath,/usr/lib/x86_64-linux-gnu,-rpath,/usr/lib/gcc/x86_64-linux-gnu
else
SDL_LIBS = `sdl-config --static-libs`
SDL_LIBS = `$(PREF)/bin/sdl-config --libs`
endif
else
ifeq ($(OS_LINUX),1)
SDL_LIBS = `sdl-config --libs` -lX11
SDL_LIBS = `$(PREF)/bin/sdl-config --libs`
else
SDL_LIBS = `sdl-config --libs`
SDL_LIBS = `$(PREF)/bin/sdl-config --libs`
endif
endif

ifeq ($(SDL_WIN32),1)
# dllをすべて静的リンクします。 (Win32かつSDLはテスト用途のため)
LIBS += -static $(SDL_LIBS) -mconsole
#LIBS += -static $(SDL_LIBS) -mconsole
LIBS += -Wl,-Bdynamic $(SDL_LIBS) -Wl,-Bstatic -lm -lcoredll -lmmtimer -lcoredll -lcommctrl
else
LIBS += $(SDL_LIBS)
LIBS += -static $(SDL_LIBS)
endif
else
DIRS += dummy
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.setting
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ UNAME_S := $(shell uname -s)
endif

# SDL使用
WIN32 = 1
OS_SDL = 1

# Win32ネイティブ
Expand All @@ -38,3 +39,9 @@ endif
ifeq ($(OS_LINUX),1)
STATIC = 0
endif

$(warning WIN32 = $(WIN32))

$(warning OS_WIN32 = $(OS_WIN32))

$(warning SDL_WIN32 = $(SDL_WIN32))
18 changes: 16 additions & 2 deletions src/Z80/Z80.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <stdio.h>

#include "../wincehelper.h"

#ifdef Z80_DEBUG
#include <stdio.h>
Expand Down Expand Up @@ -404,6 +405,13 @@ int32_t Z80::Execute(int32_t n) {
#endif

RefReg++;
/*int m1;
m1 = M1;
if ((pc == 0x9cbb) || (pc == 0x9cd4) || (pc == 0x9bf0) || (pc == 0x9bfc)) {
return m1;
}
switch (m1) {*/
uint8_t opbuf[4];
switch (M1) {
#define RST(i) case 0xc7 + 8 * (i): if (Extender(8 * i)) break; st16(sp -= 2, pc); pc = 8 * i; CLOCK(1); break;
SET_8(RST)
Expand Down Expand Up @@ -827,7 +835,13 @@ int32_t Z80::Execute(int32_t n) {
pc = HL;
break;
case 0xd9: // exx
swap(*(uint32_t *)r, bcde);
for (int i = 0; i < 4; i++) {
opbuf[i] = r[i];
}
swap(bcde, *(uint32_t *)&opbuf[0]);
for (int i = 0; i < 4; i++) {
r[i] = opbuf[i];
}
swap(HLfix, hl);
break;
case 0xc9: // ret
Expand Down Expand Up @@ -1521,7 +1535,7 @@ void Z80::StopTrace() {
TraceBuffer *endp = tracep;
int i = 0;
FILE *fo;
if (!(fo = fopen("trace.dat", "w"))) exit(1);
if (!(fo = wceh_fopen("trace.dat", "w"))) exit(1);
do {
if (++tracep >= tracebuf + TRACEMAX) tracep = tracebuf;
fprintf(fo, "%7d %04x\t", i++, tracep->pc);
Expand Down
13 changes: 10 additions & 3 deletions src/cmucom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@
#define STRCASECMP strcasecmp
#else
#ifdef _WIN32
#define STRCASECMP _strcmpi
#define STRCASECMP _stricmp
#else
#define STRCASECMP strcasecmp
#endif
#endif

#define PRINTF vm->Msgf
#define PRINTF_NOCONV vm->MsgfNoConvert
//#define PRINTF vm->Msgf
#define PRINTF printf
//#define PRINTF_NOCONV vm->MsgfNoConvert
#define PRINTF_NOCONV printf

int CMucom::htoi_sub(char hstr)
{
Expand Down Expand Up @@ -978,6 +980,7 @@ int CMucom::LoadFMVoice(const char *fname, bool sw)
// オリジナルファイルのみの場合
StoreFMVoice((unsigned char *)voicedata_org);
//Alertf("[%s]%s", voice_pathname.c_str(), voicefilename.c_str());
printf("[%s]%s", voice_pathname.c_str(), voicefilename.c_str());
}
else {
// 一時ファイルがあった場合
Expand Down Expand Up @@ -1706,8 +1709,10 @@ int CMucom::Compile(char *text, int option, bool writeMub, const char *filename)

int loopst = 0xf25a;
vm->Pokew(loopst, 0x0101); // ループ情報スタックを初期化する(ループ外の'/'でエラーを出すため)
printf("Poke OK\n");

res = vm->CallAndHalt2(vec, 'A');
printf("CallAndHalt OK\n");
if (res) {
int line = vm->Peekw(0x0f32e);
int msgid = vm->GetMessageId();
Expand All @@ -1727,6 +1732,7 @@ int CMucom::Compile(char *text, int option, bool writeMub, const char *filename)
} else {
PutMucomHeader(stmp);
}
printf("Message OK\n");

workadr = 0xf320;
fmvoice = vm->Peek(workadr + 50);
Expand All @@ -1736,6 +1742,7 @@ int CMucom::Compile(char *text, int option, bool writeMub, const char *filename)

jumpcount = vm->Peekw(MUCOM_ADDRESS_JCLOCK); // JCLOCKの値(Jコマンドのタグ位置)
jumpline = vm->Peekw(MUCOM_ADDRESS_JPLINE); // JPLINEの値(Jコマンドの行番号)
printf("JCLOCK JPLINE OK\n");

PRINTF("Used FM voice:%d", fmvoice);

Expand Down
4 changes: 2 additions & 2 deletions src/cmucom.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#define MUCOM_DATA_ADDRESS 0xc200

#ifndef USE_SDL
#define MUCOM_AUDIO_RATE 55467 // Sampling Rate 55K
#define MUCOM_AUDIO_RATE 22050 // Sampling Rate 22K
#else
#define MUCOM_AUDIO_RATE 44100
#define MUCOM_AUDIO_RATE 22050
#endif

#define MUCOM_RESET_PLAYER 0
Expand Down
6 changes: 4 additions & 2 deletions src/fmgen/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "headers.h"
#include "file.h"

#include "../wincehelper.h"

// ---------------------------------------------------------------------------
// 構築/消滅
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -39,7 +41,7 @@ bool FileIO::Open(const char* filename, uint flg)

strncpy(path, filename, _MAXPATH);

fp = fopen(filename, "rb");
fp = wceh_fopen(filename, "rb");
if (!fp)
return false;

Expand All @@ -58,7 +60,7 @@ bool FileIO::CreateNew(const char* filename)

strncpy(path, filename, _MAXPATH);

fp = fopen(filename, "wb");
fp = wceh_fopen(filename, "wb");
if (!fp)
return false;

Expand Down
25 changes: 15 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
// Special thanks to : WING☆, Makoto Wada (Ancient corp.), boukichi, kumatan
//


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#ifdef WIN32

/*#ifdef WIN32
#include <direct.h>
#define getcwd _getcwd
#define CHDIR _chdir
#else
#include <unistd.h>
#define CHDIR chdir
#define _MAX_PATH 512
#endif
#else*/
#include "wincehelper.cpp"
#define getcwd wceh_getcwd
#define CHDIR wceh_CHDIR
/*#define _MAX_PATH 512
#endif*/

#include "cmucom.h"

Expand All @@ -33,14 +36,14 @@
#define DEFAULT_OUTFILE "mucom88.mub"
#define DEFAULT_OUTWAVE "mucom88.wav"

#define RENDER_RATE 44100
#define RENDER_RATE 22050
#define RENDER_SECONDS 90

#ifdef __APPLE__
#define STRCASECMP strcasecmp
#else
#ifdef _WIN32
#define STRCASECMP _strcmpi
#define STRCASECMP _stricmp
#else
#define STRCASECMP strcasecmp
#endif
Expand Down Expand Up @@ -97,10 +100,10 @@ int main( int argc, char *argv[] )
const char* rhythmdir;
const char* drivername;

#if defined(USE_SDL) && defined(_WIN32)
/*#if defined(USE_SDL) && defined(_WIN32)
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
#endif
#endif*/

// check switch and prm

Expand Down Expand Up @@ -308,9 +311,11 @@ int main( int argc, char *argv[] )
if (voicefile != NULL) {
mucom.LoadFMVoice(voicefile);
}
printf("loaded\n");
if (mucom.CompileFile(fname, outfile) < 0) {
st = 1;
}
printf("compiled\n");
play_direct = true;
} else {
if (mucom.LoadMusic(fname) < 0) {
Expand Down
8 changes: 5 additions & 3 deletions src/membuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <assert.h>
#include "membuf.h"

#include "../wincehelper.h"

//-------------------------------------------------------------
// Routines
//-------------------------------------------------------------
Expand Down Expand Up @@ -260,15 +262,15 @@ int CMemBuf::PutFile(const char *fname )
int length;
FILE *ff;

ff=fopen( fname,"rb" );
ff=wceh_fopen( fname,"rb" );
if (ff==NULL) return -1;
fseek( ff,0,SEEK_END );
length=(int)ftell( ff ); // normal file size
fclose(ff);
if (length < 0) return -1;

p = PreparePtr( length+1 );
ff=fopen( fname,"rb" );
ff=wceh_fopen( fname,"rb" );
fread( p, 1, length, ff );
fclose(ff);
p[length]=0;
Expand Down Expand Up @@ -388,7 +390,7 @@ int CMemBuf::SaveFile(const char *fname )
//
FILE *fp;
int flen;
fp=fopen(fname,"wb");
fp=wceh_fopen(fname,"wb");
if (fp==NULL) return -1;
flen = fwrite( mem_buf, 1, cur, fp );
fclose(fp);
Expand Down
10 changes: 6 additions & 4 deletions src/module/mucom_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <io.h>

#include "mucom_module.h"

#include "../wincehelper.h"

#define MUCOM_DEFAULT_PCMFILE "mucompcm.bin"
#define DEFAULT_OUTFILE "mucom88.mub"

MucomModule::MucomModule() {
audioRate = 44100;
audioRate = 22050;
pcmfile = MUCOM_DEFAULT_PCMFILE;
outfile = DEFAULT_OUTFILE;
voicefile = NULL;
resultText = NULL;
volume = 1.0f;
volume = 0.1f;
}

MucomModule::~MucomModule() {
Expand All @@ -41,7 +43,7 @@ void MucomModule::SetVolume(double vol) {


bool MucomModule::Open(const char *workingDirectory, const char *songFilename) {
chdir(workingDirectory);
wceh_CHDIR(workingDirectory);
mucom = new CMucom();
int cmpopt = MUCOM_CMPOPT_COMPILE;
mucom->Init(NULL,cmpopt,audioRate);
Expand Down
Loading

0 comments on commit 8cedb26

Please sign in to comment.