calling MSX UNAPI (ethernet API) from C?

tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

calling MSX UNAPI (ethernet API) from C?

Post by tschak909 »

Would it be possible, to call this API from C,

https://www.konamiman.com/msx/unapi/tcp-ip-unapi-10.pdf

without needing to make a full binding for it? or would I need to wrap all of these calls?

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Looks like a potential pain in the arse,
https://www.konamiman.com/msx/networkin ... tcpcon.asm

note CALL_UNAPI, it's doing some paging in and out...

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

hmm, Nestor pointed me to this:
https://github.com/Konamiman/MSX/tree/m ... DCC/asmlib

Would this work as is with z88dk?

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Am currently trying to convert the code to properly compile with zcc...my lack of assembler knowledge here is biting me in the arse. ;)

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

What's causing this to barf?

https://github.com/Konamiman/MSX/blob/m ... /AsmCall.c

Code: Select all

mkdir -p build/./src/msx/
zcc  +msx -D__MSX__ -c src/msx/AsmCall.c -o build/./src/msx/AsmCall.c.o
Error at file 'src/msx/AsmCall.c' line 29: syntax error
Error at file 'src/msx/AsmCall.c' line 30: syntax error
Error at file 'src/msx/AsmCall.c' line 31: syntax error
Error at file 'src/msx/AsmCall.c' line 33: syntax error
Error at file 'src/msx/AsmCall.c' line 35: syntax error
Error at file 'src/msx/AsmCall.c' line 45: syntax error
Error at file 'src/msx/AsmCall.c' line 49: syntax error
Error at file 'src/msx/AsmCall.c' line 50: syntax error
Error at file 'src/msx/AsmCall.c' line 51: syntax error
Error at file 'src/msx/AsmCall.c' line 52: syntax error
Error at file 'src/msx/AsmCall.c' line 53: syntax error
Error at file 'src/msx/AsmCall.c' line 54: syntax error
Error at file 'src/msx/AsmCall.c' line 58: syntax error
Error at file 'src/msx/AsmCall.c' line 59: syntax error
Error at file 'src/msx/AsmCall.c' line 60: syntax error
Error at file 'src/msx/AsmCall.c' line 61: syntax error
Error at file 'src/msx/AsmCall.c' line 82: syntax error
Error at file 'src/msx/AsmCall.c' line 87: syntax error
Error at file 'src/msx/AsmCall.c' line 88: syntax error
Error at file 'src/msx/AsmCall.c' line 89: syntax error
Error at file 'src/msx/AsmCall.c' line 90: syntax error
Error at file 'src/msx/AsmCall.c' line 91: syntax error
Error at file 'src/msx/AsmCall.c' line 92: syntax error
Error at file 'src/msx/AsmCall.c' line 97: syntax error
Error at file 'src/msx/AsmCall.c' line 98: syntax error
Error at file 'src/msx/AsmCall.c' line 101: syntax error
Error at file 'src/msx/AsmCall.c' line 102: syntax error
Errors in source file src/msx/AsmCall.c:
Error at file 'src/msx/AsmCall.c' line 29: syntax error
                   ^ ----
Error at file 'src/msx/AsmCall.c' line 30: syntax error
                   ^ ----     exx
Error at file 'src/msx/AsmCall.c' line 31: syntax error
                   ^ ----     ld            l,(ix)
Error at file 'src/msx/AsmCall.c' line 33: syntax error
                   ^ ----     dec           a
Error at file 'src/msx/AsmCall.c' line 35: syntax error
                   ^ ----     exx
Error at file 'src/msx/AsmCall.c' line 45: syntax error
                   ^ ----     jr            z,ASMRUT_DOAF
Error at file 'src/msx/AsmCall.c' line 49: syntax error
                   ^ ----     ld      e,10(ix) ;IY
Error at file 'src/msx/AsmCall.c' line 50: syntax error
                   ^ ----     ld      d,11(ix)
Error at file 'src/msx/AsmCall.c' line 51: syntax error
                   ^ ----     push      de
Error at file 'src/msx/AsmCall.c' line 52: syntax error
                   ^ ----     push      bc
Error at file 'src/msx/AsmCall.c' line 53: syntax error
                   ^ ----     pop           ix
Error at file 'src/msx/AsmCall.c' line 54: syntax error
                   ^ ----     pop           iy
Error at file 'src/msx/AsmCall.c' line 58: syntax error
                   ^ ----     pop           af
Error at file 'src/msx/AsmCall.c' line 59: syntax error
                   ^ ----     exx
Error at file 'src/msx/AsmCall.c' line 60: syntax error
                   ^ ----
Error at file 'src/msx/AsmCall.c' line 61: syntax error
                   ^ ----     ret  ;Execute code, then CONT (both in stack)
Error at file 'src/msx/AsmCall.c' line 82: syntax error
                   ^ ----     ld      2(ix),c ;BC, DE, HL
