Adding inp/outp to stdlib for the 8080

Discussion about other targets
Post Reply
TronDD
New member
Posts: 3
Joined: Fri Dec 02, 2022 4:06 pm

Adding inp/outp to stdlib for the 8080

Post by TronDD »

I've been getting z88dk set up for my Altair8800 hardware. I'm not running CP/M. I'm up and running with serial IO and I want to get inp and outp added to stdlib since I am messing around with different hardware.

I figured the way to make inp and outp work is by dynamically creating the subroutine in memory and calling it. Turns out the Aztec C compiler uses this technique. I modified libsrc/stdlib/inp.asm and libsrc/stdlib/outp_callee.asm and added an ELIF __CPU_8080__ with the code. (Deliberating withholding the code to avoid possible license/copyright issues.)

I removed the exclusions from libsrc/stdlib/Makefile:

-ASMFILES_8080 = $(filter-out $(wildcard *sqrt*.asm *inp*.asm *outp*.asm *extract*.asm *sort_s*.asm) , $(wildcard *.asm)) $(wildcard 8080/*.asm)
+ASMFILES_8080 = $(filter-out $(wildcard *sqrt*.asm *extract*.asm *sort_s*.asm) , $(wildcard *.asm)) $(wildcard 8080/*.asm)

Recompiled fine.

However, when I compile a test program, the library code does not get added to the resulting binary. I am disassembling it and searching for a constant value from the assembly code. And, obviously, if I run it, when I hit the outp statement, I'm off in random memory.

I'm missing some piece of the puzzle that is still excluding or masking out these functions, it seems. Can someone point me to the missing puzzle piece?

#include <stdio.h>
#include <stdlib.h>

int main()
{
sleep(20); /* works, proved stdlib code is added */
printf ("Hello world\n");
/* outp ( port, byte ) */
outp( 0x11, "!" );
printf ("Goodbye world\n");
}
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Adding inp/outp to stdlib for the 8080

Post by stefano »

It's not easy to answer, it looks you found all the tricks (Dom could have a different opinion and suggest a precise code section to look at, as usual :D).

IIRC inp and outp were initially macros. Those macros still exist but in my knowledge they're now renamed into something like M_OUTP thus this shouldn't be a problem (just something you'll may want to fix for the 8080) .
I'd look in the output obj directories to be sure that the 8080 version was created, you could also look inside the object file to spot your text.

I'd also try to build a test version with the IF conditions removed (or commented out), it tends to be a nasty beast.
TronDD
New member
Posts: 3
Joined: Fri Dec 02, 2022 4:06 pm

Re: Adding inp/outp to stdlib for the 8080

Post by TronDD »

Hmm...I don't know what I was missing. But I removed the IF/ELIF from the code, recompiled and it was adding the code. I put the files back the way they were and it still worked.

Then outp wasn't returning correctly, but today it's working fine.

I think something isn't cleaned up with build.sh -c or some other inconsistency in my confused scrambling around... Sometimes I deleted .o and .lib files manually, sometimes I didn't, etc. Basically trying to avoid a full build.sh -c for one file change. But even with build.sh -c previously, it wasn't working so I have no idea.
TronDD
New member
Posts: 3
Joined: Fri Dec 02, 2022 4:06 pm

Re: Adding inp/outp to stdlib for the 8080

Post by TronDD »

Ok, inp and outp seem to be working. I'd like to submit a PR. I might be being over cautious about copyright, but the code from Aztec C has a header in it:

Code: Select all

;
;       Direct Port I/O Functions for AZTEC C II
;
;       Copyright (c) 1982 William C. Colley III
;
; I grant Manx Software Systems permission to incorporate these functions
; into the AZTEC C library subject only to the condition that my copyright
; notice remain in the source code.  WCC3.
The meat of the code is like 3 lines so I am not sure how else you could do it...

How would you like me to proceed?
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Adding inp/outp to stdlib for the 8080

Post by stefano »

I tend to leave credits in the source files.
I'd simply leave a line like this:
; 8080 version originally written in 1982 by William C. Colley III
Post Reply