ZX-IDE Tutorial for programming assembler and ZX BASIC

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
ilyad731214
Posts: 15
Joined: Thu Jul 27, 2017 9:43 am

Re: ZX-IDE Tutorial for programming assembler and ZX BASIC

Post by ilyad731214 »

sirmorris wrote: Fri Aug 04, 2017 12:15 pm I think this is expected.
I did as instructed. Why is this and how to deal with it? I have tried on win.10 and XP win... :|
ZX-81, ZX-Pand AY, 48k "Rubber", 48K+, 128K + "Toastrack", +2 "grey" 1024k Profi, Masakrator FM, DivIDE 2K11, ZX Evolution rev. C, ZX-Uno, C64, C16 64K, Plus4 + 1541 Ultimate II + SD2IEC
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: ZX-IDE Tutorial for programming assembler and ZX BASIC

Post by PokeMon »

Disassembling was an experimental feature only, quite buggy and not finished yet.
Either not planned to finish by now.
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: ZX-IDE Tutorial for programming assembler and ZX BASIC

Post by PokeMon »

Today a new release (bugfix release) was uploaded in the first post of this thread.

Following bugfixes / changes made:

1. direct access to 8 bit labels, defined in SINCL-ZX directory (includes, ZX81VAR.INC and ZX80VAR.INC)
Direct access like LD A,(ERR_NR) reported an error. This was due to a data definition of a label (pointing to type db, data byte). As in C there is an explicit casting necessary to avoid errors or warnings. So the instruction LD A,(nnnn) required a 16 bit value (label) while in the definition the label was defined to access an 8 bit value. This is solved now.

On the other hand it is no possible to use LD HL,(ERR_NR) to get access to an 8 bit label which still throws an error. There is a workaround for using a label without specified data size (like a void pointer in C) which can be defined with

Code: Select all

label SOMETHING at ERR_NR
LD HL,(SOMETHING)
2. LOAD basic instruction now supports variables, too like LOAD A$. The reason was that load is an internal directive to manipulate data in combination with STORE (examples follows later). So I decided to rename the FASM officials load directive to shorter lod and there is no more conflicts in syntax checking for lod parameters accepted.

3. Batch file execution is now prevented if an error occurs during compilation, batch file will be executed after a successful compilation only.
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX-IDE Tutorial for programming assembler and ZX BASIC

Post by Andy Rea »

Thanks Karl, for you continued effort it is much appreciated.

regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: ZX-IDE Tutorial for programming assembler and ZX BASIC

Post by PokeMon »

I just removed a small bug - only one time downloaded now.
So whoever downloaded it should download it again.
I don't want to change the release string for that. ;)
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Useful macros for PUSH and POP

Post by PokeMon »

Some useful macros for multiple PUSH/POP action to minimize written code:

Code: Select all

macro push [char] {
      if char in <all>
       PUSH AF BC DE HL IX IY
       EXX
       PUSH BC DE HL
       EXX
      else if char in <exx>
       EXX
       PUSH BC DE HL
       EXX
      else if char eqtype 0
       PUSH HL
       LD HL,char
       EX (SP),HL
      else
       PUSH char
      end if
}
This is a multipurpose macro using one call with different registers or register combinations.
The following options are offered:

Code: Select all

push AF (single register)
push DE,HL,IY (multiple registers)
push exx (all double register BC', DE', HL')
push all (all registers including IX/IY, AF and double registers BC',DE',HL')
push AF,exx (combination of single registers and register set)
push $4000 (push of numerical values without destroyed registers)
Here similar definition for a pop macro:

Code: Select all

macro pop [char] {
      if char in <all>
       EXX
       POP HL DE BC
       EXX
       POP IY IX HL DE BC AF
      else if char in <exx>
       EXX
       POP HL DE BC
       EXX
      else if char eqtype 0
       s=char
       while s>0
        INC SP
        INC SP
       s=s-1
       end while
      else
       POP char
      end if
} 

Code: Select all

pop AF (single register)
pop DE,HL,IY (multiple registers)
pop exx (all double register BC', DE', HL')
pop all (all registers including IX/IY, AF and double registers BC',DE',HL')
pop AF,exx (combination of single registers and register set)
pop 1 (remove x values from stack without destroying registers)
So typical code sequences can be shortened:

Code: Select all

PUSH AF
PUSH BC
PUSH DE
PUSH HL
do something
POP HL
POP DE
POP BC
POP AF

push AF,BC,DE,HL
do something
POP HL,DE,BC,AF
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Macro for data manipulation and string formatting

Post by PokeMon »

Here is an example of data manipulation for strings but also possible to create structures of different types.

Code: Select all

macro dbinv va {
 local dbsize
 dbsize:
  dbzx va
 s=$-dbsize
 while s>0
  lod vb byte from $-s
  store byte vb xor 128 at $-s
  s=s-1
 end while
} 
This routine inverts a complete string while setting/resetting bit 7 of every char in the given string.
This can be restricted to the last char as well like used in the internal ZX81 tables.

Code: Select all

010C: [4115] 38 39 37 2A 26 32           dbzx 'STREAM'
0112: [411B] 26 27 28                    dbzx 'ABC'
0115: [411E] B8 B9 B7 AA A6 B2           dbinv 'STREAM'
011B: [4124] A6 A7 A8                    dbinv 'ABC'
While replacing value 128 with another value like 159 this will invert more bits and scramble this way text which appears unreadable. This can be easily reverse with XORing it again with the same value later in the program.

Code: Select all

010C: [4115] 38 39 37 2A 26 32           dbzx 'STREAM'
0112: [411B] 26 27 28                    dbzx 'ABC'
0115: [411E] A7 A6 A8 B5 B9 AD           dbinv 'STREAM'
011B: [4124] B9 B8 B7                    dbinv 'ABC'

Another macro can be used to format a text in a specific style like "INPUT" to "<I>NPUT".

Code: Select all

macro dbmark va {
 local dbsize
 dbsize:
  dbzx '<>'
  dbzx va
 lod vb byte from dbsize+2
 lod vc byte from dbsize+1
 store byte vb at dbsize+1
 store byte vc at dbsize+2
} 
This is the effect to the code:

Code: Select all

027B: [4284] 35 34 30 2A                 dbzx   'POKE'
027F: [4288] 35 37 2E 33 39              dbzx   'PRINT'
0284: [428D] 13 35 12 34 30 2A           dbmark 'POKE'
028A: [4293] 13 35 12 37 2E 33 39        dbmark 'PRINT'
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Useful macros for jumps and loops

Post by PokeMon »

Last but not least some macros for auto jump and 16 bit loops.

The following macro will automatically use relative jumps if possible to the distance (+/- 128 byte) and possibly given flags. So if code is growing up no more error messages will appear that jumps are out of range. If code is deleted the shortest jump variant will be used automatically.

Code: Select all

macro jr flag,target {
      if flag in <PO,PE,P,M>
       JP flag,target
      else
       if target eq
        if flag<$+2
         if flag+129>$+2
          JR flag
         else
          JP flag
         end if
        else if flag>$
         if flag-$>130
          JP flag
         else
          JR flag
         end if
        end if
       else
        if target<$+2
         if target+129>$+2
          JR flag,target
         else
          JP flag,target
         end if
        else if target>$
         if target-$>130
          JP flag,target
         else
          JR flag,target
         end if
        end if
       end if
      end if
}
Here some results:

Code: Select all

                                         backj:
017D: [4186] 00 00 00 00 00 00 00 00     db 126 dup 0
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00          
01FB: [4204] 18 80                       jr backj
01FD: [4206] C3 89 42                    jr backf
0200: [4209] 00 00 00 00 00 00 00 00     db 128 dup 0
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
             00 00 00 00 00 00 00 00    
                                         backf:
0280: [4289] 38 FE                       jr C,backf
0282: [428B] FA 89 42                    jr M,backf
0285: [428E] FA 89 42                    JP M,backf

And finally a typical 16 bit replacement of DJNZ instruction with a counter register of choice (BC,DE,HL):

Code: Select all

macro djnz16 reg,target {
      if reg in <HL>
       DEC HL
       LD A,H
       OR L
      else if reg in <DE>
       DEC DE
       LD A,D
       OR E
      else if reg in <BC>
       DEC BC
       LD A,B
       OR C
      end if
      jr NZ,target
}
And here too, if possible short jumps are used otherwise long jumps.

Code: Select all

02A4: [42AD] 2B 7C B5 20 D7              djnz16 HL,backf
02A9: [42B2] 1B 7A B3 C2 86 41           djnz16 DE,backj
02AF: [42B8] 0B 78 B1 C2 00 00           djnz16 BC,0
Depending on the register, the typical code is used in just one line:

Code: Select all

DEC HL
LD A,H
OR L
jr NZ,target

- short version -

djnz16 HL,target
bru65pag
Posts: 23
Joined: Sun Dec 20, 2015 12:09 pm

Viewing issue with ZX-IDE

Post by bru65pag »

Good evening,
I've had this issue for some time, and was not able to fix it. One of my programs opens as shown here:
ZX-IDE-screenshot.png
making it impossible to properly use. I have no clue what the reason is. I opened the file in Notepad++, looking for hidden char that could trigger this, without success. Any clue?
Thanks in advance. Bruno.
User avatar
gammaray
Posts: 590
Joined: Sun Apr 17, 2016 2:44 am
Location: Texas

Re: ZX-IDE Tutorial for programming assembler and ZX BASIC

Post by gammaray »

Document formatted by application? RTF? Probably not DOC. I'll start looking.

It is not RTF, RTF does not appear to have binary headers.
5-TS1000,UK ZX81<-Sheelagh, US ZX81, 2-TS1500/KDLX , 3-TS2040 printer, 2-TS2020 cassette decks, ZXPAND+AY, ZeddyNET, ZXBlast, UDG, ZX8CCB, AERCO, BUILDS/REPAIRS ZX Spectrum, ZX80 Minstrel, ZXMAX48 v1 v2, 2-TS-2068, ROM, 16kRAM
Post Reply