IGNOREHORIZON                                         0:7AC8
    IGNOREOBJS                                            0:44B8
    IIO                                                   0:99C5
    IN                                                    0:5715
    INBLOCK                                               0:781A
    INCREMENT                                             0:6F96
    INDEX                                                 0:4CAF
    INIT                                                  0: F26
    INITEV                                                0:418C
    INITGRAPHICS                                          0:7DA0
    INITGRFX                                              0:9390
    INITJOY                                               0:5D7D
    INITLOG                                               0:10C0
    INITMACHINE                                           0:7D7B
    INITMEM                                               0:3EAF
    INITPIC                                               0:46E6
    INITPRI                                               0:52E1
    INITROWS                                              0:939F
    INITSCRIPT                                            0:6CBD
    INITSND                                               0:4D0E
    INITVIEW                                              0:3641
    INLINE                                              9BA: F58
    INPUTROW                                            9BA: 5D5
    INSERTOBJ                                             0:9946
    INVERTCHAR                                            0:2BB6
    INVSELECT                                             0:2EE6
    IP                                                  9BA: FAC
    IRSB                                                  0:9988
    ISDIR                                                 0:43CF
    ISFLAGSET                                             0:7143
    ISSB                                                  0:9949
    ISSET                                                 0:7125
    ISSTOPPEDOBJ                                          0:6646
    ISUPDOBJ                                              0:6625
    ITEMCOL                                             9BA:1D68
    ITEMROW                                             9BA:1D66
    ITOA                                                  0:4B1A
    ITOH                                                  0:4BAB
    JOYTIMER                                            9BA:1659
    JPREVDIR                                            9BA:1661
    JRB2S                                                 0:9485
    JRDW                                                  0:94ED
    JRGS                                                  0:9422
    JRIG                                                  0:93A5
    JRIRT                                                 0:9525
    JRSH                                                  0:9437
    JRTS                                                  0:93C9
    JX                                                  9BA:165D
    JY                                                  9BA:165F

Memory Map for AGI.EXE 10/07/87                                        Page 6  

    
    Name                                                  Addr  
    KBDHANDLER                                            0:5C76
    KEYDIR                                              9BA: 12F
    KEYMAP                                              9BA: 145
    LADDTOPIC                                             0:2BF9
    LANIMATEOBJ                                           0: 4B1
    LASTCEL                                               0:3A82
    LASTSPACE                                           9BA: D13
    LCLEARLINES                                           0:7355
    LCLEARRECT                                            0:7394
    LCLOSEDIALOGUE                                        0:362E
    LDISCARDPIC                                           0:48C3
    LDISCARDVIEW                                          0:3BB0
    LDRAW                                                 0: 9C2
    LEADINGZEROS                                          0:4B58
    LERASE                                                0: A67
    LESSF                                                 0: 834
    LESSN                                                 0: 823
    LGRAFSCRN                                             0:7343
    LINDIRECTF                                            0:701C
    LINDIRECTN                                            0:7035
    LINEPOS                                             9BA: D0F
    LINEWIDTH                                           9BA: D11
    LISTINBACK                                            0: 436
    LISTTOSCREEN                                          0: 460
    LLOADLOG                                              0:1115
    LLOADPIC                                              0:472F
    LLOADSND                                              0:4D5B
    LLOADVIEW                                             0:3694
    LMOVEOBJ                                              0:6925
    LNEWROOM                                              0:1734
    LNEWROOMF                                             0:174B
    LOADFILE                                              0:2DF6
    LOADLOG                                               0:1172
    LOADPIC                                               0:4754
    LOADSEG                                             9BA:1749
    LOADSND                                               0:4D77
    LOADVIEW                                              0:36DA
    LOADVIEWF                                             0:36B3
    LOG                                                   0:7E13
    LOGFILE                                             9BA:1863
    LOGFILENAME                                         9BA:1865
    LOGLIST                                             9BA: 96F
    LOGSEG                                                0:4107
    LONGJMP                                               0:7B23
    LOPENDIALOGUE                                         0:361C
    LOVERLAYPIC                                           0:4830
    LOWER                                                 0:4C3C
    LPICTURE                                              0:47C3
    LPRINTMSG                                             0:1BDC
    LRX                                                 9BA: 135
    LRY                                                 9BA: 137
    LSEEK                                                 0:59AA
    LSETCEL                                               0:3938
    LSETLOOP                                              0:382A
    LSETVIEW                                              0:375A
    LSTARTUPDATE                                          0:6731
    LSTOPSND                                              0:4E76
    LSTOPUPDATE                                           0:6709
    LTEXTSCRN                                             0:730B
    MACHTYPE                                            9BA:10E2

Memory Map for AGI.EXE 10/07/87                                        Page 7  

    
    Name                                                  Addr  
    MAIN                                                  0: 128
    MAKEBACKCOLOR                                         0:74EE
    MAKEFORECOLOR                                         0:74E2
    MAKELINE                                              0:1973
    MAKEOBJLIST                                           0: 330
    MAKESAVEFILENAME                                      0:57B2
    MAKESTOPPEDLIST                                       0:667E
    MAKETEXTATR                                           0:7444
    MAKEUPDLIST                                           0:6667
    MARK                                                9BA: A55
    MATCH                                                 0:1A41
    MAXDRAWN                                            9BA: 13F
    MAXLENGTH                                           9BA: D19
    MAXMEM                                              9BA: A53
    MAXPTR                                              9BA: A57
    MAXSCRIPT                                           9BA:17AB
    MEMBASE                                             9BA: A51
    MEMLEFT                                               0:1478
    MEMPTR                                              9BA: A4D
    MENUBASE                                            9BA:1D6C
    MENUCOL                                             9BA:1D64
    MENUDIM                                             9BA:1D74
    MENUINPUT                                             0:8F35
    MENUPOS                                             9BA:1D72
    MENUSUBMITTED                                       9BA:1D6A
    MIRRORCELL                                            0:54BC
    MONTYPE                                             9BA:10E4
    MOVEBYTE                                              0:5740
    MOVEDIR                                               0:16C5
    MOVEOBJF                                              0:69A2
    MOVEOBJS                                              0:14E2
    MOVESELECT                                            0:30DF
    MOVETO                                                0:164A
    MULN                                                  0:705F
    MULV                                                  0:7072
    MUSTGET                                               0:2DB1
    NEWDESCRIPT                                         9BA:1BEA
    NEWROOM                                               0:176A
    NEWSELECT                                             0:3147
    NEWVOL                                                0:2DDB
    NEXTEVENT                                             0:4212
    NEXTSCRIPT                                            0:6D8D
    NEXTTOKEN                                             0:1BBA
    NOACTION                                              0:4CA3
    NOFONTMSG                                           9BA: B75
    NOGAMESMSG                                          9BA:1C1C
    NOMEMMSG                                            9BA: B17
    NORMALCYCLE                                           0:67C3
    NORMALMOTION                                          0:6AE2
    NOTEST                                                0: 9B0
    NULLINTERRUPT                                         0:813E
    NUMBERLOOPS                                           0:3B78
    NUMFROMSTR                                            0:22EC
    NUMLINES                                            9BA: D17
    NUMWORDS                                            9BA: C9B
    OBJ2SCRN                                              0:53A1
    OBJDIR                                                0: 652
    OBJECT                                              9BA: 969
    OBJECTFILENAME                                      9BA: 961
    OBJEND                                              9BA: 96B

Memory Map for AGI.EXE 10/07/87                                        Page 8  

    
    Name                                                  Addr  
    OBJINBOX                                              0: 8C0
    OBJINPIC                                              0:540E
    OBJINRM                                               0: 913
    OBJLEN                                              9BA: 96D
    OBJPTR                                                0:724E
    OBJSTATUS                                             0:6EF6
    OBJVARPTR                                             0:72A4
    OBSERVEBLOCKS                                         0:77F5
    OBSERVEHORIZON                                        0:7AED
    OBSERVEOBJS                                           0:44E0
    OLDKBD                                              9BA:1881
    OLDVIDEO                                            9BA:1885
    ONANYTHING                                            0:7A8B
    ONLAND                                                0:7A66
    ONSTATUS                                            9BA:1657
    ONWATER                                               0:7A41
    OPEN                                                  0:590D
    OPENDIALOGUE                                          0:97E2
    OPENLOGFILE                                           0:7EC3
    OPENSCRIPT                                            0:6D70
    OPENWNDW                                              0:51E1
    OUT                                                   0:572A
    OVERLAYPIC                                            0:4854
    OVLOAD                                                0:6404
    PARSE                                                 0:1882
    PARSELINE                                           9BA: C9F
    PARSESTRING                                           0:192E
    PATRNMASKS                                          9BA:1DE8
    PAUSE                                                 0: 22F
    PAUSEMSG                                            9BA: C05
    PCB2S                                                 0:9545
    PCDW                                                  0:95A5
    PCGS                                                  0:94FB
    PCIG                                                  0:946B
    PCIRT                                                 0:9613
    PCJOYMSG                                            9BA:15E5
    PCSH                                                  0:9510
    PCTS                                                  0:94A9
    PCXC                                                  0:93A5
    PCXO                                                  0:93C7
    PICBOTTOM                                           9BA: 5DF
    PICLIST                                             9BA:12AC
    PICNO                                               9BA: 13B
    PICOBJ                                              9BA: E84
    PICPTR                                              9BA:1413
    PICRELOC                                            9BA:1415
    PICSEG                                                0:4149
    PICTOP                                              9BA: 5DD
    PICTURE                                               0:47E8
    PICVISIBLE                                          9BA:12B4
    PL                                                  9BA: CC9
    PLAYERCONTROL                                         0:6C82
    PLAYIT                                                0:7C2C
    PLAYNOTE                                              0:7CEA
    PLAYSND                                             9BA:12F4
    PLOTPOINT                                             0:4F4A
    POANIENTRY                                          9BA: E8A
    POINT                                                 0:6140
    POLLBUTTONS                                           0:5E9A
    POLLDEVICES                                           0:41B3

Memory Map for AGI.EXE 10/07/87                                        Page 9  

    
    Name                                                  Addr  
    POLLJOY                                               0:5E33
    POLLKBD                                               0:4398
    POPSCRIPT                                             0:6DDE
    POSITION                                              0:784E
    POSN                                                  0: 89E
    POSTEVENT                                             0:41C2
    PREPARESTRING                                         0: ED0
    PREVENTINPUT                                          0:3552
    PREVIOUSSCORE                                       9BA: 613
    PREVLINE                                            9BA: F82
    PREVLOG                                             9BA: 97B
    PREVPIC                                             9BA:12B2
    PREVSND                                             9BA:1304
    PREVVIEW                                            9BA: FB4
    PRI2COORD                                             0:49D4
    PRINT                                                 0:1F2A
    PRINTAT                                               0:1C6C
    PRINTF                                                0:2366
    PRINTMSGAT                                            0:1C2A
    PRIORITY                                            9BA:1408
    PRI_TBL                                             9BA:1316
    PROGRAMCONTROL                                        0:6C70
    PSPSEG                                              9BA:174D
    PUNCTUATION                                         9BA: 943
    PUSHSCRIPT                                            0:6DCC
    PUT                                                   0:71CD
    PUTAWAY                                               0:912D
    PUTCHAR                                               0:29A2
    PUTF                                                  0:71F8
    QUIT                                                  0: 286
    QUITGAME                                              0: 257
    QUITMSG                                             9BA: 5E3
    RANDMDIR                                              0:3C86
    RANDOM                                                0:6E01
    RANDSEED                                            9BA:17AD
    READ                                                  0:592E
    READBUTTONS                                           0:6066
    READJOY                                               0:5FFF
    READSAVE                                              0:265D
    RELEASELOOP                                           0:46BC
    RELEASEPRIORITY                                       0:76E4
    REPOSITION                                            0:791B
    REPOSITIONTO                                          0:79AB
    RESCANJMPBUF                                        9BA: 617
    RESET                                                 0:7111
    RESETALL                                              0: F7D
    RESETEV                                               0:419B
    RESETFLAG                                             0:70CC
    RESETINTERRUPTS                                       0:8023
    RESETIT                                               0:7135
    RESETLISTS                                            0:10A8
    RESETLOG                                              0:10CF
    RESETMACHINE                                          0:7DF9
    RESETPIC                                              0:46F5
    RESETSCANSTART                                        0:1322
    RESETSND                                              0:4D1D
    RESETVIEW                                             0:3650
    RESTART                                               0:2448
    RESTBACK                                              0:9943
    RESTMSG                                             9BA:1A20

Memory Map for AGI.EXE 10/07/87                                        Page 10 

    
    Name                                                  Addr  
    RESTORE                                               0:645D
    RESTOREALL                                            0:6695
    RESTORECURPOS                                         0:2ADF
    RESTOREGAME                                           0:24E8
    RESTOREOBJLIST                                        0: 2DF
    RESTORESCANOFS                                        0:137D
    RESTORETEXTATR                                        0:7604
    RETURNIFNOMEM                                       9BA: ECC
    REVERSE                                               0:4C01
    REVERSECYCLE                                          0:682C
    REVERSELOOP                                           0:6858
    RIGHTPOSN                                             0: 8B3
    RINDIRECT                                             0:7046
    ROOMTOTRACE                                         9BA:1D4C
    ROW_TABLE                                           9BA:1417
    RSTRTMSG                                            9BA: AD3
    SAID                                                  0: 934
    SAIDTEST                                            9BA:1D4E
    SAVEBACK                                              0:9940
    SAVECURPOS                                            0:2AB8
    SAVEDATR                                            9BA:17F5
    SAVEDCURPOS                                         9BA: E6A
    SAVEDESCRIPT                                        9BA:1CAC
    SAVEDINDEX                                          9BA:1813
    SAVEDRIVE                                           9BA:13FF
    SAVEDSCRIPT                                         9BA: 5E1
    SAVEEND                                             9BA: 5E3
    SAVEFILE                                            9BA:1CCC
    SAVEGAME                                              0:26FF
    SAVEMODE                                            9BA:1847
    SAVEMSG                                             9BA:19C2
    SAVEPATH                                            9BA:19A2
    SAVESTART                                           9BA:   2
    SAVETEXTATR                                           0:75CA
    SAVEVOL                                             9BA: BB7
    SCANLOG                                               0:28E8
    SCANOFS                                             9BA: 97D
    SCREENMODE                                          9BA:17F3
    SCRIPT                                              9BA:17A3
    SCRIPTENTRIES                                       9BA: 143
    SCRIPTOFF                                             0:6C9F
    SCRIPTON                                              0:6CAE
    SCRIPTPTR                                           9BA:17A7
    SCRIPTSIZE                                          9BA: 141
    SCRIPTTOP                                           9BA:17A5
    SCROLL                                                0:2B86
    SCROLLTRACE                                           0:8BF8
    SEGERR                                              9BA: ECA
    SEGLEN                                              9BA: ECE
    SELECT                                                0:9154
    SELECTRESTORE                                       9BA:1B6C
    SELECTSAVE                                          9BA:1AE8
    SEPSTR                                              9BA: C5F
    SET                                                   0:7107
    SETBASE                                               0:144E
    SETCEL                                                0:39AE
    SETCELF                                               0:396F
    SETCONTROL                                            0:4956
    SETCUR                                                0:2A9D
    SETCURSORCHAR                                         0:3597

Memory Map for AGI.EXE 10/07/87                                        Page 11 

    
    Name                                                  Addr  
    SETCYCLEFREQ                                          0:6895
    SETDISP                                               0:5179
    SETFLAG                                               0:70C5
    SETGAMEID                                             0: E56
    SETHORIZON                                            0:7AB0
    SETHORZ                                               0:9399
    SETINTERRUPTS                                         0:7F31
    SETIT                                                 0:712F
    SETJMP                                                0:7B14
    SETLOOP                                               0:389A
    SETLOOPF                                              0:385E
    SETMARK                                               0:1423
    SETMEMPTR                                             0:1414
    SETMENU                                               0:8CA1
    SETMENUITEM                                           0:8D53
    SETMODE                                               0:569D
    SETOBJDIR                                             0:6BFF
    SETPRIORITY                                           0:76B4
    SETSCANSTART                                          0:130D
    SETSCRIPTSIZE                                         0:6DAB
    SETSIMPLE                                             0:26D2
    SETSTEPSIZE                                           0:6B7F
    SETSTEPTIME                                           0:6BBD
    SETSTRING                                             0: D0F
    SETTEXTATR                                            0:73F0
    SETUPPERLEFT                                          0:492E
    SETUPSCANOFS                                          0:133C
    SETVIEW                                               0:37CA
    SETVIEWF                                              0:378E
    SHAKESCREEN                                           0:7641
    SHOWMEM                                               0:1495
    SHOWMENU                                              0:90DB
    SHOWOBJ                                               0:5AFE
    SHOWPIC                                               0:489B
    SHOWPRI                                             9BA:17F1
    SHOWPRISCREEN                                         0:6F5C
    SHOWSTATUS                                          9BA: 5D9
    SIMPLENAME                                          9BA: E48
    SKIPIF                                                0:2976
    SKIPOR                                                0:2950
    SNDENDFLAG                                          9BA:1306
    SNDLIST                                             9BA:12F6
    SNDSEG                                                0:416A
    SOUND                                                 0:4E24
    SOUNDOFF                                              0:7CB9
    SPRINTF                                               0:234A
    STACKBASE                                           9BA:   0
    START                                                 0:  78
    STARTC                                              9BA:15A7
    STARTCYCLING                                          0:68FD
    STARTMOTION                                           0:6B46
    STARTSOUND                                            0:7BCA
    STARTUPDATE                                           0:67A3
    STARTWANDER                                           0:6AA9
    START_COORDS                                        9BA:15A7
    STATUS                                                0:2EBB
    STATUSLINEOFF                                         0:323F
    STATUSLINEON                                          0:322A
    STATUSROW                                           9BA: 5DB
    STATUSSCREEN                                          0:3029

Memory Map for AGI.EXE 10/07/87                                        Page 12 

    
    Name                                                  Addr  
    STOLOWER                                              0:4CE0
    STOPCYCLING                                           0:68D8
    STOPMOTION                                            0:6B09
    STOPPEDLIST                                         9BA:179F
    STOPSND                                               0:4E85
    STOPUPDATE                                            0:6785
    STRCAT                                                0:4A79
    STRCMP                                                0:4AB5
    STRCPY                                                0:4A06
    STRLEN                                                0:49EB
    STRNCPY                                               0:4A3A
    SUBF                                                  0:7009
    SUBMITMENU                                            0:8E3E
    SUBN                                                  0:6FFC
    SWAPDISKMSG                                         9BA:1A86
    SYSTIMER                                            9BA: 129
    S_RAM                                               9BA:140B
    TANDYDIR                                            9BA:1773
    TESTFLAG                                              0: 873
    TESTTBL                                             9BA: 8F5
    TEXTATR                                             9BA: 5D1
    TEXTSCRN                                              0:9393
    TEXTWIN                                             9BA: D1F
    THRZ_POS                                            9BA:1402
    TIMERDISPATCH                                         0:80D0
    TIMERINT                                              0:7B30
    TIMERINTHANDLER                                       0:80A5
    TOGGLE                                                0:711B
    TOGGLEFLAG                                            0:70D3
    TOGGLEIT                                              0:713D
    TOGGLEMONITOR                                         0:758D
    TRACEACTION                                           0:8927
    TRACEDIVIDER                                        9BA:1D60
    TRACEINFO                                             0:88C1
    TRACEIT                                               0:898F
    TRACELOGS                                           9BA:1D52
    TRACEOFF                                              0:88FD
    TRACEON                                               0:8815
    TRACEPARMS                                            0:8AAD
    TRACESTATUS                                         9BA:1D50
    TRACETEST                                             0:894D
    TRANSLATE                                             0:427F
    TRWINDOWPOS                                         9BA:1D48
    TRWINDOWSIZE                                        9BA:1D4A
    TRYAGAIN                                            9BA:10A6
    TWBOTTOMROW                                         9BA:1D58
    TWDIM                                               9BA:1D5E
    TWLEFTCOL                                           9BA:1D56
    TWODRIVE                                            9BA:10DC
    TWPOS                                               9BA:1D5C
    TWRIGHTCOL                                          9BA:1D5A
    TWTOPROW                                            9BA:1D54
    ULX                                                 9BA: 131
    ULY                                                 9BA: 133
    UNANIMATEALL                                          0: 515
    UNBLOCK                                               0:77BE
    UNLINK                                                0:5974
    UPDATELINESTATS                                       0:2324
    UPDATELIST                                          9BA:179B
    USERCTRL                                            9BA: 139

Memory Map for AGI.EXE 10/07/87                                        Page 13 

    
    Name                                                  Addr  
    USERIN                                                0:325F
    USERSTR                                             9BA: 20D
    VALIDDRIVE                                            0:5A7D
    VALIDPATH                                             0:581C
    VAR                                                 9BA:   9
    VDISCARDVIEW                                          0:3BCC
    VERIFYGAMEID                                          0:5788
    VERSION                                               0:6F7D
    VERSIONMSG                                          9BA: AA3
    VGB2S                                                 0:9416
    VGDW                                                  0:9469
    VGGS                                                  0:9400
    VGIG                                                  0:93A5
    VGIRT                                                 0:9494
    VGSH                                                  0:94A6
    VGTS                                                  0:93C7
    VIEWLIST                                            9BA: FAE
    VIEWSEG                                               0:4128
    VOLMSG                                              9BA: B8F
    VREPOSITIONTO                                         0:79EE
    VRESETFLAG                                            0:70E9
    VSETFLAG                                              0:70DA
    VSHOWOBJ                                              0:5ADA
    VTESTFLAG                                             0: 878
    VTOGGLEFLAG                                           0:70F8
    V_RAM                                               9BA:140D
    WAITACAB                                              0:4331
    WAITCHAR                                              0:42F0
    WAITEVENT                                             0:4242
    WAITTOANIMATE                                         0:7BAC
    WANDER                                                0:3C3D
    WHICHMACHINE                                          0:3DC8
    WINBOT                                              9BA: D09
    WINCOL                                              9BA: E68
    WINDOWDIM                                           9BA: D1D
    WINDOWNOWAIT                                          0:1D6C
    WINDOWPOS                                           9BA: D1B
    WINDOWPRINT                                           0:1CBE
    WINDOWUP                                            9BA: D15
    WINULCOL                                            9BA: D05
    WINULROW                                            9BA: D03
    WINWIDTH                                            9BA: D01
    WORDFILENAME                                        9BA: 95F
    WORDPTR                                             9BA: C87
    WORDS                                               9BA: C73
    WORDTBL                                             9BA: C9D
    WORDTOSTRING                                          0: D48
    WRITE                                                 0:5951
    WRITECUR                                              0:34DA
    WRITEPOINTER                                          0:87D2
    WRITESAVE                                             0:2872
    WRONGMSG                                            9BA: BEB
    WRONGVOL                                              0:2DE4
    XLATCOLOR                                             0:52C4
    XLATOBJC                                              0:555E
    XTB2S                                                 0:9415
    XTDW                                                  0:949C
    XTGS                                                  0:93FF
    XTIG                                                  0:93A5
    XTIRT                                                 0:9519

