Can we get source code to TESTSPR2?

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

dave18
Posts: 86
Joined: Tue May 30, 2017 1:06 am
Location: Bristol, UK

Re: Can we get source code to TESTSPR2?

Post by dave18 » Sun Jun 04, 2017 11:11 am

hmmm, I can't seem to get this to work under ZEsarUX. My code is pretty straightforward

Code: Select all

    org $8000

    ld bc,$303b
    ld a,0
    out (c),a   ;Select sprite/pattern #0
    
    ld bc,$0055 	;output bytes port 55 
    ld hl, Sprite1	;from source Sprite1
  
    ld d,0      ;256 bytes to copy
loop
    ld a,(hl)
    out (c),a
    inc hl    
    dec d
    jp nz,loop
        
    ld bc,$0057
    ld a,32
    out (c),a    ;X position is 32
    out (c),a    ;Y position is 32
    ld a,0
    out (c),a    ;no palette offset and no rotate and mirrors flags      
    ld a,128
    out (c),a    ;Sprite visible and show pattern #0
    
    ld bc,$243b
    ld a,21
    out (c),a    ;Select register #21
    
    ld bc,$253b
    ld a,3
    out (c),a     ;All sprites visible (over border)  
    
    ret

Sprite1:
	db  $E3, $E3, $E3, $E3, $E3, $E3, $E3, $FD, $E3, $E3, $E3, $E3, $E3, $E3, $E3, $E3
	db  $E3, $E3, $E3, $E3, $E3, $E3, $FD, $FD, $FD, $E3, $E3, $E3, $E3, $E3, $E3, $E3
	db  $E3, $E3, $E3, $E3, $3C, $3C, $3C, $3C, $3C, $FD, $FD, $FD, $FD, $E3, $E3, $E3
	db  $E3, $E3, $E3, $3C, $3C, $3C, $3C, $3C, $3C, $3C, $FD, $FD, $E3, $E3, $E3, $E3
	db  $E3, $E3, $3D, $FF, $3D, $FF, $FF, $3C, $3C, $3C, $3C, $E3, $E3, $E3, $E3, $E3
	db  $E3, $E3, $FF, $00, $3D, $00, $FF, $FF, $3C, $3C, $3C, $FD, $FD, $FD, $E3, $E3
	db  $E3, $E3, $FF, $00, $3D, $00, $FF, $FF, $3C, $3C, $3C, $3C, $FD, $E3, $E3, $E3
	db  $E3, $3D, $FF, $00, $3D, $00, $FF, $FF, $FD, $FD, $3C, $3C, $E3, $E3, $E3, $E3
	db  $E3, $FD, $FF, $00, $3D, $00, $FF, $FF, $FD, $FD, $FD, $3C, $FD, $FD, $E3, $E3
	db  $E3, $3D, $3D, $FF, $3D, $FF, $FF, $3C, $FD, $00, $3D, $3C, $FD, $E3, $E3, $E3
	db  $E3, $E3, $00, $00, $FF, $00, $00, $00, $00, $3D, $E2, $3D, $E3, $E3, $E3, $E3
	db  $E3, $E3, $3D, $3D, $3D, $3D, $3D, $3D, $3D, $E2, $E2, $E2, $3D, $E3, $E3, $E3
	db  $E3, $E3, $E3, $FF, $FF, $FF, $FF, $3D, $3D, $E2, $E2, $E2, $3D, $E3, $E3, $E3
	db  $E3, $E3, $FF, $FF, $FF, $FF, $FF, $FF, $3D, $3D, $E2, $E2, $3D, $FD, $E3, $E3
	db  $E3, $E3, $FF, $FF, $FF, $FF, $E2, $E2, $E2, $3D, $3D, $3D, $3D, $3D, $FD, $E3
	db  $E2, $E2, $E2, $FF, $FF, $E2, $E2, $E2, $E2, $E2, $3D, $3D, $3D, $3D, $3D, $3C

but no sprite is displayed. It is definitely copying the sprite data ok as if I run .testspr2 my image bounces across the screen.

The display code doesn't vary much from what SavourySnaX uses so I am at a loss.

Any help much appreciated.

Dave

User avatar
chernandezba
Posts: 229
Joined: Mon May 29, 2017 8:14 pm

Re: Can we get source code to TESTSPR2?

Post by chernandezba » Sun Jun 04, 2017 11:31 am


Is there a sprite pattern viewer in zesarux? I could find a "sprite viewer" but it seems to display from a RAM address which presumably the Next sprites would not have.
Last source code has a Next sprite viewer ;)
----

ZEsarUX
ZX Second-Emulator And Released for UniX
https://github.com/chernandezba/zesarux

dave18
Posts: 86
Joined: Tue May 30, 2017 1:06 am
Location: Bristol, UK

Re: Can we get source code to TESTSPR2?

Post by dave18 » Sun Jun 04, 2017 12:05 pm

Further strange behaviour.

If I run .testspr2 after running my code so my sprite does actually appear and then break into the program (sprite still showing) and then type the following

out 12347,0 - select my sprite 0
out 87,32 - as expected x position changes to next to lefthand border
out 87,32 - as expected y position changes to under top border - sprite is now in top left of screen
out 87,0 - sprite disappears - but this write shouldn't affect visibility
out 87,128 - who knows what effect this is having but it does not make sprite reappear

According to the docs the third write to port 87 (0x57) should have the following effect:
3rd: bits 7-4 is palette offset, bit 3 is X mirror, bit 2 is Y mirror, bit 1 is rotate flag and bit 0 is X MSB.

So is it a bug in emulation that is causing the sprite to disappear or is it a feature of the sprite system that I am failing to understand.

Thanks

Dave

cmonkey
Posts: 2
Joined: Tue May 30, 2017 8:36 am

Re: Can we get source code to TESTSPR2?

Post by cmonkey » Sun Jun 04, 2017 12:27 pm

This source assembles, using Pasmo, to be a bitwise identical binary to the TESTSPR2 demo built by (presumably?) Jim. Have fun...

Code: Select all

; reversed source of testspr2
; assemble with: pasmo --bin testspr2.asm testspr2

				org		$2000

				ld		bc, $243B				; $243b = FPGA register select
				ld		a, 21					; 21 = sprite system
				out		(c), a					; select the sprite system
				ld		bc, $253B				; $253b = FPGA register write
				ld		a, 3 					; display sprites over border (bit 1) and sprites visible (bit 0)
				out		(c), a					; write the value to port $253b

				ld		hl, spriteData				; point HL at the sprite data structure storage
				ld		b, 64					; 64 sprites to process
				ld		de, 0	    				; point DE at first byte of the ROM


; init all 64 sprites by using the Z80 refresh register to create the initial x/y positions and velocities
initLoop:			push		bc					; save the loop counter
				halt							; wait for vblank

; randomize initial sprite x-pos (spriteData+0)
				ld		a, r					; refresh register into C
				ld		c, a
				ld		a, (de)					; get a byte from ROM
				inc		de					; increment the ROM pointer
				xor		c					; XOR the ROM byte with the refresh register
				xor		l					; XOR that with L (L holds low byte of pointer to sprite data structures)
				and		63					; clear upper 2 bits of A (leaving a value from 0-63 in A)
				add		a, 24					; add 24 to A (initial x-pos will be between 24 and 87)
				ld 		(hl), a					; store sprite x-pos in the data structure
				inc		hl					; increment sprite data structure pointer
				ld		b, a					; A into B
eat1:				djnz		eat1					; eat some CPU cycles to further randomize the R register

; randomize initial sprite y-pos (spriteData+1)
				ld		a, r					; refresh register into C
				ld		c, a
				ld		a, (de)					; get a byte from ROM
				inc		de					; increment the ROM pointer
				xor		c					; XOR the ROM byte with the refresh register
				xor		l					; XOR that with L (L holds low byte of pointer to sprite data structures)
				and		127					; clear upper bit of A (leaving a value from 0-127 in A)
				add		a, 24					; add 24 to A (initial y-pos will be between 24 and 151)
				ld		(hl), a					; store sprite y-pos in the data structure
				inc		hl					; increment sprite data structure pointer
				
