English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 24 January 2023, 05:24   #1
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 81
Visual Studio Code Amiga C Extension

I'm having problems with includes. As far as I can tell, I just include
<proto/xxx>
for whatever library I want to use.

However including
 <proto/alib.h>
throws a ton of errors. Attached is the output when I try to build with it included.

Although, I would appreciate if someone would point me to working implementations of
CreateExtIO()
and
DeleteExtIO()
, because I'd be just fine programming them in myself, but I can't figure out what needs to be initialised in the
IORequest
structure. I've already made my own
CreatePort()
and
DeletePort()
.

Thanks in advance.
Attached Files
File Type: txt Console Output.txt (22.0 KB, 35 views)
Steam Ranger is offline  
Old 24 January 2023, 06:45   #2
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 806
Something like:
Code:
createextio(reply_port, size):
io = AllocMem(size,MEMF_CLEAR|MEMF_PUBLIC); // handle failed alloc
io->io_Message.mn_Node.ln_Type = NT_REPLYMSG;
io->io_Message.mn_Length = size;
io->io_Message.mn_ReplyPort = reply_port;
return io;

deleteextio(io):
if (io) FreeMem(io,io->io_Message.mn_Length);
a/b is online now  
Old 24 January 2023, 07:51   #3
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 81
Quote:
Originally Posted by a/b View Post
io->io_Message.mn_Node.ln_Type = NT_REPLYMSG;
io->io_Message.mn_Length = size;
io->io_Message.mn_ReplyPort = reply_port;
So the only thing you have to fill in on the IORequest for it to be functional is the properties of it's message structure?

PS: Also do I have to abort the IORequest before removing it? The documentation says it's dangerous to abort a request that's never been used, how do I check if it's been used or not?

Last edited by Steam Ranger; 24 January 2023 at 08:10.
Steam Ranger is offline  
Old 24 January 2023, 18:33   #4
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 806
Yeah, NT_REPLYMSG tells that the previous I/O had been replied and is fully complete, and the request is ready for another or to be freed. Length is there so that you know whether it's standard, extended, etc. (how much extra data is there). ReplyPort is optional, it's there because typically it's always the same one so you fill it in once.
Other properties you have to fill in prior to doing an actual I/O, based on device, I/O type, etc.

You should only (try to, since it's not a 100% guarantee, there are device specific considerations) abort if it's in progress (if you haven't replied yet). If the type is set to NT_REPLYMSG, as I mentioned above, it's done.
a/b is online now  
Old 25 January 2023, 02:44   #5
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 81
I'm running into a problem with the timer device.
Here's the code I'm using to open it:
Code:
Devices.h
Code:
#define NewList(list) ({\
	struct List *_NewList_list = (&(MessagePort->mp_MsgList));\
	_NewList_list->lh_TailPred = (struct Node *)_NewList_list;\
	_NewList_list->lh_Head = (struct Node *)&_NewList_list->lh_Tail;\
	_NewList_list->lh_Tail = 0;\
})

struct MsgPort *CreatePort(char *Name, long int PRI) {
	long int SignalBit;
	struct MsgPort *MessagePort;

	if ((SignalBit = AllocSignal(-1L)) == -1) return NULL;

	MessagePort = (struct MsgPort*)AllocMem(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
	if (MessagePort == 0) {
		FreeSignal(SignalBit);
		return NULL;
	}
	MessagePort->mp_Node.ln_Name	= Name;
	MessagePort->mp_Node.ln_Pri	= PRI;
	MessagePort->mp_Node.ln_Type	= NT_MSGPORT;
	MessagePort->mp_Flags		= PA_SIGNAL;
	MessagePort->mp_SigBit		= SignalBit;
	MessagePort->mp_SigTask		= FindTask(0L);

	if (Name != 0) AddPort(MessagePort);
	else NewList(&(MessagePort->mp_MsgList));

	return MessagePort;
}

...

struct IORequest *CreateExtIO(struct MsgPort *MessagePort, long int IOSize) {
	struct IORequest *Output = AllocMem(IOSize, MEMF_PUBLIC|MEMF_CLEAR);
	if (Output == 0) return NULL;
	Output->io_Message.mn_Node.ln_Type	= NT_REPLYMSG;
	Output->io_Message.mn_Length		= IOSize;
	Output->io_Message.mn_ReplyPort		= MessagePort;
	return Output;
}

...

struct IORequest *FabricateExtIO(long int IOSize) {
	struct MsgPort *MessagePort = CreatePort(0L,0L);
	if (MessagePort == 0) return NULL;
	struct IORequest *Output = CreateExtIO(MessagePort, IOSize);
	if (Output == 0) DeletePort(MessagePort);
	return Output;
}
Code:
Timer.h
Code:
#include "Devices.h"

struct Library *TimerBase;

struct timerequest *OpenTimer() {
	struct timerequest *Timer = (struct timerequest*)FabricateExtIO(sizeof(struct timerequest));
	if (Timer == NULL) return NULL;
	if (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest*)Timer, 0L) != 0) {
		DismantleExtIO((struct IORequest*)Timer);
		return NULL;
	}
	TimerBase = (struct Library*)Timer->tr_node.io_Device;
	return Timer;
}

...

