6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 5:42 pm

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Thu Jan 11, 2024 5:46 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
A challenge was recently organised on facebook.

The aim was to create a short BASIC program displaying an ASCII code progressively on the screen, following the shape of a spiral which starts at the centre of the screen. The challenge was opened to all computers.

I wrote a code in assembly for the Commodore 64. Whilst writing it, I figured out that it could be used actually on any computer based on the 6502 processor. It just needed some ajustments for the screen memory adresses and # of rows. The final shape of the spiral on the screen is a perfect square (25 x 25 on the Commodore 64, 25 being the # of rows).

It takes around 20,000 cycles. It's based on 4 subroutines (each computing the positions on the left, right, up and bottom) with ADC and SBC running in a loop, and self-modifying code. Nothing exceptional nor fantastic.

While writing it, I thought that a similar challenge could be organised just for the fun of sharing knowlege and practices. Anyone interested?


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 11, 2024 6:10 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Could you show us a sketch of the target shape? (Either as ascii art in CODE tags, or as an attached image)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 11, 2024 6:15 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1399
Location: Scotland
lightbeing wrote:
A challenge was recently organised on facebook.

The aim was to create a short BASIC program displaying an ASCII code progressively on the screen, following the shape of a spiral which starts at the centre of the screen. The challenge was opened to all computers.

I wrote a code in assembly for the Commodore 64. Whilst writing it, I figured out that it could be used actually on any computer based on the 6502 processor. It just needed some ajustments for the screen memory adresses and # of rows. The final shape of the spiral on the screen is a perfect square (25 x 25 on the Commodore 64, 25 being the # of rows).

It takes around 20,000 cycles. It's based on 4 subroutines (each computing the positions on the left, right, up and bottom) with ADC and SBC running in a loop, and self-modifying code. Nothing exceptional nor fantastic.

While writing it, I thought that a similar challenge could be organised just for the fun of sharing knowlege and practices. Anyone interested?


Which group? I can't find it in my usual BASIC groups on FB...

But how can a spiral turn into a square?

Or do you mean like a turtle graphics spiral, turning 90° and increasing the side length by 1 every turn?

Like this, but with ASCII "graphics":

Attachment:
Screenshot_2024-01-11_18-14-40.png
Screenshot_2024-01-11_18-14-40.png [ 10.3 KiB | Viewed 3143 times ]


-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 11, 2024 6:44 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
The FINAL shape of the spiral is a square when the drawing has finished.

But each ASCII output during the drawing on the screen is performed as a rotation (left or right)

Here's how the final shape looks like with 205/206 PETSCII codes.

The facebook group is BASIC language programming:
https://www.facebook.com/groups/2057165187928233

The result of the challenge is here
https://magentacloud.de/s/nEcAdCPDiteLgPp


