Files
CydandClaude Opus 4.8 4abbf8879f Initial import of Red Planet v4.10 Win32 source
Imports the current Win32 source for the pod-racing game 'Red Planet',
built on the MUNGA engine and its L4 (Win32/DirectX) platform layer:

- MUNGA / MUNGA_L4: cross-platform engine core and Win32 backend
- RP / RP_L4: Red Planet game logic and Win32 application
- DivLoader, Setup1: asset loader and installer project
- lib, MUNGA_L4/openal, MUNGA_L4/sos: third-party audio dependencies

Removed stale Subversion metadata and added .gitignore/.gitattributes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 07:59:51 -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