home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / SAMPLES / FPGM.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-09-17  |  9.3 KB  |  445 lines

  1.         .xlist
  2.         include     stdlib.a
  3.         includelib    stdlib.lib
  4.         matchfuncs
  5.         .list
  6.         include        fpgm.a
  7.  
  8.  
  9.  
  10. dseg        segment        para public 'data'
  11.  
  12. ; State variables for the player:
  13.  
  14. CurRoom        word        Room1          ;Room the player is in.
  15. ItemsOnHand    word        MaxWeight dup (?) ;Items the player carries.
  16. CurWeight    word        0          ;Weight of items carried.
  17. CurScore    word        15          ;Player's current score.
  18. TotalCounter    word        9          ;Items left to place.
  19.  
  20.  
  21.  
  22. ; Input buffer for commands
  23.  
  24. InputLine    byte    128 dup (?)
  25.  
  26.  
  27. ; The following include brings in all the patterns.  They are in a separate
  28. ; file because they take up too much space in this program listing and
  29. ; make the program harder to read.
  30.  
  31.         include    Patterns.a
  32.  
  33. dseg        ends
  34.  
  35.  
  36.  
  37.  
  38.  
  39. cseg        segment        para public 'code'
  40.         assume        ds:dseg
  41.  
  42.  
  43.  
  44. ; NounToItem-     Attempts to search for one of the nouns in the current
  45. ;        command line.  Returns a pointer (in BX) to the corresponding
  46. ;        item if found on the line.
  47.  
  48. NounToItem    proc
  49.         push    cx
  50.         push    di
  51.         xor    bx, bx        ;Assume no match.
  52.         lea    di, InputLine
  53.  
  54. ; See if the noun "SIGN" appears anywhere on the input line.
  55.  
  56.         xor    cx, cx
  57.         ldxi    MatchSign
  58.         match
  59.         jnc    TryCard
  60.         lea    bx, Item1
  61.         jmp    NTIDone
  62.  
  63. ; See if the noun "CARD" appears anywhere on the input line.
  64.  
  65. TryCard:    xor    cx, cx
  66.         ldxi    MatchCard
  67.         match
  68.         jnc    TryLime
  69.         lea    bx, Item2
  70.         jmp    NTIDone
  71.  
  72. ; See if the noun "LIME" appears anywhere on the input line.
  73.  
  74. TryLime:    xor    cx, cx
  75.         ldxi    MatchLime
  76.         match
  77.         jnc    TryHW
  78.         lea    bx, Item3
  79.         jmp    NTIDone
  80.  
  81. ; See if the noun "HOMEWORK" appears anywhere on the input line.
  82.  
  83. TryHW:        xor    cx, cx
  84.         ldxi    MatchHW
  85.         match
  86.         jnc    TryMoney
  87.         lea    bx, Item4
  88.         jmp    NTIDone
  89.  
  90. ; See if the noun "MONEY" appears anywhere on the input line.
  91.  
  92. TryMoney:    xor    cx, cx
  93.         ldxi    MatchMoney
  94.         match
  95.         jnc    TryForm
  96.         lea    bx, Item5
  97.         jmp    NTIDone
  98.  
  99. ; See if the noun "FORM" appears anywhere on the input line.
  100.  
  101. TryForm:    xor    cx, cx
  102.         ldxi    MatchForm
  103.         match
  104.         jnc    TryPgm
  105.         lea    bx, Item6
  106.         jmp    NTIDone
  107.  
  108. ; See if the noun "PROGRAM" appears anywhere on the input line.
  109.  
  110. TryPgm:        xor    cx, cx
  111.         ldxi    MatchPgm
  112.         match
  113.         jnc    TryCoupon
  114.         lea    bx, Item7
  115.         jmp    NTIDone
  116.  
  117. ; See if the noun "COUPON" appears anywhere on the input line.
  118.  
  119. TryCoupon:    xor    cx, cx
  120.         ldxi    MatchCoupon
  121.         match
  122.         jnc    TryBeer
  123.         lea    bx, Item8
  124.         jmp    NTIDone
  125.  
  126. ; See if the noun "BEER" appears anywhere on the input line,
  127. ; if not, there is no valid noun which goes with GET or DROP on this line.
  128.  
  129. TryBeer:    xor    cx, cx
  130.         ldxi    MatchBeer
  131.         match
  132.         jnc    NTIDone
  133.         lea    bx, Item9
  134.  
  135.  
  136. NTIDone:    pop    di
  137.         pop    cx
  138.         ret
  139. NounToItem    endp
  140.  
  141.  
  142.  
  143. ; Here is the main program, which actually plays the game.
  144.  
  145. Main        proc
  146.         mov    ax, dseg
  147.         mov    ds, ax
  148.         mov    es, ax
  149.         meminit
  150.  
  151.         print
  152.         byte    cr,lf,lf,lf,lf,lf
  153.         byte    "Welcome to ",'"',"Randy's Riverside Rally",'"',cr,lf
  154.         byte    "If you need help, type the command ",'"HELP ME"'
  155.         byte    cr,lf,0
  156.  
  157. RoomLoop:    dec    CurScore        ;One point for each move.
  158.         jnz    NotOverYet
  159.  
  160. ; If they made too many moves without dropping anything properly, boot them
  161. ; out of the game.
  162.  
  163.         print
  164.         byte    "WHOA!  You lost!  You get to join the legions of "
  165.         byte    "the totally lame",cr,lf
  166.         byte    "who have failed at ",'"Randy',"'s Riverside Rally"
  167.         byte    '"',cr,lf,0
  168.         jmp    Quit
  169.  
  170. ; Okay, tell 'em where they are and get a new command from them.
  171.  
  172. NotOverYet:    putcr
  173.         call    Describe
  174.         print
  175.         byte    cr,lf
  176.         byte    "Command: ",0
  177.         lesi    InputLine
  178.         gets
  179.         strupr            ;Ignore case by converting to U.C.
  180.  
  181. ; Handle all the nouns which respond to "GO" down here:
  182.  
  183.         xor    cx, cx
  184.         ldxi    MatchGo
  185.         match
  186.         jnc    NoGo
  187.  
  188. ; Try GO NORTH here.
  189.  
  190.         mov    bx, CurRoom
  191.         xor    cx, cx
  192.         ldxi    MatchNorth
  193.         match
  194.         jnc    TrySouth
  195.         mov    bx, [bx].room.North
  196.  
  197. ; At this point BX contains a pointer to the room the user wants to go
  198. ; to (or zero/NULL if the user cannot go in the specify direction).
  199. ; Change the current room pointer as appropriate.
  200.  
  201. SetRoom:    test    bx, bx
  202.         jnz    SetCurRoom
  203.         print
  204.         byte    "Sorry, you cannot go in that direction",cr,lf,0
  205.         jmp    RoomLoop
  206.  
  207. SetCurRoom:    mov    CurRoom, bx
  208.         jmp    RoomLoop
  209.  
  210.  
  211. ; Handle the GO SOUTH command here.
  212.  
  213. TrySouth:    xor    cx, cx
  214.         ldxi    MatchSouth
  215.         match
  216.         jnc    TryEast
  217.         mov    bx, [bx].room.South
  218.         jmp    SetRoom
  219.  
  220. ; Handle the GO EAST command here.
  221.  
  222. TryEast:    xor    cx, cx
  223.         ldxi    MatchEast
  224.         match
  225.         jnc    TryWest
  226.         mov    bx, [bx].room.East
  227.         jmp    SetRoom
  228.  
  229. ; Handle the GO WEST command here.
  230.  
  231. TryWest:    xor    cx, cx
  232.         ldxi    MatchWest
  233.         match
  234.         jnc    BadCmd
  235.         mov    bx, [bx].room.West
  236.         jmp    SetRoom
  237.  
  238.  
  239.  
  240. ; Handle the "GET noun" commands down here.
  241.  
  242. NoGo:        xor    cx, cx
  243.         ldxi    MatchGet
  244.         match
  245.         jnc    NoGet
  246.  
  247. ; If the GET keyword appears on the command line, search for one of the
  248. ; valid nouns which may accompany GET.
  249.  
  250.         call    NounToItem
  251.         test    bx, bx            ;Is there a valid item
  252.         jz    BadCmd            ; on this line?
  253.  
  254. ; Okay, if it was a valid noun, see if that object is in the room so
  255. ; we can grab it.
  256.  
  257.         mov    di, CurRoom        ;See if present in room.
  258.         lea    di, [di].room.ItemList
  259.         call    CheckPresence
  260.         jc    GotTheItem
  261.         print
  262.         byte    "Sorry, that item is not available here.",cr,lf,0
  263.         jmp     RoomLoop
  264.  
  265. ; The user is only allowed to carry MaxWeight units of weight.  Be sure
  266. ; that picking up this object does not cause them to exceed this value.
  267.  
  268. GotTheItem:    mov    ax, [bx].item.Weight
  269.         add    ax, CurWeight
  270.         cmp    ax, MaxWeight
  271.         jbe    WeightOkay
  272.         print
  273.         byte    "Sorry, you cannot carry that much at one time."
  274.         byte    cr,lf,0
  275.         jmp    RoomLoop
  276.  
  277. ; Okay, if they can carry it, add it to their list of items.
  278.  
  279. WeightOkay:    mov    CurWeight, ax
  280.         call    RemoveItem
  281.         lea    di, ItemsOnHand
  282.         call    InsertItem
  283.         jmp    RoomLoop
  284.  
  285.  
  286.  
  287. ; Handle the "DROP noun" commands down here.
  288.  
  289. NoGet:        xor    cx, cx
  290.         ldxi    MatchDrop
  291.         match
  292.         jnc    NoDrop
  293.         call    NounToItem
  294.         test    bx, bx            ;See if a real item.
  295.         jz    BadCmd
  296.  
  297. ; If they've issued a valid drop command, make sure they own the item they
  298. ; wish to drop.
  299.  
  300.         lea    di, ItemsOnHand        ;See if we possess this item.
  301.         call    CheckPresence
  302.         jc    CanDropIt1
  303.         print
  304.         byte    "You do not currently hold that item.",cr,lf,0
  305.         jmp    RoomLoop
  306.  
  307. ; If this is the room into which the item goes, remove it from the game and
  308. ; decrement the TotalItem Counter.  If that counter goes to zero, we're done.
  309.  
  310. CanDropIt1:    mov    ax, [bx].item.Key
  311.         cmp    ax, CurRoom
  312.         jne    JustDropItHere
  313.         mov    di, [bx].item.WinDesc
  314.         puts
  315.         putcr
  316.         mov    ax, [bx].item.Value
  317.         add    CurScore, ax
  318.         mov    ax, [bx].item.Weight
  319.         sub    CurWeight, ax
  320.         lea    di, ItemsOnHand
  321.         call    RemoveItem
  322.         dec    TotalCounter
  323.         jz    AllDone
  324.         jmp    RoomLoop
  325.  
  326. AllDone:    printf
  327.         byte    "Well, you've found where everything goes and your "
  328.         byte    "score is %d",cr,lf
  329.         byte    "You might want to play again and see if you can get "
  330.         byte    "a better score",cr,lf,0
  331.         dword    CurScore
  332.         jmp    Quit
  333.  
  334. ; If this isn't the room where we're suppose to drop this thing off, just
  335. ; dump the object here so we can pick it up later.  Of course, there is the
  336. ; possibility that this particular room can't hold any more items (maximum
  337. ; of four items per room).  If it won't fit here, ignore the drop command.
  338.  
  339. JustDropItHere:    mov    di, CurRoom
  340.         lea    di, [di].room.ItemList
  341.         call    InsertItem
  342.         jc    DroppedItem
  343.         print
  344.         byte    "There is insufficient room to leave that item here."
  345.         byte    cr,lf,0
  346.         jmp    RoomLoop
  347.  
  348. ; If there is space in this room for the item, drop it off.
  349.  
  350. DroppedItem:    lea    di, ItemsOnHand
  351.         call    RemoveItem
  352.         mov    ax, [bx].item.weight
  353.         sub    CurWeight, ax
  354.         jmp    RoomLoop
  355.  
  356.  
  357. ; Check for the inventory command down here.
  358.  
  359. NoDrop:        xor    cx, cx
  360.         lea    di, InputLine
  361.         ldxi    MatchInv
  362.         match
  363.         jnc    NoInv
  364.         print
  365.         byte    "You currently have the following items in your "
  366.         byte    "possession:",cr,lf,0
  367.         mov    di, ItemsOnHand[0]
  368.         call    ShortDesc
  369.         mov    di, ItemsOnHand[2]
  370.         call    ShortDesc
  371.         mov    di, ItemsOnHand[4]
  372.         call    ShortDesc
  373.         mov    di, ItemsOnHand[6]
  374.         call    ShortDesc
  375.         printf
  376.         byte    "\nCurrent score: %d\n"
  377.         byte    "Carrying ability: %d/4\n\n",0
  378.         dword    CurScore,CurWeight
  379.         inc    CurScore        ;This command is free.
  380.         jmp    RoomLoop
  381.  
  382.  
  383.  
  384. ; Check for the QUIT game command here.
  385.  
  386. NoInv:        xor    cx, cx
  387.         lea    di, InputLine
  388.         ldxi    MatchQuit
  389.         match
  390.         jnc    NoQuit
  391.         printf
  392.         byte    "So long, your score is %d\n",0
  393.         dword    CurScore
  394.         jmp    Quit
  395.  
  396. ; Look for the HELP command here:
  397.  
  398. NoQuit:        xor    cx, cx
  399.         lea    di, InputLine
  400.         ldxi    MatchHelp
  401.         match
  402.         jnc    NoHelp
  403.         print
  404.         byte    "List of commands:",cr,lf,lf
  405.         byte    "GO {NORTH, EAST, WEST, SOUTH}",cr,lf
  406.         byte    "{GET, DROP} {LIME, BEER, CARD, SIGN, PROGRAM, "
  407.         byte    "HOMEWORK, MONEY, FORM, COUPON}",cr,lf
  408.         byte    "SHOW INVENTORY",cr,lf
  409.         byte    "QUIT GAME",cr,lf
  410.         byte    "HELP ME",cr,lf,lf
  411.         byte    "Each command costs you one point.",cr,lf
  412.         byte    "You accumulate points by picking up objects and "
  413.         byte    "dropping them in their",cr,lf
  414.         byte    "  appropriate locations.",cr,lf
  415.         byte    "If you drop an item in its proper location, it "
  416.         byte    "disappears from the game.",cr,lf
  417.         byte    "The game is over if your score drops to zero or "
  418.         byte    "you properly place",cr,lf
  419.         byte    "  all items.",cr,lf
  420.         byte    0
  421.         jmp    RoomLoop
  422.  
  423. NoHelp:
  424.  
  425. BadCmd:        print
  426.         byte    "Sorry, I don't know how to ",'"',0
  427.         puts
  428.         print
  429.         byte    '"',cr,lf,lf,0
  430.         jmp    RoomLoop
  431.  
  432.  
  433. Quit:        ExitPgm            ;DOS macro to quit program.
  434. Main        endp
  435. cseg        ends
  436.  
  437. sseg        segment    para stack 'stack'
  438. stk        db    1024 dup ("stack   ")
  439. sseg        ends
  440.  
  441. zzzzzzseg    segment    para public 'zzzzzz'
  442. LastBytes    db    16 dup (?)
  443. zzzzzzseg    ends
  444.         end    Main
  445.