home *** CD-ROM | disk | FTP | other *** search
- (*
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓·── ──·▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓│ │░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ Unit was conceived, designed and written ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ by Floor A.C. Naaijkens for ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ UltiHouse Software / The ECO Group. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ (C) MCMXCII by EUROCON PANATIONAL CORPORATION. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ All Rights Reserved for The ECO Group. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓│ │░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓·── ──·░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- *)
- {$O+}
- unit eco_pclc;
-
- interface
- uses
- dos, crt, eco_lib
-
- ;
-
-
- procedure __setcalc(x,y,f,b:integer);
- function __popcalc: real;
-
-
-
- implementation
-
-
- const
- fore: byte = lightgray;
- back: byte = black;
-
-
- var
- operand : char;
- chin : char;
- displaynum : real;
- storagenum : real;
- memory : real;
- tempst : string[15];
- shiftst : string[15];
- clearmem : boolean;
- justop : boolean;
- justnum : boolean;
- decch : char;
- ndec : integer;
- err : integer;
- exitcalc : boolean;
- xpos,ypos : integer;
- saveattr : byte;
-
-
-
- procedure beep;
- begin
- sound(1600); delay(30); sound(1300); delay(50); nosound;
- end;
-
-
- procedure __setcalc(x,y,f,b:integer); { sets position of calculator }
- begin
- xpos := x;
- ypos := y;
- if xpos > 60 then xpos := 60; { make sure calculator is on screen }
- if ypos > 19 then ypos := 19;
- if xpos < 1 then xpos := 1;
- if ypos < 1 then ypos := 1;
- fore := f; back := b;
- end;
-
-
-
- function readfromscr(x,y,len:integer): string;
- var
- tempstr : string;
- ii,l : integer;
- coff : boolean;
- r : registers;
-
- begin
- coff := false; { set true if cursor is already off }
- { turn off the cursor }
- r.ax := $0300; { service 3 }
- intr($10,r); { interrupt 10 to get cursor scan lines}
- if (r.cx and $2000) = $2000 then coff := true;
- r.cx := r.cx or $2000; { set bit 5 of top scan line to 1 }
- r.ax := $0100; { service 1 }
- intr($10,r); { interrupt 10 to turn off }
- l := 0;
- for ii := 1 to len do begin
- gotoxy(x+ii-1,y); { locate cursor }
- { read a character from the screen }
- r.ax := $0800; { service 8 }
- r.bh := 0; { screen 0 }
- intr($10,r); { interrupt 10 }
- tempstr[ii] := chr(r.al); { char returned in al }
- if tempstr[ii] <> ' ' then l := ii { if non blank remember length }
- end;
- if not coff then begin
- { flip the cursor back on }
- r.ax := $0300; { service 3 again }
- intr($10,r); { interrupt 10 to get scan lines }
- r.cx := r.cx and $dfff; { flip bit 5 of top scan line to 0 }
- r.ax := $0100; { service 1 }
- intr($10,r); {interrupt 10 to turn on cursor }
- end;
-
- tempstr[0] := chr(l); { set the string length to last non blank char. }
- readfromscr := tempstr; { set function result to temporary string }
- end;
-
-
-
-
- procedure operate; { here's where we do the arithmetic }
- begin
-
- { if a number string was just entered get it and turn it into a real value }
- if justnum then begin
- val(readfromscr(xpos+3,ypos+2,15),displaynum,err);
- justnum := false;
- end;
-
- case operand of
- '+' : displaynum := storagenum + displaynum; { addition }
- '-' : displaynum := storagenum - displaynum; { subtraction }
- '*' : displaynum := storagenum * displaynum; { multiplication }
- '/' : displaynum := storagenum / displaynum; { division }
- { add more stuff here if you wish }
- end; {case}
-
- str(displaynum:15:ndec,tempst); __write(xpos+3,ypos+2,fore,back,tempst);
- justop := true; __write(xpos+19,ypos+2,fore,back,' ');
- end;
-
-
-
- function __popcalc : real; { pocketcalc returns the value in the display }
- var sav : _scnimageptr;
- begin
- new(sav); __savscn(sav);
- exitcalc := false; justop := true; justnum := false;
- clearmem := false; operand := ' ';
- __bandwin(true, xpos,ypos,xpos+22,ypos+18, fore, back, sh_default, bt_single);
- __betwscn(xpos, xpos+22,ypos,fore,back,' Pocket Calculator ');
- __write(xpos+2,ypos+4,fore,back, '┌─────────┐ ┌───┐');
- __write(xpos+2,ypos+5,fore,back, '│ 7 8 9 │ │ / │');
- __write(xpos+2,ypos+6,fore,back, '│ 4 5 6 │ │ * │');
- __write(xpos+2,ypos+7,fore,back, '│ 1 2 3 │ │ - │');
- __write(xpos+2,ypos+8,fore,back, '│ │ │ + │');
- __write(xpos+2,ypos+9,fore,back, '│ 0 . │ │ = │');
- __write(xpos+2,ypos+10,fore,back,'└─────────┘ └───┘');
- __write(xpos+2,ypos+11,fore,back,'┌───────────────┐');
- __write(xpos+2,ypos+12,fore,back,'│ C Clear │');
- __write(xpos+2,ypos+13,fore,back,'│ D Decimal Pl. │');
- __write(xpos+2,ypos+14,fore,back,'│ M Mem. +-*/=R │');
- __write(xpos+2,ypos+15,fore,back,'└───────────────┘');
- str(displaynum:15:ndec,tempst); { display default number }
- __write(xpos+3,ypos+2,fore,back,tempst); { if first time this is zero }
- gotoxy(xpos+17,ypos+2);
- repeat { start of big keystroke reading loop }
- chin := upcase(readkey);
- case chin of
- '0'..'9','.' : begin { process a number keystroke }
- justnum := true; { if 1st digit clear display }
- if justop then __write(xpos+3,ypos+2,fore,back,' ');
- justop := false; { clear memory line at bottom }
- if clearmem then begin
- __write(xpos+2,ypos+17,fore,back,' ');
- clearmem := false;
- end; { read existing numbers from screen }
- shiftst := readfromscr(xpos+3,ypos+2,15);
- { add a zero to front of string if user entered decimal because turbo }
- { val function won't recognize a number that begins with a decimal }
- if (chin = '.') and (shiftst = '') then shiftst := ' 0';
- delete(shiftst,1,1); { delete leftmost digit (ususally blank )}
- { write out the shifted number string }
- __write(xpos+3,ypos+2,fore,back,shiftst);
- { finally write out the digit read in }
- __write(xpos+17,ypos+2,fore,back,chin);
- end;
-
- '+','-','*','/' : begin { process an operator keystroke }
- { first handle the messy case of negative }
- { numbers rather than the minus operator. }
- { test for negative number conditions }
- if justop and (chin in ['-','+']) and (operand <> ' ') then begin
- __write(xpos+3,ypos+2,fore,back,' ');
- { and write a - or + sign on display }
- __write(xpos+17,ypos+2,fore,back,chin);
- justop := false;
- end else begin { ok now we got a real operator }
- { first clean up the last operation }
- operate; justnum := false; { store the results }
- storagenum := displaynum;
- { put the operator in the hopper for next time }
- operand := chin;
- __write(xpos+20,ypos+2,fore,back,operand);
- end;
- end;
-
- '=',#13 : begin { process enter key or = key }
- operate; { first clean up last operation }
- operand := ' ';
- __write(xpos+20,ypos+2,fore,back,'=');
- end;
-
- 'C' : begin { process a "clear" instruction }
- displaynum := 0; storagenum := 0; operand := '!';
- justop := true; __write(xpos+3,ypos+2,fore,back,' ');
- end;
-
- 'D' : begin { change number of decimal places displayed }
- __write(xpos+2,ypos+17,fore,back,'Decimal Places ? ');
- repeat
- decch := readkey;
- if not (decch in ['0'..'9',#27]) then beep;
- until decch in ['0'..'9',#27];
- if decch <> #27 then begin
- val(decch,ndec,err); { convert the string to a number }
- str(displaynum:15:ndec,tempst); { and rewrite the display }
- __write(xpos+3,ypos+2,fore,back,tempst);
- end; { blank the decimal places prompt }
- __write(xpos+2,ypos+17,fore,back,' ');
- end;
-
- 'M' : begin { process memory stuff here }
- if justnum then begin
- val(readfromscr(xpos+3,ypos+2,15),displaynum,err);
- justnum := false;
- end;
- __write(xpos+2,ypos+17,fore,back,'Mem');
- gotoxy(xpos+6,ypos+17);
- write(memory:14:2);
- { get the second memory keystroke }
- { +, -, c(lear), r(ecall), =, enter, escape }
- repeat
- decch := upcase(readkey);
- if not (decch in ['+','-','C','R','=',#13,#27]) then beep;
- until decch in ['+','-','C','R','=',#13,#27];
-
- if decch <> #27 then begin
- if decch = #13 then decch := '=';
- __write(xpos+6,ypos+17,fore,back,decch);
- case decch of
- '+' : memory := memory + displaynum; { add to memory }
- '-' : memory := memory - displaynum; { subtract from memory }
- 'C' : memory := 0; { clear memory }
- 'R' : begin { recall memory to display }
- str(memory:15:ndec,tempst);
- __write(xpos+3,ypos+2,fore,back,tempst);
- displaynum := memory;
- end;
- '=' : memory := displaynum; { move display into memory }
- end; {case}
- justop := true; gotoxy(xpos+6,ypos+17);
- write(memory:14:2); { write out contents of memory }
- clearmem := true; { set switch to clear mem display }
- end else __write(xpos+2,ypos+17,fore,back,' ');
- end;
-
- #27 : exitcalc := true; { user hit escape -- set switch to exit }
- else beep; { illegal key }
- end; {case}
- until exitcalc; { end of big keystroke loop }
- __resscn(sav); dispose(sav);
- __popcalc := displaynum;
- end;
-
-
-
- begin
- xpos := 10; ypos := 5; displaynum := 0; storagenum := 0;
- memory := 0; ndec := 2;
- end.
-