[Turbo Pascal] Q&A official thread

Page 16/17
9 | 10 | 11 | 12 | 13 | 14 | 15 | | 17

By Manuel

Ascended (17943)

Manuel's picture

08-05-2020, 21:11

You can't, as it's against the rules of the language. And IMHO, that's good, as it makes the code better readable. And the machine code will be the same anyway, as PascalDragon explained. Smile

By pgimeno

Champion (289)

pgimeno's picture

09-05-2020, 21:02

Do you mean to do: if Boolean(B) then ...?

program bool;
var
  b: byte;
begin
  b := 3;
  if Boolean(b) then
    writeln('Works');
end.

By Manuel

Ascended (17943)

Manuel's picture

09-05-2020, 21:11

Ah, yeah, explicit conversion! Good idea Smile

By PascalDragon

Supporter (9)

PascalDragon's picture

10-05-2020, 00:34

rolandve wrote:

My case is about the situation where B is not a boolean but a number. Somewhere TP assigns a number to True or False (its byte size). What.you call expression is what I refer to when I say: value condition value, so the expression can be if (B > 0) . My question is: how can I trick TP in to accepting an integer as a boolean. That way you don't need an expression B > 0 but B becomes the result of the evaluation.

But why would you even want to? The code is the same no matter if you check for 0 or for True/False. I've just tested it with Turbo Pascal 3.3 on MSX myself:

program ttest;

var
  c: Integer;
  by: Byte;
  bo: Boolean;
begin
  c := $55AA;
  by := 1;
  bo := True;
  if by > 0 then
    c := c + 1;
  if bo then 
    c := c + 1;
  if Boolean(by) then
    c := c + 1;
end.

(The $55AA is just to find the code quickly in the dissassembly)

In all three cases the comparison boils down to:

; load value into l
bit 0,l
jp z,label
pgimeno wrote:

Do you mean to do: if Boolean(B) then ...?

program bool;
var
  b: byte;
begin
  b := 3;
  if Boolean(b) then
    writeln('Works');
end.

This only works by accident. Try something where the lowest bit isn't set, like 2. Wink This is because in Pascal a Boolean has the values False := 0 and True := 1. True in Pascal is not <> 0. This is also the case in Turbo Pascal 3.3 for MSX.

An optimising compiler like FPC will abuse this even more.

By pgimeno

Champion (289)

pgimeno's picture

10-05-2020, 00:51

PascalDragon wrote:

This only works by accident. Try something where the lowest bit isn't set, like 2. Wink This is because in Pascal a Boolean has the values False := 0 and True := 1. True in Pascal is not <> 0. This is also the case in Turbo Pascal 3.3 for MSX.

An optimising compiler like FPC will abuse this even more.

I seem to recall that TP4+ explicitly defined the behaviour of typecasting an integer to boolean to be zero = false and nonzero = true. I might be mistaken, it's been a while. I wrongly assumed it was the case for TP3 as well, sorry.

Edit: Just tested in Turbo Pascal 3.01A for DOS and Boolean(2) evaluates to True.

By rolandve

Master (254)

rolandve's picture

10-05-2020, 10:49

Limitations exist in any language and any compiler. Things like ' if B then' or 'expression:a:b' are shorter ways of writing often used logical situations. In the end, its not about the elegance of the high-level language but the efficiency of the compiler for delivering the fastest or smallest code.

By Manuel

Ascended (17943)

Manuel's picture

14-05-2020, 22:49

Manuel wrote:

Really? Then I must have completely forgotten that.

Looked it up:

Quote:

REM filesel.inc DOES NOT WORK with Turbo Pascal 3.3 due to the BUG in the
pointer operations of TP 3.3

I never had any problems with it, but perhaps it also occurs in other programs/libs indeed.

By rolandve

Master (254)

rolandve's picture

24-05-2020, 12:43

Hi All,

I'm working with a linked list in my code. Although that is very dynamic, it has a huge overhead. 32 KB memory disappears in the blink of an eye. So my simplest question would be: is there a memory management library for TP3? MSX-DOS 2 has a lot of logic for using the memory mapper but if you would want to use it for a linked list, you would have to code all the logic that translates the current nodes number, too the right memory-bank etc.Perhaps someone already did something like that?

Thanks all!

By rjp

Master (191)

rjp's picture

04-07-2020, 23:44

Hi lads,

I'm looking at Kari Lammassaari's libraries, and I found the scrollup.inc and scrolldo.inc, which I'm interested. But couldn't understand neither found an example of the routines.

Procedure ScrollWindowUp(ScrollAreaPtr:Integer);
{
The defined portion of screen is scolled up and an empty line is written
at the bottom line of the scrolled area

SrollAreaPtr points 4-byte array/group:

offs 0 = upper left column (x) of the area to be scrolled (1st)
+1 = uppermost row (y) of the area to be scrolled (2nd)
+2 = width of the area to be scrolled (3rd)
+3 = height of the area to be scrolled (4th)
}

I couldn't understand ScrollAreaPtr. Is it a pointer? How can I give it info? I tried first 0 * 1st + 1 * 2nd + 2 * 3rd + 3 * 4th, and I've got no success.

So, I tried to place all info into a array and tell the procedure to get this info from this array, using a integer variable: PScrollArea: integer absolute ScrollArea.

Again, I wasn't successful. Any ideas?

By rjp

Master (191)

rjp's picture

05-07-2020, 00:12

Unfortunately, TP3 don't know how to handle with directories, because it's a CP/M compiler. But I found that we can cheat TP3 using the APPEND MSX-DOS 2 environment variable.

I created a procedure, called CheatAPPEND, so I can handle with files which are located in other directories.

http://github.com/ricardojpinheiro/utils/ . Get any .PAS there and you'll find this procedure.

Hope this helps.

Cheers, Ricardo.

Page 16/17
9 | 10 | 11 | 12 | 13 | 14 | 15 | | 17