Newbrain Online 04 – Sprites

Using ChatGPT i sent photos of the Newbrain Online issue 4 about sprites which is written in Dutch and this is the result translation in English:

On the NewBrain, there is no built-in capability to make so-called SPRITES. Sprites are small figures that can be placed anywhere on the screen without affecting the original background. If you place the sprite on a section of text or something else, and then remove it again, the original text or other content is restored. I have written a machine code routine for the NewBrain that allows the creation of sprites on a high-resolution screen. The object code of this machine code program is in DATA lines in the program SPRITE DEMO.

For those who want to disassemble the program, here is a small explanation of the machine code program.

The program is structured as follows: it starts at address 30000 (decimal). First, a section follows where the specified coordinates are converted. It works as follows: the y-coordinate is multiplied by the number of characters per line (40 or 80), and then the x-coordinate is added. After that, we enter the control program. There, the old background is restored, the new background is saved, and the sprite is drawn on the screen via GOR or gXOR. The control section calls a subroutine three times, each time doing something slightly different. The explanation of the machine code above is not necessary if one only uses the routine through the main program. How the routine can be used is explained below.

Before calling the routine, you first need to specify the starting point of the high-resolution screen. This is not a problem with NewBrains that have the PEN(7) function; with other NewBrains, you must first locate the start of the high-resolution screen in a different way. Refer to line 3 (page 25). The value found (mentioned there) must then be POKEd into the program, as follows:

POKE 30500, INT(ST/256):POKE 30501,ST-256*(INT(ST/256))

At address 30502, the number of characters per line must be entered. This is either 40 or 80. At address 30503, the x-value of the sprite must be POKEd. This value can range from 0 to the number of characters per line. At address 30504, the y-value must be entered. This value can range from 0 to the number of lines that make up the high-resolution screen. At address 30505, the value 0 or the value 255 must be POKEd. With a value of 0, the sprite disappears, and with a value of 255, the sprite is drawn on the screen.

At addresses 30506 to 30506 + 63, the sprite itself is stored. These are 64 bytes in the format of 4 by 16 bytes. The sprite is made up of the bits from these bytes. When a part of the sprite is reinserted into memory with a value of 100 (decimal), this results in a section of the sprite appearing as: ..x..xx. (The bytes are displayed from left to right, from the smallest bit to the bit with the largest value: 1, 2, 4, 8, 16, 32, 64, 128.) In the program SPRITE DEMO, an example is shown of a spinning spider coded by the byte lines.

Another address is named, and that is the address where the sprite is inverted or made normal. This is address 30663. With a value of 176 at address 30663, the sprite is displayed in an invisible color, and with a value of 168 at that address, the sprite is displayed in inverse. This, along with other functionalities, is demonstrated by the SPRITE DEMO program, which includes the necessary REM lines.

Included is the program SPRITE PROGRAMMER. With this program, sprites can be easily designed and then converted into numbers. These numbers can then be placed into a DATA line and, like a small program, saved onto tape. While converting the design into numbers, you see the sprite appear in its correct size. It also works without any issues related to PEN(7), if that function is not available.

Designing a sprite using the SPRITE PROGRAMMER works as follows: you see a block of 32 by 16 dots. With the cursor keys, you can move the cursor to the desired location. With one press of the spacebar, the section is colored in, and with another press, it is erased again. Using the ESCAPE key, you can rotate the image, and with the P key, you convert it into a DATA line (first specifying the line number), and later you can save the program on tape so it can be merged into another program.

**OVERVIEW OF POKE ADDRESSES**

Address Name, UsageDefault Value
30000   CALL addressCall routine
30500   PEN(7) high  0 – upper half hi-res address
30501   PEN(7) low   0 – lower half of it 
30502Number of characters per line 40 – can alternate between 40 or 80
30503   X-coordinate  0 – between 0 and PEEK(30502)
30504Y-coordinate0 – between 0 and a number of vertical image lines
30505Draw/Erase 0 – 0 = draw, 255 = erase
30506Sprite 0 – Format: 16 layers of 4 bytes
30663 Normal/Inverse 176 – 176 = normal, 168 = inverse

Below shows how the spider in the SPRITE DEMO program looks and what values are associated with it:

**Address and content:**

| Address | +0 | +1 | +2 | +3 | Bit numbers |

Here is the code not complete yet as chatGPT allows only 4 images per day

10 PUT31:"Even geduld A.U.B."
20 ?"SPRITE door JOHN VAN DER PLOEG "
30 ?"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
40 IF TOP>30000THEN RESERVETOP-30000 :REM geheugen reserveren voor machinetaal
50 REM BINNENLEZEN VAN DE OBJECT-CODE
60 READn
70 FORi=1TO n
80 READa,b,c,d:a=a+256*b:c=c+256*d:IFc=0GOTO 100
90 FORj=aTOa+c-1:READb:POKEj,b:NEXTj
100 NEXTi:READa,b:a=a+256*b
110 INPUT("40 of 80 characters")a:IFa<>40ANDa<>80THENGOTO 110
120 IFa=40 THEN OPEN#0,0,"140":POKE30502,40 :bk=35
130 IFa=80THEN OPEN#0,0,"1140":POKE30502,80 :bk=74
140 PUT31
150 CLOSE#6:OPEN#6,6:X=10:Y=10:GOSUB 430 :CLOSE#11:OPEN#11,11
160 PLOTRNG(41,101),CEN(20,50) :REM teken spinnen-bak
170 PLOTPLA(-20,50),MVE(20,50),MVE(20,-50),MVE(-20,-50),MVE(-20,50)
180 PLOT rng(10,10),cen(5,5),pla(0,0),deg,trn(0),arc(5*PI,360),pla(0,1)
190 PLOTfill,pla(-1,3),mde(3),"TEST TEST"
200 CO=pen(7) :REM pen(7) geeft het beginadres van het Hi-res scherm.
210 POKE30500,(INT(CO/256)):POKE30501,(CO-256*(INT(CO/256)))

Leave a Reply