PRINTDCI quick-and-easy ASM printing routine
Synopsis
This short routine makes it easy to print strings from assembly code, or even from the mini-assembler. (Especially in the Enhanced monitor, which lets you enter ASCII characters using a ` prefix.)
Detail
Assemblers like EDASM have a directive called DCI that encodes an ASCII string in such a way that the end of the string can be distinguished by checking its high bit. The DCI statement converts your string into ASCII bytes so that most characters have the high bit cleared, but the last character has its high bit set.
The PRINTDCI routine pops the return address off the stack, parses-and-prints ASCII characters starting at the return address until it finds the last character (denoted by its high bit), and then pushes an updated return address onto the stack and returns to the next opcode.
|
How to use PRINTDCI it in ASM:
In the simplest case, when you want to print a text string, just insert JSR PRINTDCI into your assembler source code, then on the next line use the assembler's DCI
directive to enter your string. On the line after that, just continue your assembler program.
Here's an example, from KR9600 TESTER showing two branches that print short messages.
You can also use ASC and DB to print more elaborate strings, like titles and column headings. If you want more precise control over the end-of-string, use the MSB OFF and MSB ON directive to control the high bit yourself. Here's how KR9600 TESTER begins by printing its title, line breaks, and column headings via a single call to JSR PRINTDCI followed by contiguous control-characters and string directives.
The source code for PRINTDCI is listed at the top of this blogpost. And the source for PRINTDCI and KR9600 TESTER are both included as text files on the Prince of Persia Pre-boot disk with KR9600 TESTER attached to the KR9600 Tester blogpost.
- S.Elliott's blog
- Log in or register to post comments