/* Now that you have the source file in the screen editor, let`s use some of */ /* the edit commands available to us. Referring to the source listing in */ /* Chapter 2 of the I2ICE System User's Guide, we see that the first errors */ /* we encountered were in the GET_INPUT procedure at lines 70 and 71. */ /* */ /* Let`s use the FIND edit command to locate the first error. In our case, */ /* VALUE is used several times, so we will need more than just the word VALUE*/ /* to identify the line we want. Move the cursor to the start of the source */ /* listing. Type F (for FIND). The editor will prompt: FIND"". Enter the*/ /* string you want to find: */ /* VALUE = VALUE + CHAR - '0' */ /* is used to terminate this command. Some edit commands do not */ /* require you to press the key after entering a command. When */ /* is required to execute a command, it will be shown next to the command in */ /* brackets (< >). */ /* */ /* NOTE: Enter the string exactly as shown. The editor is searching for an */ /* exact match. If the editor does not find the string, it will display the */ /* following message (at the bottom of the screen): */ /* not found: "name-of-the-string-you-are-searching-for" */ /* */ $title('===> Change Maker Demo <===') Cmaker: DO; DECLARE TRUE literally '0FFH', FALSE literally '0', IN_PORT literally '1', OUT_PORT literally '2', lf_cr (2) BYTE DATA (0AH, 0DH), paid_text (*) BYTE DATA (7, 'Paid = '), purchased_text (*) BYTE DATA (8, 'Price = '), coins WORD, change WORD, dollars WORD, quarters WORD, nickels WORD, dimes WORD, pennies WORD, paid WORD, purchased WORD; $eject read: PROCEDURE BYTE; /*Sets char equal to ASCII byte received*/ DECLARE /*from port 1; writes byte to output port*/ char BYTE; /*also*/ char = INPUT(in_port); RETURN char; END read; write: PROCEDURE (text_ptr, text_cnt); /*Writes text_cnt ASCII bytes */ DECLARE /*that begin at txt_ptr to port2*/ text_ptr POINTER, text_cnt WORD, text BASED text_ptr (1) BYTE, i WORD; DO i = 0 TO text_cnt - 1; OUTPUT(out_port) = text(i); END; END write; write_decimal: PROCEDURE (value);/*Stores decimal digits in the array*/ DECLARE /*digit_stack; calls for their conver-*/ value WORD, /*sion to ASCII*/ i WORD, digit_stack(5) BYTE, stk_top WORD; stk_top = 5; DO WHILE value > 0; digit_stack(stk_top := stk_top - 1) = value MOD 10; value = value/10; END; DO i = stk_top TO 5; CALL convert_decimal_digit(digit_stack(i)); END; END write_decimal; convert_decimal_digit: PROCEDURE (decimal_digit);/*Converts decimal digit*/ DECLARE /*to ASCII numbers and */ decimal_digit BYTE, /*calls WRITE for each */ ascii_digit BYTE; /*ASCII digit */ ascii_digit = decimal_digit + '0'; CALL write(@ascii_digit, 1); END convert_decimal_digit; print_coin: PROCEDURE (text_ptr, value); /*Formats writing of change */ DECLARE /*values and TEXT; calls */ text_ptr POINTER, /*Write_decimal procedure */ value WORD, text BASED text_ptr STRUCTURE (cnt BYTE, string(1) BYTE), text_cnt BYTE; /* NOTE */ /* When you are searching backwards from the current cursor position, the */ /* cursor is positioned at the beginning of the string when a match is found.*/ /* With the AGAIN command you can repeat the last edit command performed. */ /* Use it now to search for another match of the string THIS IS A TEST. */ /* Enter A */ /* */ /* In our case, this was the only string the editor was able to find. Let's */ /* use the FIND command to find the start of our last set of editing instruc-*/ /* tions. Enter F. Enter the string to search for as shown below: */ /* QUIT */ /* NOTE: If the cursor is positioned above the string you are looking for, */ /* it will stop at that string since a match has been made. Press A to */ /* search again. */ /* */ IF value = 0 THEN RETURN; CALL write (@(' '), 2); CALL write_decimal(value); text_cnt = text.cnt; IF value = 1 THEN text_cnt = text_cnt - 1; /* make singular */ CALL write(@text.string, text_cnt); CALL write(@lf_cr, 2); END print_coin; payment: PROCEDURE; /*Specifies order in which*/ DECLARE /*change information is */ s_text (*) BYTE DATA (8, ' dollars'), /*written; calls */ q_text (*) BYTE DATA (9, ' quarters'), /*formatting procedure */ n_text (*) BYTE DATA (8, ' nickels'), d_text (*) BYTE DATA (6, ' dimes'), p_text (*) BYTE DATA (8, ' pennies'), p1_text (*) BYTE DATA (7, ' penny'); IF (dollars OR quarters OR dimes OR nickels OR pennies) = 0 THEN CALL write(@('No change'), 9); ELSE DO; CALL write(@('Change = '),9); CALL write (@lf_cr, 2); CALL print_coin(@s_text, dollars); CALL print_coin(@q_text, quarters); CALL print_coin(@d_text, dimes); CALL print_coin(@n_text, nickels); IF pennies = 1 THEN CALL print_coin(@p1_text, pennies); ELSE CALL print_coin(@p_text, pennies); END; END payment; get_input: PROCEDURE (text_ptr) WORD; /*Writes request to output; */ DECLARE /*converts each received ASCII*/ text_ptr POINTER, /*byte to a decimal digit and */ value_ptr POINTER, /*assembles decimal values */ value WORD, char BYTE, not_done BYTE, text BASED text_ptr STRUCTURE (cnt BYTE, string(1) BYTE); CALL write(@text.string, text.cnt); value = 0; not_done = TRUE; DO WHILE not_done; char = read; IF (char >= '0') AND (char <= '9') THEN DO; value = value + char - '0'; value = value / 10; /* */ /* NOTE */ /* The cursor stops at the end of the string when it finds a perfect match. */ /* Let's search backwards for a string now. Use the -find edit command to */ /* do this. Type -. Now enter the string to search for: */ /* THIS IS A TEST */ /* */ END ELSE not_done = FALSE; END; RETURN value; END get_input; begin:; DO; CALL write (@lf_cr, 2); paid = get_input(@paid_text); purchased = get_input(@purchased_text); CALL write (@lf_cr, 2); change = paid - purchased; dollars = change/100; coins = change MOD 100; quarters = coins/25; coins = coins MOD 25; dimes = coins/10; coins = coins MOD 10; nickels = coins/5; pennies = coins MOD 5; IF paid < purchased THEN CALL write(@('NO CHEATING!'), 12); ELSE CALL payment; END; exit:; HALT; END; /* QUIT */ /* To exit from the I2ICE editor and return to the tutorial use the QUIT */ /* command. Enter Q. Notice the menu options available to you. You have */ /* the choice of aborting from the editor (without saving the code), exe- */ /* cuting the file (I2ICE debug object file), initializing a new edit session*/ /* without exiting from the editor, or writing the code out to a disk file. */ /* */ /* Since we did not make any changes to our source file, we do not need to */ /* save it. Let's use the ABORT command to exit from the editor. Enter A. */ /* The editor will prompt you with the message: all changes lost? (y or [n]).*/ /* Enter Y. After the I2ICE prompt (*) appears on the screen, enter N */ /* to obtain the next tutorial screen. */