BBS: Inland Empire Archive Date: 02-06-93 (09:42) Number: 341 From: DAVID COLSTON Refer#: NONE To: ALL Recvd: NO Subj: Simple door 1/4 Conf: (2) Quik_Bas
A local sysop wanted a door to roll dice for a dungeons and dragons
game. I thought you might like to see it. Some of the code might look
familar<g>. Not all of the fossil routines are used, but are offered
for completeness.
--------------------Cut here------------------------------------
DECLARE SUB CheckPortStatus (Port%, Info%, Reg AS ANY)
DECLARE SUB FossInit (Port%, Present%, Reg AS ANY)
DECLARE SUB GetChar (Port%, Good%, InBound$, Present%, Reg AS ANY)
DECLARE SUB PrintCon (A$, Reg AS ANY)
DECLARE SUB SendChar (Port%, Sent%, Present%, Outbound$, Reg AS ANY)
'$INCLUDE: 'C:\bc7\src\QBX.BI'
' Include Data Types for IN
DEFINT A-Z
'$STATIC
DIM Reg AS RegType ' Used for INTERRUPT calls
A# = TIMER + 120 'Allow only two minute in this door
'This saves us from constantly monitoring
'carrier detect.
ON TIMER(A#) GOSUB Quit
ON KEY(10) GOSUB Quit'Allow local bail out by sysop
TIMER ON
KEY(10) ON
Port = VAL(LTRIM$(RTRIM$(COMMAND$)))' Port =0 is port 1, etc.
Start:
DIM Rolls(1000)
FossInit Port, Present, Reg 'Find out if fossil is present or
'if we're
just looking on a PC.
Bits = 8 'Defaults for almost all boards!
Stops = 1
Parity$ = "N"
SendChar Port, Sent, Present, CHR$(12), Reg 'Just in case they
'have
X$ = CHR$(27) + "[2J Dice Door 1.0 By David Colston (c) 1993"
X$ = X$+ CHR$(13) + CHR$(10)
'Send ansii clear screen and return; line feed
X$ = X$ + " Enter your character name:"
FOR I = 1 TO LEN(X$)
SendChar Port, Sent, Present, MID$(X$, I, 1), Reg
PrintCon MID$(X$, I, 1), Reg'Echo to board consol.
NEXT
DO
GetChar Port, Good, InBound$, Present, Reg
IF Good THEN
IF InBound$ <> CHR$(13) THEN User$ = User$ + InBound$
SendChar Port, Sent, Present, InBound$, Reg
PrintCon InBound$, Reg
END IF
LOOP UNTIL InBound$ = CHR$(13)
DiceSides:
X$ = CHR$(13) + CHR$(10) + " Enter Number of Dice Sides:"
FOR I = 1 TO LEN(X$)
SendChar Port, Sent, Present, MID$(X$, I, 1), Reg
PrintCon MID$(X$, I, 1), Reg
NEXT
Sides$ = ""
DO
GetChar Port, Good, InBound$, Present, Reg
IF Good THEN
IF INSTR(1, "1234567890", InBound$) > 0 THEN
Sides$ = Sides$ + InBound$
SendChar Port, Sent, Present, InBound$, Reg
END IF
PrintCon InBound$, Reg
END IF
LOOP UNTIL InBound$ = CHR$(13)
IF VAL(Sides$) < 2 OR VAL(Sides$) > 100 THEN GOTO DiceSides
Dice:
X$ = CHR$(13) + CHR$(10) + " Enter Number of Dice :"
FOR I = 1 TO LEN(X$)
SendChar Port, Sent, Present, MID$(X$, I, 1), Reg
PrintCon MID$(X$, I, 1), Reg
NEXT
Dice$ = ""
DO
GetChar Port, Good, InBound$, Present, Reg
IF Good THEN
IF INSTR(1, "1234567890", InBound$) > 0 THEN
Dice$ = Dice$ + InBound$
SendChar Port, Sent, Present, InBound$, Reg
END IF
PrintCon InBound$, Reg
END IF
LOOP UNTIL InBound$ = CHR$(13)
IF VAL(Dice$) < 2 OR VAL(Dice$) > 100 THEN GOTO Dice
Grey = FREEFILE
OPEN "Greyhawk.rol" FOR APPEND AS Grey' Output for game bulletin
PRINT #Grey, "On "; DATE$; " "; User$; " had the following roll."
PRINT #Grey, "# Dice = "; Dice$; " # Sides = "; Sides$
RANDOMIZE TIMER
TotalRoll = 0
FOR I = 1 TO VAL(Dice$)
Roll = INT(RND(1) * VAL(Sides$)) + 1
X$ = CHR$(13) + CHR$(10) + " Die" + STR$(I) + " Showed" + STR$(Roll)
TotalRoll = TotalRoll + Roll
FOR J = 1 TO LEN(X$)
SendChar Port, Sent, Present, MID$(X$, J, 1), Reg
PrintCon MID$(X$, J, 1), Reg
NEXT
PRINT #Grey, RIGHT$(X$, LEN(X$) - 2)
NEXT
X$ = CHR$(13) + CHR$(10) + " Total Rolled Was" + STR$(TotalRoll)
PRINT #Grey, RIGHT$(X$, LEN(X$) - 2)
PRINT #Grey, SPACE$(10)
FOR J = 1 TO LEN(X$)
SendChar Port, Sent, Present, MID$(X$, J, 1), Reg
PrintCon MID$(X$, J, 1), Reg
NEXT
SendChar Port, Sent, Present, CHR$(13), Reg
X$ = CHR$(13) + CHR$(10) + " Press any key."
FOR J = 1 TO LEN(X$)
SendChar Port, Sent, Present, MID$(X$, J, 1), Reg
PrintCon MID$(X$, J, 1), Reg
NEXT
DO
GetChar Port, Good, InBound$, Present, Reg
IF Good THEN PrintCon InBound$, Reg
LOOP UNTIL Good Quit:
END
'This door in not error trapped one of you Guys might do better!
SUB CheckPortStatus (Port, Info, Reg AS RegType)
' ah = &H03 Fossil Function Number - Status
' al = &H00 Place Holder
' dx = Communications port number (0-3)
Reg.dx = Port
Reg.ax = &H300
Interrupt &H14, Reg, Reg
IF (Reg.ax AND &H80) <> 0 THEN Info = (Info OR &H1)
' carrier detect present ?
IF (Reg.ax AND &H100) <> 0 THEN Info = (Info OR &H2)
' buffer has data?
IF (Reg.ax AND &H200) <> 0 THEN Info = (Info OR &H4)
' Was buffer overun?
IF (Reg.ax AND &H4000) = 0 THEN Info = (Info OR &H8)
' output buffer data ?
IF (Reg.ax AND &H2000) = 0 THEN Info = (Info OR &H10)
' Is output buffer overrun?
END SUB
>>> Continued to next message
* OLX 2.1 TD * Colston & Associates, Inc. 501-452-2928 or 501-785-2208

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET