English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 30 September 2020, 16:13   #1
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 385
Unable to open console.device

Hi all.

I've been pulling my hair out trying to open console.device.

I can open the screen, window, port and IORequest fine.. but it fails when I call OpenDevice().


I have followed the instructions from the ROM Kernel Reference Manual and I am using the Amiga C/C++ extension for VSCode.

Can someone please tell me what I'm doing wrong?

Thanks so much!


Part 1 of code:



Code:
#include "support/gcc8_c_support.h"
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <graphics/view.h>
#include <proto/intuition.h>
#include <intuition/intuition.h>
#include <devices/conunit.h>
#include "amiga.h"

struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;

enum ScreenMode {
    PAL_NON_INTERLACED = 256,
    NTSC_NON_INTERLACED = 200,
    PAL_INTERLACED = 512,
    NTSC_INTERLACED = 400
};

struct Config {
    enum ScreenMode screenMode;
} config;

int main() {
    SysBase = *((struct ExecBase**)4UL);
    void openLibraries();
    void closeLibraries();
    void configureApp();
    void initVideo(struct Screen**, struct Window**);
    struct Window *window;
    struct Screen *screen;
    struct View *view;
    struct IOStdReq *consoleIO;
    struct Port *consoleWritePort;

    openLibraries();
    configureApp();
    initVideo(&screen, &window);

    consoleWritePort = CreatePort("mycon.write",0);
    if (consoleWritePort == NULL) {
        KPrintF("Unable to create port!\n");
        return 1;
    }

    consoleIO = CreateStdIO(consoleWritePort);
    if (consoleIO == NULL) {
        KPrintF("Unable to create Console IO Request!\n");
        return 1;
    }

    consoleIO->io_Data = (APTR) window;
    consoleIO->io_Length = sizeof(*window);

    BYTE a;
    if (a = !OpenDevice("console.device", CONU_STANDARD, consoleIO, CONFLAG_DEFAULT)) {
        KPrintF("Unable to open console.device!");
        return 1;
    }

    UBYTE *susan = "You can't do that to a susan!";
    consoleIO->io_Data = susan;
    consoleIO->io_Length = strlen(susan);
    consoleIO->io_Command = CMD_WRITE;
    DoIO(consoleIO);

    Wait(1 << window->UserPort->mp_SigBit);

    if (!(CheckIO(consoleIO)))
        AbortIO(consoleIO);

    DeletePort(consoleWritePort);
    CloseDevice(consoleIO);

    CloseWindow(window);

    FreeMem(screen->Font, sizeof(struct TextAttr));
    CloseScreen(screen);
    OpenWorkBench();

    closeLibraries();

    return 0;
}
Nightfox is offline  
Old 30 September 2020, 16:14   #2
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 385
Part 2 of code:


Code:
void openLibraries() {
    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
    if (IntuitionBase == NULL) {
        KPrintF("Problem opening IntuitionBase!\n");
        Exit(RETURN_ERROR);
    }

    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
    if (GfxBase == NULL) {
        KPrintF("Problem opening GfxBase!\n");
        Exit(RETURN_ERROR);
    }
}

void initVideo(struct Screen **screen, struct Window **window) {
    struct TextAttr *font;
    font = AllocMem(sizeof(struct TextAttr), MEMF_CHIP);
    font->ta_Name = "topaz.font";
    font->ta_YSize = TOPAZ_SIXTY;
    font->ta_Style = FS_NORMAL;
    font->ta_Flags = FPF_ROMFONT;

    struct NewScreen NewScreen;
    NewScreen.LeftEdge = 0;
    NewScreen.TopEdge = 0;
    NewScreen.Width = 640;
    NewScreen.Height = config.screenMode;
    NewScreen.Depth = 4;
    NewScreen.DetailPen = 0;
    NewScreen.BlockPen = 1;
    NewScreen.ViewModes = HIRES;
    NewScreen.Type = CUSTOMSCREEN;
    NewScreen.Font = NULL;
    NewScreen.DefaultTitle = "DF0";
    NewScreen.Gadgets = NULL;
    NewScreen.CustomBitMap = NULL;

    if ((*screen = (struct Screen *)OpenScreen(&NewScreen)) == NULL)  {
        KPrintF("Problem opening screen!\n");
        Exit(RETURN_ERROR);
    }

    if (!CloseWorkBench()) KPrintF("Unable to close Workbench screen.\n");

    struct NewWindow NewWindow;
    NewWindow.LeftEdge = 0;
    NewWindow.TopEdge = 0;
    NewWindow.Width = 640;
    NewWindow.Height = config.screenMode;
    NewWindow.DetailPen = 0;
    NewWindow.BlockPen = 1;
    NewWindow.Title = NULL;
    NewWindow.Flags = SMART_REFRESH | ACTIVATE | BORDERLESS | NOCAREREFRESH | BACKDROP;
    NewWindow.IDCMPFlags = NULL;
    NewWindow.Type = CUSTOMSCREEN;
    NewWindow.FirstGadget = NULL;
    NewWindow.CheckMark = NULL;
    NewWindow.Screen = *screen;
    NewWindow.BitMap = NULL;
    NewWindow.MinWidth = 30;
    NewWindow.MinHeight = 20;
    NewWindow.MaxWidth = 600;
    NewWindow.MaxHeight = 600;

    if ((*window = (struct Window *)OpenWindow(&NewWindow)) == NULL) {
        KPrintF("Problem opening window!\n");
        Exit(RETURN_ERROR);
    }
}

void closeLibraries() {
    CloseLibrary(IntuitionBase);
    CloseLibrary(GfxBase);
}

void configureApp() {
    config.screenMode = PAL_NON_INTERLACED;
}
Nightfox is offline  
Old 30 September 2020, 16:50   #3
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
I always opened consoles as a file. I've never seen it done how you are doing it. I won't say you're wrong but it's a new thing here.
Samurai_Crow is offline  
Old 30 September 2020, 17:09   #4
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Everything looks ok in the above code... except for the fact OpenDevice returns zero if successful.
meynaf is offline  
Old 30 September 2020, 19:23   #5
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,217
Quote:
Originally Posted by Nightfox View Post
Hi all.

I've been pulling my hair out trying to open console.device.

I can open the screen, window, port and IORequest fine.. but it fails when I call OpenDevice().
Actually, it does not. OpenDevice() returns an error code, and thus 0 for success.


Note, however, that you should release resources even in case of failure. That is, if you open a library, and some code following it fails, you still need to close the library. If you open a screen, and opening a window fails, you need to close the screen.
Thomas Richter is offline  
Old 30 September 2020, 20:46   #6
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by Thomas Richter View Post
Actually, it does not. OpenDevice() returns an error code, and thus 0 for success.
Wait. Doesn't the NOT(!) reverse that?
alkis is offline  
Old 30 September 2020, 20:55   #7
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
Quote:
Originally Posted by alkis View Post
Wait. Doesn't the NOT(!) reverse that?
What if the result is not a logical false?
Samurai_Crow is offline  
Old 01 October 2020, 00:59   #8
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by Samurai_Crow View Post
What if the result is not a logical false?
OpenDevice returns a byte (D0.b). I think for C the value zero counts as FALSE and anything else counts as TRUE. If you NOT that (! operator) you reverse it.

Basically, if OP can remove the ! and tells us if it works as expected would be nice
alkis is offline  
Old 01 October 2020, 08:09   #9
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,217
Quote:
Originally Posted by alkis View Post
Wait. Doesn't the NOT(!) reverse that?
Correct, which is why it is not working. if (!OpenDevice) { error(); } runs into error(); if OpenDevice() returns 0, which is the success case.
Thomas Richter is offline  
Old 01 October 2020, 12:56   #10
Tomislav
Registered User
 
Join Date: Aug 2014
Location: Zagreb / Croatia
Posts: 302
You can open console window as a file: CON:x/y/width/height/title

https://wiki.amigaos.net/wiki/AmigaD...nd_Output#CON:

(There is also RAW: console which is not recommended. It is actually unbuffered CON:.)
Tomislav is offline  
Old 01 October 2020, 17:24   #11
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,217
Quote:
Originally Posted by Tomislav View Post
You can open console window as a file: CON:x/y/width/height/title

That is not the same. This opens a window, but not necessarily one associated with the console.device, and it also creates a Dos file handle, whereas the former performs I/O over the exec protocol. Also, in the console.device example, the window is owned by the application, and thus will (or must) be closed by the application, whereas in your example the window is part of the file handle, and goes away whenever the file handle goes away.


So the communication protocol is a different one, there is one additional layer in between if you open CON:.
Thomas Richter is offline  
Old 01 October 2020, 18:19   #12
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 385
Thanks so much everyone! We have discovered that I was a dumbdumb and put a NOT (!) in there even though a success is returned with a 0. I guess at the time my brain was thinking that the not in that line means (if not able to open device then...)

The console.device does indeed open and the reason why we don't see any of the text that the console writes to the window afterwards is because the window is set as a backdrop window and the text is actually hidden underneath the screen's titlebar
Nightfox 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
Unable to open your tool 'DirectoryOpus' Fleischer444 support.WinUAE 3 26 October 2017 20:17
WinUae - unable to open your... grubasek support.WinUAE 4 14 July 2012 16:33
unable to open reqtools.library RabidRabbit support.WinUAE 6 31 March 2009 13:43
unable to open your tool... analog78 New to Emulation or Amiga scene 4 01 May 2008 22:37
unable to open your tool 'installer' sasai support.WinUAE 4 04 March 2007 02:58

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 19:38.

Top

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