OT: Altair emulator code & C pointers

From: Sean 'Captain Napalm' Conner <spc_at_armigeron.com>
Date: Mon Jun 12 14:34:55 2000

It was thus said that the Great Cini, Richard once stated:
> Hi:
> I'm not particularly good at C, so I'm trying to learn more as I add
> tape image support to Claus Guiloi's Altair Emulator.
> Anyway, I have a "C pointers" question regarding copying the tape
> bits to the emulator memory. Here's some pseudo code...
> //delcared in i8080.c MEMSIZE is virtual memory size in bytes

  [ snipped --- NOTE: ``//'' is NOT a valid ANSI C comment delimeter, but
some C compilers will accept it]

  I would be inclined to do the following:

#include <stdio.h>
#include <stddef.h>

#define MAXSIZE 65536L
#ifndef FALSE
# define FALSE 0
#ifndef TRUE
# define TRUE !FALSE

typedef size_t i8080addr;

int ReadTape (char *filename,void *dest,size_t maxsize);
i8080addr AskLoadAddress (void);

unsigned char Mem [MEMSIZE];

        /* code ... */

        loadaddr = AskLoadAddress();
        if (loadaddr >= MAXSIZE) /* too large of an address */

        rc = ReadTape(filename,Mem+loadaddr,MAXSIZE - loadaddr);
        if (rc == FALSE)

        /* rest of code */

  Basically, read the file directly into the 8080 virtual memory space.
Saves moving it around afterwards.

  But for your original question reguarding:

> uchar Mem [MEMSIZE];
> PSTR pstrBuffer ; //buffer for fread command

> // copy binary image to the emulator memory
> for (i = 0; i <= iLength; i++)
> Mem[i+addr] = (uchar) *pstrBuffer+i;
> This is the important code. The Altair's memory is represented by an array
> of type uchar and pstrBuffer is the file buffer used int he fread command.
> My question is whether I'm doing the assignment right?

  The right hand side looks suspicious so I might make it read:

        for (i = 0 ; i < iLength ; i++)
          Mem[i + addr] = (uchar) (*(pstrBuffer + i));

  Arrays are zero based, so an array that is 10 elements long uses indicies
from 0 to 9, so your original code would write one too many bytes (and may
or may not crash the program, depending upon the system).

  -spc (Have C compiler, will program)
Received on Mon Jun 12 2000 - 14:34:55 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:33:01 BST