First steps in zx81 machine code, question

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
sl07h1
Posts: 34
Joined: Mon Feb 22, 2021 7:16 pm

First steps in zx81 machine code, question

Post by sl07h1 »

Hi gurus, I want to do a test with a program intented to do this: Get the address of the display file, then put next 672 (just a random number) bytes to 1, then RET.

My code (very simple) is this:

Code: Select all


      LD HL, (400Ch) <-get the display address
      LD BC,672
LOOP: INC HL
      LD (HL),1
      DEC BC
      LD A,B
      OR C
      JR NZ, LOOP
      RET

I'm using a BASIC loader to a REM line.
The code works, I can see the 672 CHR$(1) in the screen, I get the 0/0 message, but then I press enter and the computer resets.

I have experience working in the ZX-Spectrum, I have made a lot of routines involving the display, but I think that I read somewhere that the ZX81 display is trickier, not just put the bytes on it, so I think maybe I'm doing something wrong. I have 32KB or RAM (Memopak 32k)

What is wrong?

I want to be able, in the end, to put chars wherever I want in the display file, am I on the right track?

Thanks in advice.
User avatar
BarryN
Posts: 151
Joined: Thu Nov 09, 2017 11:34 pm

Re: First steps in zx81 machine code, question

Post by BarryN »

sl07h1 wrote: Sat Jul 17, 2021 5:07 am The code works, I can see the 672 CHR$(1) in the screen, I get the 0/0 message, but then I press enter and the computer resets.
Was the display file compressed or expanded when you did this? The ZX81 uses a resizable display-file (screen buffer) meaning that it can be expanded or shrunk depending on the amount of installed memory and the amount of free space at the moment. If it was compressed you might have caused a crash due to a corrupt display file.
sl07h1
Posts: 34
Joined: Mon Feb 22, 2021 7:16 pm

Re: First steps in zx81 machine code, question

Post by sl07h1 »

BarryN wrote: Sat Jul 17, 2021 5:30 am Was the display file compressed or expanded when you did this? The ZX81 uses a resizable display-file (screen buffer) meaning that it can be expanded or shrunk depending on the amount of installed memory and the amount of free space at the moment. If it was compressed you might have caused a crash due to a corrupt display file.
I don't know what you're talking about :D :D :D I guess I have a lot to learn yet... As I said I have a Memopak 32kb, so I guess the installed memory and the amount of space could be considered as "high"
sl07h1
Posts: 34
Joined: Mon Feb 22, 2021 7:16 pm

Re: First steps in zx81 machine code, question

Post by sl07h1 »

Is it possible that I should put a newline after every line? I'm playing now and I have noted that, when the number of "1" bytes is <32 everything works ok, but when I have more than that the display crashes. Maybe I have to put a newline char every time that I got to the end of the line?
User avatar
Paul
Posts: 1511
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: First steps in zx81 machine code, question

Post by Paul »

Definitely
In theory, there is no difference between theory and practice. But, in practice, there is.
sl07h1
Posts: 34
Joined: Mon Feb 22, 2021 7:16 pm

Re: First steps in zx81 machine code, question

Post by sl07h1 »

Ok, now I made another routine that writes 32 bytes, a newline, then 32 bytes more, a newline, etc. It works OK. If I change the 32 to 31, it crashes.

I'm guessing that the display file (with the 32kb) is always 21 lines of 32 bytes of something and a newline. If you write other value where is a newline, or if you write a newline elsewhere, the system crashes.

Am I right?

[EDIT]

I ran the same routine but I didn't write newlines, I just leave that byte alone. It works OK

OK, so the problem with my first routine is that I was overwriting the newlines with a 1.

Well, this was FUN!

Thanks!
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: First steps in zx81 machine code, question

Post by dr beep »

sl07h1 wrote: Sat Jul 17, 2021 6:49 am Ok, now I made another routine that writes 32 bytes, a newline, then 32 bytes more, a newline, etc. It works OK. If I change the 32 to 31, it crashes.

I'm guessing that the display file (with the 32kb) is always 21 lines of 32 bytes of something and a newline. If you write other value where is a newline, or if you write a newline elsewhere, the system crashes.

Am I right?
The display needs a fixed time per line to work. The NEWLINE delays each line to 207 tstates, but 34 characters per line also uses 207 tstates. Byte 34 however can not be inverted. A full screen starts with a newline, then uses 32 visible positions and a newline, 24x.

The screen can be shortened with less bytes visible per line and not used lines at the bottom with a single #E9 after the last NEWLINE from the last used byte.
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: First steps in zx81 machine code, question

Post by 1024MAK »

