Interrupt with NextBasic ?

The Speccy's spritely young offspring. Discuss everything from FPGA to ZX
Post Reply
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Interrupt with NextBasic ?

Post by funkheld »

How can you please create an independent movement of the graphic : Sprite/Tile/copper with the NextBasic?
Interrupt with NextBasic ?

Thanks
greeting
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Interrupt with NextBasic ?

Post by Alcoholics Anonymous »

It may be helpful to read the "New Commands and Features" documentation here:

https://gitlab.com/thesmog358/tbblue/-/ ... s/nextzxos

Sprite commands start on page 7 and there's something about automatic sprite movement on page 9. This document applies to the very latest NextZXOS 2.7 which is available on that site for download.

The best place to discuss how these things work is probably on the Next Basic facebook group:
https://www.facebook.com/groups/232541547272192

Unfortunately it's facebook and it's private but one can't get away from the fact there is a lot of activity there.

For examples, the basic games by kevman3d on itch.io are a really good source. He's spent his time to document how the games work in some associated pdfs.


The copper is a topic of its own. There is not any direct support in basic for it but it also doesn't need any -- you can easily program it from basic with REG commands. The copper is a very simple co-processor that is synchronized with the display. It only understands a handful of instructions -- wait for a position on the screen, write a value to a nextreg, stop. The key is the writing of a value to nextreg.

Here's a description of the nextreg:

https://gitlab.com/SpectrumNext/ZX_Spec ... extreg.txt

The nextreg is a field of bytes that control the Next's hardware so using the copper requires some understanding of how the hardware works. For example, you can hardware scroll the ula screen by pixel amounts horizontally by writing values to nextreg 38. If you enter "REG 38,10" from basic, your ula screen will be scrolled over by 10 pixels.

In the context of the copper, you can get the copper to scroll the ula using this register at specific points in the display to create effects that require no intervention from the z80 or your basic program. I see some have started a thread here about it and in the facebook group above, matt has done some truly amazing stuff from basic with copper tricks, including smoothly scrolling 3d tunnel.


For tiles, nextbasic does not support the hardware tilemap yet. It does have the concept of tiles for layer 2 however, which is really plotting squares onto the layer 2 pixel bitmap. Info on that is also in the document above.
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Interrupt with NextBasic ?

Post by funkheld »

thanks for the information.
I can already move sprites and copper with reg commands. I would also like to have an independent movement in the repeat loop for an instruction with an interrupt.

greeting
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Interrupt with NextBasic ?

Post by Alcoholics Anonymous »

funkheld wrote: Thu Apr 07, 2022 8:09 am I can already move sprites and copper with reg commands. I would also like to have an independent movement in the repeat loop for an instruction with an interrupt.
I don't know exactly what you mean but there is no way to execute basic commands on interrupt. Basic runs as fast as it can and the best you can do is insert busy waiting to slow down if you want to control the frame rate. If you want interrupt driven, you will have to partake in some assembly language or assembly language via a basic interface ("drivers").

Basic does have the idea of queueing up sprite commands so that it will execute all sprite movements at a particular time, including a time after the video frame is drawn so you get no tearing.

Something can be done with the copper as well... the copper can move sprites itself and you could "poke" in new screen coordinates for sprites into the running copper program. The copper can be set to do these moves outside the video frame so there is, again, no tearing. The copper can write a flag into the user nextreg 127 so you could get the copper program to write values there to indicate when basic can update sprite positions when the copper is not moving sprites around.

I am definitely not the best person to advise on basic though.. for good examples it's the basic games that should be looked at as mentioned. They're doing stuff that looks like m/c games on the original spec.
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Interrupt with NextBasic ?

Post by funkheld »

Thanks for the info.

greeting.
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Interrupt with NextBasic ?

Post by funkheld »

Code: Select all

20 RUN AT 3 
30 LOAD "dksprite.spr" BANK 13
40 SPRITE BANK 13
50 LAYER 2,1: PAPER 2: CLS
55 print BIN 00000101
60 SPRITE PRINT 1
70 SPRITE 1,100,100,25,1
80 SPRITE 2,210,210,3,1
90 SPRITE 3,180,180,22,1
95 proc movesprite()
100 repeat
110   SPRITE MOVE int
120   .........
130   ........
131   ........
132  ..........
140 repeat until 0
150 pause 0
1000 DEFPROC movesprite()
1010 SPRITE CONTINUE 1,50 TO 100 STEP 1 RUN ,50 TO 100 STEP 1 run,25 , BIN 11011101,0
1020 SPRITE CONTINUE 2,210 STOP ,30 TO 210 STEP 1 RUN ,3 to 3, BIN 0100,0
1030 SPRITE CONTINUE 3,100 TO 180 STEP 1 RUN ,100 TO 180 STEP 1 RUN ,22 , BIN 11011101,0
1040 endproc
.................................
100 repeat
110 SPRITE MOVE int
120 .........
130 ........
131 ........
132 ..........
140 repeat until 0
.................................

if there are many calls in the repeat/repeat until 0, the "sprite move int" comes to a standstill.

"sprite move int" should be called independently.
and not from the repeat/repeat until 0 but via an interrupt.
AndyC
Dynamite Dan
Posts: 1409
Joined: Mon Nov 13, 2017 5:12 am

Re: Interrupt with NextBasic ?

Post by AndyC »

Yes, NextBASIC just flat out does not have any options of calling a routine periodically (like AFTER and EVERY on the Amstrad CPC for example).

You have to structure your code such that it doesn't take too long between each call to SPRITE MOVE. Either by interleaving them between other commands periodically or structuring your code such that it loops more often and processes less each time.

Or do it in assembly and use an interrupt routine to handle moving your sprites around.
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Interrupt with NextBasic ?

Post by funkheld »

hello , thanks for the info.

greeting
Post Reply