## Pi-Tube Atom VDU: circles

discussion of games, software, hardware & emulators relating to the Acorn Atom
roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Pi-Tube Atom VDU: circles

I have been playing to draw circles with the Pi-Tube. I added the Bresenham algorithm to the framebuffer.c file:

Code: Select all

`void fb_draw_circle(int xc, int yc, int r, unsigned int colour) {   int x=0;   int y=r;   int p=3-(2*r);   fb_putpixel(xc+x,yc-y,colour);   for(x=0;x<=y;x++)   {       if (p<0)           {           p+=4*x+6;           }       else           {           y--;           p+=4*(x-y)+10;           }      fb_putpixel(xc+x,yc-y,colour);      fb_putpixel(xc-x,yc-y,colour);      fb_putpixel(xc+x,yc+y,colour);      fb_putpixel(xc-x,yc+y,colour);      fb_putpixel(xc+y,yc-x,colour);      fb_putpixel(xc-y,yc-x,colour);      fb_putpixel(xc+y,yc+x,colour);      fb_putpixel(xc-y,yc+x,colour);    }}`

and I assigned PLOT modes 88 to 95 for drawing a circle:

Code: Select all

`            } else if (g_mode >= 88 && g_mode < 96) {               // Draw a circle               fb_draw_circle(g_x_pos_last1, g_y_pos_last1, g_x_pos, col);            }`

Which means I have to move to the origin of the circle and then PLOT 93,R,R where R is the radius (only the x-coordinate is used, the y is ignored).

When I run a small test program to draw 16 circles I get this result:

I can't figure out why the distance between the circles is not linear. Any clues?
Attachments
framebuffer.txt
256K + 6502 Inside
MAN WOMAN

ctr
Posts: 107
Joined: Wed Jul 16, 2014 2:53 pm
Contact:

### Re: Pi-Tube Atom VDU: cirles

I'm not sure exactly what you're running this on, and this is a bit of a stretch, but I think you might have a problem with bit 5 (value 32) in a connector somewhere.

The intended radii of the circles in hex:

Good: 14,28,3C,50,8C,C8,DC,104,118,12C

The bad ones are drawn at:

Note that the radius of each bad circle has bit 5 set, and it is drawn at the radius with bit 5 clear. Some of the good circles also have bit 5 set in the radius, so the problem appears to be intermittent. Of course, I'm getting this from the picture so I can't be sure the bad radii are exactly right, but it's all a pretty good fit.

jgharston
Posts: 2903
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

### Re: Pi-Tube Atom VDU: cirles

roland wrote:and I assigned PLOT modes 88 to 95 for drawing a circle:

No! You can't just "assign" plot numbers. 88-95 are "Fill to background". Circles are 144-183. wiki, link.

Code: Select all

`\$ bbcbasicPDP11 BBC BASIC IV Version 0.25(C) Copyright J.G.Harston 1989,2005-2015>_`

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: cirles

jgharston wrote:No! You can't just "assign" plot numbers.

O yes, I can. In fact, I already did

I wasn't aware of your list of plot codes but I'm glad there is. I will adjust my software to match the standard plot codes. Thanks for your feedback.

I will also check the bit 5 thing but I can't imagine it's a hardware fault because the Pi Zero wouldn't execute commands from the Atom or act like a 6502 co-pro.
256K + 6502 Inside
MAN WOMAN

IanS
Posts: 504
Joined: Mon Aug 31, 2009 6:02 pm
Contact:

### Re: Pi-Tube Atom VDU: cirles

roland wrote:I can't figure out why the distance between the circles is not linear. Any clues?

Do the circles get drawn in the right order, are any drawn our of sequence because a value is overflowing?

At least one will be drawn in black, so not visible. If you draw them all in the same colour, does it look any better?

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: cirles

IanS wrote:At least one will be drawn in black, so not visible. If you draw them all in the same colour, does it look any better?

No, if they are all in the same colour then the picture is the same.
256K + 6502 Inside
MAN WOMAN

ctr
Posts: 107
Joined: Wed Jul 16, 2014 2:53 pm
Contact:

### Re: Pi-Tube Atom VDU: cirles

roland wrote:No, if they are all in the same colour then the picture is the same.

Do you get exactly the same picture every time you draw it in colour? What happens if you plot points (PLOT69) instead of circles? Are they equally spaced?

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: cirles

