[Turbo Pascal] Q&A official thread

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

By raymond

Champion (441)

raymond's picture

02-08-2019, 10:30

Yes, found it there on disk 37 as well Big smile

By rolandve

Master (218)

rolandve's picture

26-04-2020, 11:30

I've got a nice question for experts. This code hangs the machine, but why? The routine under suspicion seems to work when called with some delays. I've got two pascal Inkey routines. One coded in Pacal, one calling chGET function at bios #9F
Since I want to use inkey in a loop, I want the check on the keyboard to be as fast as possible (there are some other operations after the inkey), hence the attempt to call bios itself and not let turbo pascal do it for me.

Function Inkey : char;
var 
	key : char;
begin;
	key:=#0;
	if keypressed then
		begin
			read(kbd,key);
		end;
	inkey:=key;
end;

Function ink : char;
Const
        ctGET    = $009F;  {chGET - get one character waiting}
Var
        regs   : TRegs;
        EXPTBL : Byte Absolute $FCC1; { Slot 0 }

Begin;
  regs.IX := ctGET;
  regs.IY := EXPTBL;
  CALSLT( regs );
  ink := chr(regs.A);
End;

Procedure Bench;
	Var
		Jiffy : integer absolute $FC9E;
		sJiffy : integer;
		lus : integer;
		key : char;

	Begin;
		sJiffy:=Jiffy;
		for lus:=1 to 10000 do
			key:=Inkey;
		writeln(jiffy-sJiffy);
		sJiffy:=Jiffy;
		lus:=0;
		for lus:=1 to 10000 do
			key:=ink;
		writeln(Jiffy-sJiffy);
	end;

This benchmark routine (procedure Bench) shows 13 on average for the first 10.000 inkeys. It hangs on the next 10.000.
When not used in a tight loop, the procedure Ink seems to work ok. Does anyone know why Ink hangs, because if there is an error in ink, then this is a problem waiting to occur in later code. So anyone know why Ink hangs?

By Pencioner

Scribe (1136)

Pencioner's picture

26-04-2020, 14:43

I have an asm macro (which iirc i got at Grauw's site):

macro call_BIOS bios_addr
    ld     iy, (EXPTBL-1)       ;BIOS slot in iyh
    ld     ix, bios_addr
    call   CALSLT
endmacro

And i see that in your code it takes IY from EXPTBL not from EXPTBL-1 - don't know how this might affect your code, just noticed this difference

By pgimeno

Master (188)

pgimeno's picture

26-04-2020, 18:17

Doesn't CALSLT disable interrupts? Maybe you should re-enable them after the call.

By rolandve

Master (218)

rolandve's picture

26-04-2020, 20:46

Thanks!, tried.The results are surprising:
Turbopascal inkey routine: 13 (jiffy difference)
Call slot : 134 (jiffy difference)

Makes you wonder where that difference comes from.

By rolandve

Master (218)

rolandve's picture

27-04-2020, 09:48

And another one with Turbo Pascal 3.3f

When I use the function writeln, I get output. When I use Kari's code in a openMSX (8250 profile or boosted TurboR) the machine hangs after writing text using Kari's fast write routine. Popolony2K's libraries also behaves erratic on interaction addressing VRAM. This is a 3.3f issue. Using 3.0 the program runs as expected. You can try, with this code straight from the libraries: names left out for privacy. Does anyone know a work around for hanging on VRAM access? Thanks.

program VRAM;

Type TPString = String[255];

Var 
  tekst : TPString;

Procedure WriteVram(VramBlockUsed:Byte;
                    VramAddr,RamAddr,ByteCount:Integer);

{ VramBlocUsed  = 0 = first 64 Kb
                  1 = second 64 Kb
                  2 = Expansion Vram 64 Kb }
Var Expansion, AddrHi, AddrMid, AddrLo :Byte;
Begin
  If VramBlockUsed = 2 Then Expansion := $40 {Set the bit 6 (MXC) }
   Else Expansion := 0 ; {No expansion vram used}
  AddrHi := Hi(VramAddr) Div $40;
  If VramBlockUsed = 1 Then AddrHi := AddrHi + 4 ;
    {Set addr bit 16 in reg 14 = bit 2 }
  AddrLo := Lo(VramAddr);
  AddrMid := Hi(Vramaddr) And 63 ;

  Inline(
      $F3/$3A/ Expansion /$D3/$99/$3E/$2D/$F6/$80/$D3/$99/$3A/ AddrHi /$D3/
     $99/$3E/$0E/$F6/$80/$D3/$99/$3A/ AddrLo /$00/$D3/$99/$3A/ AddrMid /$F6/
      $40/$D3/$99/$2A/ RamAddr /$ED/$4B/ ByteCount /$7E/$D3/$98/$23/$0B/$79/
      $B0/$20/$F7/ $F3/$3e/ 0  /$D3/$99/$3E/$2D/$F6/$80/$D3/$99
        );
End;


Procedure FastWrite(St :TpString);

Var CSRX :Byte Absolute $F3DD;
    CSRY :Byte Absolute $F3DC;
    TXTNAM :Integer Absolute $f3b3;
    len  :Byte;
    VramLocation :Integer;
    Width:Byte;
Begin
   Width := Mem[$F3B0];
   If Width<80 then Width := 40 else Width := 80;
   Len := Ord(St[0]);
   VramLocation := (CSRY-1) * Width + CSRX-1 + TXTNAM;
   If VramLocation > 2000 Then VramLocation := 0;
   WriteVram(0,VramLocation,Addr(St)+1,Len);
   CSRY := ((VramLocation + Len) Div Width)+1 ;
   CSRX := ((VramLocation + Len) Mod Width)+1 ;
End; {FastWrite}

Procedure FastWriteln(St :TpString);

Var CSRX :Byte Absolute $F3DD;
    CSRY :Byte Absolute $F3DC;
    TXTNAM :Integer Absolute $f3b3;
    len  :Byte;
    VramLocation :Integer;
    Width:Byte;
Begin
   Width := Mem[$F3B0];
   If Width<80 then Width := 40 else Width := 80;
   Len := Ord(St[0]);
   VramLocation := (CSRY-1) * Width + CSRX-1 + TXTNAM;
   If VramLocation > 2000 Then VramLocation := 0;
   WriteVram(0,VramLocation,Addr(St)+1,Len);
   CSRY := (VramLocation + Len) Div Width+2 ;
   CSRX := 1;
End; {FastWriteln}

begin;
  tekst:='Hello World';
  FastWrite(tekst);
  repeat until keypressed;
end.

By Manuel

Ascended (16696)

Manuel's picture

27-04-2020, 12:40

I have used FastWrite(Ln) in the past in combination with TP3.3f, without issues.

I can send you my disk image with an example program and the exact include files I used.

By rolandve

Master (218)

rolandve's picture

27-04-2020, 18:01

Manuel wrote:

I have used FastWrite(Ln) in the past in combination with TP3.3f, without issues.

I can send you my disk image with an example program and the exact include files I used.

I downloaded these sources from your site. I've found a few other routines that work in 3.3f and 3.
Thanks

By Manuel

Ascended (16696)

Manuel's picture

28-04-2020, 00:25

So, you're not interested in my disk?

By rolandve

Master (218)

rolandve's picture

28-04-2020, 09:09

They are welcome! Yesterday I spend all day analysing other peoples code, to discover the tricks they used Smile

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