Create your own text control codes: Difference between revisions

→‎{{header|PL/M}}: Bug fix and tweaks
(Added PL/M)
(→‎{{header|PL/M}}: Bug fix and tweaks)
Line 105:
 
=={{header|PL/M}}==
PL/M doesn't have a standard printf function, or indeed a standard library.<br><br>
This sample implements a PRINTF procedure somewhat like the standard C library routine.<br><br>
Although CP/M uses ASCII, Kildall's original 8080 PL/M compiler only supports a limited character set for the program's source. In particular the compiler doesn't like lowercase letters, % or \. PL/M also requires procedures to be called with the same number of parameters they were defined with. The PRINTF defined here has the format string plus seven parameters, if fewer parameters are required, additional dummy parameters must be supplied<br>
Line 191:
/* STRING */
CALL PR$STRING( P( PPOS ) );
PPOS = PPOS + 1;
END;
ELSE IF FCH = 'I' OR FCH = 'D' THEN DO;
/* SIGNED DECIMAL INTEGER */
DECLARE V ADDRESS;
V = P( PPOS );
IF V > 32767 THEN DO;
CALL PR$CHAR( '-' );
V = - V;
END;
CALL PR$NUMBER( V );
PPOS = PPOS + 1;
END;
ELSE IF FCH = 'U' THEN DO;
/* UNSIGNED DECIMAL INTEGER */
CALL PR$NUMBER( P( PPOS ) );
PPOS = PPOS + 1;
END;
Line 216 ⟶ 200:
ELSE IF FCH = 'L' THEN DO;
/* CHARACTER OR STRING CONVERTED TO LOWER CASE */
PPOSDECLARE =V PPOS + 1BYTE;
FPTR = FPTR + 1;
IF FCH = 'S' THEN DO;
Line 222 ⟶ 207:
DECLARE SCH BASED SPTR BYTE;
SPTR = P( PPOS );
DO WHILE( ( V := SCH ) <> '$' );
IF SCHV >= 'A' AND SCHV <= 'Z' THEN SCHV = SCHV + 32;
CALL PR$CHAR( SCHV );
SPTR = SPTR + 1;
END;
Line 230 ⟶ 215:
ELSE DO;
/* LOWERCASE CHARACTER */
DECLARE V BYTE;
V = LOW( P( PPOS ) );
IF V >= 'A' AND V <= 'Z' THEN V = V + 32;
CALL PR$CHAR( V );
END;
PPOS = PPOS + 1;
END;
ELSE IF FCH = 'I' OR FCH = 'D' OR FCH = 'U' THEN DO;
/* SIGNED OR UNSIGNED DECIMAL INTEGER */
DECLARE V ADDRESS;
V = P( PPOS );
IF FCH <> 'U' AND V > 32767 THEN DO;
/* THE NUMBER IS NEGATIVE AND MUST BE PRINTED AS SIGNED */
CALL PR$CHAR( '-' );
V = - V;
END;
CALL PR$NUMBER( V );
PPOS = PPOS + 1;
END;
3,022

edits