46 lines
1.1 KiB
C
46 lines
1.1 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
#include <vcc/printer.h>
|
|
#include "format-internal.h"
|
|
|
|
// Use the BASIC PUTCHR vector directly so a CMOC console hook stays private
|
|
// to the program. Restore the previous BASIC device after each character.
|
|
static asm void printerChar(unsigned char c)
|
|
{
|
|
asm {
|
|
lda 3,s
|
|
cmpa #10
|
|
bne @send
|
|
lda #13
|
|
@send ldb >$006f ; BASIC DEVNUM
|
|
pshs b,y,u
|
|
ldb #-2 ; DEV_PRINTER
|
|
stb >$006f
|
|
jsr [$a002] ; PUTCHR takes the character in A
|
|
puls b,y,u
|
|
stb >$006f
|
|
}
|
|
}
|
|
|
|
static int writePrinter(void *context, const char *source, char fill, unsigned count)
|
|
{
|
|
while (count--) {
|
|
char c = source ? *source++ : fill;
|
|
printerChar(c);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int vcc_printer_vprintf(const char *format, va_list args)
|
|
{
|
|
return vcc_format_to(writePrinter, 0, format, args);
|
|
}
|
|
|
|
int vcc_printer_printf(const char *format, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, format);
|
|
int result = vcc_printer_vprintf(format, args);
|
|
va_end(args);
|
|
return result;
|
|
}
|