Good point to test that. I'll try with points and lines in the next few days.
256K + 6502 Inside
MAN WOMAN

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: cirles

I have made a small test program for drawing lines and that show similar faults. Those can also be related to bit 5 and perhaps also timing problems in the communication between the Atom and the Pi Zero. You can watch a low quality movie at https://youtu.be/vuL4M8_lj7Q
256K + 6502 Inside
MAN WOMAN

hoglet
Posts: 6843
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

### Re: Pi-Tube Atom VDU: cirles

That's not good

What speed are you running the Atom at?

Does changing the clock jumper on the Atom Tube interface make any difference?

Which Pi model are you using and how fast is it being clocked?

PiTubeDirect has moved on quite a bit, but in a way that's possibly now incompatible with the work on the atom_vdu branch. Specifically, the latest PiTubeDirect takes over the GPU for and uses it for Tube emulation, which makes it much more robust. With this version, using the GPU for triangle drawing would no longer be possible. What I'm not sure about is whether we could still make use of a simple frame buffer.

As you are working on this again, I might do some experiments over the weekend with adding the frame buffer code back in to the latest version.

Dave

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: cirles

I enabled the frame buffer debugging and I see this in the serial console:

Code: Select all

`move 20,0      => plot 4 20 0                                                                     draw 20,1024   => plot 5 20 1024                                                                  move 40,0      => plot 4 40 0                                                                     move 40,1024   => plot 5 40 1024                                                                  move 60,0      => plot 4 60 0                                                                     move 60,1024   => plot 5 60 1024                                                                  move 80,0      => plot 4 80 0                                                                     move 80,1024   => plot 5 80 1024                                                                  move 100,0     => plot 5 68 0                                                                     move 100,1024  => plot 4 68 1024                                                                  `

100 decimal is 01100100
68 decimal is 01000100

which proves ctr's conclusion that bit 5 is faulty.

My Atom is running at 1 MHz. The Pi Zero is running at 1GHz:

Code: Select all

`#uncomment to overclock the arm. 700 MHz is the default.arm_freq=1000core_freq=400force_turbo=1disable_pvt=1`

Changing the clock jumper doesn't change this behaviour. I'm still using the "Bolton 2016" version of the source code, so the new features cannot cause any problems.

I added some more printf statements and I found out that in normal Atom mode bit 5 was not reset. But in BBC Basic it does. Then I saw the The VDU drives masks bit 5 to avoid the inverted characters. And that is also killing my plot statements. So now I have the find out how to disable that bit 5 mask. But that's something for another day
256K + 6502 Inside
MAN WOMAN

hoglet
Posts: 6843
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

### Re: Pi-Tube Atom VDU: cirles

Are you running BBC Basic on the PiTubeDirect 6502 Co Pro?

If so, then possibly the issue is here:
https://github.com/hoglet67/AtomTubeHos ... .asm#L1295

If you use VGA80 on the Atom host side, then the masking gets skipped.

Dave

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: cirles

Yes, I'm running BBC basic on the copro. Running in VGA80 mode requires a little mod because this vdu doesn't send all screen data to the Pi.

So I hacked the TUBE client and forced the GodilFlag always to be 0x80. That fixes the problem ... however you should have DEBUG_VDU off otherwise the Pi cannot keep up with the Atom.

Sorry JGH, I didn't change the plot codes yet
256K + 6502 Inside
MAN WOMAN

hoglet
Posts: 6843
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

### Re: Pi-Tube Atom VDU: cirles

Great you have this working properly now.
hoglet wrote:As you are working on this again, I might do some experiments over the weekend with adding the frame buffer code back in to the latest version.

I've just hacked the "atom_vdu" frame buffer code into the latest build of PiTubeDirect, and it still works! So I would like to find a way to include this functionality in the next-but-one PiTubeDirect release (called Diamondback).

But there are a couple of things we might need to re-think:

1. Using the GPU for drawing will no longer be possible. This is because running the tube emulation is now it's full-time job. But as you have found, writing graphics primitives is fun, so this is an opportunity not a problem.

2. Using address line A3 and mapping the new VDU FIFO to &FEF8/&FEF9 is not now possible. This is because of the way the ARM core and the GPU are communicating via a 8-byte block of shared IO registers. It isn't possible to expand this to 16-bytes, because there isn't a "spare" area of IO registers this large. We can however make use of &FEF2 and &FEF4 to implement the VDU FIFO, but we need to find a way to make the two VDU FIFO status bits visible to the tube host.