; sprite visibility (spriteData+2) ** THIS BYTE OF THE DATA STRUCTURE IS UNUSED BY THE SPRITE DEMO **
				ld		(hl), 1					; make this sprite visible

; ??? (spriteData+3) ** THIS BYTE OF THE DATA STRUCTURE IS UNUSED BY THE SPRITE DEMO, NOT SURE WHAT IT'S PURPOSE WAS SUPPOSED TO BE **
				inc		hl					; increment sprite data structure pointer
				pop		bc					; restore the previously saved loop counter value
				push		bc					; and save it again
				push		af					; save A
				ld		a, b					; loop counter into A
				and		15					; clear upper nibble of A
				add		a,a					; A = A * 16
				add		a,a
				add		a,a
				add		a,a
				inc		a					; increment A
				ld		(hl), a					; store in sprite data structure
				pop		af					; restore A
				inc		hl					; increment sprite data structure pointer
				ld		b, a					; A into B
eat2:				djnz		eat2					; eat some CPU cycles

; randomize x velocity (spriteData+4) 
				ld		a, r					; refresh register into A
				and		7					; clear upper 5 bits of A (leaving a value from 0-7 in A)
				sub		4					; subtract 4 from A (x velocity can be either -ve, +ve or 0)
				ld		(hl), a					; store in data structure
				inc		hl					; increment sprite data structure pointer
				ld		b, a					; A into B
eat3:				djnz		eat3					; eat some CPU cycles

; randomize y velocity (spriteData+5)
				ld		a, r					; refresh register into A
				and		7					; clear upper 5 bits of A
				sub		4					; subtract 4 from A (y velocity can be either -ve, +ve or 0)
				ld		(hl), a					; store in the data structure
				inc		hl					; increment sprite data structure pointer
	
				pop		bc					; restore the loop counter
				djnz		initLoop	 			; loop for 64 sprites




; main loop of the sprite demo
loop:				halt							; wait for vblank				
				ld		bc, $303B				; FPGA sprite config port
				xor		a					; clear A
				out		(c), a					; init the address of the sprite palette
				ld		h, 64					; 64 sprites to process
				ld		de, 6	    				; 6 bytes per sprite data structure
				ld		ix, spriteData				; point IX at the sprite data structures
				ld		bc, $57 				; FPGA sprite attributes port

; do x-pos
nextSprite:			ld		a, (ix+0)				; get sprite x-pos from the data structure
				add		a, (ix+4)				; add x-velocity
				ld		(ix+0), a				; store new x-pos back to the sprite data structure
				cp		8					; compare new x-pos with a value of 8
				jr		c, invertX				; jump if less than 8
				cp		132					; compare new y-pos with a value of 132
				jr		c, yPos					; jump if less than 132