Memory Map for AGI.EXE 10/07/87                                        Page 14 

    
    Name                                                  Addr  
    XTSH                                                  0:9414
    XTSS                                                  0:954E
    XTTS                                                  0:93C5
    _CALLLOGIC                                            0:1286
    _DRAWBRUSH                                            0:616B
    _LLOADLOG                                             0:1155
    _PRINT                                                0:1F69
    _SETCEL                                               0:3A4D
    _SETLOOP                                              0:38FE
    _SETTEXTATR                                           0:7416
    _SHOWOBJ                                              0:5B1A
    _TRACEON                                              0:8832

Segments:

    Section ROOT:  Maddr=0, Msize=9390, Daddr=200, Lev=0, Ovly#=0
        
        Name                                                Addr   Size
        BASE.CODE                                              0     78
        CODE.CODE                                             78   920B
        $OVTB$.                                             9290     F3

    Section GRAPHICS:  Maddr=9390, Msize=2B0, Daddr=0, Lev=1, Ovly#=1
        CODE.CODE                                           9390     15
        CODE.CODE                                           93A5    297

    Section GRAPHICS:  Maddr=9390, Msize=1E0, Daddr=0, Lev=1, Ovly#=2
        CODE.CODE                                           9390     15
        CODE.CODE                                           93A5    1BC

    Section GRAPHICS:  Maddr=9390, Msize=260, Daddr=0, Lev=1, Ovly#=3
        CODE.CODE                                           9390     15
        CODE.CODE                                           93A5    240

    Section GRAPHICS:  Maddr=9390, Msize=5B0, Daddr=0, Lev=1, Ovly#=4
        CODE.CODE                                           9390     15
        CODE.CODE                                           93A5    43D
        CODE.CODE                                           97E2    154

    Section GRAPHICS:  Maddr=9390, Msize=120, Daddr=0, Lev=1, Ovly#=5
        CODE.CODE                                           9390     15
        CODE.CODE                                           93A5    102

    Section OBJECTS:  Maddr=9940, Msize=160, Daddr=0, Lev=1, Ovly#=6
        CODE.CODE                                           9940      9
        CODE.CODE                                           9949    14C

    Section OBJECTS:  Maddr=9940, Msize=260, Daddr=0, Lev=1, Ovly#=7
        CODE.CODE                                           9940      9
        CODE.CODE                                           9949    24E

    Section DATA:  Maddr=9BA0, Msize=1F10, Daddr=0, Lev=0, Ovly#=8, Pre-Loaded
        DATA.DATA                                           9BA0   1E82
        STACK.STACK                                         BA30     80
        CONST.CONST                                         BAB0      0
        MEMORY.MEMORY                                       BAB0      0



Memory Map for AGI.EXE 10/07/87                                        Page 15 

Common Blocks:

        $OVTB$., Addr = 9290, Size = F3
        MEMORY.MEMORY, Addr = BAB0, Size = 0
        STACK.STACK, Addr = BA30, Size = 80

Modules:

    Module A from file START
        Segment BASE.CODE, Addr = 0, Size = 78
        Segment CODE.CODE, Addr = 78, Size = B0
            $STRT$                                                0:  78
            EXIT                                                  0:  AE
            GETARGS                                               0:  C4
            START                                                 0:  78
        Segment DATA.DATA, Addr = 9BA0, Size = 2
            STACKBASE                                           9BA:   0

    Module A from file SAVEVARS
        Segment DATA.DATA, Addr = 9BA2, Size = 5E1
            BACKCOLOR                                           9BA: 5CF
            BLOCKING                                            9BA: 13D
            CURCHAR                                             9BA: 5D7
            FLAG                                                9BA: 109
            FORECOLOR                                           9BA: 5CD
            GAMEID                                              9BA:   2
            GETINPUT                                            9BA: 5D3
            HORIZON                                             9BA: 12D
            INPUTROW                                            9BA: 5D5
            KEYDIR                                              9BA: 12F
            KEYMAP                                              9BA: 145
            LRX                                                 9BA: 135
            LRY                                                 9BA: 137
            MAXDRAWN                                            9BA: 13F
            PICBOTTOM                                           9BA: 5DF
            PICNO                                               9BA: 13B
            PICTOP                                              9BA: 5DD
            SAVEDSCRIPT                                         9BA: 5E1
            SAVEEND                                             9BA: 5E3
            SAVESTART                                           9BA:   2
            SCRIPTENTRIES                                       9BA: 143
            SCRIPTSIZE                                          9BA: 141
            SHOWSTATUS                                          9BA: 5D9
            STATUSROW                                           9BA: 5DB
            SYSTIMER                                            9BA: 129
            TEXTATR                                             9BA: 5D1
            ULX                                                 9BA: 131
            ULY                                                 9BA: 133
            USERCTRL                                            9BA: 139
            USERSTR                                             9BA: 20D
            VAR                                                 9BA:   9

    Module MAIN from file MAIN
        Segment CODE.CODE, Addr = 128, Size = 174
            MAIN                                                  0: 128
            PAUSE                                                 0: 22F
            QUIT                                                  0: 286
            QUITGAME                                              0: 257
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A183, Size = 3A
            GAMEPAUSED                                          9BA: 615
            PREVIOUSSCORE                                       9BA: 613

Memory Map for AGI.EXE 10/07/87                                        Page 16 

            QUITMSG                                             9BA: 5E3
            RESCANJMPBUF                                        9BA: 617

    Module A from file ACTION
        Segment CODE.CODE, Addr = 29C, Size = 43
            ACTION                                                0: 29C
        Segment DATA.DATA, Addr = A1BD, Size = 2B8
            ACTIONTBL                                           9BA: 61D

    Module OBJLIST from file OBJLIST
        Segment CODE.CODE, Addr = 2DF, Size = 1D2
            ADDOBJTOLIST                                          0: 407
            FREEOBJLIST                                           0: 305
            LISTINBACK                                            0: 436
            LISTTOSCREEN                                          0: 460
            MAKEOBJLIST                                           0: 330
            RESTOREOBJLIST                                        0: 2DF
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A475, Size = 0

    Module ANIMATE from file ANIMATE
        Segment CODE.CODE, Addr = 4B1, Size = 2D2
            ANIMATE                                               0: 53B
            ANIMATEOBJ                                            0: 4CD
            CHKBLOCK                                              0: 6B1
            GETOBJDIRS                                            0: 61C
            LANIMATEOBJ                                           0: 4B1
            OBJDIR                                                0: 652
            UNANIMATEALL                                          0: 515
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A475, Size = 14

    Module ENCRYPT from file ENCRYPT
        Segment CODE.CODE, Addr = 783, Size = 38
            ENCRYPT                                               0: 783
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A489, Size = C
            CRYPTKEY                                            9BA: 8E9

    Module A from file DOTEST
        Segment CODE.CODE, Addr = 7BB, Size = 207
            CENTERPOSN                                            0: 8A4
            CMPSTRINGS                                            0: 9B3
            CONTROLLERSET                                         0: 909
            DOTEST                                                0: 7BB
            EQUALF                                                0: 80C
            EQUALN                                                0: 7FB
            GREATERF                                              0: 85C
            GREATERN                                              0: 84B
            HAS                                                   0: 885
            HAVEKEY                                               0: 996
            LESSF                                                 0: 834
            LESSN                                                 0: 823
            NOTEST                                                0: 9B0
            OBJINBOX                                              0: 8C0
            OBJINRM                                               0: 913
            POSN                                                  0: 89E
            RIGHTPOSN                                             0: 8B3
            SAID                                                  0: 934
            TESTFLAG                                              0: 873
            VTESTFLAG                                             0: 878
        Segment DATA.DATA, Addr = A495, Size = 4E

Memory Map for AGI.EXE 10/07/87                                        Page 17 

            TESTTBL                                             9BA: 8F5

    Module DRAW from file DRAW
        Segment CODE.CODE, Addr = 9C2, Size = 14C
            DRAWOBJ                                               0: 9DE
            ERASE                                                 0: A83
            LDRAW                                                 0: 9C2
            LERASE                                                0: A67
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A4E3, Size = 0

    Module FOLLOW from file FOLLOW
        Segment CODE.CODE, Addr = B0E, Size = 10E
            FOLLOW                                                0: B0E
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A4E3, Size = 0

    Module STRING from file STRING
        Segment CODE.CODE, Addr = C1C, Size = 30A
            COMPARESTRINGS                                        0: E84
            GETLINE                                               0: D81
            GETSTRING                                             0: C1C
            PREPARESTRING                                         0: ED0
            SETGAMEID                                             0: E56
            SETSTRING                                             0: D0F
            WORDTOSTRING                                          0: D48
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A4E3, Size = A
            PUNCTUATION                                         9BA: 943

    Module INIT from file INIT
        Segment CODE.CODE, Addr = F26, Size = 19A
            INIT                                                  0: F26
            RESETALL                                              0: F7D
            RESETLISTS                                            0:10A8
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A4ED, Size = 22
            ANIEND                                              9BA: 965
            ANILEN                                              9BA: 967
            ANIOBJ                                              9BA: 963
            OBJECT                                              9BA: 969
            OBJECTFILENAME                                      9BA: 961
            OBJEND                                              9BA: 96B
            OBJLEN                                              9BA: 96D
            WORDFILENAME                                        9BA: 95F

    Module LOGIC from file LOGIC
        Segment CODE.CODE, Addr = 10C0, Size = 2EE
            CALLLOGIC                                             0:1232
            CALLLOGICF                                            0:1258
            FINDLOG                                               0:10E7
            FLOADLOG                                              0:1131
            INITLOG                                               0:10C0
            LLOADLOG                                              0:1115
            LOADLOG                                               0:1172
            RESETLOG                                              0:10CF
            RESETSCANSTART                                        0:1322
            RESTORESCANOFS                                        0:137D
            SETSCANSTART                                          0:130D
            SETUPSCANOFS                                          0:133C
            _CALLLOGIC                                            0:1286
            _LLOADLOG                                             0:1155

Memory Map for AGI.EXE 10/07/87                                        Page 18 

        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A50F, Size = 86
            CURLOG                                              9BA: 979
            LOGLIST                                             9BA: 96F
            PREVLOG                                             9BA: 97B
            SCANOFS                                             9BA: 97D

    Module MEMMGR from file MEMMGR
        Segment CODE.CODE, Addr = 13AE, Size = 134
            FREEALL                                               0:145D
            FREEMARK                                              0:1432
            GETMEM                                                0:13AE
            GETMEMPTR                                             0:1408
            MEMLEFT                                               0:1478
            SETBASE                                               0:144E
            SETMARK                                               0:1423
            SETMEMPTR                                             0:1414
            SHOWMEM                                               0:1495
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A595, Size = 64
            HEAPBASE                                            9BA: A4F
            MARK                                                9BA: A55
            MAXMEM                                              9BA: A53
            MAXPTR                                              9BA: A57
            MEMBASE                                             9BA: A51
            MEMPTR                                              9BA: A4D

    Module MOVEOBJS from file MOVEOBJS
        Segment CODE.CODE, Addr = 14E2, Size = 168
            MOVEOBJS                                              0:14E2
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A5F9, Size = 24

    Module MOVETO from file MOVETO
        Segment CODE.CODE, Addr = 164A, Size = EA
            DIRINDEX                                              0:1705
            ENDMOVEOBJ                                            0:1691
            MOVEDIR                                               0:16C5
            MOVETO                                                0:164A
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A61D, Size = 12

    Module MSGSTR from file MSGSTR
        Segment CODE.CODE, Addr = 1734, Size = 0
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A62F, Size = 1D0
            CONTCANCELMSG                                       9BA: C31
            ESCQUITMSG                                          9BA: A8F
            NOFONTMSG                                           9BA: B75
            NOMEMMSG                                            9BA: B17
            PAUSEMSG                                            9BA: C05
            RSTRTMSG                                            9BA: AD3
            SAVEVOL                                             9BA: BB7
            VERSIONMSG                                          9BA: AA3
            VOLMSG                                              9BA: B8F
            WRONGMSG                                            9BA: BEB

    Module NEWROOM from file NEWROOM
        Segment CODE.CODE, Addr = 1734, Size = 14E
            LNEWROOM                                              0:1734
            LNEWROOMF                                             0:174B
            NEWROOM                                               0:176A

Memory Map for AGI.EXE 10/07/87                                        Page 19 

        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A7FF, Size = 0

    Module PARSE from file PARSE
        Segment CODE.CODE, Addr = 1882, Size = 35A
            BADWORD                                               0:1B9D
            MAKELINE                                              0:1973
            MATCH                                                 0:1A41
            NEXTTOKEN                                             0:1BBA
            PARSE                                                 0:1882
            PARSESTRING                                           0:192E
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A7FF, Size = 6C
            DELSTR                                              9BA: C6D
            NUMWORDS                                            9BA: C9B
            PARSELINE                                           9BA: C9F
            PL                                                  9BA: CC9
            SEPSTR                                              9BA: C5F
            WORDPTR                                             9BA: C87
            WORDS                                               9BA: C73
            WORDTBL                                             9BA: C9D

    Module PRINT from file PRINT
        Segment CODE.CODE, Addr = 1BDC, Size = 76E
            CLOSEWINDOW                                           0:1F01
            DISPLAY                                               0:2226
            DISPLAYF                                              0:227D
            FPRINTMSG                                             0:1BFF
            FPRINTMSGAT                                           0:1C47
            GETMSGPTR                                             0:21C6
            LPRINTMSG                                             0:1BDC
            NUMFROMSTR                                            0:22EC
            PRINT                                                 0:1F2A
            PRINTAT                                               0:1C6C
            PRINTMSGAT                                            0:1C2A
            UPDATELINESTATS                                       0:2324
            WINDOWNOWAIT                                          0:1D6C
            WINDOWPRINT                                           0:1CBE
            _PRINT                                                0:1F69
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A86B, Size = 5C
            CHARHEIGHT                                          9BA: D0B
            DIALOGUEOPEN                                        9BA: D07
            ESCAPECHAR                                          9BA: D0D
            LASTSPACE                                           9BA: D13
            LINEPOS                                             9BA: D0F
            LINEWIDTH                                           9BA: D11
            MAXLENGTH                                           9BA: D19
            NUMLINES                                            9BA: D17
            TEXTWIN                                             9BA: D1F
            WINBOT                                              9BA: D09
            WINDOWDIM                                           9BA: D1D
            WINDOWPOS                                           9BA: D1B
            WINDOWUP                                            9BA: D15
            WINULCOL                                            9BA: D05
            WINULROW                                            9BA: D03
            WINWIDTH                                            9BA: D01

    Module A from file PRINTF
        Segment CODE.CODE, Addr = 234A, Size = FE
            PRINTF                                                0:2366
            SPRINTF                                               0:234A

Memory Map for AGI.EXE 10/07/87                                        Page 20 

        Segment DATA.DATA, Addr = A8C7, Size = 5

    Module RESTART from file RESTART
        Segment CODE.CODE, Addr = 2448, Size = A0
            RESTART                                               0:2448
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A8CC, Size = 0

    Module RESTGAME from file RESTGAME
        Segment CODE.CODE, Addr = 24E8, Size = 1EA
            READSAVE                                              0:265D
            RESTOREGAME                                           0:24E8
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A8CC, Size = 82

    Module SAVEGAME from file SAVEGAME
        Segment CODE.CODE, Addr = 26D2, Size = 216
            SAVEGAME                                              0:26FF
            SETSIMPLE                                             0:26D2
            WRITESAVE                                             0:2872
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = A94E, Size = BA
            SIMPLENAME                                          9BA: E48

    Module A from file SCANLOG
        Segment CODE.CODE, Addr = 28E8, Size = BA
            CONDTEST                                              0:2918
            SCANLOG                                               0:28E8
            SKIPIF                                                0:2976
            SKIPOR                                                0:2950
        Segment DATA.DATA, Addr = AA08, Size = 0

    Module A from file SCROUT
        Segment CODE.CODE, Addr = 29A2, Size = 257
            CLEARLINE                                             0:2B36
            CLEARRECT                                             0:2B54
            CLRLINES                                              0:2B08
            HALFTONECHAR                                          0:2BC5
            INVERTCHAR                                            0:2BB6
            PUTCHAR                                               0:29A2
            RESTORECURPOS                                         0:2ADF
            SAVECURPOS                                            0:2AB8
            SCROLL                                                0:2B86
            SETCUR                                                0:2A9D
        Segment DATA.DATA, Addr = AA08, Size = 1C
            EXTRACHAR                                           9BA: E7C
            HALFTONE                                            9BA: E7A
            SAVEDCURPOS                                         9BA: E6A
            WINCOL                                              9BA: E68

    Module PICOBJ from file PICOBJ
        Segment CODE.CODE, Addr = 2BF9, Size = 1B8
            ADDTOPIC                                              0:2CD1
            ADDTOPICF                                             0:2C49
            LADDTOPIC                                             0:2BF9
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AA24, Size = 32
            PICOBJ                                              9BA: E84
            POANIENTRY                                          9BA: E8A

    Module SEGMENT from file SEGMENT
        Segment CODE.CODE, Addr = 2DB1, Size = 10A

Memory Map for AGI.EXE 10/07/87                                        Page 21 

            CLOSEALLVOLS                                          0:2DED
            GETSEG                                                0:2DC6
            LOADFILE                                              0:2DF6
            MUSTGET                                               0:2DB1
            NEWVOL                                                0:2DDB
            WRONGVOL                                              0:2DE4
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AA56, Size = 1C
            CURRENTDISK                                         9BA: ED0
            RETURNIFNOMEM                                       9BA: ECC
            SEGERR                                              9BA: ECA
            SEGLEN                                              9BA: ECE

    Module STATUS from file STATUS
        Segment CODE.CODE, Addr = 2EBB, Size = 3A4
            DISPLAYSTATUSLINE                                     0:31A0
            INVSELECT                                             0:2EE6
            MOVESELECT                                            0:30DF
            NEWSELECT                                             0:3147
            STATUS                                                0:2EBB
            STATUSLINEOFF                                         0:323F
            STATUSLINEON                                          0:322A
            STATUSSCREEN                                          0:3029
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AA72, Size = 84

    Module USERIN from file USERIN
        Segment CODE.CODE, Addr = 325F, Size = 3E2
            ACCEPTINPUT                                           0:357B
            CANCELLINE                                            0:3409
            CURSORSTATE                                           0:3546
            DISPLAYINPUT                                          0:35BA
            ECHO                                                  0:3488
            ECHOLINE                                              0:3436
            EDITLINE                                              0:3335
            ERASECUR                                              0:3511
            LCLOSEDIALOGUE                                        0:362E
            LOPENDIALOGUE                                         0:361C
            PREVENTINPUT                                          0:3552
            SETCURSORCHAR                                         0:3597
            USERIN                                                0:325F
            WRITECUR                                              0:34DA
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AAF6, Size = 58
            INLINE                                              9BA: F58
            IP                                                  9BA: FAC
            PREVLINE                                            9BA: F82

    Module VIEW from file VIEW
        Segment CODE.CODE, Addr = 3641, Size = 5FC
            CURRENTCEL                                            0:3AD0
            CURRENTLOOP                                           0:3B08
            CURRENTVIEW                                           0:3B40
            DISCARDVIEW                                           0:3BF0
            FINDVIEW                                              0:365C
            INITVIEW                                              0:3641
            LASTCEL                                               0:3A82
            LDISCARDVIEW                                          0:3BB0
            LLOADVIEW                                             0:3694
            LOADVIEW                                              0:36DA
            LOADVIEWF                                             0:36B3
            LSETCEL                                               0:3938

Memory Map for AGI.EXE 10/07/87                                        Page 22 

            LSETLOOP                                              0:382A
            LSETVIEW                                              0:375A
            NUMBERLOOPS                                           0:3B78
            RESETVIEW                                             0:3650
            SETCEL                                                0:39AE
            SETCELF                                               0:396F
            SETLOOP                                               0:389A
            SETLOOPF                                              0:385E
            SETVIEW                                               0:37CA
            SETVIEWF                                              0:378E
            VDISCARDVIEW                                          0:3BCC
            _SETCEL                                               0:3A4D
            _SETLOOP                                              0:38FE
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AB4E, Size = 8
            PREVVIEW                                            9BA: FB4
            VIEWLIST                                            9BA: FAE

    Module WANDER from file WANDER
        Segment CODE.CODE, Addr = 3C3D, Size = 62
            RANDMDIR                                              0:3C86
            WANDER                                                0:3C3D
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AB56, Size = 0

    Module A from file BEEP
        Segment CODE.CODE, Addr = 3C9F, Size = 2C
            BEEP                                                  0:3C9F
            ERRBEEP                                               0:3CA8

    Module ERROR from file ERROR
        Segment CODE.CODE, Addr = 3CCB, Size = CA
            DISKERROR                                             0:3D00
            ERROR                                                 0:3CCB
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AB56, Size = 126
            DISKERR                                             9BA:10C2
            TRYAGAIN                                            9BA:10A6

    Module A from file EQUIPCHK
        Segment CODE.CODE, Addr = 3D95, Size = 259
            EQUIPCHK                                              0:3D95
            INITMEM                                               0:3EAF
            WHICHMACHINE                                          0:3DC8
        Segment DATA.DATA, Addr = AC7C, Size = 18
            MACHTYPE                                            9BA:10E2
            MONTYPE                                             9BA:10E4
            TWODRIVE                                            9BA:10DC

    Module SEGPTR from file SEGPTR
        Segment CODE.CODE, Addr = 3FEE, Size = 19E
            GETDIRS                                               0:3FEE
            GETSTR                                                0:40D6
            LOGSEG                                                0:4107
            PICSEG                                                0:4149
            SNDSEG                                                0:416A
            VIEWSEG                                               0:4128
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AC94, Size = 164

    Module EVENT from file EVENT
        Segment CODE.CODE, Addr = 418C, Size = 1FC

Memory Map for AGI.EXE 10/07/87                                        Page 23 

            BUTTONTOCHAR                                          0:434D
            CHKACAB                                               0:4309
            GETKEY                                                0:42B7
            INITEV                                                0:418C
            NEXTEVENT                                             0:4212
            POLLDEVICES                                           0:41B3
            POSTEVENT                                             0:41C2
            RESETEV                                               0:419B
            TRANSLATE                                             0:427F
            WAITACAB                                              0:4331
            WAITCHAR                                              0:42F0
            WAITEVENT                                             0:4242
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = ADF8, Size = 54
            EBHEAD                                              9BA:12A8
            EBTAIL                                              9BA:12AA

    Module KBDDRV from file KBDDRV
        Segment CODE.CODE, Addr = 4388, Size = AA
            DIRTRANSLATE                                          0:4401
            FLUSHKBD                                              0:4388
            ISDIR                                                 0:43CF
            POLLKBD                                               0:4398
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AE4C, Size = 0

    Module COLLIDE from file COLLIDE
        Segment CODE.CODE, Addr = 4432, Size = 19A
            COLLIDE                                               0:4432
            DISTANCE                                              0:4508
            IGNOREOBJS                                            0:44B8
            OBSERVEOBJS                                           0:44E0
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AE4C, Size = 0

    Module ADVANCEL from file ADVANCEL
        Segment CODE.CODE, Addr = 45CC, Size = 11A
            ADVANCECEL                                            0:45CC
            FIXLOOP                                               0:4694
            RELEASELOOP                                           0:46BC
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AE4C, Size = 0

    Module PICTURE from file PICTURE
        Segment CODE.CODE, Addr = 46E6, Size = 256
            DISCARDPIC                                            0:48E7
            FINDPIC                                               0:4701
            INITPIC                                               0:46E6
            LDISCARDPIC                                           0:48C3
            LLOADPIC                                              0:472F
            LOADPIC                                               0:4754
            LOVERLAYPIC                                           0:4830
            LPICTURE                                              0:47C3
            OVERLAYPIC                                            0:4854
            PICTURE                                               0:47E8
            RESETPIC                                              0:46F5
            SETUPPERLEFT                                          0:492E
            SHOWPIC                                               0:489B
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AE4C, Size = A
            PICLIST                                             9BA:12AC
            PICVISIBLE                                          9BA:12B4

