Ok, How do I learn to program?
  • Order of the Butterfly
    Order of the Butterfly
    r-tea
    Posts: 301 from 2005/3/27
    From: Poland, Zdzies...
    Look how easy is to make a simple MUI program with GUI.
    This is a window version of Hello World in C, with a little bit extra thing :-)
    It shows you a current system time thanks to Kai Hofmann's custom class Time and TimeText.
    I marked with bold the extra parts of code. The rest of code do nothing except of opening and closing window.
    This is the power of MUI :-)


    ----------------------------------------------------------------
    #include <stdio.h>

    #include <proto/exec.h>
    #include <proto/intuition.h>
    #include <proto/muimaster.h>



    #include <libraries/mui.h>
    #include <mui/Time_mcc.h>
    #include <mui/TimeText_mcc.h>



    BOOL running = TRUE;
    static APTR app, mainwindow;
    static APTR timetxt_gadget;


    BOOL initialize(void)
    {
    BOOL res = TRUE;

    if (!(MUIMasterBase = OpenLibrary ("muimaster.library", 16)))
    {
    printf ("MUI 3.5+ required.\n");
    res = FALSE;
    }
    return res;
    }


    APTR prepare_gui(void)
    {
    app = ApplicationObject,
    MUIA_Application_Title, "Time test",

    SubWindow, mainwindow = WindowObject,
    MUIA_Window_Title, "Time test",
    WindowContents,
    HGroup,
    Child, VGroup,
    Child, timetxt_gadget=TimeTextObject,
    End,

    End,
    End,
    End,
    End;

    return app;
    }


    int main ()
    {

    ULONG signal;
    BOOL running = TRUE;

    if (initialize())
    {
    if (prepare_gui())
    {
    SetAttrs (mainwindow, MUIA_Window_Open, TRUE, TAG_END);

    DoMethod(mainwindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
    DoMethod(timetxt_gadget, MUIM_Time_SetCurrent);

    while (running)
    {
    switch (DoMethod(app, MUIM_Application_Input, &signal))
    {
    case MUIV_Application_ReturnID_Quit:
    running = FALSE;
    break;
    }

    if (running && signal)
    Wait(signal);

    }
    SetAttrs (mainwindow, MUIA_Window_Open, FALSE, TAG_END);

    MUI_DisposeObject (app);
    }
    else printf("Error: Can't create MUIC_Application object!\n");
    }

    CloseLibrary (MUIMasterBase);
    return (0);
    }


    [ Edited by r-tea on 2010/6/20 22:16 ]
    Mac mini G4@1,5GHz silent upgrade + Xerox Phaser 3140 + EPSON Perfection 1240U
    Commodore C64C + 2 x 1541II + Datasette + SD-Box

    I miss draggable screens... and do you? I know I'm in a minority unfortunately.
  • »20.06.10 - 20:11
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    boot_wb
    Posts: 874 from 2007/4/9
    From: Kingston upon ...
    @Xyphoid

    I've just found this, which I'm currently working through. I've previously done around 9 months work with ANSI C (using Borland on PC), although it was some time ago, so am fairly familiar with some of the basic concepts and some of the functions. I'm finding it a valuable insight into the Amiga-specific challenges to programming C.

    This is aimed at Amiga OS3.x, so anything you compile should at least be able to run well under MorphOS.

    The author has obviously put a lot of hard work into it as a beginners tutorial, although a basic level of programming knowledge seems to be assumed.

    Additionally, this site has a hardfile available for UAE/WinUAE with GCC already installed, so is perfect for practicing on your laptop under an emulated environment.
    www.hullchimneyservices.co.uk

    UI: Powerbook 5,6 (1.67GHz, 128MB VRam): OS3.1, OSX 10.5.8
    HTPC: Mac Mini G4 (1,5GHz, 64MB VRam): OS3.1 (ZVNC)
    Audiophile: Efika 5200b (SB Audigy): OS3.1 (VNC + Virtual Monitor)

    Windows free since 2011!
  • »24.06.10 - 16:28
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    xyphoid
    Posts: 870 from 2008/7/11
    From: Delaware, USA
    @Boot_wb
    hey that's the same site I'm currently studing!!
    thanks for the additional site This some intimidating stuff!! :-?
  • »24.06.10 - 17:29
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    xyphoid
    Posts: 870 from 2008/7/11
    From: Delaware, USA
    I got a gcc package off luckysoft GCC 2.95.4-7. How or where do you place the components, and which ones?
    thanks!
  • »25.06.10 - 02:01
    Profile
  • Fab
  • MorphOS Developer
    Fab
    Posts: 1331 from 2003/6/16
    Just install the official SDK. GCC is supplied with it.
  • »25.06.10 - 03:53
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2053 from 2003/6/4
    @ r-tea

    just wanted to compile your example as a start to have a look into MUI, but am failing on first steps. What's gcc trying to tell me here about problems to reference MUIMasterBase?

    gcc -c -o o/gcc-morphos-stable/main.o main.c
    gcc o/gcc-morphos-stable/main.o -o bin/gcc-morphos-stable/MUI_Beispiel_Morphzone
    o/gcc-morphos-stable/main.o: In function `initialize':
    o/gcc-morphos-stable/main.o(.text+0x26): undefined reference to `MUIMasterBase'
    o/gcc-morphos-stable/main.o(.text+0x82): undefined reference to `MUIMasterBase'
    o/gcc-morphos-stable/main.o: In function `main':
    o/gcc-morphos-stable/main.o(.text+0x3b6): undefined reference to `MUIMasterBase'
    o/gcc-morphos-stable/main.o(.text+0x3ba): undefined reference to `MUIMasterBase'
    o/gcc-morphos-stable/main.o(.text+0x3f2): undefined reference to `MUIMasterBase'
    o/gcc-morphos-stable/main.o(.text+0x3f6): more undefined references to `MUIMasterBase' follow
    collect2: ld returned 1 exit status
    make: *** [bin/gcc-morphos-stable/MUI_Beispiel_Morphzone] Error 1

    Done.

    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »12.07.10 - 23:03
    Profile Visit Website
  • MorphOS Developer
    Henes
    Posts: 507 from 2003/6/14
    In your case, add a "-noixemul" argument every time you call gcc.

    i.e.
    gcc -noixemul -c -o o/gcc-morphos-stable/main.o main.c
    gcc -noixemul o/gcc-morphos-stable/main.o -o bin/gcc-morphos-stable/MUI_Beispiel_Morphzone

    [ Edited by Henes on 2010/7/13 1:26 ]
  • »12.07.10 - 23:25
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2053 from 2003/6/4
    @ Henes

    Thanks, worked then. Now I just need to fully understand the example...

    Am I right then that gcc includes ixemul.library by default? And why exactly the need to exclude it? Wouldn't it just introduce some not needed overhead?

    And how to include that -ixemul drirective inside the makefile?


    # makefile for GNU make (automatically generated by makemake)
    # NOTE: indent with TAB in GNU makefiles!

    # paths are relative to the project directory (current directory during make)

    EXE = bin/gcc-morphos-stable/MUI_Beispiel_Morphzone
    OBJDIR = o/gcc-morphos-stable/

    # compiler and linker

    CC = gcc
    LD = gcc

    # target 'all' (default target)

    all : $(EXE)

    $(OBJDIR)main.o : main.c
    $(CC) $(shell gccprefs) -noixemul -c -o $(OBJDIR)main.o main.c

    OBJS = $(OBJDIR)main.o

    $(EXE) : $(OBJS)
    $(LD) $(OBJS) $(shell gccprefs) -o $(EXE)

    # target 'strip'

    strip:
    strip --remove-section=.comment $(EXE)

    # target 'clean'

    clean:
    -delete $(EXE)
    -delete $(OBJDIR)\*.o


    I thought I needed to modify it just like that - but that seems to be wrong. Well, I am nore than noobish with these things, I more or less used VisualStudio only before for my crappy stuff and was happy that I didn't need to take too much care about makefules and stuff like that.
    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »13.07.10 - 00:57
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    r-tea
    Posts: 301 from 2005/3/27
    From: Poland, Zdzies...
    @ Zylesea
    I thought I needed to modify it just like that - but that seems to be wrong. Well, I am nore than noobish with these things, I more or less used VisualStudio only before for my crappy stuff and was happy that I didn't need to take too much care about makefules and stuff like that.

    I'm noobish too, so I don't like taking too much care about makefiles etc too. I use vbcc this way:

    vc ram:mysource.c -lauto -o ram:executable

    you can add also (-+) if you use c++ multiline comments, and (-lmieee) if you use mathematics libraries with floating point funcs.
    Mac mini G4@1,5GHz silent upgrade + Xerox Phaser 3140 + EPSON Perfection 1240U
    Commodore C64C + 2 x 1541II + Datasette + SD-Box

    I miss draggable screens... and do you? I know I'm in a minority unfortunately.
  • »13.07.10 - 01:53
    Profile
  • Fab
  • MorphOS Developer
    Fab
    Posts: 1331 from 2003/6/16
    Typically, you would add in the first lines:
    CFLAGS=-noixemul
    LDFLAGS=-noixemul

    the main.o rule would become: $(CC) $(CFLAGS) $(shell gccprefs) -noixemul -c -o $(OBJDIR)main.o main.c
    and the link rule: $(LD) $(LDFLAGS) $(OBJS) $(shell gccprefs) -o $(EXE)

    That being said, it would be intested to know that $(shell gccprefs) value. I believe you used some golded makefile generator? Maybe the GUI also allows you to set cflags and ldflags yourself.
  • »13.07.10 - 03:21
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2053 from 2003/6/4
    @ r-tea
    I wanted to use gcc, because the little I know is C++, when I will add and change things to the example I will probably fall back into C++ habits and hence I need g++ then.
    Well, maybe I should taka C book and forget about C++ because g++ throws the next error messagte to me that I don't fully understand:

    g++ -noixemul -noixemul -c -o o/gcc-morphos-stable/main.o main.c
    main.c: In function `int main()':
    main.c:65: implicit declaration of function `int DoMethod(...)'
    main.c:83: ANSI C++ forbids implicit conversion from `void *' in initialization
    make: *** [o/gcc-morphos-stable/main.o] Error 1

    Done.

    Line 83 is:
    MUI_DisposeObject (app);

    If I understand that rightly "app" is a pointer of type void but MUI_DisposeObjects requires some other type with return value (but which?).
    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »13.07.10 - 11:01
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2053 from 2003/6/4
    @ Fab

    Yes, I used CubicIDE. There are many compiler options but to be honest I don't understand most of that stuff.
    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »13.07.10 - 11:04
    Profile Visit Website
  • Fab
  • MorphOS Developer
    Fab
    Posts: 1331 from 2003/6/16
    First, I see you're trying to compile your file in c++ mode (g++ instead of gcc). C++ is quite more restrictive regarding implicit conversions. So for example, if an object like app is declared as APTR (void *) and that you pass it to a function like DoMethod() or MUI_DisposeObject(), C++ will whine, because these functions expect (Object *) type.
    So, if you want to stay in c++ for whatever reason, either declare app as Object *app; or cast the app argument in the problematic calls that way: DoMetho((Object *) app, ...);
  • »13.07.10 - 13:18
    Profile Visit Website
  • Moderator
    Kronos
    Posts: 2240 from 2003/2/24
    @Zylesea

    To switch of ixemul, click on that greenish tick on blue background, a window "gccprefs" should appear.

    Click "linker options", the 4th gadget should read "ixemul", change that to "libnix".

    With libnix you get some level of autoinit for libraries and thus muimasterbase is allready defined.
  • »13.07.10 - 13:45
    Profile
  • JJ
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    JJ
    Posts: 147 from 2010/7/7
    From: Wales
    What about Modula-2 is there a decent compiler for MorphOS. Or any decent versions of bassic, like blitz or dark ?

    I am awaiting for my Mac mini to arrive and then i will be joining the MorphOS fun :)
    We don't stop playing because we grow old; we grow old because we stop playing. - George Bernard Shaw


    Xbox Live: S0ulA55a551n2
  • »13.07.10 - 16:11
    Profile
  • Just looking around
    scr33tch
    Posts: 2 from 2008/4/23
    Is there some tutorials on Internet to use the SDK "for beginners" ?

    I have created some stuff on GCC some years ago (on MOS 1.4.5) and it's very old in my memories...

    It seems MorphEd have some tools to create a new project or create the makefile... But the MorphEd options are not ok (i've just installed SDK). I have this message "Support for this compiler was not installed: gcc". Is there a page for beginers ?

    Tx
  • »31.07.10 - 11:33
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    I could compile this example with the help of '-noixemul' but when I want to run it from Ambient or Shell I only get "Error: Can't create MUIC_Application object!". Can someone tell me what is wrong or missing?
    And btw I searched through the Library (linmk above) for beginner tutorials but did not find any. Just an article about Reggae and one about the memory system. When I click on "26" articles on the top there only comes a statistic but no full catalog of available articles. Is there any complete list or should one use the one on the front page? Because there is just "in-depth" and "Reggae" but no other hints for beginners.
  • »17.10.10 - 13:27
    Profile
  • MorphOS Developer
    Krashan
    Posts: 1107 from 2003/6/11
    From: Białystok...
    Maybe some bounty for tutorial writers? ;-). There are lots of bounties noone wants to take, maybe fund transfer for such bounty is not a bad idea? If such tutorial bounty would be divided into a few milestones I would be seriously interested.
  • »17.10.10 - 19:12
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Divinity
    Posts: 498 from 2009/9/8
    Quote:


    Krashan wrote:
    Maybe some bounty for tutorial writers? ;-). There are lots of bounties noone wants to take, maybe fund transfer for such bounty is not a bad idea? If such tutorial bounty would be divided into a few milestones I would be seriously interested.


    very useful I think
  • »17.10.10 - 19:44
    Profile
  • Yokemate of Keyboards
    Yokemate of Keyboards
    amigadave
    Posts: 2794 from 2006/3/21
    From: Northern Calif...
    Anyone wanting to compare notes on learning to program with myself and a couple of other interested members here can contact me at amigadave@earthlink.net, or PMail here. I recently revived another thread about learning to program and there were a few people interested that responded there.

    I have Hollywood4.0, or 4.5 and Hollywood Designer 2.1 as well as Cubic IDE and many C/C++ study resources, plus all the Amiga ROM Kernel manuals and many other programming books. It might be best to start with Hollywood & Hollywood Designer, but not everyone will have purchased it, so some other easy language like Pascal, or Python might be better for a group learning project.

    Hollywood, Python, or Pascal may be more appropriate for certain projects and C/C++ for others. I also have Macro68 and AssemPro to learn Assembly for Classic Amiga 68k computers, Modula2 M2S, Manx C, SAS-C, StormC, AMOS & AMOS Pro and Visionary (for old text adventure games, not too popular anymore).
    MorphOS - The best Next Gen Amiga choice.
  • »18.10.10 - 00:58
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    Not the worst idea to set up such bounties although I'd like especially you to do more "practical" output as your programs are of very good quality. So you writing "just" some tutorials may be a waste of time in some way. But who else could do it on that level?

    Do you have an idea for this "Can't create MUIC_Application object!"?
  • »18.10.10 - 08:38
    Profile
  • MorphOS Developer
    Krashan
    Posts: 1107 from 2003/6/11
    From: Białystok...
    although I'd like especially you to do more "practical" output as your programs are of very good quality

    Nice to hear, thank you. Anyway in fact there is some trade-off here. On the other hand, the more educated programmers, the more good quality programs :-).

    Do you have an idea for this "Can't create MUIC_Application object!"?

    Yes. R-tea example has a drawback of using third party external MUI classes, which are not included in MorphOS distribution. I would avoid introducing such classes in the first "hello world" example personally. Then MUI tries to load these classes from disk and fails.

    There is an useful tool in MorphOS called Snoopium (located in Tools directory of the system partition by default). When you run it before running your application, it displays all disk accesses done by your program. It includes opening MUI external classes, it also shows you which tries were succesful and which failed.
  • »18.10.10 - 09:07
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    amigadave
    Posts: 2794 from 2006/3/21
    From: Northern Calif...
    I have compiled a list of 17 MZ.org members that have shown interest in a couple of threads toward learning/improving programming skills, plus 3 or 4 experienced programmers that might be interested in giving some level of assistance by answering questions and/or giving advice to the group of 17 "students".

    Of the members that want to learn/improve their programming skills, their current level of experience varies widely, so each will have a different beginning point, if any/all of them decide to keep in touch and continue to learn as a group.

    If you have ideas about how to proceed, or if you are interested in being included in such a group, please contact me.
    MorphOS - The best Next Gen Amiga choice.
  • »18.10.10 - 13:54
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    Hi again,

    I found out that I had not copied the date.library from Time.mcc package, so after having copied it I got a tiny window with just the current timestamp as output. I guess this is the only thing the demo program should do. At least it does something, so I can step by step try to get further.
    Now your tutorial might become interesting. Before you have written complete next articles (which take some time of course), can you point to some place where to find information on how to easily place GUI elements such as string gadgets, buttons inside the MUI window and how to call external programs with parameters? Like say: place a button somewhere inside the window and call an external app on mouseclick e.g. call "multiview path:to/file.jpg" and display the result in a variable in the same window or such. Some small hints might help me go on reading about these subjects until you completed some articles about these topics. ATM I find Autodocs quite overwhelming.

    Oh, I have an idea to the library introduction article: could you some time later provide a picture or such to show how different modules in MOS interact with each other? Like a layer view or something. You know, people like pictures for easier imagination :-)

    And BTW: is any of you going to Bad Bramstedt next week? I think about going there and maybe somebody is willing to give some short introduction to MOS/MUI programming. Like maybe a two hours workshop for interactively building a small app with typical elements and operrations or so? Something that one shows on the beamer wall and and students can try themselves on their machines in realtime. I think that would be really cool and motivating to people going there.

    [ Edited by connor on 2010/10/29 19:45 ]
  • »29.10.10 - 17:39
    Profile