Page 1 of 2
First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 5:07 am
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.
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 5:30 am
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.
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 5:52 am
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
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"
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 6:01 am
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?
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 6:03 am
by Paul
Definitely
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 6:49 am
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!
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 8:38 am
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.
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 3:45 pm
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
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 5:49 pm
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.
Re: First steps in zx81 machine code, question
Posted: Sat Jul 17, 2021 9:12 pm
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:
Never overwrite the $76/118 "new-line" code…