Memory Map for AGI.EXE 10/07/87                                        Page 24 

            PREVPIC                                             9BA:12B2

    Module CONTROL from file CONTROL
        Segment CODE.CODE, Addr = 493C, Size = 80
            CLEARCONTROL                                          0:493C
            SETCONTROL                                            0:4956
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AE56, Size = 32
            CONTROLLER                                          9BA:12B6

    Module ETC from file ETC
        Segment CODE.CODE, Addr = 49BC, Size = 352
            ABS                                                   0:49BC
            ATOI                                                  0:4ADF
            GETRANDOM                                             0:4C5B
            INDEX                                                 0:4CAF
            ITOA                                                  0:4B1A
            ITOH                                                  0:4BAB
            LEADINGZEROS                                          0:4B58
            LOWER                                                 0:4C3C
            NOACTION                                              0:4CA3
            PRI2COORD                                             0:49D4
            REVERSE                                               0:4C01
            STOLOWER                                              0:4CE0
            STRCAT                                                0:4A79
            STRCMP                                                0:4AB5
            STRCPY                                                0:4A06
            STRLEN                                                0:49EB
            STRNCPY                                               0:4A3A
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AE88, Size = C

    Module SOUND from file SOUND
        Segment CODE.CODE, Addr = 4D0E, Size = 19A
            FINDSND                                               0:4D29
            INITSND                                               0:4D0E
            LLOADSND                                              0:4D5B
            LOADSND                                               0:4D77
            LSTOPSND                                              0:4E76
            RESETSND                                              0:4D1D
            SOUND                                                 0:4E24
            STOPSND                                               0:4E85
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AE94, Size = 14
            PLAYSND                                             9BA:12F4
            PREVSND                                             9BA:1304
            SNDENDFLAG                                          9BA:1306
            SNDLIST                                             9BA:12F6

    Module A from file CMGRAPHX
        Segment CODE.CODE, Addr = 4EA8, Size = 439
            BACKTOSCRN                                            0:5197
            CLOSEWNDW                                             0:525D
            CLRSHDWRAM                                            0:4EA8
            COLORFILL                                             0:4F8C
            DRWHLINE                                              0:4EC0
            DRWVLINE                                              0:4EFC
            GETSHDWOFST                                           0:52A5
            GETVIDOFST                                            0:5275
            OPENWNDW                                              0:51E1
            PLOTPOINT                                             0:4F4A
            SETDISP                                               0:5179

Memory Map for AGI.EXE 10/07/87                                        Page 25 

            XLATCOLOR                                             0:52C4
        Segment DATA.DATA, Addr = AEA8, Size = E

    Module A from file CMOBJSBR
        Segment CODE.CODE, Addr = 52E1, Size = 298
            CANBHERE                                              0:52F7
            INITPRI                                               0:52E1
            MIRRORCELL                                            0:54BC
            OBJ2SCRN                                              0:53A1
            OBJINPIC                                              0:540E
            XLATOBJC                                              0:555E
        Segment DATA.DATA, Addr = AEB6, Size = A8
            PRI_TBL                                             9BA:1316

    Module FINDPOSN from file FINDPOSN
        Segment CODE.CODE, Addr = 5579, Size = 124
            FINDPOSN                                              0:5579
            GOODPOS                                               0:5653
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AF5E, Size = 0

    Module A from file MISC
        Segment CODE.CODE, Addr = 569D, Size = 115
            FILLMEM                                               0:576B
            GETCHAR                                               0:56C8
            GETMODE                                               0:56B3
            IN                                                    0:5715
            MOVEBYTE                                              0:5740
            OUT                                                   0:572A
            SETMODE                                               0:569D
            VERIFYGAMEID                                          0:5788
        Segment DATA.DATA, Addr = AF5E, Size = 5

    Module SAVENAME from file SAVENAME
        Segment CODE.CODE, Addr = 57B2, Size = 13A
            MAKESAVEFILENAME                                      0:57B2
            VALIDPATH                                             0:581C
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = AF63, Size = 3E
            EXAMPLESAVENAME                                     9BA:13D5
            SAVEDRIVE                                           9BA:13FF

    Module A from file FILEIO
        Segment CODE.CODE, Addr = 58EC, Size = 1EE
            CLOSE                                                 0:5991
            CREAT                                                 0:58EC
            DUPLICATE                                             0:59D3
            FILEDT                                                0:5AB2
            FINDFIRST                                             0:5A40
            FINDNEXT                                              0:5A65
            GETCURDIR                                             0:59F1
            GETCURDRIVE                                           0:5A29
            LSEEK                                                 0:59AA
            OPEN                                                  0:590D
            READ                                                  0:592E
            UNLINK                                                0:5974
            VALIDDRIVE                                            0:5A7D
            WRITE                                                 0:5951
        Segment DATA.DATA, Addr = AFA1, Size = 0

    Module A from file CMDATA
        Segment DATA.DATA, Addr = AFA1, Size = 1AA

Memory Map for AGI.EXE 10/07/87                                        Page 26 

            COLOR                                               9BA:1407
            CPEVNMSK                                            9BA:140A
            CPODDMSK                                            9BA:1409
            DRAWMASK                                            9BA:1405
            FINISHC                                             9BA:15A9
            FINISH_COORDS                                       9BA:15A9
            FONTRAM                                             9BA:1411
            GHRZ_POS                                            9BA:1401
            HSP_ADJMT                                           9BA:1403
            H_RAM                                               9BA:140F
            PICPTR                                              9BA:1413
            PICRELOC                                            9BA:1415
            PRIORITY                                            9BA:1408
            ROW_TABLE                                           9BA:1417
            STARTC                                              9BA:15A7
            START_COORDS                                        9BA:15A7
            S_RAM                                               9BA:140B
            THRZ_POS                                            9BA:1402
            V_RAM                                               9BA:140D

    Module SHOWOBJ from file SHOWOBJ
        Segment CODE.CODE, Addr = 5ADA, Size = 194
            SHOWOBJ                                               0:5AFE
            VSHOWOBJ                                              0:5ADA
            _SHOWOBJ                                              0:5B1A
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B14B, Size = A

    Module A from file KBDINT
        Segment CODE.CODE, Addr = 5C6E, Size = 10F
            HOLDKEY                                               0:5C6E
            KBDHANDLER                                            0:5C76
        Segment DATA.DATA, Addr = B155, Size = 18

    Module JOYDRV from file JOYDRV
        Segment CODE.CODE, Addr = 5D7D, Size = 282
            FLUSHBUTTONS                                          0:5F67
            GETDIR                                                0:5F80
            INITJOY                                               0:5D7D
            POLLBUTTONS                                           0:5E9A
            POLLJOY                                               0:5E33
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B16D, Size = A0
            BUTTON                                              9BA:15CD
            JOYTIMER                                            9BA:1659
            JPREVDIR                                            9BA:1661
            JX                                                  9BA:165D
            JY                                                  9BA:165F
            ONSTATUS                                            9BA:1657
            PCJOYMSG                                            9BA:15E5

    Module A from file JOYREAD
        Segment CODE.CODE, Addr = 5FFF, Size = 82
            READBUTTONS                                           0:6066
            READJOY                                               0:5FFF
        Segment DATA.DATA, Addr = B20D, Size = 0

    Module A from file PICDRAW
        Segment CODE.CODE, Addr = 6081, Size = 337
            DRAWPIC                                               0:6086
            DRWPICNC                                              0:6081
            POINT                                                 0:6140

Memory Map for AGI.EXE 10/07/87                                        Page 27 

            _DRAWBRUSH                                            0:616B
        Segment DATA.DATA, Addr = B20D, Size = DA

    Module A from file OVLYM
        Segment CODE.CODE, Addr = 63B8, Size = A5
            $OVIN$                                                0:63B8
            $OVLYM                                                0:63B8
            OVLOAD                                                0:6404
        Segment DATA.DATA, Addr = B2E7, Size = 8
            DATASEG                                             9BA:174B
            ENDSEG                                              9BA:1747
            LOADSEG                                             9BA:1749
            PSPSEG                                              9BA:174D

    Module KEYMAP from file KEYMAP
        Segment CODE.CODE, Addr = 645D, Size = 0
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B2EF, Size = 4C
            DIRECTIONKEY                                        9BA:174F
            TANDYDIR                                            9BA:1773

    Module RESTORE from file RESTORE
        Segment CODE.CODE, Addr = 645D, Size = 1C8
            RESTORE                                               0:645D
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B33B, Size = 0

    Module ANILIST from file ANILIST
        Segment CODE.CODE, Addr = 6625, Size = 19E
            ALLINBACK                                             0:66CF
            ALLTOSCREEN                                           0:66EC
            FORCEUPDATE                                           0:6759
            FREEALLOBJLISTS                                       0:66B2
            ISSTOPPEDOBJ                                          0:6646
            ISUPDOBJ                                              0:6625
            LSTARTUPDATE                                          0:6731
            LSTOPUPDATE                                           0:6709
            MAKESTOPPEDLIST                                       0:667E
            MAKEUPDLIST                                           0:6667
            RESTOREALL                                            0:6695
            STARTUPDATE                                           0:67A3
            STOPUPDATE                                            0:6785
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B33B, Size = 8
            STOPPEDLIST                                         9BA:179F
            UPDATELIST                                          9BA:179B

    Module CYCLE from file CYCLE
        Segment CODE.CODE, Addr = 67C3, Size = 162
            ENDOFLOOP                                             0:67EF
            NORMALCYCLE                                           0:67C3
            REVERSECYCLE                                          0:682C
            REVERSELOOP                                           0:6858
            SETCYCLEFREQ                                          0:6895
            STARTCYCLING                                          0:68FD
            STOPCYCLING                                           0:68D8
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B343, Size = 0

    Module MOTION from file MOTION
        Segment CODE.CODE, Addr = 6925, Size = 37A
            FOLLOWEGO                                             0:6A43

Memory Map for AGI.EXE 10/07/87                                        Page 28 

            GETOBJDIR                                             0:6C3D
            LMOVEOBJ                                              0:6925
            MOVEOBJF                                              0:69A2
            NORMALMOTION                                          0:6AE2
            PLAYERCONTROL                                         0:6C82
            PROGRAMCONTROL                                        0:6C70
            SETOBJDIR                                             0:6BFF
            SETSTEPSIZE                                           0:6B7F
            SETSTEPTIME                                           0:6BBD
            STARTMOTION                                           0:6B46
            STARTWANDER                                           0:6AA9
            STOPMOTION                                            0:6B09
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B343, Size = 0

    Module SCRIPT from file SCRIPT
        Segment CODE.CODE, Addr = 6C9F, Size = 162
            ADDSCRIPT                                             0:6CF2
            INITSCRIPT                                            0:6CBD
            NEXTSCRIPT                                            0:6D8D
            OPENSCRIPT                                            0:6D70
            POPSCRIPT                                             0:6DDE
            PUSHSCRIPT                                            0:6DCC
            SCRIPTOFF                                             0:6C9F
            SCRIPTON                                              0:6CAE
            SETSCRIPTSIZE                                         0:6DAB
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B343, Size = A
            DOSCRIPT                                            9BA:17A9
            MAXSCRIPT                                           9BA:17AB
            SCRIPT                                              9BA:17A3
            SCRIPTPTR                                           9BA:17A7
            SCRIPTTOP                                           9BA:17A5

    Module A from file RANDOM
        Segment CODE.CODE, Addr = 6E01, Size = 2D
            RANDOM                                                0:6E01
        Segment DATA.DATA, Addr = B34D, Size = 2
            RANDSEED                                            9BA:17AD

    Module DEBUG from file DEBUG
        Segment CODE.CODE, Addr = 6E2E, Size = 168
            GETNUM                                                0:6E2E
            OBJSTATUS                                             0:6EF6
            SHOWPRISCREEN                                         0:6F5C
            VERSION                                               0:6F7D
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B34F, Size = 44
            SHOWPRI                                             9BA:17F1

    Module A from file VAR
        Segment CODE.CODE, Addr = 6F96, Size = 12F
            ADDF                                                  0:6FE9
            ADDN                                                  0:6FDC
            ASSIGNF                                               0:6FC9
            ASSIGNN                                               0:6FBC
            DECREMENT                                             0:6FA9
            DIVN                                                  0:708D
            DIVV                                                  0:70A6
            INCREMENT                                             0:6F96
            LINDIRECTF                                            0:701C
            LINDIRECTN                                            0:7035

Memory Map for AGI.EXE 10/07/87                                        Page 29 

            MULN                                                  0:705F
            MULV                                                  0:7072
            RINDIRECT                                             0:7046
            SUBF                                                  0:7009
            SUBN                                                  0:6FFC
        Segment DATA.DATA, Addr = B393, Size = 0

    Module A from file FLAG
        Segment CODE.CODE, Addr = 70C5, Size = B4
            CLEARFLAGS                                            0:716B
            GETFLAG                                               0:7152
            ISFLAGSET                                             0:7143
            ISSET                                                 0:7125
            RESET                                                 0:7111
            RESETFLAG                                             0:70CC
            RESETIT                                               0:7135
            SET                                                   0:7107
            SETFLAG                                               0:70C5
            SETIT                                                 0:712F
            TOGGLE                                                0:711B
            TOGGLEFLAG                                            0:70D3
            TOGGLEIT                                              0:713D
            VRESETFLAG                                            0:70E9
            VSETFLAG                                              0:70DA
            VTOGGLEFLAG                                           0:70F8
        Segment DATA.DATA, Addr = B393, Size = 0

    Module OBJACT from file OBJACT
        Segment CODE.CODE, Addr = 7179, Size = 192
            DROP                                                  0:71B1
            GET                                                   0:7179
            GETF                                                  0:7195
            GETROOMF                                              0:7223
            OBJPTR                                                0:724E
            OBJVARPTR                                             0:72A4
            PUT                                                   0:71CD
            PUTF                                                  0:71F8
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B393, Size = 0

    Module SCRACT from file SCRACT
        Segment CODE.CODE, Addr = 730B, Size = 336
            CONFIGURESCREEN                                       0:7531
            GRAPHICSSCREEN                                        0:750C
            LCLEARLINES                                           0:7355
            LCLEARRECT                                            0:7394
            LGRAFSCRN                                             0:7343
            LTEXTSCRN                                             0:730B
            MAKEBACKCOLOR                                         0:74EE
            MAKEFORECOLOR                                         0:74E2
            MAKETEXTATR                                           0:7444
            RESTORETEXTATR                                        0:7604
            SAVETEXTATR                                           0:75CA
            SETTEXTATR                                            0:73F0
            TOGGLEMONITOR                                         0:758D
            _SETTEXTATR                                           0:7416
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B393, Size = 22
            SAVEDATR                                            9BA:17F5
            SAVEDINDEX                                          9BA:1813
            SCREENMODE                                          9BA:17F3


Memory Map for AGI.EXE 10/07/87                                        Page 30 

    Module A from file SHAKE
        Segment CODE.CODE, Addr = 7641, Size = 73
            SHAKESCREEN                                           0:7641
        Segment DATA.DATA, Addr = B3B5, Size = B

    Module PRIORITY from file PRIORITY
        Segment CODE.CODE, Addr = 76B4, Size = CE
            FSETPRIORITY                                          0:773C
            GETPRIORITY                                           0:7709
            RELEASEPRIORITY                                       0:76E4
            SETPRIORITY                                           0:76B4
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B3C0, Size = 0

    Module BLOCK from file BLOCK
        Segment CODE.CODE, Addr = 7782, Size = CC
            BLOCK                                                 0:7782
            IGNOREBLOCKS                                          0:77D0
            INBLOCK                                               0:781A
            OBSERVEBLOCKS                                         0:77F5
            UNBLOCK                                               0:77BE
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B3C0, Size = 0

    Module POSITION from file POSITION
        Segment CODE.CODE, Addr = 784E, Size = 2C6
            FLAGPOSN                                              0:788B
            GETPOSN                                               0:78D8
            IGNOREHORIZON                                         0:7AC8
            OBSERVEHORIZON                                        0:7AED
            ONANYTHING                                            0:7A8B
            ONLAND                                                0:7A66
            ONWATER                                               0:7A41
            POSITION                                              0:784E
            REPOSITION                                            0:791B
            REPOSITIONTO                                          0:79AB
            SETHORIZON                                            0:7AB0
            VREPOSITIONTO                                         0:79EE
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B3C0, Size = 0

    Module A from file SETJMP
        Segment CODE.CODE, Addr = 7B14, Size = 1C
            LONGJMP                                               0:7B23
            SETJMP                                                0:7B14

    Module TIMERINT from file TIMERINT
        Segment CODE.CODE, Addr = 7B30, Size = 9A
            TIMERINT                                              0:7B30
            WAITTOANIMATE                                         0:7BAC
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B3C0, Size = 4
            ANITIMER                                            9BA:1820

    Module A from file PLAYSND
        Segment CODE.CODE, Addr = 7BCA, Size = 1B1
            CONVERTFREQTOPC                                       0:7D60
            CONVERTTDVOLUME                                       0:7D43
            PLAYIT                                                0:7C2C
            PLAYNOTE                                              0:7CEA
            SOUNDOFF                                              0:7CB9
            STARTSOUND                                            0:7BCA

Memory Map for AGI.EXE 10/07/87                                        Page 31 

        Segment DATA.DATA, Addr = B3C4, Size = 23

    Module INITMACH from file INITMACH
        Segment CODE.CODE, Addr = 7D7B, Size = 98
            INITGRAPHICS                                          0:7DA0
            INITMACHINE                                           0:7D7B
            RESETMACHINE                                          0:7DF9
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B3E7, Size = 2
            SAVEMODE                                            9BA:1847

    Module LOG from file LOG
        Segment CODE.CODE, Addr = 7E13, Size = 11E
            CLOSELOGFILE                                          0:7F10
            LOG                                                   0:7E13
            OPENLOGFILE                                           0:7EC3
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B3E9, Size = 24
            LOGFILE                                             9BA:1863
            LOGFILENAME                                         9BA:1865

    Module A from file INTRPT
        Segment CODE.CODE, Addr = 7F31, Size = 238
            CRITICALERROR                                         0:813F
            DEADSTACK                                             0:810C
            NULLINTERRUPT                                         0:813E
            RESETINTERRUPTS                                       0:8023
            SETINTERRUPTS                                         0:7F31
            TIMERDISPATCH                                         0:80D0
            TIMERINTHANDLER                                       0:80A5
        Segment DATA.DATA, Addr = B40D, Size = 43
            DOSERROR                                            9BA:188D
            OLDKBD                                              9BA:1881
            OLDVIDEO                                            9BA:1885

    Module GETGAME from file GETGAME
        Segment CODE.CODE, Addr = 8169, Size = 6AC
            CHANGEDISK                                            0:8227
            ERASEPOINTER                                          0:87F2
            GETDESCRIPTION                                        0:8723
            GETGAME                                               0:8169
            GETGAMENUMBER                                         0:8398
            GETPATH                                               0:8289
            GETWINDOWSTR                                          0:8318
            WRITEPOINTER                                          0:87D2
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B450, Size = 45C
            BADPATHMSG                                          9BA:1C5C
            NEWDESCRIPT                                         9BA:1BEA
            NOGAMESMSG                                          9BA:1C1C
            RESTMSG                                             9BA:1A20
            SAVEDESCRIPT                                        9BA:1CAC
            SAVEFILE                                            9BA:1CCC
            SAVEMSG                                             9BA:19C2
            SAVEPATH                                            9BA:19A2
            SELECTRESTORE                                       9BA:1B6C
            SELECTSAVE                                          9BA:1AE8
            SWAPDISKMSG                                         9BA:1A86

    Module TRACE from file TRACE
        Segment CODE.CODE, Addr = 8815, Size = 406
            GETPARM                                               0:8BBB

Memory Map for AGI.EXE 10/07/87                                        Page 32 

            SCROLLTRACE                                           0:8BF8
            TRACEACTION                                           0:8927
            TRACEINFO                                             0:88C1
            TRACEIT                                               0:898F
            TRACEOFF                                              0:88FD
            TRACEON                                               0:8815
            TRACEPARMS                                            0:8AAD
            TRACETEST                                             0:894D
            _TRACEON                                              0:8832
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B8AC, Size = 56
            ROOMTOTRACE                                         9BA:1D4C
            SAIDTEST                                            9BA:1D4E
            TRACEDIVIDER                                        9BA:1D60
            TRACELOGS                                           9BA:1D52
            TRACESTATUS                                         9BA:1D50
            TRWINDOWPOS                                         9BA:1D48
            TRWINDOWSIZE                                        9BA:1D4A
            TWBOTTOMROW                                         9BA:1D58
            TWDIM                                               9BA:1D5E
            TWLEFTCOL                                           9BA:1D56
            TWPOS                                               9BA:1D5C
            TWRIGHTCOL                                          9BA:1D5A
            TWTOPROW                                            9BA:1D54

    Module SAVEAREA from file SAVEAREA
        Segment CODE.CODE, Addr = 8C1B, Size = 86
            FREESAVEAREA                                          0:8C8E
            GETSAVEAREA                                           0:8C1B
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B902, Size = 0

    Module MENU from file MENU
        Segment CODE.CODE, Addr = 8CA1, Size = 5E2
            CHANGEITEM                                            0:8EE3
            COMPUTEMENUWINDOW                                     0:920F
            DESELECT                                              0:91A9
            DISABLEMENU                                           0:8EC4
            DOMENU                                                0:8F55
            ENABLEALLMENUS                                        0:8E92
            ENABLEMENU                                            0:8E72
            MENUINPUT                                             0:8F35
            PUTAWAY                                               0:912D
            SELECT                                                0:9154
            SETMENU                                               0:8CA1
            SETMENUITEM                                           0:8D53
            SHOWMENU                                              0:90DB
            SUBMITMENU                                            0:8E3E
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = B902, Size = 14
            ACTIVATEMENU                                        9BA:1D62
            CURITEM                                             9BA:1D70
            CURMENU                                             9BA:1D6E
            ITEMCOL                                             9BA:1D68
            ITEMROW                                             9BA:1D66
            MENUBASE                                            9BA:1D6C
            MENUCOL                                             9BA:1D64
            MENUDIM                                             9BA:1D74
            MENUPOS                                             9BA:1D72
            MENUSUBMITTED                                       9BA:1D6A

    Module A from file PCJMPTBL