invertX:			ld		a, (ix+4)				; get x-velocity
				cpl							; invert (one's complement)
				inc		a					; increment
				ld		(ix+4), a				; store back

; do y-pos
yPos:				ld		a, (ix+1)				; get sprite y-pos from the data structure
				add		a, (ix+5)				; add y-velocity
				ld		(ix+1), a				; store new y-pos back to the sprite data structure
				cp		8					; compare new y-pos with a value of 8
				jr		c, invertY				; jump if less than 8
				cp		168					; compare new y-pos with a value of 168
				jr		c, writeSprData				; jump if less than 168
invertY:			ld		a, (ix+5)				; get y-velocity
				cpl							; invert (one's complement)
				inc		a					; increment
				ld		(ix+5), a				; store back

; write the data to the sprite chip
writeSprData:			ld		a,(ix+0)				; get current x-pos for this sprite from the data structure
				add		a, a					; double it (if result > 255 then carry flag (x-msb) will be set)
				out		(c), a					; output to port $57
				ld		a, (ix+1)				; get current y-pos for this sprite from the data structure
				out		(c), a					; output to port $57
				ld		a, 2					; A = 2 (bit 1 = sprite visible flag) ** THIS IS FOR THE OLD SPRITE SPEC **
											;										** USE LD A,0 FOR UPDATED SPRITE SPEC **
				adc		a, 0 					; add zero and carry flag (from add a,a above) to A (carry flag = x-msb)
				out		(c), a					; output to port $57 (sprite visible flag and sprite x-msb) ** JUST SPRITE X-MSB USING UPDATED SPEC
				ld		a, 64					; A = 64 ** THIS IS FOR USE WITH THE OLD SPRITE SPEC ** USE LD A, 192 FOR UPDATED SPRITE SPEC
				sub		h					; subtract loop counter from A
				out		(c), a					; output to port $57 (just sprite number for old spec, visible and sprite number for new spec)
				add		ix, de					; add 6 to IX to point it to next sprite data structure
				dec		h					; decrement the loop counter
				jr		nz, nextSprite				; loop if we haven't processed all 64 sprites yet

				ld		a, 127					; check for space bar being pressed to end the demo
				in		a, (254)
				rra
				jp		c, loop					; back to the top of the loop if not pressed

				xor  		a					; else back to BASIC
				ret

spriteData:			ds		384					; storage for 64 x 6 byte sprite data structures (even though only 4 bytes per structure are actually used)

User avatar
chernandezba
Posts: 229
Joined: Mon May 29, 2017 8:14 pm

Re: Can we get source code to TESTSPR2?

Post by chernandezba » Sun Jun 04, 2017 12:52 pm

It's not a bug on ZEsarUX. Last beta binary version follows previous sprite spec, where visible bit was on third byte
Use the previous specs or compile the last source code, where the specs are up to date.
Or wait for next beta ;)

Cheers
----

ZEsarUX
ZX Second-Emulator And Released for UniX
https://github.com/chernandezba/zesarux

dave18
Posts: 86
Joined: Tue May 30, 2017 1:06 am
Location: Bristol, UK

Re: Can we get source code to TESTSPR2?

Post by dave18 » Sun Jun 04, 2017 12:57 pm

Ah, thanks cmonkey, that gives the answer to my issue

Code: Select all

				ld		a, 2					; A = 2 (bit 1 = sprite visible flag) ** THIS IS FOR THE OLD SPRITE SPEC **
											;										** USE LD A,0 FOR UPDATED SPRITE SPEC **
It seems ZEsarUX is emulating the old sprite spec, setting bit 1 on the third write to $57 fixes my disappearing sprite but obviously the code will be wrong in the long run.

Dave

dave18
Posts: 86
Joined: Tue May 30, 2017 1:06 am
Location: Bristol, UK

Re: Can we get source code to TESTSPR2?

Post by dave18 » Sun Jun 04, 2017 12:59 pm

@chernandezba

Thanks, I'd just worked that out from the testspr2 source and we crossed posts.

Thanks for an excellent emulator with such frequent updates.

Dave

SavourySnaX
Posts: 17
Joined: Mon May 29, 2017 7:31 pm

Re: Can we get source code to TESTSPR2?

Post by SavourySnaX » Sun Jun 04, 2017 12:59 pm

Yeah, sorry my code was based on the latest source version of ZEsarUX, not the beta. I`ll update the post to make that clear.

User avatar
chernandezba
Posts: 229
Joined: Mon May 29, 2017 8:14 pm

Re: Can we get source code to TESTSPR2?

Post by chernandezba » Sun Jun 04, 2017 2:13 pm

dave18 wrote:
Sun Jun 04, 2017 12:59 pm
@chernandezba

Thanks, I'd just worked that out from the testspr2 source and we crossed posts.

Thanks for an excellent emulator with such frequent updates.

Dave
You're welcome!
----

ZEsarUX
ZX Second-Emulator And Released for UniX
https://github.com/chernandezba/zesarux

robpearmain
Posts: 62
Joined: Tue May 30, 2017 5:35 pm
Location: York
Contact:

Re: Can we get source code to TESTSPR2?

Post by robpearmain » Sun Jun 04, 2017 2:36 pm

Thanks for all of your feedback on my request, much appreciated.

Thanks to the ZEsarUX emulator, things are moving along rapidly, can't wait to see what games/demos are available come August
Rob Pearmain
Bipboi (Zx Spectrum 48k), Harry Hedgehog (ZX Spectrum [1K]), Luna C (PC), Turbotoons (PC)

ZX Spectrum 48k, +, 128k, Next (board)

Post Reply