Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 03:54 13 May 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 : NEXT STEP- To start converting all the archive of programs.

     Page 1 of 2    
Author Message
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 430
Posted: 10:42pm 29 Jul 2020
Copy link to clipboard 
Print this post

Hi, Just got my baby!!! Now I would like to start converting all the old programs For CMM1 and other variants. I got that zip file compilations of code.  Can we start this as a discussion on how to do that and maybe wind up with a guide to conversion possibly for inclusion of a section in the manual.  I have tried a few apps but think I will have to learn alot about the difference between the versions.  When I use the "option legacy on" it does not seem to help much. Is this a useful project?  I think it would be good for new users to have a section or tutorial on how to do the translation and maybe along the way, point out how to use the features in the CMM2 to make the programs better.  I'm just spitballing here. I may learn a lot by trying to do this.
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 01:10am 30 Jul 2020
Copy link to clipboard 
Print this post

  mclout999 said  Hi, Just got my baby!!! Now I would like to start converting all the old programs For CMM1 and other variants. I got that zip file compilations of code.  Can we start this as a discussion on how to do that and maybe wind up with a guide to conversion possibly for inclusion of a section in the manual.  I have tried a few apps but think I will have to learn alot about the difference between the versions.  When I use the "option legacy on" it does not seem to help much. Is this a useful project?  I think it would be good for new users to have a section or tutorial on how to do the translation and maybe along the way, point out how to use the features in the CMM2 to make the programs better.  I'm just spitballing here. I may learn a lot by trying to do this.


Yes I like that idea.

Another thing you can do if you don't use option legacy on, is map maximite, to get the colours set like the original colour maximite.

For picking a mode, you might want mode 1,2 or 3, so the pixels align properly in an LCD, or you could use mode 4 which matches the size of the older CMM.

I think it would be useful to start with shorter or easier programs to work out what needs to change, before working out the bigger ones.
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 430
Posted: 04:20am 30 Jul 2020
Copy link to clipboard 
Print this post

Sounds good. I will have to read through some of the manuals from the older MMBasics because I am getting loads of crashes and the MMTrek game hangs my CMM2 so have to turn it off to get it back!!  Hopefully this thread will gain some traction and we all collectivly find the best guidlines for translations and optimizations.
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 04:36am 30 Jul 2020
Copy link to clipboard 
Print this post

Once we get a few example I was thinking of putting them on fruitoftheshed.
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 430
Posted: 05:03am 30 Jul 2020
Copy link to clipboard 
Print this post

  capsikin said  Once we get a few example I was thinking of putting them on fruitoftheshed.


Yes, we should have them add a subfolder called CMM2 Translations. Then we can just all start dumping them in there but make sure in each one you leave comments showing original Syntax and indicate what you did to fix it. Then we have a self-teaching resource for everyone. I am open to suggestions on a consistent format for these change comments, but we should have one.
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 05:50am 30 Jul 2020
Copy link to clipboard 
Print this post

  mclout999 said  
  capsikin said  Once we get a few example I was thinking of putting them on fruitoftheshed.


Yes, we should have them add a subfolder called CMM2 Translations. Then we can just all start dumping them in there but make sure in each one you leave comments showing original Syntax and indicate what you did to fix it. Then we have a self-teaching resource for everyone. I am open to suggestions on a consistent format for these change comments, but we should have one.


I didn't mean the whole programs (though that might be good too) but examples of individual changes needed to convert programs.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5921
Posted: 07:48am 30 Jul 2020
Copy link to clipboard 
Print this post

Start with something simple.

I had to make two changes to this program. I could have used OPTION LEGACY but prefer to make the changes.

Pixel(X,Y) = COUNT Mod 8

This sets the pixel to a colour number 0 to 7

The 'new' method is:
Pixel X,Y, col(COUNT Mod 8)

It sets the colour which is stored in an array col()
This array is filled with the (more or less) standard GW Basic colours.
 'GW Basic colours
 DIM col(15) ' GWBasic colours
 col(0) = RGB( 0, 0, 0)      ' black
 col(1) = RGB( 0, 0, 170)    ' blue
 col(2) = RGB( 0, 170, 0)    ' green
 col(3) = RGB( 0, 153, 153)  ' cyan
 col(4) = RGB( 170, 0, 0)    ' red
 col(5) = RGB( 153, 0, 153)  ' magenta
 col(6) = RGB( 153, 102, 0)  ' brown
 col(7) = RGB( 170, 170, 170)' dull white
 col(8) = RGB( 85, 85, 85)   ' grey
 col(9) = RGB( 102, 102, 255)' light blue
 col(10) = RGB(102, 255, 102)' light green
 col(11) = RGB(102, 255, 255)' light cyan
 col(12) = RGB(255, 102, 102)' light red
 col(13) = RGB(255, 102, 255)' light magenta
 col(14) = RGB(255, 255, 102)' yellow
 col(15) = RGB(255, 255, 255)' bright white
 

