Can we get source code to TESTSPR2?

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

Moderator: Programming Moderators

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

Can we get source code to TESTSPR2?

Post by robpearmain » Sat Jun 03, 2017 3:52 pm

Hi

Just got ZEsarUX up and running with the excellent new video tutorial (See main website).

Would it be possible to see the source code of the testspr2 program?
Rob Pearmain
Bipboi (Zx Spectrum 48k), Harry Hedgehog (ZX Spectrum [1K]), Luna C (PC), Turbotoons (PC)

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

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

Re: Can we get source code to TESTSPR2?

Post by chernandezba » Sat Jun 03, 2017 4:37 pm

Well, looking at the basic program you probably can understand how it works, it's very simple

https://sourceforge.net/p/zesarux/code/ ... sprite.tap

It follows the specs:
http://www.specnext.com/sprites/

And probably you can ask Jim Bagley for the source code... even more, the binary is just 585 bytes length, it's easy to do a full disassembly:

2000 LD BC,243B
2003 LD A,15
2005 OUT (C),A
2007 LD BC,253B
200A LD A,03
200C OUT (C),A
200E LD HL,20C9
2011 LD B,40
2013 LD DE,0000
2016 PUSH BC
2017 HALT
2018 LD A,R
201A LD C,A
201B LD A,(DE)
201C INC DE
201D XOR C
201E XOR L
201F AND 3F
2021 ADD A,18
2023 LD (HL),A
2024 INC HL
2025 LD B,A
2026 DJNZ 2026
2028 LD A,R
202A LD C,A
202B LD A,(DE)
202C INC DE
202D XOR C
202E XOR L
202F AND 7F
2031 ADD A,18
2033 LD (HL),A
2034 INC HL
2035 LD (HL),01
2037 INC HL
2038 POP BC
2039 PUSH BC
203A PUSH AF
203B LD A,B
203C AND 0F
203E ADD A,A
203F ADD A,A
2040 ADD A,A
2041 ADD A,A
2042 INC A
2043 LD (HL),A
2044 POP AF
2045 INC HL
2046 LD B,A
2047 DJNZ 2047
2049 LD A,R
204B AND 07
204D SUB 04
204F LD (HL),A
2050 INC HL
2051 LD B,A
2052 DJNZ 2052
2054 LD A,R
2056 AND 07
2058 SUB 04
205A LD (HL),A
205B INC HL
205C POP BC
205D DJNZ 2016
205F HALT
2060 LD BC,303B
2063 XOR A
2064 OUT (C),A
2066 LD H,40
2068 LD DE,0006
206B LD IX,20C9
206F LD BC,0057
2072 LD A,(IX+00)
2075 ADD A,(IX+04)
2078 LD (IX+00),A
207B CP 08
207D JR C,2083
207F CP 84
2081 JR C,208B
2083 LD A,(IX+04)
2086 CPL
2087 INC A
2088 LD (IX+04),A
208B LD A,(IX+01)
208E ADD A,(IX+05)
2091 LD (IX+01),A
2094 CP 08
2096 JR C,209C
2098 CP A8
209A JR C,20A4
209C LD A,(IX+05)
209F CPL
20A0 INC A
20A1 LD (IX+05),A
20A4 LD A,(IX+00)
20A7 ADD A,A
20A8 OUT (C),A
20AA LD A,(IX+01)
20AD OUT (C),A
20AF LD A,00
20B1 ADC A,00
20B3 OUT (C),A
20B5 LD A,C0
20B7 SUB H
20B8 OUT (C),A
20BA ADD IX,DE
20BC DEC H
20BD JR NZ,2072
20BF LD A,7F
20C1 IN A,(FE)
20C3 RRA
20C4 JP C,205F
20C7 XOR A
20C8 RET
20C9 Internal Data....


I hope this post is not too long ;)
Cheers
----

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 » Sat Jun 03, 2017 4:42 pm

Fantastic, thanks for that. Tested, and confirmed how the clipping works, super smooth.
Rob Pearmain
Bipboi (Zx Spectrum 48k), Harry Hedgehog (ZX Spectrum [1K]), Luna C (PC), Turbotoons (PC)

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

hyphz
Posts: 54
Joined: Wed May 31, 2017 12:15 am

Re: Can we get source code to TESTSPR2?

Post by hyphz » Sat Jun 03, 2017 6:58 pm

So can anyone explain this code a bit more? I couldn't make sense of it, especially things like the DJNZ loops that point to themselves - is that just to create a pause?

I did try writing my own program to set up a sprite but I couldn't get it to do anything. Also, does OTIR sent to port (C), or does it send to port (BC) like "out (C)" does (and thus make itself useless)?

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

Re: Can we get source code to TESTSPR2?

Post by SavourySnaX » Sat Jun 03, 2017 10:19 pm

This isn't a complete answer, but here is code that uploads pattern data to pattern slot 0. Assembled with pasmo, tested with ZEsarUX pattern viewer- it should work on the next. However its not enough to make the sprite visible - I`ll post code to do that later/tomorrow - if there is interest :

Code: Select all

org 32768

; Upload a sprite to pattern 0
; Set pattern register to 0
ld b,$30
ld c,$3B
ld a,0
out (c),a     ; this does OUT (bc),a  so writes 0 to IO Port $303B

