Adafruit_Learning_System_Gu.../runcpm-rp2350-hstx-usb/runcpm-pico/console.h

64 lines
1.4 KiB
C

// SPDX-FileCopyrightText: 2023 Mockba the Borg
//
// SPDX-License-Identifier: MIT
#ifndef CONSOLE_H
#define CONSOLE_H
extern int _kbhit(void);
uint8_t _getch(void);
void _putch(uint8 ch);
/* see main.c for definition */
uint8 mask8bit = 0x7f; // TO be used for masking 8 bit characters (XMODEM related)
// If set to 0x7f, RunCPM masks the 8th bit of characters sent
// to the console. This is the standard CP/M behavior.
// If set to 0xff, RunCPM passes 8 bit characters. This is
// required for XMODEM to work.
// Use the CONSOLE7 and CONSOLE8 programs to change this on the fly.
uint8 _chready(void) // Checks if there's a character ready for input
{
return(_kbhit() ? 0xff : 0x00);
}
uint8 _getchNB(void) // Gets a character, non-blocking, no echo
{
return(_kbhit() ? _getch() : 0x00);
}
void _putcon(uint8 ch) // Puts a character
{
_putch(ch & mask8bit);
}
void _puts(const char* str) // Puts a \0 terminated string
{
while (*str)
_putcon(*(str++));
}
void _puthex8(uint8 c) // Puts a HH hex string
{
_putcon(tohex(c >> 4));
_putcon(tohex(c & 0x0f));
}
void _puthex16(uint16 w) // puts a HHHH hex string
{
_puthex8(w >> 8);
_puthex8(w & 0x00ff);
}
void _putdec(uint16_t w) {
char buf[] = " 0";
size_t i=sizeof(buf)-1;
while(w) {
assert(i > 0);
buf[--i] = '0' + (w % 10);
w /= 10;
}
_puts(buf);
}
#endif