fopen (f,"w") not working under Adam CP/M

Post Reply
tschak909
Well known member
Posts: 171
Joined: Sun Sep 09, 2018 5:44 pm

fopen (f,"w") not working under Adam CP/M

Post by tschak909 »

Very odd, but with the following code, I am erroring out with the fopen:
I do not need any more than the 3 default FCBs, so... what gives?

Code: Select all

/**
 * nget
 */

#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "network.h"

#define READ 4
#define NO_TRANSLATION 0

#define RETRY_COUNT 128
#define CONNECTED 2

void get_url(char *c)
{
  cprintf("URL: ");
  cgets(c);
}

void get_filename(char *c)
{
  cprintf("DEST FILENAME: ");
  cgets(c);
}

bool did_we_connect(void)
{
  bool retries = RETRY_COUNT;

  // Wait until connection established
  while (retries > 0)
    {
      if (network_statusbyte() & CONNECTED)
        {
          cprintf("CONNECTED!\n");
          return true;
        }
      else
        retries--;
    }

  if (retries == 0)
    {
      cprintf("COULD NOT OPEN NET CONNECTION.\n");
      return false;
    }
}

void get(char *u, char *f)
{
  FILE *fp = fopen(f,"w");
  unsigned long total = 0;

  if (fp == NULL)
    {
      cprintf("COULD NOT OPEN DEST FILE %s - ABORTING\n",f);
      fclose(fp);
      exit(1);
    }

  network_open(u,READ,NO_TRANSLATION);

  if (!did_we_connect())
    goto bye;

  while (1)
    {
      char buf[1024];
      unsigned short l = network_read(buf,sizeof(buf));

      if (fwrite(buf,sizeof(char),l,fp) != l)
        {
          cprintf("COULD NOT WRITE TO DEST FILE. ABORTING.\n");
          goto bye;
        }

      total += l;

      cprintf("%u\n",total);

      if (!(network_statusbyte() & CONNECTED))
        {
          cprintf("DONE.\n");
          break;
        }

    }

 bye:
  network_close();
  fclose(fp);
}

void main(void)
{
  char url[256];
  char filename[16];

  memset(url,0,sizeof(url));
  memset(filename,0,sizeof(filename));

  while (url[0]==0x00) { get_url(url); }
  while (filename[0]==0x00) { get_filename(filename); }

  get(url,filename);
}
WIN_20211231_14_40_11_Pro.jpg
-Thom
You do not have the required permissions to view the files attached to this post.
tschak909
Well known member
Posts: 171
Joined: Sun Sep 09, 2018 5:44 pm

Re: fopen (f,"w") not working under Adam CP/M

Post by tschak909 »

oh derp, It was because I accidentally linked with -lndos. whoops :)

-Thom
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: fopen (f,"w") not working under Adam CP/M

Post by stefano »

mm.. while we're on it, are there emulators capable of running the CP/M on the Adam ?
Are there disk images available online ?
I never succeded with that target.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Re: fopen (f,"w") not working under Adam CP/M

Post by RobertK »

stefano wrote: Sun Jan 09, 2022 12:30 pm mm.. while we're on it, are there emulators capable of running the CP/M on the Adam ?
Are there disk images available online ?
MAME will do it, attach the CP/M floppy disk image and the Adam will boot into CP/M.

A suitable disk image file is named cpm2.2_1.50.dsk.
Post Reply