• R/O
  • HTTP
  • SSH
  • HTTPS

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Functions for working with the idealized calendar of Planet Xhilr


File Info

Rev. c9ca731a29c3838146d1e7e85626e1273ae7ca7f
크기 1,124 bytes
Time 2017-06-17 10:35:04
Author Joel Matthew Rees
Log Message

UD/MOD double integer division in M6800 assembler within figForth.
The assembler I use to assemble it is here:
https://sourceforge.net/p/asm68c/wiki/Home/
and it can be run on Joe H Allen's exorsim v. 1.1.
Surprisingly, the High-level Forth version is only around twice as slow as the assembler-level version (because it only uses right-shifts).

Content

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

typedef struct string_header_s 
{  short length; 
   char string[ 1 ];
} string_header_t;

char bigblock[ 100000 ];
char * here = bigblock;

string_header_t * string_allocate( long length )
{  char * place = here;;
   if ( ( place = here + length + sizeof (string_header_t) ) >= bigblock + 100000 )
   {  return NULL;
   }
   here = place;
   ( (string_header_t *) place )->length = length;
   return (string_header_t *) place;
}

string_header_t * string_save( char string[] )
{  long length = strlen( string );
   string_header_t * headerp = string_allocate( length );
   memcpy( headerp->string, string, length );
   headerp->string[ length ] = '\0';
   return headerp;
}

void print_string( string_header_t * header )
{  int i;
   for ( i = 0; i < header->length; ++i )
   {  putchar( header->string[ i ] );
   }   
}


int main ( int argc, char * argv[] )
{  string_header_t * thing;

puts( "before thing" );

   thing = string_save( "hello" );

puts( "after thing" );

   /* ... */ 

   print_string( thing );
   putchar( '\n' );

   return EXIT_SUCCESS;
}