author | Medo <smaxein@googlemail.com> |
Mon, 20 Aug 2012 17:08:52 +0200 | |
changeset 7578 | d5c880e6d772 |
parent 7151 | ec15d9e1a7e3 |
child 8437 | 93b647d6a00f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uConsole; |
22 |
interface |
|
23 |
||
3038 | 24 |
procedure initModule; |
25 |
procedure freeModule; |
|
4 | 26 |
procedure WriteToConsole(s: shortstring); |
27 |
procedure WriteLnToConsole(s: shortstring); |
|
53 | 28 |
function GetLastConsoleLine: shortstring; |
6528 | 29 |
function ShortStringAsPChar(s: shortstring): PChar; |
4 | 30 |
|
31 |
implementation |
|
5286 | 32 |
uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF}; |
950 | 33 |
|
6982 | 34 |
const cLinesCount = 8; |
35 |
var cLineWidth: LongInt; |
|
351 | 36 |
|
4437
05192cdbce9b
un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents:
4436
diff
changeset
|
37 |
type |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
38 |
TTextLine = record |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
39 |
s: shortstring |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
40 |
end; |
4 | 41 |
|
785 | 42 |
var ConsoleLines: array[byte] of TTextLine; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
43 |
CurrLine: LongInt; |
4 | 44 |
|
785 | 45 |
procedure SetLine(var tl: TTextLine; str: shortstring); |
46 |
begin |
|
47 |
with tl do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
48 |
s:= str; |
785 | 49 |
end; |
50 |
||
4 | 51 |
procedure WriteToConsole(s: shortstring); |
7134 | 52 |
{$IFNDEF NOCONSOLE} |
371 | 53 |
var Len: LongInt; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
54 |
done: boolean; |
7134 | 55 |
{$ENDIF} |
4 | 56 |
begin |
3818
e668970413e6
add a noconsole symbol, update the project file for appstore distribution
koda
parents:
3777
diff
changeset
|
57 |
{$IFNDEF NOCONSOLE} |
5661
45618bdce725
Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents:
5460
diff
changeset
|
58 |
AddFileLog('[Con] ' + s); |
45618bdce725
Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents:
5460
diff
changeset
|
59 |
{$IFDEF ANDROID} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
60 |
Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s)); |
5286 | 61 |
{$ELSE} |
5132
11d61349efcf
Make WriteLnToConsole write to stderr instead of stdout
unc0rr
parents:
4976
diff
changeset
|
62 |
Write(stderr, s); |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
63 |
done:= false; |
3697 | 64 |
|
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
65 |
while not done do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
66 |
begin |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
67 |
Len:= cLineWidth - Length(ConsoleLines[CurrLine].s); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
68 |
SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
69 |
Delete(s, 1, Len); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
70 |
if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
71 |
begin |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
72 |
inc(CurrLine); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
73 |
if CurrLine = cLinesCount then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
74 |
CurrLine:= 0; |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
75 |
PByte(@ConsoleLines[CurrLine].s)^:= 0 |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
76 |
end; |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
77 |
done:= (Length(s) = 0); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
78 |
end; |
3818
e668970413e6
add a noconsole symbol, update the project file for appstore distribution
koda
parents:
3777
diff
changeset
|
79 |
{$ENDIF} |
5286 | 80 |
{$ENDIF} |
4 | 81 |
end; |
82 |
||
83 |
procedure WriteLnToConsole(s: shortstring); |
|
84 |
begin |
|
3825 | 85 |
{$IFNDEF NOCONSOLE} |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
86 |
WriteToConsole(s); |
5286 | 87 |
{$IFNDEF ANDROID} |
7151 | 88 |
WriteLn(stderr, ''); |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
89 |
inc(CurrLine); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
90 |
if CurrLine = cLinesCount then |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
91 |
CurrLine:= 0; |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
92 |
PByte(@ConsoleLines[CurrLine].s)^:= 0 |
3818
e668970413e6
add a noconsole symbol, update the project file for appstore distribution
koda
parents:
3777
diff
changeset
|
93 |
{$ENDIF} |
5286 | 94 |
{$ENDIF} |
4 | 95 |
end; |
96 |
||
6444 | 97 |
function ShortStringAsPChar(s: shortstring) : PChar; |
6027 | 98 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
99 |
if Length(s) = High(s) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6528
diff
changeset
|
100 |
Dec(s[0]); |
6027 | 101 |
s[Ord(Length(s))+1] := #0; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6982
diff
changeset
|
102 |
ShortStringAsPChar:= @s[1]; |
6027 | 103 |
end; |
4 | 104 |
|
53 | 105 |
function GetLastConsoleLine: shortstring; |
2695 | 106 |
var valueStr: shortstring; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
107 |
i: LongWord; |
53 | 108 |
begin |
1242 | 109 |
i:= (CurrLine + cLinesCount - 2) mod cLinesCount; |
2695 | 110 |
valueStr:= ConsoleLines[i].s; |
1242 | 111 |
|
2695 | 112 |
valueStr:= valueStr + #10; |
1242 | 113 |
|
114 |
i:= (CurrLine + cLinesCount - 1) mod cLinesCount; |
|
2695 | 115 |
valueStr:= valueStr + ConsoleLines[i].s; |
1242 | 116 |
|
2695 | 117 |
GetLastConsoleLine:= valueStr; |
53 | 118 |
end; |
119 |
||
3038 | 120 |
procedure initModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
121 |
var i: LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
122 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
123 |
CurrLine:= 0; |
3697 | 124 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
125 |
// initConsole |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
126 |
cLineWidth:= cScreenWidth div 10; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
127 |
if cLineWidth > 255 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
128 |
cLineWidth:= 255; |
3697 | 129 |
for i:= 0 to Pred(cLinesCount) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
130 |
PByte(@ConsoleLines[i])^:= 0; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
131 |
end; |
4 | 132 |
|
3038 | 133 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
134 |
begin |
4437
05192cdbce9b
un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents:
4436
diff
changeset
|
135 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
136 |
end; |
4 | 137 |
|
138 |
end. |