1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-17 09:07:32 +00:00
cc65/targettest/sym1/symNotepad.c

193 lines
5.2 KiB
C
Raw Normal View History

2021-05-12 00:08:13 +00:00
// --------------------------------------------------------------------------
// Sym-1 Notepad
//
// Wayne Parham
//
// wayne@parhamdata.com
// --------------------------------------------------------------------------
//
// Note: This program requires RAM memory in locations 0xE000 - 0xEFFF
// Alternatively, the tape I/O buffer location and size can be
// changed by altering the defined TAPIO values below.
//
// --------------------------------------------------------------------------
2021-06-07 16:50:47 +00:00
#include <sym1.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2021-05-12 00:08:13 +00:00
2021-06-15 21:39:28 +00:00
#define TAPIO_ADDRESS 0xE000
#define TAPIO_MAX_SIZE 0x0FFF
2021-05-12 00:08:13 +00:00
2021-06-16 21:47:38 +00:00
int main (void) {
char c = 0x00;
2021-06-15 21:39:28 +00:00
int l = 0x00;
int p = 0x00;
int error = 0x00;
int running = 0x01;
int writing = 0x01;
int instruction_needed = 0x01;
int heap_size = 0x00;
2021-05-12 00:08:13 +00:00
char* tapio = (char*) TAPIO_ADDRESS;
char* buffer;
heap_size = _heapmaxavail();
if( heap_size > TAPIO_MAX_SIZE ) { // No need to malloc more than
heap_size = TAPIO_MAX_SIZE; // the interface allows
}
buffer = malloc( heap_size );
memset( buffer, 0x00, heap_size );
if( buffer == 0x00 ) {
2021-06-16 21:47:38 +00:00
puts ("Memory full.");
2021-05-12 00:08:13 +00:00
running = 0;
}
tapio[0] = 0x00; // Check tape interface memory
if( tapio[0] != 0x00 )
error = 1;
tapio[0] = 0xFF;
if( tapio[0] != 0xFF )
error = 1;
tapio[TAPIO_MAX_SIZE] = 0x00;
if( tapio[TAPIO_MAX_SIZE] != 0x00 )
error = 1;
tapio[TAPIO_MAX_SIZE] = 0xFF;
if( tapio[TAPIO_MAX_SIZE] != 0xFF )
error = 1;
if( error ) {
printf( "\nNo memory at location %p, aborting.\n", tapio );
running = 0;
}
else {
memset( tapio, 0, TAPIO_MAX_SIZE );
}
while( running ) {
putchar( '\r' );
for( l = 0; l < 25; l++ ) {
putchar( '\n' );
}
2021-06-16 21:47:38 +00:00
puts ("===================== Sym-1 Notepad ====================");
2021-05-12 00:08:13 +00:00
if( instruction_needed ) {
2021-06-16 21:47:38 +00:00
puts ("Enter text and you can save it to tape for reloading");
puts ("later. There are four special 'command' characters:\n");
puts (" Control-S Save to tape");
puts (" Control-L Load from tape");
puts (" Control-C Clear memory");
puts (" Control-X Exit");
puts ("========================================================\n");
2021-05-12 00:08:13 +00:00
}
while( writing ) {
c = getchar();
if( c == 0x08 ) { // Backspace
if( p > 0 ) {
buffer[p] = 0x00;
p--;
}
}
2021-05-13 19:43:16 +00:00
else if( c == 0x13 ) { // Save
2021-06-16 21:47:38 +00:00
puts ("\n========================= Save =========================");
puts ("\nPress any key to save.");
2021-05-12 00:08:13 +00:00
c = getchar();
for( l = 0; l <= p; l++ ) {
tapio[l] = buffer[l];
}
2021-05-13 19:43:16 +00:00
l++;
2021-05-12 00:08:13 +00:00
tapio[l] = 0x00;
2021-06-16 21:47:38 +00:00
puts ("Saving to tape.");
2021-06-12 00:55:13 +00:00
error = dumpt( 'N', tapio, tapio+p );
2021-05-12 00:08:13 +00:00
if( error ) {
2021-06-16 21:47:38 +00:00
puts ("\nTape error.");
2021-05-12 00:08:13 +00:00
}
2021-05-13 19:43:16 +00:00
else
2021-05-12 00:08:13 +00:00
{
putchar( '\r' );
for( l = 0; l < 25; l++ ) {
putchar( '\n' );
}
}
2021-06-16 21:47:38 +00:00
puts ("===================== Sym-1 Notepad ====================\n");
2021-05-12 00:08:13 +00:00
for( l = 0; l <= p; l++ ) {
putchar( buffer[l] );
}
}
else if( c == 0x0C ) { // Load
p = 0;
2021-06-16 21:47:38 +00:00
puts ("\nLoading from tape.");
2021-05-12 00:08:13 +00:00
memset( buffer, 0, heap_size );
memset( tapio, 0, TAPIO_MAX_SIZE );
error = loadt( 'N' );
if( error ) {
2021-06-16 21:47:38 +00:00
puts ("\nTape error.");
puts ("===================== Sym-1 Notepad ====================\n");
2021-05-12 00:08:13 +00:00
}
else
{
for( l = 0; l <= heap_size; l++ ) {
buffer[l] = tapio[l];
}
p = strlen( buffer );
putchar( '\r' );
for( l = 0; l < 25; l++ ) {
putchar( '\n' );
}
2021-06-16 21:47:38 +00:00
puts ("===================== Sym-1 Notepad ====================\n");
2021-05-12 00:08:13 +00:00
for( l = 0; l <= p; l++ ) {
putchar( buffer[l] );
}
}
}
else if( c == 0x03 ) { // Clear
p = 0;
memset( buffer, 0, heap_size );
putchar( '\r' );
for( l = 0; l < 25; l++ ) {
putchar( '\n' );
}
2021-06-16 21:47:38 +00:00
puts ("===================== Sym-1 Notepad ====================\n");
2021-05-12 00:08:13 +00:00
}
else if( c == 0x18 ) { // Exit
writing = 0;
running = 0;
}
else {
if( p >= heap_size - 1 ) {
2021-06-16 21:47:38 +00:00
puts ("\n========================= End =========================");
puts ("Buffer full.");
2021-05-12 00:08:13 +00:00
}
else {
2021-06-12 00:55:13 +00:00
if( c == '\n' ) {
2021-05-12 00:08:13 +00:00
putchar( '\n' );
}
buffer[p] = c;
}
p++;
}
}
}
2021-05-12 00:08:13 +00:00
free( buffer );
2021-06-16 21:47:38 +00:00
puts ("\nEnjoy your day!\n");
return 0;
2021-05-12 00:08:13 +00:00
}