Post Reply 
(HP50g) HpPascal and contrast of the screen
10-26-2017, 11:31 PM (This post was last modified: 10-26-2017 11:40 PM by Gilles59.)
Post: #1
(HP50g) HpPascal and contrast of the screen
Hi All,

I wrote a breakout for the HP50g in HPPascal. See http://www.hpcalc.org/details/8662

For this program I have to change the contrast of the screen. So I use the procedure 'Contraste' in the "systemHP" unit of HPPascal. I would like that my program reset the initial contrast when it ends. The procedure to change the constrast in HPPascal is define like this :

Code:
procedure Contraste (c: byte);
begin
  asm
     A=R1
     D1=A
     A=DAT1 B
     LC(5) #101
     D1=C
     DAT1=A P
     D1=D1+ 1
     A=DAT1 P
     LC(1) #E
     A=C&A P
     DAT1=A P
  end;

A function (that returns a value in Pascal) is define in HPPascal like this (for example) :

Code:
function Keypressed : boolean;
begin
  asm
     gosbvl #4999        *KeyInBuff?
     la(1) 1
     goc yaunetouche
     la(1) 0
     :yaunetouche
    c=r1
    d1=c
    dat1=a p
 end;
end;


I know nothing about saturn ASM. I want to create a function that returns the value of the contast of the screen, Something like :

Code:

Function GetContrast : Byte;
 Begin
  Asm
  ....
 End;

Could somenone help me for the ASM code ?

In the documentation (in french) I found this : :

Quote:Appel d'une fonction ou d'une procédure

Pour appeler une fonction ou une procédure, HP PASCAL opère de la manière suivante :

Dans le cas d'une fonction, le pointeur de pile subit un incrément de la taille du résultat de la fonction.

L'appel d'une fonction de type BYTEBYTE, par exemple, sera précédé de l'instruction assembleur

D0=D0+ 2
* Réserve 2 quartets pour le résultat de la fonction

Ensuite, aussi bien pour les fonctions que pour les procédures, HP PASCAL place dans la pile tous les paramètres (facultatifs) qui sont à transmettre à la fonction ou la procédure.


Par exemple, pour appeler une fonction ADD définie par :

FUNCTION ADD (n1, n2: BYTE) : BYTE;


HP PASCAL placera sur la pile deux BYTEBYTE, par exemple:

LA(2) #45
DAT0=A B
D0=D0+ 2 * Place le BYTE 69 sur la pile

LA(2) #4E
DAT0=A B
D0=D0+ 2 * Place le BYTE 78 sur la pile

Enfin, la fonction ou la procédure est appelée par un simple GOSUBL suivi de son nom.

L'appel de la fonction ADD s'effectuera :

GOSUBL ADD * Appel de la fonction

Après le retour d'une procédure, D0 pointe sur sa valeur initiale, avant l'empilement des paramètres éventuels. Il n'y a donc aucune opération supplémentaire à effectuer.

Après le retour d'une fonction, le résultat renvoyé par celle-ci se retrouve sur la pile, à l'emplacement réservé au départ par l'instruction D0=D0+ ?

Les paramètres éventuels sont automatiquement dépilés.


Pour utiliser le résultat de la fonction, il suffit donc de dépiler ce résultat par les instructions prévues à cet effet.

Dans notre exemple de la fonction ADD, le résultat est placé dans le registre A champ B à l'aide des simples instructions suivantes :

D0=D0- 2
A=DAT0 B
* Prend le résultat sur la pile et le place dans A:B
Find all posts by this user
Quote this message in a reply
10-27-2017, 03:35 AM
Post: #2
RE: (HP50g) HpPascal and contrast of the screen
The document you referenced seems to describe a different protocol than the examples provided. Whereas the documentation talks about data register D0 being used to designate storage locations that are set for function arguments and return values, the examples appear to expect a pointer to the parameter being passed in R1a. Is it possible the document provided is for a different version of HP Pascal? Or perhaps they are both right, but simply used in different contexts (possibly when only one argument/return value is needed?). In that case, it might make sense to mimic the methods used in the examples you provided (R1a holding a pointer to the passed argument/return value).

I believe it should be possible to do what you're wanting, probably with a fairly simple asm routine if the protocol can be verified.

Also, unless I'm misunderstanding something (highly possible!), it appears that the "Contraste" function writes the low-order 4 bits of the supplied byte to address location 101 and then simply clears the hi bit (for contrast anyway) at location 102. This would imply that the function only succeeds at writing (param MOD 16) to the contrast I/O location. Is this something that you have noticed, or am I simply misunderstanding what it's doing?
Find all posts by this user
Quote this message in a reply
10-27-2017, 01:33 PM
Post: #3
RE: (HP50g) HpPascal and contrast of the screen
pardon the someone what OT please.
Where is HPPascal? I tried a search on hpcalc.org but didn't find anything
Find all posts by this user
Quote this message in a reply
10-27-2017, 02:35 PM
Post: #4
RE: (HP50g) HpPascal and contrast of the screen
(10-27-2017 01:33 PM)EugeneNine Wrote:  pardon the someone what OT please.
Where is HPPascal? I tried a search on hpcalc.org but didn't find anything

I believe this is what Gilles is referring to: http://www.hpcalc.org/details/6035
Find all posts by this user
Quote this message in a reply
10-27-2017, 03:04 PM
Post: #5
RE: (HP50g) HpPascal and contrast of the screen
Another possible pointer: http://hppascal.free.fr/pages/home.htm

The idea is not bad!

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
10-27-2017, 05:02 PM (This post was last modified: 10-27-2017 05:09 PM by Gilles59.)
Post: #6
RE: (HP50g) HpPascal and contrast of the screen
For information, I installed HPPascal 2.1 on Win10 but I had to change some settings in the W10 register (sorry i forgot exactly what ...). The help file is an old format no more supported in W10 but I found an utility to change the help file in a PDF format, if there is some interest I can put this PDF file somewhere for download.

HPPascal is an old project with no support since a long time. I'm not sure that the version published on HPCalc have the right units file (.UNT) for the HP50g and 130x80 screen. HPPascal works like this : you create your program on a PC, compile it, you get a .COD file for your HP50. With the emulator just drag ans dop the .COD and EVAL. The syntax remind me Turbo Pascal with major limitation. But it's very fast with dedicated units for graphics and sprites.

HPPASCAL is describe as Open source but you cant download it freely on http://hppascal.free.fr/pages/home.htm Sad If there is some interest I can also upload somewhere the .UNT files that as use to target the code for 49g+/50g
Find all posts by this user
Quote this message in a reply
10-27-2017, 05:14 PM
Post: #7
RE: (HP50g) HpPascal and contrast of the screen
It seems that there is some interest, Gilles.

The sample that you provided in your first post translated reasonably well with google translate -- it clobbered the LA command as might be expected, but was quite clear for most things.

Would you be able to post another example of an asm function that returns a BYTE value instead of boolean? That would help clarify that the data format is as expected, and should be a reasonable template for setting up your GetContrast command.
Find all posts by this user
Quote this message in a reply
10-27-2017, 05:53 PM
Post: #8
RE: (HP50g) HpPascal and contrast of the screen
Based on the code samples, the following may do what you need. I would recommend trying this on an emulated system first, of course:

Code:
function GetContrast: byte;
begin
   asm
      LC(5) #101
      D1=C
      A=DAT1 B
      LC(2) #1F
      A=A&C B
      C=R1 A
      D1=C
      DAT1=A B
   end;
end;
Find all posts by this user
Quote this message in a reply
10-27-2017, 06:22 PM (This post was last modified: 10-27-2017 07:10 PM by EugeneNine.)
Post: #9
RE: (HP50g) HpPascal and contrast of the screen
I played with google translate a little, got to this page

https://translate.google.com/translate?h...e_get.php3

looks like all the sources are there.

A bunch of Microsoft Visual C++ 'extensions' rather than standard C++ though.
Find all posts by this user
Quote this message in a reply
10-27-2017, 07:29 PM (This post was last modified: 10-27-2017 07:35 PM by Gilles59.)
Post: #10
RE: (HP50g) HpPascal and contrast of the screen
I did not find an example of ASM with Byte.

But I changed this :

Code:
function readkey : char;
begin
 asm
     lc(2) 0
     :bclrdk
     gosbvl #4840        *POPKEY
     goc bclrdk
     a=r1
     d1=a
     dat1=c b
 end;
 result := chr( ScanToAscii[ ord(result) ] );
end;

with this :

Code:
function readkey2 : Byte;
begin
 asm
     lc(2) 0
     :bclrdk
     gosbvl #4840        *POPKEY
     goc bclrdk
     a=r1
     d1=a
     dat1=c b
 end;
end;

And this works fine with this program :

Code:
Program Texte;
Uses CrtHP_Test;
Var a : Byte;
Begin
 WriteLn('Keyboard test :DEL to exit');
 Repeat 
  a:=ReadKey2; WriteLn(a);
 Until a=21;
End.

TU David, I will try your suggestion.
Find all posts by this user
Quote this message in a reply
10-27-2017, 08:16 PM (This post was last modified: 10-27-2017 08:17 PM by Gilles59.)
Post: #11
RE: (HP50g) HpPascal and contrast of the screen
(10-27-2017 05:53 PM)DavidM Wrote:  Based on the code samples, the following may do what you need. I would recommend trying this on an emulated system first, of course:

Code:
function GetContrast: byte;
begin
   asm
      LC(5) #101
      D1=C
      A=DAT1 B
      LC(2) #1F
      A=A&C B
      C=R1 A
      D1=C
      DAT1=A B
   end;
end;

I get an error at compilation phase : Unknown instruction in " A=A&C B "
Find all posts by this user
Quote this message in a reply
10-27-2017, 11:41 PM
Post: #12
RE: (HP50g) HpPascal and contrast of the screen
(10-27-2017 08:16 PM)Gilles59 Wrote:  
(10-27-2017 05:53 PM)DavidM Wrote:  Based on the code samples, the following may do what you need. I would recommend trying this on an emulated system first, of course:

Code:
function GetContrast: byte;
begin
   asm
      LC(5) #101
      D1=C
      A=DAT1 B
      LC(2) #1F
      A=A&C B
      C=R1 A
      D1=C
      DAT1=A B
   end;
end;

I get an error at compilation phase : Unknown instruction in " A=A&C B "

Apparently HP-Pascal uses a different order for the registers in that command, as I now see in the definition of the Contraste function. Try replacing that command with "A=C&A B" instead. Some assemblers prefer that ordering over the first.
Find all posts by this user
Quote this message in a reply
10-28-2017, 11:53 AM (This post was last modified: 10-28-2017 11:53 AM by Gilles59.)
Post: #13
RE: (HP50g) HpPascal and contrast of the screen
(10-27-2017 11:41 PM)DavidM Wrote:  Apparently HP-Pascal uses a different order for the registers in that command, as I now see in the definition of the Contraste function. Try replacing that command with "A=C&A B" instead. Some assemblers prefer that ordering over the first.

That' perfect, it works. Thank you David !
Find all posts by this user
Quote this message in a reply
10-28-2017, 12:00 PM (This post was last modified: 10-28-2017 12:26 PM by DavidM.)
Post: #14
RE: (HP50g) HpPascal and contrast of the screen
(10-28-2017 11:53 AM)Gilles59 Wrote:  That' perfect, it works. Thank you David !

You're welcome Gilles! Using GetContrast, you should now be able to validate the Contraste procedure. Does it successfully set contrast values >15? If not, you may want to have your own version of that routine as well.
Find all posts by this user
Quote this message in a reply
10-28-2017, 01:32 PM
Post: #15
RE: (HP50g) HpPascal and contrast of the screen
(10-28-2017 12:00 PM)DavidM Wrote:  
(10-28-2017 11:53 AM)Gilles59 Wrote:  That' perfect, it works. Thank you David !

You're welcome Gilles! Using GetContrast, you should now be able to validate the Contraste procedure. Does it successfully set contrast values >15? If not, you may want to have your own version of that routine as well.

Hummmm, No... Value >15 give a very low contrast ... It looks to works fine only with values between 10-15. Perhaps a difference between the 49-50g and 48 ? Or a problem with the initial Contrast program wich don't works fine ?

Code:
Program Test;

Uses CrtHPmini_49,SysHP;
Var i,c,ci : Byte;
    k : Char;

Begin
 ci:=GetContrast; c:=ci;
 For i:=1 To 10 Do WriteLn('ABCDEFGHIKLMNO');
 Write('Contrast F1- F2+ F3 to exit');
 Repeat 
  k:=ReadKey;
  If k='A' And c>0  Then c:=c-1;
  If k='B' And c<20 Then c:=c+1;
  Contraste(c); GOTOXY(1,11); Write(c); Write('  ');
 Until k='C';
 Contraste    (ci);
End.
Find all posts by this user
Quote this message in a reply
10-28-2017, 02:34 PM (This post was last modified: 10-28-2017 11:39 PM by DavidM.)
Post: #16
RE: (HP50g) HpPascal and contrast of the screen
(10-28-2017 01:32 PM)Gilles59 Wrote:  Hummmm, No... Value >15 give a very low contrast ... It looks to works fine only with values between 10-15. Perhaps a difference between the 49-50g and 48 ? Or a problem with the initial Contrast program wich don't works fine ?

As I mentioned before, it appears that the Constraste routine ignores the hi-order bit of the byte you give it, thus only setting the contrast properly for values 0-15. You could easily test this in HP-Pascal by following

Contraste(17);

with:

x := GetContrast;

...and then outputting x in whatever way makes sense. My suspicion is that x will be 1 if you do (contrast MOD 16), which would clearly indicate the problem. To make it easier, you may want to include a Contraste(14) step after the GetContrast call so that you don't have to manually reset it after running the code.

The following may work better for setting the contrast:

Code:
procedure SetContrast(newValue: byte);
begin
   asm
      A=R1 A
      D1=A
      A=DAT1 B
      LC(2) #1F
      A=C&A B
      B=A B
      LC(5) #101
      D1=C
      A=DAT1 B
      LC(2) #E0
      A=C&A B
      A=A+B B
      DAT1=A B
   end;
end;

It masks out the high-order 3 bits of the byte you give it (effectively doing x MOD 32), then adds back in the display bits from i/o location 102 before setting the new contrast value. If I've coded it properly (I can't test it myself Smile), you should also be able to do the previous test successfully with SetContrast/GetContrast to verify it.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)