Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:53 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : TinyBasic for the ATTiny85

     Page 1 of 4    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9126
Posted: 12:19pm 25 Jul 2023
Copy link to clipboard 
Print this post

Attached is a release of TinyBasic for the ATTiny85

ATTiny85.zip

See here for basics of the language and from where I copied the core code
I found code for the TONE command and TEMP function here
Bits of the Arduino ATTiny core were "acquired" to help with I/O from here
The code was compiled using Microchip Studio
I wrote the software UART and put it all together (difficult bit was supporting Ctrl-C). NB: you cannot paste code into the terminal window as the character echo from the previous character is blocking. The code uses 8075 bytes of 8192 available.

ENJOY

Source code

ATTinySource.zip


Differences from the documented version of TinyBasic are:

For all pin based commands use the physical pin number as the argument

TONE command

TONE note, octave


note is a number between 0 and 11
octave is a number between 1 and 11

TEMP function

TEMP(pinno)


WAIT command

WAIT usecs


The pinout of the ATTiny85 is as below:




Connect a USB-UART to pins 6 and 7 to communicate with the ATTiny85. The baudrate is fixed at 38400.
You then have three user pins to use for the functions and commands as shown.
The chip is programmed to run at 16MHz. Note that pin 1 could in theory be made available as an I/O pin but that requires setting a fuse and the chip could then not be re-programmed with an Arduino or USBASP.

To program the ATTiny85 you will need a USBASP (ebay) or a suitable programmed Arduino. Connect the chip as below.




You will then need to download the AVRDUDE software.

Assuming the hex file is in the same directory as AVRDUDE, the command to program the chip is:

avrdude.exe -B 125khz -p t85 -c usbasp -P usb -U lfuse:w:0xf1:m -U flash:w:"attiny85.hex"


Note: this sets one of the fuses in the chip to allow 16MHz operation (-U lfuse:w:0xf1:m). I presume the command will need to be modified slightly if you are using an Arduino to program the chip.

USBASP programmers are very cheap





Edited 2023-07-25 22:28 by matherp
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4246
Posted: 12:55pm 25 Jul 2023
Copy link to clipboard 
Print this post

bug fixes

I also have a more recent version that shows line number at stop (CTRL-C). Let me see if I can find back the source.
Good that you did not use Arduino to compile. With each new Arduino release the compiler optimizes different.

EDIT: maybe this is usefull
TinyBasicUno_v0_20_rc2.zip
I also made a version specific for the 4 squares program that had 8 level deep stack (normal is 6 level deep) and a version for the STM32F103 (bluepill) missing the EEPROM save and load, and missing SERVO.
Edited 2023-07-25 23:43 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9126
Posted: 03:31pm 25 Jul 2023
Copy link to clipboard 
Print this post

Sorry bug in the hex file

ATTiny85.zip

Now updated with many of Volhout's changes
Edited 2023-07-26 03:58 by matherp
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 07:19pm 25 Jul 2023
Copy link to clipboard 
Print this post

Ok, I have tiny85 basic mostly working!

I haven't figured out how to save the program to EEProm

the MEM command reports:

246 bytes free
512 EEProm bytes total.
1 EEProm bytes available.


The default state for the EEProm is filed with 0xFF
I tried filling the EEProm with 0x00 but with the same result.

What am I missing???

-Carl
-Carl
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 08:23pm 25 Jul 2023
Copy link to clipboard 
Print this post

I notice that when running the following program the Tiny85 is unresponsive to CTRL-C it usually responds after repeated attempts or pressing CTRL-C repeatedly.  This may be unavoidable due to the "serial blocking" mentioned in the OP

10 ?"Hello World ";
20 GOTO 10



I also discovered that I can paste code from Windows Notepad into the Tera-Term window if I set the transmit delay to 1msec/char.  It's not super fast, but it sure beats retyping everything over again.
-Carl
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 08:35pm 25 Jul 2023
Copy link to clipboard 
Print this post

Ok, I found the EFORMAT command.  It helps to read the directions.  ESAVE and ELIST and ELOAD seem to be working, but MEM still reports 1 EEPROM bytes available.
-Carl
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9126
Posted: 09:57pm 25 Jul 2023
Copy link to clipboard 
Print this post

  Quote  but MEM still reports 1 EEPROM bytes available.


