373a8364aad41f66e2487834338094029dd37ba1
[rocksndiamonds.git] / src / game_sp / Demo.c
1 // ----------------------------------------------------------------------------
2 // Demo.c
3 // ----------------------------------------------------------------------------
4
5 #include "Demo.h"
6
7 // static char *VB_Name = "modDemo";
8
9 // --- Option Explicit
10 //
11 // Public Function subCloseDemoRecordingFile()
12 //
13 // End Function
14 int RecDemoRandomSeed;
15 byte FirstDemoByte;
16 char *MySignature;
17
18 void subGetNextDemoKey()
19 {
20   int ax;
21
22   if (0 < DemoKeyRepeatCounter)
23   {
24     DemoKeyRepeatCounter = DemoKeyRepeatCounter - 1;
25   }
26   else
27   {
28     DemoOffset = DemoOffset + 1;
29     if (DemoOffset <= FileMax)
30     {
31       ax = PlayField8[DemoOffset];
32       if (ax == 0xFF)
33       {
34         demo_stopped = 1;
35         ExitToMenuFlag = 1;
36       }
37       else
38       {
39         DemoKeyCode = ax & 0xF;
40         DemoKeyRepeatCounter = (ax & 0xF0) / 0x10;
41       }
42
43     }
44     else
45     {
46       ExitToMenuFlag = 1;
47     }
48   }
49
50 #if 0
51   printf("::: %04d [%03ld, %02d] ----------> %s [%d] [%d, %d] [%d, %d]\n",
52          TimerVar,
53          DemoOffset - DemoPointer, DemoKeyRepeatCounter,
54          (DemoKeyCode == keyNone        ? "(none)"              :
55           DemoKeyCode == keyLeft        ? "left"                :
56           DemoKeyCode == keyRight       ? "right"               :
57           DemoKeyCode == keyUp          ? "up"                  :
58           DemoKeyCode == keyDown        ? "down"                :
59           DemoKeyCode == keySpace       ? "space"               :
60           DemoKeyCode == keySpaceLeft   ? "space + left"        :
61           DemoKeyCode == keySpaceRight  ? "space + right"       :
62           DemoKeyCode == keySpaceUp     ? "space + up"          :
63           DemoKeyCode == keySpaceDown   ? "space + down"        : "(unknown)"),
64          DemoKeyCode,
65          MurphyScreenXPos, MurphyScreenYPos,
66          MurphyPosIndex % 60, MurphyPosIndex / 60);
67 #endif
68
69 }
70
71 currency GetTotalFramesOfDemo()
72 {
73   currency GetTotalFramesOfDemo;
74
75   long i;
76   currency nFrames;
77   byte db;
78
79   GetTotalFramesOfDemo = 0;
80   if (! DemoAvailable)
81     return GetTotalFramesOfDemo;
82
83   nFrames = 1;
84   i = DemoPointer + 1;
85
86   // --- On Error GoTo GetTotalFramesOfDemoEH
87   db = PlayField8[i];
88   while (db != 0xFF)
89   {
90     nFrames = nFrames + (db & 0xF0) / 0x10 + 1;
91     i = i + 1;
92     db = PlayField8[i];
93   }
94
95   GetTotalFramesOfDemo = nFrames;
96   return GetTotalFramesOfDemo;
97
98   // GetTotalFramesOfDemoEH:
99   // ReportError "GetTotalFramesOfDemo()", "invalid data detected in file " & OrigPath
100   GetTotalFramesOfDemo = 0;
101   DemoAvailable = False;
102
103   return GetTotalFramesOfDemo;
104 }