ZX81 Assembly Programming - Getting Started

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

Thanks Sirmorris,

What i mean in "optimisation" in fact is not the good word...

I'm just not sure for the "System variables" part about the utility of all entries and if i need all the lines...

:D
-=Zac
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZX81 Assembly Programming - Getting Started

Post by sirmorris »

Aaaah!

In all but a couple of cases - yes, you need to have them there if you're creating a P file. It simply won't work without.

One thing that I have started doing is compiling only the REM line to a binary file, then using ZXTOOL to insert it into the BASIC wrapper which is created with ZXTXT2P.

I'll upload an example soon.

C
User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

Thanks for your help Sir Morris d^.^p

I try several things on TASM... In Swensont document, i try the little program to print a string in DEFB line like that :

Code: Select all

            LD		HL,line			;load HL with address of line
PLINE       LD		A,(HL)			;load A with a character at HL
            CP		$FF				;is this $FF
            JP		Z,END			;if so, then jump to end
            CALL	 PRINT			;print character
            INC	  HL				;increment HL to get to next character
            JP		PLINE			;jump to beginning of loop
END         RET						;exit 

line:	DEFB  _H,_E,_L,_L,_O,$00,_W,_O,_R,_L,_D,$76,$ff
And i try another version but no more results, i always have the first caracter and no more...

What's wrong with it ?
-=Zac
User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

Another "mistake", but resolved :D

In documentation, page 14 where there are 2 lines to change in HTML ZXPaintyOne editor :
1. Insert this as line 265 :
if(x:=62) savedata +=',$'
it's not ":=" but "!="

here is the source of the complet function for better view :D

Code: Select all

      function dataAsHex() {
        var savedata = '';
        for (var y = 0; y < 48; y += 2) {
          savedata += '\n$';     // <--- secondadd
          for (var x = 0; x < 64; x += 2) {
            seq = '' + pixels[y][x] + pixels[y][x+1] + pixels[y+1][x] + pixels[y+1][x+1]
            if (seqToCode[seq] == null) {
              alert('Save error: invalid block graphic at coordinates ' + (x/2) + ',' + (y/2));
              return;
            } else {
              savedata += seqToCode[seq];
            }
            if (x!=62) savedata += ',$'  // <--- first add
          }
        }
        return savedata;
      }
-=Zac
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZX81 Assembly Programming - Getting Started

Post by sirmorris »

Zac wrote:And i try another version but no more results, i always have the first caracter and no more...

What's wrong with it ?
I can't answer that question without seeing the PRINT function. If this routine doesn't save the HL register then things could get interesting.

I have attached the BASIC/assembler code that I hinted at earlier.

You need TASM somewhere on your machine, as well as ZXTEXT2P and ZXTOOL available on your command path. Edit the batch file so that the path to the tasm installation is correct for your machine.

The assembler template compiles to a representation of a complete REM line as it would appear in a program. This is then inserted into the compiled BASIC program by ZXTOOL.

To work out why your code isn't working I suggest you learn how to use the debugger in EightyOne. It will help a great deal as you can watch the flow of your code and see where the problem occurs.
Attachments
ASMBAS.zip
(913 Bytes) Downloaded 296 times
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZX81 Assembly Programming - Getting Started

Post by sirmorris »

Put the following in the REM assembler file and it will happily print hello world:

Code: Select all

   .org  16509

   .byte 0,1                  ; 1 REM ....
   .word rem_end-rem_start   ; [length of line]
   
rem_start:
   .byte $ea                  ; REM

            LD      HL,line    ;load HL with address of line
PLINE:      LD      A,(HL)     ;load A with a character at HL
            CP      $FF        ;is this $FF

            ret     Z          ;if so, then end

            rst     10h        ;print character
            INC     HL         ;increment HL to get to next character
            jr      PLINE      ;jump to beginning of loop

line:       ; HELLO WORLD
            .db $2D,$2A,$31,$31,$34,$00,$3C,$34,$37,$31,$29,$76,$ff

   .db $76                  ; NEWLINE - end of REM line

rem_end:
  
   .end
You don't need to jump to the RET - you can use the conditional return. Also you should consider using JR - jump relative - where possible as this produces smaller faster code. I've used the built-in 'print' routine RST 08 instead of the PRINT routine.


C
User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

sirmorris wrote:I can't answer that question without seeing the PRINT function. If this routine doesn't save the HL register then things could get interesting.
In my "svars.asm" file i've this entry : PRINT EQU $0808
Perhaps not the good sub-routine address ?! :D
sirmorris wrote: I have attached the BASIC/assembler code that I hinted at earlier.

You need TASM somewhere on your machine, as well as ZXTEXT2P and ZXTOOL available on your command path. Edit the batch file so that the path to the tasm installation is correct for your machine.

The assembler template compiles to a representation of a complete REM line as it would appear in a program. This is then inserted into the compiled BASIC program by ZXTOOL.
I download and look at, thanks d^.^p
sirmorris wrote:To work out why your code isn't working I suggest you learn how to use the debugger in EightyOne. It will help a great deal as you can watch the flow of your code and see where the problem occurs.
I have this idea too... can i find a little documentation for that anywhere ?
-=Zac
User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

I've made tiny changes with a pause and used RST 10 :

Code: Select all

PAUSE 	.equ	$0F35

Start		CALL	SPRINT
			  RET

myt01		DEFB	_H,_E,_L,_L,_O,__,_W,_O,_R,_L,_D,_NL,$FF
				
SPRINT	POP		HL
				LD		A,(HL)
				INC		HL
				PUSH 	HL
				CP		$FF
				RET		Z
				RST		10

				LD		BC,$0050	;PAUSE LENGTH.
				CALL	PAUSE

				JR		SPRINT
It's better but :

The program don't seem to see the $FF end data....
The program crach on eightyone emulator but "work" with bizarre code behind the string in VB81_Xur emulator

Image

if i take another source already with RST 10 and pause like this :

Code: Select all

PAUSE 	.equ	$0F35

				LD		HL,line		;load HL with address of line
PLINE		LD		A,(HL)		;load A with a character at HL
				CP		$FF				;is this $FF
				JP		Z,END			;if so, then jump to end
				RST		10				;print character

				LD		BC,$0050	;PAUSE LENGTH.
				CALL	PAUSE

				INC		HL				;increment HL to get to next character
				JP		PLINE			;jump to beginning of loop
END			RET							;exit 

line:		DEFB  _H,_E,_L,_L,_O,$00,_W,_O,_R,_L,_D,$76,$ff
I just have a "H" printed and nothing after, just 5/2 at the end of the boucle at the bottom of the screen (in vb81 and eightyone)

??? :X
-=Zac
User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

Finally, it's working with this : (using $07F1 for PRINT sub routine)

Code: Select all

PAUSE 	EQU		$0F35
PRINT		EQU		$07F1

				LD		HL,line		;load HL with address of line
PLINE		LD		A,(HL)		;load A with a character at HL
				CP		$FF				;is this $FF
				JP		Z,END			;if so, then jump to end
				CALL	PRINT			; PRINT CHAR
				INC		HL				;increment HL to get to next character
				JP		PLINE			;jump to beginning of loop
END			RET							;exit 

line:		DEFB  _H,_E,_L,_L,_O,$00,_W,_O,_R,_L,_D,$76,$ff
\o/

But when i try to add a pause between 2 chars, i've another problem :

Code: Select all

				LD		BC,$0050	;PAUSE LENGTH.
				CALL	PAUSE
where i put these 2 lines ? must i save some registry before ? (style BC or/and HL) ? like that :

Code: Select all

				PUSH	BC
				PUSH	HL
				LD		BC,$0050	;PAUSE LENGTH.
				CALL	PAUSE
				POP		HL
				POP		BC
-=Zac
User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

And finally, finally, this one seem to be good \o/

Code: Select all

PAUSE 	EQU		$0F35
PRINT		EQU		$07F1

				LD		HL,line		;load HL with address of line
PLINE		LD		A,(HL)		;load A with a character at HL
				CP		$FF				;is this $FF
				JP		Z,END			;if so, then jump to end
				CALL	PRINT			; PRINT CHAR
				INC		HL				;increment HL to get to next character

				PUSH	BC
				PUSH	HL
				LD		BC,$0050	;PAUSE LENGTH.
				CALL	PAUSE
				POP		HL
				POP		BC

				JP		PLINE			;jump to beginning of loop
END			RET							;exit 

line:		DEFB  _H,_E,_L,_L,_O,$00,_W,_O,_R,_L,_D,$76,$ff
Thanks Sir Morris ;)
-=Zac
Post Reply