Thanks - should be fixed now, and thanks for the hint on teraterm delay - works great


ATTiny85.zip

NB:

As per Volhout's post above you can now use
HELP
VAR

and

short form commands

e.g.

DW. == DWRITE
Edited 2023-07-26 07:57 by matherp
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 11:13pm 25 Jul 2023
Copy link to clipboard 
Print this post

I have ordered some chips and a programmer.
Usual wait times of 2 weeks apply.

I never thought I would see line numbers back in MMEdit but I will have a deep think.
Most of the original code for them is still hiding in the source.

I see these chips as very handy remote sensors feeding a 'mite.


Jim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 11:24pm 25 Jul 2023
Copy link to clipboard 
Print this post

Hi Peter,
Well done again.

Hi Jim,
Please keep us posted as it certainly might enable some simple low-powered remote sensors?
You might recall that I mused that Peter was remarkably quiet and hence might be plotting something.

Cheers,

Andrew
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 04:36am 26 Jul 2023
Copy link to clipboard 
Print this post

Here is the obligatory Mandelbrot program for Peter's Tiny85 Basic.
It all fits in less than 260Bytes of program memory and uses only 16bit integers.
The mathematical as well as the display resolution is poor, but it makes a nice Mandelbrot for only 80X40 text display in the terminal.

Tip: make sure to reset the Tiny85 before loading the program, things seem to get a bit sketchy when program memory is full.

Now I need to do an integer version for PicoMite just to see how fast it is.


1 M=64
2 FORJ= -20TO20
4 FORI= -40TO40
5 V=J*4:U=I*3-40:X=U:Y=V:N=0
6 R=X*X/M:Q=Y*Y/M
7 IFR+Q>256GO.11
8 IFN>=64GO.10
9 Y=2*X*Y/M+V:X=R-Q+U:N=N+1:GO.6
10 ?" ";:GO.15
11 N=N-N/2*2
12 IFN=0?"@";
13 IFN=1?"$";
15 NEXTI
16 ?""
17 NEXTJ


