mirror of
https://github.com/autc04/Retro68.git
synced 2024-12-24 17:29:38 +00:00
Merge gould.local:Projects/Retro68
This commit is contained in:
commit
b435fbeb7e
@ -1,4 +1,5 @@
|
||||
#include <Quickdraw.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class PortSetter
|
||||
{
|
||||
@ -16,4 +17,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
inline const unsigned char* operator"" _pstr(const char*p, size_t n)
|
||||
{
|
||||
unsigned char *pp = reinterpret_cast<unsigned char*>(const_cast<char*>(p));
|
||||
pp[0] = n-1;
|
||||
return pp;
|
||||
}
|
||||
#define PSTR(s) ("*" s ## _pstr)
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <Events.h>
|
||||
#include <Fonts.h>
|
||||
|
||||
#include "MacUtils.h"
|
||||
#include "Console.h"
|
||||
|
||||
QDGlobals qd;
|
||||
@ -56,7 +57,7 @@ int main(int argc, char** argv)
|
||||
|
||||
Rect r;
|
||||
SetRect(&r, qd.screenBits.bounds.left + 5, qd.screenBits.bounds.top + 45, qd.screenBits.bounds.right - 5, qd.screenBits.bounds.bottom -5);
|
||||
win = NewWindow(NULL, &r, (unsigned char*)"", true, 0, (WindowPtr)-1, false, 0);
|
||||
win = NewWindow(NULL, &r, PSTR("Retro68 Console"), true, 0, (WindowPtr)-1, false, 0);
|
||||
|
||||
SetPort(win);
|
||||
EraseRect(&win->portRect);
|
||||
|
@ -1,4 +1,10 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(Retro)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES Retro68)
|
||||
add_subdirectory(libretro)
|
||||
add_subdirectory(App2)
|
||||
add_subdirectory(Raytracer)
|
||||
else()
|
||||
add_subdirectory(MakeAPPL)
|
||||
endif()
|
||||
|
@ -1,6 +1,5 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
add_definitions(-std=c++0x)
|
||||
add_executable(MakeAPPL main.cc)
|
||||
|
||||
install(TARGETS MakeAPPL RUNTIME DESTINATION bin)
|
||||
|
@ -14,13 +14,13 @@ std::string commandPath;
|
||||
void wrapMacBinary(std::string macBinaryFile, std::string diskImagePath)
|
||||
{
|
||||
int size = static_cast<int>(
|
||||
std::ifstream(macBinaryFile).seekg(0,std::ios::end).tellg()
|
||||
std::ifstream(macBinaryFile.c_str()).seekg(0,std::ios::end).tellg()
|
||||
);
|
||||
|
||||
size += 20 * 1024;
|
||||
size += 800*1024 - size % (800*1024);
|
||||
|
||||
std::ofstream(diskImagePath, std::ios::binary | std::ios::trunc).seekp(size-1).put(0);
|
||||
std::ofstream(diskImagePath.c_str(), std::ios::binary | std::ios::trunc).seekp(size-1).put(0);
|
||||
|
||||
std::system((commandPath + "hformat " + diskImagePath + " > /dev/null").c_str());
|
||||
std::system((commandPath + "hcopy -m " + macBinaryFile + " :").c_str());
|
||||
@ -36,16 +36,23 @@ public:
|
||||
Resource(std::string type, int id, std::string data)
|
||||
: type(type), id(id), data(data) {}
|
||||
|
||||
const std::string& getData() { return data; }
|
||||
inline std::string getType() { return type; }
|
||||
inline int getID() { return id; }
|
||||
const std::string& getData() const { return data; }
|
||||
inline std::string getType() const { return type; }
|
||||
inline int getID() const { return id; }
|
||||
};
|
||||
|
||||
class Resources
|
||||
class Fork
|
||||
{
|
||||
public:
|
||||
virtual void writeFork(std::ostream& out) const { }
|
||||
virtual ~Fork() {}
|
||||
};
|
||||
|
||||
class Resources : public Fork
|
||||
{
|
||||
std::vector<Resource> resources;
|
||||
public:
|
||||
void writeFork(std::ostream& out);
|
||||
void writeFork(std::ostream& out) const;
|
||||
void addResource(Resource res) { resources.push_back(res); }
|
||||
};
|
||||
|
||||
@ -72,7 +79,7 @@ void longword(std::ostream& out, int longword)
|
||||
}
|
||||
|
||||
|
||||
void Resources::writeFork(std::ostream& out)
|
||||
void Resources::writeFork(std::ostream& out) const
|
||||
{
|
||||
std::streampos start = out.tellp();
|
||||
longword(out,0x100);
|
||||
@ -80,9 +87,9 @@ void Resources::writeFork(std::ostream& out)
|
||||
longword(out,0);
|
||||
longword(out,0);
|
||||
out.seekp(start + std::streampos(0x100));
|
||||
std::map<std::string, std::map<int, int>> resourceInfos;
|
||||
std::map< std::string, std::map<int, int> > resourceInfos;
|
||||
std::streampos datastart = out.tellp();
|
||||
for(auto p = resources.begin(); p != resources.end(); ++p)
|
||||
for(std::vector<Resource>::const_iterator p = resources.begin(); p != resources.end(); ++p)
|
||||
{
|
||||
const std::string& data = p->getData();
|
||||
resourceInfos[ p->getType() ][ p->getID() ] = out.tellp() - datastart;
|
||||
@ -99,7 +106,8 @@ void Resources::writeFork(std::ostream& out)
|
||||
word(out,0);
|
||||
std::streampos typelist = out.tellp();
|
||||
word(out,resourceInfos.size() - 1);
|
||||
for(auto p = resourceInfos.begin(); p != resourceInfos.end(); ++p)
|
||||
for(std::map< std::string, std::map<int, int> >::iterator p = resourceInfos.begin();
|
||||
p != resourceInfos.end(); ++p)
|
||||
{
|
||||
if(p->second.size())
|
||||
{
|
||||
@ -109,7 +117,8 @@ void Resources::writeFork(std::ostream& out)
|
||||
}
|
||||
}
|
||||
int typeIndex = 0;
|
||||
for(auto p = resourceInfos.begin(); p != resourceInfos.end(); ++p)
|
||||
for(std::map< std::string, std::map<int, int> >::iterator p = resourceInfos.begin();
|
||||
p != resourceInfos.end(); ++p)
|
||||
{
|
||||
if(p->second.size())
|
||||
{
|
||||
@ -119,7 +128,7 @@ void Resources::writeFork(std::ostream& out)
|
||||
out.seekp(pos);
|
||||
typeIndex++;
|
||||
|
||||
for(auto q = p->second.begin(); q != p->second.end(); ++q)
|
||||
for(std::map<int,int>::iterator q = p->second.begin(); q != p->second.end(); ++q)
|
||||
{
|
||||
word(out,q->first);
|
||||
word(out,-1);
|
||||
@ -140,9 +149,6 @@ void Resources::writeFork(std::ostream& out)
|
||||
out.seekp(end);
|
||||
}
|
||||
|
||||
typedef std::function<void (std::ostream&)> WriterFunction;
|
||||
|
||||
|
||||
// CRC 16 table lookup array
|
||||
static unsigned short CRC16Table[256] =
|
||||
{0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
||||
@ -194,13 +200,14 @@ static unsigned short CalculateCRC(unsigned short CRC, const char* dataBlock, in
|
||||
|
||||
void writeMacBinary(std::ostream& out, std::string filename,
|
||||
std::string type, std::string creator,
|
||||
WriterFunction rsrc, WriterFunction data)
|
||||
const Fork& rsrc, const Fork& data)
|
||||
{
|
||||
out.seekp(128);
|
||||
data(out);
|
||||
data.writeFork(out);
|
||||
std::streampos dataend = out.tellp();
|
||||
std::streampos rsrcstart = ((int)dataend + 0x7F) & ~0x7F;
|
||||
rsrc(out);
|
||||
rsrc.writeFork(out);
|
||||
|
||||
std::streampos rsrcend = out.tellp();
|
||||
while((int)out.tellp() % 128)
|
||||
byte(out,0);
|
||||
@ -242,7 +249,7 @@ std::string fromhex(std::string hex)
|
||||
std::string bin;
|
||||
int nibble;
|
||||
bool haveNibble = false;
|
||||
for(auto p = hex.begin(); p != hex.end(); ++p)
|
||||
for(std::string::iterator p = hex.begin(); p != hex.end(); ++p)
|
||||
{
|
||||
if(std::isspace(*p))
|
||||
continue;
|
||||
@ -269,7 +276,7 @@ std::string fromhex(std::string hex)
|
||||
|
||||
std::string readfile(std::string fn)
|
||||
{
|
||||
std::ifstream in(fn, std::ios::in|std::ios::binary);
|
||||
std::ifstream in(fn.c_str(), std::ios::in|std::ios::binary);
|
||||
return std::string(std::istreambuf_iterator<char>(in),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
@ -364,10 +371,10 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
{
|
||||
std::ofstream out(binFileName);
|
||||
writeMacBinary(out, outFileName, "APPL", "????",
|
||||
[&](std::ostream& out) { rsrc.writeFork(out); },
|
||||
[](std::ostream& out) {});
|
||||
std::ofstream out(binFileName.c_str());
|
||||
|
||||
writeMacBinary(out, outFileName, "APPL", "????",
|
||||
rsrc, Fork());
|
||||
}
|
||||
wrapMacBinary(binFileName, dskFileName);
|
||||
return 0;
|
||||
|
22
Raytracer/CMakeLists.txt
Normal file
22
Raytracer/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
if(NOT APPLE)
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11")
|
||||
endif()
|
||||
|
||||
include_directories(../App2)
|
||||
add_executable(Raytracer MACOSX_BUNDLE
|
||||
raytracer.cc
|
||||
)
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(Raytracer "-framework Carbon")
|
||||
else()
|
||||
target_link_libraries(Raytracer retrocrt)
|
||||
add_custom_command(
|
||||
OUTPUT Raytracer.bin
|
||||
COMMAND ${MAKE_APPL} -c Raytracer -o Raytracer
|
||||
DEPENDS Raytracer)
|
||||
add_custom_target(RaytracerAPPL ALL DEPENDS Raytracer.bin)
|
||||
endif()
|
||||
|
254
Raytracer/raytracer.cc
Normal file
254
Raytracer/raytracer.cc
Normal file
@ -0,0 +1,254 @@
|
||||
#ifdef __APPLE__
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#define PSTR(x) ("\p" x)
|
||||
|
||||
#else
|
||||
|
||||
#include <Quickdraw.h>
|
||||
#include <MacMemory.h>
|
||||
#include <Sound.h>
|
||||
#include <Events.h>
|
||||
#include <Fonts.h>
|
||||
#include <NumberFormatting.h>
|
||||
|
||||
#include "MacUtils.h"
|
||||
|
||||
QDGlobals qd;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
bool hitSphere(float x0, float y0, float z0, float dx, float dy, float dz, float& t)
|
||||
{
|
||||
const float xc = 0.0f, yc = 0.0f, zc = -6.0f, r = 1.0f;
|
||||
float x0c = x0 - xc;
|
||||
float y0c = y0 - yc;
|
||||
float z0c = z0 - zc;
|
||||
|
||||
/*
|
||||
(x-xc)^2 + (y-yc)^2 + (z-zc)^2 = r^2;
|
||||
(x0c + dx * t)^2 + (y0c + dy * t)^2 + (z0c + dz * t)^2 = r^2;
|
||||
x0c^2 + 2*x0c*dx*t + dx^2*t^2 + y0c^2 + 2*y0c*dy*t + dy^2*t^2 + z0c^2 + 2 * z0c*dz*t + dz^2*t^2 = r^2
|
||||
|
||||
(dx^2 + dy^2 + dz^2)*t^2 + (2*x0c*dx + 2*y0c&dy + 2*z0c*dz) * t + x0c^2+y0c^2+z0c^2-r^2
|
||||
*/
|
||||
float a = dx*dx + dy*dy + dz*dz;
|
||||
float b = 2*(x0c*dx + y0c*dy + z0c*dz);
|
||||
float c = x0c*x0c + y0c*y0c + z0c*z0c -r*r;
|
||||
|
||||
float D = b*b - 4 * a * c;
|
||||
|
||||
if(D >= 0)
|
||||
{
|
||||
float t = (-b - std::sqrt(D)) / (2*a);
|
||||
return t >= 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const float lx = -2, ly = 4, lz = 3;
|
||||
const float lenl = 1.0f / std::sqrt(lx*lx + ly*ly + lz*lz);
|
||||
const float lxn = lx*lenl, lyn = ly*lenl, lzn = lz*lenl;
|
||||
|
||||
float ray(int n, float x0, float y0, float z0, float dx, float dy, float dz)
|
||||
{
|
||||
{
|
||||
const float xc = 0.0f, yc = 0.0f, zc = -6.0f, r = 1.0f;
|
||||
float x0c = x0 - xc;
|
||||
float y0c = y0 - yc;
|
||||
float z0c = z0 - zc;
|
||||
|
||||
/*
|
||||
(x-xc)^2 + (y-yc)^2 + (z-zc)^2 = r^2;
|
||||
(x0c + dx * t)^2 + (y0c + dy * t)^2 + (z0c + dz * t)^2 = r^2;
|
||||
x0c^2 + 2*x0c*dx*t + dx^2*t^2 + y0c^2 + 2*y0c*dy*t + dy^2*t^2 + z0c^2 + 2 * z0c*dz*t + dz^2*t^2 = r^2
|
||||
|
||||
(dx^2 + dy^2 + dz^2)*t^2 + (2*x0c*dx + 2*y0c&dy + 2*z0c*dz) * t + x0c^2+y0c^2+z0c^2-r^2
|
||||
*/
|
||||
float a = dx*dx + dy*dy + dz*dz;
|
||||
float b = 2*(x0c*dx + y0c*dy + z0c*dz);
|
||||
float c = x0c*x0c + y0c*y0c + z0c*z0c -r*r;
|
||||
|
||||
float D = b*b - 4 * a * c;
|
||||
|
||||
if(D >= 0)
|
||||
{
|
||||
float t = (-b - std::sqrt(D)) / (2*a);
|
||||
if(t > 0)
|
||||
{
|
||||
float x = x0 + dx * t;
|
||||
float y = y0 + dy * t;
|
||||
float z = z0 + dz * t;
|
||||
|
||||
float dx2 = x - xc;
|
||||
float dy2 = y - yc;
|
||||
float dz2 = z - zc;
|
||||
|
||||
|
||||
float l = dx2 * dx + dy2 * dy + dz2 * dz;
|
||||
l *= 2;
|
||||
|
||||
float reflected;
|
||||
if(n)
|
||||
reflected = ray(n-1, x,y,z, dx - l*dx2, dy - l*dy2, dz - l*dz2);
|
||||
else
|
||||
reflected = 0.0f;
|
||||
|
||||
|
||||
float lambert = dx2 * lxn + dy2 * lyn + dz2 * lzn;
|
||||
|
||||
return 0.2f + 0.4f * std::max(0.0f,lambert) + 0.4f * reflected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dy < 0)
|
||||
{
|
||||
float t = (-1.5f - y0) / dy;
|
||||
float x = x0 + dx * t;
|
||||
float z = z0 + dz * t;
|
||||
|
||||
float color;
|
||||
if( (static_cast<int>( std::floor(x) )
|
||||
+ static_cast<int>( std::floor(z) )) % 2 )
|
||||
color = 0.8f;
|
||||
else
|
||||
color = 0.1f;
|
||||
|
||||
float ts;
|
||||
if(hitSphere(x,-1.5f,z, lxn, lyn, lzn, ts))
|
||||
color *= 0.2f;
|
||||
|
||||
return std::min(1.0f, color + 0.5f * ray(n-1, x,-2.0f,z,dx,-dy,dz));
|
||||
}
|
||||
|
||||
return std::max(0.0f, dy * 0.3f);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
WindowPtr win;
|
||||
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
InitGraf(&qd.thePort);
|
||||
InitFonts();
|
||||
InitWindows();
|
||||
InitMenus();
|
||||
|
||||
Rect r = qd.screenBits.bounds;
|
||||
#else
|
||||
BitMap bm;
|
||||
GetQDGlobalsScreenBits(&bm);
|
||||
Rect r = bm.bounds;
|
||||
#endif
|
||||
SetRect(&r, r.left + 5, r.top + 45, r.right - 5, r.bottom -5);
|
||||
win = NewWindow(NULL, &r, PSTR("Raytracer"), true, 0, (WindowPtr)-1, false, 0);
|
||||
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
SetPort(win);
|
||||
r = win->portRect;
|
||||
#else
|
||||
SetPortWindowPort(win);
|
||||
GetPortBounds(GetWindowPort(win), &r);
|
||||
#endif
|
||||
EraseRect(&r);
|
||||
float accum = 0.0f;
|
||||
short cx = r.right /2;
|
||||
short cy = r.bottom / 2;
|
||||
|
||||
long startTime = TickCount();
|
||||
std::vector<float> accumV(r.right);
|
||||
for(int y = 0; y < r.bottom; y++)
|
||||
{
|
||||
for(int x = 0; x < r.right; x++)
|
||||
{
|
||||
float pixel;
|
||||
|
||||
// cam = (0,0,0)
|
||||
// ray = t * (x-r.right/2, - (y-r.bottom/2), -1)
|
||||
// plane: y = -2
|
||||
|
||||
float dx = x - cx;
|
||||
float dy = - (y - cy);
|
||||
float dz = -cx;
|
||||
float n1 = 1.0f / std::sqrt(dx*dx + dy*dy + dz*dz);
|
||||
|
||||
pixel = ray(1,0,0,0,n1*dx,n1*dy,n1*dz);
|
||||
|
||||
#if 0
|
||||
accum += pixel;
|
||||
if(accum >= 0.5f)
|
||||
accum -= 1.0f;
|
||||
else
|
||||
{
|
||||
MoveTo(x,y);
|
||||
Line(0,0);
|
||||
}
|
||||
#elif 0
|
||||
accum += pixel;
|
||||
accum += accumV[x];
|
||||
if(accum >= 0.5f)
|
||||
accum -= 1.0f;
|
||||
else
|
||||
{
|
||||
MoveTo(x,y);
|
||||
Line(0,0);
|
||||
}
|
||||
accumV[x] = accum = accum / 2;
|
||||
#elif 0
|
||||
//if(pixel < Random() / 32767.0)
|
||||
if(pixel < (float)std::rand() / (32767.0f * 65536.0f))
|
||||
{
|
||||
MoveTo(x,y);
|
||||
Line(0,0);
|
||||
}
|
||||
#else
|
||||
float thresh = (float)std::rand() / (32767.0f * 65536.0f);
|
||||
thresh = 0.5f + 0.4f * (thresh - 0.5f);
|
||||
accum += pixel;
|
||||
accum += accumV[x];
|
||||
if(accum >= thresh)
|
||||
accum -= 1.0f;
|
||||
else
|
||||
{
|
||||
MoveTo(x,y);
|
||||
Line(0,0);
|
||||
}
|
||||
accumV[x] = accum = accum / 2;
|
||||
#endif
|
||||
}
|
||||
if(Button())
|
||||
return 0;
|
||||
#if TARGET_API_MAC_CARBON
|
||||
// QDFlushPortBuffer(GetWindowPort(win),NULL);
|
||||
#endif
|
||||
}
|
||||
long endTime = TickCount();
|
||||
|
||||
char buf[256];
|
||||
unsigned char* pstr = (unsigned char*)buf;
|
||||
sprintf(buf+1, "pps = %g", (double)r.right * r.bottom / (endTime - startTime) * 60.0);
|
||||
buf[0] = std::strlen(buf+1);
|
||||
|
||||
SetRect(&r, 10, 10, 10 + StringWidth(pstr) + 10, 30);
|
||||
PaintRect(&r);
|
||||
PenMode(patXor);
|
||||
FrameRect(&r);
|
||||
MoveTo(15,25);
|
||||
TextMode(srcBic);
|
||||
DrawString(pstr);
|
||||
#if TARGET_API_MAC_CARBON
|
||||
QDFlushPortBuffer(GetWindowPort(win),NULL);
|
||||
#endif
|
||||
|
||||
while(!Button())
|
||||
;
|
||||
FlushEvents(everyEvent, -1);
|
||||
return 0;
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
SRC=$(readlink -f `dirname $0`)
|
||||
SRC=$(cd `dirname $0` && pwd -P)
|
||||
mkdir -p binutils-build
|
||||
mkdir -p toolchain
|
||||
PREFIX=`pwd`/toolchain/
|
||||
set -e
|
||||
|
||||
cd binutils-build
|
||||
export "CFLAGS=-Wno-unused-but-set-variable -Wno-unused-but-set-parameter"
|
||||
export "CFLAGS=-Wno-error"
|
||||
$SRC/binutils/configure --target=m68k-unknown-elf --prefix=$PREFIX
|
||||
make -j8
|
||||
make install
|
||||
@ -20,20 +20,20 @@ make install
|
||||
|
||||
cd ..
|
||||
|
||||
#mkdir -p newlib-build
|
||||
#cd newlib-build
|
||||
BINUTILS=$(readlink -f binutils-build)
|
||||
BINUTILS=$(cd binutils-build && pwd -P)
|
||||
|
||||
export "CFLAGS=-I../../Retro68/binutils/include"
|
||||
cp $SRC/elf.h $PREFIX/include/
|
||||
export "CFLAGS=-I../../Retro68/binutils/include -I../toolchain/include"
|
||||
mkdir -p elf2flt-build
|
||||
cd elf2flt-build
|
||||
$SRC/elf2flt/configure --target=m68k-unknown-elf --prefix=$PREFIX --with-binutils-build-dir=$BINUTILS
|
||||
make -j8
|
||||
make -j8 TOOLDIR=$PREFIX/bin
|
||||
make install
|
||||
unset CFLAGS
|
||||
|
||||
cd ..
|
||||
|
||||
mkdir -p $PREFIX/man/man1
|
||||
rm -rf hfsutils
|
||||
cp -r $SRC/hfsutils .
|
||||
cd hfsutils
|
||||
@ -44,3 +44,18 @@ cd ..
|
||||
|
||||
runhaskell ../Retro68/PrepareHeaders.hs ../Retro68/Universal\ Headers toolchain/m68k-unknown-elf/include
|
||||
|
||||
mkdir -p build-host
|
||||
cd build-host
|
||||
cmake ../../Retro68/ -DCMAKE_INSTALL_PREFIX=$PREFIX
|
||||
cd ..
|
||||
|
||||
mkdir -p build-target
|
||||
cd build-target
|
||||
cmake ../../Retro68/ -DCMAKE_INSTALL_PREFIX=$PREFIX/m68k-unknown-elf \
|
||||
-DCMAKE_TOOLCHAIN_FILE=$SRC/retro68.toolchain.cmake \
|
||||
-DRETRO68_ROOT=$PREFIX \
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
cd ..
|
||||
|
||||
make -C build-host install
|
||||
make -C build-target install
|
||||
|
Loading…
Reference in New Issue
Block a user