Providers
Debian Linux
SDF
MinGW-W64
Verizon
Research
Faqs and RFCs
FileSearching
Google
Google Groups
W3Schools Online Web Tutorials
Wikipedia
Multimedia
CTIS
For the Pigs Among Us
Family Photos
My House
My Photos (1999-2002?)
My Photos (2005)
Retro Computers
Minions of Mirth
Main
Criticals
Criticals (Single Player)
Ghaqua
Maps and Points of Interest
Miscellaneous
Monster Templates
Miscellaneous
Area Codes
Bard’s Tale
Dungeons & Dragons Online
My Blog
Quote of the Day
RogueBasin
Slashdot
The Adventuer’s Guild
Weather
GitHub:eprive/Z80-MBC3
Programming
Main
Across
Biorhythm
BMP Chips
Complex Roots
Magic Square
Magic Square(js)
Matrix(js)
More DOS Programs
Roll
Strip Dups (bash)
Wacky Wood-Worker
How To
Enlightenment 0.16.7.2 Startup Patch
How to Create an OS X Iconset
My RedHat Howto
SSH to VMS (Deathrow OpenVMS Cluster)
Tools
Allowable Mortgage Interest
Dates and Mileage
Day of the Year
Fun With Time
Downloads
Educational
Utilities
BIORHYTH.C
/* BIORHYTH.C by Michael J. Chappell June 22, 2015 A fairly direct port of BIORHYTHM.BAS Copyright 1979 by Phil Feldman and Tom Rugg. Source code compiles under MIX Power C. Compiled for FreeDOS and should work under MS-DOS or PC-DOS. Tested under DOSBox 0.73 on Mac OS X 10.8.5 The code for dealing with the dates wasn't working as expected. So I rewrote date2Julian and julian2Date. I rewrote those sections based on julian Day Calculations (Gregorian Calendar) at http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html . See source for notes. */ #include <stdio.h> #include <math.h> #include "trs81.h" int l; /* counter of number of lines on screen */ int k; /* loop and work variable */ float t; /* num of chars on one side of the center of the chart */ float n; /* number of days between birth and current chart date */ float v; /* number of days in current biorhythm cycle (23, 28 or 33) */ float m; /* month */ float d; /* day */ float y; /* year (100 or greater) */ char c$[80]; /* string with date in month/day/year format */ char l$[80]; /* string with one line of the biorhythm chart */ char r$[80]; /* reply from operator after screen fills up */ char a$[80]; /* work variable */ float p; /* pi */ float jb; /* birth date in julian format */ float jd; /* julian date calculated in subroutine */ float jc; /* chart start date in julian format */ float w, b; /* work variables */ float r; /* remainder of n/v (number of days into cycle */ char temp[255]; int main(int argc, char **argv) { Initialize(); l=0; t=25; p=3.1415926535; Cls(); PrintTab(15); Print("BIORHYTHM\n"); Print("\n"); for (;;) { Print("\nEnter birth date"); getDate(); date2Julian(); jb = jd; Print("\nEnter start date for chart"); getDate(); date2Julian(); jc = jd; if (jc<jb) { Print("\nChart date can't be earlier than"); Print("\nbirth date. Try again."); continue; } else break; } do { header(); do { n = jc-jb; v = 23; remainder(); plot(); v = 28; remainder(); plot(); v = 33; remainder(); plot(); julian2Date(); sprintf(temp,"%s%s\n", c$, l$); Print(temp); jc = jc+1; l++; } while (l<12); l = 0; Print("Press 'E' to end, SPACE to continue"); do { r$[0]=Inkey$(); } while (!r$[0]); } while (r$[0]!='E' && r$[0]!='e'); /* sprintf(temp, "\nJulian Birth date: %f", jb); Print(temp); sprintf(temp, "\nJulian Chart date: %f", jc); Print(temp); */ while (!Inkey$()); } /* main */ void Initialize(void) { InitializeTRS80(0); return; } /* Initialize */ void getDate(void) { /* sets m, d, and y (month, day, and year) */ char temp[255]; do { Print("\nMonth (1 to 12)?"); scanf(" %f", &m); poscurs(cursrow()-1, 0); } while ((m<1.0) || (m>12.0)); do { Print("\nDay (1 to 31)?"); scanf(" %f", &d); poscurs(cursrow()-1, 0); } while ((d<1.0) || (m>31.0)); do { Print("\nYear?"); scanf(" %f", &y); poscurs(cursrow()-1, 0); } while (y<0.0); if (y<100) { y+=1900; sprintf(temp, "\n%4.0f Assumed.", y); Print(temp); } } /* getDate */ void date2Julian(void) { /* sets jd based on m, d, y */ /* direct translation (hopefully) w = floor((m-14)/12); jd = floor(1461*(y+4800+w)/4); b = floor(367*(m-2-w*12)/12); jd = jd+b; b = floor(floor(3*(y+4900+w))/4); jd = jd+d-32075-b; */ /* replacement with trusted code 1) Express the date as Y M D, where Y is the year, M is the month number (Jan = 1, Feb = 2, etc.), and D is the day in the month. 2) If the month is January or February, subtract 1 from the year to get a new Y, and add 12 to the month to get a new M. (Thus, we are thinking of January and February as being the 13th and 14th month of the previous year). 3) Dropping the fractional part of all results of all multiplications and divisions, let A = Y/100 B = A/4 C = 2-A+B E = 365.25x(Y+4716) F = 30.6001x(M+1) JD= C+D+E+F-1524.5 This is the Julian Day Number for the beginning of the date in question at 0 hours, Greenwich time. Note that this always gives you a half day extra. That is because the Julian Day begins at noon, Greenwich time. */ float A, B, C, E, F, JD, Y, M, D; Y=y; M=m; D=d; if (m<3) { M=m+12; Y=y-1; } A=floor(Y/100); B=floor(A/4); C=2-A+B; E=floor(365.25*(Y+4716)); F=floor(30.6001*(M+1)); JD=C+D+E+F-1524.5; jd=JD; } /* date2Julian */ void julian2Date(void) { /* sets c$ (and m, d, y) based on jc */ /* code not working as expected w=jc+68569; r=floor(4*w/146097); w=w-floor((146097*r*3)/4); y=floor(4000*(w+1)/1461001); w=w-floor(1461*y/4)+31; m=floor(80*y/2447); d=w-floor(2447*m/80); w=floor(m/11); m=m+2-12*w; y=100+(r-49)+y+w; */ /* replacement with trusted code To convert a Julian Day Number to a Gregorian date, assume that it is for 0 hours, Greenwich time (so that it ends in 0.5). Do the following calculations, again dropping the fractional part of all multiplicatons and divisions. Note: This method will not give dates accurately on the Gregorian Proleptic Calendar, i.e., the calendar you get by extending the Gregorian calendar backwards to years earlier than 1582. using the Gregorian leap year rules. In particular, the method fails if Y<400. Q = JD+0.5 Z = Integer part of Q W = (Z - 1867216.25)/36524.25 X = W/4 A = Z+1+W-X B = A+1524 C = (B-122.1)/365.25 D = 365.25xC E = (B-D)/30.6001 F = 30.6001xE Day of month = B-D-F+(Q-Z) Month = E-1 or E-13 (must get number less than or equal to 12) Year = C-4715 (if Month is January or February) or C-4716 (otherwise) */ float Q, Z, W, X, A, B, C, D, E, F, JD; JD=jc; Q = JD+0.5; Z = floor(Q); W = floor((Z-1867216.25)/36524.25); X = floor(W/4); A = Z+1+W-X; B = A+1524; C = floor((B-122.1)/365.25); D = floor(365.25*C); E = floor((B-D)/30.6001); F = floor(30.6001*E); d = floor(B-D-F+(Q-Z)); m = E-1; y = C-4716; if (m>12) { m = m-12; y = y+1; } sprintf(c$, "%02d/%02d/%02d", (int)m, (int)d, (int)y%100); } /* julian2Date */ void remainder(void) { /* sets r based on n/v */ w = floor(n/v); r = n-(w*v); } /* remainder */ void plot(void) { /* plot a point on l$ based on v and r */ if (v==23) { for (k=0; k<2*t+1; k++) l$[k]=' '; l$[k]='\0'; l$[(int)t-1]=149; } if (v==23) c$[0]='P'; else if (v==28) c$[0]='E'; else c$[0]='I'; /* v==33 */ w = 2*p*(r/v); w = t*sin(w)+t+0.5; w = floor(w); if (l$[(int)w]=='P' || l$[(int)w]=='E' || l$[(int)w]=='*') c$[0]='*'; l$[(int)w] = c$[0]; } /* plot */ void header(void) { /* clear screen and display headings */ Cls(); Print( " BIORHYTHM\n"); Print( "--DATE-- D O W N 0 U P\n"); PrintTab(8); for (k=0; k<2*t+1; k++) PrintChr(131); Print("\n"); } /* header */
This source has been viewed 54 times.
Friday, 6 December 2024
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org