Assembler Optimizer

صفحة 50/57
43 | 44 | 45 | 46 | 47 | 48 | 49 | | 51 | 52 | 53 | 54 | 55

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

03-11-2021, 03:51

Hi @max_iwamoto! Just to be sure, are you using the "-dialect tniasm" flag when calling mdl? If with that it still does not work, would you mind posting here a small sample that fails, so I can look into it?

بواسطة max_iwamoto

Hero (597)

صورة max_iwamoto

03-11-2021, 14:18

Uninteresting wrote:

I know TNIASM's last free version and the paid version have big differences. Those keywords sound like they'd be used in the paid version?

(Basically, I'm not sure if the optimizer recognizes the freeware or the paid version, and I didn't feel like going through all the 49 pages to check if this has been mentioned there.)

Yes, I am using a paid version of TNIASM.

---

santiontanon wrote:

Hi @max_iwamoto! Just to be sure, are you using the "-dialect tniasm" flag when calling mdl? If with that it still does not work, would you mind posting here a small sample that fails, so I can look into it?

Here is the command line:

C:>java -jar mdl.jar test.asm -dialect tniasm

The errors start from %symfile / %expfile.

If I remove them I will get %res8 / %res16 errors.

If I remove those, I will get next error about
ROM_PAGE_00_LEN:: EQU $ - START

And if I remove this, the next error will be PHASE / DEPHASE

And here is the small piece of code:


	%symfile	"test.sym"
	%expfile	"test.exp"



;
; STANDARD MSX VARIABLES
;

KEY_CLICK:	EQU	F3DBh		; 00h - no click sound, 01h - click sound

EXPTBL:		EQU	FCC1h
SLTTBL:		EQU	FCC5h


;
; MSX HOOKS
;

H.KEYI:			EQU	FD9Ah
H.TIMI:			EQU	FD9Fh
H.STKE:			EQU	FEDAh


;
; MSX DISK VARIABLES
;

BDOS:		EQU	F37Dh

send_string:	EQU	09h
open_file:	EQU	0Fh
close_file:	EQU	10h
create_file:	EQU	16h
set_DMA:	EQU	1Ah
write_rnd_blk:	EQU	26h
read_rnd_blk:	EQU	27h


;
; STANDARD MSX BIOS SUBROUTINES
;

ENASLT:		EQU	0024h
DISSCR:		EQU	0041h
ENASCR:		EQU	0044h
WRTVDP:		EQU	0047h
FILVRM:		EQU	0056h		; HL = start, BC = length, A = fill byte
LDIRVM:		EQU	005Ch		; HL = start RAM , DE = start VRAM , BC = block length
CHSNS:		EQU	009Ch
CHGET:		EQU	009Fh
GTSTCK:		EQU	00D5h
GTTRIG:		EQU	00D8h
GTPAD:		EQU	00DBh		; mouse
RSLREG:		EQU	0138h		; read primary slot register
SNSMAT:		EQU	0141h
KILBUF:		EQU	0156h
BIGFIL:		EQU	016Bh		;


;
; MY GAME VARIABLES
;

_MUS_ROM_PAGE:		EQU	03h

_EOM:			EQU	FAh
_EOL:			EQU	FBh
_NEW_COORDINATES:	EQU	FCh


;
; MY GAME RAM VARIABLES
;

_100_LEVEL_MAP:			EQU	CD00h		; 00h - level incomplete , 01h - level complete	;
MEDUSA_TRANSPARENCY_TABLE:	EQU	CE00h
OBJECT_TRANSPARENCY_TABLE:	EQU	CF00h


ROOM_A_DATA:		EQU	CF00h	; store room background information (for room editor)
ROOM_B_DATA:		EQU	CF80h	; store room enemy / items information (for room editor)


MAX_ENEMY_PER_ROOM:	EQU	21	; maximum number of enemies per room
ENEMY_DATA_SIZE:	EQU	0Ah	; enemy data (attributes) size per enemy
ENEMY_DATA_SIZE_2:	EQU	06h	; enemy data size per enemy to copy to the 2nd screen of double buffer


;
; GAME VARIABLES
;

	PHASE	C000h


_SAVE_ROM_4000:		%res8	1		; save ROM PAGE number that right now at 4000h

