Modifying software to compile with the Free Pascal compiler and run on modern systems...
[supernova.git] / src / NOVA.PAS
index f7e41ee146a42aa0a84730b77d2668f14a15ee0f..39735c9f86b44652f18756360dd23d6402248714 100644 (file)
@@ -1,5 +1,27 @@
 {//-------------------------------------------------------------------------}\r
 {/*                                                                         }\r
+{Copyright (C) 2014 Jason Self <j@jxself.org>                               }\r
+{                                                                           }\r
+{This file is free software: you may copy, redistribute and/or modify it    }\r
+{under the terms of the GNU Affero General Public License as published by   }\r
+{the Free Software Foundation, either version 3 of the License, or (at your }\r
+{option) any later version.                                                 }\r
+{                                                                           }\r
+{This file is distributed in the hope that it will be useful, but WITHOUT   }\r
+{ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      }\r
+{FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License}\r
+{for more details.                                                          }\r
+{                                                                           }\r
+{You should have received a copy of the GNU Affero General Public License   }\r
+{along with this program; if not, see https://gnu.org/licenses or write to: }\r
+{  Free Software Foundation, Inc.                                           }\r
+{  51 Franklin Street, Fifth Floor                                          }\r
+{  Boston, MA 02110-1301                                                    }\r
+{  USA                                                                      }\r
+{                                                                           }\r
+{This file incorporates work covered by the following copyright and         }\r
+{permission notice:                                                         }\r
+{                                                                           }\r
 {Copyright (C) 1990, 2009 - Apogee Software, Ltd.                           }\r
 {                                                                           }\r
 {This file is part of Supernova.  Supernova is free software; you can       }\r
 (*                       Copyright 1985 Scott Miller                        *)\r
 (****************************************************************************)\r
 \r
-{$C-,R-,V-,K-}\r
+{$C-,R-,V-,S-}\r
+{$IFDEF UNIX}\r
+uses ncurses,ocrt,sysutils,SDL;\r
+{$ELSE}\r
+uses crt,sysutils,SDL;\r
+{$ENDIF}\r
 \r
 const\r
    VMax    = 95;     { Verbs   }\r
@@ -44,6 +71,11 @@ const
    MMax    = 29;     { Mov's   }\r
    Null    = 0;\r
    Legal   = 255;\r
+   audio_FREQ    = 22050;  { SDL Audio parameters }\r
+   audio_SAMPLES = 512;\r
+   audio_STEP    = 16;\r
+   audio_VOLUME  = 24;\r
+   audio_MAXENTRIES = 50000;\r
 \r
 type\r
    Str1    = string[1];\r
@@ -56,7 +88,11 @@ type
    Str130  = string[131];\r
    Str234  = string[234];\r
    Str255  = string[255];\r
-   Entr    = record AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags:integer;end;\r
+   {Entr    = record AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags:integer;end;}\r
+{$IFNDEF UNIX}\r
+   TWindow = record x,y,x1,y1:integer;end;\r
+   PWin    = ^TWindow;\r
+{$ENDIF}\r
    LSet    = set of 1..NMax;\r
    SaveSet = record\r
               aInv    : set of 1..MMax;\r
@@ -67,6 +103,22 @@ type
              end;\r
 \r
 var\r
+   buflen  : byte;\r
+   sound_i,\r
+   sound_play   : integer;\r
+   sound_Freqs  : array [0..audio_MAXENTRIES] of Integer;\r
+   sound_supported,\r
+   speaker_on   : boolean;\r
+   lasttime,  \r
+   sound_ticks  : UInt32;\r
+   lastfreq,\r
+   current_freq : Real;\r
+   win1,win2,\r
+   stdscr  : pwin;\r
+   UTF8Scr : boolean;\r
+{$IFNDEF UNIX}\r
+   win_arr : array [1..3] of TWindow;\r
+{$ENDIF}\r
    SetSave : SaveSet;\r
    Sets    : file of SaveSet;\r
    Objects : file of LSet;\r
@@ -126,6 +178,7 @@ var
    Old,      { for Block Reader }\r
    Old2,\r
    x,y,o   : byte;\r
+   xi,yi   : integer;\r
    Code,     { dials, etc }\r
    Tic,\r
    StoreR,   { Knows if the previous Room that was read is the same as the  }\r
@@ -148,14 +201,14 @@ var
    R1,R2,S1: file of Str234;\r
    L1      : file of Str78;\r
    C1      : file of Str77;\r
-   T1,T2   : text[2500];\r
+   T1,T2   : Text;\r
    Identity,\r
    VStr,\r
    NStr,\r
    PStr,\r
    LastNoun,\r
    Word    : Str29;\r
-   Result  : Entr;\r
+   {Result  : Entr;}\r
    Drive,\r
    Log,\r
    CFlag   : char;\r
@@ -166,7 +219,7 @@ var
    SFlag   : boolean;  { If TRUE then a Special action took place. }\r
 {----------}\r
 \r
-{$Ia:ADPAR.pas   <<<<<------  LOADS IN MANY PARSER COMMANDS  ***************}\r
+{$I ADPAR.pas   <<<<<------  LOADS IN MANY PARSER COMMANDS  ***************}\r
 \r
 procedure Describe(Room:byte);\r
  begin\r
@@ -218,7 +271,7 @@ procedure Describe(Room:byte);
     end;\r
  end; { Describe }\r
 \r
-procedure Move{New:byte};\r
+procedure Move(New:byte);\r
  begin SF;\r
   if en(7) then RL(22) else\r
   if en(8) then RL(23) else\r
@@ -235,11 +288,11 @@ procedure Move{New:byte};
  end; { Move }\r
 \r
 \r
-{$Ia:VOCAB.pas    <<<<<-------  Loads in VOCABULARY LIST  **********}\r
+{$I VOCAB.pas    <<<<<-------  Loads in VOCABULARY LIST  **********}\r
 \r
 \r
 {****************************** ROOM ROUTINES *******************************}\r
-overlay procedure Room1;   { The Player's Ship }\r
+procedure Room1;   { The Player's Ship }\r
 begin\r
 case Prm of\r
  1:case Vb of  { Bridge }\r
@@ -309,7 +362,7 @@ case Prm of
  end; {main case}\r
 end; { Room1 }\r
 {----------}\r
-overlay procedure Room2;   { The Player's Ship }\r
+procedure Room2;   { The Player's Ship }\r
 begin\r
 case Prm of\r
  2:case Vb of  { Forward Corridor }\r
@@ -329,10 +382,10 @@ case Prm of
         if en(22) then\r
          begin RL(96);Add(23);\r
           if(not en(44))and(Region=2)then\r
-           begin Add(44);RL(327);for i:=1 to 400 do sound(random(3500)+999);\r
-            for i:=7500 downto 500 do begin sound(random(i)+i);\r
-             sound(random(3500)+2000)end;\r
-            for i:=1 to 300 do sound(random(3500)+2500);nosound;\r
+           begin Add(44);RL(327);for i:=1 to 400 do sounddelayed(random(3500)+999);\r
+            for i:=7500 downto 500 do begin sounddelayed(random(i)+i);\r
+             sounddelayed(random(3500)+2000)end;\r
+            for i:=1 to 300 do sounddelayed(random(3500)+2500);nosound;\r
            end\r
          end\r
         else RL(97)\r
@@ -351,7 +404,7 @@ case Prm of
  end; {main case}\r
 end; { Room2 }\r
 {----------}\r
-overlay procedure Room3;   { The Player's Ship }\r
+procedure Room3;   { The Player's Ship }\r
 begin\r
 case Prm of\r
 \r
@@ -418,7 +471,7 @@ case Prm of
  end; {main case}\r
 end; { Room3 }\r
 {----------}\r
-overlay procedure Room4;   { The Tavern }\r
+procedure Room4;   { The Tavern }\r
 begin\r
 case Prm of\r
  8:case Vb of  { Tavern }\r
@@ -497,7 +550,7 @@ case Prm of
  end; {main case}\r
 end; { Room4 }\r
 {----------}\r
-overlay procedure Room5;   { Barre-An Planet }\r
+procedure Room5;   { Barre-An Planet }\r
  procedure Zap; begin for x:=1 to 29 do if R[x]=Prm then Van(x) end;\r
 begin\r
 case Prm of\r
@@ -582,7 +635,7 @@ case Prm of
  end {main case}\r
 end; { Room5 }\r
 {----------}\r
-overlay procedure Room6;   { Jungle Planet }\r
+procedure Room6;   { Jungle Planet }\r
 begin\r
 case Prm of\r
 23:case Vb of  { Deep Pit }\r
@@ -608,7 +661,7 @@ case Prm of
 25:case Vb of { Sandy Clearing }\r
    4,9,51:if N1 in[Null,62,71] then begin RL(234);move(24)end;\r
    1:begin move(26);Score(5,75)end;\r
-   1..8:RL(200);\r
+   2,3,5..8:RL(200);\r
    end; {Vb}\r
 \r
 26:case Vb of { Winding Path 1 }\r
@@ -617,7 +670,7 @@ case Prm of
    59:if N1=66 then\r
        if VStr='jump in' then begin RL(288);DEAD;end\r
        else begin RS(66);move(27);Score(25,76)end;\r
-   1..8:RL(200);\r
+   1,3,4,6..8:RL(200);\r
    9,51:if N1=112 then RL(204);\r
    28:if N1=66 then RS(85);\r
    35,62:if N1=66 then begin RL(288);DEAD;end;\r
@@ -629,7 +682,7 @@ case Prm of
 27:case Vb of { Winding Path 2 }\r
    6:move(28);\r
    8,11:begin RS(65);DEAD;end;\r
-   1..8:RL(200);\r
+   1..5,7:RL(200);\r
    9,51:if N1=112 then RL(204);\r
    59:if N1=66 then\r
        if VStr='jump in' then begin RL(288);DEAD;end\r
@@ -645,7 +698,7 @@ case Prm of
    7:move(27);\r
    6:move(29);\r
    8:begin RS(67);DEAD;end;\r
-   1..8:RL(200);\r
+   1..5:RL(200);\r
    9,51:if N1=112 then RL(204);\r
    28:if N1=112 then RS(86);\r
    24:if N1=112 then RL(553);\r
@@ -658,7 +711,7 @@ case Prm of
    9,51:if N1 in[Null,112] then begin RL(201);move(30)end;\r
    6:begin RS(69);Prm:=31;T[11]:=4;end;\r
    8:if en(35)or en(130)then begin RC:=1;move(59);Score(20,77)end;\r
-   1..8:RL(200);\r
+   1..4:RL(200);\r
    28:case N1 of 112:RL(238);120:RL(544);\r
        113:if Md=1 then begin RL(314);Add(130)end end;\r
    59:if N1=120 then begin RL(541);Prm:=31;T[11]:=4;end;\r
@@ -667,7 +720,7 @@ case Prm of
  end {main case}\r
 end; { Room6 }\r
 {----------}\r
-overlay procedure Room7;   { Jungle Planet }\r
+procedure Room7;   { Jungle Planet }\r
 begin\r
 case Prm of\r
 30:case Vb of { Top of Tree }\r
@@ -689,14 +742,14 @@ case Prm of
 32:case Vb of { Winding Path 5 }\r
    1:move(33);\r
    8:begin move(29);if en(35) and not en(40) then begin RL(314);Add(40)end end;\r
-   1..8:RL(200);\r
+   2..7:RL(200);\r
    9,51:if N1=112 then RL(204);\r
    end;\r
 \r
 33:case Vb of { Winding Path 6 }\r
    2:move(32);\r
    6:if not en(28)then begin RS(68);Add(28);move(34)end else move(34);\r
-   1..8:RL(200);\r
+   1,3,4,5,7,8:RL(200);\r
    9,51:if N1=112 then RL(204);\r
    end;\r
 \r
@@ -715,7 +768,7 @@ case Prm of
    39:if(PyraCon in NounSet)or((30 in Nounset)and(PyraCon=9))then\r
        begin RL(225);Min(30);SFlag:=false;end else\r
       if HingeCon in NounSet then begin RL(228);SFlag:=false;end;\r
-   1..8:RL(200);\r
+   2..6,8:RL(200);\r
    9,51:if N1=112 then RL(204);\r
    92:if N1 in[Null,49,122] then begin RL(216);move(23) end;\r
    31:if N1 in[81,89,119] then begin RB(8,7);Pause;end;\r
@@ -733,7 +786,7 @@ case Prm of
  end {main case}\r
 end; { Room7 }\r
 {----------}\r
-overlay procedure Room8;   { Inside Pyramid (Top Level) }\r
+procedure Room8;   { Inside Pyramid (Top Level) }\r
 begin\r
 case Prm of\r
 35:case Vb of  { Vestibule }\r
@@ -774,7 +827,7 @@ case Prm of
  end {main case}\r
 end; { Room8 }\r
 {----------}\r
-overlay procedure Room9;   { Inside Pyramid (Top Level) }\r
+procedure Room9;   { Inside Pyramid (Top Level) }\r
 begin\r
 case Prm of\r
 39:case Vb of  { Holey Hall }\r
@@ -787,9 +840,9 @@ case Prm of
          begin n[68]:='podium\alter\column\';WRITE('');move(41)end;\r
    3,13:if(18 in Inv)or(4 in Inv)then begin Brief:=Brief-[39];move(39);\r
           T[15]:=3;T[16]:=9;col(10,7);RS(93);\r
-          for i:=500 to 5500 do sound(random(i)+random(i));\r
-          for j:=1 to 7000 do sound(random(i)+random(i));\r
-          for j:=i downto 500 do sound(random(j)+random(j));nosound;\r
+          for i:=500 to 5500 do sounddelayed(random(i)+random(i));\r
+          for j:=1 to 7000 do sounddelayed(random(i)+random(i));\r
+          for j:=i downto 500 do sounddelayed(random(j)+random(j));nosound;\r
          end\r
         else move(39);\r
    42,44,51,75,84,94:\r
@@ -824,7 +877,7 @@ case Prm of
  end {main case}\r
 end; { Room9 }\r
 {----------}\r
-overlay procedure Room10;   { Pyramid Maze }\r
+procedure Room10;   { Pyramid Maze }\r
 begin\r
 case Prm of\r
 42:case Vb of  { Ladder Room }\r
@@ -896,7 +949,7 @@ case Prm of
  end {main case}\r
 end; { Room10 }\r
 {----------}\r
-overlay procedure Room11;   { Inside Pyramid (Bottom Level) }\r
+procedure Room11;   { Inside Pyramid (Bottom Level) }\r
 begin\r
 case Prm of\r
 51:case Vb of  { Lower Stairway }\r
@@ -950,7 +1003,7 @@ case Prm of
  end {main case}\r
 end; { Room11 }\r
 {----------}\r
-overlay procedure Room12;   { Inside Pyramid (Bottom Level) }\r
+procedure Room12;   { Inside Pyramid (Bottom Level) }\r
 begin\r
 case Prm of\r
 56:case Vb of  { The Erusaert }\r
@@ -1019,7 +1072,7 @@ case Prm of
  end {main case}\r
 end; { Room12 }\r
 {----------}\r
-overlay procedure Room13;   { Inside Pyramid (Bottom Level) }\r
+procedure Room13;   { Inside Pyramid (Bottom Level) }\r
 begin\r
 case Prm of\r
 57:case Vb of  { Solar Chamber }\r
@@ -1036,7 +1089,7 @@ case Prm of
 59:case Vb of  { Overgrown Path }\r
    5:begin RC:=RC-1;if RC<1 then begin RL(309);move(29)end else RL(310)end;\r
    8:begin RC:=RC+1;if RC>7 then begin RL(309);move(60)end else RL(310)end;\r
-   1..8:RL(200);\r
+   1..4,6,7:RL(200);\r
    9,51:if N1=112 then RL(204);\r
    end;\r
 \r
@@ -1044,7 +1097,7 @@ case Prm of
    4,11:begin Door(61,25);\r
          if not en(43)then begin RS(137);Score(10,43)end end;\r
    5:move(59);\r
-   1..8:RL(200);\r
+   1..3,6,7,8:RL(200);\r
    28:case N1 of 96:RL(323);115:RL(324)end;\r
    41..44,54,75,88:if N1=56 then RL(315);\r
    9,51:if N1=112 then RL(204)else RL(316);\r
@@ -1064,7 +1117,7 @@ case Prm of
      case N1 of\r
       37,38:RL(318);\r
       44:begin RS(138);\r
-          for y:=60 downto 1 do for x:=800 downto 1 do sound(x*y);\r
+          for yi:=60 downto 1 do for xi:=800 downto 1 do sounddelayed(xi*yi);\r
           nosound;TFlag:=3;Brief:=Brief-[70];Score(10,89);\r
           for x:=1 to MMax do if R[x]=62 then R[x]:=70;move(70)\r
          end\r
@@ -1078,7 +1131,7 @@ case Prm of
    42,44,75:case N1 of\r
             37,38:RL(318);\r
             44:begin RS(138);\r
-                for y:=60 downto 1 do for x:=800 downto 1 do sound(x*y);\r
+                for yi:=60 downto 1 do for xi:=800 downto 1 do sounddelayed(xi*yi);\r
                 nosound;TFlag:=3;Brief:=Brief-[70];\r
                 for x:=1 to MMax do if R[x]=63 then R[x]:=70;move(70)\r
                end\r
@@ -1091,7 +1144,7 @@ case Prm of
  end {main case}\r
 end; { Room13 }\r
 {----------}\r
-overlay procedure Room14;   { Inner Planet }\r
+procedure Room14;   { Inner Planet }\r
 begin\r
 case Prm of\r
 64:case Vb of  { Lobby }\r
@@ -1176,7 +1229,7 @@ case Prm of
  end {main case}\r
 end; { Room14 }\r
 {----------}\r
-overlay procedure Room15;   { Inner Planet }\r
+procedure Room15;   { Inner Planet }\r
 begin\r
 case Prm of\r
 68:case Vb of  { Decontamination }\r
@@ -1199,7 +1252,7 @@ case Prm of
    42,44,75:\r
      if N1 in[40..43]then\r
       begin Brief:=Brief-[62,63,78];RS(138);Min(45);\r
-       for y:=60 downto 1 do for x:=800 downto 1 do sound(x*y);nosound;\r
+       for yi:=60 downto 1 do for xi:=800 downto 1 do sounddelayed(xi*yi);nosound;\r
         case N1 of\r
          40:begin for x:=1 to MMax do if R[x]=70 then R[x]:=78;\r
              TFlag:=4;move(78);Score(15,97)end;\r
@@ -1216,7 +1269,7 @@ case Prm of
  end {main case}\r
 end; { Room15 }\r
 {----------}\r
-overlay procedure Room16;   { Inner Planet }\r
+procedure Room16;   { Inner Planet }\r
 begin\r
 case Prm of\r
 73:case Vb of  { Communications }\r
@@ -1264,7 +1317,7 @@ case Prm of
  end {main case}\r
 end; { Room16 }\r
 {----------}\r
-overlay procedure Room17;   { Planetship }\r
+procedure Room17;   { Planetship }\r
 begin\r
 case Prm of\r
 78:case Vb of  { Icy Platform }\r
@@ -1305,7 +1358,7 @@ case Prm of
  end {main case}\r
 end; { Room17 }\r
 {----------}\r
-overlay procedure Room18;   { Planetship }\r
+procedure Room18;   { Planetship }\r
 begin\r
 case Prm of\r
 81:case Vb of  { Circular Corridor }\r
@@ -1373,7 +1426,7 @@ case Prm of
  end {main case}\r
 end; { Room18 }\r
 {----------}\r
-overlay procedure Room19;   { Planetship }\r
+procedure Room19;   { Planetship }\r
 begin\r
 case Prm of\r
 84:case Vb of  { Circular Corridor }\r
@@ -1437,13 +1490,13 @@ case Prm of
              begin i:=random(7000)+999;play(i,i,50);delay(random(15)+5)end\r
            end else\r
           if N1 in[38,128]then RL(403);\r
-     42,75:if N1 in[38,128]then RL(403);\r
+     42:if N1 in[38,128]then RL(403);\r
    end;\r
 \r
  end {main case}\r
 end; { Room19 }\r
 {----------}\r
-overlay procedure Room20;   { Planetship }\r
+procedure Room20;   { Planetship }\r
 begin\r
 case Prm of\r
 90:case Vb of  { Reactors East }\r
@@ -1499,7 +1552,7 @@ case Prm of
  end {main case}\r
 end; { Room20 }\r
 {----------}\r
-overlay procedure Room21;   { Planetship }\r
+procedure Room21;   { Planetship }\r
 begin\r
 case Prm of\r
 94:case Vb of  { Maintenance }\r
@@ -1561,7 +1614,7 @@ case Prm of
  end {main case}\r
 end; { Room21 }\r
 {----------}\r
-overlay procedure Room22;   { Planetship (Lower Level) }\r
+procedure Room22;   { Planetship (Lower Level) }\r
 begin\r
 case Prm of\r
 101:case Vb of  { Security Tunnel #3 }\r
@@ -1624,7 +1677,7 @@ case Prm of
  end {main case}\r
 end; { Room22 }\r
 {----------}\r
-overlay procedure Room23;   { Planetship (Lower Level) }\r
+procedure Room23;   { Planetship (Lower Level) }\r
  label JUMP;\r
 begin\r
 case Prm of\r
@@ -1690,12 +1743,13 @@ end; { Room23 }
 {**************************** END OF ROOM ROUTINES **************************}\r
 \r
 \r
-{$Ia:DEFAULT.pas   <<<<<------  LOADS IN DEFAULT ROUTINES  *******************}\r
+{$I DEFAULT.pas   <<<<<------  LOADS IN DEFAULT ROUTINES  *******************}\r
 \r
 \r
 BEGIN { Main Program }\r
 Assign1;Assign2;Assign3;Assign4;Assign5;\r
 Names1;Names2;Names3;\r
+InitScrKbd;\r
 Title;\r
 Init1;Init2;Init3;\r
 Place1;Place2;\r