Clean, self-contained extraction of the BattleTech-specific work from the
reverse-engineering workspace -- engine + game + content + build, with nothing
from Red Planet or the raw archive dumps. Builds green (Win32) and runs the
single-player drive->animate->target->fire->damage->destroy loop out of the box.
Layout:
engine/ MUNGA + MUNGA_L4 shared 2007 engine, carrying our BT render/loader
work (bgfload/L4D3D/L4VIDEO: BSL bit-slice decode, LOD/ground/shadow
models) + image codec; the minimal rp/ headers the audio HAL needs
game/ reconstructed BT logic + surviving-original BT source + fwd shims
+ WinMain launcher
content/ full runtime tree (BTL4.RES, VIDEO/, GAUGE/, AUDIO/, eggs, BTDPL.INI)
docs/ format specs + reconstruction ledgers
reference/ raw Ghidra pseudocode (recon source-of-truth) + decomp exporter
tools/ MP console emulator + map/resource scanners
One top-level CMake builds munga_engine lib + bt410_l4 game lib + btl4.exe.
All paths relativized (186 fwd shims + ~437 CMake abs paths -> repo-relative);
DXSDK is the one external, overridable via -DDXSDK. Verified: builds to a
byte-identical 2.27MB exe and runs combat (TARGET DESTROYED, 0 crashes) against
the bundled content.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
163 lines
3.7 KiB
C++
163 lines
3.7 KiB
C++
#include "mungal4.h"
|
|
#pragma hdrstop
|
|
|
|
#include "l4time.h"
|
|
//#include <bios.h>
|
|
//#include <sos.h>
|
|
#include <intrin.h>
|
|
#include <windows.h>
|
|
|
|
//#############################################################################
|
|
//########################### System Clock ##############################
|
|
//#############################################################################
|
|
|
|
SystemClock SystemClock::timer;
|
|
long SystemClock::ticksPerSecond;
|
|
__int64 SystemClock::perfCounterFreq;
|
|
|
|
//RB 1/20/07
|
|
//volatile long fast_time = 0L;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
//void outportb(short portid, unsigned char value)
|
|
//{
|
|
// __asm
|
|
// {
|
|
// MOV DX, portid
|
|
// MOV AL, value
|
|
// OUT DX, AL
|
|
// }
|
|
// __outbyte(portid, value);
|
|
//}
|
|
////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
////
|
|
//unsigned char inportb(short portid)
|
|
//{
|
|
// unsigned char retVal;
|
|
// __asm
|
|
// {
|
|
// MOV DX, portid
|
|
// IN AL, DX
|
|
// MOV retVal, AL
|
|
// }
|
|
// return retVal;
|
|
//}
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
/*TIME RB 1/20/07
|
|
void Timer_Handler()
|
|
{
|
|
++fast_time;
|
|
}*/
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
long SystemClock::GetRTC()
|
|
{
|
|
LARGE_INTEGER count;
|
|
QueryPerformanceCounter(&count);
|
|
return (long)((count.QuadPart * (__int64)1000) / SystemClock::perfCounterFreq);
|
|
}
|
|
|
|
double SystemClock::GetHiRes()
|
|
{
|
|
LARGE_INTEGER count;
|
|
QueryPerformanceCounter(&count);
|
|
return (count.QuadPart / (double)SystemClock::perfCounterFreq);
|
|
}
|
|
|
|
__int64 SystemClock::GetHiResTicks()
|
|
{
|
|
LARGE_INTEGER count;
|
|
QueryPerformanceCounter(&count);
|
|
return count.QuadPart;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
SystemClock::SystemClock()
|
|
{
|
|
//
|
|
//-------------------------------
|
|
// Initialize the timer variables
|
|
//-------------------------------
|
|
//
|
|
pauseStart = 0;
|
|
pauseTime = 0;
|
|
|
|
//
|
|
//------------------------------
|
|
// Initialize the platform timer
|
|
//------------------------------
|
|
//
|
|
// query the performance counter for its frequency
|
|
LARGE_INTEGER freq;
|
|
QueryPerformanceFrequency(&freq);
|
|
//SystemClock::ticksPerSecond = freq.QuadPart;
|
|
SystemClock::perfCounterFreq = freq.QuadPart;
|
|
SystemClock::ticksPerSecond = 1000L;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
void SystemClock::Shutdown()
|
|
{
|
|
/*STUBBED: TIME RB 1/20/07
|
|
if (timer_handler_handle != 0xFFFF)
|
|
{
|
|
#if DEBUG_LEVEL>0
|
|
WORD err = sosTIMERRemoveEvent(timer_handler_handle);
|
|
Verify(err == _ERR_NO_ERROR);
|
|
err = sosTIMERUnInitSystem(0);
|
|
Verify(err == _ERR_NO_ERROR);
|
|
#else
|
|
sosTIMERRemoveEvent(timer_handler_handle);
|
|
sosTIMERUnInitSystem(0);
|
|
#endif
|
|
}
|
|
*/
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
#define TIMER_CONTROL 0x43
|
|
#define GET_TIMER0 0xC2
|
|
#define TIMER0_PORT 0x40
|
|
#define OUTPUT_BIT 0x80
|
|
|
|
#undef inportb
|
|
#undef outportb
|
|
|
|
float Get_Frame_Percent_Used()
|
|
{
|
|
//STUBBED: SOS RB 1/14/07
|
|
|
|
///* RB 1/11/07
|
|
//outportb(TIMER_CONTROL, GET_TIMER0);
|
|
//int half = inportb(TIMER0_PORT) & OUTPUT_BIT;
|
|
//int subtick = ((int)inportb(TIMER0_PORT)) >> 1;
|
|
//subtick += (((int)inportb(TIMER0_PORT)) << 7);
|
|
//*/
|
|
|
|
//__outbyte(TIMER_CONTROL, GET_TIMER0);
|
|
//int half = __inbyte(TIMER0_PORT) & OUTPUT_BIT;
|
|
//int subtick = ((int)__inbyte(TIMER0_PORT)) >> 1;
|
|
//subtick += (((int)__inbyte(TIMER0_PORT)) << 7);
|
|
|
|
//if (timer_handler_handle == 0xFFFF)
|
|
//{
|
|
// subtick += half << 8;
|
|
// return (65535 - subtick) / 65536.0f;
|
|
//}
|
|
//else
|
|
//{
|
|
// if (half)
|
|
// {
|
|
// subtick += _wTIMERValue >> 1;
|
|
// }
|
|
// return (_wTIMERValue - 1 - subtick) / (float)_wTIMERValue;
|
|
//}
|
|
return 0.0f;
|
|
}
|