Actually looks better as white text on black background.
@@@@@@@@@@@@@@@@@@@@$$$$$$$$$$$$@@@$$$@@@@@@@@@@@@@@@@$$$$$$$$$$$$$@@@@$$@@$@@$$$
@@@@@@@@@@@@@@@@@@@$$$$$$$$$$$@@@@$$$$$@@@@@@@@@@@@@@@@@@$$$$$$$$$$$$$$$@@@@$@@@@
@@@@@@@@@@@@@@@@@@$$$$$$$$$$@@@$@@$@@$@@@@@@@$$$$$@$$$@$@@@@$$$$$$$$$$@@@$@$@$@@@
@@@@@@@@@@@@@@@@@@$$$$$$$@$$$@@$$$@$@@@@@$$$$$$$$@@$$@$$@$@@@@$$$$$$$$$$@$@$@$$$@
@@@@@@@@@@@@@@@@@$$$$$@@@$$$@@@@ $@@@@@@@@@$$$@@@@@@$@@$$$$$@@@$$$$$$$$$$$@@@@$$@
@@@@@@@@@@@@@@@@$$$$$$@@$$$@@@@@@@@@@$@@$$$$$@@@@$$@$@$@$$$$$@@@@$$$$$$$$$$$@@@@$
@@@@@@@@@@@@@@@$$$$@@@@$$$$@@@@@@@@@@$@$$$$@$@$@@$@ $@$$@$$$$@@@@@@$$$$$$$$$$$$$@
@@@@@@@@@@@@@@@$$$$@$$$$$@@@@@@@@@$@@$$$$$@@@$@@@    $ @@@$$$$@@@@@@@$$$$$$$$$$$$
@@@@@@@@@@@@@@$$$@@@$@@$@@@@@@@@@$$$$$$$@@$$$@$$@     @@$$$@@@$$@@@@@$$$$$$$$$$$$
@@@@@@@@@@@@@@$$@@$@@@$@@@@@@@@$$$$$$@@@@@@$$$@$$    $$$$@$$@$$$$@@@@@@$$$$$$$$$$
@@@@@@@@@@@@@$$$$@@$$$@@@@@@@$$$$$$@@@@@$@$ $@$        @ @$@$@$@$@@@$@@@$$$$$$$$$
@@@@@@@@@@@@@$$@@@@@@@@@@@@$$$@$$@@@$@$@@$                $   $@@$@@@@@@$$$$$$$$$
@@@@@@@@@@@@$@$@@@@@@@@@@$$$@@@$@@@$$$$ $$                   @@@@$@@@$$$$$$$$$$$$
@@@@@@@@@@@@$$@@@@@@@@$$$@$$$@$$$$$@$$@$                     $@@@$$@@@@$@@$$$$$$$
@@@@@@@@@@@@@@@@@@@$$$$$@$$$@@$$@$@@$@$                      $ @@$$@@@@@$@$$$$$$$
@@@@@@@@@@@@@@@$$@@$$@@@$$$ @$@@ @$@@$@                       $$@$$$@@@@@$$$$$$$$
@@@@@@@@@@@$@@$@$$$$@$@@$@@   $    @$@                        @@@$$@@@@@$$@$$$$$$
@@@@@@@@@@@@$$$@$$@@@@@@$$@         $@                        @$@$$@@@@@$@@$$$$$$
@@@@@@@@@@@@$$$$$@@$$$@$$$$                                   $$@$$$@@@$@@@$$$$$$
@@@@@@@@@@@$$@$$@@$@@@$$$                                    @$@@$$@@@@$@$@$$$$$$
@@@@@@@@@@@                                                @@$$@$$$@@@@$$@@$$$$$$
@@@@@@@@@@@$$@$$@@$@@@$$$                                    @$@@$$@@@@$@$@$$$$$$
@@@@@@@@@@@@$$$$$@@$$$@$$$$                                   $$@$$$@@@$@@@$$$$$$
@@@@@@@@@@@@$$$@$$@@@@@@$$@         $@                        @$@$$@@@@@$@@$$$$$$
@@@@@@@@@@@$@@$@$$$$@$@@$@@   $    @$@                        @@@$$@@@@@$$@$$$$$$
@@@@@@@@@@@@@@@$$@@$$@@@$$$ @$@@ @$@@$@                       $$@$$$@@@@@$$$$$$$$
@@@@@@@@@@@@@@@@@@@$$$$$@$$$@@$$@$@@$@$                      $ @@$$@@@@@$@$$$$$$$
@@@@@@@@@@@@$$@@@@@@@@$$$@$$$@$$$$$@$$@$                     $@@@$$@@@@$@@$$$$$$$
@@@@@@@@@@@@$@$@@@@@@@@@@$$$@@@$@@@$$$$ $$                   @@@@$@@@$$$$$$$$$$$$
@@@@@@@@@@@@@$$@@@@@@@@@@@@$$$@$$@@@$@$@@$                $   $@@$@@@@@@$$$$$$$$$
@@@@@@@@@@@@@$$$$@@$$$@@@@@@@$$$$$$@@@@@$@$ $@$        @ @$@$@$@$@@@$@@@$$$$$$$$$
@@@@@@@@@@@@@@$$@@$@@@$@@@@@@@@$$$$$$@@@@@@$$$@$$    $$$$@$$@$$$$@@@@@@$$$$$$$$$$
@@@@@@@@@@@@@@$$$@@@$@@$@@@@@@@@@$$$$$$$@@$$$@$$@     @@$$$@@@$$@@@@@$$$$$$$$$$$$
@@@@@@@@@@@@@@@$$$$@$$$$$@@@@@@@@@$@@$$$$$@@@$@@@    $ @@@$$$$@@@@@@@$$$$$$$$$$$$
@@@@@@@@@@@@@@@$$$$@@@@$$$$@@@@@@@@@@$@$$$$@$@$@@$@ $@$$@$$$$@@@@@@$$$$$$$$$$$$$@
@@@@@@@@@@@@@@@@$$$$$$@@$$$@@@@@@@@@@$@@$$$$$@@@@$$@$@$@$$$$$@@@@$$$$$$$$$$$@@@@$
@@@@@@@@@@@@@@@@@$$$$$@@@$$$@@@@ $@@@@@@@@@$$$@@@@@@$@@$$$$$@@@$$$$$$$$$$$@@@@$$@
@@@@@@@@@@@@@@@@@@$$$$$$$@$$$@@$$$@$@@@@@$$$$$$$$@@$$@$$@$@@@@$$$$$$$$$$@$@$@$$$@
@@@@@@@@@@@@@@@@@@$$$$$$$$$$@@@$@@$@@$@@@@@@@$$$$$@$$$@$@@@@$$$$$$$$$$@@@$@$@$@@@
@@@@@@@@@@@@@@@@@@@$$$$$$$$$$$@@@@$$$$$@@@@@@@@@@@@@@@@@@$$$$$$$$$$$$$$$@@@@$@@@@
@@@@@@@@@@@@@@@@@@@@$$$$$$$$$$$$@@@$$$@@@@@@@@@@@@@@@@$$$$$$$$$$$$$@@@@$$@@$@@$$$

-Carl
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4246
Posted: 06:28am 26 Jul 2023
Copy link to clipboard 
Print this post

Nice work Carl !

The same program runs on my UNO with tinybasic.
I optimized the abreviations a bit further (re-ordering the command table in the C-source code), so I could abbreviate it a bit further even.

2 M=64:F.J=-20TO20
4 F.I=-40TO40
5 V=J*4:U=I*3-40:X=U:Y=V:N=0
6 R=X*X/M:Q=Y*Y/M:IFR+Q>256G.11
8 IFN>=64G.10
9 Y=2*X*Y/M+V:X=R-Q+U:N=N+1:G.6
10 ?" ";:G.15
11 N=N-N/2*2:IFN=0?"@";
13 IFN=1?"$";
15 N.I:?:N.J


The run time on an UNO (also 16MHz) is 1 minute 40 seconds. Should be fairly similar on the Tiny85 although I am not sure how good the ARDUINO compiler is versus Microchip's own. My version is 214 bytes. I don't have ATTINY's so I can't play in this game...

Volhout
Edited 2023-07-26 16:47 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9126
Posted: 07:15am 26 Jul 2023
Copy link to clipboard 
Print this post

I get 1 min 53 with Volhout's version on the ATTiny85. I have had to compile big chunks with Os to get all the code in so I'm not surprised it is a bit slower.

You need this version for Volhout's code as before NEW came before NEXT so line 15 failed


UPDATE

Played with the optimisation of some routines - now 1'39.52"  


ATTiny85.zip

  Quote  Now I need to do an integer version for PicoMite just to see how fast it is.


5.9 seconds @ 378MHz, 17 @ 126MHz

Option default integer
Timer =0
1 M=64
2 For J= -20 To 20
4 For I= -40 To 40
5 V=J*4:U=I*3-40:X=U:Y=V:N=0
6 R=X*X/M:Q=Y*Y\M
7 If R+Q>256 GoTo 11
8 If N>=64 GoTo 10
9 Y=2*X*Y\M+V:X=R-Q+U:N=N+1:GoTo 6
10 Print " ";:GoTo 15
11 N=N-N\2*2
12 If N=0 Then Print "@";
13 If N=1 Then Print "$";
15 Next I
16 Print ""
17 Next J
Print Timer

Edited 2023-07-26 19:33 by matherp
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 11:34am 26 Jul 2023
Copy link to clipboard 
Print this post

Nice Work @Volhout and @matherp.  Some of the optimizations I tried didn't work so I finally called it "good enough"

  Volhout said  I don't have ATTINY's so I can't play in this game...

You seem to be playing quite well!  No fair playing while I'm asleep  

Re-numbering the lines shaves off an additional 3 bytes and is perhaps marginally faster:

1 M=64:F.J=-20TO20
2 F.I=-40TO40
3 V=J*4:U=I*3-40:X=U:Y=V:N=0
4 R=X*X/M:Q=Y*Y/M:IFR+Q>256G.8
5 IFN>=64G.7
6 Y=2*X*Y/M+V:X=R-Q+U:N=N+1:G.4
7 ?" ";:G.10
8 N=N-N/2*2:IFN=0?"@";
9 IFN=1?"$";
10 N.I:?:N.J


