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
|
|
|
|
|
|
|
void main(void) {
|
2021-06-15 21:39:28 +00:00
|
|
|
cha c = 0x00;
|
|
|
|
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 ) {
|
|
|
|
puts( "Memory full." );
|
|
|
|
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' );
|
|
|
|
}
|
|
|
|
|
|
|
|
puts( "===================== Sym-1 Notepad ====================" );
|
|
|
|
|
|
|
|
if( instruction_needed ) {
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-12 00:08:13 +00:00
|
|
|
puts( "\n========================= Save =========================" );
|
|
|
|
puts( "\nPress any key to save." );
|
|
|
|
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;
|
|
|
|
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 ) {
|
|
|
|
puts( "\nTape error." );
|
|
|
|
}
|
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' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
puts( "===================== Sym-1 Notepad ====================\n" );
|
|
|
|
for( l = 0; l <= p; l++ ) {
|
|
|
|
putchar( buffer[l] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( c == 0x0C ) { // Load
|
|
|
|
p = 0;
|
|
|
|
puts( "\nLoading from tape." );
|
|
|
|
memset( buffer, 0, heap_size );
|
|
|
|
memset( tapio, 0, TAPIO_MAX_SIZE );
|
|
|
|
error = loadt( 'N' );
|
|
|
|
if( error ) {
|
|
|
|
puts( "\nTape error." );
|
|
|
|
puts( "===================== Sym-1 Notepad ====================\n" );
|
|
|
|
}
|
|
|
|
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' );
|
|
|
|
}
|
|
|
|
puts( "===================== Sym-1 Notepad ====================\n" );
|
|
|
|
|
|
|
|
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' );
|
|
|
|
}
|
|
|
|
puts( "===================== Sym-1 Notepad ====================\n" );
|
|
|
|
}
|
|
|
|
else if( c == 0x18 ) { // Exit
|
|
|
|
writing = 0;
|
|
|
|
running = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if( p >= heap_size - 1 ) {
|
|
|
|
puts( "\n========================= End =========================" );
|
|
|
|
puts( "Buffer full." );
|
|
|
|
}
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free( buffer );
|
|
|
|
puts( "\nEnjoy your day!\n" );
|
|
|
|
}
|