ld b,0
ld c,$55      ; set bc to point to IO Port $0055
ld d,0         ; set up a 256 counter (16*16 == 256), starting at 0 we will decrement 256 times
ld hl,spriteData   ; set hl to point at the start of our sprite pattern
lp1:
ld a,(hl)       ; get byte from sprite pattern pointer
out (c),a      ; output byte to $0055  (this will auto increment the internal (Spectrum Next) pointer to the next byte of the sprite
inc hl           ; move to the next byte in our sprite data
dec d           ; decrement our counter (will set Z flag if result is 0, since we start at 0 the first dec will produce 255 in d)
jr nz,lp1       ; loop until we have finished 256 bytes

ret

spriteData:  ; 16*16 bytes (some graphic or other (0xE3 magenta in the default palette)
	db	0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0x00,0x00,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0x00,0x00,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0x00,0x00,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0x00,0x00,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0x00,0x00,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0x00,0xE3,0xE3,0x00,0xE3,0xE3,0x00,0x00,0x00,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3
	db	0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3,0xE3

END 32768

Last edited by SavourySnaX on Sat Jun 03, 2017 10:33 pm, edited 1 time in total.

hyphz
Posts: 54
Joined: Wed May 31, 2017 12:15 am

Re: Can we get source code to TESTSPR2?

Post by hyphz » Sat Jun 03, 2017 10:31 pm

I was trying to upload with

Code: Select all

; Select sprite (pattern?) slot 0
ld bc,p_next_sprite_num
ld a,0
out (c),a

; Upload sprite data
ld b,$0
ld hl,sprite
upload:
ld a,(hl)
out (p_next_sprite_pattern),a
inc hl
djnz upload
But I don't know if it's the upload or the display bit that's the problem. The question about b was just because I was wondering if you could actually do:

Code: Select all

ld hl, sprite
ld b, $0
ld c,p_next_sprite_pattern
otir
But obviously this is no use if B is used for the countdown and in doing so ruins the implicit

Code: Select all

out (c)
that is part of otir.

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.

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

Re: Can we get source code to TESTSPR2?

Post by SavourySnaX » Sat Jun 03, 2017 10:37 pm

Correct, that won't work. From the Zilog Manual :

"The contents of the HL register pair are placed on the address bus to select a location in
memory. The byte contained in this memory location is temporarily stored in the CPU.
Then, after the byte counter (B) is decremented, the contents of Register C are placed on
the bottom half (A0 through A7) of the address bus to select the I/O device at one of 256
possible ports. Register B can be used as a byte counter, and its decremented value is
placed on the top half (A8 through A15) of the address bus at this time
. Next, the byte to
be output is placed on the data bus and written to the selected peripheral device. Then register
pair HL is incremented. If the decremented B Register is not 0, the Program Counter
(PC) is decremented by two and the instruction is repeated. If B has gone to 0, the instruction
is terminated. "

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

Re: Can we get source code to TESTSPR2?

Post by SavourySnaX » Sat Jun 03, 2017 10:41 pm

hyphz wrote:
Sat Jun 03, 2017 10:31 pm
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.
I used the telnet debug command tbblue-get-pattern 0 which dumped the contents, but at least on the latest sources, you can use F5 -> Debug -> View Sprites

Then press H to show the hardware sprites.

hyphz
Posts: 54
Joined: Wed May 31, 2017 12:15 am

Re: Can we get source code to TESTSPR2?

Post by hyphz » Sat Jun 03, 2017 10:48 pm

Bummer. Could the Next get a new opcode to fix that, given the new importance of 16-bit port output?

Edit. Oh, great! You can't even use out with a fixed 8-bit address because if you do it puts the contents of the ****ing accumulator on the upper lines of the bus. What the heck was the point of that supposed to be? :evil:

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 8:18 am

Edit. Oh, great! You can't even use out with a fixed 8-bit address because if you do it puts the contents of the ****ing accumulator on the upper lines of the bus. What the heck was the point of that supposed to be?
Which is why much of the hardware in the past that used the z80 had lazy decoding (or ignored the upper 8 bits) -- Its possible the real Next hardware could do the same for port 0x55 -- e.g. 0x0055,0x0155...0xFE55,0xFF55 all access the same IO location, but I don't know.

Any way, to finish up the code I started last night, If you insert the below code just before the ret statement in my previous code, you will get a sprite on screen - again tested on ZEsarUX.

Code: Select all

; Quick test to get sprite to display
; Set sprite number to 0
ld b,$30
ld c,$3B
ld a,0
out (c),a     ; this does OUT (bc),a  so writes 0 to IO Port $303B

ld c,$57
ld b,0
ld a,128
out (c),a	; X=128
out (c),a	; Y=128
out (c),d	; no offset in palette or flip bits (d is still zero from above loop)
out (c),a	; set sprite visible using pattern 0 (bit 7 is visible bit, rest of bits are pattern number 0-63)

ld bc,$243B
ld a,21
out (c),a	; Set Hardware register 21
inc b		; inc to use $253B
ld a,1		; Set enable all sprites
out (c),a

Edit: originally I wasn't setting 303B to 0 before setting the sprite registers, which meant I was actually updating sprite 1, (looks like the sprite/pattern number register is auto incrementing

Edit2: This is based on the current official sprite documentation, you need to compile latest sources for it to work (not the pre-compiled beta).
Last edited by SavourySnaX on Sun Jun 04, 2017 1:00 pm, edited 1 time in total.

Post Reply