Dave

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: cirles

Personally I prefer the graphics over the copro for the Atom. I can attach the matchbox for copro stuff and the Pi for graphics.

So maybe we should have to versions of the Pi copro ... ?
256K + 6502 Inside
MAN WOMAN

dp11
Posts: 725
Joined: Sun Aug 12, 2012 8:47 pm
Contact:

### Re: Pi-Tube Atom VDU: cirles

Do we actually need FIFO status bits ? The quickest the atom can send bytes is every few uS . So the pi should have plenty of cycles. This I'm assuming will go into the new tube command execute handler which ends up running at fiq level.

hoglet
Posts: 6843
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

### Re: Pi-Tube Atom VDU: cirles

roland wrote:Personally I prefer the graphics over the copro for the Atom. I can attach the matchbox for copro stuff and the Pi for graphics.

So maybe we should have to versions of the Pi copro ... ?

If you are want to keep using (and building on) the version in the atom_vdu branch, that's also fine by me.

It's just this version is no longer being maintained, and is probably not going to be very reliable on the Atom at 2MHz.
dp11 wrote:Do we actually need FIFO status bits ? The quickest the atom can send bytes is every few uS . So the pi should have plenty of cycles. This I'm assuming will go into the new tube command execute handler which ends up running at fiq level.

Certain VDU commands (such as circle drawing, triangle filling) can be generated by the Atom faster than they can be executed on the Pi. Even if buffered, that buffer could eventually fill up.

To be honest, I haven't thought through how this might work in the new architecture. I certainly don't want to be doing the drawing from FIQ context, which is how it's currently working.

One option is a new "Co Pro" that does nothing but processes VDU commands.

But I do still like the idea of the VDU being in addition to the existing Co Processors, possibly by using one of the other exception contexts.

Dave

BigEd
Posts: 1585
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

### Re: Pi-Tube Atom VDU: circles

Can we run two threads, one on each of the two GPU cores in the Pi?? Or do I misunderstand? (One thread for Tube, one for VDU.)

hoglet
Posts: 6843
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

### Re: Pi-Tube Atom VDU: circles

BigEd wrote:Can we run two threads, one on each of the two GPU cores in the Pi?? Or do I misunderstand? (One thread for Tube, one for VDU.)

I don't believe we know how to execute code on the second GPU core (if is even exists).

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: circles

And I don't believe the Pi Zero has that many cores, has it?
256K + 6502 Inside
MAN WOMAN

hoglet
Posts: 6843
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

### Re: Pi-Tube Atom VDU: circles

roland wrote:And I don't believe the Pi Zero has that many cores, has it?

Surprisingly, there is some evidence that the non-ARM processor that is part of the GPU is actually dual core on all Pi models.

https://github.com/hermanhermitage/vide ... 5-Overview

Scalar/Vector Processor (VPU)
- Dual Core VideoCore IV® Multimedia Co-Processor

Some more "discussion" here:

This page seems to suggest it's "dual issue" rather than "dual core":
https://github.com/hermanhermitage/vide ... iderations

Dave

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: circles

That' a bit too technical for me I'll stick to drawing simple graphics like these:

The next step will be some area filling. But first I'll read some documentation how that is exactly implemented on other Acorn systems. And the ellipse is a nice challenge too.
256K + 6502 Inside
MAN WOMAN

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: circles

Three new primitives:
• Ellipse outline (axis-aligned)
• Ellipse filled (axis-aligned)
• Parallelogram filled

256K + 6502 Inside
MAN WOMAN

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: circles

And another feature: horizontal fill to right until background colour:

This is fun to write
256K + 6502 Inside
MAN WOMAN

roland
Posts: 2856
Joined: Thu Aug 29, 2013 8:29 pm
Location: Born (NL)
Contact:

### Re: Pi-Tube Atom VDU: circles

Inspired by the Easter eggs that we ate today I taught my Atom and Pi to draw one:

This is done with PLOT 77, horizontal line fill until none-background pixel found.
256K + 6502 Inside
MAN WOMAN

### Who is online

Users browsing this forum: Bing [Bot] and 5 guests