English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 12 February 2014, 20:06   #1
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Pragmas in SAS/C

Hi, I'm trying to compile the following (using SAS/C 6.58):

Code:
#include <dos/dos.h>
#include <intuition/intuitionbase.h>
#include <pragma/exec_lib.h>
#include <pragma/dos_lib.h>
#include <pragma/intuition_lib.h>
#include <stdlib.h>
#include <stdio.h>

extern struct IntuitionBase* IntuitionBase;

extern APTR MyOpenWindow;
extern APTR OrigOpenWindow;
extern volatile struct Screen* MyOpenWindowScreen;

LONG LVOOpenWindow = -204;

struct TextAttr topaz8 =
{
    "topaz.font",
    8, 0, 0
};

struct NewScreen newscreen =
{
    0,            //    WORD                    LeftEdge;
    0,            //    WORD                    TopEdge;
    640,          //    WORD                    Width;
    256,          //    WORD                    Height;
    2,            //    WORD                    Depth;
    0,            //    UBYTE                    DetailPen;
    1,            //    UBYTE                    BlockPen;
    HIRES,        //    UWORD                    ViewModes;
    CUSTOMSCREEN, //    UWORD                    Type;
    &topaz8,      //    struct TextAttr *    Font;
    "ScreenCON",   //    UBYTE *                DefaultTitle;
    0,            //    struct Gadget *    Gadgets;
    0             //    struct BitMap *    CustomBitMap;
};

int main(int argc, char* argv[])
{
    if(IntuitionBase->LibNode.lib_Version >= 36)
    {
        puts("This program does not run on AmigaOS2.0 and above!");
        exit(RETURN_FAIL);
    }
    
    if((MyOpenWindowScreen = OpenScreen(&newscreen)))
    {
        OrigOpenWindow = SetFunction
        (
            (struct Library*)IntuitionBase,
            LVOOpenWindow,
            (ULONG(*)())MyOpenWindow
        );
    
        Execute("NewShell", 0, 0);
    
        SetFunction
        (
            (struct Library*)IntuitionBase,
            LVOOpenWindow,
            (ULONG (*)())OrigOpenWindow
        );
    
        for(;;)
        {
            Delay(50);
            if(!MyOpenWindowScreen->FirstWindow)
            {
                break;
            }
        }
        CloseScreen((struct Screen*)MyOpenWindowScreen);
        
        exit(RETURN_OK);
    }
    
    exit(RETURN_ERROR);
}
Now, SAS/C does not have such pragmas. However, instead of "pragma/exec_lib.h" it has "pragmas/exec_pragmas.h", same for the others.

But if i substitute these I get the following error:

Code:
Error 9 in screencon.c line 57: undefined identifier "DOSBase"
(and a couple of warnings). Can anyone help me compile this?
marduk_kurios is offline  
Old 12 February 2014, 22:00   #2
aragon
Registered User
 
aragon's Avatar
 
Join Date: Aug 2003
Location: hamburg
Posts: 56
Seems that it's too long ago for me to remember this, but I tried this:
Code:
[...]
//#include <pragma/exec_lib.h>
//#include <pragma/dos_lib.h>
//#include <pragma/intuition_lib.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
[...]
At least I could compile it, but the linker failed due to the external references.
Code:
SAS/C Amiga Compiler 6.59
Copyright (c) 1988-1995 SAS Institute Inc.
Slink - Version 6.59
Copyright (c) 1988-1995 SAS Institute, Inc.  All Rights Reserved.

Undefined symbols        First Referenced
_MyOpenWindowScreen      File 'test.o'
Enter a DEFINE value for _MyOpenWindowScreen (default ___stub): _OrigOpenWindow          File 'test.o'
Enter a DEFINE value for _OrigOpenWindow (default ___stub): _MyOpenWindow            File 'test.o'
Enter a DEFINE value for _MyOpenWindow (default ___stub): Error 510: _MyOpenWindowScreen symbol - Near Reference to data item not in near data section

  First Reference in Unit test.c at offset 00000010 in file 'test.o'
  To Unit _stub.c at offset 000089a0 in file 'LIB:sc.lib'
