FASM-ZX Problem

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
User avatar
blittled
Posts: 229
Joined: Fri Dec 19, 2008 3:04 am
Location: Northwestern Pennsylvania, USA

FASM-ZX Problem

Post by blittled »

I'm using

Code: Select all

format zx81
;labelusenumeric
;LISTOFF

    // hardware options to be set and change defaults in ZX81DEF.INC
     MEMAVL     =       MEM_16K                // can be MEM_1K, MEM_2K, MEM_4K, MEM_8K, MEM_16K, MEM_32K, MEM_48K
                                               // default value is MEM_16K
     STARTMODE  EQU     SLOW_MODE              // SLOW_MODE or FAST_MODE
     DFILETYPE  EQU     AUTO                   // COLLAPSED or EXPANDED or AUTO
     STARTUPMSG EQU    'CREATED WITH ZX81-IDE' // any message will be shown on screen after loading, max. 32 chars

     include 'SINCL-ZX\ZX81.INC'               // definitions of constants
;LISTON           
Further down the code I use

Code: Select all

LD A,(FRAMES)

and I get Error: Operand sizes do not match.

If I go into ZX81VARS.INC and change FRAMES to FRAMES: then it works. Is there a way this can be done without changing the ZX81VAR file?
2X Timex Sinclair 1000, ZX81, ZX80Core, 5X 16K Ram Pack, ZXBlast, ZX P file to Ear Input Signal Converter, Elf II
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: FASM-ZX Problem

Post by PokeMon »

Hmm I have to check.
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: FASM-ZX Problem

Post by PokeMon »

You can use the attached version - just copy the FASMW-ZX.EXE into your ZX-IDE directory and overwrite the old one.
This is just a small bug correction and not worth to build up an official release.
It is marked as "1.71.01s.Z80 11/2016" and has one more bug corrected when accidently using AF register to save to or load from memory with LD instruction (not PUSH/POP).

The following instructions where not marked as invalid from the parser in earlier releases and gave strange results:

LD AF,(xxxx)
LD (xxxx),AF
Attachments
FASMW-ZX.zip
(60.73 KiB) Downloaded 158 times
User avatar
blittled
Posts: 229
Joined: Fri Dec 19, 2008 3:04 am
Location: Northwestern Pennsylvania, USA

Re: FASM-ZX Problem

Post by blittled »

Thanks Pokemon!

What I'm doing is porting fruitcake's disassembly of MAZOGS into FASM-ZX. Since you did a great job in mixing BASIC and Assembly I thought this would help with dealing with all the PEEKS, POKES and RAND USR lines if I make modification to the assembly code. It has definitely tested FASM-ZX.

Here are some things I found:
I redid the ZX81VARS.INC with colons at the labels as listed below to handle any reference to the system variables.

Code: Select all

;
; ZX81VARS.INC
; include file with variables used by Sinclair ZX81
; for FASMZ80 (flatassembler with Z80 instruction set)
;
; V1.2
;

virtual at MEMST

ERR_NR:  db	 ?	 ; error number $ff is no error
FLAGS:	 db	 ?	 ; flags of system
ERR_SP:  dw	 ?	 ; first item of machine stack
RAMTOP:  dw	 ?	 ; top address of ram, first non-existing memory location
MODE:	 db	 ?	 ; cursor mode (K/L,F,G)
PPC:	 dw	 ?	 ; line number currently executed

SAVE_BEGIN:		 ; start address of prgrams loaded into memory

end virtual

	ORG	SAVE_BEGIN

	VERSN:	 db 0		 ; version, 0=ZX81 BASIC
	E_PPC:	 dw 0		 ; number of current line with cursor (in listing)
	D_FILE:  dw DFILE_ADDR	 ; begin of D_FILE (display file) in memory
	DF_CC:	 dw DFILE_ADDR+1 ; current cursor position in D_FILE (used for print routine)
	VARS:	 dw VARS_ADDR	 ; begin of variable section in memory
	DEST:	 dw 0		 ; address of variable in assignment
	E_LINE:  dw WORKSPACE	 ; address of workspace
if defined AUTORUN
	CH_ADD:  dw AUTORUN	 ; address of next character to be interpreted
else
	CH_ADD:  dw 0		 ; address of next character to be interpreted
