Using hardware sprites

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

Moderator: Programming Moderators

Post Reply
User avatar
Sludge
Posts: 30
Joined: Wed May 31, 2017 12:37 am
Location: England

Using hardware sprites

Post by Sludge » Fri Sep 28, 2018 11:53 am

What do you do to print a hardware sprite on the next?

I'm currently printing tiles using a routine, how do I replace this with hardware sprites?

I am under the impression the whole hardware sprite thing is just a series of OUT commands, is that right?

seedy1812
Posts: 66
Joined: Tue May 30, 2017 11:31 am

Re: Using hardware sprites

Post by seedy1812 » Fri Sep 28, 2018 1:13 pm

Have a look at Simon Brattel's example
http://www.desdes.com/products/oldfiles ... prites.asm

Alcoholics Anonymous
Posts: 495
Joined: Mon May 29, 2017 7:00 pm

Re: Using hardware sprites

Post by Alcoholics Anonymous » Fri Sep 28, 2018 1:52 pm


User avatar
Sludge
Posts: 30
Joined: Wed May 31, 2017 12:37 am
Location: England

Re: Using hardware sprites

Post by Sludge » Sun Sep 30, 2018 2:10 pm

Thanks guys.

User avatar
emook
Posts: 69
Joined: Mon May 29, 2017 6:55 pm

Re: Using hardware sprites

Post by emook » Sun Sep 30, 2018 7:04 pm

Code: Select all

       ; simple zx next sprite asm demo 
        ; compiled from information on the specnext site and forums
        ; compile with pasmo 
        ; pasmo -v --tapbas --err nextsprite.asm nextsprite.tap

                org 24576

start 

        ;select slot #0
        
                ld a, 0
                ld bc, $303b
                out (c), a

        ;send pattern data

                ld hl,sprite1
                ld bc,$005b
                otir

        ;out 0x57, 32:  x position in 32
        ;out 0x57, 32:  y position in 32
        ;out 0x57, 0:  no palette offset and no rotate and mirrors flags
        ;out 0x57, 130:  sprite visible and show pattern #0

                ld bc, $57
                ld a, 64
                out (c), a                                      ; x pos is 16 bit number, if over 255 msb stored below
                ld a,64
                out (c), a                                      ; y pos

        ; bits 7-4 pallete offset
        ; bit 3 x mirror
        ; bit 2 y mirror
        ; bit 1 rotate
        ; bit 0 x msb
        ; off  xf yf r xmsb
        ; 0000 0  0  0 0

                ld a, 0
                out (c), a
                
        ; pattern and visibility

                ld a, 128

        ; 10000000 = 128
        ; bit 7 visible flag
        ; bit 6 reserved
        ; bits 5-0 pattern index 0-64
        ; v r index
        ; 1 0 000001

                out (c), a

        ;out 0x243b, 21:  select register #21

                ld bc, $243b
                ld a, 21
                out (c), a

        ;out 0x253b, 1:  all sprites visible

                ld bc, $253b
                ld a, 1
                out (c), a

                ret

sprite1:
                db  $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $e3, $e3, $00, $00, $00, $00, $00, $e3, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $e3, $e3, $00, $00, $c8, $c8, $00, $00, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $00, $00, $c8, $c8, $a4, $c8, $c8, $c8, $00, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $00, $00, $a4, $a4, $a4, $a4, $a4, $a4, $c8, $00, $e3, $e3, $e3;
                db  $e3, $e3, $00, $00, $a4, $a4, $a4, $a4, $a4, $00, $a4, $00, $a4, $00, $e3, $e3;
                db  $e3, $e3, $00, $64, $a4, $a4, $a4, $a4, $a4, $a4, $f8, $a4, $a4, $00, $e3, $e3;
                db  $e3, $e3, $00, $64, $a4, $00, $a4, $00, $a4, $a4, $d4, $d4, $f8, $f8, $e3, $e3;
                db  $e3, $e3, $00, $64, $64, $a4, $00, $a4, $a4, $a4, $d4, $a4, $00, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $00, $64, $a4, $64, $64, $64, $64, $a4, $f8, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $00, $00, $64, $64, $64, $64, $00, $00, $00, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $00, $00, $00, $00, $00, $00, $e3, $e3, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $e3, $e3, $00, $fc, $00, $fc, $e3, $e3, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $e3, $e3, $00, $fc, $00, $fc, $e3, $e3, $e3, $e3, $e3, $e3;
                db  $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3, $e3;


---------
ZXorDIE
http://zxbasic.uk/NextBuild NextBuild
http://zxbasic.uk ZXBD Snapshot uploader
http://zxbasic.uk/db/0 ZXBasic Online Database

User avatar
Sludge
Posts: 30
Joined: Wed May 31, 2017 12:37 am
Location: England

Re: Using hardware sprites

Post by Sludge » Mon Oct 01, 2018 7:59 pm

I've assemble that code on ZX Spin and saved it as a z80 snapshot, but cant get it to work on ZEsarUX.

Does ZEsarUX have its own assembler?

Alcoholics Anonymous
Posts: 495
Joined: Mon May 29, 2017 7:00 pm

Re: Using hardware sprites

Post by Alcoholics Anonymous » Mon Oct 01, 2018 10:32 pm

No you should just be able to load the snapshot but as a snapshot the machine will likely crash when it tries to return to basic. So maybe put an infinite loop at the end.

From basic:

SPECTRUM "foo.z80"

or

.run foo.z80

The program is only initializing the first sprite but you should be initializing all of them to be invisible at the very least. The contents of sprite memory can be random at power up and could be something else after another program runs.

namco
Posts: 6
Joined: Sun Aug 13, 2017 7:58 pm

Re: Using hardware sprites

Post by namco » Wed Feb 27, 2019 7:45 am

Sludge wrote:
Mon Oct 01, 2018 7:59 pm
I've assemble that code on ZX Spin and saved it as a z80 snapshot, but cant get it to work on ZEsarUX.

Does ZEsarUX have its own assembler?
This works on ZEsarUX 7.2 but won't display unless you enable Real Video either with the command line switch --realvideo or in Settings > Display and Real Video (ignore Autodetect Real Video).

Post Reply