_TEMP_VAR_A:		%res8	1		; temporary variable A
_TEMP_VAR_B:		%res8	1		; temporary variable B


_FD9F:			%res8	5		; backup of hook FD9Fh (H.TIMI)

RAM_VDP_SUBROUTINES:	EQU	$

			DEPHASE


;
; IN-GAME MUSIC VARIABLES
;

STOP_MUS:		EQU	4000h	; stop music playback
INIT_MUS:		EQU	4003h	; init music / sound effect -> A = ??h (0 - stop music playback)
PLAY_MUS:		EQU	4009h	; play music




;-------------------------------------------------------------------------------
;
; ROM PAGE 00
;
;-------------------------------------------------------------------------------

	ORG	0000h

START:
	PHASE	4000h

	DB	"AB"
	DW	ROM_START
	DS	0Ch,00h

ROM_START:

	DEPHASE

	PHASE	8000h + ROM_START - 4000h	; because ROM page 00h moves to 8000h

	DI
	CALL	RSLREG
	AND	%00001100
	RRCA
	RRCA
	LD	B,A
	LD	HL,EXPTBL
	ADD	A,L
	LD	L,A
	LD	C,(HL)
	INC	L
	INC	L
	INC	L
	INC	L
	LD	A,(HL)
	AND	%00001100
	OR	B
	OR	C

	LD	H,A
	LD	L,F7h		; RST 30h
	LD	(H.STKE),HL
	LD	HL,START_2 - 4000h
	LD	(H.STKE+2),HL
	LD	A,C9h
	LD	(H.STKE+4),A

	LD	A,01h
	LD	(7000h),A
	RET

START_2:
	DI
	LD	SP,E200h



	DEPHASE

ROM_PAGE_00_LEN::	EQU	$ - START

	DS	(4000h - ROM_PAGE_00_LEN),FFh	; fill the rest of the ROM with FFh

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

03-11-2021, 16:02

Thank you very much!! I'll take a look at this today after work, and get back to you!

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

04-11-2021, 05:33

Alright, I just looked at it, and indeed there is some syntax in that file that mdl did not support. I added support for everything I saw, and published a temporary release here: https://github.com/santiontanon/mdlz80optimizer/releases/tag...

Could you give that a try and see if that works?

Also, I noticed that your file has some syntax that I could not find in the tniasm documentation. For example, "%res8". I assumed it is equivalent to "rb" (which is the command specified in the tniasm documentation I have). I also noticed a line with two colons after a label: "ROM_PAGE_00_LEN::" Does this have any special meaning in tniasm? I also could not find that in the documentation. For now, I just made "::" a synonym of ":" for the tniasm dialect, but I am not sure if it has some other meaning. Maybe these are features of tniasm 1.0? (since the documentation is not available online, I am not sure; I could only find documentation for tniasm 0.45).

Thanks a lot for sharing that file, and let me know if it works now. It works for that example on my computer now. But if there is any other syntax that does not work, do let me know, and I'd be happy to look into it! :)

بواسطة max_iwamoto

Hero (597)

صورة max_iwamoto

04-11-2021, 16:25

santiontanon wrote:

Alright, I just looked at it, and indeed there is some syntax in that file that mdl did not support. I added support for everything I saw, and published a temporary release here: https://github.com/santiontanon/mdlz80optimizer/releases/tag...

Could you give that a try and see if that works?

Also, I noticed that your file has some syntax that I could not find in the tniasm documentation. For example, "%res8". I assumed it is equivalent to "rb" (which is the command specified in the tniasm documentation I have). I also noticed a line with two colons after a label: "ROM_PAGE_00_LEN::" Does this have any special meaning in tniasm? I also could not find that in the documentation. For now, I just made "::" a synonym of ":" for the tniasm dialect, but I am not sure if it has some other meaning. Maybe these are features of tniasm 1.0? (since the documentation is not available online, I am not sure; I could only find documentation for tniasm 0.45).

Thanks a lot for sharing that file, and let me know if it works now. It works for that example on my computer now. But if there is any other syntax that does not work, do let me know, and I'd be happy to look into it! :)

Yes, the new version is working. Thank you very much for updating it. I found some interesting optimizations.

%res8 is working now but %res16 is still missing. But it is not a big deal, I replaced all in my source with RB AND RW. Those are just macros for %res8 and %res16. The "::" is used to export labels into an external file.