Attachments:
vice-screen-2024011119332343.png
vice-screen-2024011119332343.png [ 5.82 KiB | Viewed 3135 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 11, 2024 9:11 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
OK, so it's a spiral fill pattern, printing whatever (but the usual diagonal "maze" happens to look good)

By spiral fill I mean something like
Code:
16 15 14 13
 5  4  3 12
 6  1  2 11
 7  8  9 10


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 11, 2024 9:57 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
BigEd wrote:
OK, so it's a spiral fill pattern, printing whatever (but the usual diagonal "maze" happens to look good)

By spiral fill I mean something like
Code:
16 15 14 13
 5  4  3 12
 6  1  2 11
 7  8  9 10


Exactly.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 12, 2024 12:07 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1399
Location: Scotland
I eventually found it on Facebook - dates back to November 2023.

https://www.facebook.com/100009370485120/videos/3745971862283827/

This is Richard Russels entry in BBC Basic:

https://wasm.bbcbasic.net/bbcsdl.html?app=bbcbasic.co.uk%2Fwebapps%2Fcompo4

Code:
10 MODE 1
20 VDU 5,19,1,4,0,0,0
30 GCOL 0,129 : CLG
40 VDU 23,205,&80,&40,&20,&10,&08,&04,&02,&01
50 VDU 23,206,&01,&02,&04,&08,&10,&20,&40,&80
60 X = 608 : Y = 512 : N = 1
70 REPEAT
80 FOR I = 1 TO N : MOVE X,Y : VDU 205.5 + RND(1) : X = X+32 : T = INKEY(1) : NEXT
90 FOR I = 1 TO N : MOVE X,Y : VDU 205.5 + RND(1) : Y = Y+32 : T = INKEY(1) : NEXT
100 N = N+1
110 FOR I = 1 TO N : MOVE X,Y : VDU 205.5 + RND(1) : X = X-32 : T = INKEY(1) : NEXT
120 FOR I = 1 TO N : MOVE X,Y : VDU 205.5 + RND(1) : Y = Y-32 : T = INKEY(1) : NEXT
130 N = N+1
140 UNTIL N > 40
150 END



And, sorry to be a grump, but after taking far too long to try to find the original posting on Facebook and then having to wade through what I consider to be an utterly dreadful website with the results I have to say that frankly I just can't be bothered at this point.

I strongly suggest that in-future you provide direct links or just re-post the entire thing here so that those who care can see what you mean with the minimal of effort because life's just too short.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 12, 2024 2:22 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
I think there’s an interesting challenge in optimising some 6502 code which makes coordinates for this kind of spiral. I’ve previously seen this spiral as an Ulam Spiral, where each point is used to indicate if a number is prime or not.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 12, 2024 2:49 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
BigEd wrote:
I think there’s an interesting challenge in optimising some 6502 code which makes coordinates for this kind of spiral. I’ve previously seen this spiral as an Ulam Spiral, where each point is used to indicate if a number is prime or not.


That's what I tought. Optimizing the code could be fun.

On a computer with 40 colums, the rotation will move on the screen by adding or subtracting those values +1,+40, -1,-1,-40,-40,+1,+1,+1,+40,+40,+40 and so on.

The "fastest" way would be to builld a table with precalculated positions (high byte and low byte) but the table would take 1250 bytes (based on 25 rows). Furthermore, I tend to consider that precalculated positions is not really... "sexy".


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 12, 2024 3:51 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
A table doesn't seem very interesting, that's for sure! Often these challenges have a size limitation, or will score on the basis of size, so that can push solutions towards ingenuity. The smallest code to do the job might be a good challenge, in fact... I don't think it's likely to be slow, in any case.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 12, 2024 6:54 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
I think we just need to move left one then down one, then right two and up two, then left three and down three, and so on. One way could be to store a direction vector starting with (-1,0) and rotate it left 90 degrees at each corner by swapping its elements and negating the new first element - so (-1,0) becomes (0,-1) then (1,0) then (0,1) and then back to (-1,0). The numbers are small enough that they don't wrap, which helps! Or it may make more sense to unroll the loop. I might sketch something a bit later if I get time.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 5:52 am 
Offline

Joined: Fri Dec 21, 2018 1:05 am
Posts: 1076
Location: Albuquerque NM USA
lightbeing wrote:
The aim was to create a short BASIC program displaying an ASCII code progressively on the screen, following the shape of a spiral which starts at the centre of the screen. The challenge was opened to all computers.

Your topic has inspired me to this attempt at displaying ASCII spiral with a 6502 VGA controller. The screen is 640x480 monochrome. It is a 25MHz 6502 and screen is 32 rows x 80 columns characters in 8x15 fonts. 6502 spent 90% of its time painting the screen, so the spiral displaying task was done during the vertical retrace time--roughly equivalent to 2MHz 6502. The program is in 6502 assembly.
Bill


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 12:28 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
gfoot wrote:
I think we just need to move left one then down one, then right two and up two, then left three and down three, and so on. One way could be to store a direction vector starting with (-1,0) and rotate it left 90 degrees at each corner by swapping its elements and negating the new first element - so (-1,0) becomes (0,-1) then (1,0) then (0,1) and then back to (-1,0). The numbers are small enough that they don't wrap, which helps! Or it may make more sense to unroll the loop. I might sketch something a bit later if I get time.


Very interesting. Thank you. I get the idea of a direction vector. I think that's what I call a "quadrant indicator". The screen is divided in 4 quarters (upper right, down right, down left, upper right) in order to determine the actual position of the rotation and the branching of the code.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 12:57 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
BigEd wrote:
A table doesn't seem very interesting, that's for sure! Often these challenges have a size limitation, or will score on the basis of size, so that can push solutions towards ingenuity. The smallest code to do the job might be a good challenge, in fact... I don't think it's likely to be slow, in any case.


Indeed. It's very fast. For my own code, I had to add a raster loop as a waiting loop in order to make the progress of the spiral visible to the naked eye.

You're right. The length of the code should be limited to a maximum number of bytes. Mine is 143 bytes long. Although it uses 7 bytes for the waiting loop, I have the feeling that it's not completely optimised and ingenious. I guess 200 bytes long is far enough.

I would also add the following rules in order to make the competition fair:
- pure 6502 legal codes
- use of screen memory and one ASCII/screen code
- use of "internal" routines prohibited
- direction of rotation may be right or left
- final shape displayed on screen is 25x25 (you can do more but it takes more cycles...)

If anyone is interested in participating or helping me in organising the challenge, just let me know.


Attachments:
vice-video-2024011313094162.gif
vice-video-2024011313094162.gif [ 306.83 KiB | Viewed 2994 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: bencoder and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: