English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 10 June 2018, 09:45   #121
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 661
Quote:
Originally Posted by Shatterhand View Post
Any ideas if its possible to implement something like this?
Yes, it is definitely possible. The question is how... In c I'd create an array of function pointers and call those.

Ultimately its just an array of memory addresses which you jump to.

I think this is what you want
Code:
On Expression Goto|Gosub Program Label[,Program Label...] 

On allows a program to branch, via either a Goto or a Gosub, to one of a number of
Program Labels depending upon the result of the specified Expression.

If the specified Expression results in a 1, then the first Program Label will be
branched to. A result of 2 will cause the second Program Label to be branched to and
so on. If the result of Expression is less than one, or not enough

Program Labels are supplied, program flow will continue without a branch.
E-Penguin is offline  
Old 10 June 2018, 17:39   #122
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 35
Posts: 2,957
OH MY GOD.
I remember when I coded on MSX Basic there was this EXACT command and I had completely forgot about it.

Yes, found this on the manual. Somehow I believe that, performance-wise, this will be just like doing a select...case . I'll have to test speed of this to see if it's faster than doing a few ifs on a tree strcuture.

Thank you a lot!
Shatterhand is offline  
Old 11 June 2018, 00:27   #123
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 35
Posts: 2,957
Ok, I've made a few tests.

Select..Case seems to be just a series of If..else one after the other. If the first "case" is the right one, it executes faster than the last "case" is the true one (or if there's no case at all).. it's actually a little faster than doing IFs for some reason, but not a lot faster to make a big difference unless you are doing a shitload of them (Still worth using it though - should use it more on my code)

In the other hand, On..Gosub is pretty fast most of the time. If the first subroutine is the selected one it will go a little faster, but then the speed doesnt change if its the second or the thirtieth one being executed. This is *great*


EDIT: Testing on REAL hardware (my 68000 A600 with 2Mb Chip Ram) gives me a lot more random results than on Winuae emulating a 040. Still, the same results more or less, On..Gosub always more or less at the same speed either the second or thirtieth option is the true one, while Select Case is a little faster when it's the first or second option, then it becomes progressively slower.

On..Gosub should be used instead of Select..Case when it's viable and you are dealing with more than 5 possibilities. When the right option was the 5th one or before that one, sometimes Select..Case is faster, sometimes On..Gosub is faster (like I said, it's weirdly too random), but from the 6th possibility onwards, On..Gosub is always faster.

So, when using Select Case, always try to have the more common possibility before the less common ones.

Last edited by Shatterhand; 11 June 2018 at 00:51.
Shatterhand is offline  
Old 11 June 2018, 00:53   #124
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 35
Posts: 2,957
NEW QUESTION.

What's the MAX value of VPOS?
Shatterhand is offline  
Old 13 June 2018, 13:35   #125
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 328
Quote:
What's the MAX value of VPOS?
I quickly tested this and seems like the highest value is 311. And I think the values higher than 256 (or 255 since 0 counts as a value too) are always outside the normal display height of 256.
Master484 is offline  
Old 19 June 2018, 12:24   #126
AlfaRomeo
A1200 040 SAM440EP 667
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 793
When an event calls the next statement it keeps generating sequences all the time.
Is there a easy way to make the statement generate only one sequence and then stop generating more?

Code:
Statement rndKey{}
alpha$="ABCDEFGHIJKLMNOPQRSTYUVWXZabcdefghijklmnopqrstyuvwxz#/+=0123456789"

Dim s$(Len(alpha$))
Dim p$(20)

For x=0 To Len(alpha$)
  s$(x)=Mid$(alpha$,x,1)
Next

For i=0 To 19
  p$(i)=s$(Rnd(66))
  pass$=pass$+ p$(i)
Next

MUISet 3, #MUIA_ShowMe, 1 : MUISetString 3, "Generated key> "+pass$
End Statement
AlfaRomeo is offline  
Old 19 June 2018, 12:34   #127
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,318
Do you mean, only generate a pass$ string once, then keep them for the rest of the program's run? You need to make the pass$ variable global, then check if the string contains any characters, and only generate the random characters if it doesn't. Something like this:

Code:
pass$ = ""

Statement rndKey{}
SHARED pass$

If pass$ = ""

  alpha$="ABCDEFGHIJKLMNOPQRSTYUVWXZabcdefghijklmnopqrstyuvwxz#/+=0123456789"

  Dim s$(Len(alpha$))
  Dim p$(20)

  For x=0 To Len(alpha$)
    s$(x)=Mid$(alpha$,x,1)
  Next

  For i=0 To 19
    p$(i)=s$(Rnd(66))
    pass$=pass$+ p$(i)
  Next

End If

MUISet 3, #MUIA_ShowMe, 1 : MUISetString 3, "Generated key> "+pass$
End Statement
Daedalus is offline  
Old 19 June 2018, 21:13   #128
AlfaRomeo
A1200 040 SAM440EP 667
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 793
Hi Daedalus, thanks for your help again.

I mean "freeze" the statement and keep the 1st pass$ until a MUICycle is changed.

I want to keep the pass$ to the rest of the program, but as the statement will be selected by a MUICycle gadget (outside statement), the statement will keep generating new pass$´s while the cycle gadget where keeped in the same choice.
That will be slowing down the computer and, when showing a MUIString with the pass$ inside the statement it will be mutating all the time.
AlfaRomeo is offline  
Old 19 June 2018, 23:04   #129
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,318
Well, I think my suggestion might be what you're looking for in that case. It will only run the generation code the first time it's needed.
Daedalus is offline  
Old 19 June 2018, 23:51   #130
AlfaRomeo
A1200 040 SAM440EP 667
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 793
If you run this code (including already your suggestion), and change the MUICycle and go to see the console output you will see that the statement generates many passwords.
Anyway, I think your suggestion it´s the best bet, thanks


Code:
optimize 7

; Set some application properties
MUIApplicationTitle "3ncrYptor"
MUIApplicationDescription "MUI encrypter/Decrypter program"

pass$=""

Statement rndKey{}
SHARED pass$
alpha$="ABCDEFGHIJKLMNOPQRSTYUVWXZabcdefghijklmnopqrstyuvwxz#/+=0123456789"

Dim s$(Len(alpha$))
Dim p$(20)

For x=0 To Len(alpha$)
  s$(x)=Mid$(alpha$,x,1)
Next

For i=0 To 19
  p$(i)=s$(Rnd(66))
  pass$=pass$+ p$(i)
Next

MUISet 3, #MUIA_ShowMe, 1 : MUISetString 3, "Generated key> "+pass$

NPrint pass$
End Statement


Statement noRnd{}

  MUISet 2, #MUIA_ShowMe, 1 : teste$=MUIGetString$(2)
;  MUIFreeObject 3

End Statement

success.l=0
myChoice.l=False
cy.l=0

;NoCli
WBStartup
FindScreen 0

Dim PageName$(2)

PageName$(0)="3ncrYpter"
PageName$(1)="d3crypt3r"

MUILabel 0,"Generate a random key?",#MUIO_Label_DoubleFrame
MUICycle 1,"Rnd key","Yes","No"
MUIString 2,"Enter key",10 : MUISet 2, #MUIA_ShowMe, 0
MUIString 3,"",37 : MUISet 3, #MUIA_ShowMe, 0
MUIHSpace 4,60


MUIAddObjsHGroup 6,0,1
MUICreateHGroup 6

MUIAddObjsHGroup 7,2,3,4
MUICreateHGroup 7

MUIAddObjsVGroup 8,6,7
MUICreateVGroup 8

MUIAddObjsPage 10,8
MUICreatePage 10,"3ncrYpt3r","d3crYpt3r"

MUICreateWindow 11,"crYpt3r","PAGE",10
MUIAddSubWindow 11

If MUICreateApplication <> True Then End

MUINotifyApp 11,#MUIA_Window_CloseRequest,1,-11


success=MUIOpenWindow(11)

Repeat
  ev.l=MUIWaitEvent
  Select ev
    Case myChoice
      cy=MUIGetCycle(1)
      If cy=1 Then rndKey{}
      If cy=2 Then noRnd{}
    End Select
Until ev=-11

MUICloseWindow 11

End
AlfaRomeo is offline  
Old 20 June 2018, 00:35   #131
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 661
Code:
PaletteRange Palette#,StartCol,EndCol,r0,g0,b0,r1,g1,b1 

PaletteRange creates a spread of colors within a palette. Similar to DPaint's spread
function PaletteRange takes a start and end colour and creates the color tweens
between them.
Does this work for anyone? I just get black in all the colour registers. I've gone as far as writing my own RGB interpolation function (which, sadly, I just lost because I didn't press save) but surely there must be a way of getting this to work.
E-Penguin is offline  
Old 20 June 2018, 00:58   #132
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,318
Quote:
Originally Posted by E-Penguin View Post
Does this work for anyone? I just get black in all the colour registers. I've gone as far as writing my own RGB interpolation function (which, sadly, I just lost because I didn't press save) but surely there must be a way of getting this to work.
Hmmm, I was never able to get it to work either, and if you print out the palette values, you can see they haven't changed too, which means it's not just a case of the palette updates not being applied to the screen. I've written my own routine in the past too for this...
Daedalus is offline  
Old 20 June 2018, 01:06   #133
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 661
Glad it's not just me then! I'll post my version here once I'm done with it.

Out of interest did you convert to HSV colour space? Google suggests it might give nicer colour transitions.
E-Penguin is offline  
Old 20 June 2018, 01:18   #134
Dunny
Registered User

Dunny's Avatar
 
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,068
Wait. Just wait a minute. Why is nobody talking about this?

Quote:
Originally Posted by E-Penguin View Post
The concept is "asteroids using pictures of actual asteroids from spacecraft I have flown"
I mean, come on...
Dunny is offline  
Old 20 June 2018, 01:20   #135
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,318
No, it was just a very straightforward RGB spread using floats. I dug out the code there but it's not particularly elegant since it uses other functions for actually storing the values. HSL might indeed give better results - that conversion's a little more involved of course, and I'm not sure the subtleties would be even captured on ECS with only 4 bits per gun.
Daedalus is offline  
Old 20 June 2018, 01:44   #136
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 661
Quote:
Originally Posted by Dunny View Post
Wait. Just wait a minute. Why is nobody talking about this?
Well some pictures are of a comet, but one has to take what one can get. Maybe phobos too if I can find a nice pic.

Quote:
Originally Posted by Daedalus View Post
No, it was just a very straightforward RGB spread using floats. I dug out the code there but it's not particularly elegant since it uses other functions for actually storing the values. HSL might indeed give better results - that conversion's a little more involved of course, and I'm not sure the subtleties would be even captured on ECS with only 4 bits per gun.
RGB interpolation tends to go through a grey phase which is less visually appealing. I'll write both versions tomorrow.
E-Penguin is offline  
Old 20 June 2018, 12:34   #137
Dunny
Registered User

Dunny's Avatar
 
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,068
Quote:
Originally Posted by E-Penguin View Post
Well some pictures are of a comet, but one has to take what one can get. Maybe phobos too if I can find a nice pic.
Nonononono! I was referring to this:

Quote:
from spacecraft I have flown
What are you not telling us?
Dunny is offline  
Old 20 June 2018, 13:03   #138
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 661
I fly interplanetary spacecraft for the European Space Agency as a day job. It's a lot like working with vintage hardware but in SPAAAAAAAAAAAAAAAAAACE
E-Penguin is offline  
Old 20 June 2018, 14:27   #139
Dunny
Registered User

Dunny's Avatar
 
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,068
And here I was thinking I was mad, but no - people are actually thinking that BB is more important than this. We have a real life rocket ship pilot in our midst.

Jeez, I love this place.
Dunny is offline  
Old 20 June 2018, 14:46   #140
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,318
Hehe, in my defence, I already knew about that
Daedalus is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Blitz basic 2 Help Havie Coders. Blitz Basic 30 08 September 2013 09:15
blitz basic petza request.Apps 11 08 April 2007 01:49
Blitz Basic 2 anyone? jobro request.Apps 12 28 November 2005 18:15
Blitz Basic StopCD32 Tony Landais Coders. General 2 08 May 2003 22:51
Blitz Basic 2 LaundroMat Retrogaming General Discussion 5 24 July 2001 08:10

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:55.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.10078 seconds with 14 queries