### Re: New to Machine code, help required

Posted:

**Fri Dec 07, 2018 9:19 pm**Hi rune,

The main way to print a character on the zx81, is to feed the D_file (video memory), using the LD (address) function (POKE).

The RST10 (Call $0010) pass the A register to the ROM display routine.

LDIR able to copy a part of memory from HL to DE, with the BC lenght.

LD HL,$4100 ; From

LD DE,$4200 ; Target

LD BC,$100 ; length

LDIR

equal to :

LD HL,$4100

LD DE,$4200

LD BC,$100

loop1:

EXX DE,HL ; DE=FROM HL=TARGET

LD A,(DE)

LD (HL),A

INC DE

INC HL

DEC BC

LD A,B

OR C

EXX DE,HL ; HL=HL+BC ($4200): FROM DE=DE+BC ($4300): BC=0

RET Z

JR LOOP1

The LDIR function is a Z80 integrated subroutine to loop and copy to a target memory.

The LDIR will loop $100 time.(The target memory will be feed at any loop!)

You can use this routine to slow down the CPU:

LD HL,$4100

LD DE,$4100

LD BC,$FFFF

LDIR

Or add BC to HL & DE:

LD HL,$4100

LD DE,$4100

LD BC,$100

LDIR ; HL+100 : DE+100

=

ADD HL,BC

PUSH HL

LD H,D ; or EX DE,HL

LD L,E ; ---------------

ADD HL,BC

LD D,H

LD E,L

POP HL

;HL=HL+BC

;DE=DE+BC

LD HL,$4100

LD DE,$4101

LD BC,$100

=

LD($4101),($4100) ; $4101= $4100

LD($4102),($4101) ; $4102= $4101 ....

LD($410+n+1),($4100+n) ; $410+n+1= $4100+n = $4100

A link to the Z80 functions... http://zx81.vb81.free.fr/ASM2.html

The main way to print a character on the zx81, is to feed the D_file (video memory), using the LD (address) function (POKE).

The RST10 (Call $0010) pass the A register to the ROM display routine.

LDIR able to copy a part of memory from HL to DE, with the BC lenght.

LD HL,$4100 ; From

LD DE,$4200 ; Target

LD BC,$100 ; length

LDIR

equal to :

LD HL,$4100

LD DE,$4200

LD BC,$100

loop1:

EXX DE,HL ; DE=FROM HL=TARGET

LD A,(DE)

LD (HL),A

INC DE

INC HL

DEC BC

LD A,B

OR C

EXX DE,HL ; HL=HL+BC ($4200): FROM DE=DE+BC ($4300): BC=0

RET Z

JR LOOP1

The LDIR function is a Z80 integrated subroutine to loop and copy to a target memory.

The LDIR will loop $100 time.(The target memory will be feed at any loop!)

You can use this routine to slow down the CPU:

LD HL,$4100

LD DE,$4100

LD BC,$FFFF

LDIR

Or add BC to HL & DE:

LD HL,$4100

LD DE,$4100

LD BC,$100

LDIR ; HL+100 : DE+100

=

ADD HL,BC

PUSH HL

LD H,D ; or EX DE,HL

LD L,E ; ---------------

ADD HL,BC

LD D,H

LD E,L

POP HL

;HL=HL+BC

;DE=DE+BC

Each loop "poke" a byte in memory from HL to DE !(Probably) nothing is being printed to the screen, not even blank characters during the LDIR

LD HL,$4100

LD DE,$4101

LD BC,$100

=

LD($4101),($4100) ; $4101= $4100

LD($4102),($4101) ; $4102= $4101 ....

LD($410+n+1),($4100+n) ; $410+n+1= $4100+n = $4100

A link to the Z80 functions... http://zx81.vb81.free.fr/ASM2.html