├── dists ├── hanoi.d64 └── hanoi.d71 ├── binary ├── hanoi-p.com └── hanoi128.com ├── README.md ├── source ├── graph.inc ├── hanoi128.pas └── hanoi-p.pas └── LICENSE /dists/hanoi.d64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblendorio/hanoi-cpm/HEAD/dists/hanoi.d64 -------------------------------------------------------------------------------- /dists/hanoi.d71: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblendorio/hanoi-cpm/HEAD/dists/hanoi.d71 -------------------------------------------------------------------------------- /binary/hanoi-p.com: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblendorio/hanoi-cpm/HEAD/binary/hanoi-p.com -------------------------------------------------------------------------------- /binary/hanoi128.com: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblendorio/hanoi-cpm/HEAD/binary/hanoi128.com -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Towers of Hanoi - CP/M version 2 | ## Contents of package 3 | - **source** - Source code in Turbo Pascal 3.01A (Borland) 4 | - [**hanoi-p.pas**](https://github.com/sblendorio/hanoi-cpm/blob/master/source/hanoi-p.pas) - Portable version: uses just *KayPro* / *ADM-3A* escape sequences. Black and white. 5 | - [**hanoi128.pas**](https://github.com/sblendorio/hanoi-cpm/blob/master/source/hanoi128.pas) - Commodore 128 specific version: uses low-level calls and specific escape sequences to get colours. 6 | - [**graph.inc**](https://github.com/sblendorio/hanoi-cpm/blob/master/source/graph.inc) - Library needed by Commodore 128 specific version 7 | - **binary** - Compiled .COM executable files for CP/M-80 8 | - [**hanoi-p.com**](https://github.com/sblendorio/hanoi-cpm/raw/master/binary/hanoi-p.com) - Binary portable version 9 | - [**hanoi128.com**](https://github.com/sblendorio/hanoi-cpm/raw/master/binary/hanoi128.com) - Binary Commodore 128 specific version 10 | - **dists** - Collection of CP/M bootable disk images for Commodore 128 11 | - [**hanoi.d71**](https://github.com/sblendorio/hanoi-cpm/raw/master/dists/hanoi.d71) - Includes CP/M boot code, all sources and binaries, some utilities 12 | - [**hanoi.d64**](https://github.com/sblendorio/hanoi-cpm/raw/master/dists/hanoi.d64) - Includes CP/M boot code, all sources and binaries 13 | 14 | ## Credits 15 | Thanks to [TomHarte](https://github.com/TomHarte) for his [CP/M for OS X](https://github.com/TomHarte/CP-M-for-OS-X) 16 | 17 | ## Screenshots 18 | ### Commodore 128 version 19 | ![C128 version](http://www.sblendorio.eu/images/hanoi-128-1.png) ![C128 version](http://www.sblendorio.eu/images/hanoi-128-2.png) 20 | ### Portable version 21 | ![Portable version](http://www.sblendorio.eu/images/hanoi-p-1.png) ![Portable version](http://www.sblendorio.eu/images/hanoi-p-2.png) 22 | -------------------------------------------------------------------------------- /source/graph.inc: -------------------------------------------------------------------------------- 1 | {----------------------------------------------------------------------------} 2 | { Programmname : GRAPH128.INC } 3 | { Version : 1.00 } 4 | { Aufgabe : Include-File zur Unterstuetzung der 640*200 Grafik } 5 | { Sprache : Turbo Pascal 3.00A } 6 | { Computer : Commodore 128(D) mit RGBI-Monitor } 7 | { Betriebssystem : CP/M 3.0 } 8 | { Autor : Ralph Schlichtmeier } 9 | { Copyright : Markt & Technik Verlag AG } 10 | {----------------------------------------------------------------------------} 11 | 12 | TYPE filename = STRING [14]; 13 | str80 = STRING [80]; 14 | color = (black, dk_grey, blue, lt_blue, green, lt_green, grey, cyan, 15 | red, orange, violet, pink, brown, yellow, lt_grey, white); 16 | chardef = ARRAY [32 .. 127, 0 .. 7] OF BYTE; 17 | switch = (on, off, slow, fast, no); 18 | 19 | VAR charset1, charset2 : chardef; 20 | 21 | {----------------------------------------------------------------------------} 22 | 23 | PROCEDURE VDCregWr (reg, wert: BYTE); 24 | BEGIN 25 | INLINE ($01/$00/$D6/ { LD BC,00D6h } 26 | $3A/reg/ { LD A,(reg) } 27 | $ED/$79/ { OUT (C),A } 28 | $ED/$78/ { status: IN A,(C) } 29 | $17/ { RLA } 30 | $D2/*-5/ { JR NC,status } 31 | $0C/ { INC C } 32 | $3A/wert/ { LD A,(wert) } 33 | $ED/$79) { OUT (C),A } 34 | END; 35 | 36 | {----------------------------------------------------------------------------} 37 | 38 | FUNCTION VDCregRd (reg: BYTE): BYTE; 39 | BEGIN 40 | INLINE ($01/$00/$D6/ { LD BC,00D6h } 41 | $3A/reg/ { LD A,(reg) } 42 | $ED/$79/ { OUT (C),A } 43 | $ED/$78/ { status: IN A,(C) } 44 | $17/ { RLA } 45 | $D2/*-5/ { JR NC,status } 46 | $0C/ { INC C } 47 | $ED/$68/ { IN L,(C) } 48 | $26/$00/ { LD H,00h } 49 | $C9) { RET } 50 | END; 51 | 52 | {----------------------------------------------------------------------------} 53 | 54 | PROCEDURE VDCmemWr (adr : INTEGER; wert : BYTE); 55 | BEGIN 56 | VDCregWr (18, Hi (adr)); VDCregWr (19, Lo (adr)); VDCregWr (31, wert) 57 | { RAM-Adresse HighByte } { RAM-Adresse LowByte } { Datenregister } 58 | END; 59 | 60 | {----------------------------------------------------------------------------} 61 | 62 | FUNCTION VDCmemRd (adr : INTEGER) : BYTE; 63 | BEGIN 64 | VDCregWr (18, Hi (adr)); VDCregWr (19, Lo (adr)); VDCmemRd := VDCregRd (31) 65 | { RAM-Adresse HighByte } { RAM-Adresse LowByte } { Datenregister } 66 | END; 67 | 68 | {----------------------------------------------------------------------------} 69 | 70 | PROCEDURE VDCadrWr (adr : INTEGER); 71 | BEGIN 72 | VDCregWr (18, Hi (adr)); VDCregWr (19, Lo (adr)); 73 | { RAM-Adresse HighByte } { RAM-Adresse LowByte } 74 | END; 75 | 76 | {----------------------------------------------------------------------------} 77 | 78 | PROCEDURE CursorFlash (cf : switch); 79 | VAR mode : BYTE; 80 | BEGIN 81 | CASE cf OF 82 | off : mode := VDCregRd (10) AND 191 OR 32; 83 | slow : mode := VDCregRd (10) OR 96; 84 | fast : mode := VDCregRd (10) AND 223 OR 64; 85 | no : mode := VDCregRd (10) AND 159 86 | ELSE 87 | mode := VDCregRd (10) 88 | END; 89 | VDCregWr (10, mode) 90 | END; 91 | 92 | {----------------------------------------------------------------------------} 93 | 94 | PROCEDURE AltChars (sw : switch); 95 | VAR mode : STRING [3]; 96 | BEGIN 97 | IF sw = on THEN mode := 'G1' ELSE mode := 'G0'; 98 | Write (CON, #27, mode) 99 | END; 100 | 101 | {----------------------------------------------------------------------------} 102 | 103 | PROCEDURE Flash (sw : switch); 104 | VAR mode : STRING [3]; 105 | BEGIN 106 | IF sw = on THEN mode := 'G2' ELSE mode := 'G0'; 107 | Write (CON, #27, mode) 108 | END; 109 | 110 | {----------------------------------------------------------------------------} 111 | 112 | PROCEDURE Underline (sw : switch); 113 | VAR mode : STRING [3]; 114 | BEGIN 115 | IF sw = on THEN mode := 'G3' ELSE mode := 'G0'; 116 | Write (CON, #27, mode) 117 | END; 118 | {----------------------------------------------------------------------------} 119 | 120 | PROCEDURE Reverse (sw : switch); 121 | VAR mode : STRING [3]; 122 | BEGIN 123 | IF sw = on THEN mode := 'G4' ELSE mode := 'G0'; 124 | Write (CON, #27, mode) 125 | END; 126 | {----------------------------------------------------------------------------} 127 | 128 | PROCEDURE InvScr; 129 | BEGIN 130 | VDCregWr (24, VDCregRd (24) XOR 64) 131 | END; 132 | 133 | {----------------------------------------------------------------------------} 134 | 135 | PROCEDURE Bell; 136 | BEGIN 137 | REPEAT 138 | Write (#7); Delay (500) 139 | UNTIL KeyPressed 140 | END; 141 | 142 | {----------------------------------------------------------------------------} 143 | 144 | PROCEDURE TextColor (txtcolor : color); 145 | CONST colorcode : ARRAY [0 .. 15] OF BYTE = (0, 12, 6, 14, 5, 13, 11, 3, 146 | 2, 10, 8, 4, 9, 7, 15, 1); 147 | VAR txt : BYTE; 148 | BEGIN 149 | txt := 32 OR (colorcode [Ord (txtcolor)]); 150 | Write (CON, #27#27#27, Chr(txt)) 151 | END; 152 | 153 | {----------------------------------------------------------------------------} 154 | 155 | PROCEDURE BackgroundColor (bgrcolor : color); 156 | VAR bgr : BYTE; 157 | BEGIN 158 | bgr := (VDCregRd (26) AND 240) OR Ord (bgrcolor); 159 | VDCregWr (26, bgr) 160 | { Farbregister unteres Nibble, Farbe aus Reg. 26 } 161 | END; 162 | 163 |  -------------------------------------------------------------------------------- /source/hanoi128.pas: -------------------------------------------------------------------------------- 1 | PROGRAM Hanoi; 2 | {$I GRAPH.INC} 3 | CONST _ESC = #27; 4 | _CLS = #26; 5 | _HOME = #30; 6 | _REVERSE = #27'G4'; 7 | _PLAIN = #27'G0'; 8 | _BLINK = #27'G2'; 9 | _UNDERLINE = #27'G3'; 10 | _ALTSET = #27'G1'; 11 | _DARK = #27')'; 12 | _LIGHT = #27'('; 13 | _BEEP = #7; 14 | 15 | {0} _BLACK = #27#27#27#32; 16 | {1} _WHITE = #27#27#27#33; 17 | {2} _RED = #27#27#27#34; 18 | {3} _CYAN = #27#27#27#35; 19 | {4} _PURPLE = #27#27#27#36; 20 | {5} _GREEN = #27#27#27#37; 21 | {6} _BLUE = #27#27#27#38; 22 | {7} _YELLOW = #27#27#27#39; 23 | {8} _DARKPURPLE = #27#27#27#40; 24 | {9} _BROWN = #27#27#27#41; 25 | {10} _LIGHTRED = #27#27#27#42; 26 | {11} _DARKGREY = #27#27#27#43; 27 | {12} _MIDGREY = #27#27#27#44; 28 | {13} _LIGHTGREEN = #27#27#27#45; 29 | {14} _LIGHTBLUE = #27#27#27#46; 30 | {15} _LIGHTGREY = #27#27#27#47; 31 | 32 | colorset:array[1..7] of string[4]=(_BLUE,_DARKGREY,_LIGHTGREEN,_RED,_DARKPURPLE, 33 | _GREEN,_CYAN); 34 | 35 | type charset=set of char; 36 | stringvar=string[100]; 37 | 38 | var ch:char; 39 | stack:array [1..3] of string[7]; 40 | block:array [1..7] of string[80]; 41 | l,scelta,ctemp:integer; 42 | anim:byte; 43 | 44 | procedure hidecursor; 45 | begin 46 | cursorflash(off); 47 | end; 48 | 49 | procedure showcursor; 50 | begin 51 | cursorflash(fast); 52 | end; 53 | 54 | function readkey(validkeys:charset):char; 55 | var ch:char; 56 | begin 57 | repeat read(kbd,ch) until ch in validkeys; 58 | readkey := ch; 59 | end; 60 | 61 | function repl(a:stringvar;n:integer):stringvar; 62 | var i:integer; 63 | b:stringvar; 64 | begin 65 | b:=''; 66 | if n>0 then 67 | for i:=1 to n do b:=b+a; 68 | repl:=b; 69 | end; 70 | 71 | function pot(x,y:integer):integer; 72 | var i,pt:integer; 73 | begin 74 | pt:=1; 75 | for i:=1 to y do pt:=pt*x; 76 | pot:=pt; 77 | end; 78 | 79 | function atoi(s:stringvar):integer; 80 | var n,err:integer; 81 | begin 82 | val(s,n,err); 83 | atoi:=n; 84 | end; 85 | 86 | function itoa(n:integer):stringvar; 87 | var s:stringvar; 88 | begin 89 | str(n,s); 90 | itoa:=s; 91 | end; 92 | 93 | function lastchar(s:stringvar):char; 94 | begin 95 | lastchar := s[length(s)]; 96 | end; 97 | 98 | function invpos(s:stringvar;c:char):integer; 99 | var i,p:integer; 100 | begin 101 | p:=0; 102 | if length(s)>0 then 103 | for i:=1 to length(s) do 104 | if s[i]=c then p:=i; 105 | invpos:=p; 106 | end; 107 | 108 | function scambia(p,d:integer):boolean; 109 | var valida:boolean; 110 | a,b:integer; 111 | begin 112 | a:=atoi(lastchar(stack[p])); 113 | b:=atoi(lastchar(stack[d])); 114 | if stack[d]='' then b:=100; 115 | if (a<>0) and (a-1) then begin 164 | write(_BEEP); 165 | dispmessage('Base n.'+itoa(p)+' is empty'); 166 | end; 167 | until (length(stack[p])<>0) or (p=-1); 168 | if p=-1 then begin 169 | input:=1; 170 | exit; 171 | end; 172 | gotoxy(64,6); write(_DARKPURPLE,itoa(p)); 173 | gotoxy(64,7); 174 | d:=getnumber; 175 | if d=-1 then begin 176 | input:=1; 177 | exit; 178 | end; 179 | gotoxy(64,7); write(_DARKPURPLE,itoa(d)); 180 | input:=0; 181 | end; 182 | 183 | procedure plotbox(x1,y1,x2,y2:integer); 184 | var i,j:integer; 185 | begin 186 | for i:=1 to 2 do 187 | for j:=y1 to y2 do begin 188 | if i=1 then gotoxy(x1,j) else gotoxy(x2,j); 189 | write(_RED,_REVERSE,' '); 190 | end; 191 | gotoxy(x1,y1); write(_RED,_REVERSE,repl(' ',x2-x1+1)); 192 | gotoxy(x1,y2); write(_RED,_REVERSE,repl(' ',x2-x1+1)); 193 | write(_PLAIN); 194 | end; 195 | 196 | procedure center(y:integer;col:stringvar;s:stringvar); 197 | begin 198 | gotoxy((80-length(s)) div 2,y);write(col,s); 199 | end; 200 | 201 | procedure pulisci(a,b:integer); 202 | var i:integer; 203 | s:stringvar; 204 | begin 205 | s:=repl(' ',72); 206 | for i:=a to b do begin 207 | gotoxy(5,i);write(s); 208 | end; 209 | end; 210 | 211 | procedure initialize; 212 | begin 213 | anim:=0; 214 | l:=2; 215 | scelta:=1; 216 | end; 217 | 218 | procedure introscreen; 219 | begin 220 | if scelta=1 then begin 221 | clrscr; 222 | plotbox(3,2,78,24); 223 | plotbox(4,2,77,24); 224 | end else 225 | pulisci(3,23); 226 | gotoxy(36,4); write(_CYAN,'Towers of'); 227 | gotoxy(24,06); write(_YELLOW); 228 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ', _REVERSE,' ', _PLAIN,' ',_REVERSE,' '); 229 | write(_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 230 | gotoxy(24,07); write(_YELLOW); 231 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 232 | write(_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 233 | gotoxy(24,08); write(_YELLOW); 234 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 235 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 236 | gotoxy(24,09); write(_YELLOW); 237 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ', _PLAIN, ' '); 238 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 239 | gotoxy(24,10); write(_YELLOW); 240 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 241 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 242 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 243 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 244 | gotoxy(24,11); write(_YELLOW); 245 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 246 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 247 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 248 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 249 | gotoxy(24,12); write(_YELLOW); 250 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 251 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 252 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 253 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 254 | gotoxy(29,14); write(_PLAIN,_CYAN,'by Francesco Sblendorio'); 255 | end; 256 | 257 | function writeboolean(v:byte):stringvar; 258 | begin 259 | case v of 260 | 0: writeboolean:='Off'; 261 | 1: writeboolean:='On '; 262 | end; 263 | end; 264 | 265 | procedure selectionscreen; 266 | var c:char; 267 | m,err:integer; 268 | begin 269 | gotoxy(32,16); write(_BLUE, 'Make your choice'); 270 | gotoxy(21,17); write(_BLUE, 'Use ',_WHITE,'+',_BLUE,' and ',_WHITE,'-',_BLUE,' keys to change blocks number'); 271 | m:=0; 272 | while (m<1) or (m>4) do begin 273 | gotoxy(21,19); write(_BLACK,'1. Start game. Number of blocks: ',_WHITE,itoa(l),' ',_BLACK); 274 | gotoxy(21,20); write('2. Toggle animation. Current: ',_WHITE,writeboolean(anim),_BLACK); 275 | gotoxy(21,21); write('3. About Towers of Hanoi'); 276 | gotoxy(21,22); write('4. Exit to CP/M command prompt'); 277 | c:=readkey(['1','2','3','4','+','-',#13,#27]); 278 | val(c,m,err); 279 | if (c='+') and (l<7) then l:=l+1; 280 | if (c='-') and (l>1) then l:=l-1; 281 | if (c=#13) then m:=1; 282 | if (c=#27) then m:=4; 283 | end; 284 | scelta:=m; 285 | end; 286 | 287 | procedure printblock(n:byte); 288 | begin 289 | write(_REVERSE,colorset[n],block[n],_PLAIN); 290 | end; 291 | 292 | procedure resetgame; 293 | var i,j:integer; 294 | c:char; 295 | begin 296 | j:=-1; 297 | for i:=1 to 7 do 298 | block[i]:=_PLAIN+repl(' ',(7-i)*2)+_REVERSE+repl(' ',4*i-2)+_PLAIN+repl(' ',(7-i)*2); 299 | for i:=1 to 3 do stack[i]:=''; 300 | for i:=l downto 1 do stack[1]:=stack[1]+itoa(i); 301 | clrscr; 302 | plotbox(1,1,80,23); 303 | gotoxy(1,2); insline; 304 | gotoxy(1,2); write(_RED,_REVERSE,' ',_PLAIN,repl(' ',78),_REVERSE,' '); 305 | gotoxy(2,23);write(_BLACK,_REVERSE,repl(' ',13),'1',repl(' ',25),'2',repl(' ',25),'3',repl(' ',12),_PLAIN); 306 | gotoxy(7,4);write(_BROWN,'Current status'); 307 | gotoxy(7,6);write(_BLUE,'# Moves done :'); 308 | gotoxy(7,7);write(_BLUE,'# Moves needed: ',_WHITE,pot(2,l)-1); 309 | gotoxy(58,4);write(_RED,'Move'); 310 | gotoxy(58,6);write(_DARKPURPLE,'From:'); 311 | gotoxy(58,7);write(_DARKPURPLE,' To:'); 312 | gotoxy(2,24);write(_RED,_REVERSE,'>',_PLAIN); 313 | dispmessage(''); 314 | end; 315 | 316 | procedure visual; 317 | var i,j,k:integer; 318 | b:stringvar; 319 | begin 320 | for i:=1 to 3 do begin 321 | b:=stack[i]; 322 | k:=length(b); 323 | if k<>0 then 324 | for j:=1 to k do begin 325 | gotoxy(2+(26*(i-1)),23-j); 326 | printblock(atoi(b[j])); 327 | end; 328 | gotoxy(2+(26*(i-1)),22-k); write(_PLAIN,repl(' ',26)); 329 | end; 330 | end; 331 | 332 | procedure moveblock(p,d:integer); 333 | var xStart,xEnd,yStart,yEnd,b,Dx,i:integer; 334 | begin 335 | yStart:=23-length(stack[p]); 336 | yEnd:=23-length(stack[d]); 337 | xStart:=2+(26*(p-1)); 338 | xEnd:=2+(26*(d-1)); 339 | Dx:=d-p; 340 | b:=atoi(lastchar(stack[d])); 341 | for i:=yStart-2 downto 14 do begin 342 | gotoxy(xStart,i); printblock(b); 343 | gotoxy(xStart,i+1); write(_PLAIN,repl(' ',26)); 344 | delay(40); 345 | end; 346 | delay(60); 347 | if Dx>0 then begin 348 | for i:=xStart to xEnd-1 do begin 349 | gotoxy(i,14); write(_PLAIN,' '); printblock(b); 350 | delay(25); 351 | end; 352 | end else begin 353 | for i:=xStart-1 downto xEnd do begin 354 | gotoxy(i,14); printblock(b); write(_PLAIN,' '); 355 | delay(25); 356 | end; 357 | end; 358 | delay(75); 359 | for i:=15 to yEnd do begin 360 | gotoxy(xEnd,i); printblock(b); 361 | gotoxy(xEnd,i-1); write(_PLAIN,repl(' ',26)); 362 | delay(40); 363 | end; 364 | end; 365 | 366 | procedure game; 367 | var p,d,mosse,min:integer; 368 | c:char; 369 | valida:boolean; 370 | begin 371 | resetgame; 372 | mosse:=0; 373 | min:=pot(2,l)-1; 374 | visual; 375 | while (not verify) do begin 376 | repeat 377 | showcursor; 378 | if input(p,d)=1 then begin 379 | hidecursor; 380 | exit; 381 | end; 382 | valida:=scambia(p,d); 383 | if not valida then begin 384 | write(_BEEP); 385 | if p<>d then 386 | dispmessage(itoa(p)+' to '+itoa(d)+': Illegal move') 387 | else 388 | dispmessage('FROM=TO: Illegal move'); 389 | end else begin 390 | delay(300); 391 | hidecursor; 392 | mosse:=mosse+1; 393 | end; 394 | until valida; 395 | if anim=1 then begin 396 | dispmessage('Move from '+itoa(p)+' to '+itoa(d)); 397 | moveblock(p,d); 398 | end; 399 | dispmessage(''); 400 | gotoxy(23,6); 401 | if mosse<=min then write(_WHITE) else write(_RED); 402 | write(mosse); 403 | visual; 404 | end; 405 | if mosse=min then begin 406 | center(10,_RED,'P E R F E C T'); 407 | dispmessage('You won'); 408 | write(_BEEP); 409 | end else begin 410 | center(10,_BLACK,'It''s ok, but you could do it better'); 411 | dispmessage('You could do it better, try again'); 412 | write(_BEEP); 413 | end; 414 | center(13,_WHITE,'-- Press any key to go back to main menu --'); 415 | read(kbd,c); 416 | end; 417 | 418 | procedure infoscreen; 419 | var c:char; 420 | begin 421 | pulisci(3,22); 422 | center(4,_BLACK+_REVERSE,' '); 423 | center(5,_BLACK+_REVERSE,' Towers of Hanoi '); 424 | center(6,_BLACK+_REVERSE,' '); 425 | center(8,_PLAIN+_YELLOW,'written by'); 426 | center(9,_YELLOW,'Francesco Sblendorio'); 427 | center(10,_BLUE+_UNDERLINE,'http://www.sblendorio.eu'); 428 | center(12,_PLAIN+_WHITE,'(C) 1996 MS-DOS version (C) 2015 CP/M version'); 429 | write(_PLAIN); 430 | read(kbd,c); 431 | end; 432 | 433 | procedure esci; 434 | var c:char; 435 | begin 436 | pulisci(16,22); 437 | center(18,_RED,'Are you sure you want to exit?'); 438 | center(20,_WHITE,'(Y/N)'); 439 | c := readkey(['y','Y','n','N','0','1',#27]); 440 | case c of 441 | 'y','Y','1': scelta:=4; 442 | 'n','N','0',#27: scelta:=-1; 443 | end; 444 | end; 445 | 446 | procedure exitscreen; 447 | begin 448 | write(_PLAIN,_WHITE); 449 | backgroundcolor(black); 450 | clrscr; 451 | end; 452 | 453 | begin 454 | hidecursor; 455 | backgroundcolor(lt_grey); write(_PLAIN); 456 | initialize; 457 | repeat 458 | if scelta=-1 then pulisci(16,22) else if scelta<>2 then introscreen; 459 | selectionscreen; 460 | case scelta of 461 | 1: game; 462 | 2: anim:=1-anim; 463 | 3: infoscreen; 464 | 4: esci; 465 | end; 466 | until scelta=4; 467 | exitscreen; 468 | showcursor; 469 | end. 470 | -------------------------------------------------------------------------------- /source/hanoi-p.pas: -------------------------------------------------------------------------------- 1 | PROGRAM Hanoi; 2 | {I GRAPH.INC} 3 | CONST _ESC = #27; 4 | _CLS = #26; 5 | _HOME = #30; 6 | _REVERSE = #27'B0'; 7 | _PLAIN = #27'C0'; 8 | _BLINK = #27'B2'; 9 | _NOBLINK = #27'C2'; 10 | _UNDERLINE = #27'B3'; 11 | _NOUNDERLINE = #27'C3'; 12 | _DARK = #27'B1'; 13 | _LIGHT = #27'C1'; 14 | _BEEP = #7; 15 | 16 | { 17 | _BLACK = #27#27#27#32; 18 | _WHITE = #27#27#27#33; 19 | _RED = #27#27#27#34; 20 | _CYAN = #27#27#27#35; 21 | _PURPLE = #27#27#27#36; 22 | _GREEN = #27#27#27#37; 23 | _BLUE = #27#27#27#38; 24 | _YELLOW = #27#27#27#39; 25 | _DARKPURPLE = #27#27#27#40; 26 | _BROWN = #27#27#27#41; 27 | _LIGHTRED = #27#27#27#42; 28 | _DARKGREY = #27#27#27#43; 29 | _MIDGREY = #27#27#27#44; 30 | _LIGHTGREEN = #27#27#27#45; 31 | _LIGHTBLUE = #27#27#27#46; 32 | _LIGHTGREY = #27#27#27#47; 33 | } 34 | _BLACK = ''; 35 | _WHITE = ''; 36 | _RED = ''; 37 | _CYAN = ''; 38 | _PURPLE = ''; 39 | _GREEN = ''; 40 | _BLUE = ''; 41 | _YELLOW = ''; 42 | _DARKPURPLE = ''; 43 | _BROWN = ''; 44 | _LIGHTRED = ''; 45 | _DARKGREY = ''; 46 | _MIDGREY = ''; 47 | _LIGHTGREEN = ''; 48 | _LIGHTBLUE = ''; 49 | _LIGHTGREY = ''; 50 | 51 | colorset:array[1..7] of string[4]=(_BLUE,_DARKGREY,_LIGHTGREEN,_RED,_DARKPURPLE, 52 | _GREEN,_CYAN); 53 | 54 | type charset=set of char; 55 | stringvar=string[100]; 56 | 57 | var ch:char; 58 | stack:array [1..3] of string[7]; 59 | block:array [1..7] of string[80]; 60 | l,scelta,ctemp:integer; 61 | anim:byte; 62 | 63 | procedure hidecursor; 64 | begin 65 | { cursorflash(off); } 66 | write(#27'C4'); 67 | end; 68 | 69 | procedure showcursor; 70 | begin 71 | { cursorflash(fast); } 72 | write(#27'B4'); 73 | end; 74 | 75 | function readkey(validkeys:charset):char; 76 | var ch:char; 77 | begin 78 | repeat read(kbd,ch) until ch in validkeys; 79 | readkey := ch; 80 | end; 81 | 82 | function repl(a:stringvar;n:integer):stringvar; 83 | var i:integer; 84 | b:stringvar; 85 | begin 86 | b:=''; 87 | if n>0 then 88 | for i:=1 to n do b:=b+a; 89 | repl:=b; 90 | end; 91 | 92 | function pot(x,y:integer):integer; 93 | var i,pt:integer; 94 | begin 95 | pt:=1; 96 | for i:=1 to y do pt:=pt*x; 97 | pot:=pt; 98 | end; 99 | 100 | function atoi(s:stringvar):integer; 101 | var n,err:integer; 102 | begin 103 | val(s,n,err); 104 | atoi:=n; 105 | end; 106 | 107 | function itoa(n:integer):stringvar; 108 | var s:stringvar; 109 | begin 110 | str(n,s); 111 | itoa:=s; 112 | end; 113 | 114 | function lastchar(s:stringvar):char; 115 | begin 116 | lastchar := s[length(s)]; 117 | end; 118 | 119 | function invpos(s:stringvar;c:char):integer; 120 | var i,p:integer; 121 | begin 122 | p:=0; 123 | if length(s)>0 then 124 | for i:=1 to length(s) do 125 | if s[i]=c then p:=i; 126 | invpos:=p; 127 | end; 128 | 129 | function scambia(p,d:integer):boolean; 130 | var valida:boolean; 131 | a,b:integer; 132 | begin 133 | a:=atoi(lastchar(stack[p])); 134 | b:=atoi(lastchar(stack[d])); 135 | if stack[d]='' then b:=100; 136 | if (a<>0) and (a-1) then begin 185 | write(_BEEP); 186 | dispmessage('Base n.'+itoa(p)+' is empty'); 187 | end; 188 | until (length(stack[p])<>0) or (p=-1); 189 | if p=-1 then begin 190 | input:=1; 191 | exit; 192 | end; 193 | gotoxy(64,6); write(_DARKPURPLE,itoa(p)); 194 | gotoxy(64,7); 195 | d:=getnumber; 196 | if d=-1 then begin 197 | input:=1; 198 | exit; 199 | end; 200 | gotoxy(64,7); write(_DARKPURPLE,itoa(d)); 201 | input:=0; 202 | end; 203 | 204 | procedure plotbox(x1,y1,x2,y2:integer); 205 | var i,j:integer; 206 | begin 207 | for i:=1 to 2 do 208 | for j:=y1 to y2 do begin 209 | if i=1 then gotoxy(x1,j) else gotoxy(x2,j); 210 | write(_RED,_REVERSE,' '); 211 | end; 212 | gotoxy(x1,y1); write(_RED,_REVERSE,repl(' ',x2-x1+1)); 213 | gotoxy(x1,y2); write(_RED,_REVERSE,repl(' ',x2-x1+1)); 214 | write(_PLAIN); 215 | end; 216 | 217 | procedure center(y:integer;col:stringvar;s:stringvar); 218 | begin 219 | gotoxy((80-length(s)) div 2,y);write(col,s); 220 | end; 221 | 222 | procedure pulisci(a,b:integer); 223 | var i:integer; 224 | s:stringvar; 225 | begin 226 | s:=repl(' ',72); 227 | for i:=a to b do begin 228 | gotoxy(5,i);write(s); 229 | end; 230 | end; 231 | 232 | procedure initialize; 233 | begin 234 | anim:=0; 235 | l:=2; 236 | scelta:=1; 237 | end; 238 | 239 | procedure introscreen; 240 | begin 241 | if scelta=1 then begin 242 | clrscr; 243 | plotbox(3,2,78,24); 244 | plotbox(4,2,77,24); 245 | end else 246 | pulisci(3,23); 247 | gotoxy(36,4); write(_CYAN,'Towers of'); 248 | gotoxy(24,06); write(_YELLOW,_DARK); 249 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ', _REVERSE,' ', _PLAIN,' ',_REVERSE,' '); 250 | write(_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 251 | gotoxy(24,07); write(_YELLOW); 252 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 253 | write(_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 254 | gotoxy(24,08); write(_YELLOW); 255 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 256 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 257 | gotoxy(24,09); write(_YELLOW); 258 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' ', _PLAIN, ' '); 259 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 260 | gotoxy(24,10); write(_YELLOW); 261 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 262 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 263 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 264 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 265 | gotoxy(24,11); write(_YELLOW); 266 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 267 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 268 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 269 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 270 | gotoxy(24,12); write(_YELLOW); 271 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 272 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 273 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' ',_PLAIN,' '); 274 | write(_REVERSE,' ',_PLAIN,' ',_REVERSE,' '); 275 | gotoxy(29,14); write(_LIGHT,_PLAIN,_CYAN,'by Francesco Sblendorio'); 276 | end; 277 | 278 | function writeboolean(v:byte):stringvar; 279 | begin 280 | case v of 281 | 0: writeboolean:='Off'; 282 | 1: writeboolean:='On '; 283 | end; 284 | end; 285 | 286 | procedure selectionscreen; 287 | var c:char; 288 | m,err:integer; 289 | begin 290 | gotoxy(32,16); write(_BLUE, 'Make your choice'); 291 | gotoxy(21,17); write(_BLUE, 'Use ',_WHITE,'+',_BLUE,' and ',_WHITE,'-',_BLUE,' keys to change blocks number'); 292 | m:=0; 293 | while (m<1) or (m>4) do begin 294 | gotoxy(21,19); write(_BLACK,'1. Start game. Number of blocks: ',_WHITE,itoa(l),' ',_BLACK); 295 | gotoxy(21,20); write('2. Toggle animation. Current: ',_WHITE,writeboolean(anim),_BLACK); 296 | gotoxy(21,21); write('3. About Towers of Hanoi'); 297 | gotoxy(21,22); write('4. Exit to CP/M command prompt'); 298 | c:=readkey(['1','2','3','4','+','-',#13,#27]); 299 | val(c,m,err); 300 | if (c='+') and (l<7) then l:=l+1; 301 | if (c='-') and (l>1) then l:=l-1; 302 | if (c=#13) then m:=1; 303 | if (c=#27) then m:=4; 304 | end; 305 | scelta:=m; 306 | end; 307 | 308 | procedure printblock(n:byte); 309 | begin 310 | { write(_REVERSE,colorset[n],block[n],_PLAIN); } 311 | write(_REVERSE,_DARK,colorset[n],block[n],_LIGHT,_PLAIN); 312 | end; 313 | 314 | procedure resetgame; 315 | var i,j:integer; 316 | c:char; 317 | begin 318 | j:=-1; 319 | for i:=1 to 7 do 320 | block[i]:=_PLAIN+repl(' ',(7-i)*2)+_REVERSE+repl(' ',4*i-2)+_PLAIN+repl(' ',(7-i)*2); 321 | for i:=1 to 3 do stack[i]:=''; 322 | for i:=l downto 1 do stack[1]:=stack[1]+itoa(i); 323 | clrscr; 324 | plotbox(1,1,80,23); 325 | gotoxy(1,2); insline; 326 | gotoxy(1,2); write(_RED,_REVERSE,' ',_PLAIN,repl(' ',78),_REVERSE,' '); 327 | gotoxy(2,23);write(_BLACK,_REVERSE,repl(' ',13),'1',repl(' ',25),'2',repl(' ',25),'3',repl(' ',12),_PLAIN); 328 | gotoxy(7,4);write(_BROWN,'Current status'); 329 | gotoxy(7,6);write(_BLUE,'# Moves done :'); 330 | gotoxy(7,7);write(_BLUE,'# Moves needed: ',_WHITE,pot(2,l)-1); 331 | gotoxy(58,4);write(_RED,'Move'); 332 | gotoxy(58,6);write(_DARKPURPLE,'From:'); 333 | gotoxy(58,7);write(_DARKPURPLE,' To:'); 334 | gotoxy(2,24);write(_RED,_REVERSE,'>',_PLAIN); 335 | dispmessage(''); 336 | end; 337 | 338 | procedure visual; 339 | var i,j,k:integer; 340 | b:stringvar; 341 | begin 342 | for i:=1 to 3 do begin 343 | b:=stack[i]; 344 | k:=length(b); 345 | if k<>0 then 346 | for j:=1 to k do begin 347 | gotoxy(2+(26*(i-1)),23-j); 348 | printblock(atoi(b[j])); 349 | end; 350 | gotoxy(2+(26*(i-1)),22-k); write(_PLAIN,repl(' ',26)); 351 | end; 352 | end; 353 | 354 | procedure moveblock(p,d:integer); 355 | var xStart,xEnd,yStart,yEnd,b,Dx,i:integer; 356 | begin 357 | yStart:=23-length(stack[p]); 358 | yEnd:=23-length(stack[d]); 359 | xStart:=2+(26*(p-1)); 360 | xEnd:=2+(26*(d-1)); 361 | Dx:=d-p; 362 | b:=atoi(lastchar(stack[d])); 363 | for i:=yStart-2 downto 14 do begin 364 | gotoxy(xStart,i); printblock(b); 365 | gotoxy(xStart,i+1); write(_PLAIN,repl(' ',26)); 366 | delay(40); 367 | end; 368 | delay(60); 369 | if Dx>0 then begin 370 | for i:=xStart to xEnd-1 do begin 371 | gotoxy(i,14); write(_PLAIN,' '); printblock(b); 372 | delay(25); 373 | end; 374 | end else begin 375 | for i:=xStart-1 downto xEnd do begin 376 | gotoxy(i,14); printblock(b); write(_PLAIN,' '); 377 | delay(25); 378 | end; 379 | end; 380 | delay(75); 381 | for i:=15 to yEnd do begin 382 | gotoxy(xEnd,i); printblock(b); 383 | gotoxy(xEnd,i-1); write(_PLAIN,repl(' ',26)); 384 | delay(40); 385 | end; 386 | end; 387 | 388 | procedure game; 389 | var p,d,mosse,min:integer; 390 | c:char; 391 | valida:boolean; 392 | begin 393 | resetgame; 394 | mosse:=0; 395 | min:=pot(2,l)-1; 396 | visual; 397 | while (not verify) do begin 398 | repeat 399 | showcursor; 400 | if input(p,d)=1 then begin 401 | hidecursor; 402 | exit; 403 | end; 404 | valida:=scambia(p,d); 405 | if not valida then begin 406 | write(_BEEP); 407 | if p<>d then 408 | dispmessage(itoa(p)+' to '+itoa(d)+': Illegal move') 409 | else 410 | dispmessage('FROM=TO: Illegal move'); 411 | end else begin 412 | delay(300); 413 | hidecursor; 414 | mosse:=mosse+1; 415 | end; 416 | until valida; 417 | if anim=1 then begin 418 | dispmessage('Move from '+itoa(p)+' to '+itoa(d)); 419 | moveblock(p,d); 420 | end; 421 | dispmessage(''); 422 | gotoxy(23,6); 423 | if mosse<=min then write(_WHITE) else write(_RED); 424 | write(mosse); 425 | visual; 426 | end; 427 | if mosse=min then begin 428 | center(10,_RED,'P E R F E C T'); 429 | dispmessage('You won'); 430 | write(_BEEP); 431 | end else begin 432 | center(10,_BLACK,'It''s ok, but you could do it better'); 433 | dispmessage('You could do it better, try again'); 434 | write(_BEEP); 435 | end; 436 | center(13,_WHITE,'-- Press any key to go back to main menu --'); 437 | read(kbd,c); 438 | end; 439 | 440 | procedure infoscreen; 441 | var c:char; 442 | begin 443 | pulisci(3,22); 444 | center(4,_BLACK+_REVERSE,' '); 445 | center(5,_BLACK+_REVERSE,' Towers of Hanoi '); 446 | center(6,_BLACK+_REVERSE,' '); 447 | center(8,_PLAIN+_YELLOW,'written by'); 448 | center(9,_YELLOW,'Francesco Sblendorio'); 449 | center(10,_BLUE+_UNDERLINE,'http://www.sblendorio.eu'); 450 | center(12,_NOUNDERLINE+_WHITE,'(C) 1996 MS-DOS version (C) 2015 CP/M version'); 451 | write(_PLAIN); 452 | read(kbd,c); 453 | end; 454 | 455 | procedure esci; 456 | var c:char; 457 | begin 458 | pulisci(16,22); 459 | center(18,_RED,'Are you sure you want to exit?'); 460 | center(20,_WHITE,'(Y/N)'); 461 | c := readkey(['y','Y','n','N','0','1',#27]); 462 | case c of 463 | 'y','Y','1': scelta:=4; 464 | 'n','N','0',#27: scelta:=-1; 465 | end; 466 | end; 467 | 468 | procedure exitscreen; 469 | begin 470 | write(_PLAIN,_WHITE,_NOUNDERLINE); 471 | { backgroundcolor(black); } 472 | clrscr; 473 | end; 474 | 475 | begin 476 | hidecursor; 477 | { backgroundcolor(lt_grey); } 478 | write(_PLAIN); 479 | initialize; 480 | repeat 481 | if scelta=-1 then pulisci(16,22) else if scelta<>2 then introscreen; 482 | selectionscreen; 483 | case scelta of 484 | 1: game; 485 | 2: anim:=1-anim; 486 | 3: infoscreen; 487 | 4: esci; 488 | end; 489 | until scelta=4; 490 | exitscreen; 491 | showcursor; 492 | end. 493 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------