Single pixel motion in high res?

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Spinnetti
Posts: 282
Joined: Sat Sep 12, 2020 11:29 pm

Re: Single pixel motion in high res?

Post by Spinnetti »

Thanks!

We are doing a HRG game now, but I'm sure its not nearly as efficient as your code and would love to learn more in a small scope like that. I think for most games a small block of UDG would be more than enough too. Sometimes its hard looking at a whole program to just understand the key components. a moving block example would help a lot :)
Zeddy: ZX80, ZX81/ZXpand, TS1000/ZXpand, TS1500/Zxpand+,Printer
Speccy: 48k, +, +2, +3, TS2068, "Bare Metal" Pi, Next KS2, IF1/Microdrives/Vdrive/Light Gun/VGA-Joy
QL: Minerva/QL-VGA/Custom PSU
C5: 24v, LiFE battery, Disc brakes
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Single pixel motion in high res?

Post by dr beep »

Demo almost ready. Display is working, movement is all it needs.

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

Re: Single pixel motion in high res?

Post by dr beep »

Here an exemple how to display a bitwise UDG on the screen

Controls QAOP
demo001.asm
(6.99 KiB) Downloaded 175 times
demo001.p
(360 Bytes) Downloaded 211 times
Spinnetti
Posts: 282
Joined: Sat Sep 12, 2020 11:29 pm

Re: Single pixel motion in high res?

Post by Spinnetti »

Thanks, Very helpful - that will give me a lot to chew on for quite a while! What Assembler do you use? format seems to have lots of differences from my usual FASMW-ZX. Once I fully understand your code I should be able to do lots of cool stuff - thanks for taking the time to share!

We did roll something based on WRX that's working but there's a lot for me to learn from you code and once I fully understand it I'll refactor. I feel like a dunce lol. I'll ask a much more basic (non-HRG) question in another post :) This is what we have so far with little animated dudes. Its not a Robotron clone, but inspired by it, and single joystick.
Robotack 20220207.jpg
Zeddy: ZX80, ZX81/ZXpand, TS1000/ZXpand, TS1500/Zxpand+,Printer
Speccy: 48k, +, +2, +3, TS2068, "Bare Metal" Pi, Next KS2, IF1/Microdrives/Vdrive/Light Gun/VGA-Joy
QL: Minerva/QL-VGA/Custom PSU
C5: 24v, LiFE battery, Disc brakes
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Single pixel motion in high res?

Post by dr beep »

Spinnetti wrote: Tue Feb 08, 2022 3:30 am Thanks, Very helpful - that will give me a lot to chew on for quite a while! What Assembler do you use? format seems to have lots of differences from my usual FASMW-ZX. Once I fully understand your code I should be able to do lots of cool stuff - thanks for taking the time to share!
The assembler is SJASM, but the file compiles directly to an executable .P directly after loading.
The BASIC to start the machinecode is fully coded over sysvar so even when the code would load but not run you still can't see the REM with other BASIC since there is none.

The code itself is quite simple.

Set up a hires routine to display, set IX.

Clear the screen

show an udg
wait some time
erase udg
do any possible move
go back to show udg
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Single pixel motion in high res?

Post by dr beep »

Optimized screenaddress.

Code: Select all

; calculate screenaddress for XY-pos in BC (optimized in speed)
; Right address = SCREEN + B*32 + INT (C/8)
; B*32 = B/8 where B MOD 8 must be in 3 highbits C
scrad	srl b		; B / 2
	rr c		; Bit 0 from B in bit 7 C, and C/2
	srl b		; B / 2, now B = B/4
	rr c		; Bit 0 from B in bit 7 C, and C/2, C= C/4
	srl b		; B / 2, now B = B/8
	rr c		; Bit 0 from B in bit 7 C, and C/2, C= C/8
	ld hl,screen	; BC now B*32+ INT (C/8), now we need start of screen too
	add hl,bc	; HL now screenaddress
	ret
Spinnetti
Posts: 282
Joined: Sat Sep 12, 2020 11:29 pm

Re: Single pixel motion in high res?

Post by Spinnetti »

Awesome, thanks for the additional feedback. We should be able to crank out this next couple games alot faster than the 40 years it took us for our first one lol :)
Zeddy: ZX80, ZX81/ZXpand, TS1000/ZXpand, TS1500/Zxpand+,Printer
Speccy: 48k, +, +2, +3, TS2068, "Bare Metal" Pi, Next KS2, IF1/Microdrives/Vdrive/Light Gun/VGA-Joy
QL: Minerva/QL-VGA/Custom PSU
C5: 24v, LiFE battery, Disc brakes
ChrisB
Posts: 31
Joined: Tue Dec 17, 2024 8:53 am
Location: France

Re: Single pixel motion in high res?

Post by ChrisB »

Hello,
I tried to display 2 or more UDGs on screen, but I can't get it right.
Maybe Dr Beep willing to give some help ?
See the game loop.
Thank you !

Code: Select all

	ORG  #4009             ;#4009                        
  
; program starts here, both BASIC and machinecode               
basic      EX   AF,AF'            ; delay intrupt,opcode no bit 6
           LD   H,B               ; preset for 48K bug to #40   
           JR   init0             ; continue where room         
                       
           DEFB 236,212,28        ; The BASIC                   
           DEFB 126               ; fully placed over sysvar    
           DEFB 143,0,18          ; start BASIC=#4009 also MC   
                       
           DEFW last              ; needed by loading           
chadd      DEFW last-1 
xptr       DEFW 0      
stkbot     DEFW last   
stkend     DEFW last   
berg       DEFB 0      
mem        DEFW 0      
           DEFB 128    
  
           DEFB 0,0,0  
  