Memory Map for AGI.EXE 10/07/87                                        Page 33 

        Segment CODE.CODE, Addr = 9390, Size = 15
            BLK2SCRN                                              0:939C
            DRAWWNDW                                              0:93A2
            GRAFSCRN                                              0:9396
            INITGRFX                                              0:9390
            INITROWS                                              0:939F
            SETHORZ                                               0:9399
            TEXTSCRN                                              0:9393

    Module A from file PCGRAPHX
        Segment CODE.CODE, Addr = 93A5, Size = 297
            PCB2S                                                 0:9545
            PCDW                                                  0:95A5
            PCGS                                                  0:94FB
            PCIG                                                  0:946B
            PCIRT                                                 0:9613
            PCSH                                                  0:9510
            PCTS                                                  0:94A9
            PCXC                                                  0:93A5
            PCXO                                                  0:93C7
        Segment DATA.DATA, Addr = B916, Size = 62
            COLORTBL                                            9BA:1D76

    Module A from file JRJMPTBL
        Segment CODE.CODE, Addr = 9390, Size = 15

    Module A from file JRGRAPHX
        Segment CODE.CODE, Addr = 93A5, Size = 1BC
            JRB2S                                                 0:9485
            JRDW                                                  0:94ED
            JRGS                                                  0:9422
            JRIG                                                  0:93A5
            JRIRT                                                 0:9525
            JRSH                                                  0:9437
            JRTS                                                  0:93C9
        Segment DATA.DATA, Addr = B978, Size = 0

    Module A from file XTJMPTBL
        Segment CODE.CODE, Addr = 9390, Size = 15

    Module A from file XTGRAPHX
        Segment CODE.CODE, Addr = 93A5, Size = 240
            XTB2S                                                 0:9415
            XTDW                                                  0:949C
            XTGS                                                  0:93FF
            XTIG                                                  0:93A5
            XTIRT                                                 0:9519
            XTSH                                                  0:9414
            XTSS                                                  0:954E
            XTTS                                                  0:93C5
        Segment DATA.DATA, Addr = B978, Size = 0

    Module A from file HJMPTBL
        Segment CODE.CODE, Addr = 9390, Size = 15

    Module A from file HGRAPHX
        Segment CODE.CODE, Addr = 93A5, Size = 43D
            HB2S                                                  0:94B6
            HBS                                                   0:9429
            HCVB                                                  0:95C6
            HDW                                                   0:9516
            HIG                                                   0:93A5

Memory Map for AGI.EXE 10/07/87                                        Page 34 

            HIRT                                                  0:95A4
            HSH                                                   0:9428
            HSS                                                   0:9773
            HTS                                                   0:93F9
            HVIDEOINT                                             0:95DA
        Segment DATA.DATA, Addr = B978, Size = 90
            PATRNMASKS                                          9BA:1DE8

    Module HDIALOG from file HDIALOG
        Segment CODE.CODE, Addr = 97E2, Size = 154
            CLOSEDIALOGUE                                         0:9923
            GETDIALOGUE                                           0:98BB
            OPENDIALOGUE                                          0:97E2
        Segment CONST.CONST, Addr = BAB0, Size = 0
        Segment DATA.DATA, Addr = BA08, Size = 14
            ENTERCMNDSTR                                        9BA:1E6E

    Module A from file VGJMPTBL
        Segment CODE.CODE, Addr = 9390, Size = 15

    Module A from file VGGRAPHX
        Segment CODE.CODE, Addr = 93A5, Size = 102
            VGB2S                                                 0:9416
            VGDW                                                  0:9469
            VGGS                                                  0:9400
            VGIG                                                  0:93A5
            VGIRT                                                 0:9494
            VGSH                                                  0:94A6
            VGTS                                                  0:93C7
        Segment DATA.DATA, Addr = BA1C, Size = 0

    Module A from file IOJMPTBL
        Segment CODE.CODE, Addr = 9940, Size = 9
            INSERTOBJ                                             0:9946
            RESTBACK                                              0:9943
            SAVEBACK                                              0:9940

    Module A from file IOBJSBRS
        Segment CODE.CODE, Addr = 9949, Size = 14C
            IIO                                                   0:99C5
            IRSB                                                  0:9988
            ISSB                                                  0:9949
        Segment DATA.DATA, Addr = BA1C, Size = 0

    Module A from file HOJMPTBL
        Segment CODE.CODE, Addr = 9940, Size = 9

    Module A from file HOBJSBRS
        Segment CODE.CODE, Addr = 9949, Size = 24E
            HIO                                                   0:9A1F
            HRSB                                                  0:99B4
            HSSB                                                  0:9949
        Segment DATA.DATA, Addr = BA1C, Size = 6
copy agi.exe %2
copy *.ovl %2
setstr gameID %1 %2agi.exe
copy ..\src\agi.doc %2
/* SHOWOBJ
** Show the player an object on the screen
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"
#include	"object.h"
#include	"objlist.h"
#include	"screen.h"


STRPTR	ShowObj();
STRPTR	VShowObj();
void		_ShowObj();


#define	SHOWY	MAXY


extern	OBJECT	object[];
extern	TEXT		ENTERcont[];
extern	VIEWNODE	viewList;
extern	BOOL		returnIfNoMem;
extern	UBYTE	var[];
extern	WORD		monType;

extern	UWORD	MemLeft();
extern	VIEWNODE	*FindView(), *LoadView();
extern	STRPTR	GetMem();
extern	SAVEAREA	*GetSaveArea();




STRPTR
VShowObj(lp)
register	STRPTR	lp;
{
	_ShowObj(var[*lp++]);
	return (lp);
}





STRPTR
ShowObj(lp)
register	STRPTR	lp;
{
	_ShowObj(*lp++);
	return (lp);
}





void
_ShowObj(objView)
COUNT	objView;
/* Display the given object view, print the message, and wait for the
** player to press enter.
*/
{
	register	VIEWNODE	*vEnt;
			SAVEAREA	*sp;
			COUNT	backSize;
			ANIOBJ	obj;
			BOOL		viewHere, objShown;


	ScriptOff();
	objShown = FALSE;

	/* Load the object view
	*/
	viewHere = (FindView(objView) != NULL);
	returnIfNoMem = TRUE;
	if (LoadView(objView, FALSE) == NULL) {
		/* Not enough memory to load the view
		*/
		returnIfNoMem = FALSE;
		WindowPrint("Not now.");
		return;
		}
	returnIfNoMem = FALSE;

	/* Set up the aniObj structure which will be used to display this view
	*/
	obj.loop = obj.cel = 0;
	SetView(&obj, objView);
	obj.prevcel = obj.celptr;
	obj.x = obj.prevx = (MAXX - obj.xsize)/2;
	obj.y = obj.prevy = MAXY;
	obj.pri = 15;
	obj.control |= FIXEDPRI;
	obj.num = -1;
	backSize = obj.xsize;
	if (monType == MONO)
		backSize += (((obj.x & 1) + backSize + 1) / 2) * 2;
	backSize = backSize * obj.ysize + sizeof(SAVEAREA);

	/* If there is enough memory to save the background so that we can
	** draw the object, do so.
	*/
	if (MemLeft() > backSize) {
		objShown = TRUE;
		sp = GetSaveArea(&obj);
		SaveBack(sp);
		InsertObj(&obj);
		Obj2Scrn(&obj);
		}

	vEnt = FindView(objView);
	WindowPrint((char *) vEnt->ptr + W8086(vEnt->ptr->vdesc));

	if (objShown) {
		RestBack(sp);
		Obj2Scrn(&obj);
		FreeSaveArea(sp);
		}

	/* Toss the view
	*/
	if (!viewHere)
		DiscardView(objView);

	ScriptOn();
	return;
}

/* ADVANCEL
** Determine the next cel to display for objects which cycle.
**
**	compile: MWC
**
*/



#include	"types.h"
#include	"game.h"
#include	"aniobj.h"


void		AdvanceCel();
STRPTR	FixLoop();
STRPTR	ReleaseLoop();


extern	ANIOBJ	*aniObj;




void
AdvanceCel(obj)
register	ANIOBJ	*obj;
/* Determine which cel of an object to display next
*/
{
	register		UBYTE		theCel;
				UBYTE		lastCel;


	if (obj->control & NOADVANC) {
		obj->control &= ~NOADVANC;
		return;
		}

	/* Advance to the next cel in the loop
	*/
	theCel = obj->cel;
	lastCel = obj->celcnt - 1;
	switch (obj->cycle) {
		case NORMAL:
			/* Move to the next sequential cel
			*/
			if (++theCel > lastCel)
				theCel = 0;
			break;

		case ENDLOOP:
			/* Advance to the end of the loop, set flag in parms[0]
			** when done
			*/
			if (theCel >= lastCel || ++theCel == lastCel) {
				Set(obj->parms[0]);			/* set flag */
				obj->control &= ~CYCLE;		/* done cycling object */
				obj->dir = 0;
				obj->cycle = NORMAL;
				}
			break;

		case RVRSLOOP:
			/* Move backwards, celwise, until beginning of loop, then
			** set flag
			*/
			if (theCel == 0 || --theCel == 0) {
				Set(obj->parms[0]);			/* set flag */
				obj->control &= ~CYCLE;
				obj->dir = 0;
				obj->cycle = NORMAL;
				}
			break;

		case REVERSE:
			/* Cycle continually, but from end of loop to beginning
			*/
			if (theCel > 0)
				--theCel;
			else
				theCel = lastCel;
			break;
		}

	/* Get pointer to the new cel and set cel dimensions
	*/
	SetCel(obj, theCel);
}



STRPTR
FixLoop(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*obj;

	obj = aniObj + *lp++;
	obj->control |= FIXEDLOOP;
	return (lp);
}




STRPTR
ReleaseLoop(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*obj;

	obj = aniObj + *lp++;
	obj->control &= ~FIXEDLOOP;
	return (lp);
}

/* ANILIST
** Routines dealing with lists of animated objects.
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"
#include	"aniobj.h"
#include	"objlist.h"

BOOL		IsUpdObj();
BOOL		IsStoppedObj();
OBJLIST	*MakeUpdList();
OBJLIST	*MakeStoppedList();
void		RestoreAll();
void		FreeAllObjLists();
void		AllInBack();
void		InsertAll();
STRPTR	LStopUpdate();
STRPTR	LStartUpdate();
STRPTR	ForceUpdate();
void		StopUpdate();
void		StartUpdate();


OBJLIST	updateList, stoppedList;

extern	ANIOBJ	*aniObj, *aniEnd;

extern	OBJLIST	*MakeObjList();





BOOL
IsUpdObj(obj)
register	ANIOBJ	*obj;
/* Return TRUE if object is an updating object, FALSE otherwise
*/
{
	return ((obj->control & (UPDATE | DRAWN)) == (UPDATE | DRAWN));
}



BOOL
IsStoppedObj(obj)
ANIOBJ	*obj;
/* Return TRUE is 'obj' is a stop-updated object, FALSE otherwise
*/
{
	return ((obj->control & (UPDATE | DRAWN)) == DRAWN);
}



OBJLIST	*
MakeUpdList()
{
	return (MakeObjList(IsUpdObj, &updateList));
}



OBJLIST	*
MakeStoppedList()
{
	return (MakeObjList(IsStoppedObj, &stoppedList));
}




void
RestoreAll()
{
	RestoreObjList(&updateList);
	RestoreObjList(&stoppedList);
}



void
FreeAllObjLists()
{
	FreeObjList(&updateList);
	FreeObjList(&stoppedList);
}



void
AllInBack()
{
	ListInBack(MakeStoppedList());
	ListInBack(MakeUpdList());
}




void
AllToScreen()
{
	ListToScreen(&stoppedList);
	ListToScreen(&updateList);
}




STRPTR
LStopUpdate(lp)
register	STRPTR	lp;
{
	StopUpdate(aniObj + *lp++);
	return (lp);
}




STRPTR
LStartUpdate(lp)
register	STRPTR	lp;
{
	StartUpdate(aniObj + *lp++);
	return (lp);
}




STRPTR
ForceUpdate(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*obj;

	obj = aniObj + *lp++;

	RestoreAll();			/* restore all backgrounds */
	AllInBack();			/* remake lists and re-insert objects */
	AllToScreen();			/* re-display all objects */

	return (lp);
}




void
StopUpdate(obj)
register	ANIOBJ	*obj;
{
	if ((obj->control & UPDATE) != 0) {
		RestoreAll();			/* restore backgrounds of all objects */
		obj->control &= ~UPDATE;	/* mark the object as not updating */
		AllInBack();			/* remake lists and re-insert objects */
		}
}



void
StartUpdate(obj)
register	ANIOBJ	*obj;
{
	if ((obj->control & UPDATE) == 0) {
		RestoreAll();			/* restore backgrounds of all objects */
		obj->control |= UPDATE;	/* mark the object as updating */
		AllInBack();			/* remake lists and re-insert objects */
		}
}

/* ANIMATE
** Handle one cycle of animation in an adventure game
**
**	compile: MWC
**
** Change History:
**	25/03/87  11:11:37	JAS
**		Removed all references to egoDir.
**	13/03/87	12:38:00	DCI
**		Fixed ChkBlock() to also set egoDir to zero when Ego is blocked.
**	26/02/87  09:50:39	JAS
**		Fixed GetObjDirs() to only get directions of animated objects
**		(oops).
**	17/02/87  15:38:03	JAS
**		No longer call ObjDir() in Animate().  A call is made to
**		GetObjDirs() before starting the logic scan in main().
**		This allows ego's direction to be known to the logics
**		even when ego is on a move.obj().
**
**		ObjDir() is now only called when obj->moveclk == 1, i.e.
**		when the object is ready to move.  This fixes (I hope) the
**		problem with objects with a movefreq > 1 on a wander() thinking
**		that they're blocked and picking a new direction on those
**		cycles in which they're not moving.
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"
#include	"script.h"
#include	"objlist.h"


STRPTR	LAnimateObj();
void		AnimateObj();
STRPTR	UnAnimateAll();
void		Animate();
void		GetObjDirs();
void		ObjDir();
void		ChkBlock();




extern	ANIOBJ	*aniObj, *aniEnd;
extern	BOOL		blocking;
extern	OBJLIST	*updateList;
extern	UBYTE	var[];


extern	STRPTR	GetMem();
extern	OBJLIST	*MakeUpdList();





STRPTR
LAnimateObj(lp)
register	STRPTR	lp;
{
	AnimateObj(*lp++);
	return (lp);
}




void
AnimateObj(n)
register	WORD		n;
{
	register	ANIOBJ	*op;

	if ((op = aniObj + n) >= aniEnd)
		Error(13, n);
	if (op->control & ANIMATED)
		return;

	op->control = ANIMATED | UPDATE | CYCLE;
	op->motion = NORMAL;
	op->cycle = NORMAL;
	op->dir = 0;
}




STRPTR
UnAnimateAll(lp)
STRPTR	lp;
{
	register	ANIOBJ	*obj;

	/* Restore all backgrounds and free background memory
	*/
	RestoreAll();

	/* Unanimate and erase all objects
	*/
	for (obj = aniObj ; obj < aniEnd ; ++obj)
		obj->control &= ~(ANIMATED | DRAWN);

	return (lp);
}


	

void
Animate()
{
/* object views -- same, right, left, front, back */
#define		S	4
#define		R	0
#define		L	1
#define		F	2
#define		B	3

	register	ANIOBJ	*obj;		/* currently animated object */
	register	WORD		updFlag;		/* does anything need updating? */
			UBYTE	newLoop;
	static	UBYTE	twoLoop[] = {S, S, R, R, R, S, L, L, L};
	static	UBYTE	fourLoop[] = {S, B, R, R, R, F, L, L, L};

	updFlag = 0;					/* initialize update flag */

	/* Loop through the animated objects, pointing to the next cel for all
	** objects which are to be updated
	*/
	for (obj = aniObj ; obj < aniEnd ; ++obj) {
		if ((obj->control & (ANIMATED | UPDATE | DRAWN)) == (ANIMATED | UPDATE | DRAWN)) {
			/* Increment the number of objects to update
			*/
			++updFlag;

			/* Get the appropriate loop based on the current direction
			*/
			newLoop = S;
			if ((obj->control & FIXEDLOOP) == 0) {
				if (obj->loopcnt == 2 || obj->loopcnt == 3)
					newLoop = twoLoop[obj->dir];
				else if (obj->loopcnt == 4)
					newLoop = fourLoop[obj->dir];
				}

			/* If the object is to move in this cycle and the loop
			** has changed, point to the new loop.
			*/
			if (obj->moveclk == 1 && newLoop != S && obj->loop != newLoop)
				SetLoop(obj, newLoop);

			/* If it is time to cycle the object, advance its cel
			*/
			if ((obj->control & CYCLE) &&
				obj->cycleclk && --obj->cycleclk == 0) {
					AdvanceCel(obj);
					obj->cycleclk = obj->cyclfreq;
				}
			}
		}

	/* If at least one object is to be updated, update all objects
	*/
	if (updFlag) {
		/* Restore backgrounds of updating objects
		*/
		RestoreObjList(&updateList);

		/* Move all the objects
		*/
		MoveObjs();

		/* Re-make the update list and display all objects in it.
		*/
		ListInBack(MakeUpdList());
		ListToScreen(&updateList);

		/* Clear the 'must be on water or land' bits for ego
		*/
		ego->control &= ~(PRICTRL1 | PRICTRL2);
		}
}




void
GetObjDirs()
{
	register	ANIOBJ	*obj;

	for (obj = aniObj ; obj < aniEnd ; ++obj)
		if ((obj->control & (ANIMATED | UPDATE | DRAWN)) ==
				(ANIMATED | UPDATE | DRAWN)
			&& obj->moveclk == 1)
				ObjDir(obj);
}




void
ObjDir(obj)
register	ANIOBJ	*obj;
/* Set the direction for the current object based on its motion type
*/
{

	switch (obj->motion) {
		case WANDER:
			Wander(obj);
			break;
		case FOLLOW:
			Follow(obj);
			break;
		case MOVETO:
			MoveTo(obj);
			break;
		}

	/* If no blocks are in effect, clear the 'blocked' flag.  Otherwise,
	** if object must observe blocks, check for blocking
	*/
	if (!blocking)
		obj->control &= ~BLOCKED;
	else if ((obj->control & IGNRBLK) == 0 && obj->dir != 0)
		ChkBlock(obj);
}





void
ChkBlock(obj)
register	ANIOBJ	*obj;	/* currently animated object */
/* A block is in effect and the object must observe blocks -- check to see
** if the object can move in its current direction
*/
{
	BOOL		objInBlock;
	int		ox, oy;

	/* Get obj coord into temp vars and determine if the object is
	** currently within the block.
	*/
	ox = obj->x;
	oy = obj->y;
	objInBlock = InBlock(ox, oy);

	/* Get object coordinate after moving
	*/
	switch (obj->dir) {
		case 1:
			oy -= obj->stepsize;
			break;
		case 2:
			ox += obj->stepsize;
			oy -= obj->stepsize;
			break;
		case 3:
			ox += obj->stepsize;
			break;
		case 4:
			ox += obj->stepsize;
			oy += obj->stepsize;
			break;
		case 5:
			oy += obj->stepsize;
			break;
		case 6:
			ox -= obj->stepsize;
			oy += obj->stepsize;
			break;
		case 7:
			ox -= obj->stepsize;
			break;
		case 8:
			ox -= obj->stepsize;
			oy -= obj->stepsize;
			break;
		}

	/* If moving the object will not change its 'in block' status, let
	** it move.
	*/
	if (objInBlock == InBlock(ox, oy))
		obj->control &= ~BLOCKED;
	else {
		obj->control |= BLOCKED;
		obj->dir = 0;
		/* When Ego is the blocked object also set ego's direction
		 * to zero.
		 */
		if (obj == ego)
			var[EGODIR] = 0;
		}
}

/* BLOCK
** Routines dealing with the block() command
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"



STRPTR	Block();
STRPTR	UnBlock();
STRPTR	IgnoreBlocks();
STRPTR	ObserveBlocks();
BOOL		InBlock();



extern	BOOL		blocking;
extern	COORD	ulx, uly, lrx, lry, horizon;
extern	ANIOBJ	*aniObj;





STRPTR
Block(lp)
register	STRPTR	lp;
{
	blocking = TRUE;
	ulx = *lp++;
	uly = *lp++;
	lrx = *lp++;
	lry = *lp++;

	return (lp);
}
	


STRPTR
UnBlock(lp)
STRPTR	lp;
{
	blocking = FALSE;
	return (lp);
}
	


STRPTR
IgnoreBlocks(lp)
register	STRPTR	lp;
{
	aniObj[*lp++].control |= IGNRBLK;
	return (lp);
}
	


STRPTR
ObserveBlocks(lp)
register	STRPTR	lp;
{
	aniObj[*lp++].control &= ~IGNRBLK;
	return (lp);
}




BOOL
InBlock(ox, oy)
register	int	ox, oy;
/* Is the object 'obj' in a block?
*/
{
	return (ox > ulx && ox < lrx && oy > uly && oy < lry);
}

/* COLLIDE
** Check for object collisions
**
**	compile: MWC
**
** CHANGE HISTORY:
**	06/04/87  10:52:38	JAS
**		Fixed Distance() so that it doesn't wrap if the combined x & y
**		distances are too great.
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"

BOOL		Collide();
STRPTR	IgnoreObjs();
STRPTR	ObserveObjs();
STRPTR	Distance();


extern	ANIOBJ	*aniObj, *aniEnd;
extern	UBYTE	var[];




BOOL
Collide(obj)
register	ANIOBJ	*obj;
/* Return TRUE if object 'obj' has collided with another object,
** FALSE if not
*/
{
	register	ANIOBJ	*otherObj;
	
	if (obj->control & IGNROBJ)		/* object won't collide with anyone */
		return(FALSE);
	
	for (otherObj = aniObj ; otherObj < aniEnd ; ++otherObj) {
		/* Collision with another object if:
		**	- other object is animated and drawn
		**	- other object is not ignoring objects
		**	- other object is not this object
		**	- the two objects have overlapping baselines
		*/
		if ((otherObj->control & (ANIMATED | DRAWN)) == (ANIMATED | DRAWN)
	        && !(otherObj->control & IGNROBJ)
	        && (obj->num != otherObj->num)
	        && (obj->x + obj->xsize >= otherObj->x)
	        && (obj->x <= otherObj->x + otherObj->xsize))
			/* At this point, the two objects have overlapping
			** x coordinates. A collision has occurred if they have
			** the same y coordinate or if the object in question has
			** moved across the other object in the last animation cycle
			*/
			if ((obj->y == otherObj->y)
	                  || (obj->y > otherObj->y && obj->prevy < otherObj->prevy)
	                  || (obj->y < otherObj->y && obj->prevy > otherObj->prevy))
					return(TRUE);
		}
	return(FALSE);
}


	
STRPTR
IgnoreObjs(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*op;

	op = aniObj + *lp++;
	op->control |= IGNROBJ;

	return (lp);
}

	

STRPTR
ObserveObjs(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*op;

	op = aniObj + *lp++;
	op->control &= ~IGNROBJ;

	return (lp);
}



STRPTR
Distance(lp)
STRPTR	lp;
{
	register	ANIOBJ	*op, *obj;
			COUNT	dist;
			

	op = aniObj + *lp++;
	obj = aniObj + *lp++;
	if ((op->control & DRAWN) == 0 || (obj->control & DRAWN) == 0)
		var[*lp++] = MAXVAR;
	else {
		dist = abs((op->x + op->xsize/2) - (obj->x + obj->xsize/2))
					+ abs(op->y - obj->y);
		var[*lp++] = (dist > 254)? 254 : dist;
		}

	return (lp);
}

/* CONTROL
** Routines to deal with controllers.
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"
#include	"event.h"

void		ClearControl();
void		HandleControl();
STRPTR	SetControl();



		UBYTE	controller[NUMCONTROL];

extern	KEYMAP	keyMap[];




void
ClearControl()
/* Clear all controllers
*/
{
	FillMem(controller, NUMCONTROL, 0);
}




