I'm puzzling a bit over the TRS-80's printf() implementation. I'm guessing this probably applies to whatever lower level functions printf() is using as well... Basically it *appears* that printf() isn't keeping the TRS-80's cursor location RAM addresses up to date. That wouldn't be a big deal, but it causes weird behavior when your code exits if you've got stuff on the screen that you intend to stay on the screen when you go back to DOS. The classic example would be a command line utility. Basically, since the cursor position RAM locations aren't up to date (addresses 0x4020 and 0x4021), when you exit and return to DOS, DOS stomps over whatever is on the screen at the time instead of gracefully giving you a prompt just below the last thing your program printed.
I was able to hack around this issue by changing trs80_crt0.asm to add these lines in the cleanup: block.
Code: Select all
push hl ld hl, $3f00 ; put cursor toward bottom of screen ld ($4020), hl pop hl
I guess another way to do it would be in the cleanup: routine to examine the contents of the screen buffer, and place the cursor at the line immediately following the lowest non-whitespace thing on the screen. I guess this would still be sort of a hack, since it's non-standard behavior (what if the last thing I did was put the cursor in the middle of the screen with my printf, but there was already stuff below the middle?) Still, it would be better than current behavior, less hacky than the thing above, and wouldn't require diving deeply into the printf() implementation.
My assembler skills are a little rusty, but I'll see if I can figure out how to do that... Stay tuned if you're targeting TRS-80.