New to Machine code, help required

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
XavSnap
Posts: 526
Joined: Sat May 10, 2008 4:23 pm

Re: New to Machine code, help required

Post by XavSnap » 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
(Probably) nothing is being printed to the screen, not even blank characters during the LDIR
Each loop "poke" a byte in memory from HL to DE !
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

:D

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

rune
Posts: 158
Joined: Thu Sep 04, 2014 8:35 am

Re: New to Machine code, help required

Post by rune » Sat Dec 08, 2018 9:02 am

Hi XavSnap

I understand how the LDIR call works. Your examples show this to good effect.

When I said that Panthers second example wasn't working, it was because the HL and DE registers had never been initialised. Therefore they would have been moving data anywhere, but it wasn't to the screen.

Also, in addition to displayable memory locations the display file contains the N/L character. If these are moved - as they would be when BC > 32 - the display file is likely to crash.

Earlier you mentioned that DEC BC affected the flags Z register. According to my book (Zaks) the DEC rr call doesn't affect any registers. Hence the reason why it has to be tested using the accumulator. You use a similar thing here...

LD A,$00
DEC HL
CP H

and here

DEC BC
LD A,B
OR C

But DEC B or DEC C would set the zero flag. The length of the display file is 704 (or 727 with N/L) so would be 02C0 (or 027D) ie testing B=0 doesnt mean C will also = 0.
Dave

User avatar
XavSnap
Posts: 526
Joined: Sat May 10, 2008 4:23 pm

Re: New to Machine code, help required

Post by XavSnap » Sat Dec 08, 2018 10:31 pm

:D
Earlier you mentioned that DEC BC affected the flags Z register. According to my book (Zaks) the DEC rr call doesn't affect any registers.
True.

DEC HL
RET N
Won't work.
The F flag (AF register) isn't updated like a DEC H !

Hence the reason why it has to be tested using the accumulator. You use a similar thing here...
LD A,$00 ; LOAD A register
DEC HL ; DEC HL register... H (if HL>$FF) or L(if HL<$FF) register
CP H ; Test the H register...

But, the L register won't be tested !!!
You steel in height bits.
You had to test H AND L registers.
LD A,$00
DEC HL
CP H
JR NZ, LOOP1
CP L
JR NZ, LOOP1
;it' null
; JUMP TO SOMETHING
RET
LOOP1:
; Not null
RET


and here

DEC BC
LD A,B
OR C

...It's a miscellaneous stuff to detect a null BC
In this routine, you get the B value : 00001000
and the C value : 00000001
00001000
OR
00000001
= (00001000+00000001)=00001001(>0)
Result : Z flag set to 0 (false).

If B=0 AND C=0:
(00000000+00000000)=0
Result : Z flag set to 1 (true).

On a pair register, you add to use the "ADD HL,RP" and "SBC HL,RP" functions.

Example: To compare DE with a value INC DE to $200
SBC function(subtract)
PUSH HL
LD HL,$200
SBC HL,DE ; Subtract DE from HL
JP P,p1 ; DE<200; it's a positive value.
; DE<0, DE is a negative value.
POP HL
JR n1


ADD function(add!)
PUSH HL
LD HL,$FFFF-$200
ADD HL,DE ; Subtract DE from HL
JP NC,p1 ; DE<200; it's a positive value.
; DE<0, DE is a negative value. (Carry value set to 1)
POP HL
JR n1


Hoops...
I forgot the magic DJNZ function...

LD BC,$0211 ; B=11 and C=02 =$11+2x$FF ($0211 loops!)
LOOP1:
PUSH BC
; You routine...
POP BC
DJNZ LOOP1 ;B=B-1; Stop loop to LOOP1 ; if B=0
LD B,$FF
DEC C
JR NZ LOOP1 ;
; next ...

User avatar
XavSnap
Posts: 526
Joined: Sat May 10, 2008 4:23 pm

Re: New to Machine code, help required

Post by XavSnap » Sun Dec 09, 2018 3:18 am

:mrgreen:

LD A,$00
DEC HL
CP H


Code: Select all

Lb40A4:
	LD BC,0000
	CALL CURSEUR ; Set the basic cursor to x,y (0,0)

		LD HL,$03BF ; HL=counter+$00FF=$02C0+$00FF
Lb40A7:
		LD A,161 ; '5' to display
		RST 10H ; Display= A reg.
		LD A,$00 ; set A
		DEC HL ; ...
		CP H ; compare H<>A... if HL=$00FF set AF register z=1 to exit the loop
		JR NZ, Lb40A7 ; [$40A7:16551]
		;HL=$00FF ($02C0 loops)
		RET ; ==========================
:ugeek:

HullZX81man
Posts: 3
Joined: Sat Feb 24, 2018 9:07 pm

Re: New to Machine code, help required

Post by HullZX81man » Sun Dec 09, 2018 11:14 am

Hi

Just curious which Assembler's you are using?

rune
Posts: 158
Joined: Thu Sep 04, 2014 8:35 am

Re: New to Machine code, help required

Post by rune » Sun Dec 09, 2018 1:39 pm

LD A,$00
DEC HL
CP H

Ah, now I see what you are doing...

@HullZX81man, I use TASM. I write the code in Notepad++, a batch file (below) assembles the code and produces a .p file which I can then drop onto eightyone emulator to test.

@echo off

set /p file=File to compile:

echo.assembling tVars.asm
tasm -80 -b -s %file%.asm %file%.p
pause

User avatar
XavSnap
Posts: 526
Joined: Sat May 10, 2008 4:23 pm

Re: New to Machine code, help required

Post by XavSnap » Sun Dec 09, 2018 7:35 pm

The TASM ZX81's kit... (EO & VB81xur)
TASM_ZX81.zip
(281.71 KiB) Downloaded 9 times
EO:
TASM compil a 'P' file... (you had to reload the P file to refresh the file...)

VB81 XuR:
Create and load the BLANK text file (one REM), select the REM to assign the memory room, in the disassembler window.
Load (refresh) the binary in the rem line...

HullZX81man
Posts: 3
Joined: Sat Feb 24, 2018 9:07 pm

Re: New to Machine code, help required

Post by HullZX81man » Tue Dec 11, 2018 10:42 pm

Thank you very much.

Post Reply