long int GetTimestamp() {
	struct timeval *SysTime;
	GetSysTime(SysTime);
	return SysTime->tv_secs * 1000L + SysTime->tv_micro / 1000L;
}
It compiles fine, manages to open the device without errors, puts a seemingly correct address into
TimerBase
,
and yet when
GetSysTime()
is called it gives this in a pop-up:
Failed to get Stack Trace: Cannot access memory at address 0xaea00f8 (from data-disassemble -s 0x0aea00f8 -e 0x0aea015c -- 5)

And outputs this:
B-Trap FFFF at 000A9CD2 -> 00F80AE8
Your Amiga program just did something terribly stupid 0AEA00F8 PC=00F80BC4
...
CPU halted: reason = 3 PC=00f80bc4


Please help...
Steam Ranger is offline  
Old 25 January 2023, 04:29   #6
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 806
Probably not related, but...
1. NewList macro is not using its parameter list, looks like there's a hardcoded outside variable in the first line, right-hand side. It should probably be: struct List *_NewList_list = list;
2. NewList macro again, why ({...})? () is typically associated with function calls, you should probably only use {}
a/b is online now  
Old 25 January 2023, 05:24   #7
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 81
I copied character for character the existing newlist macro, as for whatever reason the one in my includes wasn't working.
Steam Ranger is offline  
Old 25 January 2023, 13:38   #8
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 81
Here's
Timer.h
and
Devices.h
, incase more info is needed. I cannot figure out why this isn't working, especially since no part of the opening process gives an error. It just all worked correctly and then
WinUAE Error 3
.

They've got
*.c
extensions just so I can upload them, but they're
*.h
Files.
Attached Files
File Type: c Devices.c (2.3 KB, 13 views)
File Type: c Timer.c (881 Bytes, 11 views)
Steam Ranger is offline  
Old 25 January 2023, 16:57   #9
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 806
AbortIOInProgress should use != instead of == (you're aborting if type == NT_REPLYMSG).

And again, what is the purpose of ({...})? After NewList macro expansion you end up with
if (...) {...} else ({...})
instead of
if (...) {...} else {...}
I don't know what compiler you're using, if it's a gcc port it could be OK since this is not a valid c, it's a gcc extension, and I don't know what will other compilers produce.
In any case there's no need for () because, as far as I can see, macro is not intended to be used as a right-hand expression (it would always "return" 0).
a/b is online now  
Old 25 January 2023, 18:55   #10
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 2,270
Is there actually a reason why you don't use NewList() in amiga.lib, CreateMsgPort() in exec and CreateExtIO() in exec? Or their corresponding counterparts from amiga.lib?
Thomas Richter is offline  
Old 26 January 2023, 02:41   #11
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 81
Whenever I include it it throws errors because of
_stdargs
or something before every function definition, but if I splice those out of the file the functions fail. So I decided to make my own set of functions, which also has the benefit that I can tweak them to have additional features.

PS:
NewList
by default expands to have those brackets around it, but even once I've removed them it doesn't alter the functionality one bit. Also, I'm using
gcc 8
.

Last edited by Steam Ranger; 26 January 2023 at 02:43. Reason: PS
Steam Ranger is offline  
Old 26 January 2023, 12:56   #12
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 81
Ah, I just realised. In
GetTimestamp()
my intention was to create a
struct timeval
in stack memory, pass a pointer to it into
GetSysTime()
and then return some values from it.

I forgot that declaring a pointer to the structure doesn't create it, but instead you have to declare the structure and use
&
to get a pointer.

Thanks for your help anyway.

Last edited by Steam Ranger; 26 January 2023 at 12:56. Reason: Smiley
Steam Ranger is offline  
Old 26 January 2023, 15:39   #13
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,290
Quote:
Originally Posted by Steam Ranger View Post
Whenever I include it it throws errors because of
_stdargs
or something before every function definition
Probably
__stdargs
as in
clib/compiler_specific.h
:
Code:
#if (defined(__GNUC__) && defined(AMIGA)) || defined(__SASC)
#define __STDARGS__ __stdargs
Then the person who did your specific gcc-port forgot to include the attribute, or named it differently.

Quote:
but if I splice those out of the file the functions fail.
Which means the default ABI of your compiler is incompatible to most other 68k compilers. Usually an 68k compiler will pass arguments on the stack. The
_stdargs
attribute is for those compilers which don't. Which makes it especially annoying when such an attribute is missing. Maybe there is an option for the command line?

Quote:
So I decided to make my own set of functions
You can probably make your own NDK.
Or switch to a more compatible compiler. My observation is that the version of a gcc-port directly correlates to the incompatibility with classic AmigaOS compilers.
phx is online now  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amiga GCC 8.3+gdb extension for Visual Studio Code Bartman Coders. C/C++ 104 06 November 2022 18:49
Amiga Assembly extension for Visual Studio Code prb28 Coders. Asm / Hardware 316 17 August 2022 18:01
Issue getting started with amiga-debug Visual Studio Code Extension (Windows) dalton Coders. General 2 23 June 2022 22:02
Amiga Assembly exension for Visual Studio Code 0.19 released prb28 Coders. General 2 02 January 2020 19:34
Visual Studio Code Blitz Basic extension earok Coders. Blitz Basic 29 16 July 2019 18:59

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 23:02.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Page generated in 0.08441 seconds with 15 queries