Providers
Debian Linux
SDF
MinGW-W64
Verizon
Research
Search Engines
Bing
DuckDuckGo
Google
Metacrawler
SearX
Miscellaneous
Faqs and RFCs
Open Directory Project
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
TRS81.H
/* TRS-80 compatability functions */ #if !defined(TRS81_H) #define TRS81_H #include <bios.h> #include <conio.h> #include <ctype.h> #include <direct.h> #include <dos.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define HORZOFF 8 #define VERTOFF 1 #define PrintAt(x) poscurs(VERTOFF+(x)*3/64/3*3, HORZOFF+(x)%64) #define PrintChrAt(w,c) PrintAt(w); PrintChr(c); #define PrintStrAt(w,c) PrintAt(w); Print(c); #define NewLine printf("\n\n\n") #define PrnOut(a) {for (i=1; i<=a[0]; i++) fputc(a[i], stdprn);} float timefactor; char trs80chr[256][4]; void InitializeTRS80(int); void PrintScreen(void); char Inkey$(void); void Random(void); double Rnd(int); void Cls(); void ForLoop(float); void PrintChr(char); void PrintTab(int); char Look(int); char Peek(int); void Poke(int,char); void Print(char *); void _Set(int, int); void _Reset(int, int); int _Point(int, int); void Set(int, int); void Reset(int, int); int Point(int, int); void CloseTRS80(void); void String$(char *,int, char); void ScrollUp(void) { union REGS r; r.h.ah = 0x06; r.h.al = 0x03; r.h.bh = 0x07; /* attribute */ r.h.ch = VERTOFF; r.h.cl = HORZOFF; r.h.dh = VERTOFF+0x30-1; r.h.dl = HORZOFF+0x40-1; int86(0x10, &r, &r); poscurs(VERTOFF+45, HORZOFF); return; } char *String$(char *p, int n, char c) { memset(p, 0, n+1); memset(p, c, n); return p; } /* String$ */ void PrintChr(char c) { char temp[2] = " "; temp[0] = c; Print(temp); return; } /* PrintChr */ void Print(char *line){ int curcol; int currow; int i; int s; i=0; while (line[i]) { s = i; curcol = curscol(); currow = cursrow(); while (line[i]>=' ') { if (curscol()<(HORZOFF+64)) putchar(trs80chr[line[i]][0]); i++; } putchar('\n'); poscurs(currow+1, curcol); i = s; while (line[i]>=' ') { if (curscol()<(HORZOFF+64)) putchar(trs80chr[line[i]][1]); i++; } putchar('\n'); poscurs(currow+2, curcol); i = s; while (line[i]>=' ') { if (curscol()<(HORZOFF+64)) putchar(trs80chr[line[i]][2]); i++; } poscurs(currow, curscol()); if (curscol()>=HORZOFF+64) { currow += 3; if (currow>(VERTOFF+45)) { currow-=3; ScrollUp(); } poscurs(currow, HORZOFF); PrintTab(0); } switch (line[i]) { case 23: break; case '\n': currow += 3; if (currow>(VERTOFF+45)) { currow -= 3; ScrollUp(); } poscurs(currow, HORZOFF); PrintTab(0); i++; break; case '\b': putchar('\b'); i++; break; case '\0': return; break; } } Inkey$(); } /* Print */ char Look(int p) { int oldrow, oldcol; char c; oldrow = cursrow(); oldcol = curscol(); poscurs(VERTOFF+(p)*3/64/3*3, HORZOFF+(p)%64); c = readch(); poscurs(oldrow, oldcol); return c; } /* Look */ char Peek(int p) { int oldrow, oldcol; char c; oldrow = cursrow(); oldcol = curscol(); p-=15360; poscurs(VERTOFF+(p)*3/64/3*3, HORZOFF+(p)%64); c = readch(); poscurs(oldrow, oldcol); return c; } /* Peek */ void Poke(int p, char c) { int oldrow, oldcol; int currow, curcol; oldrow = cursrow(); oldcol = curscol(); p-=15360; poscurs(VERTOFF+(p)*3/64/3*3, HORZOFF+(p)%64); currow = cursrow(); curcol = curscol(); putchar(trs80chr[c][0]); poscurs(currow+1, curcol); putchar(trs80chr[c][1]); poscurs(currow+2, curcol); putchar(trs80chr[c][2]); poscurs(oldrow, oldcol); return; } /* Peek */ void PrintTab(int x) { union REGS r; if (cursrow()<(VERTOFF+0x2f)) { poscurs(cursrow(), HORZOFF+x); } else { r.h.ah = 0x06; r.h.al = 0x03; r.h.bh = 0x07; /* attribute */ r.h.ch = VERTOFF; r.h.cl = HORZOFF; r.h.dh = VERTOFF+0x30-1; r.h.dl = HORZOFF+0x40-1; int86(0x10, &r, &r); poscurs(cursrow()-3, HORZOFF+x); } } char Inkey$(void) { union REGS r; int c; c = bioskey(1); if (c==0x3b00) { /* if F1 the Wait for KeyPress */ getch(); getch(); do { c = bioskey(1); if (c) { c = tolower((char)(bioskey(0)&0xff)); if (!c) { getch(); return ' '; } } if (c=='\x1b') /* if ESC then Quit */ exit(1); if (c=='`') { /* if ` then PrintScreen */ PrintScreen(); c = 0; } } while (!c); getch(); c = bioskey(1); } if (c) { c = tolower((char)(bioskey(0)&0xff)); if (!c) { getch(); return ' '; } } if (c=='\x1b') /* if ESC then Quit */ exit(1); if (c=='`') { /* if ` then PrintScreen */ PrintScreen(); c = 0; } return c; } /* Inkey$ */ void Cls(void) { union REGS r; r.h.ah = 0x06; r.h.al = 0x00; r.h.bh = 0x07; /* attribute */ r.h.ch = VERTOFF; r.h.cl = HORZOFF; r.h.dh = VERTOFF+0x30-1; r.h.dl = HORZOFF+0x40-1; int86(0x10, &r, &r); poscurs(VERTOFF, HORZOFF); return; } /* Cls */ void InitializeTRS80(int mode) { time_t current, start; int i; FILE *fp; char *fspec; union REGS r; static int TRS80REG = 0; if (!TRS80REG) { atexit(CloseTRS80); TRS80REG = 1; for (time(&start),time(¤t),timefactor=0; difftime(current, start)!=2.0; time(¤t)) timefactor++; if (kbhit()) getch(); timefactor /= 2; for (i=0; i<256; i++) { strcpy(trs80chr[i], " "); trs80chr[i][0] = i; } fspec = searchpath("trs80chr.dat"); fp = fopen(fspec, "rb"); fread(trs80chr[128], 4, 64, fp); fclose(fp); } setvmode(3); r.x.ax = 0x1112; /* change to 8x8 font */ r.h.bl = 0x00; int86(0x10, &r, &r); r.h.ah = 0x06; r.h.al = 0x00; r.h.bh = 0x17; /* attribute */ r.h.ch = 0x00; r.h.cl = 0x00; r.h.dh = 0x32; r.h.dl = 0x50; int86(0x10, &r, &r); Cls(); } /* InitializeTRS80 */ void Random(void) { time_t current; srand(current); return; } /* Random */ double Rnd(int n) { if (n) return (double)(rand()%n); else return (double)rand()/RAND_MAX; } /* Rnd */ void ForLoop(float delay) { int keystatus; unsigned long d, t=0; time_t current; char c = 0; d = delay*timefactor/1000; for (t=0; t<d; t++) { time(¤t); difftime(¤t, ¤t); } return; } /* ForLoop */ void _Reset(int y, int x) { char c; poscurs(VERTOFF+y, HORZOFF+x/2); c = readch(); if (x&1) switch (c) { case '\xdd': case '\xdb': putchar('\xdd'); break; default: putchar('\xff'); break; } else switch (c) { case '\xde': case '\xdb': putchar('\xde'); break; default: putchar('\xff'); break; } return; } void _Set(int y, int x) { char c; poscurs(VERTOFF+y, HORZOFF+x/2); c = readch(); if (x&1) switch (c) { case '\xdd': case '\xdb': putchar('\xdb'); break; default: putchar('\xde'); break; } else switch (c) { case '\xde': case '\xdb': putchar('\xdb'); break; default: putchar('\xdd'); break; } return; } int _Point(int y, int x) { char c; poscurs(VERTOFF+y, HORZOFF+x/2); c = readch(); if (x&1) switch (c) { case '\xde': case '\xdb': return 1; break; default: return 0; break; } else switch (c) { case '\xdd': case '\xdb': return 1; break; default: return 0; break; } return 0; } int Point(int y, int x) { int IsSet = 0; int currow, curcol; if ((y<0)||(y>47)) /* row out of range */ return IsSet; if ((x<0)||(x>127)) /* column out of range */ return IsSet; currow = cursrow(); curcol = curscol(); IsSet = _Point(y, x); poscurs(currow, curcol); return IsSet; } /* Point */ void Reset(int y, int x) { int currow, curcol; if ((y<0)||(y>47)) /* row out of range */ return; if ((x<0)||(x>127)) /* column out of range */ return; currow = cursrow(); curcol = curscol(); _Reset(y, x); poscurs(currow, curcol); return; } /* Reset */ void Set(int y, int x) { int currow, curcol; if ((y<0)||(y>47)) /* row out of range */ return; if ((x<0)||(x>127)) /* column out of range */ return; currow = cursrow(); curcol = curscol(); _Set(y, x); poscurs(currow, curcol); return; } /* Set */ void PrintScreen(void) { int norm = 1; int i; union REGS r; int stat; char P_Init$[] = {29, 27,':',0,0,0, 27,'%',1,0, 27,'&',0, '`','`', '\x8b', '\xef', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xef', 27,'3',24 }; char P_Cond$[] = {3, 27, '!', 5 }; char P_Norm$[] = {3, 27, '!', 0 }; char P_Rest$[] = {6, 27,'3',36, 27,'!',0 }; int oldrow, oldcol; char c; int row, col; r.h.ah = 2; r.x.dx = 0; int86(0x17, &r, &r); /* Get Printer Status */ if (r.h.ah!=0x90) { r.h.ah = 1; r.x.dx = 0; int86(0x17, &r, &r); /* Initialize Printer */ ForLoop(500.0); r.h.ah = 2; r.x.dx = 0; int86(0x17, &r, &r); /* Get Printer Status */ if (r.h.ah!=0x90) /* if Printer UNavailable exit with error */ exit(2); } oldrow = cursrow(); oldcol = curscol(); PrnOut(P_Init$); PrnOut(P_Norm$); fprintf(stdprn, " `"); for (col=0;col<65;col++) fputc('`',stdprn); fprintf(stdprn, "\n"); for (row=0; row<48; row++) { fprintf(stdprn, " `"); for (col=0; col<64; col++) { poscurs(VERTOFF+row, HORZOFF+col); c = readch(); switch (c) { case 219: /* graphic block full*/ PrnOut(P_Cond$); fputc('`', stdprn); fputc('`', stdprn); PrnOut(P_Norm$); break; case 221: /* graphic block left*/ PrnOut(P_Cond$); fputc('`', stdprn); fputc(' ', stdprn); PrnOut(P_Norm$); break; case 222: /* graphic block right*/ PrnOut(P_Cond$); fputc(' ', stdprn); fputc('`', stdprn); PrnOut(P_Norm$); break; case 255: /* graphic space*/ fputc(' ', stdprn); break; default: if (c>127) c-=128; if (c<32) c+=64; fputc(c, stdprn); break; } } PrnOut(P_Norm$); fprintf(stdprn, "`\n"); } fprintf(stdprn, " `"); for (col=0;col<65;col++) fputc('`',stdprn); poscurs(oldrow, oldcol); PrnOut(P_Rest$); fprintf(stdprn, "\n\n"); } /* PrintScreen */ void CloseTRS80(void) { setvmode(3); } #endif
This source has been viewed 20 times.
Sunday, 13 July 2025
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org