Error at file 'src/msx/AsmCall.c' line 87: syntax error
                   ^ ----     ld      7(ix),h
Error at file 'src/msx/AsmCall.c' line 88: syntax error
                   ^ ----     dec       a
Error at file 'src/msx/AsmCall.c' line 89: syntax error
                   ^ ----     jr        z,CALL_END
Error at file 'src/msx/AsmCall.c' line 90: syntax error
                   ^ ----
Error at file 'src/msx/AsmCall.c' line 91: syntax error
                   ^ ----     exx               ;Alternate HLDEBC
Error at file 'src/msx/AsmCall.c' line 92: syntax error
                   ^ ----     pop     hl
Error at file 'src/msx/AsmCall.c' line 97: syntax error
                   ^ ----     ld      10(ix),l ;IY
Error at file 'src/msx/AsmCall.c' line 98: syntax error
                   ^ ----     ld      11(ix),h
Error at file 'src/msx/AsmCall.c' line 101: syntax error
                   ^ ----     ex            af,af
Error at file 'src/msx/AsmCall.c' line 102: syntax error
                   ^ ----     pop       ix
Makefile.msx:23: recipe for target 'build/./src/msx/AsmCall.c.o' failed
make: *** [build/./src/msx/AsmCall.c.o] Error 1
:/
-Thom
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I'm guessing it's the "ld 11(ix)" syntax which needs to be "ld (ix+11)"
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Ok, yup, making that change and it builds... I wonder if it works... I do see it pushing and popping ix and iy, but part of me wonders if this code won't go sideways somehow...

*nervous*

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Yup, any call to AsmCall causes the whole program to go off into the weeds. I'll try to figure out what it is doing, but I do admit I am way out of my depth, here, and could use some guidance.

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

is there already a mechanism I can use to call external monolithic z80 routines, that I should be using instead of trying to bring over konamiman's code?

-Thom
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I suspect the code is going into space because it's written for sdcc's calling convention rather than sccz80.

It's easy to fix, just:

1. Add #include <sys/compiler.h>
2. Annotate the prototype with __z88dk_sdccdecl

And then the function will work with both compilers (details are here: https://github.com/z88dk/z88dk/wiki/CallingConventions)
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

oh ok! Thanks. gosh, didn't think about the calling convention :)

Will see if I can massage this into submission. :)

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

almost, adding the calling convention now doesn't cause it to hang, but rather, causes the program to continuously jump back to 0x100.

-Thom
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I'm in the process of incorporating the library into the MSX port since it seems to be quite useful.

I've just run it on a non-MSX target and found a very subtle problem that's probably causing your problem: remove the # from the line that reads ld de,#CONT

If you don't, then the call executes but you end up returning to 0x5d which will probably run onto 0x100 and restart the program.
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Faaaantastic. :)

-Thom
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I added it in last night - just include <arch/msx.h> - hopefully it will work for you.
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Am I hallucinating or is AsmCall not in the library?

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

I am. you plopped it into arch/z80, which makes more sense. yes...

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Yup, it builds. Thanks so much for that.

Have you been able to use it for something else? I'm having issues with GetUnapiCount() returning anything other than 0.. hmm...

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Returning to this thread,

Given the following code:

Code: Select all

#include <msx.h>
#include <arch/msx/asm.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
  int count;
  printf("Testing Harness\r\n");
  printf("---------------\r\n\r\n");

  count=UnapiGetCount("TCP/IP");

  printf("UNAPIGetCount(TCP/IP) - %d",count);

  printf("end\n\n");

  return 0;
}
It is currently returning:

Image

Really need this code to work, it's pivotal for MSX support of PLATOTERM, as it is the only emulatable I/O that I have in BlueMSX.

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Am guessing AsmCall is messing up returning the value. :(

-Thom
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

It was a subtle compiler difference: enums may be chars with sdcc, but are always ints with sccz80. As a result the registers_out parameter was always 0: discard values!
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Fantastic! Yup, that worked! :)

Image

Onward!

-Thom
tschak909
Member
Posts: 83
Joined: Sun Sep 09, 2018 5:44 pm

Post by tschak909 »

Getting closer, but now UnapiCall may be mangling things a bit.

Image

In my code:

https://github.com/tschak909/platotermz ... /io.c#L105

I am calling an UNAPI call: TCPIP_GET_CAPAB, which is defined here in section 4.1.2:
https://github.com/Konamiman/MSX/blob/m ... api-10.pdf

Bit 3 gives whether active TCP connections are possible, which are required by this program.

It's failing, and it shouldn't, because INL is literally the canonical implementation of UNAPI TCP/IP on the MSX, and this is used by more than a few of the test programs (tweeter.c, etc.)

*scratch-head*

-Thom
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Can you ELI5 on how to get an MSX emulator (which has a debugger) up and running with this UNAPI extension?

I've got the equivalent code running on the test target and see I get to the _codeBlock dispatch with the right registers in place so AsmCall is working correctly now.
Post Reply