STRPTR
SetControl(lp)
register	STRPTR	lp;
{
	register	WORD		i;
			WORD		key, keyval;


	/* Get key code to assign to the controller
	*/
	key = *lp++;
	key += (*lp++) * 256;
	keyval = *lp++;

	/* Find an empty keymap slot, then add key mapping to it.
	*/
	for (i = 0 ; i < KEYMAPSIZE-1 ; ++i)
		if (keyMap[i].key == 0) {
			keyMap[i].key = key;
			keyMap[i].keyval = keyval;
			break;
			}

	return (lp);
}

/* CYCLE
** Set up routines for the various cycling types of objects
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"


STRPTR	NormalCycle();
STRPTR	EndOfLoop();
STRPTR	ReverseCycle();
STRPTR	ReverseLoop();
STRPTR	SetCycleFreq();
STRPTR	StopCycling();
STRPTR	StartCycling();


extern	ANIOBJ	*aniObj;
extern	UBYTE	var[];



STRPTR
NormalCycle(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*op;

	op = aniObj + *lp++;
	op->cycle = NORMAL;
	op->control |= CYCLE;
	return (lp);
}





STRPTR
EndOfLoop(lp)
register	STRPTR	lp;
/* Set up for cycling an object from the first cel of the current loop to
** the last, setting a flag when done.
*/
{
	register	ANIOBJ	*op;

	op = aniObj + *lp++;
	op->cycle = ENDLOOP;
	op->control |= UPDATE | CYCLE | NOADVANC;
	Reset(op->parms[0] = *lp++);

	return (lp);
}



STRPTR
ReverseCycle(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*op;

	op = aniObj + *lp++;
	op->cycle = REVERSE;
	op->control |= CYCLE;
	return (lp);
}



STRPTR
ReverseLoop(lp)
register	STRPTR	lp;
/* Set up for cycling an object from the last cel of the current loop to the
** first, setting a flag on completion.
*/
{
	register	ANIOBJ	*op;

	op = aniObj + *lp++;
	op->cycle = RVRSLOOP;
	op->control |= UPDATE | CYCLE | NOADVANC;
	Reset(op->parms[0] = *lp++);

	return (lp);
}



STRPTR
SetCycleFreq(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*op;

	op = aniObj + *lp++;
	op->cycleclk = op->cyclfreq = var[*lp++];
	return (lp);
}



STRPTR
StopCycling(lp)
register	STRPTR	lp;
{
	aniObj[*lp++].control &= ~CYCLE;
	return (lp);
}



STRPTR
StartCycling(lp)
register	STRPTR	lp;
{
	aniObj[*lp++].control |= CYCLE;
	return (lp);
}


/* DEBUG
** Debug logic actions
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"
#include	"screen.h"


STRPTR	GetNum();
STRPTR	ObjStatus();
STRPTR	ShowPriScreen();

BOOL		showPri = FALSE;

extern	TEXT		versionMsg[];
extern	UBYTE	var[];
extern	ANIOBJ	*aniObj;
extern	WORD		inputRow, monType;
extern	BOOL		dialogueOpen;


extern	STRPTR	Print();





STRPTR
GetNum(lp)
register	STRPTR	lp;
{
	TEXT		numStr[4];
	TEXT		msg[400];

	numStr[0] = '\0';
	if (monType != MONO || dialogueOpen) {
		EraseCur();
		SetCur(inputRow, 0);
		printf(Print(msg, GetMsgPtr(*lp++), 40)); /* print the prompt */
		WriteCur();
		GetLine(numStr, 4);					  /* get the response */
		DisplayInput();
		}
	else
		{
		OpenDialogue(Print(msg, GetMsgPtr(*lp++), 36), 4); /* print the prompt */
		GetLine(numStr, 4);							 /* get the response */
		CloseDialogue();
		}
	var[*lp++] = (UBYTE) AToI(numStr);

	return (lp);
}




STRPTR
ObjStatus(lp)
register	STRPTR	lp;
{
	register	ANIOBJ	*op;
			WORD		n;
			TEXT		msg[100];

	op = aniObj + (n = var[*lp++]);
	sprintf(msg,
		"Object %d:\nx: %d  xsize: %d\ny: %d  ysize: %d\npri: %d\nstepsize: %d",
		n, op->x, op->xsize, op->y, op->ysize, op->pri, op->stepsize);
	WindowPrint(msg);
	return (lp);
}




STRPTR
ShowPriScreen(lptr)
STRPTR	lptr;
{
	showPri = TRUE;
	BackToScrn();
	WaitAcAb();
	BackToScrn();
	showPri = FALSE;
	return (lptr);
}



STRPTR
Version(lp)
STRPTR	lp;
{
	WindowPrint(versionMsg);
	return (lp);
}

/* DRAW
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"
#include	"objlist.h"

STRPTR	LDraw();
void		DrawObj();
STRPTR	LErase();
void		Erase();


extern	ANIOBJ	*aniObj, *aniEnd;
extern	OBJLIST	*updateList, *stoppedList;

extern	OBJLIST	*MakeObjList(), *MakeStoppedList(), *MakeUpdList();




STRPTR
LDraw(lp)
register	STRPTR	lp;
{
	DrawObj(*lp++);
	return (lp);
}



void
DrawObj(n)
register	WORD		n;
/* Draw object n on the screen, relocating it if necessary
*/
{
	register	ANIOBJ	*obj;

	obj = aniObj + n;

	if (obj > aniEnd)
		Error(19, n);
	if (obj->celptr == NULL)
		Error(20, n);

	/* If object is already drawn, return
	*/
	if (obj->control & DRAWN)
		return;

	obj->control |= UPDATE;

	/* Find a position for the object
	*/
	FindPosn(obj);

	/* Set previous values to current for 'obj2scrn'
	*/
	obj->prevcel = obj->celptr;
	obj->prevx = obj->x;
	obj->prevy = obj->y;

	RestoreObjList(&updateList);	/* restore backgrounds of updating objects */
	obj->control |= DRAWN;
	ListInBack(MakeUpdList());	/* remake update list and insert objects */
	Obj2Scrn(obj);				/* put the object on the screen */

	obj->control &= ~NOADVANC;
}



STRPTR
LErase(lp)
register	STRPTR	lp;
{
	Erase(*lp++);
	return (lp);
}




void
Erase(n)
register	WORD		n;
/* Erase object n from the screen
*/
{
	register	ANIOBJ	*obj;
			BOOL		wasStopped;	/* was updating stopped? */

	/* If object is not drawn, just return
	*/
	obj = aniObj + n;
	if (obj > aniEnd)
		Error(12, n);
	if (!(obj->control & DRAWN))
		return;

	RestoreObjList(&updateList);
	if (wasStopped = ((obj->control & UPDATE) == 0))
		RestoreObjList(&stoppedList);
	obj->control &= ~DRAWN;
	if (wasStopped)
		ListInBack(MakeStoppedList());
	ListInBack(MakeUpdList());
	Obj2Scrn(obj);			/* erase object from the screen */
}

/* ENCRYPT
** Use a key to encrypt/decrypt a portion of memory
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"

void		Encrypt();


TEXT		cryptKey[] = "Avis Durgan";



void
Encrypt(mp, end)
register	STRPTR	mp;
		STRPTR	end;
/* Use the key 'cryptKey' to encrypt memory between 'mp' and 'end'
*/
{
	register	STRPTR	cc;		/* pointer to encryption key */

	cc = cryptKey;
	while (mp < end) {
		if (!*cc)
			cc = cryptKey;		/* if at end of key, start over again */
		*mp++ ^= *cc++;
		}
}
/* ERROR
** Error routine for testing.
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"setjmp.h"
#include	"game.h"

void		Error();
BOOL		DiskError();

#define	WRITE_PROTECT	0x100
#define	NOT_READY		2



TEXT		tryAgain[] = 
"\nPress ENTER to try again.";


STRPTR	diskErr[] = {
			"",						/* write protect */
			"Unknown unit",
			"",						/* drive not ready */
			"Unknown command",
			"Data error",
			"Bad request structure",
			"Seek error",
			"Unknown media type",
			"Sector not found",
			"",						/* printer out of paper */
			"Write fault",
			"Read fault",
			"General failure"
			};


extern	jmp_buf	rescanJmpBuf;
extern	TEXT		escQuitMsg[];
extern	UBYTE	var[];
extern	UWORD	dosError;



void
Error(errNo, n)
WORD		errNo, n;
{
	StopSnd();	/* turn off sound */
	FreeAll();	/* free memory allocated to various objects, logics, etc. */
	ResetEv();	/* flush the event queue */
	ResetLists();	/* initialize the lists */

	ErrBeep();
	ErrBeep();

	var[ERROR_NUM] = errNo;
	var[ERROR_PARAM] = n;

	/* Blast back to rescan room 0 logics
	*/
	longjmp(rescanJmpBuf, 1);
}




BOOL
DiskError()
{
	TEXT		errStr[100];

	EraseCur();
	ErrBeep();
	ErrBeep();

	switch (dosError) {
		case 0:
			strcpy(errStr, "Disk error.\n");
			break;

		case WRITE_PROTECT:
			strcpy(errStr, "The disk is write protected.\n");
			break;

		case NOT_READY:
			strcpy(errStr, "The disk drive is not ready.\n");
			break;

		default:
			sprintf(errStr, "Disk error:\n%s\n", diskErr[dosError]);
			break;
		}

	strcat(errStr, tryAgain);
	strcat(errStr, escQuitMsg);

	return (WindowPrint(errStr));
}

/* ETC
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"


COORD	Pri2Coord();
UWORD	Abs();
WORD		AToI();
STRPTR	IToA();
STRPTR	IToH();
STRPTR	strcpy();
STRPTR	strncpy();
STRPTR	strcat();
int		strcmp();
WORD		strlen();
STRPTR	Reverse();
UBYTE	lower();
STRPTR	GetRandom();
STRPTR	NoAction();
STRPTR	index();
STRPTR	SToLower();


#define	PRIBASE	48
#define	PRIWIDTH	12
#define	BACKPRI	4
#define	STRLEN	10

#define	IsUpper(c)	(c >= 'A' && c <= 'Z')


static	TEXT		str[STRLEN+1];

extern	BOOL		twoDrive;
extern	UBYTE	var[];

extern	UWORD	Random();




UWORD
Abs(x)
register	WORD	x;
/* Return the absolute value of x
*/
{
	return ((x < 0)? -x : x);
}




COORD
Pri2Coord(pri)
WORD		pri;
{
	return (PRIBASE + PRIWIDTH * (pri - BACKPRI - 1));
}




WORD
strlen (s)
/* Return the length of the string pointed to by 's'.
*/
register	STRPTR	s;
{
	register	STRPTR	t;

	t = s;
	while (*t++)
		;
	return (t - s - 1);
}



STRPTR
strcpy(d, s)
register	STRPTR	s, d;
{
	STRPTR	ptr = d;

	while (*d++ = *s++)
		;

	return (ptr);
}



STRPTR
strncpy(d, s, n)
register	STRPTR	s, d;
		WORD		n;
{
	STRPTR	ptr = d;

	while (--n && (*d++ = *s++))
		;
	*d++ = '\0';

	return (ptr);
}



STRPTR
strcat(s, t)
register	STRPTR	s, t;
{
	STRPTR	ptr = s;

	while (*s)
		++s;
	while (*s++ = *t++)
		;

	return (ptr);
}



int
strcmp(s, t)
register	STRPTR	s, t;
{
	for ( ; *s != '\0' && *s == *t ; ++s, ++t)
		;
	return (*s - *t);
}




WORD
AToI(str)
register	STRPTR	str;
{
	register	WORD		n;

	/* Scan off spaces
	*/
	for ( ; *str == ' ' ; str++)
		;

	/* Convert the number
	*/
	n = 0;
	while (*str >= '0' && *str <= '9')
		n = 10*n + *str++ - '0';

	return (n);
}




STRPTR
IToA(n)
register	UWORD	n;
{
	register	STRPTR	s;

	s = str;
	do
		*s++ = n % 10 + '0';
	while ((n /= 10) > 0);
	*s = '\0';

	return (Reverse(str));
}



STRPTR
LeadingZeros(s, fieldWidth)
		STRPTR	s;
register	UWORD	fieldWidth;
{
	register	UWORD	length;
			TEXT		tmpStr[STRLEN+1];

	length = strlen(strcpy(tmpStr, s));

	FillMem(str, STRLEN, '0');

	if (fieldWidth < length)
		fieldWidth = length;

	strcpy(str + fieldWidth - length, tmpStr);
	
	return (str);
}






STRPTR
IToH(n)
WORD		n;
{
	register	STRPTR	s;
	register	UBYTE	c;

	s = str;
	do	{
		c = n % 16;
		*s++ = c + ((c > 9)?  'a'-10 : '0');
	} while ((n /= 16) > 0);
	*s = '\0';

	return (Reverse(str));
}




STRPTR
Reverse(str)
STRPTR	str;
/* Reverse the string 'str' in place.
*/
{
			UBYTE	temp;
	register	STRPTR	s1, s2;

	s1 = str;
	s2 = str + strlen(str) - 1;
	while (s1 < s2) {
		temp = *s1;
		*s1++ = *s2;
		*s2-- = temp;
		}

	return (str);
}



UBYTE
lower(c)
register	UBYTE	c;
{
	return ((IsUpper(c))? c + ('a' - 'A') : c);
}



STRPTR
GetRandom(lp)
register	STRPTR	lp;
{
	UWORD	maxVal, minVal;

	minVal = *lp++;
	maxVal = *lp++;
	var[*lp++] = (Random() % (maxVal - minVal + 1)) + minVal;

	return (lp);
}



STRPTR
NoAction(lp)
STRPTR	lp;
/* A 'no action' action for filling the action table
*/
{
	return (lp);
}



STRPTR
index(s, c)
register	STRPTR	s;
register	UBYTE	c;
{
	while (*s != '\0' && *s != c)
		++s;

	return ((*s == c)? s : NULL);
}



STRPTR
SToLower(s)
register	STRPTR	s;
{
	register	STRPTR	t;

	for (t = s ; *t != '\0' ; ++t)
		*t = lower(*t);

	return (s);
}

/* EVENTS
** The event interface to the input device drivers.
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"event.h"

void			InitEv();
void			ResetEv();
void			PollDevices();
BOOL			PostEvent();
EVENT		*NextEvent();
EVENT		*WaitEvent();
EVENT		*Translate();
WORD			GetKey();
WORD			WaitChar();
WORD			ChkAcAb();
WORD			WaitAcAb();
void			ButtonToChar();




#define	BUFSIZE	20


static	EVENT	eventBuf[BUFSIZE];
		EVENT	*ebHead, *ebTail;

extern	KEYMAP	keyMap[];
extern	LONG		sysTimer;




void
InitEv()
/* Initialize the device drivers
*/
{
	InitJoy();
	ResetEv();
}




void
ResetEv()
/* Clear the device event buffer and any events waiting in the devices
*/
{
	FlushKbd();
	FlushButtons();
	ebHead = ebTail = eventBuf;
}



void
PollDevices()
/* Read the various devices, posting any events in the event buffer.
*/
{
	PollButtons();
	PollKbd();
}




BOOL
PostEvent(type, value)
WORD		type, value;
/* Add an event to the event buffer.  Return 1 if there was room, 0 otherwise.
*/
{
	register	EVENT	*svdHead;
			BOOL		retval;

	/* Add the event to the buffer at the current head
	*/
	retval = 0;
	ebHead->type = type;
	ebHead->val = value;

	/* Advance the head.  If the new head is equal to the tail, then
	** the buffer is full, so retract the head back to its original
	** position.
	*/
	svdHead = ebHead;
	if (++ebHead >= &eventBuf[BUFSIZE])
		ebHead = eventBuf;
	if (ebHead != ebTail)
		return (TRUE);
	else {
		ebHead = svdHead;
		return (FALSE);
		}
}




EVENT	*
NextEvent()
/* Return a pointer to the next event in the event buffer.  If there are
** none in the buffer, return NULL.
*/
{
	register	EVENT	*event;

	event = (ebHead == ebTail)? NULL : ebTail++;

	if (ebTail >= &eventBuf[BUFSIZE])
		ebTail = eventBuf;

	return (event);
}



EVENT	*
WaitEvent()
{
	register	EVENT	*event;
			LONG		oldSysTimer;

	oldSysTimer = sysTimer;
	while ((event = NextEvent()) == NULL)
		if (oldSysTimer != sysTimer) {
			PollJoy();
			oldSysTimer = sysTimer;
			}

	return (event);
}





EVENT	*
Translate(ePtr)
register	EVENT	*ePtr;
/* Translate a character to a controller or a character to a direction key
** if necessary.
*/
{
	register	KEYMAP	*keyPtr;

	if (ePtr->type == CHAR) {
		/* Do a controller translation
		*/
		for (keyPtr = keyMap ; keyPtr->key != 0 ; ++keyPtr)
			if (ePtr->val == keyPtr->key) {
				ePtr->type = CONTROL;
				ePtr->val = keyPtr->keyval;
				break;
				}

		/* Translate the char to a direction key if appropriate
		*/
		DirTranslate(ePtr);
		}

	return (ePtr);
}





WORD
GetKey()
/* Get a character.  Return 0 if none available.
*/
{
	register	WORD		v, t;
			EVENT	*event;

	if ((event = NextEvent()) == NULL)
		return (0);

	ButtonToChar(event);
	t = event->type;
	v = event->val;

	if (t == CHAR)
		return (v);
	else
		return (-1);
}




WORD
WaitChar()
/* Wait for a character, then return it.  Treat the ESC key (which is the
** pause controller) as a character.
*/
{
	register	WORD		c;

	while ((c = GetKey()) == 0 || c == -1)
		;
	return (c);
}




WORD
ChkAcAb()
/* Check if either ACCEPT or ABORT has been selected.  Return the value if
** so, zero otherwise.
*/
{
	register	WORD		c;

	if ((c = GetKey()) == '\r')
		return (ACCEPT);
	else if (c == ESC)
		return (ABORT);
	else
		return (-1);
}



WORD
WaitAcAb()
/* Wait for and return either 'ACCEPT' or 'ABORT'
*/
{
	register	WORD		c;

	/* Clear devices
	*/
	ResetEv();

	/* Wait for the appropriate key
	*/
	while ((c = ChkAcAb()) == -1)
		;

	return (c);
}



void
ButtonToChar(ePtr)
register	EVENT	*ePtr;
{
	register	WORD		c;

	if (ePtr->type == CHAR) {
		if ((c = ePtr->val) == B0_CLICK || c == B0_DBLCLICK)
			ePtr->val = '\r';
		else if (c == B1_CLICK || c == B1_DBLCLICK)
			ePtr->val = ESC;
		}
}

/* FINDPOSN
** Find a position for an object on the screen
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"aniobj.h"


void		FindPosn();
BOOL		GoodPos();


extern	BOOL		Collide();
extern	BOOL		CanBHere();


extern	COORD	horizon;
extern	ANIOBJ	*aniObj;



void
FindPosn(obj)
register	ANIOBJ	*obj;
/* Find a position for object 'obj' where it does not collide with any
** unappropriate objects or priority regions.  If the object can't be in
** its current position, first try moving it left, then right, then start
** scanning in a spiral pattern for a position at which it can be placed.
*/
{
	register	COORD	legLen;
			WORD		legDir,legCnt;		/* variables for spiral scan */
/*
			COORD	savex;
			COORD	delta;
*/
	
	if (obj->y <= horizon && (obj->control & IGNRHRZ) == 0)
		obj->y = horizon + 1;

	/* If current position is OK, return
	*/
	if (GoodPos(obj) && !Collide(obj) && CanBHere(obj))
		return;
	
	/* Try moving horizontally by up to object's baseline
	*/
/*	savex = obj->x;
	for (delta = 1 ; delta <= obj->xsize ; ++delta) {
		if ((obj->x = savex - delta) < MINX)
			obj->x = MINX;
		if (GoodPos(obj) && !Collide(obj) && CanBHere(obj))
			return;

		if ((obj->x = savex + obj->xsize) > MAXX + 1)
			obj->x = MAXX + 1 - obj->xsize;
		if (GoodPos(obj) && !Collide(obj) && CanBHere(obj))
			return;
		}
*/	
	/* Start scan
	*/
	legDir = 0;
	legLen = legCnt = 1;
	while (!GoodPos(obj) || Collide(obj) || !CanBHere(obj)) {
		switch (legDir) {
			case	0:			/* move left */
				--obj->x;
				if (--legCnt == 0) {
					legDir = 1;
					legCnt = legLen;
					}
				break;
			case	1:			/* move down */
				++obj->y;
				if (--legCnt == 0) {
					legDir = 2;
					legCnt = ++legLen;
					}
				break;
			case	2:			/* move right */
				++obj->x;
				if (--legCnt == 0) {
					legDir = 3;
					legCnt = legLen;
					}
				break;
			case	3:			/* move up */
				--obj->y;
				if (--legCnt == 0) {
					legDir = 0;
					legCnt = ++legLen;
					}
				break;
			}
		}
}



BOOL
GoodPos(obj)
register	ANIOBJ	*obj;
/* Return TRUE if the object's position puts it on the screen, FALSE otherwise
*/
{
	return (obj->x >= MINX && (obj->x + obj->xsize) <= MAXX + 1
	     && (obj->y - obj->ysize) >= MINY - 1 && obj->y <= MAXY
	     && ((obj->control & IGNRHRZ) || obj->y > horizon));
}

/* FOLLOW
** The object 'obj' is supposed to follow ego.
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"
#include	"aniobj.h"


/* Distance from ego which is considered to be completion of the motion
*/
#define	endDist	parms[0]

/* Flag to set on completion of the motion
*/
#define	endFlag	parms[1]

/* Distance to move in current direction (for random search)
*/
#define	randDist	parms[2]


extern	UWORD	Abs();
extern	UWORD	Random();
extern	WORD		MoveDir();
extern	WORD		RandmDir();

extern	ANIOBJ	*aniObj;





void
Follow(obj)
register	ANIOBJ	*obj;
{
	WORD		dir;
	COORD	ecx,ocx;
	COORD	maxDist;
	
	/* Get coordinates of center of object's & ego's bases
	*/
	ecx = ego->x + (COORD) ego->xsize/2;
	ocx = obj->x + (COORD) obj->xsize/2;
	
	/* Get direction from object's center to ego's center
	*/
	dir = MoveDir(ocx,obj->y,ecx,ego->y,obj->endDist);
	
	/* If the direction is zero, the object and ego have collided -- signal
	** completion.
	*/
	if (dir == 0) {
		obj->dir = 0;
		obj->motion = NORMAL;
		Set(obj->endFlag);
		return;
		}
	
	/* If the object has not moved since last time, assume it is blocked and
	** move in a random direction for a random distance no greater than the
	** distance between the object and ego
	*/
	/* NOTE: randDist = -1 indicates that this is initialization, and thus
	** we don't care about the previous position
	*/
	if (obj->randDist == -1)
		obj->randDist = 0;
	else if (obj->control & STOPPED) {
		/* Make sure that the object goes in some direction
		*/
		while ((obj->dir = RandmDir()) == 0)
			;
	
		/* Average the x and y distances to the object for movement limit
		*/
		maxDist = (Abs(ocx - ecx) + Abs(obj->y - ego->y))/2 + 1;
	
		/* Make sure that the distance is at least the object stepsize
		*/
		if (maxDist <= obj->stepsize)
			obj->randDist = obj->stepsize;
		else
			while ((obj->randDist = Random() % maxDist) < obj->stepsize)
				;
	
		return;
		}
	
	/* If 'randDist' is non-zero, keep moving the object in the current
	** direction.
	*/
	if (obj->randDist != 0) {
		if ((obj->randDist -= obj->stepsize) < 0)
			obj->randDist = 0;		/* done with the random movement */
		return;
		}
	
	/* Otherwise, just move the object towards ego.  Whew...
	*/
	obj->dir = dir;
}