For raw speed changing the maximum number of iterations from 64 to 32 on line 5 gets me to about 1min5sec with minimal impact on the shape of the Mandelbrot.

Now that there is more free memory, here is a slightly slower version with more "colors" giving more contrast to the "banding" around the basic Mandelbrot shape:

1 M=64:F.J=-20TO20
2 F.I=-40TO40
3 V=J*4:U=I*3-40:X=U:Y=V:N=0
4 R=X*X/M:Q=Y*Y/M:IFR+Q>256G.8
5 IFN>=64G.7
6 Y=2*X*Y/M+V:X=R-Q+U:N=N+1:G.4
7 ?" ";:G.13
8 N=N-N/5*5:IFN=0?"@";
9 IFN=1?"$";
10 IFN=2?"#";
11 IFN=3?"%";
12 IFN=4?"&";
13 N.I:?:N.J


Note that with only 9 bytes free, the interpreter becomes a bit unstable, sometimes requiring a reset of the ATTiny85 between pasting a new program into the terminal window
-Carl
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 12:48pm 26 Jul 2023
Copy link to clipboard 
Print this post

Here is a version of Peter's PicoMite port that takes advantage of the increased integer resolution and adds lots of "colors" through the magic of string operators.

Hurray for Strings  

Note: this version also runs fine on a PicoMiteVGA and possibly other 'Mites with little or no modification.

I plan to do an integer version for PicoMiteVGA with 320X240 16 color graphics, but it may take me a day or two to get to it.

Option default integer
Timer =0
1 M=8192
2 For J= -20 To 20
4 For I= -40 To 39
5 V=j*512:U=I*384-4000:X=U:Y=V:N=0
6 R=X*X/M:Q=Y*Y\M
7 If R+Q>32768  GoTo 11
8 If N>=64 GoTo 10
9 Y=2*X*Y\M+V:X=R-Q+U:N=N+1:GoTo 6
10 Print " ";:GoTo 15
11 N=N Mod 7
12 Print Chr$(33+N);
15 Next I
16 Print ""
17 Next J
Print Timer

Edited 2023-07-26 22:56 by Sasquatch
-Carl
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4246
Posted: 01:34pm 26 Jul 2023
Copy link to clipboard 
Print this post

Hi Carl,

I squeezed another 4 characters out....
Used GOSUB X ....

1 M=64:F.J=-20TO20
2 F.I=-40TO40
3 V=J*4:U=I*3-40:X=U:Y=V:N=0
4 R=X*X/M:Q=Y*Y/M:IFR+Q>256G.7
5 IFN>=64?" ";:G.8
6 Y=2*X*Y/M+V:X=R-Q+U:N=N+1:G.4
7 N=N-N/5*5:GOS.N+9
8 N.I:?:N.J:E.
9 ?"@";:R.
10 ?"$";:R.
11 ?"#";:R.
12 ?"%";:R.
13 ?"&";:R.

PicomiteVGA PETSCII ROBOTS
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 03:01pm 26 Jul 2023
Copy link to clipboard 
Print this post

  Volhout said  I squeezed another 4 characters out....
Used GOSUB X ....


Well done!  Again!  I was not aware of the GOSUB X command.  Any other undocumented commands I should be aware of?  MOD and SHIFT (<< and >>) operators would be nice.
-Carl
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 03:34pm 26 Jul 2023
Copy link to clipboard 
Print this post

You think we're made of memory? << and >> are two characters each!  ;)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 362
Posted: 06:15pm 26 Jul 2023
Copy link to clipboard 
Print this post

Ok, Here is an integer version of the Mandelbrot for PicoMiteVGA.

It's really not much faster than the more verbose Floating Point version at 54 seconds vs 71 for floating point.  Makes me wonder how integer multiply is being handled in the PicoMite firmware???


Option Default Integer

MODE 2  'Works in Mode2 on PicoMiteVGA

CLS

Dim CMap(16)

