How would i do this on Saturn C?

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

Daniel Eriksson

New Member
Joined
May 5, 2001
Messages
602
Points
16
Website
server3002.freeyellow.com
How would i make this program in Saturn C? (with SGL)

If i push button C the program goes to line x and if i push Z it would go to line y. In basic it would look something like:

IF buttonpress = "X" THEN GOTO 10 ELSE GOTO 15

I don´t know much about Saturnprogramming yet, but i´ll try to learn! Please help me with this.
 

ExCyber

Staff member
Joined
Aug 8, 2001
Messages
4,014
Points
36
Age
37
You could do something like that in C, but it's not generally considered to be good programming practice; using function calls or a switch statement (or a combination of the two) would generally be preferable. In fact, some introductory texts on C don't cover the goto statement for this reason, even though there are cases where it is the cleanest way to transfer control (e.g. jumping out of a deep nested loop).

Here's what it would look like using the goto statement (these might not be 100% correct; my Saturn isn't hooked up for testing ATM and I'm not very familiar with SGL):

Code:
if (Smpc_Peripheral[0].data & PER_DGT_TC == 0) // C button is pressed

goto cbuttoncode;

else if (Smpc_Peripheral[0].data & PER_DGT_TZ == 0) // Z button is pressed

goto zbuttoncode;

cbuttoncode:

// Code for C button press goes here

zbuttoncode:

// Code for Z button press goes here
With this code however, you would have to use additional statements to make the button handling code terminate itself somehow, otherwise the program would just keep running past the end of the button code (but then again this behavior is similar to BASIC, so maybe it's what you want)

With function calls it would look like this:

Code:
if (Smpc_Peripheral[0].data & PER_DGT_TC)

CButtonPress();

else if (Smpc_Peripheral[0].data & PER_DGT_TZ)

ZButtonPress();

CButtonPress()

{

  // Code for C Button press goes here

}

ZButtonPress()

{

  // Code for C Button press goes here

}
The advantage of using function calls is that they will return to where the program was before, similar to a GOSUB in basic. Anyway, if you're tempted to use goto in a C program, I recommend reading more about C; it's designed so that you generally shouldn't have to use goto, and works better if you use the other program control statements/constructs. Also, the button constants are all listed in sl_def.h if you want to look them up.
 
Top