[68k] Storing a value into n?
(1/5) > >>
blue_bear_94:
I have trouble with a library in the works. The code I am using is below:
Code: Select All | Copy To Clipboard

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

// C Source File
// Created 6/3/2012; 2:16:41 PM
// Decthyth General 68k Libraries
#include <tigcclib.h>
#define RETURN_VALUE n
void DlgError(const char* msg)
{
DlgMessage("Error",msg,BT_CANCEL,BT_NONE);
}
void WriteToNInt(long n)
{
push_longint(n);
}
void WriteToNFloat(float n)
{
push_Float(n);
}
// Main Function
/*
NOTE: When I say that a function returns a value,
I mean that the value is stored to n.
*/
void _main(void)
{
int mode;
unsigned char a;
ESI argptr=top_estack;
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("First arg must be + int");
return;
}
mode=GetIntArg(argptr);
switch (mode)
{
case 0:
WriteToNFloat(0.1);
}
}


clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-1");clip.setText(StripHTML("// C Source File
// Created 6/3/2012; 2:16:41 PM
// Decthyth General 68k Libraries
#include <tigcclib.h>
#define RETURN_VALUE n
void DlgError(const char* msg)
{
DlgMessage("Error",msg,BT_CANCEL,BT_NONE);
}
void WriteToNInt(long n)
{
push_longint(n);
}
void WriteToNFloat(float n)
{
push_Float(n);
}
// Main Function
/*
NOTE: When I say that a function returns a value,
I mean that the value is stored to n.
*/
void _main(void)
{
int mode;
unsigned char a;
ESI argptr=top_estack;
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("First arg must be + int");
return;
}
mode=GetIntArg(argptr);
switch (mode)
{
case 0:
WriteToNFloat(0.1);
}
}
"))When I compile this example and put in dcth(0):n, it just returns n (no value stored). Do you know what's wrong? Thanks in advance!
Lionel Debroux:
Code: Select All | Copy To Clipboard

1

#define RETURN_VALUE n

clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-2");clip.setText(StripHTML("#define RETURN_VALUE n"))Oh, it's not that simple: RETURN_VALUE is an argument-less macro :)

If you want to store data to a variable, you need to either use a high-level function such as VarStore, or do it the hard way, by building the variable yourself: HeapAlloc + SymAdd + etc. (lots of error checking), write the two size bytes, write the variable's contents (here, nine out of ten bytes from the float) and end tag (0x23 FLOAT_TAG).
blue_bear_94:
Fixed. I edited the code to
Code: Select All | Copy To Clipboard

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

// C Source File
// Created 6/3/2012; 2:16:41 PM
// Decthyth General 68k Libraries
#include <tigcclib.h>
//#define RETURN_VALUE n
void DlgError(const char* msg)
{
DlgMessage("Error",msg,BT_CANCEL,BT_NONE);
}
void WriteToNInt(long n)
{
push_longint(n);
VarStore(SYMSTR("n"),STOF_ESI,0,top_estack);
}
void WriteToNFloat(float n)
{
push_Float(n);
VarStore(SYMSTR("n"),STOF_ESI,0,top_estack);
}
// Main Function
/*
NOTE: When I say that a function returns a value,
I mean that the value is stored to n.
*/
void _main(void)
{
int mode;
unsigned char a;
ESI argptr=top_estack;
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("First arg must be + int");
return;
}
mode=GetIntArg(argptr);
switch (mode)
{
case 0:
WriteToNFloat(0.1);
break;
}
}


clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-3");clip.setText(StripHTML("// C Source File
// Created 6/3/2012; 2:16:41 PM
// Decthyth General 68k Libraries
#include <tigcclib.h>
//#define RETURN_VALUE n
void DlgError(const char* msg)
{
DlgMessage("Error",msg,BT_CANCEL,BT_NONE);
}
void WriteToNInt(long n)
{
push_longint(n);
VarStore(SYMSTR("n"),STOF_ESI,0,top_estack);
}
void WriteToNFloat(float n)
{
push_Float(n);
VarStore(SYMSTR("n"),STOF_ESI,0,top_estack);
}
// Main Function
/*
NOTE: When I say that a function returns a value,
I mean that the value is stored to n.
*/
void _main(void)
{
int mode;
unsigned char a;
ESI argptr=top_estack;
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("First arg must be + int");
return;
}
mode=GetIntArg(argptr);
switch (mode)
{
case 0:
WriteToNFloat(0.1);
break;
}
}
"))(again, thanks!)
Lionel Debroux:
That's the correct way to use VarStore, indeed :)
TravisE:
Quote from: Lionel Debroux on 03 June, 2012, 21:29:12

Code: Select All | Copy To Clipboard

1

#define RETURN_VALUE n

clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-4");clip.setText(StripHTML("#define RETURN_VALUE n"))Oh, it's not that simple: RETURN_VALUE is an argument-less macro :)

If you want to store data to a variable, you need to either use a high-level function such as VarStore, or do it the hard way, by building the variable yourself: HeapAlloc + SymAdd + etc. (lots of error checking), write the two size bytes, write the variable's contents (here, nine out of ten bytes from the float) and end tag (0x23 FLOAT_TAG).


The docs refer to using a variable name as an argument to RETURN_VALUE to automatically store the last value pushed to the expression stack to the variable, and I even seem to remember using this myself once. Has this changed?
Navigation
Message Index
Next page