Files
BT412/engine/MUNGA_L4/JOYSTICK.asm
T
arcattackandClaude Opus 4.8 7b7d465e5e Initial commit: bt411 -- standalone Windows BattleTech (Tesla 4.10 port)
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>
2026-07-05 21:03:40 -05:00

148 lines
5.5 KiB
NASM

.list
;===========================================================================
; File: PCjoystk.asm
; Project: MUNGA
; Contents: PC joystick interface
;---------------------------------------------------------------------------
; Date Who Modification
; -------- --- -----------------------------------------------------------
; ??/??/?? JMA Initial coding
; 12/01/95 CPB Made pretty, expanded to four analog inputs (2 sticks).
; 01/20/95 CPB Added PC_Joystick_Mask
;---------------------------------------------------------------------------
; Copyright (C) 1995, Virtual World Entertainment, Inc. All rights reserved
; PROPRIETARY and CONFIDENTIAL
;===========================================================================
include l4asm.inc
include pcdpmi.inc
;===========================================================================
; Equates
;===========================================================================
JOYPORT EQU 0201h
XBIT1 EQU 00000001b
YBIT1 EQU 00000010b
XBIT2 EQU 00000100b
YBIT2 EQU 00001000b
BTTNA1 EQU 00010000b
BTTNB1 EQU 00100000b
BTTNA2 EQU 01000000b
BTTNB2 EQU 10000000b
ANALOGBITS EQU XBIT1+YBIT1+XBIT2+YBIT2
BUTTONBITS EQU BTTNA1+BTTNB1+BTTNA2+BTTNB2
;===========================================================================
; Data segment
;===========================================================================
BEGIN_DATA
PUBLIC PC_Joystick1_Raw_X,PC_Joystick1_Raw_Y
PUBLIC PC_Joystick2_Raw_X,PC_Joystick2_Raw_Y
PUBLIC PC_Joystick_Mask,PC_Joystick_Buttons
PC_Joystick1_Raw_X dw 0
PC_Joystick1_Raw_Y dw 0
PC_Joystick2_Raw_X dw 0
PC_Joystick2_Raw_Y dw 0
PC_Joystick_Mask db ANALOGBITS
PC_Joystick_Buttons db 0
END_DATA
;===========================================================================
; Code segment
;===========================================================================
BEGIN_CODE
;-------------------------------------------------------------------------
; PC_Joystick_Poll(void)
; Reads joystick values, places values into public memory locations
;-------------------------------------------------------------------------
; Enter:
; (void)
;-------------------------------------------------------------------------
; Returns:
; (void)
;-------------------------------------------------------------------------
BEGIN_C_PROC PC_Joystick_Update <eax,ebx,ecx,edx>
BUILD_STACK_FRAME
;--------------------------------------------------------------
; Disable interrupts, saving the old state of interrupts
;--------------------------------------------------------------
DPMI_DISABLE_SAVE_INT ;pushes ax!
;--------------------------------------------------------------
; Set up for timing loop
;--------------------------------------------------------------
mov dx,JOYPORT
xor cx,cx
;--------------------------------------------------------------
; Clear the port and start reading
;--------------------------------------------------------------
mov ah,PC_Joystick_Mask ;load AH with all bits set, clear al
xor al,al
out dx,al ;trigger the timers
check_again:
;--------------------------------------------------------------
; Read the port, check for changes
;--------------------------------------------------------------
in al,dx ;read the status bits
and al,PC_Joystick_Mask ;remove non-analog bits
xor al,ah ;check for a change
jz short no_change ;no change, hang out
;--------------------------------------------------------------
; See what changed
;--------------------------------------------------------------
test al,XBIT1
jz short no_x1_change
mov PC_Joystick1_Raw_X,cx
no_x1_change:
test al,YBIT1
jz short no_y1_change
mov PC_Joystick1_Raw_Y,cx
no_y1_change:
test al,XBIT2
jz short no_x2_change
mov PC_Joystick2_Raw_X,cx
no_x2_change:
test al,YBIT2
jz short no_y2_change
mov PC_Joystick2_Raw_Y,cx
no_y2_change:
;--------------------------------------------------------------
; See if we have read all the bits
;--------------------------------------------------------------
xor ah,al
jz short read_done
;--------------------------------------------------------------
; Increment the count and check again
;--------------------------------------------------------------
no_change:
inc cx
cmp cx,2048 ;arbitrary limit
jnz check_again
;--------------------------------------------------------------
; All done with analog values. Re-enable interrupts
;--------------------------------------------------------------
read_done:
DPMI_RESTORE_PREV_INT ;pops ax!
;--------------------------------------------------------------
; Read the buttons
;--------------------------------------------------------------
in al,dx ;read the status bits
not al ;invert the bits (so 1=closed)
and al,BUTTONBITS ;remove extraneous bits
mov PC_Joystick_Buttons,al ;save the result
;--------------------------------------------------------------
; Return
;--------------------------------------------------------------
END_C_PROC
END_CODE
END