• Please review our updated Terms and Rules here

More Pascal code at my site! :-))

CP/M User

Veteran Member
Joined
May 2, 2003
Messages
2,986
Location
Back of Burke (Guday!), Australia
I'll just start my mentioning to most of you this program will seem pointless.

For those interested, I've added some more code to my site:
http://www.geocities.com/cpm22_user/programs/Amstrad_CPC/TurboPAS/

I've called it brkdown (well it's supposed to be Breakdown, but it's better than nothing). No Sorry lads, it's not a game (so no knocking down walls with ball & bat) I'm afraid. It's a demonstration of taking a large integer number (works better as a hex though) & spliting it into two smaller bytes. For example, once executed the program will ask you to enter a number (between $0 & $FFFF <- The dollar signs are important because this is the way TP handles Hexidecimal numbers or anything between -32767 & 32767 as an int, don't know why it won't take -32768, this is supposed to represent $8000, though $8000 works as entered in the program).
Anyway once the integer of some kind is entered, the program splits the numbers into byte size numbers, so $ffff is $ff & $ff, $f0ff is $f0 $ff (the results are displayed in hexidecimal <- this routine is from my dechex.pas program which I mentioned earlier).

I wrote this program because eventually my other program will need to take a integer value & use this for making a byte sized number <- which works better for what I'm doing.

Just one last thing, does anybody know of a way to print an error message if the use enters a invalid number or something? If somebody does a runtime error is the result, I'd be interested to know about that.

Cheers,
CP/M User.
 
Re: More Pascal code at my site! :))

"CP/M User" wrote:

> Just one last thing, does anybody know of a way to print
> an error message if the use enters a invalid number or
> something? If somebody does a runtime error is the
> result, I'd be interested to know about that.

Just in regards to the error checking, I've successfully written
a I/O checking routine which directs the program to a message
advising the user that invalid input was entered & to enter it
again. In case anybody downloaded this program prior to this
announcement, could you please download the current update
(sorry about that if you have).

Thanks,
CP/M User.
 
I just browsed a CD with some old archives of mine, including a lot of Pascal programs written in Turbo Pascal 4.0 many years ago (1993 to be exact). For a few of the programs, I saved an executable, and to my delight, the programs still are executable in a command shell in Win98. Even the one program that directly plots inverse spaces into screen memory at $B800 runs correctly! That one was invented to be used on our Wang PC compatible, which ran an old DOS version without ANSI graphics. Thus I made a small program that lets you plot a picture using letters A to O for fifteen foreground colours, and then convert the letters to IBMSCII codes 240-255 and a special viewer which interprets the codes as different colours. Regular text would be displayed in the last used colour, but otherwise the program was limited to plotting inverted spaces.

Looking at the source code, there are things I barely understand what they do. I also get the feeling that Turbo Pascal was customized as a very high level language, maybe more than regular Pascal dialects are? I mean, structures like these:

Code:
var f: file of char;

procedure kpr;
  begin
    Repeat until keypressed;
    c:=readkey;
  end;

begin
  assign(f,"file.txt");
  ( .. snipped code ..)
  kpr;
end.

I particularly like "repeat until keypressed", very non-technical and nice.
 
"carlsson" wrote:

> I just browsed a CD with some old archives of mine, including a lot of
> Pascal programs written in Turbo Pascal 4.0 many years ago (1993 to
> be exact). For a few of the programs, I saved an executable, and to my
> delight, the programs still are executable in a command shell in Win98.

> Even the one program that directly plots inverse spaces into screen
> memory at $B800 runs correctly! That one was invented to be used on
> our Wang PC compatible, which ran an old DOS version without ANSI
> graphics. Thus I made a small program that lets you plot a picture
> using letters A to O for fifteen foreground colours, and then convert the
> letters to IBMSCII codes 240-255 and a special viewer which interprets
> the codes as different colours. Regular text would be displayed in the
> last used colour, but otherwise the program was limited to plotting
> inverted spaces.

That sounds interesting, if you want to can you PM the code through?

I did a few programs which use $B800 which are perfectly legimitate in
CGA Screen modes - so they also apply on CGA. It's the later EGA/VGA
which have segments which start at a different address $A000 & Mono at
$B000. In CGA screen modes (which include text modes & Graphical
modes) all start at $B800!
The trouble to all of this though is the EGA card. It doesn't seem to handle
CGA stuff very well - particuarly when you get into the nitty gritty and
start using the non-BIOS supported MODE (160x100x16) & while
VGA/SVGA handle this one better modifications are required to get the
portions correct. EGA would no doubt handle 80x25, but 'am unsure about
it doing Mode 4,5 - 320x200x4 & Mode 6 640x200x2. Mode 7 is the old
Mono text screen mode 80x25. From what I've seen, the VGA & SVGA
handle CGA much better, cause all you need to do to access them is tell
which screen mode you want & it the VGA does the rest (downto the
colouring & resolution).