Now I would like to provide details about optimization methods:

"-po" works the best and provides many options and no errors.

"-so" works but gives a lot of warnings, such as " Could not evaluate c000h to an integer constant" or "Could not evaluate f8h to an integer constant", etc...

Now, I was really excited to use "-ro", I assume it was designed to find similar parts of code to save even more space. But as soon as I run it, it gives me an error about " INCLUDE "FILE.ASM" ". That's not a big deal, I removed INCLUDE temporarily.
Then it gives me the following error: "Some local labels are out of range, to begin with, cancelling execution". Erro about command "JR .WaitTR" or similar. The local label is not out of range. If I change it to JP, it works, but right away gives me an error on the next local JR...

Is there some setting to ignore it or another way to execute "-ro" ?

Thank you.

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

04-11-2021, 16:40

Thanks for testing!! I'll add support for "%res16" (it's just a 1 line change Smile ). As for those "Could not evaluate c000h to an integer constant", it's definitively a bug in MDL. I think the problems with "-ro" are also derived from this but. It should be easy to fix! I'll take a look tonight after work! Smile

As for the "include "file.asm"" error, could you show me which error do you get?

Thanks a lot for testing, all this is great to make MDL more compatible with tniasm Smile

بواسطة max_iwamoto

Hero (597)

صورة max_iwamoto

04-11-2021, 16:59

santiontanon wrote:

Thanks for testing!! I'll add support for "%res16" (it's just a 1 line change Smile ). As for those "Could not evaluate c000h to an integer constant", it's definitively a bug in MDL. I think the problems with "-ro" are also derived from this but. It should be easy to fix! I'll take a look tonight after work! Smile

As for the "include "file.asm"" error, could you show me which error do you get?

Thanks a lot for testing, all this is great to make MDL more compatible with tniasm Smile

I tried to include an exact path to the file in INCLUDE and still got the same error - "Problem including file in test3.asm#8121 ..."
The next line is saying "Error parsing source file test3.asm and exit with error code 2.

If I remove "INCLUDE", I will get the local JR error and it will exit with error code 3.

---

INCLUDE issues also present in "-po". It only works if INCLUDE removed.

بواسطة max_iwamoto

Hero (597)

صورة max_iwamoto

04-11-2021, 17:15

MDL gave me optimization suggstion and while applying it, I came up with another one Smile

Here is the code sample:

	LD	HL,ROOM_A_DATA
	LD	DE,ROOM_A_DATA + 1
	LD	BC,0080h
	LD	(HL),B			; empty space in ROOM DATA
	LDIR
	LD	(HL),FFh		; no enemy / item in ROOM DATA
	LD	BC,007Fh
	LDIR

MDL suggested changing LD (HL),00h to LD (HL),B... And I did it. Now if you look before the next LDIR there is LD BC,007Fh but it could be changed to LD C,7Fh because B is already 00h after the previous LDIR execution.

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

04-11-2021, 17:59

oh! That's a very interesting one! That's right, I had not thought that it is safe to assume that "bc = 0" after ldir! Making a note of that to add a new pattern, thanks!! Big smile

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

05-11-2021, 03:01

I just uploaded a new version (same link as before: https://github.com/santiontanon/mdlz80optimizer/releases/tag... ). The issue with the labels like "c000h" should be fixed. But I would advise against using this type of constants though. For example you have a line that looks like this:

_EOM:			EQU	FAh

Notice that "fah" could perfectly be a variable name. So, MDL was interpreting it as such. Same with "c000h", etc. I have added an exception for the "tniasm" dialect to parse these as hex constants (now, using tniasm dialect, if after parsing the input assembler files there are symbols that could be interpreted as hex constants and that have not been defined, they will be converted to hex constants). But most assemblers will give you errors with those. The usual recommendation is to insert a leading 0, like this, to prevent ambiguities:

_EOM:			EQU	0FAh

In any case, that should work now. Oh, and I also added a new optimization pattern based on your idea haha (I credited you in the source code for the idea for that pattern, but let me know if you want your name removed) :)

Also, I wonder if the "include" error was also due to the labels issue. Not sure! In any case, I hope this version works better! :)

صفحة 50/57
43 | 44 | 45 | 46 | 47 | 48 | 49 | | 51 | 52 | 53 | 54 | 55