diff --git a/doc/sym1.sgml b/doc/sym1.sgml index d02e3b1b1..f04f36ae1 100644 --- a/doc/sym1.sgml +++ b/doc/sym1.sgml @@ -113,6 +113,7 @@ All the samples will run on the "stock" 4k Sym-1, except for symio.c, symTiny does the same as symhello, but does it with puts() rather than printf() to show the difference in compiled binary size. symDisplay allows entry of a message, which is then displayed by scrolling it across the front panel display. symIO allows access to the Sym-1 digital I/O ports. +symNotepad is a simple text entry/retrieval program that uses tape storage. License

diff --git a/samples/symNotepad.c b/samples/symNotepad.c new file mode 100644 index 000000000..e9866e526 --- /dev/null +++ b/samples/symNotepad.c @@ -0,0 +1,198 @@ +// -------------------------------------------------------------------------- +// 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. +// +// -------------------------------------------------------------------------- + +#include ; +#include ; +#include ; + +#define TAPIO_ADDRESS 0xE000 +#define TAPIO_MAX_SIZE 0x0FFF + +void main(void) { + char 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; + 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--; + } + } + else if( c == 0x13 ) { // Save + puts( "\n========================= Save =========================" ); + puts( "\nPress any key to save." ); + c = getchar(); + for( l = 0; l <= p; l++ ) { + tapio[l] = buffer[l]; + } + l++; + tapio[l] = 0x00; + puts( "Saving to tape." ); + error = dumpt( 'N', (int) tapio, (int) tapio+p ); + if( error ) { + puts( "\nTape error." ); + } + else + { + putchar( '\r' ); + for( l = 0; l < 25; l++ ) { + putchar( '\n' ); + } + } + puts( "===================== Sym-1 Notepad ====================\n" ); + for( l = 0; l <= p; l++ ) { + putchar( buffer[l] ); + if( buffer[l] == '\r' ) { + putchar( '\n' ); + } + } + } + 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] ); + if( buffer[l] == '\r' ) { + putchar( '\n' ); + } + } + } + } + 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 { + if( c == '\r' ) { + putchar( '\n' ); + } + buffer[p] = c; + putchar( c ); + } + p++; + } + } + } + + free( buffer ); + + puts( "\nEnjoy your day!\n" ); + + return; +} diff --git a/samples/tutorial/sym1/symNotepad.c b/samples/tutorial/sym1/symNotepad.c new file mode 100644 index 000000000..e9866e526 --- /dev/null +++ b/samples/tutorial/sym1/symNotepad.c @@ -0,0 +1,198 @@ +// -------------------------------------------------------------------------- +// 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. +// +// -------------------------------------------------------------------------- + +#include ; +#include ; +#include ; + +#define TAPIO_ADDRESS 0xE000 +#define TAPIO_MAX_SIZE 0x0FFF + +void main(void) { + char 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; + 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--; + } + } + else if( c == 0x13 ) { // Save + puts( "\n========================= Save =========================" ); + puts( "\nPress any key to save." ); + c = getchar(); + for( l = 0; l <= p; l++ ) { + tapio[l] = buffer[l]; + } + l++; + tapio[l] = 0x00; + puts( "Saving to tape." ); + error = dumpt( 'N', (int) tapio, (int) tapio+p ); + if( error ) { + puts( "\nTape error." ); + } + else + { + putchar( '\r' ); + for( l = 0; l < 25; l++ ) { + putchar( '\n' ); + } + } + puts( "===================== Sym-1 Notepad ====================\n" ); + for( l = 0; l <= p; l++ ) { + putchar( buffer[l] ); + if( buffer[l] == '\r' ) { + putchar( '\n' ); + } + } + } + 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] ); + if( buffer[l] == '\r' ) { + putchar( '\n' ); + } + } + } + } + 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 { + if( c == '\r' ) { + putchar( '\n' ); + } + buffer[p] = c; + putchar( c ); + } + p++; + } + } + } + + free( buffer ); + + puts( "\nEnjoy your day!\n" ); + + return; +}