I have that code saved as an INC file to save copy and pasting it in each time.

'JULIA.BAS - Draws Julia set fractal images
'by loki

Mode 3
Cls
 'GW Basic colours
 DIM col(15) ' GWBasic colours
 col(0) = RGB( 0, 0, 0)      ' black
 col(1) = RGB( 0, 0, 170)    ' blue
 col(2) = RGB( 0, 170, 0)    ' green
 col(3) = RGB( 0, 153, 153)  ' cyan
 col(4) = RGB( 170, 0, 0)    ' red
 col(5) = RGB( 153, 0, 153)  ' magenta
 col(6) = RGB( 153, 102, 0)  ' brown
 col(7) = RGB( 170, 170, 170)' dull white
 col(8) = RGB( 85, 85, 85)   ' grey
 col(9) = RGB( 102, 102, 255)' light blue
 col(10) = RGB(102, 255, 102)' light green
 col(11) = RGB(102, 255, 255)' light cyan
 col(12) = RGB(255, 102, 102)' light red
 col(13) = RGB(255, 102, 255)' light magenta
 col(14) = RGB(255, 255, 102)' yellow
 col(15) = RGB(255, 255, 255)' bright white
 
'Specify initial values
RealOffset = -1.30
ImaginOffset = -1.22
'------------------------------------------------*
'Set the Julia set constant [eg C = -1.2 + 0.8i]
CRealVal = -0.78
CImagVal = -0.20
'------------------------------------------------*
MAXIT=80 'max iterations
PixelWidth = MM.HRes
PixelHeight = MM.VRes
GAP = PixelHeight / PixelWidth
SIZE = 2.50
XDelta = SIZE / PixelWidth
YDelta = (SIZE * GAP) / PixelHeight

'Loop processing - visit every pixel
For X = 0 To (PixelWidth - 1)
 CX = X * Xdelta + RealOffset
 For Y = 0 To (PixelHeight - 1)
   CY = Y * YDelta + ImaginOffset
   Zr = CX
   Zi = CY
   COUNT = 0
   'Begin Iteration loop
   Do While (( COUNT <= MAXIT ) And (( Zr * Zr + Zi * Zi ) < 4 ))
     new_Zr = Zr * Zr - Zi * Zi + CRealVal
     new_Zi = 2 * Zr * Zi + CImagVal
     Zr = new_Zr
     Zi = new_Zi
     COUNT = COUNT + 1
   Loop
   'Pixel(X,Y) = COUNT Mod 8 ' CMM1 method
   Pixel X,Y, col(COUNT Mod 8)
 Next Y
Next X
Do
 a$ = Inkey$
Loop While a$ = ""


No other changes were required in this case.

Jim
VK7JH
MMedit   MMBasic Help
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8601
Posted: 08:09am 30 Jul 2020
Copy link to clipboard 
Print this post

The biggest issue with many of these old programs is the re-use of variables with different types. e.g. A and A$
Modern versions of MMBasic (V5 onwards) don't allow this so that is the first thing to fix.
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 430
Posted: 08:24am 30 Jul 2020
Copy link to clipboard 
Print this post

  matherp said  The biggest issue with many of these old programs is the re-use of variables with different types. e.g. A and A$
Modern versions of MMBasic (V5 onwards) don't allow this so that is the first thing to fix.


That makes sense as I keep getting errors saying variable already used or somthing like that.  This is the kind if insight I wanted this thread to bring out.  This could be in the first section on translating programs.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8601
Posted: 08:32am 30 Jul 2020
Copy link to clipboard 
Print this post

  Quote   This could be in the first section on translating programs.

Page 43 of the user manual
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 01:50pm 30 Jul 2020
Copy link to clipboard 
Print this post

I've started the page at http://fruitoftheshed.com/Colour%20MaxiMite%202%20(CMM2).Converting-older-MMBASIC-programs.ashx

Others are welcome to add to it. I haven't really put up example code yet, beyond syntax. We can link examples on separate pages and/or make them file uploads (though I haven't tried the file uploads myself yet), if they don't fit on the single wiki page.
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 430
Posted: 03:06pm 30 Jul 2020
Copy link to clipboard 
Print this post

  matherp said  
  Quote   This could be in the first section on translating programs.

Page 43 of the user manual