; all above reusable AFTER loading                              
  
lastk      DEFB 255,255,255     ; used by ZX81                
margin     DEFB 55              ; used by ZX81                
nxtlin     DEFW basic           ; reusable after load     

	nop  
	defb #40,#40,#40   
	
  	nop                 
   
taddr      DEFW 0               ; used by ZX81 on LOAD only   
	; unharmed code               

    DEFW 0               
   
frames
    DEFB 255                   
    DEFB 255               		; highbyte must have bit 7 set
coords     DEFW 0                

prcc       DB 0,0,0              
   
cdflag     DEFB 64              ; used by ZX81                

;-------------------------------------------------------------------   
; Place ANY code to fill up to #4040                            
; init

init0
	ld ix,hr
	ld hl,screen
	ld de,screen+1
	ld (hl),0
	ld bc,6143
	ldir			; clear hires screen

;-------------------------------------------------------------------
; game loop

ploop
	ld bc,(mycoord1)	; get X and Y UDG on screen in BC
	call mydisplay1
	ld bc,(mycoord2)	; get X and Y UDG on screen in BC
	call mydisplay2
	
	call mydelay
	
	ld de,myudg1
	call prudg		; erase udg
	ld de,myudg2
	call prudg		; erase udg

	jr ploop		; do playloop

;-------------------------------------------------------------------
; mydisplay

mydisplay1
	call scrad		; calculate screen address
	push hl			; save position
	ld de,myudg1
	call prudg		; show UDG
	pop hl
	ret
	
mydisplay2
	call scrad		; calculate screen address
	push hl			; save position
	ld de,myudg2
	call prudg		; show UDG
	pop hl
	ret

;-------------------------------------------------------------------
; delay

mydelay
	push hl
	ld hl,frames
	ld a,(hl)
	sub 5			; lower number will speed up game.
mywait
	cp (hl)
	jr nz,mywait	; wait some time
	pop hl
	ret

;-------------------------------------------------------------------
; show/erase udg

prudg
	ld b,8
prudg1
	ld a,(de)		; get udg 
	xor (hl)		; xor udg on screen
	ld (hl),a		; write on screen
	inc de
	inc hl
	ld a,(de)		; also second position
	xor (hl)
	ld (hl),a
	inc de
	ld a,l
	add a,31		; move to next line on screen
	ld l,a
	jr nc,bdec
	inc h			; next block on screen when needed
bdec	djnz prudg1 
	ret

;-------------------------------------------------------------------
; calculate screenaddress for XY-pos in BC (optimized in speed)
; Right address = SCREEN + B*32 + INT (C/8)
; B*32 = B/8 where B MOD 8 must be in 3 highbits C

scrad	srl b		; B / 2
	rr c			; Bit 0 from B in bit 7 C, and C/2
	srl b			; B / 2, now B = B/4
	rr c			; Bit 0 from B in bit 7 C, and C/2, C= C/4
	srl b			; B / 2, now B = B/8
	rr c			; Bit 0 from B in bit 7 C, and C/2, C= C/8
	ld hl,screen	; BC now B*32+ INT (C/8), now we need start of screen too
	add hl,bc		; HL now screenaddress
	ret

;-------------------------------------------------------------------
; some lowres, HR must start AFTER #403F, but before #4070      

hr  LD   HL,lowres+#8000   	; the lowres display          
    LD   BC,#211            ; 1 line lowres text          
    LD   A,#1E  
    LD   I,A    
    LD   A,#Fb  
    CALL #2B5       ; show lowres screen          
 
    LD   B,11	    ; match hires display with lowres
hr00    DJNZ hr00   

	ld hl,screen-32	; start of hiresscreen (must be NNX0) where X = 0 2 4 8 A C E
	ld de,32		; screen line length  

;-------------------------------------------------------------------
; the hr part          

	ld b,176		; display 176 lines
hr1	add hl,de		; next line
	ld a,h			; preset first line to show
	ld i,a			; set highbyte of display (always the same)
	call lbuf+#8000
	
	dec b
	jp nz,hr1

; fixed end of HR-routine
exit	CALL #292   ; back from intrupt           	
	CALL #220   
	LD   IX,hr  
	JP   #2A4   

lbuf	ld a,l
	ld r,a
	block 32,0
	ret nc

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

lowres	db 118
	db "T"+101,"E"+101,"S"+101,"T"+101,0,"W"+101,"I"+101,"T"+101
	db "H"+101,0,"U"+101,"D"+101,"G"+101
	db 118

mycoord1 db 128,92	; middle of the screen
mycoord2 db 128,74

myudg1
	db %00011000,0
	db %00101100,0
	db %00111100,0
	db %00011000,0
	db %00111100,0
	db %00101100,0
	db %01011110,0
	db %01111110,0
	
myudg2
	db %11111111,0
	db %10000001,0
	db %10000001,0
	db %10000001,0
	db %10000001,0
	db %10000001,0
	db %10000001,0
	db %11111111,0

vars	db 128
last	equ $

screen equ #6000	; somewhere far away in memory 
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Single pixel motion in high res?

Post by dr beep »

first glance in a minute... ld a,l add a,32 ld l,a
ChrisB
Posts: 31
Joined: Tue Dec 17, 2024 8:53 am
Location: France

Re: Single pixel motion in high res?

Post by ChrisB »

That's not working when replacing 31 with 32.
I think the problem is when alternating the two displays, the screen is flickering badly between the 2 UDGs.
demo001.p
(312 Bytes) Downloaded 26 times
Post Reply