If the ZX81 ROM finds less than about 3¾k bytes of available RAM, the display file operates as a compressed display file to conserve RAM. This is especially important when the machine only has the internal 1k bytes of RAM only. In this mode, the size of the display file changes as items are printed to the ‘screen’. If the screen is blank, the display file may well just be new line codes.

Above about 3¾k bytes of available RAM, the display file operates in the fully expanded mode. Now it normally takes up its full size. New line codes are normally still required at the end of each line.

Don’t forget, with the ZX81, the Z80A actually tries to execute the display file data as code. It’s only the ULA overriding the character data from the RAM before the Z80A reads it that means the Z80A actually sees NOP instructions.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: First steps in zx81 machine code, question

Post by dr beep »

1024MAK wrote: Sat Jul 17, 2021 3:45 pm If the ZX81 ROM finds less than about 3¾k bytes of available RAM, the display file operates as a compressed display file to conserve RAM. This is especially important when the machine only has the internal 1k bytes of RAM only. In this mode, the size of the display file changes as items are printed to the ‘screen’. If the screen is blank, the display file may well just be new line codes.

Above about 3¾k bytes of available RAM, the display file operates in the fully expanded mode. Now it normally takes up its full size. New line codes are normally still required at the end of each line.

Don’t forget, with the ZX81, the Z80A actually tries to execute the display file data as code. It’s only the ULA overriding the character data from the RAM before the Z80A reads it that means the Z80A actually sees NOP instructions.

Mark
The screen will also remain compressed when the loaded game uses a compressed screen and the ROM-routines to decompress the screen are never used. The screen is decompressed with a CLS, but if you don't use that, the screen stays compressed.

Best thing is to define the screen you need in MC and make your own CLS in MC as well.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: First steps in zx81 machine code, question

Post by XavSnap »

Six way to fill a screen !


Header:

Code: Select all

#define ORG  .org       ; TASM cross-assembler definitions
#define equ  .equ
;-----------------------------------

;------- Rom and Ram Symbols -------
RAM_D_FILE equ $400C ; D_file address.
EXTERR equ $005B ; Basic Break function ! Ignore line instructions.
CURSEUR equ $8F5 ; Point to PRINT AT DEST.(BC=X,Y)
CHAINE equ $B6B ; PRINT A CHAINE (BC=LEN;DE=TEXT LOC)
	
ORG 16514

Code: Select all

;--------- Routine 1 ----------	
	LD BC,0000
	CALL CURSEUR
	LD BC,22*32
LOOP1:
	LD A,157 ; '1'
	RST 10H
	DEC BC
	LD A,B
	OR C
	JR NZ,LOOP1
	RET

Code: Select all

;--------- Routine 2 ----------

	LD HL,(RAM_D_FILE)
	LD B,158 ; '2'
	LD DE,32*24+23
LOOP2:
	LD A,$76
	INC HL
	CP (HL)
	DEC DE
	JR Z,LOOP2
	LD (HL),B
	LD A,D
	OR E
	RET Z
	JR LOOP2

Code: Select all

;--------- Routine 3 ----------

	LD HL,(RAM_D_FILE)
LOOP3:
	INC HL
	LD D,H
	LD E,L
	INC DE
	LD A,159 ; '3'
	LD (HL),A
	LD BC,31
	LDIR
	LD A,$80
	EX DE,HL
	INC HL
	CP (HL)
	EX DE,HL
	RET Z
	INC HL
	JR LOOP3

Code: Select all

;--------- Routine 4 ----------

	LD HL,(RAM_D_FILE)
	INC HL
	LD D,H
	LD E,L
	INC DE
	LD A,160 ; '4'
	LD (HL),A
	LD BC,31
	LDIR
	LD BC,$0100
	CALL CURSEUR
	LD L,21

LOOP4:

	LD DE,(RAM_D_FILE)
	INC DE
	LD BC,32
	CALL CHAINE
	DEC L
	RET Z
	RET Z
	JR LOOP4

Code: Select all

;--------- Routine 5 ----------

Lb40A4:
	LD BC,0000
	CALL CURSEUR
		LD HL,$03BF 
Lb40A7:
		LD A,161 ; '5'
		RST 10H ; Display= A reg.
		LD A,$00 
		DEC HL 
		CP H 
		JR NZ, Lb40A7 ; [$40A7:16551]
		RET ; ==========================

Code: Select all

;--------- Routine 6 ----------

	LD BC,0000
	CALL CURSEUR
		LD BC,$BF02 ; $FF+$FF+$BF
LOOP5:
		LD A,161 ; '6'
		RST 10H ; Display= A reg.
		LD A,$00 
		DJNZ LOOP5 ; if B<>0
		LD B,$FF 
		DEC C
		JR NZ, LOOP5
		RET ; ==========================
	
footer:

Code: Select all

.end
Never overwrite the $76/118 "new-line" code…
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply