0 Members and 2 Guests are viewing this topic.
// C Source File// Created 6/3/2012; 2:16:41 PM// Decthyth General 68k Libraries#include <tigcclib.h>#define RETURN_VALUE nvoid 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); }}
#define RETURN_VALUE n
// C Source File// Created 6/3/2012; 2:16:41 PM// Decthyth General 68k Libraries#include <tigcclib.h>//#define RETURN_VALUE nvoid 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; }}
Code: [Select]#define RETURN_VALUE nOh, 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).
/* 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);}
// 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!");}
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...
// C Source File// Created 6/3/2012; 2:16:41 PM// Decthyth General 68k Libraries#include <tigcclib.h>//#define RETURN_VALUE nvoid 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"); } }}
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);
void WriteToNBool(int n){ push_quantum(0x2B+!!n); VarStore(SYMSTR("n"),STOF_ESI,0,top_estack);}
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.
while (!(*temp3==TRUE_TAG||*temp3==LIST_END_TAG||*temp3==END_TAG));
case 19: a=GetArgType(argptr); if (a!=LIST_TAG) { DlgError("Arg 2 must be list"); return; } temp3=argptr - 1; // Skip the LIST_TAG do { temp3=next_expression_index(temp3); } while (!(*temp3==TRUE_TAG||*temp3==END_TAG)); WriteToNBool(*temp3==TRUE_TAG);
case 19: a=GetArgType(argptr); if (a!=LIST_TAG) { DlgError("Arg 2 must be list"); return; } temp3=argptr-1; while (!(*temp3==TRUE_TAG||*temp3==END_TAG||*temp3==LIST_START_TAG)); { temp3=next_expression_index(temp3); } WriteToNBool(*temp3==TRUE_TAG); break; case 20: a=GetArgType(argptr); if (a!=LIST_TAG) { DlgError("Arg 2 must be list"); return; } temp3=argptr-1; while (!(*temp3==FALSE_TAG||*temp3==END_TAG||*temp3==LIST_START_TAG)); { temp3=next_expression_index(temp3); } WriteToNBool(*temp3!=FALSE_TAG); break; case 21: a=GetArgType(argptr); if (a!=LIST_TAG) { DlgError("Arg 2 must be list"); return; } temp3=argptr-1; x=1; while (!(*temp3==TRUE_TAG||*temp3==END_TAG||*temp3==LIST_START_TAG)) { temp3=next_expression_index(temp3); x++; } WriteToNInt(x*(*temp3==TRUE_TAG));
FILE* WriteListToFilePtr(ESI temp){ int i=0,j=0;; long* u=NULL; if (!(u=malloc(32))) return NULL; clrscr();//! for(i=0;i<8;i++) { u[i]=GetIntArg(temp); printf("u[%d]=%ld\n",i,u[i]); } free(u); ngetchx();}
How does ARB_REAL_INT work?
Edit: Now I need to write from a TI-Basic list to a long array... solutions, anyone?