[68k] Storing a value into n?
<< < (2/5) > >>
Lionel Debroux:
Indeed, you're right, http://debrouxl.github.com/gcc4ti/htretval.html indicates that RETURN_VALUE can take an argument :)
I didn't remember about that capability, or even using it, but since I once compiled and ran all GCC4TI examples (finding and fixing several bugs inherited from TIGCC in the process), I did use it...

So I'm not sure at all why blue_bear_94's original code doesn't work...
TravisE:
Maybe you either need to push END_TAG before pushing your arguments or delete everything up to the END_TAG, or something like that. For instance, I had a very small program that returns the value of FiftyMsecTick (which I used for more precise timing in TI-BASIC programs) that looked like this:

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

/* Program creation date:  2007/04/23
   Compilation command used:  tigcc -O3 -Wall tick.c
*/

#define MIN_AMS 200
#define RETURN_VALUE tmrval

#include <args.h>
#include <estack.h>
#include <system.h>

void _main(void) {   
    // Return result:
    while (GetArgType (top_estack) != END_TAG)  // Clean up arguments
        top_estack = next_expression_index (top_estack);
    top_estack--;
    push_longint(FiftyMsecTick);
}


clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-1");clip.setText(StripHTML("/* Program creation date:  2007/04/23
   Compilation command used:  tigcc -O3 -Wall tick.c
*/

#define MIN_AMS 200
#define RETURN_VALUE tmrval

#include <args.h>
#include <estack.h>
#include <system.h>

void _main(void) {   
    // Return result:
    while (GetArgType (top_estack) != END_TAG)  // Clean up arguments
        top_estack = next_expression_index (top_estack);
    top_estack--;
    push_longint(FiftyMsecTick);
}
"))
I don't remember where I got the “clean up arguments” code, but I'm sure I pasted it from somewhere rather than figure out how to write it myself. :)

My other (very small test program) I could find like this added its own END_TAG, like this:

Code: Select All | Copy To Clipboard

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// Test routine--returns the string "Hello, world!"

#define RETURN_VALUE ret

#define USE_TI89

#include <args.h>
#include <estack.h>
#include <vat.h>

void _main(void)
{
  ESI argptr = top_estack;
  push_END_TAG ();
  push_zstr("Hello, world!");
}


clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-2");clip.setText(StripHTML("// Test routine--returns the string "Hello, world!"

#define RETURN_VALUE ret

#define USE_TI89

#include <args.h>
#include <estack.h>
#include <vat.h>

void _main(void)
{
  ESI argptr = top_estack;
  push_END_TAG ();
  push_zstr("Hello, world!");
}
"))
A quick test in TIEmu seemed to show that this program works.
blue_bear_94:
Quote from: Lionel Debroux on 03 June, 2012, 21:44:42

Indeed, you're right, http://debrouxl.github.com/gcc4ti/htretval.html indicates that RETURN_VALUE can take an argument :)
I didn't remember about that capability, or even using it, but since I once compiled and ran all GCC4TI examples (finding and fixing several bugs inherited from TIGCC in the process), I did use it...

So I'm not sure at all why blue_bear_94's original code doesn't work...

Well, since the modified code works, I'm going to use it. But I have another problem.
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

// 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);
}
short show_picvar (SYM_STR SymName, short x, short y, short Attr)
{
  SYM_ENTRY *sym_entry = SymFindPtr (SymName, 0);
  if (!sym_entry) return FALSE;
  if (peek (HToESI (sym_entry->handle)) != PIC_TAG) return FALSE;
  BitmapPut (x, y, HeapDeref (sym_entry->handle) + 2, ScrRect, Attr);
  return TRUE;
}
// 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.11);
break;
case 1:
SYM_STR name;
int x,y,attr;
a=GetArgType(argptr);
if (a!=STR_TAG)
{
DlgError("Arg 2 must be string");
return;
}
name=GetSymstrArg(argptr);
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("Arg 3 must be + int");
return;
}
x=GetIntArg(argptr);
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("Arg 4 must be + int");
return;
}
y=GetIntArg(argptr);
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("Arg 5 must be + int");
return;
}
attr=GetIntArg(argptr);
//*A_REVERSE, *A_NORMAL, *A_XOR, *A_SHADED, *A_REPLACE, *A_OR, *A_AND, A_THICK1, A_SHADE_V, A_SHADE_H, A_SHADE_NS, A_SHADE_PS
if (attr>=7)
{
DlgError("Wrong attribute");
return;
}
if (!show_picvar(name,x,y,attr))
{
DlgError("Pic does not exist");
}

}
}


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);
}
short show_picvar (SYM_STR SymName, short x, short y, short Attr)
{
  SYM_ENTRY *sym_entry = SymFindPtr (SymName, 0);
  if (!sym_entry) return FALSE;
  if (peek (HToESI (sym_entry->handle)) != PIC_TAG) return FALSE;
  BitmapPut (x, y, HeapDeref (sym_entry->handle) + 2, ScrRect, Attr);
  return TRUE;
}
// 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.11);
break;
case 1:
SYM_STR name;
int x,y,attr;
a=GetArgType(argptr);
if (a!=STR_TAG)
{
DlgError("Arg 2 must be string");
return;
}
name=GetSymstrArg(argptr);
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("Arg 3 must be + int");
return;
}
x=GetIntArg(argptr);
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("Arg 4 must be + int");
return;
}
y=GetIntArg(argptr);
a=GetArgType(argptr);
if (a!=POSINT_TAG)
{
DlgError("Arg 5 must be + int");
return;
}
attr=GetIntArg(argptr);
//*A_REVERSE, *A_NORMAL, *A_XOR, *A_SHADED, *A_REPLACE, *A_OR, *A_AND, A_THICK1, A_SHADE_V, A_SHADE_H, A_SHADE_NS, A_SHADE_PS
if (attr>=7)
{
DlgError("Wrong attribute");
return;
}
if (!show_picvar(name,x,y,attr))
{
DlgError("Pic does not exist");
}

}
}
"))produces an error "Expected expression before SYM_STR".
Edit: Fixed. However, I am trying to see if a list has any true entries; here is my code. What do you suggest?
Code: Select All | Copy To Clipboard

1
2
3
4
5
6
7
8
9
10
11
12
13

case 19:
a=GetArgType(argptr);
if (a!=LIST_TAG)
{
DlgError("Arg 2 must be list");
return;
}
temp3=argptr;
do
{
temp3=next_expression_index(temp3);
} while (!(*temp3==TRUE_TAG||*temp3==LIST_END_TAG||*temp3==END_TAG));
WriteToNBool(*temp3==TRUE_TAG);

clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-4");clip.setText(StripHTML("case 19:
a=GetArgType(argptr);
if (a!=LIST_TAG)
{
DlgError("Arg 2 must be list");
return;
}
temp3=argptr;
do
{
temp3=next_expression_index(temp3);
} while (!(*temp3==TRUE_TAG||*temp3==LIST_END_TAG||*temp3==END_TAG));
WriteToNBool(*temp3==TRUE_TAG);"))WriteToNBool is a function to write a Boolean value to n:
Code: Select All | Copy To Clipboard

1
2
3
4
5

void WriteToNBool(int n)
{
push_quantum(0x2B+!!n);
VarStore(SYMSTR("n"),STOF_ESI,0,top_estack);
}

clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-5");clip.setText(StripHTML("void WriteToNBool(int n)
{
push_quantum(0x2B+!!n);
VarStore(SYMSTR("n"),STOF_ESI,0,top_estack);
}"))
Lionel Debroux:
Quote

I don't remember where I got the “clean up arguments” code, but I'm sure I pasted it from somewhere rather than figure out how to write it myself. :)
Yup, for instance from one of the examples on the htretval.html page I linked above :)
I saw the snippet yesterday evening, but at the time, I didn't remember that GetIntArg and friends do not modify top_estack... So yeah, at a minimum, the code snippet from the first post needs to clean up the arguments, before pushing the result.

Code: Select All | Copy To Clipboard

1

while (!(*temp3==TRUE_TAG||*temp3==LIST_END_TAG||*temp3==END_TAG));

clip = new ZeroClipboard.Client();clip.setHandCursor( true );clip.glue("a-6");clip.setText(StripHTML("while (!(*temp3==TRUE_TAG||*temp3==LIST_END_TAG||*temp3==END_TAG));"))||*temp3==LIST_END_TAG is wrong for two reasons:
* programs are not supposed to see that internal tag from ExtTags when dealing with expressions - if they do, chances are that the calculator is in an unstable state;
* LIST_END_TAG has the same value as NEGINT_TAG (from Tags), so your code will spuriously store "true" to n if the list contains any negative integer.
=> retry without the middle comparison against LIST_END_TAG :)
blue_bear_94:
The problem is that false is always stored, even when there is a true entry in the argument list. Also this is supposed to be used with a Boolean list.
Navigation
Message Index
Next page
Previous page