News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_AMSDOS

Drawing Fast Circles in Locomotive BASIC

Started by AMSDOS, 07:16, 12 August 10

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

While looking for another thing I found these programs I wrote which I had mentioned previously.


10 ' Setup Data
20 ' CP/M User - Public Domain
30 ' For Amstrad CPC or CPC Emulators
40 ' Run Me First
50 DATA DD,5E,00,DD,56,01,DD,6E
60 DATA 02,DD,66,03,73,23,72,C9
70 FOR addr=&BE00 TO &BE0F
80 READ a$:POKE addr,VAL("&"+a$)
90 NEXT addr
100 DEG:count=0
110 FOR a=1 TO 360
120 CALL &BE00,&4000+count,INT(320+190*COS(a))
130 count=count+2
140 NEXT a:count=0
150 FOR a=1 TO 360
160 CALL &BE00,&42E0+count,INT(200+190*SIN(a))
170 count=count+2
180 NEXT a
190 SAVE"BASCIR.DAT",B,&4000,&5AF



10 ' Quick Circle in BASIC
20 ' CP/M User
30 MEMORY &3FFF:LOAD"BASCIR.DAT",&4000
40 DATA DD,6E,00,DD,66,01,DD,5E,02,DD,56,03,46,23,4E,21
50 DATA 2B,BE,70,23,71,EB,46,23,4E,21,2D,BE,70,23,71,ED
60 DATA 5B,2D,BE,2A,2B,BE,CD,F6,BB,C9,00,00,00,00,00,00
70 tot=0:FOR addr=&BE00 TO &BE2F
80 READ a$:by=VAL("&"+a$)
90 POKE addr,by:tot=tot+by:NEXT addr
100 IF tot<>&1206 THEN PRINT"Data Error!":STOP
110 CLS:MYPOS=&42E0:MXPOS=&4000
120 FOR count=1 TO 360:MOVE 320,200
130 CALL &BE00,MXPOS,MYPOS
140 MYPOS=MYPOS+2:MXPOS=MXPOS+2:NEXT count

This was just some code I was playing around with while trying to perform some faster drawing without the aid of the maths. The first program sets it all up and does the maths and then pokes the values into Memory. For this example I was looking for a way of making a faster alternative which would be fast in Turbo Pascal as well as BASIC. BASIC in a sense being an interpreted language didn't have as big an issue when calculating cause of it's ability of using look-up tables, TP on the other hand doesn't so once everything is compiled into an executable file the whole drawing process look longer to achieve.


This was just some code I was playing around with while trying to perform some faster drawing without the aid of the maths. The first program sets it all up and does the maths and then pokes the values into Memory. For this example I was looking for a way of making a faster alternative which would be fast in Turbo Pascal as well as BASIC. BASIC in a sense being an interpreted language didn't have as big an issue when calculating cause of it's ability of using look-up tables, TP on the other hand doesn't so once everything is compiled into an executable file the whole drawing process look longer to achieve.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

arnoldemu

Nice. I have some fast line, ellipse and circle drawing routines on a disc. I think they come from a book and they were then modified by a teacher at my secondary school (at least 15 years ago). I can upload them and hopefully we can find the original source.

They work using bresenheim's method, so maybe be good to adapt to other languages if needed.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

TFM

Hey guys, whats about a small contest? Who can draw the fastest circle.

Let's say...

- Draw a full circle (360 degrees)
- with a radius of .... hmmm... 100 pixel, ok?
- in ... hmm... Mode 1 (most beautiful for a circle)
- Check time to draw 100 circles, ok?

Any other ideas?

Can you guys make a benchmark for the abouve circle routines that way? I mean on a REAL CPC. A .DSK would be fine for everyone :-)

The contest is open :-)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

AMSDOS

Hmmm, I have a feeling that if I do that then you'll come out with something much faster in FutureOS?  :-[  Of course a 17k Screen Dump takes a couple of secs to display itself!  ;D

Fast lines and Mathematical algorithms are good to look at.

I ported a fractal program to Turbo Pascal 3 on the PCs a few years ago using a simular method as I used in the above program by storing the values of that Fractal into an array, consequently the size of it had to be reduced significantly due to the vast detail of it.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

TFM

Quote from: CP/M User on 03:48, 13 August 10
Hmmm, I have a feeling that if I do that then you'll come out with something much faster in FutureOS?  :-[  Of course a 17k Screen Dump takes a couple of secs to display itself!  ;D

