Experience with lhTools for PC-1500

Talk in English

Modérateur : Politburo

kuzja
Fonctionne à 75 bauds
Fonctionne à 75 bauds
Messages : 17
Enregistré le : 01 avr. 2021 14:26

Experience with lhTools for PC-1500

Message par kuzja »

This thread is aimed at the experience with lhTools, and especially the LH5801 cross-assembler lhasm. The software is available at http://www.pc1500.com/.
It could happen I missed some of the information that was already posted in the French forums; if it is the case, please post a link to it here.

I am running lhTools under Linux Manjaro and they are running fine without any problems. Nevertheless there are some small issues that can cause a slight inconvenience, though they are not really limiting and once you get used to them, you perhaps don't even realize their existence. So they are most visible to a new user like me. :)

The list is not long, and there might be a misunderstanding from my side, so please correct me where I am wrong.

Part I. - lhasm
Tested version: 0.7.6p1

1. To tell the compiler whether a number is decimal, octal, or hexadecimal, prefixes like &, #, \X, \o etc. are used. However, if you use no prefix, hexadecimal is presumed. This can lead to ambiguities, as a number can have the same format as a symbol (e.g. label). So in the instruction

Code : Tout sélectionner

	CALL BC10
"BC10" can be understood either as an address, or as a label (which could mean e.g. "multiply BC by 10"). The compiler seems to interpret it as a label, if such label exists, but a human reader might be confused.

2. The prefixes cannot be used with the .ORIGIN: directive. It requires hexadecimal number with no prefix.

3. .EQU directive accepts most of (perhaps all?) specifiers and operators listed in chapters 2.2 and 2.3 of the manual. But an error is raised if the expression contains a symbol. So you can write

Code : Tout sélectionner

SEPAR	.EQU	$:
OFFSET	.EQU	[+10]&4455
etc., but not

Code : Tout sélectionner

VAR2	.EQU	VAR1
ADR2	.EQU	[+0100]BASE
However, the symbols can be used for immediate values like in

Code : Tout sélectionner

	LDA (VAR1)
	LD H,[+10]<VAR1
and the compiler correctly understands even an expression like

Code : Tout sélectionner

	LDA (2+ADR)    ; (but not ADR+2)
4. The compiler requires a label to be on a separate line. This is no serious limitation, but if there is an instruction after the label, the compiler silently ignores it, without any warning!

5. Except for the ML instructions, the compiler has a number of predefined symbols and mnemonics for the use with PC-1500. In chapter 2.1 of the manual, mnemonics for selected SBR() calls are listed. But besides this, there are apparently other named addresses for some useful ROM routines and system variables, but these are not documented.

6. The compiler understands the instruction CLA, which is compiled as &34. But such ML code is not listed in the LH5801 Assembly Language documentation. What does it do...?

7. The indirect instructions AND (R), AND (mn), OR (R), OR (mn) (and perhaps some other?) should not be followed by a comment, otherwise a warning is raised
--WARNING-- Argument 4; Trailing garbage not processed!
followed by a fatal error "Assembler confused" etc. If there is no comment, these instructions compile correctly.

The list will be extended if I come across other irregularities.
For the time being I have no (or very small) experience with the other tools (lhdump, lhcom, lhpoke).
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

I also add another mistake - and this is very important as lhasm and lhdump won't assemble and disassemble the code correctly:

In all versions up to 0.7.6.p1 included, the mnemonics RPV and SPV are switched. RPV must be &B8 and SPV must be &A8. BTW, the Assembler has also the same error; MacBas2014 proceeses SPV and RPV correctly. This error comes from the XMON manual, where SPV and RPV are also switched, but XMON itself assembles SPV and RPV with correct code. A version of the lhTools increase to 0.7.7 is now published.

This was report by another user, and I already seen this while building the "proto" images of the TE-1507 with the new and WIP 0.8.0. But I forgot to backport it the 0.7.x....
Modifié en dernier par cgh le 10 avr. 2021 23:28, modifié 6 fois.
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

Thanks a lot ! This is very nice and precise list of remarks or bugs :geek:

I will take time to try to correct some. Others (like "CALL BC10") are inherited from the old - old - old (too old) versions and so, are kept for backward compatibility; perhaps and certainly not a very good choice...

I am currently completing the lhTools-0.8.0. I will have a look to how the correct some of them.

About the undocumented mnemonics, like CLA, these use the register MN. I will add a specific part for this register.

For the entry points and the macros SBR, in fact, I take the fact that people using the lhTools, already have some knowledge about ML and PC1500 internals. But, adding appendices describing some of them is, I think, a very good option. I will so update the documentation.

Thanks you for using the lhTools :)
Modifié en dernier par cgh le 10 avr. 2021 23:28, modifié 4 fois.
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

The CLA mnemonic is a macro to LDA N. The undocummented register MN has a specific behaviour that is used for optimizing code in some ways. (This was published in a french magasine, certainly a SHARPENTIER...). The code of these instructions are the columns &3x and &7x. CLA = &34.

- The register M seems to always take the last upper byte processed when a 16-bits operation is performed.
- The register N is always &00. So CLA := LDA N := A=0. But requires 1 byte, instead of LDA 00 which takes 2.

The MN register can not be stored, so POP MN just "pop" the last 16-bytes word from the stack.

The lhTools and PockEmul deal correctly with the register MN, as I use some optimizations like CLA, CPA N, ... inside my own softwares.
Modifié en dernier par cgh le 10 avr. 2021 23:30, modifié 2 fois.
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

kuzja a écrit : 09 avr. 2021 22:35 7. The indirect instructions AND (R), AND (mn), OR (R), OR (mn) (and perhaps some other?) should not be followed by a comment, otherwise a warning is raised
--WARNING-- Argument 4; Trailing garbage not processed!
followed by a fatal error "Assembler confused" etc. If there is no comment, these instructions compile correctly.
This is a very insteresting bug ! 8O 8O 8O 8O :oops:
In fact, AND (R) ; was taken as AND (R),n like the , is not mandatory (due to backward compatibility...). Like the pass 1 of the assembler has tolerance about bad values or symbols not defined, the assembler believes that ; is a symbol and so prepare the code 49 n which is AND (BC),n.
But the pass 2, which expects NO tolerance about bad or undefined values, set the code to AND (BC) that is 09.
Finally, the assembler checks for pointers when assembling the code, it detects that a mnemonic request for 2 bytes (pass 1) and the same mnemonic for 1 byte (pass 2), and so, like this differs, it raises the fatal error about pointer confusion:

Code : Tout sélectionner

a.a line 13: !!!FATAL!!! Assembler confused. END from a.a differs between passes
This is corected by rejecting string starting with ; that marks a comment :geek:
The patch below:

Code : Tout sélectionner

--- lhTools-0.7.6p1/lhasm.c	2019-03-24 21:22:39.000000000 +0100
+++ lhTools-0.7.8/lhasm.c	2021-04-10 10:13:59.964344066 +0200
@@ -1399,6 +1399,9 @@
   LHU16 max = 0xFFFF, vs, vv, rel = 0xFFFF, opval = 0, is = 0;
   char symna[80];
 
+  if( !str || (str && *str == ';') )
+    return 0;
+
   if( asmrunmacro && (str && 0 == strncmp( str, "__#", 3 )) )
     {
     if( 1 == sscanf( str + 3, "%hu", &vs ) )
Thanks a lot for reporting this :) !
Modifié en dernier par cgh le 10 avr. 2021 23:30, modifié 1 fois.
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

kuzja a écrit : 09 avr. 2021 22:35 4. The compiler requires a label to be on a separate line. This is no serious limitation, but if there is an instruction after the label, the compiler silently ignores it, without any warning!
This is a regression due to introduction of the .ARRAY directive, that remove the error if the define is followed by something else than a comment.
The fact that a symbol definition cannot be followied by an instruction is to prevent against recursion when defining a symbol inside a macro. This is a limitation and should be documented.

Waiting for a delivery, here is the patch:

Code : Tout sélectionner

--- lhTools-0.7.7/lhasm.c	2019-03-24 21:22:39.000000000 +0100
+++ lhTools-0.7.8/lhasm.c	2021-04-10 11:36:13.657475367 +0200
@@ -5244,6 +5247,8 @@
           LHASM_ERR( "Unknown array base address %s\n", arg[4+export] );
           v = ((t < b) ? (b - t) : (t - b)) / sz;
         }
+      else if( arg[1+export] && *arg[1+export] != ';' )
+        LHASM_ERR( "Unexpected arguments \"%s\"\n", arg[1+export]);
       else
         v = lhAsmGetPC();
       if( asmpass == 1 )
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

kuzja a écrit : 09 avr. 2021 22:35 3. .EQU directive accepts most of (perhaps all?) specifiers and operators listed in chapters 2.2 and 2.3 of the manual. But an error is raised if the expression contains a symbol. So you can write

Code : Tout sélectionner

