Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help with deciphering what does an expresion in this program do

tipul01tipul01 Posts: 3Member
[b][red]This message was edited by tipul01 at 2005-6-4 10:35:10[/red][/b][hr]

Comments

  • Phat NatPhat Nat Posts: 757Member
    [b][red]This message was edited by Phat Nat at 2005-5-29 20:6:50[/red][/b][hr]
    : pls help me with this. i'm posting the source code here. i really need your help. what does the [0..1] field of the array do? what is it's use??? i mean, the pointer is called only with the value 0. not evean once with the value 1. pls help....
    :
    : program target;
    : uses crt;
    : type
    : ScrnArray = array[0..24,0..79,0..1] of byte;
    : ScrnPtr = ^ScrnArray;
    :
    : var
    : Ch : char;
    : ScrnMode : byte absolute $0040:$0049;
    : MonoBase : ScrnArray absolute $B000:$0000;
    : ColorBase : ScrnArray absolute $B800:$0000;
    : ScrnBase : ScrnPtr;
    : LoopCount : integer;
    : TargetSymbol : byte;
    : TargetRow : integer;
    : TargetCol : integer;
    : MissileCol : integer;
    : MissileRow : integer;
    : GunRow : integer;
    : GunCol : integer;
    : Active : boolean;
    : Quit : boolean;
    :
    : const
    : SoundFlg : boolean = true;
    :
    : BlankSpace = $20;
    : DownSymbol = $1f;
    : UpSymbol = $1e;
    : BlownSymbol = $2a;
    : GunSymbol = $10;
    : MissileSymbol = $2d;
    :
    : TitleRow = 0;
    : ScoreRow = 24;
    : TimeCol = 40;
    : WinCol = 28;
    : MisCol = 40;
    : MaxTargetRow = 24;
    : MinTargetRow = 0;
    : MinMissileCol = 1;
    : MaxMissileCol = 79;
    :
    :
    : {-------------------------------------}
    : procedure GameOver;
    : var S:string;
    : i:integer;
    : begin
    : S := '** GAME OVER **';
    : for i := 1 to length(S) do
    : ScrnBase^[8][i+30][0]:= ord(S[i]);
    : end;
    :
    : procedure DecTime;
    : begin
    : dec(ScrnBase^[TitleRow][TimeCol][0]);
    : if ScrnBase^[TitleRow][TimeCol][0] < $30 then
    : begin
    : ScrnBase^[TitleRow][TimeCol][0] := $39;
    : dec(ScrnBase^[TitleRow][TimeCol-1][0]);
    : if ScrnBase^[TitleRow][TimeCol-1][0] < $30 then
    : begin
    : ScrnBase^[TitleRow][TimeCol-1][0] := $39;
    : dec(ScrnBase^[TitleRow][TimeCol-2][0]);
    : end;
    : end;
    : if (ScrnBase^[TitleRow][TimeCol][0] < $31) and
    : (ScrnBase^[TitleRow][TimeCol-1][0] < $31) and
    : (ScrnBase^[TitleRow][TimeCol-2][0] < $31) then
    : begin
    : GameOver;
    : Quit := true;
    : end;
    : end;
    :
    :
    : procedure UpdateTarget;
    : begin
    : if SoundFlg then sound(400);
    : LoopCount := 0;
    : ScrnBase^[TargetRow][TargetCol][0] := BlankSpace;
    : if TargetSymbol = UpSymbol then
    : begin
    : dec(TargetRow);
    : if TargetRow < succ(MinTargetRow) then
    : TargetSymbol := DownSymbol;
    : end
    : else
    : begin
    : inc(TargetRow);
    : If TargetRow > pred(MaxTargetRow) then
    : TargetSymbol := UpSymbol;
    : end;
    : ScrnBase^[TargetRow][TargetCol][0] := TargetSymbol;
    : delay(10);
    : nosound;
    : DecTime;
    : end;
    :
    : procedure FireCheck;
    : begin
    : Ch := #0;
    : if KeyPressed then
    : begin
    : Ch := UpCase(ReadKey);
    : if Ch = #0 then Ch := char(ord(ReadKey) or $80);
    : end;
    : if (Ch = #32) and not(Active) then
    : begin
    : MissileCol := MinMissileCol;
    : ScrnBase^[MissileRow][MissileCol][0] := MissileSymbol;
    : Active := true;
    : end;
    : if (Ch < #13) and (Ch > #0) or (Ch = 'Q') then Quit := true;
    : if Ch = 'S' then SoundFlg := not(SoundFlg);
    : if Active and SoundFlg then sound(MissileCol shl 8);
    : delay(10);
    : nosound;
    : end;
    :
    : procedure IncWin;
    : begin
    : inc(ScrnBase^[ScoreRow][WinCol][0]);
    : if ScrnBase^[ScoreRow][WinCol][0] > $39 then
    : begin
    : ScrnBase^[ScoreRow][WinCol][0]:= $30;
    : inc(ScrnBase^[ScoreRow][pred(WinCol)][0]);
    : end;
    : if (ScrnBase^[ScoreRow][WinCol][0] > $38) and
    : (ScrnBase^[ScoreRow][pred(WinCol)][0] > $38) then
    : begin
    : GameOver;
    : Quit := true;
    : end;
    : end;
    :
    : procedure IncMiss;
    : begin
    : inc(ScrnBase^[ScoreRow][MisCol][0]);
    : if ScrnBase^[ScoreRow][MisCol][0] > $39 then
    : begin
    : ScrnBase^[ScoreRow][MisCol][0] := $30;
    : inc(ScrnBase^[ScoreRow][pred(MisCol)][0]);
    : end;
    : if (ScrnBase^[ScoreRow][MisCol][0] = $38) and
    : (ScrnBase^[ScoreRow][pred(MisCol)][0] = $38) then
    : begin
    : GameOver;
    : Quit := true;
    : end;
    : end;
    :
    : procedure DoZap;
    : var i:integer;
    : begin
    : for i := 50 downto 5 do
    : begin
    : sound(i shl 6);
    : delay(50 div i);
    : end;
    : NoSound;
    : end;
    :
    : procedure CheckHit;
    : begin
    : (*
    : if Active and (MissileCol > 77) then
    : begin
    : MissileRow := TargetRow;
    : MissileCol := pred(TargetCol);
    : end;
    : *)
    : ScrnBase^[MissileRow][MissileCol][0] := BlankSpace;
    : inc(MissileCol);
    : if MissileCol < MaxMissileCol then
    : begin
    : ScrnBase^[MissileRow][MissileCol][0] := MissileSymbol;
    : end
    : else
    : begin
    : if (MissileRow = TargetRow) and (MissileCol = TargetCol) then
    : begin
    : ScrnBase^[TargetRow][TargetCol][0] := BlownSymbol;
    : if SoundFlg then DoZap;
    : IncWin;
    : end
    : else
    : begin
    : IncMiss;
    : end;
    : Active := false;
    : end;
    : end;
    :
    : procedure InitStuff;
    : var S:string;
    : i:integer;
    : begin
    : if ScrnMode = 7 then
    : ScrnBase := @MonoBase
    : else
    : ScrnBase := @ColorBase;
    : S := 'TARGET';
    : for i := 1 to length(S) do
    : ScrnBase^[TitleRow][i][0] := ord(S[i]);
    : Active := false;
    : LoopCount := 0;
    : GunRow := 12;
    : GunCol := 0;
    : MissileRow := 12;
    : MissileCol := 0;
    : TargetRow := 1;
    : TargetCol := 79;
    : TargetSymbol := DownSymbol;
    : ScrnBase^[GunRow][GunCol][0] := GunSymbol;
    : ScrnBase^[TargetRow][TargetCol][0] := UpSymbol;
    : S := 'S = Sunet on/off';
    : for i := 1 to length(S) do
    : ScrnBase^[ScoreRow][i][0] := ord(S[i]);
    : S := 'Apasa Space ca sa tragi!';
    : for i := 1 to length(S) do
    : ScrnBase^[ScoreRow][i+50][0] := ord(S[i]);
    : S := 'HIT';
    : for i := 1 to length(S) do
    : ScrnBase^[ScoreRow][WinCol-length(S)+i][0] := ord(S[i]);
    : S := 'MISS:00';
    : for i := 1 to length(S) do
    : ScrnBase^[ScoreRow][MisCol-length(S)+i][0] := ord(S[i]);
    : S := 'TIME:999';
    : for i := 1 to length(S) do
    : ScrnBase^[TitleRow][TimeCol-length(S)+i][0]:= ord(S[i]);
    : GotoXY(succ(TimeCol),succ(TitleRow));
    : end;
    :
    : {--------------------}
    : begin
    : clrscr;
    : InitStuff;
    : Quit := false;
    : while not(Quit) do
    : begin
    : FireCheck;
    : if Active then CheckHit;
    : inc(loopcount);
    : if LoopCount > 24 then UpdateTarget;
    : end;
    : end.


    [code]ScrnArray = array[0..24,0..79,0..1] of byte;[/code]

    The way that the Text Screen is set up is 80 characters wide and 25 characters high. Also, each character on the screen takes up two bytes of memory (therefore the 0..1). The first byte is the Character (such as 'A' '1' 'r' or whatever. The Second Byte is the color of that character. So if you use the [1] section of the array, you can change the Background/Foreground color of each character on the screen.

    This byte is actually two nibbles (4-bits). The top 4-bits are the background color for the character and the lower 4-bits are the foreground color. So if you set [0,0,1] to Hex Number $17, The very top-left character on the screen will have a background that is Blue (1) and a foreground that is gray (7).
    *NOTE* If you set the background above color 7 (8-15) the character will flash on the screen.

    Phat Nat




  • tipul01tipul01 Posts: 3Member
    : [b][red]This message was edited by Phat Nat at 2005-5-29 20:6:50[/red][/b][hr]
    : : pls help me with this. i'm posting the source code here. i really need your help. what does the [0..1] field of the array do? what is it's use??? i mean, the pointer is called only with the value 0. not evean once with the value 1. pls help....
    : :
    : : program target;
    : : uses crt;
    : : type
    : : ScrnArray = array[0..24,0..79,0..1] of byte;
    : : ScrnPtr = ^ScrnArray;
    : :
    : : var
    : : Ch : char;
    : : ScrnMode : byte absolute $0040:$0049;
    : : MonoBase : ScrnArray absolute $B000:$0000;
    : : ColorBase : ScrnArray absolute $B800:$0000;
    : : ScrnBase : ScrnPtr;
    : : LoopCount : integer;
    : : TargetSymbol : byte;
    : : TargetRow : integer;
    : : TargetCol : integer;
    : : MissileCol : integer;
    : : MissileRow : integer;
    : : GunRow : integer;
    : : GunCol : integer;
    : : Active : boolean;
    : : Quit : boolean;
    : :
    : : const
    : : SoundFlg : boolean = true;
    : :
    : : BlankSpace = $20;
    : : DownSymbol = $1f;
    : : UpSymbol = $1e;
    : : BlownSymbol = $2a;
    : : GunSymbol = $10;
    : : MissileSymbol = $2d;
    : :
    : : TitleRow = 0;
    : : ScoreRow = 24;
    : : TimeCol = 40;
    : : WinCol = 28;
    : : MisCol = 40;
    : : MaxTargetRow = 24;
    : : MinTargetRow = 0;
    : : MinMissileCol = 1;
    : : MaxMissileCol = 79;
    : :
    : :
    : : {-------------------------------------}
    : : procedure GameOver;
    : : var S:string;
    : : i:integer;
    : : begin
    : : S := '** GAME OVER **';
    : : for i := 1 to length(S) do
    : : ScrnBase^[8][i+30][0]:= ord(S[i]);
    : : end;
    : :
    : : procedure DecTime;
    : : begin
    : : dec(ScrnBase^[TitleRow][TimeCol][0]);
    : : if ScrnBase^[TitleRow][TimeCol][0] < $30 then
    : : begin
    : : ScrnBase^[TitleRow][TimeCol][0] := $39;
    : : dec(ScrnBase^[TitleRow][TimeCol-1][0]);
    : : if ScrnBase^[TitleRow][TimeCol-1][0] < $30 then
    : : begin
    : : ScrnBase^[TitleRow][TimeCol-1][0] := $39;
    : : dec(ScrnBase^[TitleRow][TimeCol-2][0]);
    : : end;
    : : end;
    : : if (ScrnBase^[TitleRow][TimeCol][0] < $31) and
    : : (ScrnBase^[TitleRow][TimeCol-1][0] < $31) and
    : : (ScrnBase^[TitleRow][TimeCol-2][0] < $31) then
    : : begin
    : : GameOver;
    : : Quit := true;
    : : end;
    : : end;
    : :
    : :
    : : procedure UpdateTarget;
    : : begin
    : : if SoundFlg then sound(400);
    : : LoopCount := 0;
    : : ScrnBase^[TargetRow][TargetCol][0] := BlankSpace;
    : : if TargetSymbol = UpSymbol then
    : : begin
    : : dec(TargetRow);
    : : if TargetRow < succ(MinTargetRow) then
    : : TargetSymbol := DownSymbol;
    : : end
    : : else
    : : begin
    : : inc(TargetRow);
    : : If TargetRow > pred(MaxTargetRow) then
    : : TargetSymbol := UpSymbol;
    : : end;
    : : ScrnBase^[TargetRow][TargetCol][0] := TargetSymbol;
    : : delay(10);
    : : nosound;
    : : DecTime;
    : : end;
    : :
    : : procedure FireCheck;
    : : begin
    : : Ch := #0;
    : : if KeyPressed then
    : : begin
    : : Ch := UpCase(ReadKey);
    : : if Ch = #0 then Ch := char(ord(ReadKey) or $80);
    : : end;
    : : if (Ch = #32) and not(Active) then
    : : begin
    : : MissileCol := MinMissileCol;
    : : ScrnBase^[MissileRow][MissileCol][0] := MissileSymbol;
    : : Active := true;
    : : end;
    : : if (Ch < #13) and (Ch > #0) or (Ch = 'Q') then Quit := true;
    : : if Ch = 'S' then SoundFlg := not(SoundFlg);
    : : if Active and SoundFlg then sound(MissileCol shl 8);
    : : delay(10);
    : : nosound;
    : : end;
    : :
    : : procedure IncWin;
    : : begin
    : : inc(ScrnBase^[ScoreRow][WinCol][0]);
    : : if ScrnBase^[ScoreRow][WinCol][0] > $39 then
    : : begin
    : : ScrnBase^[ScoreRow][WinCol][0]:= $30;
    : : inc(ScrnBase^[ScoreRow][pred(WinCol)][0]);
    : : end;
    : : if (ScrnBase^[ScoreRow][WinCol][0] > $38) and
    : : (ScrnBase^[ScoreRow][pred(WinCol)][0] > $38) then
    : : begin
    : : GameOver;
    : : Quit := true;
    : : end;
    : : end;
    : :
    : : procedure IncMiss;
    : : begin
    : : inc(ScrnBase^[ScoreRow][MisCol][0]);
    : : if ScrnBase^[ScoreRow][MisCol][0] > $39 then
    : : begin
    : : ScrnBase^[ScoreRow][MisCol][0] := $30;
    : : inc(ScrnBase^[ScoreRow][pred(MisCol)][0]);
    : : end;
    : : if (ScrnBase^[ScoreRow][MisCol][0] = $38) and
    : : (ScrnBase^[ScoreRow][pred(MisCol)][0] = $38) then
    : : begin
    : : GameOver;
    : : Quit := true;
    : : end;
    : : end;
    : :
    : : procedure DoZap;
    : : var i:integer;
    : : begin
    : : for i := 50 downto 5 do
    : : begin
    : : sound(i shl 6);
    : : delay(50 div i);
    : : end;
    : : NoSound;
    : : end;
    : :
    : : procedure CheckHit;
    : : begin
    : : (*
    : : if Active and (MissileCol > 77) then
    : : begin
    : : MissileRow := TargetRow;
    : : MissileCol := pred(TargetCol);
    : : end;
    : : *)
    : : ScrnBase^[MissileRow][MissileCol][0] := BlankSpace;
    : : inc(MissileCol);
    : : if MissileCol < MaxMissileCol then
    : : begin
    : : ScrnBase^[MissileRow][MissileCol][0] := MissileSymbol;
    : : end
    : : else
    : : begin
    : : if (MissileRow = TargetRow) and (MissileCol = TargetCol) then
    : : begin
    : : ScrnBase^[TargetRow][TargetCol][0] := BlownSymbol;
    : : if SoundFlg then DoZap;
    : : IncWin;
    : : end
    : : else
    : : begin
    : : IncMiss;
    : : end;
    : : Active := false;
    : : end;
    : : end;
    : :
    : : procedure InitStuff;
    : : var S:string;
    : : i:integer;
    : : begin
    : : if ScrnMode = 7 then
    : : ScrnBase := @MonoBase
    : : else
    : : ScrnBase := @ColorBase;
    : : S := 'TARGET';
    : : for i := 1 to length(S) do
    : : ScrnBase^[TitleRow][i][0] := ord(S[i]);
    : : Active := false;
    : : LoopCount := 0;
    : : GunRow := 12;
    : : GunCol := 0;
    : : MissileRow := 12;
    : : MissileCol := 0;
    : : TargetRow := 1;
    : : TargetCol := 79;
    : : TargetSymbol := DownSymbol;
    : : ScrnBase^[GunRow][GunCol][0] := GunSymbol;
    : : ScrnBase^[TargetRow][TargetCol][0] := UpSymbol;
    : : S := 'S = Sunet on/off';
    : : for i := 1 to length(S) do
    : : ScrnBase^[ScoreRow][i][0] := ord(S[i]);
    : : S := 'Apasa Space ca sa tragi!';
    : : for i := 1 to length(S) do
    : : ScrnBase^[ScoreRow][i+50][0] := ord(S[i]);
    : : S := 'HIT';
    : : for i := 1 to length(S) do
    : : ScrnBase^[ScoreRow][WinCol-length(S)+i][0] := ord(S[i]);
    : : S := 'MISS:00';
    : : for i := 1 to length(S) do
    : : ScrnBase^[ScoreRow][MisCol-length(S)+i][0] := ord(S[i]);
    : : S := 'TIME:999';
    : : for i := 1 to length(S) do
    : : ScrnBase^[TitleRow][TimeCol-length(S)+i][0]:= ord(S[i]);
    : : GotoXY(succ(TimeCol),succ(TitleRow));
    : : end;
    : :
    : : {--------------------}
    : : begin
    : : clrscr;
    : : InitStuff;
    : : Quit := false;
    : : while not(Quit) do
    : : begin
    : : FireCheck;
    : : if Active then CheckHit;
    : : inc(loopcount);
    : : if LoopCount > 24 then UpdateTarget;
    : : end;
    : : end.
    :
    :
    : [code]ScrnArray = array[0..24,0..79,0..1] of byte;[/code]
    :
    : The way that the Text Screen is set up is 80 characters wide and 25 characters high. Also, each character on the screen takes up two bytes of memory (therefore the 0..1). The first byte is the Character (such as 'A' '1' 'r' or whatever. The Second Byte is the color of that character. So if you use the [1] section of the array, you can change the Background/Foreground color of each character on the screen.
    :
    : This byte is actually two nibbles (4-bits). The top 4-bits are the background color for the character and the lower 4-bits are the foreground color. So if you set [0,0,1] to Hex Number $17, The very top-left character on the screen will have a background that is Blue (1) and a foreground that is gray (7).
    : *NOTE* If you set the background above color 7 (8-15) the character will flash on the screen.
    :
    : Phat Nat
    :
    :

    thank you very much mr Phat Nat! i am in your det. Tipul01


Sign In or Register to comment.