Opry99er Posted September 2, 2016 Share Posted September 2, 2016 CALL LIGHTBULB(J,O,Y) 1 Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 2, 2016 Author Share Posted September 2, 2016 I'm asking but I'm going to go try anyway to see what happens...Can you gosub out of a subprogram? I'm guessing yes of course, as long as you "return" to it. Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted September 2, 2016 Share Posted September 2, 2016 I'm asking but I'm going to go try anyway to see what happens... Can you gosub out of a subprogram? I'm guessing yes of course, as long as you "return" to it. That would defeat the purpose of a subroutine/function. If you could do that, it would defeat its portability. ...lee Quote Link to comment Share on other sites More sharing options...
+mizapf Posted September 2, 2016 Share Posted September 2, 2016 I'm asking but I'm going to go try anyway to see what happens... Can you gosub out of a subprogram? I'm guessing yes of course, as long as you "return" to it. There nothing to say against that. You could have two subprograms with a common routine both are sharing. You could then either pack that into another subroutine that you can CALL, or you GOSUB there. Quote Link to comment Share on other sites More sharing options...
+mizapf Posted September 2, 2016 Share Posted September 2, 2016 (edited) The difference between calls in Extended Basic and C++: #include <stdio.h> void subroutine(int first, int& second); int main() { int myvar = 42; int anotherone = 74; subroutine(myvar, anotherone); printf("Values are %d and %d\n", myvar, anotherone); } void subroutine(int first, int& second) { first = 13; second = 31; } $ g++ testref.cpp -o testref $./testref Values are 42 and 31 You see that in C++ the subroutine determines whether we have a call-by-value or a call-by-reference. Edited September 2, 2016 by mizapf Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 2, 2016 Share Posted September 2, 2016 On TIdBiT..... Just do this: Code In: //Tidbit source code for a toggle program //This program asks for user input, then toggles the screen //between blank and stars. CALL CLEAR:: CALL SCREEN(9) :: X=0 GOSUB MESSAGE // START is the main loop. we will be branching to other subs from here, but we will always returns // and we will always branch out. We can add as many comments as we want to anywhere we want // and they will not be stored in memory, especially because when we translate the code, it strips // all of it out and allows us to copy and paste only line numbers. START: GOSUB KEYCHECK IF X=1 THEN GOSUB STARS IF X=2 THEN GOSUB BLANK GOSUB MESSAGE GOTO START // "STARS" fills the screen with stars STARS: FOR I=1 TO 24 CALL HCHAR(I,1,42,32) NEXT I RETURN // "BLANK" blanks the screen out BLANK: FOR I=1 TO 24 CALL HCHAR(I,1,32,32) NEXT I RETURN // "MESSAGE" types the message "CLICK A BUTTON" MESSAGE: DISPLAY AT(24,5):"CLICK A BUTTON"; RETURN // "KEYCHECK" checks for any keypress, then returns back to the main loop to allow program // to continue. If no key is pressed, it holds here. KEYCHECK: CALL KEY(0,K,S) :: IF S<1 THEN KEYCHECK X=X+1 :: IF X>2 THEN X=1 RETURN Code Out: 100 CALL CLEAR:: CALL SCREEN(9) :: X=0 110 GOSUB 250 120 GOSUB 270 130 IF X=1 THEN GOSUB 170 140 IF X=2 THEN GOSUB 210 150 GOSUB 250 160 GOTO 120 170 FOR I=1 TO 24 180 CALL HCHAR(I,1,42,32) 190 NEXT I 200 RETURN 210 FOR I=1 TO 24 220 CALL HCHAR(I,1,32,32) 230 NEXT I 240 RETURN 250 DISPLAY AT(24,5):"CLICK A BUTTON"; 260 RETURN 270 CALL KEY(0,K,S) :: IF S<1 THEN 270 280 X=X+1 :: IF X>2 THEN X=1 290 RETURN 2 Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 2, 2016 Author Share Posted September 2, 2016 (edited) That would defeat the purpose of a subroutine/function. If you could do that, it would defeat its portability. ...lee Yes I get that. And portability is wonderful. I'm kind of working backwards. My ZOMBI game is already written. Mostly. So I want to get it done before I have to rewrite. It takes a real long time to load so with subprograms being left out of the pre-scan, I want to at least take advantage of that. I don't expect any of them to be portable outside of Zombi. For me to do a complete rewrite, the way I work, I'd have to print it out, literally use scissors and tape and pencil notes all over before I could attempt to rewrite it in text. And I'm not motivated more to do that than I am to get the game finished.Once the game is done, I won't be able to sleep until it is rewritten. And at that point I would kill any gosubs from subs and really tighten it all up nicely. I just started a little thing and am running with it but the performance and load times are killing the fun. Edited September 2, 2016 by Sinphaltimus Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 2, 2016 Author Share Posted September 2, 2016 The difference between calls in Extended Basic and C++: #include <stdio.h> void subroutine(int first, int& second); int main() { int myvar = 42; int anotherone = 74; subroutine(myvar, anotherone); printf("Values are %d and %d\n", myvar, anotherone); } void subroutine(int first, int& second) { first = 13; second = 31; } $ g++ testref.cpp -o testref $./testref Values are 42 and 31 You see that in C++ the subroutine determines whether we have a call-by-value or a call-by-reference. Yeah, I don't know C so looking at your C code is foreign to me. I get the structure and kind of what's going on but I still can't write C to get a result out of tidbit if that's what is required. Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 2, 2016 Author Share Posted September 2, 2016 On TIdBiT..... Just do this: Code In: //Tidbit source code for a toggle program //This program asks for user input, then toggles the screen //between blank and stars. CALL CLEAR:: CALL SCREEN(9) :: X=0 GOSUB MESSAGE // START is the main loop. we will be branching to other subs from here, but we will always returns // and we will always branch out. We can add as many comments as we want to anywhere we want // and they will not be stored in memory, especially because when we translate the code, it strips // all of it out and allows us to copy and paste only line numbers. START: GOSUB KEYCHECK IF X=1 THEN GOSUB STARS IF X=2 THEN GOSUB BLANK GOSUB MESSAGE GOTO START // "STARS" fills the screen with stars STARS: FOR I=1 TO 24 CALL HCHAR(I,1,42,32) NEXT I RETURN SNIP Code Out: 100 CALL CLEAR:: CALL SCREEN(9) :: X=0 110 GOSUB 250 120 GOSUB 270 130 IF X=1 THEN GOSUB 170 140 IF X=2 THEN GOSUB 210 SNIP 250 DISPLAY AT(24,5):"CLICK A BUTTON"; 260 RETURN 270 CALL KEY(0,K,S) :: IF S<1 THEN 270 280 X=X+1 :: IF X>2 THEN X=1 290 RETURN OK, that's making more sense to me because what you input is XB specific as far as commands, and I get structure - similar to how batch files are written in dos. Alright I may be able to use tidbit at some moment after all. When I have time to play around. Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 2, 2016 Share Posted September 2, 2016 It is XB 100%, ONLY no line numbers, and labels to label your subs or code segments. Syntax is exactly the same. 1 Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 2, 2016 Share Posted September 2, 2016 Oh, and you can use my BLANK code as your CALL CLEAR subroutine if you want. 1 Quote Link to comment Share on other sites More sharing options...
+InsaneMultitasker Posted September 2, 2016 Share Posted September 2, 2016 There nothing to say against that. You could have two subprograms with a common routine both are sharing. You could then either pack that into another subroutine that you can CALL, or you GOSUB there. You can GOSUB out of a sub program and execute code from within another subprogram or the main program, provided you do not use variables. You can GOTO and GOSUB into the main program with similar restrictions. You can even turn off prescan to trick the interpreter into accepting things like combining FOR..NEXT loops and IF..THEN statements. Good practices? Probably not 1 Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 2, 2016 Author Share Posted September 2, 2016 (edited) It's temporary. I feel like this game is more of a prototype and I want to see it through. I'm just slapping it together. I never really though it could evolve in to what it is becoming. So once I know I can do it, I'll go back and do it better. Edited September 2, 2016 by Sinphaltimus Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 2, 2016 Author Share Posted September 2, 2016 This is all great stuff. Before I can go just using subprograms, I better learn all the ins and outs first. I can't slowly convert my program. I'm running out of memory and I bet it's because of gosubbing out of subprograms with variables involved. So, back to my gosubs for now.There's gold in this topic. Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 3, 2016 Share Posted September 3, 2016 Have you optimized your character definitions and color calls yet? Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 3, 2016 Author Share Posted September 3, 2016 No. Quote Link to comment Share on other sites More sharing options...
sometimes99er Posted September 3, 2016 Share Posted September 3, 2016 It takes a real long time to load so with subprograms being left out of the pre-scan, I want to at least take advantage of that. I don't think they're left out of the pre-scan. Se attached. Top of "page 8". Quote Link to comment Share on other sites More sharing options...
Willsy Posted September 3, 2016 Share Posted September 3, 2016 I wrote a sprite designer in extended basic that uses sub programs for everything. It's on this board somewhere. I no longer have the code, unfortunately. Quote Link to comment Share on other sites More sharing options...
Willsy Posted September 3, 2016 Share Posted September 3, 2016 You can GOSUB out of a sub program and execute code from within another subprogram or the main program, provided you do not use variables. You can GOTO and GOSUB into the main program with similar restrictions. You can even turn off prescan to trick the interpreter into accepting things like combining FOR..NEXT loops and IF..THEN statements. Good practices? Probably not No! Don't do it! That would be utterly evil and guarantee you a place in hell. If two subs share some common code then make that common code a sub and CALL it, don't branch to it with a goto or gosub. I'm going to have nightmares about this tonight 2 Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 3, 2016 Author Share Posted September 3, 2016 I jumped the gun and delved straight in to sudprograms street about 80 of ny current project was written. With a complete understanding of it and preplanning, it quickly became a nightmare. So for the time being, I'm writing the rest as I started it, spaghetti code, bloat and all. I'll optimize as need until all core game Britannica are in place and working. At that time, I will take the time and plan the rewrite properly. I absolutely want to recompile with xb257 (maybe I got the name wrong) and then create a bin for fr99. I am aware of some Considerations line my if/then/else statements and the compiler. Are there other things I have to keep in mind if I want the recompile to work for me in regards to subprograms and the like? Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 3, 2016 Share Posted September 3, 2016 The compiler is one thing. XB256 is another. You can use XB256 to create your program and then compile it, IF your program conforms to the compiler's format requirements. XB256 is a pretty amazing piece of kit. as is the compiler. If you plan to compile, do yourself a favor and start reworking your code now to fit the compiler format. It is really tough to go backwards. 1 Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 3, 2016 Share Posted September 3, 2016 This is where TIdBiT becomes especially useful... 1 Quote Link to comment Share on other sites More sharing options...
Sinphaltimus Posted September 3, 2016 Author Share Posted September 3, 2016 (edited) I'm going to use my existing code as a reference and do a complete rewrite. When I dig in to that, I plan to use tidbit first. Will tidbit generate xb256 friendly code for compiling? Edited September 3, 2016 by Sinphaltimus Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 3, 2016 Share Posted September 3, 2016 It generates exactly the code you put in. But having the ability to write source code with labels makes the compiler-style coding a breeze. 1 Quote Link to comment Share on other sites More sharing options...
Opry99er Posted September 3, 2016 Share Posted September 3, 2016 You can add and insert as many pieces as you want to a section of code... No worries about line numbers or resequencing to fit more code in, etc. Just point the program to a label and it will translate all your free-form code into line numbers. Look at the example I posted. TIdBiT did not change any of my code... Just assigned it line numbers. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.