Atlas - STORY.C
Home / systems / IBM-PC / Storyteller Lines: 7 | Size: 4435 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* Takes in a .st file and reads it to the user like its a storybook */ 2 3/*Example file: 4@bg <VGA_COLOR> 5@fg <VGA_COLOR> 6@cls 7The quick brown fox jumps over the lazy dog. 8@pause 9@cls 10There was always a lazy dog. 11@pause 12@cls 13The end. 14*/ 15 16#include <dos.h> 17#include <conio.h> 18#include <stdio.h> 19#include <string.h> 20#include <stdlib.h> 21 22 23/*Borland C style code for MSDOS 5*/ 24 25void beep(int freq, int ms) 26{ 27 sound(freq); 28 delay(ms); 29 nosound(); 30} 31 32 33int main(int argc, char *argv[]) 34{ 35 FILE *file; 36 char line[256]; 37 int color; 38 int waiting; 39 int i; 40 int beeponlineonly=0; 41 char *p; 42 43 if (argc < 2) 44 { 45 cprintf("Usage: STORY <filename.st>\r\n"); 46 return 1; 47 } 48 49 beep(500, 100); 50 beep(700, 100); 51 beep(900, 100); 52 beep(1100, 100); 53 cprintf("Loading story from %s...\r\n", argv[1]); 54 55 file = fopen(argv[1], "r"); 56 if (!file) 57 { 58 cprintf("Error: Could not open file %s\r\n", argv[1]); 59 return 1; 60 } 61 62 clrscr(); 63 64 while (fgets(line, sizeof(line), file)) 65 { 66 if (line[0] == '@') 67 { 68 /* Handle commands */ 69 if (strncmp(line, "@bg ", 4) == 0) 70 { 71 /* Set background color */ 72 color = atoi(line + 4); 73 textbackground(color); 74 } 75 else if (strncmp(line, "@fg ", 4) == 0) 76 { 77 /* Set foreground color */ 78 color = atoi(line + 4); 79 textcolor(color); 80 } 81 else if (strncmp(line, "@soundcls", 10) == 0) 82 { 83 for (i = 0; i < 25; i++) 84 { 85 beep(100 + i * 50, 50); 86 cprintf("\r\n"); 87 } 88 clrscr(); 89 } 90 91 else if (strncmp(line, "@cls", 4) == 0) 92 { 93 clrscr(); 94 } 95 96 97 else if (strncmp(line, "@pause", 6) == 0) 98 { 99 beep(1000, 200); 100 /* animate 3 dots until a key is pressed */ 101 waiting = 1; 102 while (waiting) 103 { 104 for (i = 0; i < 3; i++) 105 { 106 beep(100 + i * 100, 100); 107 cprintf("."); 108 delay(500); 109 110 if (kbhit()) 111 { 112 getch(); 113 waiting = 0; 114 beep(1200, 200); 115 beep(1000, 200); 116 break; 117 } 118 } 119 cprintf("\b\b\b \b\b\b"); /* Clear the dots */ 120 } 121 } 122 123 else if (strncmp(line, "@linebeep", 9) == 0) 124 { 125 beeponlineonly = 1; 126 } 127 else if (strncmp(line, "@charbeep", 9) == 0) 128 { 129 beeponlineonly = 0; 130 } 131 } 132 else 133 { 134 /* print each char with typing delay and punctuation pauses */ 135 if (beeponlineonly) 136 { 137 beep(600, 50); 138 } 139 140 for (p = line; *p; p++) 141 { 142 if (*p == '\n') 143 { 144 putch('\r'); 145 putch('\n'); 146 continue; 147 } 148 149 if (*p == '\r') 150 { 151 continue; 152 } 153 154 putch(*p); 155 if (beeponlineonly) 156 { 157 delay(1); 158 } 159 if (!beeponlineonly) 160 { 161 if (*p == '.' || *p == '!' || *p == '?' || *p == ',') 162 { 163 beep(800, 200); 164 delay(300); 165 } 166 if (*p == ' ') 167 { 168 delay(100); 169 } 170 else 171 { 172 beep(600, 50); 173 delay(50); 174 } 175 } 176 } 177 } 178 } 179 180 fclose(file); 181 beep(1200, 500); 182 clrscr(); 183 return 0; 184} 185[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.