Hehe, the idea with the screen dump is not bad. But a compressed screen can be displayed much faster ;-)

Now seriously, I have a circle routine in FIOLIB http://www.cpcwiki.eu/index.php/FIOLIB
But even if it is not bad, it can be made faster. Have the code on paper since a long time, but have no time to integrate it.

However a circle speed contest would be nice!

Quote from: CP/M User on 03:48, 13 August 10
Fast lines and Mathematical algorithms are good to look at.
I agree :-) :-) :-) But it's also a lot of fun to developp something by yourself and then look at other solutions :-)

Quote from: CP/M User on 03:48, 13 August 10
I ported a fractal program to Turbo Pascal 3 on the PCs a few years ago using a simular method as I used in the above program by storing the values of that Fractal into an array, consequently the size of it had to be reduced significantly due to the vast detail of it.
Hmm, may it runs unter CP/M with Turbo Pascal???
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

AMSDOS

Compressed screens are usually quicker (there's a competition in that since some Compressors display screens faster than others), but if I load my Screen to &4000 and use my old friend LDIR it would make for interesting comparision.

Wooo that FIOLIB might just beat my Firmware!  I've gone ahead with it anyway and have produced a DSK image with the specifications you've specified. I've made alterations from my original Setup program so now instead of poking the values as Integers, it's poking what generally looks like a true circle (as earlier returning the values as Integers was having a different result on the Circle). I've attached a plain BASIC version of the program, same result though takes longer to draw, so I'll stick that into the WebCPC presentations! :D

Sorry I should of explained earlier that the Fractal program I converted to work in TP3 would need further adjustments to work on a CPC!  ???  Unfortunately two things it does (since I checked it out) is setup a 256 Colour Pallete and has an array file 40k in size!  :-[  Mode 1 would probably be the best resolution for it, though I don't know how good Fractals look in 4 colours! Also I don't know why I'm calling it a Fractal, but the real terminology is Mandelbrot!  :-[
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

TFM

#6
Give us a link if you have finished your .DSK. Will be interesting to look at it  :)
EDIT: Ah found it! You made a new thread! Great! Thanks!

About Mandelbrot... Well, yes, think Mode 1 could be the best choice... you can use a kind of "dithering" to get a bit more than 4 colours.  Oh the other hand, if you look at a Fraktalbrot or Mandelfrak (heee? it's tooo late at night  ??? ) then Mode 0 can make sense if the "lines" in the picture are relatively "flat". I mean their angle is not more than 45 Degrees over the horizon.

But the 40 KB table will probably use up all free RAM in CP/M - if really 40 KB are needed. Well, I got a feeling it costs too much time to make a CPC version of this.

About FIOLIB - I really have to overwork it in the coming time and add more functons. However, it's a curious thing - I don't know how to program in C, but since the FIOLIB is made in Z80 code, I was able to do it ;-) For any kind of comments I always have an open ear. I remember that I got some very good ideas from france. Have to realize all that stuff. Wished the day wouldn't have only 36 hours :-(
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

AMSDOS

Probably because I was using CP/M which recognised 640k probably meant that Array file would work out alright, everything about the Array file which I produced is simply calculations of the colours for the Mandelbrot so it wasn't 40k of Typing in!  ;D  It was constructed as an Include file and is Text Based, so everything would blow up in regard to that! The result was a 80x50 image in 255 colours, but on a CPC everything would be downscaled, as is the array itself is 16k the program would have to be modified to plot every 2nd(??) pixel onscreen out of a possible 4 colours. Probably have to go back to the core program and calculate everything (slow) and substitute the CPC equivalents for the PC equivalents.

Interesting FIOLIB was done in Z80, my Include file (for TP3 on a CPC) is a bit like that lots of Procedures with Inline Machine Code, mostly Firmware if not all I think it might have been!
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ssg

#8
Quote from: TFM/FS on 19:46, 12 August 10
Hey guys, whats about a small contest? Who can draw the fastest circle.

The contest is open :-)


Elite wins ;-)


edit: oh did someone say basic? :)

TFM

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

AMSDOS

Naming names here means nothing, unless source is presented!  ;)

It could be a M/C routine presented in BASIC which can be used in BASIC!  :)
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod