📄 madvent.asm
字号:
; MADVENT.ASM
;
; This is a "shell" of an adventure game that you can use to create
; your own adventure style games.
.xlist
.286
include stdlib.a
includelib stdlib.lib
matchfuncs
.list
dseg segment para public 'data'
; Equates:
NULL equ 0
MaxWeight equ 4 ;Max weight user can carry at one time.
; The "ROOM" data structure defines a room, or area, where a player can
; go. The NORTH, SOUTH, EAST, and WEST fields contain the address of
; the rooms to the north, south, east, and west of the room. The game
; transfers control to the room whose address appears in these fields
; when the player supplies a GO NORTH, GO SOUTH, etc., command.
;
; The ITEMLIST field contains a list of pointers to objects appearing
; in this room. In this game, the user can pick up and drop these
; objects (if there are any present).
;
; The DESCRIPTION field contains a (near) address of a short description
; of the current room/area.
Room struct
north word ? ;Near pointers to other structures where
south word ? ; we will wind up on the GO NORTH, GO SOUTH,
west word ? ; etc., commands.
east word ?
ItemList word MaxWeight dup (?)
Description word ? ;Description of room.
Room ends
; The ITEM data structure describes the objects that may appear
; within a room (in the ITEMLIST above). The VALUE field contains
; the number of points this object is worth if the user drops it
; off in the proper room (i.e, solves the puzzle). The WEIGHT
; field provides the weight of this object. The user can only
; carry four units of weight at a time. This field is usually
; one, but may be more for larger objects. The KEY field is the
; address of the room where this object must be dropped to solve
; the problem. The SHORTDESC field is a pointer to a string that
; the program prints when the user executes an INVENTORY command.
; LONGDESC is a pointer to a string the program prints when des-
; cribing the contents of a room. The WINDESC field is a pointer
; to a string that the program prints when the user solves the
; appropriate puzzle.
Item struct
Value word ?
Weight word ?
Key word ?
ShortDesc word ?
LongDesc word ?
WinDesc word ?
Item ends
; State variables for the player:
CurRoom word Room1 ;Room the player is in.
ItemsOnHand word MaxWeight dup (?) ;Items the player carries.
CurWeight word 0 ;Weight of items carried.
CurScore word 15 ;Player's current score.
TotalCounter word 9 ;Items left to place.
Noun word 0 ;Current noun value.
Verb word 0 ;Current verb value.
NounPtr word 0 ;Ptr to current noun item.
; Input buffer for commands
InputLine byte 128 dup (?)
; The following macros generate a pattern which will match a single word
; which appears anywhere on a line. In particular, they match a word
; at the beginning of a line, somewhere in the middle of the line, or
; at the end of a line. This program defines a word as any sequence
; of character surrounded by spaces or the beginning or end of a line.
;
; MatchNoun/Verb matches lines defined by the regular expression:
;
; (ARB* ' ' | <empty string>) string (' ' | EOS)
MatchNoun macro Name, next, WordString, ItemVal, ItemPtr
local WS1, WS2, WS3, WS4
local WS5, WS6, WordStr
Name Pattern {sl_match2, WS1, next}
WS1 Pattern {MatchStr, WordStr, WS2, WS5}
WS2 Pattern {arb,0,0,WS3}
WS3 Pattern {Matchchar, ' ',0, WS4}
WS4 Pattern {MatchStr, WordStr, 0, WS5}
WS5 Pattern {SetNoun,ItemVal,0,WS6}
WS6 Pattern {SetPtr, ItemPtr,0,MatchEOS}
WordStr byte WordString
byte 0
endm
MatchVerb macro Name, next, WordString, ItemVal
local WS1, WS2, WS3, WS4
local WS5, WordStr
Name Pattern {sl_match2, WS1, next}
WS1 Pattern {MatchStr, WordStr, WS2, WS5}
WS2 Pattern {arb,0,0,WS3}
WS3 Pattern {Matchchar, ' ',0, WS4}
WS4 Pattern {MatchStr, WordStr, 0, WS5}
WS5 Pattern {SetVerb,ItemVal,0,MatchEOS}
WordStr byte WordString
byte 0
endm
; Generic patterns which most of the patterns use:
MatchEOS Pattern {EOS,0,MatchSpc}
MatchSpc Pattern {MatchChar,' '}
; Here are the list of nouns allowed in this program.
NounPat pattern {sl_match2, MatchNorth}
MatchNoun MatchNorth, MatchSouth, "NORTH", 1, 0
MatchNoun MatchSouth, MatchEast, "SOUTH", 2, 0
MatchNoun MatchEast, MatchWest, "EAST", 3, 0
MatchNoun MatchWest, MatchLime, "WEST", 4, 0
MatchNoun MatchLime, MatchBeer, "LIME", 5, Item3
MatchNoun MatchBeer, MatchCard, "BEER", 6, Item9
MatchNoun MatchCard, MatchSign, "CARD", 7, Item2
MatchNoun MatchSign, MatchPgm, "SIGN", 8, Item1
MatchNoun MatchPgm, MatchHW, "PROGRAM", 9, Item7
MatchNoun MatchHW, MatchMoney, "HOMEWORK", 10, Item4
MatchNoun MatchMoney, MatchForm, "MONEY", 11, Item5
MatchNoun MatchForm, MatchCoupon, "FORM", 12, Item6
MatchNoun MatchCoupon, 0, "COUPON", 13, Item8
; Here is the list of allowable verbs.
VerbPat pattern {sl_match2, MatchGo}
MatchVerb MatchGO, MatchGet, "GO", 1
MatchVerb MatchGet, MatchDrop, "GET", 2
MatchVerb MatchDrop, MatchInv, "DROP", 3
MatchVerb MatchInv, MatchQuit, "INVENTORY", 4
MatchVerb MatchQuit, MatchHelp, "QUIT", 5
MatchVerb MatchHelp, 0, "HELP", 6
; Data structures for the "maze".
Room1 room {Room1, Room5, Room4, Room2,
{Item1,0,0,0},
Room1Desc}
Room1Desc byte "at the Commons",0
Item1 item {10,2,Room3,GS1,GS2,GS3}
GS1 byte "a big sign",0
GS2 byte "a big sign made of styrofoam with funny "
byte "letters on it.",0
GS3 byte "The ETA PI Fraternity thanks you for return"
byte "ing their sign, they",cr,lf
byte "make you an honorary life member, as long as "
byte "you continue to pay",cr,lf
byte "your $30 monthly dues, that is.",0
Room2 room {NULL, Room5, Room1, Room3,
{Item2,0,0,0},
Room2Desc}
Room2Desc byte 'at the "C" on the hill above campus',0
Item2 item {10,1,Room1,LC1,LC2,LC3}
LC1 byte "a lunch card",0
LC2 byte "a lunch card which someone must have "
byte "accidentally dropped here.", 0
LC3 byte "You get a big meal at the Commons cafeteria"
byte cr,lf
byte "It would be a good idea to go visit the "
byte "student health center",cr,lf
byte "at this time.",0
Room3 room {NULL, Room6, Room2, Room2,
{Item3,0,0,0},
Room3Desc}
Room3Desc byte "at ETA PI Frat House",0
Item3 item {10,2,Room2,BL1,BL2,BL3}
BL1 byte "a bag of lime",0
BL2 byte "a bag of baseball field lime which someone "
byte "is obviously saving for",cr,lf
byte "a special occasion.",0
BL3 byte "You spread the lime out forming a big '++' "
byte "after the 'C'",cr,lf
byte "Your friends in Computer Science hold you "
byte "in total awe.",0
Room4 room {Room1, Room7, Room7, Room5,
{Item4,0,0,0},
Room4Desc}
Room4Desc byte "in Dr. John Smith's Office",0
Item4 item {10,1,Room7,HW1,HW2,HW3}
HW1 byte "a homework assignment",0
HW2 byte "a homework assignment which appears to "
byte "to contain assembly language",0
HW3 byte "The grader notes that your homework "
byte "assignment looks quite",cr,lf
byte "similar to someone else's assignment "
byte "in the class and reports you",cr,lf
byte "to the instructor.",0
Room5 room {Room1, Room9, Room7, Room2,
{Item5,0,0,0},
Room5Desc}
Room5Desc byte "in the computer lab",0
Item5 item {10,1,Room9,M1,M2,M3}
M1 byte "some money",0
M2 byte "several dollars in an envelope in the "
byte "trashcan",0
M3 byte "The waitress thanks you for your "
byte "generous tip and gets you",cr,lf
byte "another pitcher of beer. "
byte "Then she asks for your ID.",cr,lf
byte "You are at least 21 aren't you?",0
Room6 room {Room3, Room9, Room5, NULL,
{Item6,0,0,0},
Room6Desc}
Room6Desc byte "at the campus book store",0
Item6 item {10,1,Room8,AD1,AD2,AD3}
AD1 byte "an add/drop/change form",0
AD2 byte "an add/drop/change form filled out for "
byte "assembly to get a letter grade",0
AD3 byte "You got the form in just in time. "
byte "It would have been a shame to",cr,lf
byte "have had to retake assembly because "
byte "you didn't realize you needed to ",cr,lf
byte "get a letter grade in the course.",0
Room7 room {Room1, Room7, Room4, Room8,
{Item7,0,0,0},
Room7Desc}
Room7Desc byte "in the assembly lecture",0
Item7 item {10,1,Room5,AP1,AP2,AP3}
AP1 byte "an assembly language program",0
AP2 byte "an assembly language program due in "
byte "the assemblylanguage class.",0
AP3 byte "The sample program the instructor gave "
byte "you provided all the information",cr,lf
byte "you needed to complete your assignment. "
byte "You finish your work and",cr,lf
byte "head to the local pub to celebrate."
byte cr,lf,0
Room8 room {Room5, Room6, Room7, Room9,
{Item8,0,0,0},
Room8Desc}
Room8Desc byte "at the Registrar's office",0
Item8 item {10,1,Room6,C1,C2,C3}
C1 byte "a coupon",0
C2 byte "a coupon good for a free text book",0
C3 byte 'You get a free copy of "Cliff Notes for '
byte 'The Art of Assembly',cr,lf
byte 'Language Programming" Alas, it does not '
byte "provide all the",cr,lf
byte "information you need for the class, so you "
byte "sell it back during",cr,lf
byte "the book buy-back period.",0
Room9 room {Room6, Room9, Room8, Room3,
{Item9,0,0,0},
Room9Desc}
Room9Desc byte "at The Pub",0
Item9 item {10,2,Room4,B1,B2,B3}
B1 byte "a pitcher of beer",0
B2 byte "an ice cold pitcher of imported beer",0
B3 byte "Dr. Smith thanks you profusely for your "
byte "good taste in brews.",cr,lf
byte "He then invites you to the pub for a "
byte "round of pool and",cr,lf
byte "some heavy duty hob-nobbing, "
byte "CS Department style.",0
dseg ends
cseg segment para public 'code'
assume ds:dseg
; SetNoun- Copies the value in SI (the matchparm parameter) to the
; NOUN variable.
SetNoun proc far
push ds
mov ax, dseg
mov ds, ax
mov Noun, si
mov ax, di
stc
pop ds
ret
SetNoun endp
; SetVerb- Copies the value in SI (the matchparm parameter) to the
; VERB variable.
SetVerb proc far
push ds
mov ax, dseg
mov ds, ax
mov Verb, si
mov ax, di
stc
pop ds
ret
SetVerb endp
; SetPtr- Copies the value in SI (the matchparm parameter) to the
; NOUNPTR variable.
SetPtr proc far
push ds
mov ax, dseg
mov ds, ax
mov NounPtr, si
mov ax, di
stc
pop ds
ret
SetPtr endp
; CheckPresence-
; BX points at an item. DI points at an item list. This
; routine checks to see if that item is present in the
; item list. Returns Carry set if item was found,
; clear if not found.
CheckPresence proc
; MaxWeight is an assembly-time adjustable constant that determines
; how many objects the user can carry, or can be in a room, at one
; time. The following repeat macro emits "MaxWeight" compare and
; branch sequences to test each item pointed at by DS:DI.
ItemCnt = 0
repeat MaxWeight
cmp bx, [di+ItemCnt]
je GotIt
ItemCnt = ItemCnt+2
endm
clc
ret
GotIt: stc
ret
CheckPresence endp
; RemoveItem- BX contains a pointer to an item. DI contains a pointer
; to an item list which contains that item. This routine
; searches the item list and removes that item from the
; list. To remove an item from the list, we need only
; store a zero (NULL) over the top of its pointer entry
; in the list.
RemoveItem proc
; Once again, we use the repeat macro to automatically generate a chain
; of compare, branch, and remove code sequences for each possible item
; in the list.
ItemCnt = 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -