30 September 2020, 16:13 | #1 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 408
|
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; } |
30 September 2020, 16:14 | #2 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 408
|
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; } |
30 September 2020, 16:50 | #3 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
|
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.
|
30 September 2020, 17:09 | #4 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,358
|
Everything looks ok in the above code... except for the fact OpenDevice returns zero if successful.
|
30 September 2020, 19:23 | #5 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,324
|
Quote:
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. |
|
30 September 2020, 20:46 | #6 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 725
|
|
30 September 2020, 20:55 | #7 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
|
|
01 October 2020, 00:59 | #8 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 725
|
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 |
01 October 2020, 08:09 | #9 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,324
|
|
01 October 2020, 12:56 | #10 |
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:.) |
01 October 2020, 17:24 | #11 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,324
|
Quote:
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:. |
|
01 October 2020, 18:19 | #12 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 408
|
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 |
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 |
|
|