I have read the thing a few times but it just does not go into am much detail as I need and show more example code.  I still think this thread will be a very practical exercise in the best ways to do the porting as the manual is very terse with few examples that this thread can provide.  I just reread it and it points out the issues but I am going to need some fleshing out of how to deal with these differences a have some practical examples.
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 03:25pm 30 Jul 2020
Copy link to clipboard 
Print this post

This is a great idea. I think overall, we could do with a resource of example code on doing various things. like, for example, I had an issue where I was doing this



DIM INTEGER VALUE = 0
DIM ANARRAY(63,3) AS INTEGER
FOR VALUE = 0 TO 63
 VALUEINPUT(VALUE)
NEXT VALUE

FUNCTION VALUEINPUT(VALUE)
LOCAL INTEGER INDEX = (VALUE/4) AND &HFFFF
LOCAL INTEGER TEMPVALUE
SELECT CASE (VALUE MOD 4)
CASE 0: TEMPVALUE = ANARRAY(INDEX,0)
CASE 1: TEMPVALUE = ANARRAY(INDEX,1)
CASE 2: TEMPVALUE = ANARRAY(INDEX,2)
CASE 3: TEMPVALUE = ANARRAY(INDEX,3)
END SELECT
VALUEINPUT = TEMPVALUE
END FUNCTION

the problem with this code is that, when it got to INDEX = 63, it was erroring out with "Error Index out of Dimension"

The reason for this is because it was treating INDEX as a float. the fix (pun unintended.. you'll see why).. is to use use "FIX(VALUE / MOD) AND &HFFFF". The function worked as intended then.

I'm sure there's probably other ways of achieving the same thing, but this is what I did.
Edited 2020-07-31 01:25 by Atomizer_Zero
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3027
Posted: 03:32pm 30 Jul 2020
Copy link to clipboard 
Print this post

  Atomizer_Zero said  Tthe problem with this code is that, when it got to INDEX = 63, it was erroring out with "Error Index out of Dimension"

The reason for this is because it was treating INDEX as a float. the fix (pun unintended.. you'll see why).. is to use use "FIX(VALUE / MOD) AND &HFFFF". The function worked as intended then.

I'm sure there's probably other ways of achieving the same thing, but this is what I did.

as per another recent thread:
FUNCTION VALUEINPUT(VALUE as integer) as integer
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8601
Posted: 03:36pm 30 Jul 2020
Copy link to clipboard 
Print this post

Also if you want integer division use \ not /

(VALUE/4) gives a float as all divides convert to float as per the manual page bottom page 22
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 03:40pm 30 Jul 2020
Copy link to clipboard 
Print this post

Learning everyday. Half the fun of this is finding this stuff out. Thanks for your assistance lizby and matherp.

Is using a \ faster than fix() ? I would assume yes.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8601
Posted: 03:50pm 30 Jul 2020
Copy link to clipboard 
Print this post

  Quote  Is using a \ faster than fix() ? I would assume yes.


Probably slightly

Personally, my approach is to start all programs with

OPTION EXPLICIT and then either OPTION DEFAULT INTEGER or OPTION DEFAULT NONE. Unless you are doing math there is no advantage and lots of disadvantages to using floats especially when bit twiddling
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 04:07pm 30 Jul 2020
Copy link to clipboard 
Print this post

Thing about that is, I am using both those options. It was still treating the division as a float.

EDIT: Correction , I wasn't using OPTION EXPLICIT afterall. I thought I was... hmm. That's a mistake on my end.
Edited 2020-07-31 02:08 by Atomizer_Zero
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8601
Posted: 04:11pm 30 Jul 2020
Copy link to clipboard 
Print this post

  Quote  It was still treating the division as a float.


yes, that is the way Geoff designed it - just use the integer divide "\" to avoid the problem
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 01:05am 31 Jul 2020
Copy link to clipboard 
Print this post

  mclout999 said  
  matherp said  The biggest issue with many of these old programs is the re-use of variables with different types. e.g. A and A$
Modern versions of MMBasic (V5 onwards) don't allow this so that is the first thing to fix.


That makes sense as I keep getting errors saying variable already used or somthing like that.  This is the kind if insight I wanted this thread to bring out.  This could be in the first section on translating programs.


This is what I've put so far on the wiki:
  Quote  
Different variable names by type
Many old programs re-use variables with different types. e.g. A and A$. Modern versions of MMBasic (V5 onwards) don't allow this so that is the first thing to fix. e.g they could be A and AStr$ instead.

Old:

DIM A
DIM A$

A=1.6
A$="Hello"
PRINT A$

New:

DIM A
DIM AStr$

A=1.6
AStr$="Hello"
PRINT AStr$


Edited 2020-07-31 11:06 by capsikin
 
     Page 1 of 2    
Print this page
© JAQ Software 2024