/* RESTORE
 * Restore the game to a given state, based on the game script
 *
 *	compile: MWC
 *
 * Change History
 *	87.05.27 15:33	JAS
 *		Moved the SetView of an object's view outside the 'if animated'
 *		test in the object re-draw loop.
 */

#include	"types.h"
#include	"game.h"
#include	"aniobj.h"
#include	"picobj.h"
#include	"script.h"
#include	"logic.h"


void		Restore();


extern	BOOL		picVisible;
extern	ANIOBJ	*aniObj, *aniEnd;
extern	PICOBJ	picObj;
extern	WORD		picNo;

extern	SCRIPT	*NextScript();
extern	STRPTR	GetMem();
extern	LOGNODE	*LoadLog();




void
Restore()
/* Reload the necessary things c"INIT.C         WX     gQ"INITMACH.VGAJ   4g J    c"MENU.C      !   ~n !    a)"KBDDRV.C    3   z 3    mE"KEYMAP.C            mE"LOG.C       H    H    mE"HOBJSBRS.OBJ   ֜     P#"INTRPT.OBJ          P#"MEMMGR.C       ;     ~"MOTION.C       6     "MOVEOBJS.C  0
   ̾ 0
    mE"MOVETO.C    T    T    Zy"JOYDRV.C       P     -x"INITDIR.OBJ v     v     n"NEWROOM.C   z   Z z    mE"OBJACT.C            mE"OBJLIST.C      a     '_y"PARSE.C        J      a"PICOBJ.C            mE"PICTURE.C   3    3    dS"POSITION.C  
   ) 
    mE"PRIORITY.C     v4     mE"RESTART.C   ^   7 ^    tT"SQSG.3      
   \; 
    r"SAVEAREA.C     2F     mE"GETGAME.C   $   J $    #"SAVENAME.C     o     $"EQUIPCHK.ASM    pw      ma>"SCRIPT.C       |     C="SEGMENT.C           Kw"based on the current (i.e. restored)
 * variables
 */
{
	register	SCRIPT	*scriptPtr;
	register	UWORD	i;
			ANIOBJ	*obj;
			UWORD	objCtrl;

	/* Make certain `PlayIt' is not called during timer interrupt
	 */
	StopSnd();

	/* Reset all lists to their base states
	 */
	ResetLists();

	/* Turn off scripting, so as to prevent the restore from adding
	 * to the script.
	 */
	ScriptOff();

	/* 'Erase' all objects, remembering their control bytes. In a memory
	 * conservation move, the control bytes are stored in the object's X
	 * coordinate field which in turn has been saved in the object's number
	 * field. All these fields are restored to their original values when
	 * the objects are redrawn at the end of this subroutine.
	 */
	for (obj = aniObj ; obj < aniEnd ; ++obj) {
		obj->num = obj->x;			/* save X coordinate */
		obj->x = obj->control;		/* save control bytes */
		if (obj->control & ANIMATED) {
			obj->control &= ~DRAWN;
			obj->control |= UPDATE;
			}
		}

	/* Free all allocated memory
	 */
	RestoreAll();
	FreeAll();

	picVisible = FALSE;

	/* Scan the script, executing each specified action
	 */
	OpenScript();
	while ((scriptPtr = NextScript()) != NULL) {
		i = scriptPtr->who;
		switch (scriptPtr->action) {
			case S_LOADLOG:
				RestoreScanOfs(LoadLog(i));
				break;
			case S_LOADVIEW:
				LoadView(i, TRUE);
				break;
			case S_LOADPIC:
				LoadPic(i);
				break;
			case S_LOADSND:
				LoadSnd(i);
				break;
			case S_DRAWPIC:
				Picture(i);
				break;
			case S_ADDPIC:
				scriptPtr = NextScript();
				picObj.view = scriptPtr->action;
				picObj.loop = scriptPtr->who;
				scriptPtr = NextScript();
				picObj.cel = scriptPtr->action;
				picObj.x = scriptPtr->who;
				scriptPtr = NextScript();
				picObj.y = scriptPtr->action;
				picObj.pri = scriptPtr->who;
				AddToPic();
				break;
			case S_DSCRDPIC:
				DiscardPic(i);
				break;
			case S_DSCRDVIEW:
				DiscardView(i);
				break;
			case S_OVERLAYPIC:
				OverlayPic(i);
				break;
			}
		}

	/* Re-enable scripting
	 */
	ScriptOn();

	/* Draw all objects in the animation tables
	 */
	for (obj = aniObj, i = 0 ; obj < aniEnd ; ++obj, ++i) {
		objCtrl = obj->x;			/* get control bytes */
		obj->x = obj->num;			/* restore X coordinate */
		obj->num = i;				/* restore object's number */
		if (FindView(obj->view))
			SetView(obj, obj->view);
		if (objCtrl & ANIMATED) {
			if (objCtrl & DRAWN) {
				DrawObj(obj->num);
                                /* Force reinitialization of follow path
                                */
                                if (obj->motion == FOLLOW)
                                	obj->parms[2] = -1;
                                }
			if ((objCtrl & (UPDATE | DRAWN)) == DRAWN)
				StopUpdate(obj);

                        /* Reset control bits to pre-restore settings
                        */
                        obj->control = objCtrl;
			}
		}

	/* Show what we've drawn
	 */
	EraseCur();
	CancelLine();
	BackToScrn();
	picVisible = TRUE;

	DisplayStatusLine();
	DisplayInput();
}

/* INIT
** Initialize stuff for KQ (& load overlays)
**
**	compile: MWC
**
** Change History:
** 87.04.30 9:43	JAS
**	ResetAll() now properly sets up the NUM_VOICES and HAS_NOISE vars
**	properly (used to set up for JR & TD on the PC).
** 07/04/87  10:07:27	JAS
**	ResetAll() now decrypts 'object', which is encrypted by 'mkobj'.
** 25/03/87  11:17:23	JAS
**	Removed references to egoDir.
** 18/02/87  16:10:19	JAS
** 	Changed 'wordFileName' and 'objectFileName' from TEXT to STRPTR,
** 	so that they can be reassigned by the test version of GetDirs.
*/

#include	"types.h"
#include	"game.h"
#include	"aniobj.h"
#include	"object.h"
#include	"segio.h"


void		Init();
void		ResetAll();
void		ResetLists();


ANIOBJ	*aniObj;
ANIOBJ	*aniEnd;
WORD		aniLen;
OBJECT	*object;
OBJECT	*objEnd;
WORD		objLen;


STRPTR	wordFileName = "words.tok";
STRPTR	objectFileName = "object";



extern	ANIOBJ	*poAniEntry;
extern	UBYTE	var[];
extern	WORD		picNo;
extern	BOOL		blocking, userCtrl;
extern	STRPTR	wordTbl;
extern	WORD		machType, monType;
extern	WORD		aniInt;
extern	UWORD	segLen;

extern	STRPTR	LoadFile();
extern	STRPTR	GetMem();





void
Init()
{
	/* Do the machine specific initializations
	*/
	InitMachine();

	/* Get the segment directories
	*/
	GetDirs();

	/* Set the text attribute to default, and display the input line.
	*/
	_SetTextAtr(15, 0);			/* white on black */
	DisplayInput();
	
	/* Initialize the input event routines
	*/
	InitEv();

	/* Load the word tables
	*/
	wordTbl = LoadFile(wordFileName, NULL);

	/* Initialize the various lists
	*/
	InitLog();
	InitView();
	InitSnd();
	InitPic();

	/* Load object tables and initialize all variables
	*/
	ResetAll();

	/* Load the room 0 logics
	*/
	LoadLog(0);

	SetBase();		/* set this as the base of free memory */

	/* Turn sounds on
	*/
	Set(SOUNDON);
}




void
ResetAll()
/* Load the object tables and reset all variables.  This routine should
** put the game in a state for a restart.  Note that the word tables and
** room 0 logics remain resident.
*/
{
	register	ANIOBJ	*obj;
	register	WORD		i;
			WORD		numAni;
			WORD		objEndOfs;

	/* Load the object table
	*/
	if (object != NULL)		/* Point to beginning of object table */
		--object;			/* if already loaded. */
	object = (OBJECT *)	LoadFile(objectFileName, object);
	Encrypt(object, (STRPTR) object + segLen);
	objLen = segLen - sizeof(OBJECT);
	numAni = object->room;
	objEndOfs = W8086(object->nameofs);
	++object;
	objEnd = (OBJECT *) ((STRPTR) object + objEndOfs);

	/* Get the number of animated objects from the room number of the
	** first entry of the object table, point past that entry to the
	** objects, and allocate and initialize aniObj.  Add one object at
	** the end of the table for use by picobj
	*/
	++numAni;
	if (aniObj == NULL)
		aniObj = (ANIOBJ *) GetMem(aniLen = numAni * sizeof(ANIOBJ));
	FillMem(aniObj, aniLen, 0);
	aniEnd = aniObj + numAni;
	poAniEntry = aniEnd - 1;
	for (i = 0, obj = aniObj ; i < numAni ; ++i, ++obj)
		obj->num = i;
	
	/* Reset variables, flags, controllers, and various lists
	*/
	FillMem(var, NUMVARS, 0);
	ClearFlags();
	ClearControl();
	ResetLists();

	RestoreAll();

	/* Reset various variables
	*/
	var[MACHINE_TYPE] = machType;
	var[MONITOR_TYPE] = monType;
	var[INPUTLEN] = MAXINPUT + 1;
	Set(INITLOGS);				/* set 'initialize logics' flag */
	userCtrl = TRUE;
	picNo = 0;
	blocking = 0;

	/* Set vars and flags relating to the sound capabilities of the machine.
	*/
	if (machType == PC)
		var[NUM_VOICES] = 1;
	else {
		var[NUM_VOICES] = 3;
		Set(HAS_NOISE);
		}
}



void
ResetLists()
{
	ResetLog();
	ResetView();
	ResetSnd();
	ResetPic();
}

/* INITMACH
** Machine specific initializations.
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"
#include	"screen.h"


void		InitMachine();
void		InitGraphics();
void		ResetMachine();



/* Overlay numbers of graphics routines
*/
#define	PCGRAF		1		/* PC graphics */
#define	JRGRAF		2		/* PCjr graphics */
#define	XTGRAF		3		/* EGA graphics */
#define	HGRAF		4		/* Hercules graphics */
#define	VGGRAF		5		/* VGA/MCGA graphics (PS/2) */

/* Overlay numbers of object routines
*/
#define	IBMOBJS		6		/* IBM objects */
#define	HGCOBJS		7		/* Hercules objects */



WORD		saveMode;

extern	WORD		monType, machType;



void
InitMachine()
{
	register	COUNT	i;

	/* Clear the device event buffer and any events waiting in the devices
	*/
	ResetEv();

	/* Initialize the graphics system.
	*/
	InitGraphics();

	/* Set up the interrupt handlers that we will use.
	*/
	SetInterrupts();

	/* Close all the file handles which DOS has given us in order
	** to get enough file handles to do our thing.
	*/
	for (i = 0 ; i < 5 ; ++i)
		close(i);
}



void
InitGraphics()
/* Load the appropriate overlays and initialize the graphics
*/
{
	register	WORD		objOverlay, grafOverlay;

	/* Get and save current screen mode
	*/
	saveMode = GetMode();

	if (monType == MONO) {
		objOverlay = HGCOBJS;
		grafOverlay = HGRAF;
		}
	else {
		objOverlay = IBMOBJS;
		if (monType == EGA)
				grafOverlay = XTGRAF;
		else if (machType == PC)
				grafOverlay = PCGRAF;
		else
				grafOverlay = JRGRAF;
		}
	Ovload(grafOverlay);
	Ovload(objOverlay);
	SetDisp();
}	




void
ResetMachine()
{
	/* Close the log file
	*/
	CloseLogFile();

	/* Reset any interrupt vectors which we're using
	*/
	ResetInterrupts();

	/* Restore original screen mode
	*/
	SetMode(saveMode);
}

/* MENU
** Routines for handling menus in AGI
**
**	compile: MWC
**
** Change History:
** 87 Sept pmk
**	Suppress halftone on VGA
** 20/02/87  10:34:18	JAS
**	Added a call to ButtonToChar() in DoMenu() so that the joystick
**	buttons can be used to select from the menu.
**
** 18/02/87  15:00:44	JAS
**	Mucked around to ensure that menus with no items will not either
**	print garbage or go into endless loops.
*/

#include	"types.h"
#include	"game.h"
#include	"event.h"
#include	"screen.h"

STRPTR	SetMenu();
STRPTR	SetMenuItem();
STRPTR	SubmitMenu();
STRPTR	EnableMenu();
void		EnableAllMenus();
STRPTR	DisableMenu();
void		ChangeItem();
STRPTR	MenuInput();
void		DoMenu();

void		ShowMenu();
void		PutAway();
void		Select();
void		Deselect();
void		ComputeMenuWindow();



#define	DISABLE	0
#define	ENABLE	1

#define	CHARWIDTH		4		/* in our coordinates */
#define	VMARGIN		charHeight
#define	HMARGIN		CHARWIDTH

typedef	struct	menuHead {
	struct	MenuItem	*next;
	struct	MenuItem	*prev;
	STRPTR			name;
	COUNT			row, col;
	BOOL				enabled;
	}	MENUHEADER;


typedef	struct	MenuItem {
	MENUHEADER		h;
	COUNT			ctrl;
	}	MENUITEM;


typedef	struct	Menu {
	MENUHEADER		h;
	struct	MenuItem	*items;
	struct	MenuItem	*curItem;
	COUNT			height;
	}	MENU;


BOOL		activateMenu;
WORD		menuCol, itemRow, itemCol;
BOOL		menuSubmitted;
MENU		*menuBase, *curMenu;
MENUITEM	*curItem;
UWORD	menuPos, menuDim;

extern	COUNT	picTop;
extern	COUNT	charHeight; 		/* modified in EQUIPCHK.ASM for HGC */
extern	BOOL		showStatus, halfTone;

extern	STRPTR	GetMsgPtr();
extern	EVENT	*WaitEvent();
extern	WORD		monType;



STRPTR
SetMenu(lp)
register	STRPTR	lp;
{
	register	MENU		*mp;
	register	STRPTR	menuName;

	menuName = GetMsgPtr(*lp++);

	if (menuSubmitted == TRUE)
		return (lp);

	/* Allocate space for the next menu and link it into the menu list
	*/
	mp = (struct Menu *) GetMem(sizeof(struct Menu));
	if (menuBase == NULL) {
		menuBase = mp;
		menuCol = 1;
		}
	else {
		/* If previous menu didn't have any items, disable it.
		*/
		if (curMenu->items == NULL)
			curMenu->h.enabled = FALSE;
		curMenu->h.next = mp;
		mp->h.prev = curMenu;
		}
	mp->h.next = menuBase;
	menuBase->h.prev = mp;
	curMenu = mp;

	/* Set the position of this menu name in the menu strip (leave two
	** chars between menu titles).
	*/
	mp->h.row = 0;
	mp->height = 0;
	mp->h.name = menuName;
	mp->h.col = menuCol;
	mp->h.enabled = TRUE;
	mp->items = NULL;
	menuCol += strlen(menuName) + 1;

	/* Initialize stuff for the menu items to follow
	*/
	curItem = NULL;
	itemRow = 1;

	return (lp);
}





STRPTR
SetMenuItem(lp)
register	STRPTR	lp;
{
	register	MENUITEM	*ip;
	register	STRPTR	itemName;
			UBYTE	itemController;

	itemName = GetMsgPtr(*lp++);
	itemController = *lp++;

	if (menuSubmitted == TRUE)
		return (lp);

	/* Allocate a menu item structure and link it in
	*/
	ip = (struct MenuItem *) Getmem(sizeof(struct MenuItem));
	if (curItem == NULL) {
		curMenu->curItem = curMenu->items = ip;
		ip->h.prev = ip;
		}
	else {
		curItem->h.next = ip;
		ip->h.prev = curItem;
		}
	ip->h.next = curMenu->items;
	curMenu->items->h.prev = ip;
	curItem = ip;

	/* Position the menu item in the menu
	*/
	ip->h.name = itemName;
	if (itemRow == 1) {
		if (curMenu->h.col + strlen(itemName) < 39)
			itemCol = curMenu->h.col;
		else
			itemCol = 39 - strlen(itemName);
		}
	ip->h.row = ++itemRow;
	ip->h.col = itemCol;
	ip->h.enabled = TRUE;
	ip->ctrl = itemController;

	++curMenu->height;

	return (lp);
}





STRPTR
SubmitMenu(lp)
STRPTR	lp;
{
	/* If the last menu didn't have any items, disable it.
	*/
	if (curMenu->items == NULL)
		curMenu->h.enabled = FALSE;

	/* Set heap base above menu structures.
	*/
	SetBase();

	/* Make the first menu the current one.
	*/
	curMenu = menuBase;
	curItem = curMenu->items;
	menuSubmitted = TRUE;
	return (lp);
}




STRPTR
EnableMenu(lp)
register	STRPTR	lp;
{
	ChangeItem(*lp++, ENABLE);
	return (lp);
}




void
EnableAllMenus()
/* Enable all the menus in the menustrip.
*/
{
	register	struct	Menu		*mp;
	register	struct	MenuItem	*ip;

	if ((mp = menuBase) != NULL) {
		do	{
			if (mp->h.enabled) {
				ip = mp->items;
				do	{
					ip->h.enabled = TRUE;
					ip = ip->h.next;
				} while (ip != mp->items);
				}
			mp = mp->h.next;
		} while (mp != menuBase);
		}
}



STRPTR
DisableMenu(lp)
register	STRPTR	lp;
{
	ChangeItem(*lp++, DISABLE);
	return (lp);
}





void
ChangeItem(c, how)
register	COUNT	c;
		COUNT	how;
/* Enable/Disable (depending on 'how'), the menu item whose controller is 'c'.
*/
{
	register	struct	Menu		*mp;
	register	struct	MenuItem	*ip;

	mp = menuBase;
	do	{
		if (mp->h.enabled) {
			ip = mp->items;
			do	{
				if (ip->ctrl == c)
					ip->h.enabled = (how == ENABLE);
				ip = ip->h.next;
			} while (ip != mp->items);
			}
		mp = mp->h.next;
	} while (mp != menuBase);
}




STRPTR
MenuInput(lp)
{
	if (IsSet(ENABLE_MENU))
		activateMenu = TRUE;
	return (lp);
}




void
DoMenu()
{
	register	MENU		*mp;
	register	MENUITEM	*ip;
			EVENT	*ev;
			
	SaveCurPos();
	SaveTextAtr();

	ClearLine(0, MakeBackColor(15));
	mp = menuBase;
	do	{
		Deselect(mp);
		mp = mp->h.next;
	} while (mp != menuBase);

	mp = curMenu;
	ip = curItem;
	ShowMenu(mp);

	forever {
		ev = WaitEvent();
		ButtonToChar(ev);
		DirTranslate(ev);
		switch (ev->type) {
			case CHAR:
				switch (ev->val) {
					case '\r':
						if (!ip->h.enabled)
							continue;
						PostEvent(CONTROL, ip->ctrl);

					case ESC:
						PutAway(mp, ip);

						RestoreTextAtr();
						RestoreCurPos();
						if (showStatus)
							DisplayStatusLine();
						else
							ClearLine(0, 0);
						activateMenu = FALSE;
						return;
					}
				break;

			case DIR:
				switch (ev->val) {
					case 1:				/* up */
						Deselect(ip);
						ip = ip->h.prev;
						Select(ip);
						break;

					case 2:				/* top of cur menu */
						Deselect(ip);
						ip = mp->items;
						Select(ip);
						break;

					case 3:				/* right */
						PutAway(mp, ip);
						for (mp = mp->h.next ; !mp->h.enabled ; mp = mp->h.next)
							;
						ip = mp->curItem;
						ShowMenu(mp);
						break;

					case 4:				/* bottom of cur menu */
						Deselect(ip);
						ip = mp->items->h.prev;
						Select(ip);
						break;

					case 5:				/* down */
						Deselect(ip);
						ip = ip->h.next;
						Select(ip);
						break;

					case 6:				/* rightmost menu */
						PutAway(mp, ip);
						mp = menuBase->h.prev;
						ip = mp->curItem;
						ShowMenu(mp);
						break;

					case 7:				/* left */
						PutAway(mp, ip);
						for (mp = mp->h.prev ; !mp->h.enabled ; mp = mp->h.prev)
							;
						ip = mp->curItem;
						ShowMenu(mp);
						break;

					case 8:				/* leftmost menu */
						PutAway(mp, ip);
						mp = menuBase;
						ip = mp->curItem;
						ShowMenu(mp);
						break;
					}
			}

		curMenu = mp;
		curItem = ip;
		}
}




void
ShowMenu(mp)
register	MENU	*mp;
{
	register	MENUITEM	*ip;

	Select(mp);

	ComputeMenuWindow(mp);
	OpenWndw(menuPos, menuDim, 0x000f);

	if ((ip = mp->items) != NULL) {
		do	{
			if (ip == mp->curItem)
				Select(ip);
			else
				Deselect(ip);
			ip = ip->h.next;
		} while (ip != mp->items);
		}
}




void
PutAway(mp, ip)
register	MENU		*mp;
register	MENUITEM	*ip;
{
	mp->curItem = ip;
	Deselect(mp);
	CloseWndw(menuPos, menuDim);
}




void
Select(ip)
register	MENUITEM	*ip;
{
	SetCur(ip->h.row, ip->h.col);
	_SetTextAtr(MakeForeColor(15), MakeBackColor(0));
	if (!ip->h.enabled && monType != VGA)
		halfTone = TRUE;
	printf(ip->h.name);
	halfTone = FALSE;
}




void
Deselect(ip)
register	MENUITEM	*ip;
{
	COUNT	row, col;

	row = ip->h.row;
	col = ip->h.col;

	_SetTextAtr(MakeForeColor(0), MakeBackColor(15));
	SetCur(row, col);
	if (!ip->h.enabled && monType != VGA)
		halfTone = TRUE;
	printf(ip->h.name);
	halfTone = FALSE;
}





void
ComputeMenuWindow(mp)
register	MENU		*mp;
{
	COUNT	height, width;

	width = strlen(mp->items->h.name);
	height = mp->height;

	/* Compute window size and position and put them into the appropriate
	** bytes of the words.
	*/
	menuDim = ((height * charHeight + 2 * VMARGIN) << 8)
				| (width * CHARWIDTH + 2 * HMARGIN);

	menuPos = (((mp->items->h.col - 1) * CHARWIDTH) << 8)
				| ((height + 2 - picTop) * charHeight + VMARGIN - 1);
}

/* KBDDRV
** Keyboard driver for adventure games
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"
#include	"event.h"


void			FlushKbd();
void			PollKbd();
WORD			IsDir();
void			DirTranslate();


extern	COUNT	machType;
extern	KEYMAP	directionKey[], tandyDir[];



void
FlushKbd()
/* Clear the keyboard buffer
*/
{
	while (GetChar())
		;
}





void
PollKbd()
/* Post keyboard events.
*/
{
	register	WORD		c, value;

	while ((c = GetChar()) != 0) {
		if ((value = IsDir(c)) != -1)
			PostEvent(DIR, value);
		else
			PostEvent(CHAR, c);
		}
}




WORD
IsDir(c)
register	WORD		c;
/* If c is a direction key, return the corresponding direction, else -1.
** This also handles toggling of movement when under keyboard control.
*/
{
	register	KEYMAP	*kp;
			WORD		value;

	value = -1;

	/* See if the key is a direction key
	*/
	for (kp = directionKey ; kp->key != 0 ; ++kp)
		if (c == kp->key) {
			value = kp->keyval;
			break;
			}

	return (value);
}




void
DirTranslate(ePtr)
register	EVENT	*ePtr;
{
	register	KEYMAP	*keyPtr;

	if (machType == TD) {
		for (keyPtr = tandyDir ; keyPtr->key != 0 ; ++keyPtr)
			if (ePtr->val == keyPtr->key) {
				ePtr->type = DIR;
				ePtr->val = keyPtr->keyval;
				break;
				}
		}
}

/* KEYMAP
** The mapping of keys to codes used internally by the interpreter.
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"
#include	"event.h"
#include	"keydefs.h"



KEYMAP	directionKey[] = {
		UPARW, 1,
		PGUP, 2,
		RGHTARW, 3,
		PGDN, 4,
		DNARW, 5,
		END, 6,
		LFTARW, 7,
		HOME, 8,
		0, 0
		};

KEYMAP	tandyDir[] = {
		'8', 1,
		'9', 2,
		'6', 3,
		'3', 4,
		'2', 5,
		'1', 6,
		'4', 7,
		'7', 8,
		'5', 0,
		0, 0
		};

/* LOG
** Write the input line out to a log file for debugging/design
**
**	compile: MWC
**
*/

#include	"types.h"
#include	"game.h"


STRPTR	Log();

FILE_HANDLE	logFile = NO_HANDLE;
TEXT			logFileName[] = "logfile";


extern	TEXT			prevLine[];
extern	UBYTE		var[];

extern	FILE_HANDLE	open(), creat();




STRPTR
Log(lp)
STRPTR	lp;
{
	register	FILE_HANDLE	fd;
			TEXT			outLine[1000];
			COUNT		theMsg;

	theMsg = *lp++;

	if (logFile == NO_HANDLE)
		OpenLogFile();

	/* If the log file is open and we are able to duplicate the handle,
	** log the messages.  Otherwise, bag it.
	*/
	if (logFile != NO_HANDLE && (fd = Duplicate(logFile)) != NO_HANDLE) {
		/* Write the room number, input line, and message to the file
		*/
		sprintf(outLine, "\n\nRoom %d\nInput line: %s\n", var[CURROOM], prevLine);
		write(fd, outLine, strlen(outLine));
		Print(outLine, GetMsgPtr(theMsg), 78);
		write(fd, outLine, strlen(outLine));
	
		close(fd);
		}

	return (lp);
}



OpenLogFile()
{
	/* Open (or create) the file and seek to the end
	*/
	if (logFile == NO_HANDLE) {
		if ((logFile = open(logFileName, 2)) == NO_HANDLE)
			logFile = creat(logFileName, 0);
		lseek(logFile, 0L, 2);
		}
}



CloseLogFile()
{
	if (logFile != NO_HANDLE) {
		close(logFile);
		logFile = NO_HANDLE;
		}
}

 A;  cgroupcodedatadgrou
HB2S =
 HBS   HCVB! 
 HDWq 
 HIG    HIRT '
 HSH  
 HSS 
 HTST   	HVideoInt5  
patrnMasks    t;IOBJSBRS
;IBM object animation subroutines

cgroup	group code
dgroup	group data
assume	cs:cgroup,ds:dgroup,es:dgroup


public	ISSB, IRSB, IIO

extrn	s_ram:word
extrn	SetIt:near, ResetIt:near, getShdwOfst:near, MirrorCell:near

include	macro.ah
include	game.ah
include	cmequ8s.ah

data	segment byte public 'data'
data	ends	;dummy segment

code	segment byte public 'code'


;|-----------------------------------------------------------------------------|
;|      This subroutine moves a block of shadow ram background into a save     |
;|  area that can be restored later by the `IRSB' subroutine.                  |
;|-----------------------------------------------------------------------------|

ISSB:
	enter	sbSaveArea

	mov	bp,sbSaveArea		;point BX to save area
	mov	al,byte ptr[bp+saY]	;get save area's upper left corner Y coord
	mov	ah,byte ptr[bp+saX] 	;get save area's upper left corner X coord
	call	getShdwOfst		;get offset in shadow ram of point X,Y
	mov	si,di			;SI = shadow ram offset of lower left corner
	mov	ah,byte ptr[bp+saHeight]
	mov	al,byte ptr[bp+saWidth]
	mov	di,[bp+saBitMap]	;DI = pointer to background save area

	push	ds		;save data addressing
	mov	ds,s_ram	;establish shadow ram addressing
	xor	dx,dx
	mov	cx,dx
	mov	dx,shdw_lnth
	sub	dl,al		;compute next line offset factor (nlof)

SBLoop:
	mov	cl,al		;set CX to # of bytes to save (object width)
	rep	movsb		;save background
	add	si,dx		;move to next line to be saved
	dec	ah		;are there more lines to be saved?
	jnz	SBLoop		;yes

	pop	ds		;restore data addressing

	exit			;return control to calling routine


;|-----------------------------------------------------------------------------|
;|      This subroutine restores a block of shadow ram background from a save  |
;|  area that was filled by the `ISSB' subroutine.			       |
;|-----------------------------------------------------------------------------|

IRSB:
	enter	rbSaveArea

	mov	bp,rbSaveArea		;point BX to save area structure
	mov	al,byte ptr[bp+saY]	;get save area's lower left corner Y coord
	mov	ah,byte ptr[bp+saX] 	;get save area's lower left corner X coord
	call	getShdwOfst		;get offset in shadow ram of point X,Y
	mov	si,[bp+saBitMap]	;SI = background save area offset
	mov	ah,byte ptr[bp+saHeight]
	mov	al,byte ptr[bp+saWidth]

	push	es		;save data addressing
	mov	es,s_ram	;establish shadow ram addressing
	xor	dx,dx
	mov	cx,dx
	mov	dx,shdw_lnth
	sub	dl,al		;compute next line offset factor (nlof)

RBLoop:
	mov	cl,al		;set CX to # of bytes to restore (object length)
	rep	movsb		;restore background
	add	di,dx		;move to next line to be restored
	dec	ah		;are there more lines to be restored?
	jnz	RBLoop		;yes

	pop	es		;restore data addressing

	exit			;return control to calling routine


;|-----------------------------------------------------------------------------|
;|      This subroutine expands an object cel from its compressed form into    |
;|  shadow ram.  As the cel is expanded, each shadow ram background pixel that |
;|  has a priority greater than or equal to the object's priority is replaced  |
;|  by the object's pixel.                                                     |
;|-----------------------------------------------------------------------------|

IIO:
	enter	anistrpt	;identify calling routine's parameter

	mov	bp,anistrpt	;point BP to animation data structure
	mov	al,[bp+num]	;get object #
	push	ax		;save object #
	mov	si,[bp+celptr]	;point SI to current cell
	test	byte ptr[si+skipclr],MIRRORED ;is this a mirrored cell?
	jz	IOCell		;no

	push	bp		;pass animation pointer on to MIRROR routine
	call	MirrorCell	;mirror cell
	pop	bp		;point BP to animation structure
	mov	si,[bp+celptr]	;point SI to current cell

IOCell:
	inc	si		;increment passed object length entry
	lodsw			;AH = skip color, AL = object height
	mov	dx,ax		;DH = skip color, DL = object height
	mov	ah,byte ptr[bp+x] ;get cel's base X coord
	mov	al,byte ptr[bp+y] ;get cel's base Y coord
	sub	al,dl		;compute cel's top Y coord
	inc	al		;top Y coord = base Y coord - height + 1
	call	getShdwOfst	;set DI to shadow ram offset of base X, top Y
	shl	dh,1		;move skip color to high nibble
	shl	dh,1
	shl	dh,1
	shl	dh,1
	push	es		;save data addressing
	mov	es,s_ram	;establish shadow ram addressing
	mov	bl,1		;turn `Ego is visible' flag off
	mov	bh,[bp+pri]	;get object's priority
	shl	bh,1		;move priority code to high nibble
	shl	bh,1
	shl	bh,1
	shl	bh,1
	mov	bp,di		;save address of line start
	xor	cx,cx
	jmp	IOGetCC

IOSkip:

	cbw			;extend `# of pixels to skip' to a full word
	add	di,ax		;skip over background

IOGetCC:
	lodsb			;get cell code (ALhi = color, ALlo = # pixels)
	or	al,al		;is this the end of line code?
	jz	IOEOL		;yes

	mov	ah,al		;duplicate cell code
	and	ax,0F00Fh	;isolate color code (AH hi) & pixel count (AL lo)
	cmp	ah,dh		;is this a skip?
	je	IOSkip		;yes

	mov	cl,al		;load pixel counter
	shr	ah,1		;move cell color to low nibble
	shr	ah,1
	shr	ah,1
	shr	ah,1

IOLoop:
	mov	al,es:[di]	;get shadow ram (high = priority, low = color)
	and	al,0F0h		;isolate priority nibble
	cmp	al,20h		;is this a special priority?
	jbe	IOSpclPri	;yes

	cmp	al,bh		;is shadow priority > object priority?
	ja	IONoDraw		;yes

	mov	al,bh		;replace shadow priority with object priority

IODraw:
	or	al,ah		;replace shadow color with object color
	stosb			;draw object pixel in shadow ram
	xor	bl,bl		;turn `Ego is visible' flag on
	loop	IOLoop		;if there is another byte to check, then do so
	jmp	IOGetCC

IOEOL:
	dec	dl		;are there more lines to draw?
	jz	IOEnd		;no

	add	bp,shdw_lnth	;move down 1 line
	mov	di,bp		;set starting DI value
	jmp	IOGetCC

IOSpclPri:
	push	di		;save object pixel offset
	xor	ch,ch		;default: shadow priority <= object pri.

IOSpclCK:
	cmp	di,sbotm_ln	;is current pixel in the bottom line of shadow memory?
	jae	IOPriCk		;yes - default: shadow priority <= object pri.

	add	di,shdw_lnth	;move down one pixel
	mov	ch,es:[di]	;get pixel
	and	ch,0F0h		;isolate shadow priority
	cmp	ch,20h		;is this one also a special priority
	jbe	IOSpclCK	;yes

IOPriCk:
	pop	di		;restore object pixel offset
	cmp	ch,bh		;is shadow priority > object priority?
	mov	ch,0		;clear CH no matter what
	jna	IODraw		;no - draw pixel

IONoDraw:
	inc	di		;this pixel is hidden - don't draw it
	loop	IOLoop
	jmp	IOGetCC

IOEnd:
	pop	es		;restore data addressing
	pop	ax		;restore object #
	or	al,al		;is this object #0 (Ego)?
	jnz	IOXit		;no

	mov	al,SEE_EGO	;update `Ego is visible' flag
	test	bl,bl		;is Ego	visible?
	.if	zero
		call	ResetIt	;no
	.else
		call	SetIt	;yes
	.end

IOXit:
	exit			;return control to calling routine


code	ends

	end

;FLAG
;Actions on flags


include	macro.ah
include	game.ah

public	Set
public	Reset
public	Toggle
public	IsSet
public	SetFlag
public	ResetFlag
public	ToggleFlag
public	VSetFlag
public	VResetFlag
public	VToggleFlag
public	IsFlagSet
public	GetFlag
public	SetIt
public	ResetIt
public	ToggleIt
public	ClearFlags


cgroup	group	code
dgroup	group	data


flagParm	equ	ss:[bx+2]


data	segment public byte 'data'

extrn	flag:byte
extrn	var:byte

data	ends



code	segment public byte 'code'
assume	cs:cgroup, ds:dgroup, es:dgroup


SetFlag		proc	near

	lodsb
	call	SetIt
	mov	ax,si
	return

SetFlag		endp



ResetFlag	proc	near

	lodsb
	call	ResetIt
	mov	ax,si
	return

ResetFlag	endp



ToggleFlag	proc	near

	lodsb
	call	ToggleIt
	mov	ax,si
	return

ToggleFlag	endp



VSetFlag	proc	near

	lodsb
	xor	bh,bh
	mov	bl,al
	mov	al,var[bx]
	call	SetIt
	mov	ax,si
	return

VSetFlag	endp


VResetFlag	proc	near

	lodsb
	xor	bh,bh
	mov	bl,al
	mov	al,var[bx]
	call	ResetIt
	mov	ax,si
	return

VResetFlag	endp



VToggleFlag	proc	near

	lodsb
	xor	bh,bh
	mov	bl,al
	mov	al,var[bx]
	call	ToggleIt
	mov	ax,si
	return

VToggleFlag	endp




Set		proc	near

	mov	bx,sp
	mov	al,byte ptr flagParm
	call	SetIt
	return

Set		endp



Reset		proc	near

	mov	bx,sp
	mov	al,byte ptr flagParm
	call	ResetIt
	return

Reset		endp



Toggle		proc	near

	mov	bx,sp
	mov	al,byte ptr flagParm
	call	ToggleIt
	return

Toggle		endp



IsSet		proc	near

	mov	bx,sp
	mov	al,byte ptr flagParm
	call	IsFlagSet
	return

IsSet		endp



SetIt		proc	near

	call	GetFlag
	or	[bx],al
	return

SetIt		endp



ResetIt		proc	near

	call	GetFlag
	xor	al,0ffh
	and	[bx],al
	return

ResetIt		endp



ToggleIt	proc	near

	call	GetFlag
	xor	[bx],al
	return

ToggleIt	endp



IsFlagSet	proc	near

	call	GetFlag
	test	[bx],al
	.if	zero
		xor	ax,ax
	.else
		xor	ax,ax
		inc	ax
		.end
	return
	
IsFlagSet	endp		




GetFlag		proc	near
;Flag number is in al.  Return with bx pointing to the flag byte and ax
;with the appropriate bit set.

	xor	ah,ah

	mov	bx,ax
	shr	bx,1		;divide number by 8 to get byte offset
	shr	bx,1
	shr	bx,1
	add	bx,offset dgroup:flag

	mov	cx,ax
	and	cx,7		;get offset in the byte
	mov	al,80h
	shr	al,cl		;shift the bit to the proper position

	return

GetFlag		endp



ClearFlags	proc	near

	push	di
	xor	ax,ax
	mov	cx,NUMFLAGS/16
	lea	di,flag
	rep	stosw
	pop	di
	return

ClearFlags	endp



code	ends
	end

;INITDIR
;Initial directory for KQ II.  This is read from a given sector to tell
;the interpreter where the various necessary directories are on the disk.

;typedef   struct {
;     byte volume;
;     byte head;
;     int  track;
;     int  sector;
;     int  offset;
;     }    SEGMENT;


data	segment public byte 'data'

aniobj		db	1,0
		dw	10,3,0
object		db	1,0
		dw	10,1,0
words		db	1,0
		dw	10,8,0
logdir		db	1,0
		dw	7,6,0
picdir		db	1,0
		dw	7,8,0
viewdir		db	1,0
		dw	8,1,0
snddir		db	1,0
		dw	8,3,0
ovl1dir		db	1,0
		dw	9,1,0		    ;pcgraf.ovl
ovl2dir		db	1,0
		dw	8,5,0		    ;jrgraf.ovl
ovl3dir		db	1,0
		dw	6,1,0		    ;kqdata.ovl

data	ends

	end
;INTRPT
;Grab/restore various interrupts.

include	macro.ah
include	game.ah
include cmequ8s.ah

public	TimerIntHandler
public	SetInterrupts
public	ResetInterrupts
public	TimerDispatch
public	DeadStack
public	NullInterrupt
public	CriticalError


cgroup	group	code
dgroup	group	data


SetInt		equ	25h
GetInt		equ	35h

prtScrInt	equ	5
timeInt		equ	8
kbdInt		equ	9
videoInt	equ	10h
userTimeInt	equ	1ch
charInt		equ	1fh
ctrlBrkInt	equ	23h
critErrInt	equ	24h


timerPort	equ	40h	;address of counter port for interval timer
EOI		equ	20h	;end-of-interrupt to 8259


;This is the counter to load the programmable interval timer with in order
;to get interrupts at a rate of 60/second.  Clock to the PIT is 1.19318 MHz.
TIMER_DIVISOR	equ	19886
TIMER_COUNT	equ	3	;issue BIOS interrupt every 3 interrupts



data	segment	public byte 'data'

extrn	stackBase:word
extrn	playSnd:word
extrn	monType:word
extrn	extraChar:byte

public	oldKbd, oldVideo, dosError

oldTimer	dd	?
oldUserTimer	dd	?
oldCtrlBrk	dd	?
oldCritErr	dd	?
oldPrtScr	dd	?
oldKbd		dd	?
oldVideo	dd	?
oldChar		dd	?

dosError	dw	?

timerCounter	db	TIMER_COUNT

badStackMsg	db	"Stack blown.",LF
		db	"Press ESC to exit.",0

data	ends




code	segment	public byte 'code'
assume	cs:cgroup,ds:dgroup

extrn	PlayIt:near
extrn	ErrBeep:near
extrn	WindowNoWait:near
extrn	GetChar:near
extrn	Quit:near
extrn	TimerInt:near
extrn	KbdHandler:near
extrn	HVideoInt:near



SetInterrupts	proc	near
;Set the address of our various interrupt handlers.

	;First, save the address of the current handlers
	push	es

	dos	GetInt,prtScrInt
	mov	word ptr oldPrtScr,bx
	mov	word ptr oldPrtScr[2],es

	dos	GetInt,kbdInt
	mov	word ptr oldKbd,bx
	mov	word ptr oldKbd[2],es

	dos	GetInt,timeInt
	mov	word ptr oldTimer,bx
	mov	word ptr oldTimer[2],es

	dos	GetInt,userTimeInt
	mov	word ptr oldUserTimer,bx
	mov	word ptr oldUserTimer[2],es

	dos	GetInt,ctrlBrkInt
	mov	word ptr oldCtrlBrk,bx
	mov	word ptr oldCtrlBrk[2],es

	dos	GetInt,critErrInt
	mov	word ptr oldCritErr,bx
	mov	word ptr oldCritErr[2],es

	dos	GetInt,charInt
	mov	word ptr oldChar,bx
	mov	word ptr oldChar[2],es

	cmp	monType,MONO
	.if	equal
		dos	GetInt,videoInt
		mov	word ptr oldVideo,bx
		mov	word ptr oldVideo[2],es
		.end

	pop	es

	;Point the interrupts to our routines
	push	ds

	mov	dx,offset cgroup:NullInterrupt
	mov	ax,cs
	mov	ds,ax
	dos	SetInt,prtScrInt
	dos	SetInt,ctrlBrkInt

	mov	dx,offset cgroup:KbdHandler
	mov	ax,cs
	mov	ds,ax
	dos	SetInt,kbdInt

	;Change the timer interrupt frequency to 60/second
	mov	al,36h			;timer 0, LSB, MSB, mode 3
	out	timerPort+3,al
	mov	ax,TIMER_DIVISOR
	out	timerPort,al
	xchg	ah,al
	out	timerPort,al

	mov	dx,offset cgroup:TimerIntHandler
	mov	ax,cs
	mov	ds,ax
	dos	SetInt,timeInt

	mov	dx,offset cgroup:TimerDispatch
	mov	ax,cs
	mov	ds,ax
	dos	SetInt,userTimeInt

	mov	dx,offset cgroup:CriticalError
	mov	ax,cs
	mov	ds,ax
	dos	SetInt,critErrInt

	mov	dx,offset dgroup:extraChar
	mov	ax,es
	mov	ds,ax
	dos	SetInt,charInt

	cmp	es:monType,MONO
	.if	equal
		mov	dx,offset cgroup:HVideoInt
		mov	ax,cs
		mov	ds,ax
		dos	SetInt,videoInt
		.end

	pop	ds

	return

SetInterrupts	endp





ResetInterrupts	proc	near
;Set all interrupts back to their original handlers

	lds	dx,oldChar
	dos	SetInt,charInt
	mov	ax,es
	mov	ds,ax

	lds	dx,oldPrtScr
	dos	SetInt,prtScrInt
	mov	ax,es
	mov	ds,ax

	;Set the timer frequency back to normal (18.2/second)
	mov	al,36h			;timer 0, LSB, MSB, mode 3
	out	timerPort+3,al
	xor	al,al
	out	timerPort,al
	out	timerPort,al

	lds	dx,oldTimer
	dos	SetInt,timeInt
	mov	ax,es
	mov	ds,ax

	lds	dx,oldUserTimer
	dos	SetInt,userTimeInt
	mov	ax,es
	mov	ds,ax

	lds	dx,oldKbd
	dos	SetInt,kbdInt
	mov	ax,es
	mov	ds,ax

	lds	dx,oldCtrlBrk
	dos	SetInt,ctrlBrkInt
	mov	ax,es
	mov	ds,ax

	lds	dx,oldCritErr
	dos	SetInt,critErrInt
	mov	ax,es
	mov	ds,ax

	cmp	monType,MONO
	.if	equal
		lds	dx,oldVideo
		dos	SetInt,videoInt
		mov	ax,es
		mov	ds,ax
		.end

	return

ResetInterrupts	endp




TimerIntHandler	proc	near
;This routines gets the interrupt from the timer chip, deals with
;any sounds that need playing, and passes the interrupt to the normal
;BIOS interrupt handler every third interrupt (a rate of 20/second).

	push	ax
	push	ds
	mov	ax,dgroup
	mov	ds,ax

	cld
	cmp	playSnd,0
	.if	not_equal
		call	PlayIt
		.end

	dec	byte ptr timerCounter
	.if	nonzero
		;Nothing to do -- issue the end-of-interrupt
		mov	al,EOI
		out	20h,al
	.else
		;Time to call the BIOS routine (which will issue EOI for us)
		mov	timerCounter,TIMER_COUNT
		pushf
		call	oldTimer
		.end
	pop	ds
	pop	ax
	iret


TimerIntHandler	endp




TimerDispatch	proc	near

	;save all registers
	cli
	pusha

	mov	ax,dgroup
	mov	ds,ax			;get addressability to our data
	mov	es,ax
	call	TimerInt		;go to our interrupt handler
	pushf				;simulate an interrupt
	call	oldUserTimer		;call the previous handler

	;Check for stack overflow.
	mov	si,stackBase
	cmp	word ptr [si],STACKFLAG
	.if	not_equal
		mov	word ptr [si],STACKFLAG
		;Monkey the stack so that the return is to DeadStack
		mov	bx,sp
		mov	word ptr [bx+18],offset cgroup:DeadStack
		mov	word ptr [bx+20],cs
		.end

	popa
	sti
	iret				;return

TimerDispatch	endp



DeadStack	proc	near

	mov	ax,dgroup
	mov	ds,ax			;get addressability to our data
	mov	es,ax

	mov	ax,stackBase
	add	ax,STACKSIZE
	mov	sp,ax
	call	ErrBeep
	call	ErrBeep
	pcall	WindowNoWait,&badStackMsg
	do
		call	GetChar
		cmp	ax,ESC
	until	equal
	call	Quit

DeadStack	endp




NullInterrupt	proc	near
;Nullify this interrupt by just returning.

	iret

NullInterrupt	endp



CriticalError	proc	near
;Handle a critcal DOS error by setting the dosError code, restoring
;our registers from the stack, setting the carry, and returning to
;the original DOS call.

	;Pop DOS's return address off the stack
	add	sp,6

	;Get back data addressability and put the error code into dosError
	mov	ax,dgroup
	mov	ds,ax
	and	di,0ffh			;mask off undefined portion
	.if	zero
		mov	di,100h		;use non-zero value for write-protect
		.end
	mov	dosError,di

	;Set the carry flag in the flags which will be returned to the caller
	mov	bp,sp
	mov	ax,[bp+22]	;get the original flags
	or	ax,1		;set the carry
	mov	[bp+22],ax	;and put the flags back

	;Restore all registers from the stack
	pop	ax
	pop	bx
	pop	cx
	pop	dx
	pop	si
	pop	di
	pop	bp
	pop	ds
	pop	es

	;And return to the orignal caller to DOS
	iret


CriticalError	endp




code	ends
	end

;PCJOYRD
;Joystick read routine for IBM PC
;
;Change History:
;24/03/87  14:40:22	JAS
;	Added code to make certain that we don't get indications of a
;	joystick when one is not present.

include	macro.ah
include	game.ah

public	ReadJoy
public	ReadButtons


cgroup	group	code
dgroup	group	data



joyport	equ	201h
xbit	equ	01h
ybit	equ	02h
but1	equ	10h
but2	equ	20h

kbd	equ	16h
chkkey	equ	1


data	segment byte public 'data'

butstrc	struc
pressed	dw	0
down	dw	0
click	dw	0
dblclk	dw	0
timer	dw	2 dup(0)
butstrc	ends

BUTSIZE	equ	size butstrc

extrn	jx:word,jy:word
extrn	button:near

data	ends




code	segment public byte 'code'
assume	cs:cgroup,ds:dgroup



ReadJoy	proc	near

	enter
	
	cli
	
	bios	kbd,chkkey		;is there a keystroke waiting?
	.if	nonzero
		mov	ax,-1
		jmp	short JoyExit
		.end
	
	xor	bx,bx			;zero the counts (bh = x, bl = y)
	
	mov	ch,xbit			;test values for the bits in the port
	mov	cl,ybit
	
	mov	dx,joyport
	
	out	dx,al			;pulse the joystick
	do
		;The following instructions force the low bits of the
		;data bus to 1s, so that on machines with a floating
		;data bus (like the Tandy 3000), we can tell if a
		;joystick is present.
		flush
		aaa

		in	al,dx		;read the port
		test	al,ch		;see if the x bit has gone low
		.if	nonzero
			nop		;to equalize timing of both branches
			cli
			inc	bh	;nope -- increment the x count
			je	NotHere	;if rolled over, assume timeout
			.end
		test	al,cl		;see if the y bit has gone low
		.if	nonzero
			nop		;to equalize timing of both branches
			cli
			inc	bl	;nope -- increment the y count
			je	NotHere
			.end
		and	al,xbit or ybit	;have both x and y gone low?
	until	zero			;yep -- we're done
	
	bios	kbd,chkkey		;is there a keystroke waiting?
	.if	nonzero
		mov	ax,-1
		jmp	short JoyExit
		.end
	
	sti
	xor	ah,ah
	mov	al,bh
	mov	jx,ax		;report the x count
	xor	bh,bh
	mov	jy,bx		;report the y count
	xor	ax,ax
	jmp	short JoyExit
	
	
NotHere:
	xor	ax,ax
	mov	jx,ax
	mov	jy,ax
	
	
	
JoyExit:
	sti
	exit


ReadJoy	endp





ReadButtons	proc	near
;Read the joystick buttons.

	mov	dx,joyport
	in	al,dx		;read the port for the buttons
	
	xor	bx,bx
	test	al,but1
	.if	zero
		inc	bx
		.end
	mov	button.pressed,bx
	
	xor	bx,bx
	test	al,but2
	.if	zero
		inc	bx
		.end
	mov	button.pressed + BUTSIZE,bx
	
	return


ReadButtons	endp



code	ends
	end

;RANDOM
;Return a random number between 0 and 255
;This uses the linear congruential method with a multiplier of 31821.

include	macro.ah

public	Random


cgroup	group	code
dgroup	group	data


MULT		equ	07c4dh

timer		equ	1ah
gettime		equ	0



data	segment byte public 'data'

public	randSeed
randSeed	dw	0

data	ends




code	segment byte public 'code'
assume	cs:cgroup,ds:dgroup



Random proc	near

	enter

	cmp	randSeed,0
	.if	equal
		bios	timer,gettime
		mov	randSeed,dx
	.end
	;generate a new random number
	mov	ax,MULT
	mul	randSeed		;multiply the seed by the multiplier
	inc	ax				;add one
	mov	randSeed,ax			;save the new seed

	xor	al,ah
	xor	ah,ah

	exit

Random endp


code	ends
	end

;JRJMPTBL
;Jump table for PCjr graphics routines


cgroup	group	code

code	segment public byte 'code'
assume	cs:cgroup


extrn	jrig:near, jrts:near, jrgs:near, jrsh:near, jrb2s:near, jrirt:near
extrn	jrdw:near

initgrfx:
	jmp	jrig

textscrn:
	jmp	jrts

grafscrn:
	jmp	jrgs

sethorz:
	jmp	jrsh

blk2Scrn:
	jmp	jrb2s

initrows:
	jmp	jrirt

DrawWndw:
	jmp	jrdw

code	ends


end

/* SCRACT
** Screen related actions
**
**	compile: MWC
**
*/


#include	"types.h"
#include	"game.h"
#include	"screen.h"

#define	INVERSE	0x8f			/* inverse video ? orig 0x8f */

STRPTR	LTextScrn();
STRPTR	LGrafScrn();
STRPTR	LClearLines();
STRPTR	LClearRect();
STRPTR	SetTextAtr();
void		_SetTextAtr();
UWORD	MakeTextAtr();
UWORD	MakeForeColor();
UWORD	MakeBackColor();
void		GraphicsScreen();
STRPTR	ConfigureScreen();
STRPTR	ToggleMonitor();
void		SaveTextAtr();
void		RestoreTextAtr();



SCR_MODE	screenMode = GRAPHMODE;

#define	WHITE_ON_BLACK	0x07
#define	BLACK_ON_WHITE	0x70
#define	MAXSAVED		5
UWORD	savedAtr[MAXSAVED][3];
COUNT	savedIndex;


extern	COUNT	picTop, picBottom;
extern	WORD		machType, monType;
extern	UWORD	textAtr, foreColor, backColor;
extern	UWORD	picReloc, statusRow, inputRow;
extern	UBYTE	var[];




STRPTR
LTextScrn(lp)
register	STRPTR	lp;
{
	EraseCur();
	screenMode = TEXTMODE;
	_SetTextAtr(foreColor, backColor);
	TextScrn();
	ClrLines(0, 24, textAtr);
	return (lp);
}
	


STRPTR
LGrafScrn(lp)
STRPTR	lp;
{
	EraseCur();
	GraphicsScreen();
	return (lp);
}

	

STRPTR
LClearLines(lp)
register	STRPTR	lp;
{
	register	WORD		top;
			WORD		bottom;

	top = *lp++;
	bottom = *lp++;
	ClrLines(top, bottom, MakeBackColor(*lp++));
	return (lp);
}




STRPTR
LClearRect(lp)
register	STRPTR	lp;
{
	WORD		top, bottom, left, right;

	top = *lp++;
	left = *lp++;
	bottom = *lp++;
	right = *lp++;
	ClearRect(top, left, bottom, right, MakeBackColor(*lp++));

	return (lp);
}




STRPTR
SetTextAtr(lp)
register	STRPTR	lp;
{
	register	UWORD	fore;

	fore = *lp++;
	_SetTextAtr(fore, *lp++);
	return (lp);
}



void
_SetTextAtr(fore, back)
register	UWORD	fore, back;
{
	textAtr = MakeTextAtr(fore, back);
	foreColor = MakeForeColor(fore);
	backColor = MakeBackColor(back);
}



UWORD
MakeTextAtr(fore, back)
register	UWORD	fore, back;
/* Return the requested text attribute in it's internal representation
*/
{
	if (monType == MONO) {
		if (back < fore)
			return(WHITE_ON_BLACK);
		else
			return(BLACK_ON_WHITE);
		}
	else	if (screenMode == TEXTMODE)
		/* For text mode, put background in high nibble, fore in low
		*/
		return ((back << 4) | fore);
	else if (back != 0)
		/* In graphics if back is not black, approximate with inverse
		** text (black on white).
		*/
		return (INVERSE);
	else if (monType == EGA || machType != PC)
		/* EGA and PCjr can do any color foreground in graphics (I think...)
		*/
		return (fore);
	else {
		/* If colored text in graphics mode, approximate with 'nearest'
		** color
		*/
		switch (fore) {
			case 0:				/* black on black */
				return (0);
				break;

			case 1:				/* map all these to cyan */
			case 2:
			case 3:
			case 9:
			case 10:
			case 11:
				return (1);
				break;

			case 4:				/* map all these to magenta */
			case 5:
			case 6:
			case 12:
			case 13:
			case 14:
				return (2);
				break;

			default:				/* everything else goes to white */
				return (3);
			}
		}
}



UWORD
MakeForeColor(fore)
UWORD	fore;
/* Return the internal representation for the requested foreground color.
*/
{
	return (fore);
}



UWORD
MakeBackColor(back)
register	UWORD	back;
/* Return the internal representation for the requested background color.
*/
{
	if (screenMode == GRAPHMODE && back != 0)
		/* In graphics if back is not black, approximate with inverse
		** text (black on white).
		*/
		return (0xff);	/* mask off inverse */
	else 
		return (0);
}





void
GraphicsScreen()
{
	screenMode = GRAPHMODE;
	_SetTextAtr(foreColor, backColor);
	GrafScrn();
	DisplayStatusLine();
	DisplayInput();
}



STRPTR
ConfigureScreen(lp)
register	STRPTR	lp;
{

	picTop = *lp++;
	picBottom = picTop + 21;
	if (monType == MONO)
		if (picTop > 1)
			picReloc = HGC_RELOC_FACTOR;
		else
			picReloc = picTop * HGC_RELOC_FACTOR;
	else
		picReloc = picTop * IBM_RELOC_FACTOR;
	inputRow = *lp++;
	statusRow = *lp++;
	return (lp);
}



STRPTR
ToggleMonitor(lp)
STRPTR	lp;
{
	if (machType == PC && var[CURROOM] != 0 && monType != EGA
		&& monType != MONO) {
			SetupScanOfs();
			monType ^= 1;
			SaveCurPos();
			SetDisp();
			RestoreCurPos();
			Restore();			/* restore room, reloading ego */
			}

	return (lp);
}



void
SaveTextAtr()
{
	register	UWORD	*savePtr;

	if (savedIndex < MAXSAVED) {
		savePtr = &savedAtr[savedIndex][0];
		*savePtr = foreColor;
		*++savePtr = backColor;
		*++savePtr = textAtr;
		++savedIndex;
		}
}


void
RestoreTextAtr()
{
	register	UWORD	*savePtr;

	if (savedIndex > 0) {
		savePtr = &savedAtr[--savedIndex][0];
		foreColor = *savePtr;
		backColor = *++savePtr;
		textAtr = *++savePtr;
		}
}

;MISC
;Miscellaneous assembler routines

include	macro.ah
include	game.ah
include	trace.ah


public	SetMode
public	GetMode
public	GetChar
public	In
public	Out
public	MoveByte
public	FillMem
public	VerifyGameID


cgroup	group	code
dgroup	group	data


;BIOS video functions
video		equ	10h
bsetmod		equ	0		
bgetmod		equ	15


;BIOS keyboard stuff
kbd		equ	16h
getch		equ	0
chkkbd		equ	1
getshift	equ	2
scrollLock	equ	10h


data	segment public byte 'data'

extrn	var:byte
extrn	sysTimer:dword
extrn	gameID:near
extrn	traceStatus:word

time		dd	0
scrollState	db	0ffh

data	ends





code	segment byte public 'code'
assume	cs:cgroup, ds:dgroup, es:dgroup


extrn	Quit:near
extrn	_TraceOn:near
extrn	TraceOff:near




SetMode	proc	near
;Set video mode.

	enter	smode
	mov	al,byte ptr smode
	bios	video,bsetmod
	exit

SetMode	endp



GetMode	proc	near
;Return the current video mode.

	enter
	bios	video,bgetmod
	xor	ah,ah
	exit	

GetMode	endp




GetChar	proc	near
;Returns a char as Int, usIng the extended ASCII of the PC.  If no char is
;ready, returns NULL.

	enter

	;Check for the scroll-lock state changing -- if it does,
	;either start or stop tracing, depending on the state of tracing.
	bios	kbd,getshift
	and	al,scrollLock
	cmp	scrollState, 0ffh
	.if	equal
		mov	scrollState,al
	.else
		cmp	al,scrollState
		.if	not_equal
			mov	scrollState,al
			cmp	traceStatus,TRACE_OFF
			.if	equal
				call	_TraceOn
			.else
				call	TraceOff
				.end
			.end
		.end


	;Check for characters
	bios	kbd,chkkbd
	.if	zero
		xor	ax,ax		;no char available
	.else
		bios	kbd,getch
		test	al,al
		.if	nonzero
			xor	ah,ah
			.end
		.end
	exit	

GetChar	endp



In	proc	near
;Read the port 'Inport'

	enter	Inport

	mov	dx,Inport			;get the port number
	In	al,dx				;read the port
	xor	ah,ah

	exit

In	endp



Out	proc	near
;Send 'value' to 'Outport'.

	enter	Outport,value

	mov	dx,Outport
	mov	al,value
	Out	dx,al

	exit

Out	endp



MoveByte	proc	near
;Move 'movelen' bytes of memory from 'fromseg:from' to 'toseg:to'

	enter	toseg,to,fromseg,from,movelen

	push	ds
	push	es

	mov	ax,fromseg
	mov	ds,ax
	mov	si,from
	mov	ax,toseg
	mov	es,ax
	mov	di,to
	mov	cx,movelen
	rep	movsb
	mov	ax,movelen

	pop	es
	pop	ds

	exit

MoveByte	endp



FillMem		proc	near
;Fill memory with a certain value

	enter	fillStart, fillLen, fillVal

	mov	di,fillStart
	mov	cx,fillLen
	mov	al,fillVal
	rep	stosb

	;Return the start address
	mov	ax,fillStart

	exit

FillMem		endp




VerifyGameID	proc	near
;Verify that the gameID being set is that which this interpreter is designed
;for.  Quit if it is not.

	enter

	mov	si, offset dgroup:gameID
	mov	di, offset cgroup:checkID
	do
		lodsb			;get a byte of the ID being set.
		cmp	al,byte ptr cs:[di]
		.if	not_equal
			call	Quit
			.end
		inc	di
		or	al,al
	until	zero

	exit


checkID		db	"gameIDX"

VerifyGameID	endp


code	ends
	end

;VGJMPTBL
;Jump table for VGA graphics routines




cgroup	group	code

code	segment public byte 'code'
assume	cs:cgroup


extrn	vgig:near, vgts:near, vggs:near, vgsh:near, vgb2s:near, vgirt:near
extrn	vgdw:near

initgrfx:			;called from cmgraphx.asm
	jmp	vgig

textscrn:			;never called
	jmp	vgts

grafscrn:			;never called
	jmp	vggs

sethorz:			;never called
	jmp	vgsh

blk2Scrn:			;called from cmgraphx.asm
	jmp	vgb2s

initrows:			;called from cmgraphx.asm
	jmp	vgirt

DrawWndw:			;called from cmgraphx.asm
	jmp	vgdw

code	ends


end

;JRGRAPHX
;Picture drawing subroutines for the PCjr


cgroup	group code
dgroup	group data
assume	cs:cgroup, ds:dgroup, es:dgroup

include	macro.ah
include	cmequ8s.ah
include	jrequ8s.ah


public	jrig, jrts, jrgs, jrsh, jrb2s, jrirt, jrdw


extrn	hsp_adjmt:word, ghrz_pos:byte, thrz_pos:byte, machtype:word
extrn	s_ram:word, v_ram:word, row_table:word, textAtr:word
extrn	BackToScrn:near, getShdwOfst:near, getVidOfst:near



data	segment	byte public 'data'
data	ends		;dummy segment

;masm 'segment at' bug - see scrout.asm
;;;romdata		segment at 40h
;;;	org	65h
;;;crt_mode_set	db	?
;;;romdata		ends
romdata		equ	0040h
crt_mode_set	equ	0065h




code	segment byte public 'code'

jrig:

	mov	ax,89h		;initialize graphics: 320x200 16 color mode
	int	10h
	mov	ah,11		;set background color to black
	xor	bx,bx
	int	10h
	mov	al,0bh		;turn on color burst (BIOS error in TANDY 1000)
	mov	dx,3d8h
	out	dx,al
	call	jrsh		;set horizontal sync position

	push	es
	mov	es,v_ram	;video segment
	xor	ax,ax
	mov	di,ax		;clear entire graphics screen to black
	mov	cx,4000h
	rep	stosw
	pop	es

	ret


jrts:				;set video screen to text mode
	enter
	mov	ax,81h		;set text to 40x25 color mode
	int	10h
	mov	dx,machtype	;get machine type while DS points to DGROUP

;;;assume	ds:romdata
	push	ds
	mov	ax,romdata
	mov	ds,ax
	cmp	dx,JR		;is this a PCjr?

	.if	equal		;yes
		mov	dx,3dah	;Video Gate Array
		in	al,dx	;set to address state
		mov	al,3
		out	dx,al	;select mode control 2
		xor	al,al
		out	dx,al	;change blink to intensity
	.else
		mov	al,8
		mov	ds:crt_mode_set,al
		mov	dx,3d8h
		out	dx,al	;change blink to intensity
	.end

	pop	ds
assume	ds:dgroup

	call	jrsh		;align text screen
	mov	ah,1		;select set cursor type function
	mov	cx,1000h	;invisible cursor
	int	10h
	mov	ah,2		;select set cursor position function
	xor	bh,bh
	xor	dx,dx		;row 0, column 0
	int	10h

	mov	al,byte ptr textAtr	;get character attribute
	mov	ah,6		;scroll window
	xor	al,al		;0 lines -> clear the window
	xor	cx,cx		;upper left of screen
	mov	dx,1827h	;lower right of screen
	int	10h
	exit


jrgs:				;set video screen to graphics mode
	enter
	call	jrig		;set graphics mode
	call	BackToScrn
	exit


jrsh:				;set horizontal sync position
	cmp	machtype,JR	;is this a PCjr?

	.if	equal
		mov	ah,5	;read CRT/CPU page registers
		mov	al,80h
		int	10h	;BH = CRT page
		mov	bl,bh
		xor	bh,bh	;BX = CRT page
		mov	ax,400h	;set AX to segment length per page
		mul	bx	;compute video memory segment
		mov	v_ram,ax
	.end

	mov	ah,15		;get current video mode
	int	10h
	xor	bx,bx
	cmp	al,9		;is screen in graphics mode?

	.if	equal		;set graphics horizontal sync position
		mov	bl,ghrz_pos	  
		add	bx,hsp_adjmt
		mov	ghrz_pos,bl
	.else			;set text horizontal sync position
		mov	bl,thrz_pos
		add	bx,hsp_adjmt
		mov	thrz_pos,bl
	.end

	mov	hsp_adjmt,0	;clear horizontal sync position adjustment
	mov	dx,3d4h		;point to video chip index register
	mov	al,2		;select horiz. sync position register
	out	dx,al		;load video chip index register
	inc	dx		;point to video chip data register
	mov	al,bl		;set horiz. sync position value
	out	dx,al		;shift the screen

	ret


jrb2s:

;|-----------------------------------------------------------------------------|
;|      This subroutine translates a rectangular block of shadow ram into a    |
;|  block of color data in video ram.  The input parameters are: 	       |
;|  			AH = bottom left corner X coordinate		       |
;|  			AL = bottom left corner Y coordinate		       |
;|  			BH = height (# of lines)			       |
;|  			BL = length (# of shadow bytes)			       |
;|-----------------------------------------------------------------------------|

	test	ah,1		;is base X coord even?
	jz	b2s_lnthck	;yes
	dec	ah		;set base X coord to even coord
	inc	bl		;adjust length accordingly

b2s_lnthck:
	inc	bl		;force length to even number of pixels
	and	bl,0FEh
	mov	cx,bx		;save block height & length
	call	getShdwOfst	;get shadow ram offset of block base X,Y
	mov	bx,cx		;restore block height & length
	mov	bp,bx		;compute next shadow line offset factor (nslof)
	and	bp,0FFh		;isolate block length
	add	bp,shdw_lnth	;nslof = shadow line length + shadow block length
	xor	dx,dx		;compute next video line offset factor (nvlof)
	mov	dl,bl		;get video block length
	add	dx,next_vbnk	;nvlof = next bank offset + video block length
	shr	bl,1		;convert shadow block length to words
	mov	si,di		;put shadow ram offset into SI
	mov	cx,bx		;save block height & length
	call	getVidOfst	;put video ram offset into DI
	mov	bx,cx		;restore block height & length
	push	ds		;save data addressing
	push	es
	mov	es,v_ram	;destination is video ram
	mov	ds,s_ram	;source is shadow ram
	xor	cx,cx

b2s_lop1:
	mov	cl,bl		;set object length
	push	dx		;save nvlof

b2s_lop2:
	lodsw			;get 2 shadow bytes: AH=|PL|CL|, AL=|PH|CH|
	and	ax,0F0Fh	;isolate color nibbles: AH=|00|CL|, AL=|00|CH|
	mov	dx,ax
	shl	dx,1		;shift high color nibbles into high nibbles
	shl	dx,1
	shl	dx,1
	shl	dx,1		;DX=|CL|00|CH|00|
	or	ax,dx		;combine low and high color nibbles: AX=|CL|CL|CH|CH|
	stosw			;put color pixels into video ram
	loop	b2s_lop2	;loop until entire block line has been moved
	pop	dx		;restore nvlof
	dec	bh		;are there more lines to move?
	jz	b2s_xit		;no
	sub	si,bp		;move to next shadow line
	sub	di,dx		;move to next video line
	jnb	b2s_lop1	;no bank underflow
	add	di,vadjstmt	;adjust DI to point into next bank
	jmp	b2s_lop1

b2s_xit:
	pop	es		;restore data addressing
	pop	ds
	ret			;return control to calling routine


jrdw:

;|-----------------------------------------------------------------------------|
;|      This subroutine draws a rectangular window in video ram.  The input    |
;| parameters are:							       |
;|  			AH = bottom left corner X coordinate		       |
;|  			AL = bottom left corner Y coordinate		       |
;|  			BH = height (# of lines)			       |
;|  			BL = length (# of shadow bytes)			       |
;|			DL = color ;JRGRAPHX
;Picture drawing subroutines for the PCjr


cgroup	group code
dgroup	group data
assume	cs:cgroup, ds:dgroup, es:dgroup

include	macro.ah
include	cmequ8s.ah
include	jrequ8s.ah


public	jrig, jrts, jrgs, jrsh, jrb2s, jrirt, jrdw


extrn