> Looking at the source code, there are things I barely understand what
> they do. I also get the feeling that Turbo Pascal was customized as a
> very high level language, maybe more than regular Pascal dialects are?
> I mean, structures like these:

I'm kinda suprised no-one acknowledge's this - meaning I've had people
tell me they found BASIC easier to understand. Speaking from a TP3
perspective though, it has some issues which most compilable languages
which are direct problems in relation to peforming calculations. TP 4 (I
think) & later address some of this by using cheat statements like INC();
& DEC(); which simply speed up simple calculations. TP 3 & earlier are
limited to "variable:=variable+1" or "variable:=variable-1" which does
the same thing as "INC(variable,1);" or "DEC(variable,1);" though very
slowly. One advantage I found in TP 3 is the use of Arrays - so instead of
calculating for the results, provide the results. Much better.

But it's interesting you said it's a Very High-Level Language, cause people
think BASIC is easier. Personally, I think BASIC is far more complicated
& messy (when you start messing about with GOTOs), so I just say for
once that these people were once stuck in the BASIC boom of the 80s &
that they'll never accept anything else. I've said it before & I'll say it
again, there's many tutorials, books, programs out there for TP (even TP
3), so it's not as if there's nothing out there. I've even had some fun
reworking a BASIC program into TP 3 - so there's no reason why it can't
be done! ;-)

Code:
var f: file of char;

procedure kpr;
  begin
    Repeat until keypressed;
    c:=readkey;
  end;

begin
  assign(f,"file.txt");
  ( .. snipped code ..)
  kpr;
end.

> I particularly like "repeat until keypressed", very non-technical and nice.

What was that old language which wasn't, of yeah Pseudo-Code. "repeat
until keypressed" is about as close as it gets to it! ;-)

CP/M User.
 
"Terry Yager" wrote:

> Isn't that kinda like a "LOOP UNTIL" (what language is that?)
> statement? ...Or even "DO WHILE...?" (Sorry, sometimes I tend to
> think in Pseudo-Code).

I think "Do...While" is actually a legimate statement, not sure if it's C, or
something else. It works the same way a "Repeat...Until" would work in
Pascal (I know that much).

"Loop...Until" could be Pseudo-code even though it has the same type of
Loop structure in a "Repeat Until" where a process is initiated & is last
checked - exit's if the condition is met. Hence "Repeat Until Keypress;"
simply wait's for a Keypress! ;-)

It's true that while "Repeat until Keypress" isn't quite Pseudo-Code it has
that English about it which makes it close to Pseudo-Code (the rule of
course being with Pseudo-Code is it's requirement to resemble English -
this is the requirement of Pseudo-code! ;-)

CP/M User.
 
The "do while" construct is something I remember from S-BASIC, but I seem to recall the "loop until" construct from another language, or even the same one(?), or even mebbe BASIC-09 on the TRS-80 CoCo, under OS-9?

--T
 
Terry Yager said:
The "do while" construct is something I remember from S-BASIC, but I seem to recall the "loop until" construct from another language, or even the same one(?), or even mebbe BASIC-09 on the TRS-80 CoCo, under OS-9?

--T


I think BBC basic had that?
 
Jorg said:
Terry Yager said:
The "do while" construct is something I remember from S-BASIC, but I seem to recall the "loop until" construct from another language, or even the same one(?), or even mebbe BASIC-09 on the TRS-80 CoCo, under OS-9?

--T


I think BBC basic had that?

Could be, I have played with BBC a little...

--T
 
Words like do-while, repeat-until and so on probably have been used in a lot of verbose programming languages. Pascal has a while statement too, IIRC - one has to decide whether the test should be executed before or after one round in the loop has been taken.

In this case, the actual loop is empty and the test is everything. The keypressed and readkey procedures are part of the TurboPascal unit "CRT" which my program utilizes. For a corresponding program in C, one would probably use a getch() call in some curses (yes, it is called curses or ncurses!) or a conio unit, depending on operating system. Theoretically, I know how to get unbuffered I/O, at least from Unix systems, but it is rather complex.
 
CP/M User said:
if you want to can you PM the code through?
Sure, or by e-mail if you prefer. As I wrote, I have a bunch of various code, including a horse betting game which I put a lot of effort into.

I've even had some fun reworking a BASIC program into TP 3
I remember using some converter from Turbo Pascal to Turbo C. Like most automatic converters, it did a very messy job. A lot of strange constructs compared to how you normally would write them in C. It didn't even compile straight out of the box, IIRC. If it is only a small amount of code, it often is better to rewrite it from scratch, using a listing in the other programming language as the source.
 
"CP/M User" wrote:

>> if you want to can you PM the code through?

"carlsson" wrote:

> Sure, or by e-mail if you prefer. As I wrote, I have a bunch of various
> code, including a horse betting game which I put a lot of effort into.

Yeah you can e-mail that graphical text program if you wish.

I won't trouble you for the horse betting game, but if you have the EXE,
I'll have a look at it & review it for you.

Was the text program you mention earlier very large (e.g. Over 1000
lines of program?). It doesn't worry me if it's under that sort of limit, but
if the program becomes too big, it's just too much to handle (time wise).

>> I've even had some fun reworking a BASIC program into TP 3

> I remember using some converter from Turbo Pascal to Turbo C. Like
> most automatic converters, it did a very messy job. A lot of strange
> constructs compared to how you normally would write them in C. It
> didn't even compile straight out of the box, IIRC. If it is only a small
> amount of code, it often is better to rewrite it from scratch, using a
> listing in the other programming language as the source.

Yeah, I never really tried writing a program which interprets one lot of
source code into another - merely because I have little faith in them. I
merely turned myself into the program by interpreting the code myself. I
done some BASIC to TP 3 & TP 4.x & later based code interpretations
back into TP 3. Admittibly it's a lot harder translating BASIC to TP 3 cause
every statement needs to be translated into it's TP equivalant. TP
4,5,5.5,6 & 7 still has code which allows it to be used in TP 3 - it's just a
question of interpreting the later code.

You mention the use of READKEY ealier in another thread which TP 3
doesn't support - however adding a library with a little interrrupt calling
soon changes that. The other alternative which TP 3 support is the use of
the KBD function in conjuction with the read statement. It's structured
differently, though is more or less the same.

CP/M User.
 
The program to plot colourful lowres pictures consists of two part. First the converter to convert letters A to O into the codes 240..255. Then the viewer program to display those pictures. The amount of code is not greater than I can spam the forum publically.

Code:
program COLconvert;

{$I-}

uses CRT;

var f,g: file of char;
    c: char;
    b,d: byte;
    ext: boolean;
    s: array [1..2] of string;

begin
  IF (PARAMSTR(1)<>'') and (PARAMSTR(2)<>'') THEN BEGIN
    for d:=1 to 2 do begin
      ext:=false;
      IF PARAMSTR(d)<>'' THEN BEGIN
        s[d]:=paramstr(d);
        for b:=1 to length(s[d]) do if s[d][b]='.' then ext:=true;
        if ext=false then s[d]:=s[d]+'.col';
      end;
    end;
    assign (f,s[1]); assign (g,s[2]);
    reset (f); rewrite (g);
    IF IORESULT<>0 THEN writeln ('File(s) Not Found') else begin
      while not eof(f) do begin
        read (f,c); if (ord(c)>64) and (ord(c)<80) then c:=chr(ord(c)+176);
        write (g,c);
      end;
      close (f);
    end;
  END ELSE begin
    writeln ('COLor Converter v1.2 by Anders Carlsson');
    WRITELN ('Usage: COL-CV <path> filename1 <path> filename2');
  end;
  {$I+}
end.

Code:
program PICLOAD;

{$I-}

uses CRT;

var f: file of char;
    c: char;
    s: string;
    b,x,y: byte;
    ext: boolean;
    offs: word;

procedure kpr;
  begin
    b:=wherey;
    gotoxy (1,25);
    write ('<PRESS A KEY>');
    Repeat until keypressed;
    c:=readkey;
    gotoxy (1,25);
    clreol;
    gotoxy (1,b);
  end;

begin
  ext:=false;
  y:=0;
  x:=0;
  IF PARAMSTR(1)<>'' THEN BEGIN
    s:=paramstr(1);
    for b:=1 to length(s) do if s[b]='.' then ext:=true;
    if ext=false then s:=s+'.col';
    assign (f,s);
    reset (f);
    IF IORESULT<>0 THEN writeln ('File Not Found') else begin
      clrscr;
      b:=0;
      while not eof(f) do begin
        read (f,c);
        offs:=y*160+x*2;
        if ord(c)>240 then begin
          memw[$b800:offs]:=((ord(c)-240)*256)+ord('Û');
          x:=x+1;
        end else case ord(c) of
          32..240: begin
            memw[$b800:offs]:=ord(c)+256;
            x:=x+1;
          end;
          10: x:=0;
          13: y:=y+1;
        end;
        if x=0 then inc(b);
        if b=48 then begin kpr; b:=0; end;
      end;
      close (f);
      WRITELN;
      kpr;
    end;
  END ELSE begin
    writeln ('COLor Loader v1.4 by Anders Carlsson');
    WRITELN ('Usage: COL-LD <path> filename');
  end;
  {$I+}
end.

I'm not sure which code ord('Û') is supposed to match; it may be a conversion bug from IBMSCII to Latin-1.
 
Back
Top