Commit 21b2306e authored by Scott Duensing's avatar Scott Duensing

Setting up new repository with just the JoeyLib code in it.

parents
*.sta filter=lfs diff=lfs merge=lfs -text
*.mod filter=lfs diff=lfs merge=lfs -text
*~
*.user
lib/
src/SDL2/
src/music
src/music.w
src/*.dis
#!/bin/bash -e
if [ -d ${JOEY}/sdks/iix/IIgs/out/joey ]; then
rm -rf ${JOEY}/sdks/iix/IIgs/out/joey
fi
mkdir -p ${JOEY}/sdks/iix/IIgs/out/joey
pushd ${JOEY}/joeylib/src
iix assemble jIIgs.asm keep=31:/out/joey/jIIgsasm
iix compile jIIgs.c keep=31:/out/joey/jIIgsc
iix compile joey.c keep=31:/out/joey/joey
iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.A
iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.ROOT
iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsc.a
iix makelib 31:/out/joey/joeylib +31:/out/joey/joey.a
iix compile test.c keep=31:/out/joey/test
iix -DKeepType=S16 link 31:/out/joey/test 31:/out/joey/joeylib keep=31:/out/joey/test
iix dumpobj +D 31:/out/joey/test &> test.dis || true
php ${JOEY}/sdks/iix/ntconverter.php *.mod
popd
rm JLSTATS || true
rm /tmp/import.po || true
AC=${JOEY}/sdks/iix/ac/
CADIUS=${JOEY}/sdks/iix/cadius/cadius.sh
IMPORT=/tmp/import.po
${AC}/import.sh ${JOEY}/sdks/iix/IIgs/out/joey/test S16
${AC}/import.sh ${JOEY}/joeylib/src/kanga.sta
${AC}/import.sh ${JOEY}/joeylib/src/font.sta
${AC}/import.sh ${JOEY}/joeylib/src/music MUS
${AC}/import.sh ${JOEY}/joeylib/src/music.w BIN
cp -f ${JOEY}/joeylib/lib/IIgs/Tool221#ba0000 ${JOEY}/dist/IIgs/.
cp -f ${JOEY}/joeylib/src/joey.h ${JOEY}/dist/.
cp -f ${JOEY}/sdks/iix/IIgs/out/joey/joeylib ${JOEY}/dist/IIgs/joeylib#b20000
if [ ! -z $1 ]; then
pushd ${JOEY}/sdks/iix/gsplus
./gsplus -config IIgsTest.cfg || true
popd
echo ""
${AC}/export.sh JLSTATS
cat JLSTATS
fi
#!/bin/bash -e
BUILD="${JOEY}/joeylib/build"
SRC="${JOEY}/joeylib/src"
function doBuild() {
if [ -d "${BUILD}" ]; then
rm -rf "${BUILD}"
fi
mkdir -p "${BUILD}"
if [ -d "${DIST}" ]; then
rm -rf "${DIST}"
fi
mkdir -p "${DIST}"
pushd "${BUILD}"
${CC} ${CFLAGS} -c -o jPC.o ${SRC}/jPC.c
${CC} ${CFLAGS} -c -o joey.o ${SRC}/joey.c
cp -f *.o "${DIST}"/.
popd
pushd ${DIST}
ar -x ${INSTALLED}/libSDL2.a
ar -x ${INSTALLED}/libSDL2_mixer.a
ar -x ${INSTALLED}/libmikmod.a
ar rcs joeylib.a *.o
rm *.o
popd
}
CC="gcc"
CFLAGS="-Wall -D_REENTRANT -I${SRC}"
DIST="${JOEY}/dist/linux/x64"
INSTALLED="${JOEY}/SDL2/installed/linux/x64/lib"
doBuild
CC="gcc"
CFLAGS="-m32 -Wall -D_REENTRANT -I${SRC}"
DIST="${JOEY}/dist/linux/x86"
INSTALLED="${JOEY}/SDL2/installed/linux/x86/lib"
doBuild
CC="x86_64-w64-mingw32-gcc"
CFLAGS="-Wall -D_REENTRANT -I${SRC}"
DIST="${JOEY}/dist/windows/x64"
INSTALLED="${JOEY}/SDL2/installed/windows/x64/lib"
doBuild
CC="i686-w64-mingw32-gcc"
CFLAGS="-Wall -D_REENTRANT -I${SRC}"
DIST="${JOEY}/dist/windows/x86"
INSTALLED="${JOEY}/SDL2/installed/windows/x86/lib"
doBuild
CC="o32-clang"
CFLAGS="-Wall -D_REENTRANT -I${SRC}"
DIST="${JOEY}/dist/macos/x86"
INSTALLED="${JOEY}/SDL2/installed/macos/x86/lib"
doBuild
CC="o64-clang"
CFLAGS="-Wall -D_REENTRANT -I${SRC}"
DIST="${JOEY}/dist/macos/x64"
INSTALLED="${JOEY}/SDL2/installed/macos/x64/lib"
doBuild
rm -rf build
TEMPLATE = app
CONFIG += console
CONFIG -= \
app_bundle \
qt
QMAKE_CFLAGS += \
-I$$PWD/src \
-D_REENTRANT
HEADERS += \
src/joey.h \
src/stddclmr.h
SOURCES += \
src/joey.c \
src/jPC.c \
src/test.c
OTHER_FILES += \
src/jIIgs.c \
src/jIIgs.asm \
src/jIIgs.macro \
build-IIgs.sh \
build-PC.sh
SDL_LIBS = \
-L$$PWD/lib/linux/x64 \
-Wl,-rpath,$$PWD/lib/linux/x64 \
-Wl,--enable-new-dtags \
-lSDL2 \
-Wl,--no-undefined \
-lm \
-ldl \
-lpthread \
-lrt
SDL_MIXER_LIBS = \
-L$$PWD/lib/linux/x64 \
-lSDL2_mixer \
-lmikmod
LIBS += \
$$SDL_LIBS \
$$SDL_MIXER_LIBS
File added
This diff is collapsed.
/*
* JoeyLib
* Copyright (C) 2018 Scott Duensing <scott@kangaroopunch.com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <string.h>
#include <locator.h>
#include <memory.h>
#include <misctool.h>
#include <sound.h>
#undef false
#undef true
#define JOEY_LIBRARY
#include "joey.h"
#ifdef JOEY_DEBUG
#include <stdio.h>
#endif
typedef struct {
char length;
char text[255];
} _jlPascalStringT;
extern void asmBorder(int c);
extern void asmGrOff(void);
extern void asmGrOn(void);
extern int asmJoy(int which);
extern void asmShOff(void);
extern void asmShOn(void);
extern void asmSlam(void);
extern void asmStart(int myID, int hertzBy10);
extern void asmStop(void);
extern pascal void NTStartUp(Word) inline(0x02DD, dispatcher);
extern pascal void NTShutDown(void) inline(0x03DD, dispatcher);
extern pascal void NTLoadOneMusic(Pointer) inline(0x09DD, dispatcher);
extern pascal void NTPlayMusic(Word) inline(0x0ADD, dispatcher);
extern pascal Word NTGetPlayingMusic(void) inline(0x10DD, dispatcher);
extern pascal void NTPauseMusic(void) inline(0x13DD, dispatcher);
extern pascal void NTContinueMusic(void) inline(0x14DD, dispatcher);
char _jlKeyCheck(char key);
static byte *KEYBOARD = (byte *)0x00C000;
static byte *KEYSTROBE = (byte *)0x00C010;
static byte *BUTTON0 = (byte *)0x00C061;
static byte *BUTTON1 = (byte *)0x00C062;
static jlPixelPairT *SHRPIXELS = (jlPixelPairT *)0x012000; // Shadow of 0xE12000
static byte *SHRSCB = (byte *)0x019D00; // Shadow of 0xE19D00
static jlColorT *SHRCOLORS = (jlColorT *)0x019E00; // Shadow of 0xE19E00
static byte *BORDER = (byte *)0xE0C034;
static byte _jlBorderSaved;
static int _jlMyID;
static int _jlMemID;
static int _jlMusicMemID;
static Handle _jlSHRShadowHandle;
static int _jlHertz;
#ifdef JOEY_DEBUG
#define JOEY_CHECK_TOOL_ERROR(w) if (_toolErr) _jlDieWithToolError(w, _toolErr);
void _jlDieWithToolError(const char *what, int err) {
char message[256];
sprintf(message, "Tool Error %04X %s", err, what);
jlUtilDie(message);
}
void _jlDebugBorder(jlBorderColorsE color) {
jlDisplayBorder(color);
asmBorder(_jlBorderColor);
//*BORDER = *BORDER & 0xF0 | _jlBorderColor;
}
#else
#define JOEY_CHECK_TOOL_ERROR(w)
#endif
void jlDisplayPresent(void) {
asmShOn();
asmSlam();
asmShOff();
asmBorder(_jlBorderColor);
}
void jlDrawClear(void) {
memset(SHRPIXELS, _jlDrawColorNibbles, 32000);
}
int jlGameGetAxis(byte which) {
return asmJoy((int)which) - 128;
}
bool jlGameGetButton(byte which) {
if (which > 0) return (bool)(*BUTTON1 > 127);
return (bool)(*BUTTON0 > 127);
}
char _jlKeyCheck(char key) {
if ((key < 8) || (key > 127)) {
key = 0;
} else {
// Map LF to CR
if (key == 10) {
key = 13;
}
// Map DEL to BS
if (key == 127) {
key = 8;
}
// Is this outside the range we care about?
if ((key < ' ') || (key > '~')) {
if ((key != 8) && (key != 13) && (key != 27)) {
key = 0;
}
}
}
return key;
}
bool jlKeyPressed(void) {
bool result = false;
// On other platforms we should call jlIdle() here.
if ((*KEYBOARD & 0x80) != 0) {
result = (_jlKeyCheck(*KEYBOARD & 0x7F) != 0);
}
return result;
}
char jlKeyRead(void) {
// On other platforms we should call jlIdle() here.
// Reset keyboard strobe
*KEYSTROBE = 0;
return _jlKeyCheck(*KEYBOARD & 0x7F);
}
void jlPaletteSet(byte index, byte r, byte g, byte b) {
SHRCOLORS[index].r = r;
SHRCOLORS[index].g = g;
SHRCOLORS[index].b = b;
}
void jlSoundFree(jlSoundT *sound) {
//***TODO***
}
bool jlSoundIsPlaying(jlSoundT *sound) {
//***TODO***
}
bool _jlSoundLoad(jlSoundT **sound, char *filename) {
//***TODO***
}
void jlSoundMusicContinue(void) {
NTContinueMusic();
}
bool jlSoundMusicIsPlaying(void) {
return (NTGetPlayingMusic() != 0xFFFF);
}
void jlSoundMusicPause(void) {
NTPauseMusic();
}
void jlSoundMusicPlay(char *name) {
_jlPascalStringT file;
strcpy(file.text, name);
file.length = strlen(name);
NTStartUp(_jlMusicMemID);
JOEY_CHECK_TOOL_ERROR("NTStartup")
NTLoadOneMusic((Pointer)&file);
JOEY_CHECK_TOOL_ERROR("NTLoadOneMusic")
NTPlayMusic(false);
JOEY_CHECK_TOOL_ERROR("NTPlayMusic")
}
void jlSoundMusicStop(void) {
NTShutDown();
JOEY_CHECK_TOOL_ERROR("NTShutDown")
}
void jlSoundPlay(jlSoundT *sound) {
//***TODO***
}
bool _jlStaCreate(jlStaT **sta) {
jlStaT *t = (jlStaT *)jlMalloc(sizeof(jlStaT));
if (t != NULL) {
memset(t, 0, sizeof(jlStaT));
t->id[0] = 'S';
t->id[1] = 'T';
t->id[2] = 'A';
t->version = 0;
memcpy(t->palette, SHRCOLORS, sizeof(t->palette));
memcpy(t->pixels, SHRPIXELS, sizeof(t->pixels));
*sta = t;
return true;
}
return false;
}
void jlStaDisplay(jlStaT *sta) {
memcpy(SHRCOLORS, sta->palette, sizeof(sta->palette));
memcpy(SHRPIXELS, sta->pixels, sizeof(sta->pixels));
}
void jlUtilIdle(void) {
// No need to pump the message loop on the IIgs
}
bool jlUtilMustExit(void) {
return false;
}
void jlUtilShutdown(void) {
// Clear the display.
jlDrawColor(0);
jlDrawClear();
// Restore Border
jlDisplayBorder((jlBorderColorsE)_jlBorderSaved);
jlDisplayPresent();
// SHR Off
asmGrOff();
asmStop();
// Shutdown tools
UnloadOneTool(0xDD); // NinjaTracker
MTShutDown();
DisposeAll(_jlMemID);
MMShutDown(_jlMyID);
TLShutDown();
jlUtilDie("Clean Exit.");
}
void jlUtilStartup(char *appName) {
(void)appName;
// Start up neded tools
TLStartUp();
_jlMyID = MMStartUp();
_jlMemID = _jlMyID | 0x0100; // Set aux ID to 1.
_jlMusicMemID = _jlMyID | 0x0200; // Set music ID.
MTStartUp();
LoadOneTool(0xDD, 0); // NinjaTracker
JOEY_CHECK_TOOL_ERROR("LoadOneTool")
// Reserve shadow area for SHR
_jlSHRShadowHandle = NewHandle((LongWord)0x8000, (Word)_jlMemID, (Word)(attrLocked + attrFixed + attrBank + attrAddr), (Pointer)0x012000);
// Start assembly module
_jlHertz = (int)ReadBParam((Word)0x1D) == 0 ? 60 : 50; // Is this a PAL or NTSC machine?
asmStart(_jlMyID, _jlHertz / 10);
// SHR on
asmGrOn();
// If you work out the Screen Conrol Bytes, everything we want is zero.
// So we just memset all 200 of them.
memset(SHRSCB, 0, 200);
// Hide border.
_jlBorderSaved = *BORDER & 0x0F;
jlDisplayBorder(BORDER_BLACK);
jlPaletteDefault();
// Clear the display.
jlDrawColor(0);
jlDrawClear();
jlDrawColor(15);
jlDisplayPresent();
}
;
; Based on M16.cc from ORCA/C
;
MACRO
&lab jsubroutine &parms,&work
&lab anop
using savedDBR ; ADDED
aif c:&work,.a
lclc &work
&work setc 0
.a
gbla &totallen
gbla &worklen
&worklen seta &work
&totallen seta 0
aif c:&parms=0,.e
lclc &len
lclc &p
lcla &i
&i seta 1
.b
&p setc &parms(&i)
&len amid &p,2,1
aif "&len"=":",.c
&len amid &p,1,2
&p amid &p,4,l:&p-3
ago .d
.c
&len amid &p,1,1
&p amid &p,3,l:&p-2
.d
&p equ &totallen+4+&work
&totallen seta &totallen+&len
&i seta &i+1
aif &i<=c:&parms,^b
.e
tsc
aif &work=0,.f
sec
sbc #&work
tcs
.f
phd ; Push Direct Register
tcd ; Transfer C Accumulator to Direct Register
; === START OF OUR MODIFICATION ===
phb ; Push Data Bank Register
phb ; Push Data Bank Register
pla ; Pull Accumulator
sta >savedDBR ; Store Accumulator in savedDBR (Data Bank Register)
phk ; Push K (Program Bank Register)
plb ; Pull Data Bank Register
; === END OF OUR MODIFICATION ===
mend
MACRO
&lab jreturn &r
&lab anop
; === START OF OUR MODIFICATION ===
using savedDBR
lda >savedDBR ; Load our saved Data Bank Register
pha ; Push the C Accumulator
plb ; Pull Data Bank Register
plb ; Pull Data Bank Register
; === END OF OUR MODIFICATION ===
lclc &len
aif c:&r,.a
lclc &r
&r setc 0
&len setc 0
ago .h
.a
&len amid &r,2,1
aif "&len"=":",.b
&len amid &r,1,2
&r amid &r,4,l:&r-3
ago .c
.b
&len amid &r,1,1
&r amid &r,3,l:&r-2
.c
aif &len<>2,.d
ldy &r
ago .h
.d
aif &len<>4,.e
ldx &r+2
ldy &r
ago .h
.e
aif &len<>10,.g
ldy #&r
ldx #^&r
ago .h
.g
mnote 'Not a valid return length',16
mexit
.h
aif &totallen=0,.i
lda &worklen+2
sta &worklen+&totallen+2
lda &worklen+1
sta &worklen+&totallen+1
.i
pld
tsc
clc
adc #&worklen+&totallen
tcs
aif &len=0,.j
tya
.j
rtl
mend
This diff is collapsed.
This diff is collapsed.
/*
* JoeyLib
* Copyright (C) 2018 Scott Duensing <scott@kangaroopunch.com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef H_JOEY_
#define H_JOEY_
#define JOEY_DEBUG
#include <stdlib.h>
#ifndef bool
#define bool unsigned char
#define true 1
#define false 0
#endif
#define byte unsigned char
extern byte _jlDrawColor;
extern byte _jlDrawColorNibbles;
extern byte _jlBorderColor;
enum _jlBorderColorsE {
BORDER_BLACK = 0,
BORDER_DEEP_RED = 1,
BORDER_DEEP_BLUE = 2,
BORDER_PURPLE = 3,
BORDER_DARK_GREEN = 4,
BORDER_DARK_GRAY = 5,
BORDER_MEDIUM_BLUE = 6,
BORDER_LIGHT_BLUE = 7,
BORDER_BROWN = 8,
BORDER_ORANGE = 9,
BORDER_LIGHT_GRAY = 10,
BORDER_PINK = 11,
BORDER_GREEN = 12,
BORDER_YELLOW = 13,
BORDER_AQUAMARINE = 14,
BORDER_WHITE = 15
};
typedef enum _jlBorderColorsE jlBorderColorsE;
typedef struct {
byte b : 4;
byte g : 4;
byte r : 4;
byte reserved : 4;
} jlColorT;
typedef struct {
byte l : 4;
byte r : 4;
} jlPixelPairT;
typedef struct {
void *data;
int channel;
} jlSoundT;
typedef struct {
char id[3];
byte version;
jlColorT palette[16]; // 4 bits reserved, 4 bits red, 4 green, 4 blue
jlPixelPairT pixels[32000]; // 320x200, 4 bits per pixel
} jlStaT;
typedef struct _jlStackS {
struct _jlStackS *previous;
void *data;
} jlStackT;
typedef struct {
char id[3];
byte version;
unsigned int length;
byte *data;
} jlVecT;
// Memory Management
#ifdef JOEY_DEBUG
#define JOEY_MEM_BLOCKS 64
typedef struct {
void *addr;
char *file;
size_t size;
int line;
} jlMemoryBlockT;
#define jlFree(p) _jlFree((void **)&(p))
void _jlFree(void **pointer);
#define jlMalloc(s) _jlMalloc(s, __LINE__, __FILE__)
void *_jlMalloc(size_t size, int line, char *file);
#define jlRealloc(p, s) _jlRealloc(p, s)
void *_jlRealloc(void *pointer, size_t size);
#else
#define jlFree free
#define jlMalloc malloc
#endif
// Determine platform and settings