Boriel's zx basic

If you like transforming your statements into code, this is the place for you

Moderator: Programming Moderators

maniccyberdog
Posts: 14
Joined: Mon May 29, 2017 7:23 pm

Boriel's zx basic

Post by maniccyberdog » Mon Jun 12, 2017 12:55 pm

Hi all,
Anyone working on a ZX Spectrum Next sprite library for Boriel's zx basic? I don't want to reinvent the wheel :D

LCD
Posts: 21
Joined: Tue May 30, 2017 9:03 am

Re: Boriel's zx basic

Post by LCD » Mon Jun 12, 2017 1:45 pm

Had just some thoughts, but not started yet. Need first to fix some problems of BorIDE.

maniccyberdog
Posts: 14
Joined: Mon May 29, 2017 7:23 pm

Re: Boriel's zx basic

Post by maniccyberdog » Wed Jun 14, 2017 1:05 pm

Not perfect, but a start on creating a library for zxb. All feedback welcome, as I'm new to z80 asm!

;##### CODE START ########
ASM
;Global Vars
XH: DEFB 0
XL: DEFB 0
Y: DEFB 0
SPRN: DEFB 0
PTTN: DEFB 0
END ASM


;#### Basic Block of Code #######
cls
NEWPATTERN(5)
for j = 16 to 249
for i = 16 to 303
pause 2
SPRITE(i,j,2,5)
next i
next j
end
;###### End Basic ######


function SPRITE(x as uInteger, y as uByte,spriteNumber as UByte,patternNumber as UByte)
ASM
ld a, (IX+9)
ld (SPRN),a
ld a, (IX+11)
ld (PTTN),a
ld a,(IX+4)
ld (XL),a
ld a,(IX+5)
ld (XH),a
ld a,(IX+7)
ld (Y),a ;X and Y Stored
ld bc,$303b ;Select sprite number
ld a,(SPRN)
out (c),a
ld bc,$0057 ;The four byte load X, Y, Offset, visable
ld a,(XL)
out (c),a ;X (0-7)
ld a,(Y) ;Y
out (c),a
ld a,(XH) ;X (bit 8)
and 1 ;mask
out (c),a
ld a,(PTTN)
or 128 ;Visible 10000000
out (c),a

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)

END ASM
END function

function NEWPATTERN(patternNumber as UByte)
ASM
ld (PTTN),a
ld bc,$303b
ld a,(PTTN)
out (c),a
ld bc,$0055
ld hl,Sprite1
ld d,0

loop:
ld a,(hl)
out (c),a
inc hl
dec d
jp nz,loop
END ASM
END function

ASM

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



END ASM

LCD
Posts: 21
Joined: Tue May 30, 2017 9:03 am

Re: Boriel's zx basic

Post by LCD » Thu Jun 15, 2017 11:30 pm

I had the idea to use OTIR. Something like this (not tested yet):
SUB SetUpSprite (nrOfSprite as ubyte, addressOfSprite as uinteger)
ASM
LD BC,12347
LD A,(IX+5)
Out (C),A
LD H,(IX+7)
LD L,(IX+6)
LD C,85
LD B,255
OTIR
END ASM
END SUB

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

Re: Boriel's zx basic

Post by emook » Sat Jun 17, 2017 9:05 pm

Hi maniccyberdog

I've tried your code but get errors stating PTTN is not define - are these set somewhere else?

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

LCD
Posts: 21
Joined: Tue May 30, 2017 9:03 am

Re: Boriel's zx basic

Post by LCD » Sun Jun 18, 2017 1:25 am

emook wrote:
Sat Jun 17, 2017 9:05 pm
Hi maniccyberdog

I've tried your code but get errors stating PTTN is not define - are these set somewhere else?

Thanks!
The Line

Code: Select all

PTTN: DEFB 0
should define PTTN.

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

Re: Boriel's zx basic

Post by emook » Sun Jun 18, 2017 9:17 am

Ahh missed of the first chuck of code copying!
---------
ZXorDIE
http://zxbasic.uk/NextBuild NextBuild
http://zxbasic.uk ZXBD Snapshot uploader
http://zxbasic.uk/db/0 ZXBasic Online Database

User avatar
boriel
Posts: 10
Joined: Wed Jun 07, 2017 9:10 pm

Re: Boriel's zx basic

Post by boriel » Wed Jun 21, 2017 11:02 am

Boriel here.
If I can be of any help (I don't own a ZXNext and don't know about any emulator), please tell me.

For the radastan mode there is a radastan.bas library already bundled with ZX Basic 1.5.x (work in progress). This library will have a PutSprite, but maybe ZX Next has other graphics mode or hardware things that might be useful for sprites.

Also, if the library is free/open source, I can include your one (e.g. the code above) with ZX Basic if you give me permission. :roll:

maniccyberdog
Posts: 14
Joined: Mon May 29, 2017 7:23 pm

Re: Boriel's zx basic

Post by maniccyberdog » Wed Jun 21, 2017 2:43 pm

Thanks for the offer, due to limited time in my life at the moment- I'll come back to this once I have my next board in August:-)

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

Re: Boriel's zx basic

Post by emook » Wed Jun 21, 2017 11:08 pm

Hi Boriel

Yes the Next has 64 hardware sprites :)
---------
ZXorDIE
http://zxbasic.uk/NextBuild NextBuild
http://zxbasic.uk ZXBD Snapshot uploader
http://zxbasic.uk/db/0 ZXBasic Online Database

Post Reply