end if
	X_PTR:	 dw 0		 ; address of character preceeding "S" marker
	STKBOT:  dw WORKSPACE	 ; stack botton (top-down)
	STKEND:  dw WORKSPACE	 ; end of stack (top)
	BERG:	 db 0		 ; calculators b register, possibly write error, should be BREG :-)
	MEM:	 dw MEMBOT	 ; address for calculator's memory
	UNUSED1: db 0		 ; unused variable / space
	DF_SZ:	 db 2		 ; no. of lines in lower part of screen including 1 blank line
	S_TOP:	 dw 0		 ; no. of top program line in automatic listings
	LAST_K:  dw 0		 ; last key pressed
	DEBOUNCE: db 0		 ; debounce status of keyboard
	MARGIN:  db PAL 	 ; margin value, could be used PAL or NTSC
if defined AUTORUN
	NXTLIN:  dw AUTORUN	 ; next line to be executed
else
	NXTLIN:  dw 0		 ; next line to be executed
end if
	OLDPPC:  dw 0		 ; line to jump when executing CONT (continue)
	FLAGX:	 db 0		 ; internal flags
	STRLEN:  dw 0		 ; length of string, interally used
	T_ADDR:  dw 0		 ; next item in syntax (token) table
	SEED:	 dw 0		 ; seed variable set by RAND
	FRAMES:  dw 0		 ; counter of frames sent to TV, used by PAUSE command
	COORDS:  db 0		 ; x coordinate of last point plotted
		 db 0		 ; y coordinate of last point plotted
	PR_CC:	 db $BC 	 ; LPRINT position used with real printer
	S_POSN:  db 33		 ; column no. for print position
		 db 24		 ; line no. for print position
match =FAST_MODE,STARTMODE {
	CDFLAG:  db FAST_MODE
}
match =SLOW_MODE,STARTMODE {
	CDFLAG:  db SLOW_MODE
}
match =STARTMODE,STARTMODE {
	CDFLAG:  db SLOW_MODE
}
	assert	 CDFLAG > -1
	PRBUFF:  db 32 dup(0)	 ; printer buffer, initialized with 0
		 db NEWLINE	 ; printer buffer ends with a newline character
	MEMBOT:  db 30 dup(0)	 ; calculator additional memory 	   ???
	UNUSED2: dw 0		 ; unused variable / space

BASIC_AREA:
I found that version 1.701.s produces an error when LD E,(HL) or LD D,(HL) is processed version 1.701.q does not have that error.

The most interesting bug I found is when L408C or L4B0C is in a line I get an Invalid Operand error. I changed the label L408C: to PLOC: and still got the error but when I changed L408C: to L408X: and L4B0C: to L4B0X: it compiled fine. It look like any label ending in the letter C cannot be identified.

Once I made those corrections I could compile MAZOGS with 1.701.q and run it without an issue.

One interesting thing I found that fruitcake caught, by using a macro, is that the code uses the 4 byte ED prefixed version of LD HL,(ADDR) rather than the 3 byte version. When I originally compiled it I used the 3 byte version and MAZOGS hung at making the maze. Until I figure out how to do macros I just used the 3 byte version with a NOP after to keep all code lining up with the Basic references. This was probably Don Priestley's way of securing the code from reverse engineering since re-assembling a disassembly of the code would replace the 4 bytes with 3 bytes causing the program to fail.

I hope what I found helps out in future versions of FASM-ZX.
2X Timex Sinclair 1000, ZX81, ZX80Core, 5X 16K Ram Pack, ZXBlast, ZX P file to Ear Input Signal Converter, Elf II
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: FASM-ZX Problem

Post by PokeMon »

So - here you have a changed FASMW-ZX.EXE to try out.
If no further bugs found I will publish it as a new release.
I tested it thoroughly now with my test programs to assure that the output with existing programs is the same as before.
Sorry for this quick shot yesterday.

So the new version should compile fine.
The bug with the label is removed - this is a bit more complex story as it could appear in general whenever the combination "C)" is used regardless if there is a label in brackets or a complex arithmetic expression. This was an old dirty hack to recognize the OUT (C),A instruction while register C is invalid in this context. So removed now.

Finally I added a new pseudo register HX which can be used instead of HL to force the correct long version of LD HL,(xxxx) or LD (xxxx),HL with 4 bytes all in all. Just use LD HX,(xxxx) or LD (xxxx),HX. So this way "HL,(" can be simply replaced with "HX,(" resp. "),HL" with "),HX". This way you can replace only indirect addressing simple. Don't know if there are strange effects possible when HX is used with other mnemonics - I simply added this handling for the LD instruction.

So please try it out and let me know. Didn't gave a new release number string as this is just one day and one user. ;)
Attachments
FASMW-ZX.zip
(60.77 KiB) Downloaded 160 times
Post Reply