CMap(0) = RGB(0,0,0)
CMap(1) = RGB(0,85,0)
CMap(2) = RGB(0,170,0)
CMap(3) = RGB(0,255,0)
CMap(4) = RGB(0,0,255)
CMap(5) = RGB(0,55,255)
CMap(6) = RGB(0,170,255)
CMap(7) = RGB(0,255,255)
CMap(8) = RGB(255,0,0)
CMap(9) = RGB(255,85,0)
CMap(10) = RGB(255,170,0)
CMap(11) = RGB(255,255,0)
CMap(12) = RGB(255,0,255)
CMap(13) = RGB(255,85,255)
CMap(14) = RGB(255,170,255)
CMap(15) = RGB(255,255,255)

Timer = 0
 
M=8192
For J= 1 To 239
 V=(J-120)*102
 For I= 1 To 319
   U=(I-160)*76-5734:X=U:Y=V:N=0
   For N = 1 TO 32
     R=X*X\M:Q=Y*Y\M
     If R+Q>32768 Then Exit For
     Y=2*X*Y\M+V:X=R-Q+U
   Next N
   IF N-1 < 32 Then
     Pixel I-1,J-1,CMap%(N Mod 15)
   Else
     Pixel I-1,J-1,CMap%(0)  'Otherwise Make the Pixel black
   EndIf
 Next I
Next J

Print Timer/1000



And here is the floating point version for comparison:


If MM.Device$ = "PicoMiteVGA" Then
 MODE 2  'Works in Mode1 or Mode2 on PicoMiteVGA
EndIf

CLS

Dim CMap%(16)

CMap%(0) = RGB(0,0,0)
CMap%(1) = RGB(0,85,0)
CMap%(2) = RGB(0,170,0)
CMap%(3) = RGB(0,255,0)
CMap%(4) = RGB(0,0,255)
CMap%(5) = RGB(0,55,255)
CMap%(6) = RGB(0,170,255)
CMap%(7) = RGB(0,255,255)
CMap%(8) = RGB(255,0,0)
CMap%(9) = RGB(255,85,0)
CMap%(10) = RGB(255,170,0)
CMap%(11) = RGB(255,255,0)
CMap%(12) = RGB(255,0,255)
CMap%(13) = RGB(255,85,255)
CMap%(14) = RGB(255,170,255)
CMap%(15) = RGB(255,255,255)

XMax = MM.HRes - 1
YMax = MM.VRes - 1

Timer = 0
Mandelbrot(32,1.0,-0.7,0.0)
Print Timer/1000

'Pure MMBASCIC version of the Mandelbrot Sub
'Mandelbrot(Depth,Scale,XCenter,YCenter)
'Variable names shortened for efficiency
Sub Mandelbrot(IMax%,Mag!,XCen!,YCen!)  'Maximum Iterations (Depth), Magnification (Scale)
                                        'X-Center, Y-Center
 For HY = 1 To YMax    'Step through each Row (Line) of pixels (Y-Axis)
   CY = (HY / YMax - 0.5) / Mag! * 3.0 - YCen!

   For HX = 1 To XMax   'Step through each Pixel in the Row (X-Axis)
     CX = (HX / XMax - 0.5) / Mag! * 3.0 + XCen!

     X = 0.0:Y = 0.0

     For Iter = 1 To IMax%      'Step from 1 to Maximum Iterations
       XSqr = X * X
       YSqr = Y * Y

       If XSqr + YSqr > 4 Then Exit For  'If "radius" greater than escape value stop
                                           'C^2 = A^2 + B^2 or R^2 = X^2 + Y^2

       Y = 2 * X * Y + CY     'Iterate next value
       X = XSqr - YSqr + CX

     Next Iter

     If Iter - 1 < IMax% Then   'If we didn't reach the Maximum number of iterations (Depth)
       Pixel HX-1,HY-1,CMap%(Iter Mod 15) 'color the pixel based on number of Iterations
     Else
       Pixel HX-1,HY-1,CMap%(0)  'Otherwise Make the Pixel black
     EndIf

   Next HX

 Next HY
End Sub

-Carl
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4246
Posted: 09:07pm 26 Jul 2023
Copy link to clipboard 
Print this post

@Peter,

Thanks for using my fixes. I really appreciate it.

Harm
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9126
Posted: 09:28pm 26 Jul 2023
Copy link to clipboard 
Print this post

Arriving soon:

% operator for MOD
I2C read and write


 
     Page 1 of 4    
Print this page
© JAQ Software 2024