Perhaps this helps you to resolve the rest...
aragon is offline  
Old 12 February 2014, 22:21   #3
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Thank you, good sir. That helped, it now compiles. However, The linker has undefined symbols:




That is probably why it does not work right. It does open a screen and also opens a shell - as it should. But the shell is attached to the Workbench screen, not the screencon screen.

I have a binary that works, but the friend who helped me is offline now. I will ask him when he is back.
marduk_kurios is offline  
Old 13 February 2014, 09:00   #4
aragon
Registered User
 
aragon's Avatar
 
Join Date: Aug 2003
Location: hamburg
Posts: 56
Nice to see it's slowly coming to life. Can you post the complete sources including the makefile? What are you trying to achieve? Is this some code example that's working with a different compiler or something you built on your own?
aragon is offline  
Old 13 February 2014, 20:36   #5
aragon
Registered User
 
aragon's Avatar
 
Join Date: Aug 2003
Location: hamburg
Posts: 56
BTW, why are the global vars declared as extern? If you remove that keyword, it will link nicely...
aragon is offline  
Old 13 February 2014, 22:31   #6
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Thanks, but I have a working version now. FWIW, as follows:

Code:
screencon.c:

#include <dos/dos.h>
#include <intuition/intuitionbase.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <stdlib.h>
#include <stdio.h>

#ifdef __SASC
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#endif

#ifdef __MAXON__
#include <pragma/exec_lib.h>
#include <pragma/dos_lib.h>
#include <pragma/intuition_lib.h>
#endif

struct IntuitionBase* IntuitionBase = 0;

extern APTR MyOpenWindow;
extern APTR OrigOpenWindow;
extern struct Screen* MyOpenWindowScreen;

LONG LVOOpenWindow = -204;

struct TextAttr topaz8 =
{
    "topaz.font",
    8, 0, 0
};

struct NewScreen newscreen =
{
    0,            /* WORD                    LeftEdge      */
    0,            /* WORD                    TopEdge       */
    640,          /* WORD                    Width         */
    200,          /* WORD                    Height        */
    2,            /* WORD                    Depth         */
    0,            /* UBYTE                    DetailPen     */
    1,            /* UBYTE                    BlockPen      */
    HIRES,        /* UWORD                    ViewModes     */
    CUSTOMSCREEN, /* UWORD                    Type          */
    &topaz8,      /* struct TextAttr *    Font              */
    "ScreenCON",  /* UBYTE *                DefaultTitle      */
    0,            /* struct Gadget *    Gadgets           */
    0             /* struct BitMap *    CustomBitMap      */
};

int main(int argc, char* argv[])
{
    int res;
    LONG exec;
    struct Screen wbench;
    WORD top;
    char command[128];
    
    if(!(IntuitionBase = (struct IntuitionBase*)OpenLibrary("intuition.library", LIBRARY_MINIMUM)))
    {
        puts("Could not open intuition.library");
        res = RETURN_FAIL;
        goto cleanexit;
    }
    
    if(IntuitionBase->LibNode.lib_Version >= 36)
    {
        puts("This program does not run on AmigaOS2.0 and above!");
        res = RETURN_FAIL;
        goto cleanexit;
    }
    
    if(GetScreenData(&wbench, sizeof(wbench), WBENCHSCREEN, 0))
    {
        newscreen.LeftEdge = wbench.LeftEdge;
        newscreen.TopEdge = wbench.TopEdge;
        newscreen.Width = wbench.Width;
        newscreen.Height = wbench.Height;
        newscreen.Depth = wbench.RastPort.BitMap->Depth;
        newscreen.Font = wbench.Font;
    }
    
    if((MyOpenWindowScreen = OpenScreen(&newscreen)))
    {
        top = MyOpenWindowScreen->WBorTop + MyOpenWindowScreen->Font->ta_YSize + 1;
        sprintf(command, "NewShell NEWCON:0/%d/%d/%d/ScreenCON From S:Shell-Startup", top, MyOpenWindowScreen->Width, MyOpenWindowScreen->Height - top);
        
        OrigOpenWindow = SetFunction
        (
            (struct Library*)IntuitionBase,
            LVOOpenWindow,
            (ULONG(*)())MyOpenWindow
        );
        
        exec = Execute(command, 0, 0);
        
        SetFunction
        (
            (struct Library*)IntuitionBase,
            LVOOpenWindow,
            (ULONG (*)())OrigOpenWindow
        );
        
        if(exec == DOSFALSE)
        {
            printf("%s failed: #%d\n", command, IoErr());
            res = RETURN_ERROR;
        }
        else
        {
            res = RETURN_OK;
        }
        
        for(;;)
        {
            Delay(50);
            if(!MyOpenWindowScreen->FirstWindow)
            {
                break;
            }
        }
    }
    else
    {
        res = RETURN_ERROR;
    }
    
cleanexit:
    if(MyOpenWindowScreen)
    {
        CloseScreen(MyOpenWindowScreen);
        MyOpenWindowScreen = 0;
    }
    
    if(IntuitionBase)
    {
        CloseLibrary((struct Library*)IntuitionBase);
        IntuitionBase = 0;
    }
    
    exit(res);
}





MyOpenWindow.asm:

    XDEF    _MyOpenWindow
    XDEF    _OrigOpenWindow
    XDEF    _MyOpenWindowScreen
    
    include    "intuition/intuition.i"
    
    section code
    
MyOpenWindow:
    move.l    _MyOpenWindowScreen,nw_Screen(a0)
    move.l    #WFLG_BORDERLESS|WFLG_NOCAREREFRESH|WFLG_SMART_REFRESH|WFLG_ACTIVATE,nw_Flags(a0)
    move.l    #0,nw_Title(a0)
    move.w    #CUSTOMSCREEN,nw_Type(a0)
    movea.l    _OrigOpenWindow,a1
    jsr    (a1)
    rts
    
    cnop    0,4

_OrigOpenWindow:
    dc.l    0

_MyOpenWindow:
    dc.l    MyOpenWindow

_MyOpenWindowScreen:
    dc.l    0
    
    dc.b    0,'$VER: ScreenCON 1.0 (13.02.14) Kai Scherrer <kai@kaiiv.de>',0
    
    end





smakefile:


ScreenCON : ScreenCON.o MyOpenWindow.o
    sc link ScreenCON.o+MyOpenWindow.o

ScreenCON.o : ScreenCON.c
    sc data=far ANSI OBJNAME ScreenCON.o STRICT ScreenCON.c

MyOpenWindow.o : MyOpenWindow.asm
    sc MyOpenWindow.asm
marduk_kurios is offline  
Old 14 February 2014, 12:21   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
The proto headers are not only used by SAS/C, but by all modern Amiga compilers (gcc, vbcc, StormC, etc.). And including a proto-header also includes the declarations from clib, so you don't need to specify them additionally.
phx is offline  
Old 14 February 2014, 12:58   #8
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Quote:
Originally Posted by phx View Post
The proto headers are not only used by SAS/C, but by all modern Amiga compilers (gcc, vbcc, StormC, etc.). And including a proto-header also includes the declarations from clib, so you don't need to specify them additionally.
I'm beginning to understand includes a little bit better. Also woop (german forum) helped me quite a bit as we idle in the same irc channel for decades. Well, almost two [if you look closely, he has credited himself in the source]

Still, I have to read a bit more. I'm still not really sure what the difference between the different include types are. Some C source includes "/pragma/" while SAS/C has "pragmas". But actually you need "proto"... That's not really intuitive...
marduk_kurios is offline  
Old 14 February 2014, 14:13   #9
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,351
Quote:
Originally Posted by marduk_kurios View Post
Thanks, but I have a working version now. FWIW, as follows:
Now that is an ingenious/evil hack!

For a more legal way to get a CLI/Shell on a custom screen under Kickstart 1.x, check out Commodore's example program here. With that, you open your own screen and window and "attach" a CON: handler to the window.
mark_k is offline  
Old 14 February 2014, 14:22   #10
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Quote:
Originally Posted by mark_k View Post
Now that is an ingenious/evil hack!
Yes, woop said that it is a bit nasty to change the function

Quote:
For a more legal way to get a CLI/Shell on a custom screen under Kickstart 1.x, check out Commodore's example program here. With that, you open your own screen and window and "attach" a CON: handler to the window.
Thanks, I will check it out.
marduk_kurios is offline  
Old 14 February 2014, 14:26   #11
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
Quote:
Originally Posted by marduk_kurios View Post
Some C source includes "/pragma/" while SAS/C has "pragmas". But actually you need "proto"... That's not really intuitive...
Most compilers have two methods to call OS functions:

1. Through a stub function from amiga.lib.
The stub function reads the arguments from the stack, puts them into the appropriate registers, loads the library base into A6 and performs the OS call. You only need to include clib/libname_protos.h for that.

2. Optionally through a compiler-specific direct interface.
Some use #pragma directives (SAS/C, Maxon, StormC), some use assembler inlines (vbcc, gcc) and others something even different.
This method is much faster, because the compiler places the arguments directly into the right registers and executes an inline OS-call, without using a stub function from amiga.lib.

As those fast inline OS-call methods are compiler specific they are defined in different paths like pragma, pragmas, inline, etc.. But all (most) compilers have in common hat <proto/libname.h> can be used to include the correct, compiler-specific files.

Always use proto to keep your source portable. Or clib (without proto) if you want to use stubs from amiga.lib instead of inline calls.
phx is offline  
Old 14 February 2014, 14:44   #12
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Thanks, phx. That actually helps a lot. Is there any good (free) reading material you can recommend on this topic?
marduk_kurios is offline  
Old 14 February 2014, 22:15   #13
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
Not free, but Ralph Babel's The Amiga Guru Book handles these topics very extensively.
phx is offline  
Old 14 February 2014, 23:02   #14
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Thanks
marduk_kurios is offline  
Old 15 February 2014, 00:17   #15
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 763
Thanks phx for that info. Im learning C too and always include protos but didnt understand why pragmas/inline/protos etc etc...
tolkien is offline  
Old 15 February 2014, 10:59   #16
aragon
Registered User
 
aragon's Avatar
 
Join Date: Aug 2003
Location: hamburg
Posts: 56
Quote:
Originally Posted by marduk_kurios View Post
Thanks, phx. That actually helps a lot. Is there any good (free) reading material you can recommend on this topic?
This sheds some light on the subject:
http://daniel.haxx.se/stuff/LIBRARY.TXT

The other helpful link I found is only available in German:
http://serpens.de/~zza/amigafaq/AmigaFAQg_32.html (Automatic translation might help here...)

And of course, you should refer to the SAS/C manual.
aragon is offline  
Old 15 February 2014, 16:28   #17
marduk_kurios
move $dff006,$dff180
 
marduk_kurios's Avatar
 
Join Date: Feb 2014
Location: USA
Posts: 66
Thanks for the links.

And yes, the SAS/C Manual should be read. It is very easy to understand, even for beginners. Just not the right material for differences on various compilers
marduk_kurios is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
SAS/C 6.58 on 1.3 marduk_kurios Coders. C/C++ 25 29 July 2018 18:17
SAS C v6.50 Avanaboy request.Apps 2 22 April 2012 02:48
SAS/C v6.50 zerostress request.Apps 3 08 October 2007 10:35
Sas C V 6.0 Jherek Carnelia request.Apps 1 20 March 2007 10:13
Sas C Scoglio request.Apps 0 28 October 2002 11:13

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:09.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10442 seconds with 13 queries