LOWRES -demo

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
ChrisB
Posts: 31
Joined: Tue Dec 17, 2024 8:53 am
Location: France

Re: LOWRES -demo

Post by ChrisB »

Thank you for your help Dr Beep.
I changed the code, but I can't understand why it is moving to the right only once ?

Code: Select all

; free codeable memory

;----------------------------------------------

gamecode
	ld hl,line1		; first display
	ld (hl),"H"-27	
	ld hl,line2
	ld (hl),"H"-27
	ld hl,line3
	ld (hl),"A"-27	
	ld hl,line4
	ld (hl),"A"-27

;bkpt	jr bkpt

wkey	ld bc,(lastk)		; get key information
	ld a,c			; copy C in A to keep C
	inc a			; Test if NOKEY pressed
	jr z,wkey		; NO KEY, wait for key

	call erase

	call right

okmove  jr wkey		; stay in playloop


;---------ROUTINES-----------------------------

erase
	ld hl,line1
	ld (hl),0		; erase old position

	ld hl,line2
	ld (hl),0

	ld hl,line3
	ld (hl),0

	ld hl,line4
	ld (hl),0
	ret

right
	ld hl,line1
	inc hl			; move right
	ld (hl),"H"-27

	ld hl,line2
	inc hl
	ld (hl),"H"-27

	ld hl,line3
	inc hl
	ld (hl),"A"-27

	ld hl,line4
	inc hl	
	ld (hl),"A"-27

	ret

;----------------------------------------------

; the display file, Code the lines needed.
dfile
	db 118,118
line1
	block	32,0
	ld	h,d
	ld	l,e
	db	118
line2	
	block	32,0
	ld	h,d
	ld	l,e
	db	118
line3	
	block	32,0
	ld	h,d
	ld	l,e
	db	118
line4	
	block	32,0
	ld	h,d
	ld	l,e
	db	118

	db	#e9	; fill unused part of the screen

	
vars	db 128
last	equ $		

end		
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: LOWRES -demo

Post by dr beep »

because you don't have a variable location within the line.

You reset your position to the same position as you started after a move.
ChrisB
Posts: 31
Joined: Tue Dec 17, 2024 8:53 am
Location: France

Re: LOWRES -demo

Post by ChrisB »

Sorry I'm just beginner.
I added a variable with no success...

Code: Select all

; free codeable memory

vhor	db	1

;----------------------------------------------

gamecode
	ld hl,line1		; first display
	ld (hl),"H"-27	
	ld hl,line2
	ld (hl),"H"-27
	ld hl,line3
	ld (hl),"A"-27	
	ld hl,line4
	ld (hl),"A"-27

	ld hl,1			; initialize line counter to 1
	ld (vhor),hl

;bkpt	jr bkpt

wkey	ld bc,(lastk)		; get key information
	ld a,c			; copy C in A to keep C
	inc a			; Test if NOKEY pressed
	jr z,wkey		; NO KEY, wait for key

	;call erase

	call right

okmove  jr wkey		; stay in playloop


;---------ROUTINES-----------------------------

erase
	ld hl,line1
	ld (hl),0		; erase old position

	ld hl,line2
	ld (hl),0

	ld hl,line3
	ld (hl),0

	ld hl,line4
	ld (hl),0
	ret

right

	push de
	ld hl,0
	ld de,line1
	add hl,de
	ld de,(vhor)	 
	add hl,de	; add line counter to hl
	inc de
	;ld (vhor),de	; save incremented line counter -> problem	
	pop de
	ld (hl),"H"-27

	ret


	ld hl,line2
	inc hl
	ld (hl),"H"-27

	ld hl,line3
	inc hl
	ld (hl),"A"-27

	ld hl,line4
	inc hl	
	ld (hl),"A"-27

	ret

;----------------------------------------------

; the display file, Code the lines needed.
dfile
	db 118,118
line1
	block	32,0
	ld	h,d
	ld	l,e	
	db	118

line2	
	block	32,0
	ld	h,d
	ld	l,e
	db	118
line3	
	block	32,0
	ld	h,d
	ld	l,e
	db	118
line4	
	block	32,0
	ld	h,d
	ld	l,e
	db	118

	db	#e9	; fill unused part of the screen

	
vars	db 128
last	equ $		

end	
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: LOWRES -demo

Post by dr beep »

No problem learning to code.

try this:

Ld hl,line1



Display
Push hl
Ld de,line2-line1 ; size of a line
Ld (hl),”A”-27
Add hl,de
Ld (hl),”A”-27
Add hl,de
Ld (hl),”Z”-27
Add hl,de
Ld(hl),”Z”-27
Pop hl
Ret

for erase same but place 0 in (hl)

On keypress only do INC HL
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: LOWRES -demo

Post by dr beep »

dr beep wrote: Sun Feb 02, 2025 8:32 pm No problem learning to code.

try this:

Ld hl,line1

Loop
Call display

Delay loop

Call erase
Read key
Alter hl

Jr loop




Display
Push hl
Ld de,line2-line1 ; size of a line
Ld (hl),”A”-27
Add hl,de
Ld (hl),”A”-27
Add hl,de
Ld (hl),”Z”-27
Add hl,de
Ld(hl),”Z”-27
Pop hl
Ret

for erase same but place 0 in (hl)

On keypress only do INC HL
ChrisB
Posts: 31
Joined: Tue Dec 17, 2024 8:53 am
Location: France

Re: LOWRES -demo

Post by ChrisB »

Ok, it's working fine. Thank you very much again.
Now I have to add controls, and vertical move.

Code: Select all

gamecode
	ld hl,line1
loop1
	call display
	call delay
	call wkey
	call erase
	inc hl			; horizontal move (right only, no controls)
	jr loop1		; stay in playloop


;---------ROUTINES-----------------------------

wkey	ld bc,(lastk)		; get key information
	ld a,c			; copy C in A to keep C
	inc a			; Test if NOKEY pressed
	jr z,wkey		; NO KEY, wait for key
	ret

display
	push hl
	ld de,line2-line1	; size of a line
	ld (hl),"H"-27
	add hl,de
	ld (hl),"H"-27
	add hl,de
	ld (hl),"A"-27
	add hl,de
	ld (hl),"A"-27
	pop hl
	ret

erase				; erase old position
	push hl
	ld de,line2-line1	
	ld (hl),0		
	add hl,de
	ld (hl),0
	add hl,de
	ld (hl),0
	add hl,de
	ld (hl),0
	pop hl
	ret

delay
	push hl
	ld	a,256-10
	ld	hl,frames
	add	a,(hl)
wfk	cp	(hl)
	jr	nz,wfk	
	pop hl
	ret

;----------------------------------------------

; the display file, Code the lines needed.
dfile
	db 118,118
line1
	block	32,0
	ld	h,d
	ld	l,e	
	db 118
line2	
	block	32,0
	ld	h,d
	ld	l,e	
	db 118

	block	32,0
	ld	h,d
	ld	l,e	
	db 118

	block	32,0
	ld	h,d
	ld	l,e	
	db 118

	db	#e9	; fill unused part of the screen

	
vars	db 128
last	equ $		

end			
By the way, I absolutely loved your series of tutorials here https://www.sinclairzxworld.com/viewtop ... f=6&t=4045, with exercices and examples, growing to a complete small game.
I think you may use this method again, it is so gratifying for a lot of us. But I know it is time consuming !
Attachments
screen.asm
(2.33 KiB) Downloaded 51 times
screen.p
(268 Bytes) Downloaded 49 times
Post Reply