SEPAR	.EQU	$:
OFFSET	.EQU	[+10]&4455
etc., but not

Code : Tout sélectionner

VAR2	.EQU	VAR1
ADR2	.EQU	[+0100]BASE
However, the symbols can be used for immediate values like in

Code : Tout sélectionner

	LDA (VAR1)
	LD H,[+10]<VAR1
and the compiler correctly understands even an expression like

Code : Tout sélectionner

	LDA (2+ADR)    ; (but not ADR+2)
This depends of your context. A symbol must be defined witth a non ambigous immediate value during the pass 1, and must not differ between the two passes. So
The following works:

Code : Tout sélectionner

	.ORIGIN: 40C5
	.CODE
VAR1	.EQU &1234
VAR2	.EQU VAR1
	CALL VAR2
	RET
	.END
But the following won't because the symbol VAR2 can not be defined due to the inexistece of VAR1 at this time.

Code : Tout sélectionner

	.ORIGIN: 40C5
	.CODE
VAR2	.EQU VAR1
VAR1	.EQU &1234
	CALL VAR2
	RET
	.END
Do you have anorher case when it happens ? If yes, could you share it ?

But it looks like defining a symbol with an expression containing a symbol is not working correctly and the value is wrong... I need to have a look deeply inside the evaluator :( :cry:
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

The lhTools 0.7.7 are now available on the site of repaire.
This version corrects the switch of the ML code between SPV and RPV.
A new version 0.7.8 is expected soon when all issues reported by kuzja will be corrected and the lhTools will succesfsully complete their tests suite :geek:

Thank you for using the lhTools !

May the PC1500 be with you ;)
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

kuzja a écrit : 09 avr. 2021 22:35 3. .EQU directive accepts most of (perhaps all?) specifiers and operators listed in chapters 2.2 and 2.3 of the manual. But an error is raised if the expression contains a symbol. So you can write

Code : Tout sélectionner

SEPAR	.EQU	$:
OFFSET	.EQU	[+10]&4455
etc., but not

Code : Tout sélectionner

VAR2	.EQU	VAR1
ADR2	.EQU	[+0100]BASE
However, the symbols can be used for immediate values like in
Here, you must use a variable to have the code assembled. The code below does not assemble:

Code : Tout sélectionner

	.ORIGIN: 40C5
	.CODE
VAR1	.EQU &1234
VAR2	.EQU VAR1
VAR4	.EQU [+10]VAR1
	CALL VAR2
	CALL VAR4
	LD PC,[+06]VAR2
	LDA ([+06]VAR4)
	RET
	.END
But the following is accepted correctly:

Code : Tout sélectionner

	.ORIGIN: 40C5
	.CODE
VAR1	.EQU &1234
VAR2	.EQU VAR1
%04v	.EQU VAR1
VAR4	.EQU [+10]%04v
	CALL VAR2
	CALL VAR4
	LD PC,[+06]VAR2
	LDA ([+06]VAR4)
	RET
	.END
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

Yes ! It is corrected. This was difficult, but it works !

Code : Tout sélectionner

cgh@varvotier:~/work/pc1500/REBUID_JUN2018/lhTools-0.7.8$ cat vnok.s
	.ORIGIN: 40C5
	.CODE
VAR1	.EQU &1234
VAR2	.EQU VAR1
VAR4	.EQU [+10]VAR1
	CALL VAR2
	CALL VAR4
	LD PC,[+06]VAR2
	LDA ([+06]VAR4)
	RET
	.END
cgh@varvotier:~/work/pc1500/REBUID_JUN2018/lhTools-0.7.8$ ./lhasm -T vnok2.s
    . . .
;	lhTools Version 0.7.8 #0
;
;	Source file: vnok2.s
;	lhasm options:
;		-T \
;		vnok2.s

    1
		.ORIGIN:	40C5
    2		.CODE	40C5
    3	40C5	VAR1:	.EQU 1234
    4	40C5	VAR2:	.EQU 1234
    5	40C5	VAR4:	.EQU 1244
    6	40C5	BE 12 34       	CALL	VAR2 
    7	40C8	BE 12 44       	CALL	VAR4 
    8	40CB	BA 12 3A       	LD	PC [+06]VAR2 
    9	40CE	A5 12 4A       	LDA	([+06]VAR4) 
   10	40D1	9A             	RET	
   11	40D2	.END
		;; 40C5	vnok2.s$$._start
		;; 40D2	vnok2.s$$._end
		;; 000D	vnok2.s$$._length

		.SYMBOLS:
	1234	VAR1
	1234	VAR2
	1244	VAR4



Written 13 bytes (40C5:40D2) to vnok2.bin Checksum 0972
The lhTools-0.7.8 are almost ready. I need now to pass all the tests suites. And the documentation to update with issues reported :geek:
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
kuzja
Fonctionne à 75 bauds
Fonctionne à 75 bauds
Messages : 17
Enregistré le : 01 avr. 2021 14:26

Re: Experience with lhTools for PC-1500

Message par kuzja »

Thanks for a prompt response and explanation. :)
What I didn't stress enough in my first post is that out of my 7 comments, just one can be considered a bug (and only a minor one). That proves how wonderful piece of software the lhTools are. Many thanks to the author! :)
Others (like "CALL BC10") are inherited from the old - old - old (too old) versions and so, are kept for backward compatibility; perhaps and certainly not a very good choice...
I fully understand that breaking the compatibility is undesirable and would do more harm than good. Perhaps a compromise might be that the compiler issues a non-critical warning if a label could be misinterpreted as a hex number...? But it's just an idea.
About the undocumented mnemonics, like CLA, these use the register MN. I will add a specific part for this register.
Well, I can see there are even more secrets about the LH8150 ML than I expected. :) :)
For the entry points and the macros SBR, in fact, I take the fact that people using the lhTools, already have some knowledge about ML and PC1500 internals. But, adding appendices describing some of them is, I think, a very good option. I will so update the documentation.
I think there are two separate things: First, what mnemonics is understood by the lhasm, and second, what the subroutines actually do.
The former is covered for the selected SBR() calls by the manual, but other names (like GETKEY or HEXDEC) are not listed.
The latter would be a nice bonus, but I agree it is rather out of scope of the lhTools manual.
kuzja
Fonctionne à 75 bauds
Fonctionne à 75 bauds
Messages : 17
Enregistré le : 01 avr. 2021 14:26

Re: Experience with lhTools for PC-1500

Message par kuzja »

Concerning the .EQU topic:
This depends of your context. A symbol must be defined witth a non ambigous immediate value during the pass 1, and must not differ between the two passes. So
The following works:

Code : Tout sélectionner

	.ORIGIN: 40C5
	.CODE
VAR1	.EQU &1234
VAR2	.EQU VAR1
	CALL VAR2
	RET
	.END
You are right, it was my mistake during the tests.
But it looks like defining a symbol with an expression containing a symbol is not working correctly and the value is wrong...
That's what probably caused confusion during my tests. I tried

Code : Tout sélectionner

VAR1	.EQU	&4455
VAR2	.EQU	VAR1
VAR3	.EQU	[+100]VAR1
and because the third line caused an error "Badly formed parameter", I didn't notice the line 2 compiled correctly in this case.
Here, you must use a variable to have the code assembled.
It is an interesting idea. I am afraid I've underestimated the difference between a symbol and a variable. :) I'll have a closer look at that.
cgh a écrit : 10 avr. 2021 20:15 Yes ! It is corrected. This was difficult, but it works !
Thumbs up!!! :) :) Thanks for all patches and corrections! :)
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

The lhTools 0.7.8 are now available on the site of repaire.
This version corrects all issues reported by kuzja except these about the documentation (The macros and supported ROM entry points). A dedicated manual will be published later.

Thank you for using the lhTools !

May the PC1500 be with you :)
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
kuzja
Fonctionne à 75 bauds
Fonctionne à 75 bauds
Messages : 17
Enregistré le : 01 avr. 2021 14:26

Re: Experience with lhTools for PC-1500

Message par kuzja »

Thanks a lot! I've downloaded the new version and will give it a try. :)
cgh
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 2142
Enregistré le : 30 août 2011 12:23
Localisation : Vous êtes ici -> .

Re: Experience with lhTools for PC-1500

Message par cgh »

kuzja a écrit : 13 avr. 2021 10:27 Thanks a lot! I've downloaded the new version and will give it a try. :)
Wonderful :) Please, send all issues or remarks you will find. It is nice to have feedback from user.
Il y a ceux qui voient les choses telles qu'elles sont et se demandent pourquoi, et il y a ceux qui imaginent les choses telles qu'elles pourraient être et se disent... pourquoi pas? - George Bernard Shaw
J'adore parler de rien, c'est le seul domaine où j'ai de vagues connaissances ! - Oscar Wilde
Ce n'est pas parce que les choses sont difficiles que nous n'osons pas. C'est parce que nous n'osons pas que les choses sont difficiles. - Sénèque
Répondre

Retourner vers « Silicium in English »