![]() |
![]() |
#21 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,965
|
Not maybe, definitely.
That's quite a shame, because they're quite important. Quote:
Code:
move.l #123,d0 bsr subroutine subroutine movem.l d1,-(sp) move.l d0,d1 lsl.l #1,d0 add.l d1,d0 movem.l (sp)+,d1 rts |
|
![]() |
![]() |
#22 |
Registered User
Join Date: May 2023
Location: Norwich
Posts: 530
|
I'm not convinced that will actually make any difference at all in terms of code efficiency. GOSUB is essentially just a synonym for JSR. It only makes a difference with functions/procedures because you're removing the overhead of passing parameters etc, which you could just as "easily" do by converting them to GOSUBs (obviously all the problems of using global variables to manage shared data would then exist).
|
![]() |
![]() |
#23 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
Yep, there's an overhead involved in using functions. If you're using AmiBlitz, you can specify a FAST keyword when defining a function. This makes them a bit faster, but imposes some limitations like not initialising local variables to 0 and not being able to pass strings as parameters. Goto and Gosub are much more efficient - as said, they compile to pretty simple jumps, at the expense of the code modularity and organisation.
I haven't benchmarked it, but if you're looking for more condensed code, Blitz also supports the On version of Goto / Gosub from other Basics. You can jump to a number of labels based on a value, starting from 1. For your code: Code:
If WHATEVENT= $40 AND EventWindow = mywindow ; Do something if gadget is selected/hit On GadgetHit - 49 Gosub HITSEARCHBOX, HITSEARCHBUTT, HITDESTBOX, HITDESTBUTT, HITEXTRACTTYPE EndIf |
![]() |
![]() |
#24 |
Registered User
Join Date: Jan 2005
Location: UmeƄ
Age: 44
Posts: 962
|
Is the potential performance overhead of a function call relevant in this case? It looks like it will spend most time waiting on events here.
Had it been an hot inner loop of some computational function, it would be more relevant to worry about calling functions or jumping. |
![]() |
![]() |
#25 | |
Registered User
Join Date: Oct 2021
Location: England
Posts: 1,330
|
Quote:
yeah i dont ever call the gadget numbers directly, they are all preassigned numbers at the beginning of the program starting at 50 and work up from there in 1's, so at the beginning for example i start with #_SEARCHBOX=50, and every time i need to refer to the button this equates to i refer to it as #_SEARCHBOX rather than a hard/fixed 50, just makes it easier for me when i see a load of GT-Gadget commands using those named tags instead of numbers. Code:
GTString mywindow,#_SEARCHBOX,0,0,LRSIZE,GADHEIGHT,"",$0,256,SRCHTXT$ Code:
GTString mywindow,50,0,0,LRSIZE,GADHEIGHT,"",$0,256,SRCHTXT$ but that "On" solution again looks perfect for what i want, ill try and use that for my 2 main projects. |
|
![]() |
![]() |
#26 |
Registered User
Join Date: Oct 2021
Location: England
Posts: 1,330
|
This is at the start of my GUI for UHC Tools, not a massive amount of gadgets but its how i refer to them rather than fixed numbers, my other program uses significantly more gadgets/number id's.
Code:
; Gadget Identifier List ; Row 1 of gadgets #_SEARCHBOX = 50 #_SEARCHBUTT = 51 #_DESTBOX = 52 #_DESTBUTT = 53 #_EXTRACTTYPE = 54 ; Row 2 of gadgets #_DOWNLOADBUTT = 55 #_CLEARSEARCHBUTT = 56 #_RECENTUPLOADBUTT = 57 #_VIEWREADMEBUTT = 58 #_MIRRORLISTCYCLE = 59 ; Row 3 HeaderText #_HEADERTEXT = 60 ; Row 4 of gadgets - Listviews #_SEARCHRESULTLIST = 61 #_MIRRORLIST = 62 #_CATEGORYLIST = 63 #_UPDATEWATCHER = 64 ; Row 5 of gadgets - Info bar #_INFOTEXT = 65 |
![]() |
![]() |
#27 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
Yep, using constants definitely makes code more readable and is something that should be encouraged. The thing to bear in mind is that the On form of Gosub effectively does use gadget numbers directly, so if the constants ever change in the future you might have unexpected results from the jump. But so long as you don't change them, it should work fine.
|
![]() |
![]() |
#28 |
Registered User
Join Date: Oct 2021
Location: England
Posts: 1,330
|
noted, cheers.
|
![]() |
![]() |
#29 | |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
Quote:
casestatement entirely. I guess this is more or less what's going on here. I don't know if it's possible to do function pointers in blitz? maybe with some embedded asm or something hacky. |
|
![]() |
![]() |
#30 | |
Registered User
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 2,184
|
Quote:
|
|
![]() |
![]() |
#31 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
Yeah, I don't think you can do that with the standard Blitz commands, but you can jump to an address with a JMP or JSR. The addresses of program labels can be found using a question mark:
myAddress.l = ?myLabel |
![]() |
![]() |
#32 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,381
|
You can use a self-modifying macro to create an enumeration automatically.
Then you can use a macro to make a label for your Gosub matching the ID generated by the macro. |
![]() |
![]() |
#33 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
Ooh, that sounds very clever, I must try it out some time.
|
![]() |
![]() |
#34 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,381
|
There is also the CNAME ~expression~ feature to help out with this.
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Probably a dumb question about the aca1232 | source | Hardware mods | 4 | 05 March 2019 18:47 |
Dumb Question but need help with printers | source | support.Apps | 2 | 04 June 2015 06:21 |
Probably a dumb question.. | xlar54 | support.Other | 6 | 03 January 2010 21:20 |
Question from a dumb American. | illy5603 | support.Hardware | 43 | 19 September 2009 00:27 |
Probably a really dumb question... | BumpyCarrot | New to Emulation or Amiga scene | 3 | 28 February 2003 02:04 |
|
|