2020-08-17 02:59:23 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2020-09-02 03:46:43 +00:00
|
|
|
// Apple //e Enhanced text editor
|
2020-08-09 23:36:46 +00:00
|
|
|
// Supports Apple //e Auxiliary memory and RamWorks style expansions
|
2020-09-02 03:46:43 +00:00
|
|
|
// Bobbi July-Sept 2020
|
2020-07-12 21:34:11 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2020-09-02 03:46:43 +00:00
|
|
|
//
|
|
|
|
// See GitHub for open issues!!!
|
|
|
|
//
|
2020-09-01 01:17:30 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2020-08-01 04:25:08 +00:00
|
|
|
// Note: Use my fork of cc65 to get a flashing cursor!!
|
2020-09-01 01:17:30 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2020-07-19 16:25:55 +00:00
|
|
|
|
2020-08-01 06:29:33 +00:00
|
|
|
#include <conio.h>
|
|
|
|
#include <ctype.h>
|
2020-09-06 18:40:50 +00:00
|
|
|
#include <dio.h>
|
2020-09-02 00:13:25 +00:00
|
|
|
#include <dirent.h>
|
2020-08-01 06:29:33 +00:00
|
|
|
#include <stdint.h>
|
2020-07-12 21:34:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-07-15 21:21:59 +00:00
|
|
|
#include <string.h>
|
2020-07-15 22:51:46 +00:00
|
|
|
#include <unistd.h>
|
2020-07-12 21:34:11 +00:00
|
|
|
|
2020-07-16 21:38:37 +00:00
|
|
|
#define NCOLS 80 // Width of editing screen
|
|
|
|
#define NROWS 22 // Height of editing screen
|
2020-08-11 20:29:26 +00:00
|
|
|
#define CURSORROW 10 // Row cursor initially shown on (if enough text)
|
2020-07-19 21:53:49 +00:00
|
|
|
#define PROMPT_ROW NROWS + 1 // Row where input prompt is shown
|
2020-08-07 02:43:14 +00:00
|
|
|
#define IOSZ 1024 // Size of chunks to use when loading/saving file
|
2020-08-13 19:46:16 +00:00
|
|
|
#define CUTBUFSZ 8192 // Size of cut buffer. Must be >IOSZ.
|
2020-07-12 21:34:11 +00:00
|
|
|
|
2020-09-06 20:47:03 +00:00
|
|
|
#define INFOADDR 0x0800 // Aux mem address for info about buffer
|
|
|
|
#define GAPBUFADDR 0x0880 // Aux mem address for gapbuffer itself
|
|
|
|
|
2020-09-03 22:58:47 +00:00
|
|
|
#define EOL '\r' // ProDOS uses CR line endings
|
2020-07-18 04:03:27 +00:00
|
|
|
|
|
|
|
#define BELL 0x07
|
|
|
|
#define BACKSPACE 0x08
|
|
|
|
#define RETURN 0x0d
|
2020-07-19 15:15:57 +00:00
|
|
|
#define ESC 0x1b
|
2020-07-18 04:03:27 +00:00
|
|
|
#define DELETE 0x7f
|
2020-07-12 21:34:11 +00:00
|
|
|
|
2020-09-06 21:21:51 +00:00
|
|
|
// Aux memory from GAPBUFADDR to 0xbffe (0xbfff is zero pad byte)
|
|
|
|
#define BUFSZ (0xbffe - GAPBUFADDR)
|
2020-08-13 19:46:16 +00:00
|
|
|
char iobuf[CUTBUFSZ]; // Buffer for disk I/O and cut/paste
|
2020-08-09 23:36:46 +00:00
|
|
|
uint8_t banktbl[1+8*16]; // Handles up to 8MB. Map of banks.
|
2020-08-17 02:46:47 +00:00
|
|
|
uint8_t auxbank = 0; // Currently selected aux bank (physical)
|
|
|
|
uint8_t l_auxbank = 1; // Currently selected aux bank (logical)
|
2020-08-13 19:46:16 +00:00
|
|
|
uint16_t cutbuflen = 0; // Length of data in cut buffer
|
2020-08-06 02:30:55 +00:00
|
|
|
|
2020-08-09 22:16:59 +00:00
|
|
|
// The following fields, plus the gap buffer, represent the state of
|
|
|
|
// the current buffer. These are stashed in each aux page from 0x200 up.
|
2020-09-01 01:17:30 +00:00
|
|
|
// Total 80 + 3 + 2 + 2 + 1 + 2 + 2 = 92 bytes
|
|
|
|
#define BUFINFOSZ 92
|
2020-08-09 22:16:59 +00:00
|
|
|
char filename[80] = "";
|
2020-08-12 03:04:46 +00:00
|
|
|
uint8_t status[3] = {0, 0, 0}; // status[0] is 1 if file has been modified
|
2020-08-11 20:29:26 +00:00
|
|
|
// status[1] is 1 if should warn for overwrite
|
2020-08-12 03:04:46 +00:00
|
|
|
// status[2] is part # for multi-part files
|
2020-08-09 22:16:59 +00:00
|
|
|
uint16_t gapbegin = 0;
|
|
|
|
uint16_t gapend = BUFSZ - 1;
|
2020-09-01 01:17:30 +00:00
|
|
|
uint8_t canundo = 0; // For OA-Z "Undo"
|
|
|
|
uint16_t oldgapbegin = 0; // ditto
|
|
|
|
uint16_t oldgapend = BUFSZ - 1; // ditto
|
2020-07-12 21:34:11 +00:00
|
|
|
|
2020-08-05 23:30:32 +00:00
|
|
|
char userentry[82] = ""; // Couple extra chars so we can store 80 col line
|
2020-07-18 05:22:33 +00:00
|
|
|
char search[80] = "";
|
2020-07-19 05:25:29 +00:00
|
|
|
char replace[80] = "";
|
2020-09-02 22:42:00 +00:00
|
|
|
char startdir[80] = "";
|
2020-07-16 21:38:37 +00:00
|
|
|
|
2020-08-11 20:29:26 +00:00
|
|
|
uint8_t rowlen[NROWS]; // Number of chars on each row of screen
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
// Interface to read_char_update_pos()
|
2020-08-09 22:16:59 +00:00
|
|
|
uint8_t do_print;
|
2020-08-17 16:44:13 +00:00
|
|
|
uint16_t pos = 0, startsel = 65535U, endsel = 65535U;
|
2020-07-12 21:34:11 +00:00
|
|
|
uint8_t row, col;
|
|
|
|
|
|
|
|
uint8_t cursrow, curscol; // Cursor position is kept here by draw_screen()
|
|
|
|
|
2020-09-03 22:58:47 +00:00
|
|
|
uint8_t email_mode; // If 0 quit to ProDOS
|
|
|
|
// If 1 quit to EMAIL.SYSTEM
|
|
|
|
// If 2 ask about attachments and quit to either
|
|
|
|
// ATTACHER.SYSTEM (if y) or EMAIL.SYSTEM (if n)
|
2020-07-16 21:38:37 +00:00
|
|
|
|
2020-08-13 19:46:16 +00:00
|
|
|
enum editmode {SEL_NONE, SEL_SELECT, SRCH1, SRCH2, SRCH3};
|
|
|
|
enum editmode mode;
|
2020-07-17 21:30:16 +00:00
|
|
|
|
2020-07-19 04:21:03 +00:00
|
|
|
// Mousetext Open-Apple
|
2020-07-18 04:03:27 +00:00
|
|
|
char openapple[] = "\x0f\x1b""A\x18\x0e";
|
|
|
|
|
2020-08-10 21:15:39 +00:00
|
|
|
// Mousetext Closed-Apple
|
|
|
|
char closedapple[] = "\x0f\x1b""@\x18\x0e";
|
|
|
|
|
2020-09-03 01:37:39 +00:00
|
|
|
char openfilemsg[] =
|
|
|
|
" Select file from tree browser, or [Tab] to enter filename. [Esc] cancels.";
|
|
|
|
|
|
|
|
char namefilemsg[] =
|
|
|
|
" Enter a new filename to create file. Select an existing file to overwrite it.";
|
|
|
|
|
2020-09-06 20:47:03 +00:00
|
|
|
// The following are used for reconnecting /RAM and /RAM3 on exit
|
|
|
|
uint16_t s3d1vec;
|
|
|
|
uint16_t s3d2vec;
|
|
|
|
uint8_t s3d1dev;
|
|
|
|
uint8_t s3d2dev;
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
/*
|
|
|
|
* Return number of bytes of freespace in gapbuf
|
|
|
|
*/
|
|
|
|
#define FREESPACE() (gapend - gapbegin + 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return number of bytes of data in gapbuf
|
|
|
|
*/
|
|
|
|
#define DATASIZE() (gapbegin + (BUFSZ - 1 - gapend))
|
2020-07-18 02:33:25 +00:00
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
/*
|
|
|
|
* Obtain current position in gapbuf
|
|
|
|
* This is the positon where the next character will be inserted
|
|
|
|
*/
|
|
|
|
#define GETPOS() (gapbegin)
|
|
|
|
|
2020-08-06 02:30:55 +00:00
|
|
|
/*
|
|
|
|
* Obtain one byte from the gapbuf[] in aux memory
|
|
|
|
* Must be in LC
|
2020-08-07 03:42:52 +00:00
|
|
|
* i - Index into gapbuf[]
|
|
|
|
* Returns value at gapbuf[i]
|
2020-08-06 02:30:55 +00:00
|
|
|
*/
|
|
|
|
#pragma code-name (push, "LC")
|
|
|
|
char get_gapbuf(uint16_t i) {
|
2020-09-06 20:47:03 +00:00
|
|
|
*(uint16_t*)(0xfe) = (uint16_t)GAPBUFADDR + i; // Stuff address in Zero Page
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
|
|
|
__asm__("sta $c003"); // Read aux mem
|
2020-08-06 02:30:55 +00:00
|
|
|
__asm__("lda ($fe)");
|
|
|
|
__asm__("sta $ff");
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("sta $c002"); // Read main mem
|
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-08-06 02:30:55 +00:00
|
|
|
return *(uint8_t*)(0xff);
|
|
|
|
}
|
|
|
|
#pragma code-name (pop)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set one byte in the gapbuf[] in aux memory
|
|
|
|
* Must be in LC
|
2020-08-07 03:42:52 +00:00
|
|
|
* i - Index into gapbuf
|
|
|
|
* c - Byte value to set
|
2020-08-06 02:30:55 +00:00
|
|
|
*/
|
|
|
|
#pragma code-name (push, "LC")
|
|
|
|
void set_gapbuf(uint16_t i, char c) {
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-08-06 02:30:55 +00:00
|
|
|
__asm__("sta $c005"); // Write aux mem
|
2020-09-06 20:47:03 +00:00
|
|
|
(*(char*)((char*)GAPBUFADDR + i)) = c;
|
2020-08-06 02:30:55 +00:00
|
|
|
__asm__("sta $c004"); // Write main mem
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-08-06 02:30:55 +00:00
|
|
|
}
|
|
|
|
#pragma code-name (pop)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a memmove() on aux memory. Uses indices into gapbuf[].
|
|
|
|
* Must be in LC
|
2020-08-07 03:42:52 +00:00
|
|
|
* dst - Destination index into gapbuf[]
|
|
|
|
* src - Source index into gapbuf[]
|
2020-08-26 23:40:12 +00:00
|
|
|
* n - Length in bytes
|
2020-08-06 02:30:55 +00:00
|
|
|
*/
|
|
|
|
#pragma code-name (push, "LC")
|
2020-08-06 03:45:23 +00:00
|
|
|
void move_in_gapbuf(uint16_t dst, uint16_t src, size_t n) {
|
|
|
|
if (dst > src) {
|
2020-08-07 02:30:51 +00:00
|
|
|
// Start with highest addr and copy downwards
|
2020-08-07 02:43:14 +00:00
|
|
|
*(uint16_t*)(0xfa) = n; // Stuff sz in ZP
|
2020-09-06 20:47:03 +00:00
|
|
|
*(uint16_t*)(0xfc) = (uint16_t)GAPBUFADDR + src - 1; // Stuff src in ZP
|
|
|
|
*(uint16_t*)(0xfe) = (uint16_t)GAPBUFADDR + dst - 1; // Stuff dst in ZP
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-08-06 03:45:23 +00:00
|
|
|
__asm__("sta $c005"); // Write aux mem
|
|
|
|
__asm__("sta $c003"); // Read aux mem
|
2020-08-26 23:40:12 +00:00
|
|
|
__asm__("clc"); // Prepare the source pointer
|
|
|
|
__asm__("lda $fd"); // MSB of source
|
|
|
|
__asm__("adc $fb"); // MSB of n
|
|
|
|
__asm__("sta $fd");
|
2020-08-07 02:14:26 +00:00
|
|
|
|
2020-08-26 23:40:12 +00:00
|
|
|
__asm__("clc"); // Prepare the dest pointer
|
|
|
|
__asm__("lda $ff"); // MSB of dest
|
|
|
|
__asm__("adc $fb"); // MSB of n
|
|
|
|
__asm__("sta $ff");
|
2020-08-07 02:14:26 +00:00
|
|
|
|
2020-08-26 23:40:12 +00:00
|
|
|
__asm__("ldy $fa"); // LSB of n
|
|
|
|
dl1:
|
|
|
|
__asm__("lda ($fc),y");
|
|
|
|
__asm__("sta ($fe),y");
|
2020-08-26 23:48:26 +00:00
|
|
|
__asm__("cpy #$00"); // Copy leftover bytes
|
|
|
|
__asm__("beq %g", ds1);
|
2020-08-26 23:40:12 +00:00
|
|
|
__asm__("dey");
|
|
|
|
__asm__("jmp %g", dl1);
|
|
|
|
ds1:
|
|
|
|
__asm__("ldx #$00");
|
|
|
|
dl2:
|
|
|
|
__asm__("cpx $fb"); // MSB of n
|
|
|
|
__asm__("beq %g", ds2); // No more complete 256 byte blocks, done!
|
|
|
|
__asm__("dec $fd"); // MSB of source
|
|
|
|
__asm__("dec $ff"); // MSB of dest
|
|
|
|
__asm__("ldy #$00"); // Copy one block of 256 bytes
|
|
|
|
dl3:
|
|
|
|
__asm__("dey");
|
|
|
|
__asm__("lda ($fc),y");
|
|
|
|
__asm__("sta ($fe),y");
|
|
|
|
__asm__("cpy #$00");
|
|
|
|
__asm__("bne %g", dl3);
|
|
|
|
__asm__("inx");
|
|
|
|
__asm__("jmp %g", dl2);
|
2020-08-07 02:14:26 +00:00
|
|
|
ds2:
|
2020-08-06 03:45:23 +00:00
|
|
|
__asm__("sta $c002"); // Read main mem
|
|
|
|
__asm__("sta $c004"); // Write main mem
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-08-06 03:45:23 +00:00
|
|
|
} else {
|
2020-08-26 22:53:27 +00:00
|
|
|
// Start with lowest addr and copy upwards
|
2020-08-07 02:43:14 +00:00
|
|
|
*(uint16_t*)(0xfa) = n; // Stuff sz in ZP
|
2020-09-06 20:47:03 +00:00
|
|
|
*(uint16_t*)(0xfc) = (uint16_t)GAPBUFADDR + src; // Stuff src in ZP
|
|
|
|
*(uint16_t*)(0xfe) = (uint16_t)GAPBUFADDR + dst; // Stuff dst in ZP
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-08-06 03:45:23 +00:00
|
|
|
__asm__("sta $c005"); // Write aux mem
|
|
|
|
__asm__("sta $c003"); // Read aux mem
|
2020-08-26 22:53:27 +00:00
|
|
|
__asm__("ldx #$00");
|
2020-08-07 02:14:26 +00:00
|
|
|
al1:
|
2020-08-26 22:53:27 +00:00
|
|
|
__asm__("cpx $fb"); // MSB of n
|
|
|
|
__asm__("beq %g", as1); // No more complete 256 byte blocks
|
|
|
|
|
|
|
|
__asm__("ldy #$00"); // Copy one block of 256 bytes
|
|
|
|
al2:
|
|
|
|
__asm__("lda ($fc),y");
|
|
|
|
__asm__("sta ($fe),y");
|
|
|
|
__asm__("iny");
|
|
|
|
__asm__("bne %g", al2);
|
|
|
|
|
|
|
|
__asm__("inc $fd"); // MSB of source
|
|
|
|
__asm__("inc $ff"); // MSB of dest
|
|
|
|
__asm__("inx");
|
|
|
|
__asm__("jmp %g", al1);
|
2020-08-07 02:14:26 +00:00
|
|
|
as1:
|
2020-08-26 22:53:27 +00:00
|
|
|
__asm__("ldy #$00"); // Copy leftover bytes
|
|
|
|
al3:
|
|
|
|
__asm__("cpy $fa"); // LSB of n
|
|
|
|
__asm__("beq %g", as2); // Done!
|
|
|
|
__asm__("lda ($fc),y");
|
|
|
|
__asm__("sta ($fe),y");
|
|
|
|
__asm__("iny");
|
|
|
|
__asm__("jmp %g", al3);
|
2020-08-07 02:14:26 +00:00
|
|
|
as2:
|
2020-08-06 03:45:23 +00:00
|
|
|
__asm__("sta $c002"); // Read main mem
|
|
|
|
__asm__("sta $c004"); // Write main mem
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-08-06 03:45:23 +00:00
|
|
|
}
|
2020-08-06 02:30:55 +00:00
|
|
|
}
|
|
|
|
#pragma code-name (pop)
|
|
|
|
|
2020-08-08 23:29:33 +00:00
|
|
|
#pragma data-name (push, "LC")
|
2020-09-04 05:23:03 +00:00
|
|
|
char needle[80] = ""; // Must be in LC memory
|
2020-08-08 23:29:33 +00:00
|
|
|
#pragma data-name (pop)
|
|
|
|
|
2020-08-07 03:42:52 +00:00
|
|
|
/*
|
|
|
|
* Do a strstr() on aux memory. Uses index into gapbuf[].
|
|
|
|
* Must be in LC
|
|
|
|
* i - Index into gapbuf[]
|
2020-08-08 23:29:33 +00:00
|
|
|
* srch - String to search for
|
2020-08-07 03:42:52 +00:00
|
|
|
* loc - Location where string found (index into gapbuf[]) returned here
|
|
|
|
* Returns 1 if found, 0 otherwise
|
|
|
|
*/
|
|
|
|
#pragma code-name (push, "LC")
|
2020-08-08 23:29:33 +00:00
|
|
|
#pragma optimize (off)
|
|
|
|
uint8_t search_in_gapbuf(uint16_t i, char *srch, uint16_t *loc) {
|
|
|
|
|
|
|
|
__asm__("lda $c083"); // Read and write LC RAM bank 2
|
|
|
|
__asm__("lda $c083"); // Read and write LC RAM bank 2
|
|
|
|
memcpy(needle, srch, 80);
|
|
|
|
|
|
|
|
// ZP usage
|
|
|
|
// $f7: TMP1
|
|
|
|
// $f8-$f9: PTR4 in original strstr.s code.
|
|
|
|
// $fa-$fb: PTR1 in original strstr.s code.
|
|
|
|
// $fc-$fd: PTR2 in original strstr.s code.
|
|
|
|
// $fe-$ff: PTR3 in original strstr.s code.
|
|
|
|
*(uint16_t*)(0xfc) = (uint16_t)needle;
|
|
|
|
*(uint16_t*)(0xf8) = (uint16_t)needle; // Another copy of needle ptr
|
|
|
|
|
2020-09-06 20:47:03 +00:00
|
|
|
*(uint16_t*)(0xfa) = (uint16_t)GAPBUFADDR + i; // Haystack pointer
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-08-08 23:29:33 +00:00
|
|
|
__asm__("sta $c005"); // Write aux mem
|
|
|
|
__asm__("sta $c003"); // Read aux mem
|
|
|
|
|
|
|
|
__asm__("ldy #$00");
|
|
|
|
__asm__("lda ($fc),y"); // Get first byte of needle
|
|
|
|
__asm__("beq %g", found); // Needle is empty --> we're done
|
|
|
|
|
|
|
|
// Search for beginning of string
|
|
|
|
__asm__("sta $f7"); // Save start of needle
|
|
|
|
l1:
|
|
|
|
__asm__("lda ($fa),y"); // Get next char from haystack
|
|
|
|
__asm__("beq %g", notfound); // Jump if end
|
|
|
|
__asm__("cmp $f7"); // Start of needle found?
|
|
|
|
__asm__("beq %g", l2); // Jump if so
|
|
|
|
__asm__("iny"); // Next char
|
|
|
|
__asm__("bne %g", l1);
|
|
|
|
__asm__("inc $fb"); // Bump high byte of haystack
|
|
|
|
__asm__("bne %g", l1); // Branch always
|
|
|
|
|
|
|
|
// We found the start of needle in haystack
|
|
|
|
l2:
|
|
|
|
__asm__("tya"); // Get offset
|
|
|
|
__asm__("clc");
|
|
|
|
__asm__("adc $fa");
|
|
|
|
__asm__("sta $fa"); // Make ptr1 point to start
|
|
|
|
__asm__("bcc %g", l3);
|
|
|
|
__asm__("inc $fb");
|
|
|
|
|
|
|
|
// ptr1 points to the start of needle now. Setup temporary pointers for the
|
|
|
|
// search. The low byte of ptr4 is already set.
|
|
|
|
l3:
|
|
|
|
__asm__("sta $fe"); // LSB PTR3
|
|
|
|
__asm__("lda $fb"); // MSB PTR1
|
|
|
|
__asm__("sta $ff"); // MSB PTR3
|
|
|
|
__asm__("lda $fd"); // MSB PTR2
|
|
|
|
__asm__("sta $f9"); // MSB PTR4
|
|
|
|
__asm__("ldy #1"); // First char is identical, so start on second
|
|
|
|
|
|
|
|
// Do the compare
|
|
|
|
l4:
|
|
|
|
__asm__("lda ($f8),y"); // Get char from needle
|
|
|
|
__asm__("beq %g", found); // Jump if end of needle (-> found)
|
|
|
|
__asm__("cmp ($fe),y"); // Compare with haystack
|
|
|
|
__asm__("bne %g", l5); // Jump if not equal
|
|
|
|
__asm__("iny"); // Next char
|
|
|
|
__asm__("bne %g", l4);
|
|
|
|
__asm__("inc $ff");
|
|
|
|
__asm__("inc $f9"); // Bump hi byte of pointers
|
|
|
|
__asm__("bne %g", l4); // Next char (branch always)
|
|
|
|
|
|
|
|
// The strings did not compare equal, search next start of needle
|
|
|
|
l5:
|
|
|
|
__asm__("ldy #1"); // Start after this char
|
|
|
|
__asm__("bne %g", l1); // Branch always
|
|
|
|
|
|
|
|
// We found the needle
|
|
|
|
found:
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("sta $c002"); // Read main mem
|
|
|
|
__asm__("sta $c004"); // Write main mem
|
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-09-06 20:47:03 +00:00
|
|
|
*loc = *(uint16_t*)0xfa - GAPBUFADDR;
|
2020-08-08 23:29:33 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
// We reached end of haystack without finding needle
|
|
|
|
notfound:
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("sta $c002"); // Read main mem
|
|
|
|
__asm__("sta $c004"); // Write main mem
|
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-08-08 23:29:33 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
//#else
|
|
|
|
// char *p = strstr(gapbuf + i, needle);
|
|
|
|
// if (p) {
|
|
|
|
// *loc = p - gapbuf;
|
|
|
|
// return 1;
|
|
|
|
// } else
|
|
|
|
// return 0;
|
|
|
|
//#endif
|
2020-08-07 03:42:52 +00:00
|
|
|
}
|
2020-08-08 23:29:33 +00:00
|
|
|
#pragma optimize (on)
|
2020-08-07 03:42:52 +00:00
|
|
|
#pragma code-name (pop)
|
|
|
|
|
2020-08-01 04:25:08 +00:00
|
|
|
/*
|
|
|
|
* Annoying beep
|
|
|
|
*/
|
|
|
|
void beep(void) {
|
2020-08-04 02:22:18 +00:00
|
|
|
uint8_t *p = (uint8_t*)0xc030; // Speaker
|
2020-08-03 03:20:19 +00:00
|
|
|
uint8_t junk;
|
|
|
|
uint16_t i;
|
2020-08-05 04:58:30 +00:00
|
|
|
for (i = 0; i < 200; ++i) {
|
2020-08-03 03:20:19 +00:00
|
|
|
junk = *p;
|
2020-08-05 04:58:30 +00:00
|
|
|
for (junk = 0; junk < 50; ++junk); // Reduce pitch
|
2020-08-04 21:32:17 +00:00
|
|
|
}
|
2020-08-01 04:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear to EOL
|
|
|
|
*/
|
|
|
|
void clreol(void) {
|
|
|
|
uint8_t x = wherex(), y = wherey();
|
|
|
|
cclear(80 - x);
|
|
|
|
gotoxy(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear to EOL, wrap to next line
|
|
|
|
*/
|
|
|
|
void clreol_wrap(void) {
|
|
|
|
uint8_t x = wherex();
|
|
|
|
cclear(80 - x);
|
|
|
|
gotox(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear line
|
|
|
|
*/
|
|
|
|
void clrline(void) {
|
|
|
|
uint8_t x = wherex();
|
|
|
|
gotox(0);
|
|
|
|
cclear(80);
|
|
|
|
gotox(x);
|
|
|
|
}
|
|
|
|
|
2020-07-16 21:38:37 +00:00
|
|
|
/*
|
|
|
|
* Put cursor at beginning of PROMPT_ROW
|
|
|
|
*/
|
|
|
|
void goto_prompt_row(void) {
|
2020-08-01 04:25:08 +00:00
|
|
|
gotoxy(0, PROMPT_ROW);
|
2020-07-16 21:38:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-02 00:29:19 +00:00
|
|
|
/*
|
|
|
|
* Refresh the status line at the bottom of the screen
|
|
|
|
*/
|
|
|
|
void update_status_line(void) {
|
|
|
|
uint8_t nofile = 0;
|
2020-08-14 03:21:42 +00:00
|
|
|
uint8_t l;
|
2020-08-02 00:29:19 +00:00
|
|
|
|
|
|
|
static char selmsg1[] = ": Go to end of selection, then [Return]";
|
|
|
|
static char selmsg2[] = ": Go to target, then [Return] to ";
|
|
|
|
|
|
|
|
goto_prompt_row();
|
|
|
|
|
|
|
|
if (strlen(filename) == 0) {
|
|
|
|
strcpy(filename, "<scratch>");
|
|
|
|
nofile = 1;
|
|
|
|
}
|
|
|
|
revers(1);
|
|
|
|
switch (mode) {
|
|
|
|
case SEL_NONE:
|
2020-08-13 03:11:11 +00:00
|
|
|
if (status[2] == 0) {
|
|
|
|
cprintf("OA-? Help | [%03u] %c File:%s %2uKB free",
|
|
|
|
l_auxbank, status[0] ? '*' : ' ', filename,
|
|
|
|
(FREESPACE() + 512) / 1024);
|
|
|
|
l = 44 - strlen(filename);
|
|
|
|
} else {
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "%s Part:%u", filename, status[2]);
|
2020-08-13 03:11:11 +00:00
|
|
|
cprintf("OA-? Help | [%03u] %c File:%s %2uKB free",
|
|
|
|
l_auxbank, status[0] ? '*' : ' ', userentry,
|
|
|
|
(FREESPACE() + 512) / 1024);
|
|
|
|
l = 45 - strlen(userentry);
|
|
|
|
}
|
2020-08-02 00:29:19 +00:00
|
|
|
break;
|
2020-08-13 19:46:16 +00:00
|
|
|
case SEL_SELECT:
|
2020-08-11 00:05:18 +00:00
|
|
|
cprintf("Select: OA-[Space] to end");
|
|
|
|
l = 80 - 25;
|
|
|
|
break;
|
2020-08-02 00:29:19 +00:00
|
|
|
case SRCH1:
|
|
|
|
cprintf("Searching ...");
|
|
|
|
l = 80 - 13;
|
|
|
|
break;
|
|
|
|
case SRCH2:
|
|
|
|
cprintf("Searching - wrapped ...");
|
|
|
|
l = 80 - 23;
|
|
|
|
break;
|
|
|
|
case SRCH3:
|
2020-08-13 03:11:11 +00:00
|
|
|
if (status[2] == 0) {
|
|
|
|
cprintf("OA-? Help | [%03u] %c File:%s %2uKB free | Not Found",
|
|
|
|
l_auxbank, status[0] ? '*' : ' ', filename, (FREESPACE() + 512) / 1024);
|
|
|
|
l = 44 - 12 - strlen(filename);
|
|
|
|
} else {
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "%s Part:%u", filename, status[2]);
|
2020-08-13 03:11:11 +00:00
|
|
|
cprintf("OA-? Help | [%03u] %c File:%s %2uKB free | Not Found",
|
|
|
|
l_auxbank, status[0] ? '*' : ' ', userentry,
|
|
|
|
(FREESPACE() + 512) / 1024);
|
|
|
|
l = 45 - 12 - strlen(userentry);
|
|
|
|
}
|
2020-08-02 00:29:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-08-13 20:50:17 +00:00
|
|
|
cclear(l);
|
2020-08-02 00:29:19 +00:00
|
|
|
revers(0);
|
|
|
|
|
|
|
|
if (nofile)
|
|
|
|
strcpy(filename, "");
|
|
|
|
|
|
|
|
gotoxy(curscol, cursrow);
|
|
|
|
cursor(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set modified status
|
|
|
|
*/
|
|
|
|
void set_modified(uint8_t mod) {
|
2020-08-11 20:29:26 +00:00
|
|
|
if (status[0] == mod)
|
2020-08-02 00:29:19 +00:00
|
|
|
return;
|
2020-08-11 20:29:26 +00:00
|
|
|
status[0] = mod;
|
2020-08-02 00:29:19 +00:00
|
|
|
update_status_line();
|
|
|
|
}
|
|
|
|
|
2020-07-16 21:38:37 +00:00
|
|
|
/*
|
|
|
|
* Prompt for a name in the bottom line of the screen
|
|
|
|
* Returns number of chars read.
|
|
|
|
* prompt - Message to display before > prompt
|
|
|
|
* is_file - if 1, restrict chars to those allowed in ProDOS filename
|
2020-07-19 15:15:57 +00:00
|
|
|
* Returns number of chars read, or 255 if ESC pressed
|
2020-07-16 21:38:37 +00:00
|
|
|
*/
|
|
|
|
uint8_t prompt_for_name(char *prompt, uint8_t is_file) {
|
|
|
|
uint16_t i;
|
|
|
|
char c;
|
|
|
|
cursor(0);
|
|
|
|
goto_prompt_row();
|
2020-08-01 04:25:08 +00:00
|
|
|
clreol();
|
|
|
|
revers(1);
|
|
|
|
cprintf("%s>", prompt);
|
|
|
|
revers(0);
|
2020-07-19 21:53:49 +00:00
|
|
|
gotox(2 + strlen(prompt));
|
2020-07-16 21:38:37 +00:00
|
|
|
i = 0;
|
|
|
|
while (1) {
|
|
|
|
c = cgetc();
|
|
|
|
if (is_file && !isalnum(c) && (c != RETURN) && (c != BACKSPACE) &&
|
2020-07-19 15:15:57 +00:00
|
|
|
(c != DELETE) && (c != ESC) && (c != '.') && (c != '/')) {
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-07-16 21:38:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case RETURN:
|
|
|
|
goto done;
|
|
|
|
case BACKSPACE:
|
|
|
|
case DELETE:
|
|
|
|
if (i > 0) {
|
2020-07-19 21:53:49 +00:00
|
|
|
gotox(wherex() - 1);
|
|
|
|
cputc(' ');
|
|
|
|
gotox(wherex() - 1);
|
2020-07-16 21:38:37 +00:00
|
|
|
--i;
|
|
|
|
} else
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-07-16 21:38:37 +00:00
|
|
|
break;
|
2020-07-19 15:15:57 +00:00
|
|
|
case ESC:
|
|
|
|
userentry[0] = '\0';
|
|
|
|
i = 255;
|
|
|
|
goto esc_pressed;
|
2020-07-16 21:38:37 +00:00
|
|
|
default:
|
2020-07-19 21:53:49 +00:00
|
|
|
cputc(c);
|
2020-07-16 21:38:37 +00:00
|
|
|
userentry[i++] = c;
|
|
|
|
}
|
|
|
|
if (i == 79)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
userentry[i] = '\0';
|
2020-07-19 15:15:57 +00:00
|
|
|
esc_pressed:
|
2020-08-01 04:25:08 +00:00
|
|
|
clrline();
|
2020-07-16 21:38:37 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
|
|
|
cursor(1);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prompt ok?
|
2020-08-09 06:37:25 +00:00
|
|
|
* Returns 0 for yes
|
|
|
|
* 1 for no
|
|
|
|
* 2 for ESC
|
2020-07-16 21:38:37 +00:00
|
|
|
*/
|
|
|
|
char prompt_okay(char *msg) {
|
|
|
|
char c;
|
2020-07-16 23:16:59 +00:00
|
|
|
cursor(0);
|
2020-07-16 21:38:37 +00:00
|
|
|
goto_prompt_row();
|
2020-08-01 04:25:08 +00:00
|
|
|
clreol();
|
|
|
|
revers(1);
|
2020-08-09 06:37:25 +00:00
|
|
|
cprintf("%s (y/n/ESC)", msg);
|
2020-08-01 04:25:08 +00:00
|
|
|
revers(0);
|
2020-07-16 21:38:37 +00:00
|
|
|
while (1) {
|
|
|
|
c = cgetc();
|
2020-08-05 00:25:05 +00:00
|
|
|
if ((c == 'y') || (c == 'Y') || (c == 'n') || (c == 'N') || c == ESC)
|
2020-07-16 21:38:37 +00:00
|
|
|
break;
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-07-16 21:38:37 +00:00
|
|
|
}
|
|
|
|
if ((c == 'y') || (c == 'Y'))
|
|
|
|
c = 0;
|
2020-08-09 06:37:25 +00:00
|
|
|
else if (c == ESC)
|
|
|
|
c = 2;
|
|
|
|
else
|
|
|
|
c = 1;
|
2020-08-02 00:29:19 +00:00
|
|
|
update_status_line();
|
2020-07-16 21:38:37 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error message
|
|
|
|
*/
|
|
|
|
void show_error(char *msg) {
|
2020-07-16 23:16:59 +00:00
|
|
|
cursor(0);
|
2020-07-16 21:38:37 +00:00
|
|
|
goto_prompt_row();
|
2020-08-02 03:18:13 +00:00
|
|
|
clreol();
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
|
|
|
revers(1);
|
2020-08-02 00:29:19 +00:00
|
|
|
cprintf("%s [Press Any Key]", msg);
|
2020-08-01 04:25:08 +00:00
|
|
|
revers(0);
|
2020-07-16 21:38:37 +00:00
|
|
|
cgetc();
|
2020-08-02 00:29:19 +00:00
|
|
|
update_status_line();
|
2020-07-18 02:33:25 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
/*
|
|
|
|
* Insert a character into gapbuf at current position
|
|
|
|
* c - character to insert
|
|
|
|
*/
|
2020-08-03 02:28:01 +00:00
|
|
|
void insert_char(char c) {
|
2020-07-12 21:34:11 +00:00
|
|
|
if (FREESPACE()) {
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapbegin++, c);
|
2020-08-03 02:28:01 +00:00
|
|
|
return;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
2020-08-03 02:28:01 +00:00
|
|
|
beep();
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete the character to the left of the current position
|
|
|
|
*/
|
2020-08-03 02:28:01 +00:00
|
|
|
void delete_char(void) {
|
|
|
|
if (gapbegin == 0) {
|
|
|
|
beep();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
--gapbegin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete the character to the right of the current position
|
|
|
|
*/
|
2020-08-03 02:28:01 +00:00
|
|
|
void delete_char_right(void) {
|
|
|
|
if (gapend == BUFSZ - 1) {
|
|
|
|
beep();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
++gapend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the current position
|
|
|
|
* pos - position to which to move
|
|
|
|
*/
|
2020-08-03 02:28:01 +00:00
|
|
|
void jump_pos(uint16_t pos) {
|
2020-08-04 18:51:11 +00:00
|
|
|
uint16_t l;
|
2020-08-03 02:28:01 +00:00
|
|
|
if (pos > BUFSZ - 1) {
|
|
|
|
beep();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
if (pos == GETPOS())
|
2020-08-03 02:28:01 +00:00
|
|
|
return;
|
2020-08-04 18:51:11 +00:00
|
|
|
if (pos > GETPOS()) {
|
|
|
|
l = pos - gapbegin;
|
2020-08-06 02:30:55 +00:00
|
|
|
move_in_gapbuf(gapbegin, gapend + 1, l);
|
2020-08-04 18:51:11 +00:00
|
|
|
gapbegin += l;
|
|
|
|
gapend += l;
|
|
|
|
} else {
|
|
|
|
l = gapbegin - pos;
|
2020-08-06 02:30:55 +00:00
|
|
|
move_in_gapbuf(gapend - l + 1, gapbegin - l, l);
|
2020-08-04 18:51:11 +00:00
|
|
|
gapbegin -= l;
|
|
|
|
gapend -= l;
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT)
|
2020-08-05 02:27:54 +00:00
|
|
|
endsel = gapbegin;
|
2020-08-03 02:28:01 +00:00
|
|
|
return;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 03:12:01 +00:00
|
|
|
/*
|
|
|
|
* Go to next tabstop
|
|
|
|
*/
|
|
|
|
uint8_t next_tabstop(uint8_t col) {
|
|
|
|
return (col / 8) * 8 + 8;
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:29:26 +00:00
|
|
|
#define FROMAUX 0
|
|
|
|
#define TOAUX 1
|
|
|
|
/*
|
|
|
|
* Copy to/from aux memory using AUXMOVE
|
|
|
|
*/
|
|
|
|
void copyaux(char *src, char *dst, uint16_t len, uint8_t dir) {
|
|
|
|
char **a1 = (char**)0x3c;
|
|
|
|
char **a2 = (char**)0x3e;
|
|
|
|
char **a4 = (char**)0x42;
|
|
|
|
*a1 = src;
|
|
|
|
*a2 = src + len - 1; // AUXMOVE moves length+1 bytes!!
|
|
|
|
*a4 = dst;
|
|
|
|
if (dir == TOAUX) {
|
|
|
|
__asm__("sec"); // Copy main->aux
|
|
|
|
__asm__("jsr $c311"); // AUXMOVE
|
|
|
|
} else {
|
|
|
|
__asm__("clc"); // Copy aux->main
|
|
|
|
__asm__("jsr $c311"); // AUXMOVE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate logic aux bank number to physical.
|
|
|
|
* This is necessary because there may be 'holes' in the banks
|
|
|
|
* Logical banks are numbered 1..maxbank contiguously.
|
|
|
|
* Physical banks start at 0 and may be non-contiguous.
|
|
|
|
*/
|
|
|
|
uint8_t bank_log_to_phys(uint8_t l) {
|
2020-08-16 20:33:23 +00:00
|
|
|
return banktbl[l];
|
2020-08-11 20:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the active bank of aux memory
|
|
|
|
* Current physical bank is in auxbank
|
|
|
|
* logbank - desired logical bank
|
|
|
|
*/
|
|
|
|
#pragma code-name (push, "LC")
|
|
|
|
void change_aux_bank(uint8_t logbank) {
|
2020-08-14 04:10:38 +00:00
|
|
|
if (logbank > banktbl[0]) {
|
|
|
|
show_error("Nonexistent bank");
|
|
|
|
return;
|
|
|
|
}
|
2020-08-11 20:29:26 +00:00
|
|
|
l_auxbank = logbank;
|
2020-08-12 03:04:46 +00:00
|
|
|
// Saves filename[], status, gapbegin, gapend (BUFINFOSZ bytes)
|
2020-08-11 20:29:26 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-09-06 20:47:03 +00:00
|
|
|
copyaux(filename, (void*)INFOADDR, BUFINFOSZ, TOAUX);
|
2020-08-12 03:04:46 +00:00
|
|
|
// Load new filename[], status, gapbegin, gapend (BUFINFOSZ bytes)
|
2020-08-11 20:29:26 +00:00
|
|
|
auxbank = bank_log_to_phys(l_auxbank);
|
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-09-06 20:47:03 +00:00
|
|
|
copyaux((void*)INFOADDR, filename, BUFINFOSZ, FROMAUX);
|
2020-08-11 20:29:26 +00:00
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
|
|
|
}
|
|
|
|
#pragma code-name (pop)
|
|
|
|
|
2020-08-12 03:04:46 +00:00
|
|
|
/*
|
|
|
|
* Used by load_file() when opening a new bank for a large file
|
2020-08-13 00:59:36 +00:00
|
|
|
* and also by CA-E "Extend file"
|
2020-08-12 22:32:46 +00:00
|
|
|
* Returns 0 if all is well, 1 if we run into an already occupied bank
|
2020-08-12 03:04:46 +00:00
|
|
|
*/
|
2020-08-13 00:59:36 +00:00
|
|
|
uint8_t open_new_aux_bank(uint8_t partnum) {
|
2020-08-12 03:04:46 +00:00
|
|
|
strcpy(userentry, filename);
|
|
|
|
status[2] = partnum;
|
2020-08-14 05:03:45 +00:00
|
|
|
if (l_auxbank >= banktbl[0])
|
|
|
|
return 1;
|
2020-08-12 22:32:46 +00:00
|
|
|
change_aux_bank(++l_auxbank);
|
|
|
|
if (DATASIZE() > 0) {
|
2020-08-14 05:03:45 +00:00
|
|
|
change_aux_bank(--l_auxbank);
|
2020-08-12 22:32:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-08-12 03:04:46 +00:00
|
|
|
strcpy(filename, userentry);
|
2020-08-12 22:32:46 +00:00
|
|
|
return 0;
|
2020-08-12 03:04:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 20:50:17 +00:00
|
|
|
/*
|
|
|
|
* Spinner while loading / saving
|
2020-08-17 14:45:52 +00:00
|
|
|
* saving - 1 if we are saving, 0 if we are loading
|
|
|
|
* copymode - 1 if this is cut/paste, 0 otherwise
|
2020-08-13 20:50:17 +00:00
|
|
|
*/
|
2020-08-17 14:45:52 +00:00
|
|
|
void spinner(uint32_t sz, uint8_t saving, uint8_t copymode) {
|
2020-08-13 20:50:17 +00:00
|
|
|
static char chars[] = "|/-\\";
|
2020-08-16 20:33:23 +00:00
|
|
|
static char buf[80] = "";
|
2020-08-13 20:50:17 +00:00
|
|
|
static uint8_t i = 0;
|
|
|
|
gotoxy(0, PROMPT_ROW);
|
2020-08-17 14:45:52 +00:00
|
|
|
if (copymode)
|
|
|
|
snprintf(buf, 80, "%s clipboard: %c [%lu]",
|
|
|
|
(saving ? "Copying to" : "Pasting from"), chars[(i++) % 4], sz);
|
|
|
|
else
|
|
|
|
snprintf(buf, 80, "%s '%s': %c [%lu]",
|
|
|
|
(saving ? "Saving" : "Opening"), filename, chars[(i++) % 4], sz);
|
2020-08-13 20:50:17 +00:00
|
|
|
revers(1);
|
|
|
|
cprintf("%s", buf);
|
|
|
|
cclear(79 - strlen(buf));
|
|
|
|
revers(0);
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:16:47 +00:00
|
|
|
// Forward declaration
|
|
|
|
void draw_screen(void);
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
/*
|
|
|
|
* Load a file from disk into the gapbuf
|
|
|
|
* filename - name of file to load
|
2020-07-25 01:30:16 +00:00
|
|
|
* replace - if 1, replace old file.
|
2020-08-17 14:45:52 +00:00
|
|
|
* copymode - if 1, then load from CLIPBOARD
|
2020-07-12 21:34:11 +00:00
|
|
|
* Returns 0 on success
|
|
|
|
* 1 if file can't be opened
|
|
|
|
*/
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (push, "LC")
|
2020-08-17 14:45:52 +00:00
|
|
|
uint8_t load_file(char *fname, uint8_t replace, uint8_t copymode) {
|
2020-08-11 20:29:26 +00:00
|
|
|
uint8_t partctr = 0;
|
2020-08-04 02:22:18 +00:00
|
|
|
uint8_t col;
|
|
|
|
char *p;
|
|
|
|
uint16_t i, j, s;
|
|
|
|
uint8_t c, cont;
|
2020-08-11 20:29:26 +00:00
|
|
|
FILE *fp = fopen(fname, "r");
|
2020-07-12 21:34:11 +00:00
|
|
|
if (!fp)
|
|
|
|
return 1;
|
2020-08-04 02:22:18 +00:00
|
|
|
if (!replace)
|
|
|
|
col = curscol;
|
2020-07-19 21:53:49 +00:00
|
|
|
goto_prompt_row();
|
2020-07-25 01:30:16 +00:00
|
|
|
if (replace) {
|
|
|
|
gapbegin = 0;
|
|
|
|
gapend = BUFSZ - 1;
|
|
|
|
col = 0;
|
|
|
|
}
|
2020-08-13 20:08:51 +00:00
|
|
|
cutbuflen = 0;
|
2020-08-06 02:30:55 +00:00
|
|
|
p = iobuf;
|
2020-08-04 02:22:18 +00:00
|
|
|
do {
|
2020-08-17 14:45:52 +00:00
|
|
|
spinner(DATASIZE(), 0, copymode);
|
2020-08-07 02:43:14 +00:00
|
|
|
s = fread(p, 1, IOSZ, fp);
|
|
|
|
cont = (s == IOSZ ? 1 : 0);
|
2020-08-05 03:40:12 +00:00
|
|
|
for (i = 0; i < s; ++i) {
|
|
|
|
switch (p[i]) {
|
2020-08-04 02:22:18 +00:00
|
|
|
case '\r': // Native Apple2 files
|
|
|
|
case '\n': // UNIX files
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapbegin++, '\r');
|
2020-08-04 02:22:18 +00:00
|
|
|
col = 0;
|
2020-08-14 05:03:45 +00:00
|
|
|
if (replace && (FREESPACE() < 15000) && (banktbl[0] > 1)) {
|
2020-08-12 23:16:47 +00:00
|
|
|
draw_screen();
|
2020-08-13 00:59:36 +00:00
|
|
|
if (open_new_aux_bank(++partctr) == 1) {
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80,
|
2020-08-14 05:03:45 +00:00
|
|
|
"Buffer [%03u] not avail. Truncating file.", l_auxbank + 1);
|
2020-08-12 22:32:46 +00:00
|
|
|
show_error(userentry);
|
2020-08-14 05:03:45 +00:00
|
|
|
if (partctr == 1) // If truncated to one part ...
|
|
|
|
status[2] = 0; // Make it a singleton
|
|
|
|
partctr = 0; // Prevent status[2] increment below
|
2020-08-12 22:32:46 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2020-08-12 23:16:47 +00:00
|
|
|
}
|
2020-08-04 02:22:18 +00:00
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
c = next_tabstop(col) - col;
|
|
|
|
for (j = 0; j < c; ++j)
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapbegin++, ' ');
|
2020-08-04 02:22:18 +00:00
|
|
|
col += c;
|
|
|
|
break;
|
|
|
|
default:
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapbegin++, p[i]);
|
2020-08-04 02:22:18 +00:00
|
|
|
++col;
|
2020-08-05 03:40:12 +00:00
|
|
|
}
|
2020-08-12 03:04:46 +00:00
|
|
|
if (FREESPACE() < IOSZ * 2) {
|
|
|
|
show_error("File truncated");
|
|
|
|
goto done;
|
2020-08-11 20:29:26 +00:00
|
|
|
}
|
2020-08-04 02:22:18 +00:00
|
|
|
}
|
|
|
|
} while (cont);
|
|
|
|
done:
|
2020-07-12 21:34:11 +00:00
|
|
|
fclose(fp);
|
2020-07-25 01:30:16 +00:00
|
|
|
if (replace) {
|
2020-08-12 03:04:46 +00:00
|
|
|
if (partctr > 0)
|
|
|
|
status[2] = ++partctr;
|
2020-07-25 01:30:16 +00:00
|
|
|
jump_pos(0);
|
|
|
|
pos = 0;
|
2020-08-02 00:29:19 +00:00
|
|
|
set_modified(0);
|
2020-08-11 20:29:26 +00:00
|
|
|
status[1] = 0; // No need to prompt for overwrite on save
|
2020-07-25 01:30:16 +00:00
|
|
|
startsel = endsel = 65535U;
|
|
|
|
mode = SEL_NONE;
|
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (pop)
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save gapbuf to file
|
2020-08-12 22:32:46 +00:00
|
|
|
* If copymode is 0, use filename[] otherwise "CLIPBOARD"
|
2020-08-10 04:41:54 +00:00
|
|
|
* copymode - if 1, copy test from startsel to endsel only
|
2020-08-12 03:04:46 +00:00
|
|
|
* append - if 1, append to file instead of overwriting
|
2020-07-12 21:34:11 +00:00
|
|
|
* Returns 0 on success
|
|
|
|
* 1 if file can't be opened
|
|
|
|
*/
|
2020-08-12 22:32:46 +00:00
|
|
|
uint8_t save_file(uint8_t copymode, uint8_t append) {
|
2020-08-04 02:22:18 +00:00
|
|
|
uint16_t pos = gapbegin;
|
2020-08-10 04:41:54 +00:00
|
|
|
uint16_t sz;
|
2020-08-04 02:22:18 +00:00
|
|
|
uint8_t retval = 1;
|
|
|
|
uint8_t i;
|
2020-08-09 03:08:54 +00:00
|
|
|
uint16_t p, j;
|
2020-08-03 02:28:01 +00:00
|
|
|
FILE *fp;
|
|
|
|
_filetype = PRODOS_T_TXT;
|
|
|
|
_auxtype = 0;
|
2020-08-12 22:32:46 +00:00
|
|
|
fp = fopen((copymode ? "CLIPBOARD" : filename), (append ? "a" : "w"));
|
2020-07-12 21:34:11 +00:00
|
|
|
if (!fp)
|
2020-08-04 02:22:18 +00:00
|
|
|
goto done;
|
2020-08-10 04:41:54 +00:00
|
|
|
jump_pos(copymode == 1 ? startsel : 0);
|
2020-07-19 21:53:49 +00:00
|
|
|
goto_prompt_row();
|
2020-08-13 20:08:51 +00:00
|
|
|
cutbuflen = 0;
|
2020-08-07 02:43:14 +00:00
|
|
|
p = gapend + 1;
|
2020-08-10 04:41:54 +00:00
|
|
|
if (copymode)
|
|
|
|
sz = endsel - startsel;
|
|
|
|
else
|
|
|
|
sz = DATASIZE();
|
|
|
|
for (i = 0; i < sz / IOSZ; ++i) {
|
2020-08-17 14:45:52 +00:00
|
|
|
spinner(i * IOSZ, 1, copymode);
|
2020-08-07 02:43:14 +00:00
|
|
|
for (j = 0; j < IOSZ; ++j)
|
|
|
|
iobuf[j] = get_gapbuf(p++);
|
|
|
|
if (fwrite(iobuf, IOSZ, 1, fp) != 1)
|
2020-08-04 02:22:18 +00:00
|
|
|
goto done;
|
2020-07-19 21:53:49 +00:00
|
|
|
}
|
2020-08-17 14:45:52 +00:00
|
|
|
spinner(i * IOSZ, 1, copymode);
|
2020-08-10 04:41:54 +00:00
|
|
|
for (j = 0; j < sz - (IOSZ * i); ++j)
|
2020-08-07 02:43:14 +00:00
|
|
|
iobuf[j] = get_gapbuf(p++);
|
2020-08-10 04:41:54 +00:00
|
|
|
if (fwrite(iobuf, sz - (IOSZ * i), 1, fp) != 1)
|
2020-08-07 02:43:14 +00:00
|
|
|
goto done;
|
2020-08-04 02:22:18 +00:00
|
|
|
retval = 0;
|
2020-08-12 23:16:47 +00:00
|
|
|
status[0] = 0; // No longer marked modified
|
2020-08-04 02:22:18 +00:00
|
|
|
done:
|
2020-07-12 21:34:11 +00:00
|
|
|
fclose(fp);
|
2020-08-04 02:22:18 +00:00
|
|
|
jump_pos(pos);
|
2020-08-10 04:41:54 +00:00
|
|
|
return retval;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 03:04:46 +00:00
|
|
|
/*
|
|
|
|
* Obtain the first bank number for the current file
|
|
|
|
*/
|
|
|
|
uint8_t find_first_bank(void) {
|
|
|
|
if (status[2] == 0) // Not a multi-bank file
|
|
|
|
return l_auxbank;
|
|
|
|
if (status[2] == 1) // First bank of multi-bank file
|
|
|
|
return l_auxbank;
|
|
|
|
return l_auxbank - status[2] + 1; // Assumes banks allocated in order
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save a large file that spans multiple banks
|
|
|
|
*/
|
2020-08-12 22:32:46 +00:00
|
|
|
uint8_t save_multibank_file(void) {
|
2020-08-12 03:04:46 +00:00
|
|
|
uint8_t bank = find_first_bank();
|
2020-08-12 23:16:47 +00:00
|
|
|
uint8_t origbank = l_auxbank;
|
2020-08-13 01:46:50 +00:00
|
|
|
uint8_t retval = 0, modified = 0, first = 1;
|
|
|
|
uint8_t filebank;
|
2020-08-12 23:16:47 +00:00
|
|
|
if (bank != origbank) {
|
2020-08-12 03:04:46 +00:00
|
|
|
change_aux_bank(bank);
|
|
|
|
draw_screen();
|
|
|
|
}
|
2020-08-13 00:59:36 +00:00
|
|
|
if (status[2] == 0) // Oh, it's actually just a single bank file
|
2020-08-12 22:32:46 +00:00
|
|
|
return save_file(0, 0);
|
2020-08-13 00:59:36 +00:00
|
|
|
if (status[2] != 1) {
|
2020-08-12 03:04:46 +00:00
|
|
|
show_error("SBF error"); // Should never happen
|
2020-08-12 23:16:47 +00:00
|
|
|
retval = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
// Look at all banks and see if any are modified
|
2020-08-13 00:59:36 +00:00
|
|
|
do {
|
2020-08-12 23:16:47 +00:00
|
|
|
filebank = status[2];
|
|
|
|
if (status[1] == 1) {
|
|
|
|
modified = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
change_aux_bank(++l_auxbank);
|
2020-08-13 00:59:36 +00:00
|
|
|
} while (status[2] == filebank + 1);
|
2020-08-12 23:16:47 +00:00
|
|
|
change_aux_bank(bank);
|
2020-08-13 00:59:36 +00:00
|
|
|
do {
|
2020-08-12 23:16:47 +00:00
|
|
|
filebank = status[2];
|
2020-08-13 00:59:36 +00:00
|
|
|
draw_screen();
|
2020-08-13 01:46:50 +00:00
|
|
|
if (save_file(0, (first == 1 ? 0 : 1)) == 1) {
|
2020-08-12 23:16:47 +00:00
|
|
|
retval = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
2020-08-13 01:46:50 +00:00
|
|
|
first = 0;
|
|
|
|
change_aux_bank(++l_auxbank);
|
2020-08-13 00:59:36 +00:00
|
|
|
} while (status[2] == filebank + 1);
|
2020-08-12 23:16:47 +00:00
|
|
|
done:
|
|
|
|
if (origbank != l_auxbank) {
|
2020-08-13 00:59:36 +00:00
|
|
|
change_aux_bank(origbank);
|
|
|
|
draw_screen();
|
2020-08-12 23:16:47 +00:00
|
|
|
}
|
|
|
|
return retval;
|
2020-08-12 03:04:46 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
/*
|
|
|
|
* Read next char from gapbuf[] and update state.
|
|
|
|
* Returns 1 on EOL, 0 otherwise
|
|
|
|
* If do_print is set, print char on the screen.
|
|
|
|
* Interface is via the following globals:
|
|
|
|
* do_print - if 1, update screen
|
|
|
|
* pos - position in buffer, advanced by one
|
|
|
|
* row, col - position on screen
|
|
|
|
* rowlen[] - length of each screen row in chars
|
|
|
|
*/
|
|
|
|
uint8_t read_char_update_pos(void) {
|
2020-08-04 23:14:52 +00:00
|
|
|
uint16_t delta = gapend - gapbegin;
|
2020-08-17 16:44:13 +00:00
|
|
|
uint16_t s = startsel, e = endsel;
|
2020-07-12 21:34:11 +00:00
|
|
|
char c;
|
2020-08-17 16:44:13 +00:00
|
|
|
if (startsel > endsel) {
|
|
|
|
s = endsel;
|
|
|
|
e = startsel;
|
|
|
|
}
|
2020-08-06 02:30:55 +00:00
|
|
|
if ((c = get_gapbuf(pos++)) == EOL) {
|
2020-07-12 21:34:11 +00:00
|
|
|
if (do_print) {
|
|
|
|
rowlen[row] = col + 1;
|
2020-08-01 04:25:08 +00:00
|
|
|
clreol_wrap();
|
|
|
|
gotox(0);
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
++row;
|
|
|
|
col = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-08-17 16:44:13 +00:00
|
|
|
if (((pos > s) && (pos <= e)) || // Left of cursor
|
|
|
|
((pos - delta > s) && (pos - delta - 1 <= e))) // Right of cursor
|
2020-08-02 00:35:34 +00:00
|
|
|
revers(1);
|
|
|
|
else
|
|
|
|
revers(0);
|
2020-08-01 05:53:56 +00:00
|
|
|
if (do_print)
|
2020-07-19 21:53:49 +00:00
|
|
|
cputc(c);
|
2020-08-01 05:53:56 +00:00
|
|
|
revers(0);
|
2020-07-12 23:05:25 +00:00
|
|
|
++col;
|
2020-07-16 04:00:34 +00:00
|
|
|
if (do_print)
|
|
|
|
rowlen[row] = col;
|
2020-07-13 03:12:01 +00:00
|
|
|
if (col == NCOLS) {
|
2020-07-12 21:34:11 +00:00
|
|
|
++row;
|
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Draw screenful of text
|
|
|
|
*/
|
|
|
|
void draw_screen(void) {
|
|
|
|
uint16_t startpos;
|
|
|
|
uint8_t rowsabove, cursorrow;
|
|
|
|
|
2020-07-16 04:33:48 +00:00
|
|
|
// Initialize all rows to length 0 to cover those rows that may have
|
2020-07-13 04:05:15 +00:00
|
|
|
// no text and would otherwise be unitialized.
|
|
|
|
for (rowsabove = 0; rowsabove < NROWS; ++rowsabove)
|
2020-07-16 04:33:48 +00:00
|
|
|
rowlen[rowsabove] = 0;
|
2020-07-13 04:05:15 +00:00
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
// First we have to scan back to work out where in the buffer to
|
|
|
|
// start drawing on the screen at the top left. This is at most
|
2020-08-27 01:29:01 +00:00
|
|
|
// CURSORROW * NCOLS chars.
|
2020-07-12 21:34:11 +00:00
|
|
|
startpos = gapbegin;
|
2020-08-27 01:29:01 +00:00
|
|
|
if (startpos > (CURSORROW + 2) * NCOLS)
|
|
|
|
startpos -= (CURSORROW + 2) * NCOLS;
|
2020-07-12 21:34:11 +00:00
|
|
|
else
|
|
|
|
startpos = 0;
|
|
|
|
|
|
|
|
// Format the text and work out the number of rows it takes up
|
|
|
|
pos = startpos;
|
|
|
|
row = col = 0;
|
|
|
|
do_print = 0;
|
|
|
|
while (pos < gapbegin)
|
|
|
|
read_char_update_pos();
|
|
|
|
rowsabove = row; // Number of complete rows above cursor
|
|
|
|
|
|
|
|
if (rowsabove <= CURSORROW) {
|
|
|
|
pos = 0;
|
|
|
|
cursorrow = rowsabove;
|
|
|
|
} else {
|
|
|
|
cursorrow = CURSORROW;
|
|
|
|
|
|
|
|
// Now repeat the formatting of the text, eating the first
|
|
|
|
// (rowsabove - cursorrow) lines
|
|
|
|
pos = startpos;
|
|
|
|
row = col = 0;
|
|
|
|
while (row < (rowsabove - cursorrow))
|
|
|
|
read_char_update_pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally actually write the text to the screen!
|
|
|
|
videomode(VIDEOMODE_80COL);
|
|
|
|
clrscr();
|
2020-08-01 04:25:08 +00:00
|
|
|
revers(0);
|
2020-07-12 21:34:11 +00:00
|
|
|
row = col = 0;
|
|
|
|
do_print = 1;
|
|
|
|
while (pos < gapbegin)
|
|
|
|
read_char_update_pos();
|
|
|
|
|
|
|
|
curscol = col;
|
|
|
|
cursrow = row;
|
|
|
|
|
|
|
|
// Now write the text after the cursor up to the end of the screen
|
|
|
|
pos = gapend + 1;
|
|
|
|
while ((pos < BUFSZ) && (row < NROWS))
|
|
|
|
read_char_update_pos();
|
|
|
|
|
2020-08-02 00:29:19 +00:00
|
|
|
update_status_line();
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scroll screen up and update rowlen[]
|
|
|
|
*/
|
|
|
|
void scroll_up() {
|
|
|
|
draw_screen();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scroll screen down and update rowlen[]
|
|
|
|
*/
|
|
|
|
void scroll_down() {
|
|
|
|
draw_screen();
|
|
|
|
}
|
|
|
|
|
2020-07-31 04:16:12 +00:00
|
|
|
/*
|
|
|
|
* Returns 1 if current position in gap buffer is on the last line of
|
|
|
|
* the file (ie: no following CR), 0 otherwise
|
|
|
|
*/
|
|
|
|
uint8_t is_last_line(void) {
|
|
|
|
uint16_t p = gapend + 1;
|
|
|
|
while (p < BUFSZ) {
|
2020-08-06 02:30:55 +00:00
|
|
|
if (get_gapbuf(p++) == '\r')
|
2020-07-31 04:16:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
/*
|
|
|
|
* Update screen after delete_char_right()
|
|
|
|
*/
|
|
|
|
void update_after_delete_char_right(void) {
|
|
|
|
uint8_t eol = 0;
|
2020-07-16 21:38:37 +00:00
|
|
|
uint8_t i;
|
2020-07-12 21:34:11 +00:00
|
|
|
col = curscol;
|
|
|
|
row = cursrow;
|
|
|
|
do_print = 1;
|
|
|
|
|
|
|
|
// Print rest of line up to EOL
|
|
|
|
pos = gapend + 1;
|
2020-08-24 01:38:18 +00:00
|
|
|
if (pos == BUFSZ)
|
|
|
|
--rowlen[row];
|
|
|
|
else
|
|
|
|
while (!eol && (pos < BUFSZ) && (row < NROWS)) {
|
|
|
|
i = col;
|
|
|
|
eol = read_char_update_pos();
|
|
|
|
}
|
|
|
|
|
2020-07-31 04:16:12 +00:00
|
|
|
if (is_last_line())
|
2020-08-01 04:25:08 +00:00
|
|
|
clreol_wrap();
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
// If necessary, print rest of screen
|
2020-08-06 02:30:55 +00:00
|
|
|
if ((get_gapbuf(gapend) == EOL) || (i == NCOLS - 1)) {
|
2020-07-12 21:34:11 +00:00
|
|
|
while ((pos < BUFSZ) && (row < NROWS))
|
|
|
|
read_char_update_pos();
|
|
|
|
|
2020-08-01 04:25:08 +00:00
|
|
|
clreol_wrap();
|
2020-07-17 21:30:16 +00:00
|
|
|
|
2020-07-16 23:16:59 +00:00
|
|
|
// Erase the rest of the screen (if any)
|
2020-07-17 21:30:16 +00:00
|
|
|
for (i = row + 1; i < NROWS; ++i) {
|
2020-07-16 23:16:59 +00:00
|
|
|
gotoxy(0, i);
|
2020-08-01 04:25:08 +00:00
|
|
|
clrline();
|
2020-07-16 23:16:59 +00:00
|
|
|
}
|
2020-07-16 21:38:37 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
|
|
|
cursor(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update screen after delete_char()
|
|
|
|
*/
|
|
|
|
void update_after_delete_char(void) {
|
|
|
|
uint8_t eol = 0;
|
2020-07-16 21:38:37 +00:00
|
|
|
uint8_t i;
|
2020-07-12 21:34:11 +00:00
|
|
|
col = curscol;
|
|
|
|
row = cursrow;
|
|
|
|
|
2020-08-06 02:30:55 +00:00
|
|
|
if (get_gapbuf(gapbegin) == EOL) {
|
2020-07-12 21:34:11 +00:00
|
|
|
// Special handling if we deleted an EOL
|
|
|
|
if (row > 0)
|
|
|
|
col = rowlen[--row] - 1;
|
|
|
|
else {
|
|
|
|
scroll_up();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Erase char to left of cursor & update row, col
|
2020-07-19 21:53:49 +00:00
|
|
|
gotox(wherex() - 1);
|
|
|
|
cputc(' ');
|
|
|
|
gotox(wherex() - 1);
|
2020-07-12 21:34:11 +00:00
|
|
|
if (col > 0)
|
|
|
|
--col;
|
|
|
|
else {
|
2020-08-02 21:28:42 +00:00
|
|
|
col = NCOLS - 1;
|
2020-07-12 21:34:11 +00:00
|
|
|
if (row > 0)
|
|
|
|
--row;
|
|
|
|
else {
|
|
|
|
scroll_up();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
curscol = col;
|
|
|
|
cursrow = row;
|
|
|
|
gotoxy(curscol, cursrow);
|
|
|
|
|
|
|
|
do_print = 1;
|
|
|
|
|
|
|
|
// Print rest of line up to EOL
|
|
|
|
pos = gapend + 1;
|
2020-08-24 01:38:18 +00:00
|
|
|
if (pos == BUFSZ)
|
|
|
|
--rowlen[row];
|
|
|
|
else
|
|
|
|
while (!eol && (pos < BUFSZ) && (row < NROWS)) {
|
|
|
|
i = col;
|
|
|
|
eol = read_char_update_pos();
|
|
|
|
}
|
|
|
|
|
2020-07-31 04:16:12 +00:00
|
|
|
if (is_last_line())
|
2020-08-01 04:25:08 +00:00
|
|
|
clreol_wrap();
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
// If necessary, print rest of screen
|
2020-08-06 02:30:55 +00:00
|
|
|
if ((get_gapbuf(gapbegin) == EOL) || (i == NCOLS - 1)) {
|
2020-07-12 21:34:11 +00:00
|
|
|
while ((pos < BUFSZ) && (row < NROWS))
|
|
|
|
read_char_update_pos();
|
|
|
|
|
2020-08-01 04:25:08 +00:00
|
|
|
clreol_wrap();
|
2020-07-17 21:30:16 +00:00
|
|
|
|
2020-07-16 23:16:59 +00:00
|
|
|
// Erase the rest of the screen (if any)
|
2020-07-17 21:30:16 +00:00
|
|
|
for (i = row + 1; i < NROWS; ++i) {
|
2020-07-16 23:16:59 +00:00
|
|
|
gotoxy(0, i);
|
2020-08-01 04:25:08 +00:00
|
|
|
clrline();
|
2020-07-16 23:16:59 +00:00
|
|
|
}
|
2020-07-16 21:38:37 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
|
|
|
cursor(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update screen after insert_char()
|
|
|
|
*/
|
|
|
|
void update_after_insert_char(void) {
|
|
|
|
uint8_t eol = 0;
|
|
|
|
uint8_t prevcol;
|
|
|
|
col = curscol;
|
|
|
|
row = cursrow;
|
|
|
|
|
|
|
|
// Print character just inserted
|
|
|
|
pos = gapbegin - 1;
|
|
|
|
do_print = 1;
|
|
|
|
read_char_update_pos();
|
|
|
|
|
|
|
|
curscol = col;
|
|
|
|
cursrow = row;
|
2020-07-19 21:53:49 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
if (cursrow == NROWS) {
|
|
|
|
scroll_down();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print rest of line up to EOL
|
|
|
|
pos = gapend + 1;
|
|
|
|
while (!eol && (pos < BUFSZ) && (row < NROWS)) {
|
|
|
|
prevcol = col;
|
|
|
|
eol = read_char_update_pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If necessary, print rest of screen
|
2020-08-06 02:30:55 +00:00
|
|
|
if ((get_gapbuf(gapbegin - 1) == EOL) || (prevcol == 0))
|
2020-07-12 21:34:11 +00:00
|
|
|
while ((pos < BUFSZ) && (row < NROWS))
|
|
|
|
read_char_update_pos();
|
|
|
|
|
|
|
|
gotoxy(curscol, cursrow);
|
|
|
|
cursor(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the cursor left
|
|
|
|
*/
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (push, "LC")
|
2020-07-12 21:34:11 +00:00
|
|
|
void cursor_left(void) {
|
|
|
|
if (gapbegin > 0)
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapend--, get_gapbuf(--gapbegin));
|
2020-07-12 21:34:11 +00:00
|
|
|
else {
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-07-17 01:10:27 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
2020-07-12 21:34:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (curscol == 0) {
|
2020-07-13 03:12:01 +00:00
|
|
|
if (cursrow == 0) {
|
2020-07-12 21:34:11 +00:00
|
|
|
scroll_up();
|
2020-07-13 03:12:01 +00:00
|
|
|
if (cursrow == 0) {
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-07-13 03:12:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--cursrow;
|
2020-08-01 19:32:58 +00:00
|
|
|
curscol = rowlen[cursrow] - 1;
|
2020-07-12 21:34:11 +00:00
|
|
|
} else
|
|
|
|
--curscol;
|
|
|
|
gotoxy(curscol, cursrow);
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-04 23:14:52 +00:00
|
|
|
endsel = gapbegin;
|
|
|
|
revers(gapbegin < startsel ? 1 : 0);
|
2020-08-06 02:30:55 +00:00
|
|
|
cputc(get_gapbuf(gapbegin));
|
2020-08-04 23:14:52 +00:00
|
|
|
}
|
2020-08-05 02:27:54 +00:00
|
|
|
revers(0);
|
2020-08-04 23:14:52 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (pop)
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the cursor right
|
|
|
|
*/
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (push, "LC")
|
2020-07-12 21:34:11 +00:00
|
|
|
void cursor_right(void) {
|
2020-07-17 01:10:27 +00:00
|
|
|
if (gapend < BUFSZ - 1)
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapbegin++, get_gapbuf(++gapend));
|
2020-07-12 21:34:11 +00:00
|
|
|
else {
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-08-04 21:49:27 +00:00
|
|
|
goto done;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
++curscol;
|
2020-08-24 02:59:04 +00:00
|
|
|
if ((gapend == BUFSZ - 1) && (get_gapbuf(gapend) != EOL))
|
2020-08-04 21:49:27 +00:00
|
|
|
goto done;
|
2020-08-03 02:49:53 +00:00
|
|
|
if (curscol == rowlen[cursrow]) {
|
2020-08-02 04:13:32 +00:00
|
|
|
if (cursrow == NROWS - 1)
|
|
|
|
scroll_down();
|
|
|
|
++cursrow;
|
|
|
|
curscol = 0;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
2020-08-04 21:49:27 +00:00
|
|
|
done:
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-04 21:49:27 +00:00
|
|
|
endsel = gapbegin;
|
2020-08-04 23:14:52 +00:00
|
|
|
revers(gapbegin > startsel ? 1 : 0);
|
2020-08-06 02:30:55 +00:00
|
|
|
cputc(get_gapbuf(gapbegin - 1));
|
2020-08-04 21:49:27 +00:00
|
|
|
}
|
2020-08-05 02:27:54 +00:00
|
|
|
revers(0);
|
2020-07-12 21:34:11 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
|
|
|
}
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (pop)
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the cursor up
|
2020-07-16 04:00:34 +00:00
|
|
|
* Returns 1 if at top, 0 otherwise
|
2020-07-12 21:34:11 +00:00
|
|
|
*/
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (push, "LC")
|
2020-07-16 04:00:34 +00:00
|
|
|
uint8_t cursor_up(void) {
|
2020-07-12 21:34:11 +00:00
|
|
|
uint8_t i;
|
2020-07-13 03:12:01 +00:00
|
|
|
if (cursrow == 0) {
|
2020-07-12 21:34:11 +00:00
|
|
|
scroll_up();
|
2020-07-13 03:12:01 +00:00
|
|
|
if (cursrow == 0) {
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-07-13 03:12:01 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
2020-07-16 04:00:34 +00:00
|
|
|
return 1;
|
2020-07-13 03:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-05 02:27:54 +00:00
|
|
|
for (i = curscol; i > 0; --i) {
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapend--, get_gapbuf(--gapbegin));
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-05 02:27:54 +00:00
|
|
|
gotoxy(i - 1, cursrow);
|
|
|
|
revers(gapbegin < startsel ? 1 : 0);
|
2020-08-06 02:30:55 +00:00
|
|
|
cputc(get_gapbuf(gapbegin));
|
2020-08-05 02:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
--cursrow;
|
|
|
|
// Short line ...
|
2020-07-16 04:33:48 +00:00
|
|
|
if (curscol > rowlen[cursrow] - 1)
|
2020-07-12 21:34:11 +00:00
|
|
|
curscol = rowlen[cursrow] - 1;
|
2020-08-05 02:27:54 +00:00
|
|
|
for (i = rowlen[cursrow]; i > curscol; --i) {
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapend--, get_gapbuf(--gapbegin));
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-05 02:27:54 +00:00
|
|
|
gotoxy(i - 1, cursrow);
|
|
|
|
revers(gapbegin < startsel ? 1 : 0);
|
2020-08-06 02:30:55 +00:00
|
|
|
cputc(get_gapbuf(gapbegin));
|
2020-08-05 02:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-04 23:54:38 +00:00
|
|
|
endsel = gapbegin;
|
|
|
|
}
|
2020-08-05 02:27:54 +00:00
|
|
|
revers(0);
|
2020-07-12 21:34:11 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
2020-07-16 04:00:34 +00:00
|
|
|
return 0;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (pop)
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the cursor down
|
2020-07-16 04:00:34 +00:00
|
|
|
* Returns 1 if at bottom, 0 otherwise
|
2020-07-12 21:34:11 +00:00
|
|
|
*/
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (push, "LC")
|
2020-07-16 04:00:34 +00:00
|
|
|
uint8_t cursor_down(void) {
|
2020-07-12 21:34:11 +00:00
|
|
|
uint8_t i;
|
2020-07-17 01:10:27 +00:00
|
|
|
if (cursrow == NROWS - 1)
|
2020-07-12 21:34:11 +00:00
|
|
|
scroll_down();
|
2020-08-06 02:30:55 +00:00
|
|
|
if ((get_gapbuf(gapend + rowlen[cursrow] - curscol) != EOL) &&
|
2020-07-17 01:10:27 +00:00
|
|
|
(rowlen[cursrow] != NCOLS))
|
|
|
|
return 1; // Last line
|
|
|
|
|
2020-08-24 02:59:04 +00:00
|
|
|
if (rowlen[cursrow] == 0) {
|
|
|
|
beep();
|
|
|
|
return 1;
|
|
|
|
}
|
2020-07-17 01:10:27 +00:00
|
|
|
for (i = 0; i < rowlen[cursrow] - curscol; ++i) {
|
2020-08-04 23:54:38 +00:00
|
|
|
if (gapend < BUFSZ - 1) {
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapbegin++, get_gapbuf(++gapend));
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-05 02:27:54 +00:00
|
|
|
revers(gapbegin > startsel ? 1 : 0);
|
2020-08-06 02:30:55 +00:00
|
|
|
cputc(get_gapbuf(gapbegin - 1));
|
2020-08-05 02:27:54 +00:00
|
|
|
}
|
2020-08-04 23:54:38 +00:00
|
|
|
}
|
2020-07-17 01:10:27 +00:00
|
|
|
else {
|
2020-08-01 04:25:08 +00:00
|
|
|
beep();
|
2020-07-16 04:00:34 +00:00
|
|
|
return 1;
|
2020-07-13 03:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-17 01:10:27 +00:00
|
|
|
++cursrow;
|
2020-07-12 21:34:11 +00:00
|
|
|
// Short line ...
|
2020-08-24 02:59:04 +00:00
|
|
|
if (rowlen[cursrow] == 0)
|
2020-08-24 02:04:05 +00:00
|
|
|
curscol = 0;
|
|
|
|
else if (curscol > rowlen[cursrow] - 1)
|
2020-07-12 21:34:11 +00:00
|
|
|
curscol = rowlen[cursrow] - 1;
|
2020-08-04 23:54:38 +00:00
|
|
|
gotoxy(0, cursrow);
|
|
|
|
for (i = 0; i < curscol; ++i) {
|
|
|
|
if (gapend < BUFSZ - 1) {
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(gapbegin++, get_gapbuf(++gapend));
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-05 02:27:54 +00:00
|
|
|
revers(gapbegin > startsel ? 1 : 0);
|
2020-08-06 02:30:55 +00:00
|
|
|
cputc(get_gapbuf(gapbegin - 1));
|
2020-08-05 02:27:54 +00:00
|
|
|
}
|
2020-08-04 23:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
if (mode == SEL_SELECT) {
|
2020-08-04 23:54:38 +00:00
|
|
|
endsel = gapbegin;
|
|
|
|
}
|
2020-08-05 02:27:54 +00:00
|
|
|
revers(0);
|
2020-07-12 21:34:11 +00:00
|
|
|
gotoxy(curscol, cursrow);
|
2020-07-16 04:00:34 +00:00
|
|
|
return 0;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
2020-07-19 04:21:03 +00:00
|
|
|
#pragma code-name (pop)
|
2020-07-12 21:34:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Goto beginning of line
|
|
|
|
*/
|
|
|
|
void goto_bol(void) {
|
|
|
|
while (curscol > 0)
|
|
|
|
cursor_left();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Goto end of line
|
|
|
|
*/
|
|
|
|
void goto_eol(void) {
|
|
|
|
while (curscol < rowlen[cursrow] - 1)
|
|
|
|
cursor_right();
|
|
|
|
}
|
|
|
|
|
2020-07-18 02:33:25 +00:00
|
|
|
/*
|
|
|
|
* Word left
|
|
|
|
*/
|
|
|
|
void word_left(void) {
|
|
|
|
do {
|
|
|
|
cursor_left();
|
2020-08-06 02:30:55 +00:00
|
|
|
} while ((get_gapbuf(gapbegin) != ' ') && (get_gapbuf(gapbegin) != EOL) &&
|
2020-07-18 02:33:25 +00:00
|
|
|
(gapbegin > 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Word right
|
|
|
|
*/
|
|
|
|
void word_right(void) {
|
|
|
|
do {
|
|
|
|
cursor_right();
|
2020-08-06 02:30:55 +00:00
|
|
|
} while ((get_gapbuf(gapbegin) != ' ') && (get_gapbuf(gapbegin) != EOL) &&
|
2020-07-18 02:33:25 +00:00
|
|
|
(gapend < BUFSZ - 1));
|
|
|
|
}
|
|
|
|
|
2020-07-12 21:34:11 +00:00
|
|
|
/*
|
|
|
|
* Jump forward 15 screen lines
|
|
|
|
*/
|
|
|
|
void page_down(void) {
|
|
|
|
uint8_t i;
|
|
|
|
for (i = 0; i < 15; ++i)
|
2020-07-16 04:00:34 +00:00
|
|
|
if (cursor_down() == 1)
|
|
|
|
break;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Jump back 15 screen lines
|
|
|
|
*/
|
|
|
|
void page_up(void) {
|
|
|
|
uint8_t i;
|
|
|
|
for (i = 0; i < 15; ++i)
|
2020-07-16 04:00:34 +00:00
|
|
|
if (cursor_up() == 1)
|
|
|
|
break;
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 05:53:56 +00:00
|
|
|
/*
|
|
|
|
* Perform word-wrapping on current paragraph
|
2020-08-01 19:38:56 +00:00
|
|
|
* addbreaks - if 1, add breaks to do word wrap, otherwise it 'unwraps'
|
|
|
|
* (ie: removes all carriage returns in paragraph)
|
2020-08-01 05:53:56 +00:00
|
|
|
*/
|
2020-08-01 19:38:56 +00:00
|
|
|
void word_wrap_para(uint8_t addbreaks) {
|
2020-08-01 06:29:33 +00:00
|
|
|
uint16_t i = gapbegin;
|
|
|
|
uint8_t rets = 0, col = 0;
|
|
|
|
uint16_t startpara = 0;
|
|
|
|
// Find start of paragraph ("\r\r" delimiter)
|
|
|
|
while (i > 0) {
|
|
|
|
--i;
|
2020-08-06 02:30:55 +00:00
|
|
|
if (get_gapbuf(i) == '\r')
|
2020-08-01 06:29:33 +00:00
|
|
|
++rets;
|
|
|
|
else
|
|
|
|
rets = 0;
|
|
|
|
if (rets == 2) {
|
|
|
|
startpara = i + 2;
|
|
|
|
break;
|
|
|
|
}
|
2020-08-01 05:53:56 +00:00
|
|
|
}
|
2020-08-01 06:29:33 +00:00
|
|
|
// Iterate through para, up to the cursor
|
|
|
|
i = startpara;
|
|
|
|
while (i < gapbegin) {
|
2020-08-06 02:30:55 +00:00
|
|
|
if (get_gapbuf(i) == '\r')
|
|
|
|
set_gapbuf(i, ' ');
|
2020-08-01 05:53:56 +00:00
|
|
|
++col;
|
2020-08-01 19:38:56 +00:00
|
|
|
if (addbreaks && (col == 76)) {
|
2020-08-01 06:29:33 +00:00
|
|
|
// Backtrack to find a space
|
2020-08-06 02:30:55 +00:00
|
|
|
while ((get_gapbuf(i) != ' ') && (i > startpara))
|
2020-08-01 06:29:33 +00:00
|
|
|
--i;
|
|
|
|
if (i == startpara) {
|
|
|
|
beep();
|
|
|
|
return;
|
|
|
|
}
|
2020-08-06 02:30:55 +00:00
|
|
|
set_gapbuf(i, '\r'); // Break line
|
2020-08-01 06:29:33 +00:00
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
++i;
|
2020-08-01 05:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-18 04:03:27 +00:00
|
|
|
/*
|
|
|
|
* Help screen
|
2020-08-01 04:25:08 +00:00
|
|
|
* EDITHELP.TXT is expected to contain lines of exactly 80 chars
|
2020-07-18 04:03:27 +00:00
|
|
|
*/
|
2020-08-14 03:21:42 +00:00
|
|
|
void help(uint8_t num) {
|
|
|
|
FILE *fp;
|
2020-08-05 23:30:32 +00:00
|
|
|
char *p;
|
2020-08-01 04:25:08 +00:00
|
|
|
char c;
|
2020-08-06 02:30:55 +00:00
|
|
|
uint16_t i, s;
|
2020-08-05 23:30:32 +00:00
|
|
|
uint8_t cont;
|
2020-07-19 21:53:49 +00:00
|
|
|
revers(0);
|
2020-07-18 04:03:27 +00:00
|
|
|
cursor(0);
|
|
|
|
clrscr();
|
2020-09-02 22:42:00 +00:00
|
|
|
snprintf(iobuf, 80, "%s/EDITHELP%u.TXT", startdir, num);
|
2020-08-14 03:21:42 +00:00
|
|
|
fp = fopen(iobuf, "rb");
|
2020-08-01 04:25:08 +00:00
|
|
|
if (!fp) {
|
2020-08-14 03:21:42 +00:00
|
|
|
printf("Can't open help file\n\n");
|
2020-08-01 04:25:08 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2020-08-13 20:08:51 +00:00
|
|
|
cutbuflen = 0;
|
2020-08-06 02:30:55 +00:00
|
|
|
p = iobuf;
|
2020-08-05 23:30:32 +00:00
|
|
|
do {
|
2020-08-07 02:43:14 +00:00
|
|
|
if (FREESPACE() < IOSZ) {
|
2020-08-05 23:30:32 +00:00
|
|
|
beep();
|
|
|
|
goto done;
|
|
|
|
}
|
2020-08-07 02:43:14 +00:00
|
|
|
s = fread(p, 1, IOSZ, fp);
|
|
|
|
cont = (s == IOSZ ? 1 : 0);
|
2020-08-05 23:30:32 +00:00
|
|
|
for (i = 0; i < s; ++i) {
|
|
|
|
c = p[i];
|
2020-08-10 21:15:39 +00:00
|
|
|
if (c == '{')
|
2020-08-05 23:30:32 +00:00
|
|
|
printf("%s", openapple);
|
2020-08-11 00:05:18 +00:00
|
|
|
else if (c == '}')
|
2020-08-10 21:15:39 +00:00
|
|
|
printf("%s", closedapple);
|
2020-08-05 23:30:32 +00:00
|
|
|
else if ((c != '\r') && (c != '\n'))
|
|
|
|
putchar(c);
|
|
|
|
}
|
|
|
|
} while (cont);
|
2020-08-01 04:25:08 +00:00
|
|
|
done:
|
2020-08-05 23:30:32 +00:00
|
|
|
fclose(fp);
|
2020-07-18 04:03:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 21:21:59 +00:00
|
|
|
/*
|
2020-09-04 02:02:58 +00:00
|
|
|
* Chain EMAIL.SYSTEM
|
2020-07-15 21:21:59 +00:00
|
|
|
*/
|
|
|
|
void load_email(void) {
|
2020-07-16 21:38:37 +00:00
|
|
|
revers(0);
|
|
|
|
clrscr();
|
2020-09-03 22:28:54 +00:00
|
|
|
sprintf(userentry, "%s/EMAIL.SYSTEM", startdir);
|
|
|
|
exec(userentry, NULL);
|
2020-07-15 21:21:59 +00:00
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
|
2020-07-28 21:14:43 +00:00
|
|
|
/*
|
2020-09-04 02:02:58 +00:00
|
|
|
* Chain ATTACHER.SYSTEM
|
2020-07-28 21:14:43 +00:00
|
|
|
*/
|
|
|
|
void load_attacher(void) {
|
|
|
|
revers(0);
|
|
|
|
clrscr();
|
2020-09-03 22:28:54 +00:00
|
|
|
sprintf(userentry, "%s/ATTACHER.SYSTEM", startdir);
|
|
|
|
exec(userentry, filename);
|
2020-07-28 21:14:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 01:37:39 +00:00
|
|
|
void file_ui(char *, char *, char *); // Forward declaration
|
|
|
|
void name_file(void); // Forward declaration
|
2020-09-02 20:23:53 +00:00
|
|
|
|
2020-07-18 05:45:36 +00:00
|
|
|
/*
|
|
|
|
* Save file to disk, handle user interface
|
|
|
|
*/
|
|
|
|
void save(void) {
|
2020-08-11 20:29:26 +00:00
|
|
|
uint8_t rc;
|
2020-08-12 03:04:46 +00:00
|
|
|
FILE *fp;
|
2020-07-19 04:01:59 +00:00
|
|
|
if (strlen(filename) == 0) {
|
2020-08-11 20:29:26 +00:00
|
|
|
status[1] = 1; // Prompt if save will overwrite existing file
|
2020-09-02 20:23:53 +00:00
|
|
|
name_file();
|
|
|
|
if (strlen(filename) == 0)
|
2020-07-19 15:15:57 +00:00
|
|
|
return;
|
2020-07-19 04:01:59 +00:00
|
|
|
}
|
2020-08-12 03:04:46 +00:00
|
|
|
// If status[1] is set, check for overwrite
|
|
|
|
if (status[1]) {
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (fp) {
|
|
|
|
fclose(fp);
|
2020-09-02 20:23:53 +00:00
|
|
|
beep();
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "File '%s' exists, overwrite", filename);
|
2020-08-12 03:04:46 +00:00
|
|
|
if (prompt_okay(userentry) != 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2020-08-12 22:32:46 +00:00
|
|
|
rc = save_multibank_file();
|
2020-08-11 20:29:26 +00:00
|
|
|
switch (rc) {
|
|
|
|
case 0: // Success
|
|
|
|
status[1] = 0; // No need to prompt for overwrite next time
|
|
|
|
set_modified(0);
|
|
|
|
break;
|
|
|
|
case 1: // Save error
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "Can't save '%s'", filename);
|
2020-08-11 20:29:26 +00:00
|
|
|
show_error(userentry);
|
|
|
|
break;
|
2020-07-18 05:45:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 03:08:54 +00:00
|
|
|
/*
|
|
|
|
* Perform replace part of search/replace
|
|
|
|
* pos - position where search term was found
|
|
|
|
* r - if 0 then perform replace operation
|
2020-08-09 06:37:25 +00:00
|
|
|
* ask - if 1 then prompt for each replacement
|
2020-08-09 06:16:20 +00:00
|
|
|
* Returns 1 if search should continue, 0 otherwise
|
2020-08-09 03:08:54 +00:00
|
|
|
*/
|
2020-08-09 06:37:25 +00:00
|
|
|
uint8_t finish_search_replace(uint16_t pos, uint8_t r, uint8_t ask) {
|
2020-08-09 03:08:54 +00:00
|
|
|
uint8_t i;
|
|
|
|
mode = SEL_NONE;
|
|
|
|
jump_pos(pos);
|
2020-08-09 07:12:42 +00:00
|
|
|
startsel = gapend + 1;
|
|
|
|
endsel = gapend + 1 + strlen(search);
|
2020-08-09 06:37:25 +00:00
|
|
|
draw_screen();
|
2020-08-09 03:08:54 +00:00
|
|
|
if (r == 0) { // Replace mode
|
2020-08-09 06:37:25 +00:00
|
|
|
if (ask) {
|
|
|
|
i = prompt_okay("Replace");
|
2020-08-09 07:12:42 +00:00
|
|
|
if (i == 1) { // 'n'
|
|
|
|
cursor_right();
|
2020-08-09 06:37:25 +00:00
|
|
|
return 1; // Continue
|
2020-08-09 07:12:42 +00:00
|
|
|
}
|
|
|
|
if (i == 2) { // ESC
|
|
|
|
startsel = endsel = 65535U;
|
2020-08-09 06:37:25 +00:00
|
|
|
return 0; // Abort
|
2020-08-09 07:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-09 03:08:54 +00:00
|
|
|
for (i = 0; i < strlen(search); ++i)
|
|
|
|
delete_char_right();
|
|
|
|
for (i = 0; i < strlen(replace); ++i)
|
|
|
|
insert_char(replace[i]);
|
2020-08-09 07:12:42 +00:00
|
|
|
set_modified(1);
|
|
|
|
draw_screen();
|
|
|
|
cursor_right();
|
|
|
|
return 1; // Continue
|
2020-08-09 03:08:54 +00:00
|
|
|
}
|
2020-08-09 07:12:42 +00:00
|
|
|
startsel = endsel = 65535U;
|
|
|
|
return 0; // Do not continue
|
2020-08-09 06:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform search/replace operation
|
|
|
|
* r - if 0 then perform replace operation
|
2020-08-09 06:37:25 +00:00
|
|
|
* ask - if 1 then prompt for each replacement
|
2020-08-09 06:16:20 +00:00
|
|
|
*/
|
2020-08-09 06:37:25 +00:00
|
|
|
void do_search_replace(uint8_t r, uint8_t ask) {
|
2020-08-09 06:16:20 +00:00
|
|
|
uint8_t wrapcount = 0;
|
|
|
|
uint16_t foundpos;
|
2020-08-09 07:12:42 +00:00
|
|
|
search:
|
2020-08-09 06:16:20 +00:00
|
|
|
mode = SRCH1; // Searching ..
|
|
|
|
update_status_line();
|
2020-08-17 02:59:23 +00:00
|
|
|
set_gapbuf(BUFSZ + 1, '\0'); // NULL term for search_in_gapbuf()
|
2020-08-09 06:16:20 +00:00
|
|
|
if (search_in_gapbuf(gapend + 1, search, &foundpos) == 0) {
|
2020-08-09 19:32:58 +00:00
|
|
|
if (wrapcount > 0) {
|
|
|
|
mode = SEL_NONE;
|
2020-08-09 06:16:20 +00:00
|
|
|
return; // Wrapped already. Give up.
|
2020-08-09 19:32:58 +00:00
|
|
|
}
|
2020-08-09 06:16:20 +00:00
|
|
|
++wrapcount;
|
|
|
|
mode = SRCH2; // Wrapped ..
|
|
|
|
update_status_line();
|
|
|
|
set_gapbuf(gapbegin, '\0'); // NULL term for search_in_gapbuf()
|
|
|
|
if (search_in_gapbuf(0, search, &foundpos) == 0) {
|
|
|
|
mode = SRCH3; // Not found ..
|
|
|
|
return;
|
|
|
|
}
|
2020-08-09 06:37:25 +00:00
|
|
|
if (finish_search_replace(foundpos, r, ask) == 1)
|
2020-08-09 06:16:20 +00:00
|
|
|
goto search;
|
2020-08-09 07:12:42 +00:00
|
|
|
mode = SEL_NONE;
|
2020-08-09 06:16:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-09 06:37:25 +00:00
|
|
|
if (finish_search_replace(gapbegin + foundpos - (gapend + 1), r, ask) == 1)
|
2020-08-09 06:16:20 +00:00
|
|
|
goto search;
|
2020-08-09 07:12:42 +00:00
|
|
|
mode = SEL_NONE;
|
2020-08-09 03:08:54 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 02:46:47 +00:00
|
|
|
/*
|
2020-09-06 18:40:50 +00:00
|
|
|
* Check if there are files on a RAM disk
|
|
|
|
* dev - Device number of RAM disk
|
|
|
|
*/
|
|
|
|
void check_ramdisk(uint8_t dev) {
|
|
|
|
dhandle_t dio_hdl;
|
|
|
|
uint8_t c;
|
|
|
|
dio_hdl = dio_open(dev);
|
|
|
|
dio_read(dio_hdl, 2, iobuf);
|
|
|
|
dio_close(dio_hdl);
|
|
|
|
c = iobuf[0x25] + 256 * iobuf[0x26]; // File count
|
|
|
|
if (c > 0) {
|
2020-09-06 21:21:51 +00:00
|
|
|
fputs("\n/",stdout);
|
2020-09-06 18:40:50 +00:00
|
|
|
for (c = 0; c < (iobuf[0x04] & 0x0f); ++c)
|
|
|
|
putchar(iobuf[0x05 + c]);
|
|
|
|
printf(" is not empty.\n");
|
|
|
|
printf("[Q] to quit, and preserve RAMDisk\n");
|
|
|
|
beep();
|
|
|
|
c = cgetc();
|
|
|
|
if ((c == 'Q') || (c == 'q'))
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disconnect RAM disks /RAM and/or /RAM3
|
|
|
|
* Note that both /RAM and /RAM3 may be active at the same time!!
|
2020-08-17 02:46:47 +00:00
|
|
|
*/
|
|
|
|
void disconnect_ramdisk(void) {
|
|
|
|
uint8_t i, j;
|
|
|
|
uint8_t *devcnt = (uint8_t*)0xbf31; // Number of devices
|
|
|
|
uint8_t *devlst = (uint8_t*)0xbf32; // Disk device numbers
|
|
|
|
uint16_t *s0d1 = (uint16_t*)0xbf10; // s0d1 driver vector
|
2020-09-06 18:40:50 +00:00
|
|
|
uint16_t *s3d1 = (uint16_t*)0xbf16; // s3d1 driver vector
|
2020-08-17 02:46:47 +00:00
|
|
|
uint16_t *s3d2 = (uint16_t*)0xbf26; // s3d2 driver vector
|
2020-09-06 21:52:20 +00:00
|
|
|
if (*s0d1 != *s3d2)
|
|
|
|
check_ramdisk(3 + (2 - 1) * 8); // s3d2
|
|
|
|
if (*s0d1 != *s3d1)
|
|
|
|
check_ramdisk(3 + (1 - 1) * 8); // s3d1
|
2020-09-06 20:47:03 +00:00
|
|
|
if (*s0d1 == *s3d2) {
|
|
|
|
s3d2dev = 0;
|
2020-09-06 18:40:50 +00:00
|
|
|
goto s3d1; // No /RAM
|
2020-09-06 20:47:03 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i <= *devcnt; ++i)
|
|
|
|
if ((devlst[i] & 0xf0) == 0xb0) {
|
|
|
|
s3d2dev = devlst[i];
|
|
|
|
for (j = i; j <= *devcnt; ++j)
|
|
|
|
devlst[j] = devlst[j + 1];
|
2020-08-17 02:46:47 +00:00
|
|
|
break;
|
2020-09-06 20:47:03 +00:00
|
|
|
}
|
|
|
|
s3d2vec = *s3d2;
|
2020-08-17 02:46:47 +00:00
|
|
|
*s3d2 = *s0d1;
|
|
|
|
--(*devcnt);
|
2020-09-06 18:40:50 +00:00
|
|
|
s3d1:
|
2020-09-06 20:47:03 +00:00
|
|
|
if (*s0d1 == *s3d1) {
|
|
|
|
s3d1dev = 0;
|
2020-09-06 18:40:50 +00:00
|
|
|
return; // No /RAM3
|
2020-09-06 20:47:03 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i <= *devcnt; ++i)
|
|
|
|
if ((devlst[i] & 0xf0) == 0x30) {
|
|
|
|
s3d1dev = devlst[i];
|
|
|
|
for (j = i; j <= *devcnt; ++j)
|
|
|
|
devlst[j] = devlst[j + 1];
|
2020-09-06 18:40:50 +00:00
|
|
|
break;
|
2020-09-06 20:47:03 +00:00
|
|
|
}
|
|
|
|
s3d1vec = *s3d1;
|
2020-09-06 18:40:50 +00:00
|
|
|
*s3d1 = *s0d1;
|
|
|
|
--(*devcnt);
|
2020-08-17 02:46:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 20:47:03 +00:00
|
|
|
void s3d1driver(void) {
|
|
|
|
__asm__("jmp (%v)", s3d1vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void s3d2driver(void) {
|
|
|
|
__asm__("jmp (%v)", s3d2vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconnect RAMdisk on exit
|
|
|
|
*/
|
|
|
|
#pragma optimize (off)
|
|
|
|
void reconnect_ramdisk(void) {
|
|
|
|
uint8_t *devcnt = (uint8_t*)0xbf31; // Number of devices
|
|
|
|
uint8_t *devlst = (uint8_t*)0xbf32; // Disk device numbers
|
|
|
|
uint16_t *s3d1 = (uint16_t*)0xbf16; // s3d1 driver vector
|
|
|
|
uint16_t *s3d2 = (uint16_t*)0xbf26; // s3d2 driver vector
|
|
|
|
if (s3d2dev) {
|
|
|
|
*s3d2 = s3d2vec;
|
|
|
|
++(*devcnt);
|
|
|
|
devlst[*devcnt] = s3d2dev;
|
|
|
|
__asm__("lda #$03"); // FORMAT request
|
|
|
|
__asm__("sta $42");
|
|
|
|
__asm__("lda #$b0"); // Unit number (s3d2)
|
|
|
|
__asm__("sta $43");
|
|
|
|
__asm__("lda #$00"); // LSB of buffer pointer
|
|
|
|
__asm__("sta $44");
|
|
|
|
__asm__("lda #$20"); // MSB of buffer pointer
|
|
|
|
__asm__("sta $45");
|
|
|
|
__asm__("lda $c08b"); // R/W enable LC, bank 1 on
|
|
|
|
__asm__("lda $c08b");
|
|
|
|
__asm__("jsr %v", s3d2driver); // Call driver
|
|
|
|
__asm__("bit $c082"); // ROM back online
|
|
|
|
__asm__("bcc %g", s3d1); // If no error ...
|
|
|
|
beep();
|
|
|
|
printf("Unable to reconnect S3D2");
|
|
|
|
}
|
|
|
|
s3d1:
|
|
|
|
if (s3d1dev) {
|
|
|
|
*s3d1 = s3d1vec;
|
|
|
|
++(*devcnt);
|
|
|
|
devlst[*devcnt] = s3d1dev;
|
|
|
|
__asm__("lda #$03"); // FORMAT request
|
|
|
|
__asm__("sta $42");
|
|
|
|
__asm__("lda #$30"); // Unit number (s3d1)
|
|
|
|
__asm__("sta $43");
|
|
|
|
__asm__("lda #$00"); // LSB of buffer pointer
|
|
|
|
__asm__("sta $44");
|
|
|
|
__asm__("lda #$20"); // MSB of buffer pointer
|
|
|
|
__asm__("sta $45");
|
|
|
|
__asm__("lda $c08b"); // R/W enable LC, bank 1 on
|
|
|
|
__asm__("lda $c08b");
|
|
|
|
__asm__("jsr %v", s3d1driver); // Call driver
|
|
|
|
__asm__("bit $c082"); // ROM back online
|
2020-09-06 21:21:51 +00:00
|
|
|
__asm__("bcc %g", done); // If no error ...
|
2020-09-06 20:47:03 +00:00
|
|
|
beep();
|
|
|
|
printf("Unable to reconnect S3D1");
|
|
|
|
}
|
2020-09-06 21:21:51 +00:00
|
|
|
done:
|
|
|
|
return;
|
2020-09-06 20:47:03 +00:00
|
|
|
}
|
|
|
|
#pragma optimize (on)
|
|
|
|
|
2020-08-09 23:36:46 +00:00
|
|
|
/*
|
|
|
|
* Available aux banks. Taken from RamWorks III Manual p47
|
2020-08-11 20:29:26 +00:00
|
|
|
* banktbl is populated as follows:
|
|
|
|
* First byte is number of banks
|
|
|
|
* Following bytes are the logical bank numbers in physical bank order
|
|
|
|
* Final byte is $ff terminator
|
2020-08-09 23:36:46 +00:00
|
|
|
*/
|
|
|
|
void avail_aux_banks(void) {
|
|
|
|
__asm__("sta $c009"); // Store in ALTZP
|
|
|
|
__asm__("ldy #$7f"); // Maximum valid bank
|
|
|
|
findbanks:
|
|
|
|
__asm__("sty $c073"); // Select bank
|
|
|
|
__asm__("sty $00"); // Store bank num in ALTZP
|
|
|
|
__asm__("tya");
|
|
|
|
__asm__("eor #$ff");
|
|
|
|
__asm__("sta $01"); // Store the inverse in ALTZP too
|
|
|
|
__asm__("dey");
|
|
|
|
__asm__("bpl %g", findbanks);
|
|
|
|
// Read back the bytes we wrote to find valid banks
|
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("tay");
|
|
|
|
__asm__("tax");
|
|
|
|
findthem:
|
|
|
|
__asm__("sty $c073"); // Select bank
|
|
|
|
__asm__("sta $c076"); // Why?
|
|
|
|
__asm__("cpy $00");
|
|
|
|
__asm__("bne %g", notone);
|
|
|
|
__asm__("tya");
|
|
|
|
__asm__("eor #$ff");
|
|
|
|
__asm__("cmp $01");
|
|
|
|
__asm__("bne %g", notone);
|
|
|
|
__asm__("inx");
|
|
|
|
__asm__("tya");
|
|
|
|
__asm__("sta %v,x", banktbl);
|
|
|
|
__asm__("cpx #128"); // 8MB max
|
|
|
|
__asm__("bcs %g", done);
|
2020-08-11 20:29:26 +00:00
|
|
|
notone: // 'not one', not 'no tone' !
|
2020-08-09 23:36:46 +00:00
|
|
|
__asm__("iny");
|
|
|
|
__asm__("bpl %g", findthem);
|
|
|
|
done:
|
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Back to aux bank 0
|
|
|
|
__asm__("sta $c008"); // Turn off ALTZP
|
|
|
|
__asm__("stx %v", banktbl); // Number of banks
|
|
|
|
__asm__("lda #$ff");
|
|
|
|
__asm__("inx");
|
|
|
|
__asm__("sta %v,x", banktbl); // Terminator
|
|
|
|
}
|
|
|
|
|
2020-08-09 22:16:59 +00:00
|
|
|
/*
|
|
|
|
* Initialize the data at 0x200 in each aux bank so that all buffers
|
|
|
|
* are empty, unmodified and without a filename
|
|
|
|
*/
|
|
|
|
void init_aux_banks(void) {
|
2020-08-09 23:36:46 +00:00
|
|
|
uint8_t i;
|
2020-08-14 21:33:00 +00:00
|
|
|
uint16_t count;
|
2020-09-06 21:21:51 +00:00
|
|
|
clrscr();
|
2020-08-10 21:15:39 +00:00
|
|
|
revers(1);
|
|
|
|
cprintf("EDIT.SYSTEM Bobbi 2020");
|
|
|
|
revers(0);
|
2020-08-14 04:10:38 +00:00
|
|
|
cprintf("\n\n\n %u x 64KB aux banks -> %uKB\n", banktbl[0], banktbl[0]*64);
|
2020-08-14 05:19:21 +00:00
|
|
|
for (i = 1; i <= banktbl[0]; ++i) {
|
2020-08-09 23:36:46 +00:00
|
|
|
auxbank = bank_log_to_phys(i);
|
2020-08-11 20:29:26 +00:00
|
|
|
// Saves filename[], gapbegin, gapend and modified (BUFINFOSZ bytes)
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-09-06 20:47:03 +00:00
|
|
|
copyaux(filename, (void*)INFOADDR, BUFINFOSZ, TOAUX);
|
2020-08-09 22:16:59 +00:00
|
|
|
}
|
|
|
|
auxbank = 0;
|
2020-08-09 23:36:46 +00:00
|
|
|
l_auxbank = 1;
|
2020-08-09 22:16:59 +00:00
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-09-06 20:47:03 +00:00
|
|
|
for (count = 0; count < 50000; ++count); // Delay so user can read message
|
2020-08-09 22:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-08-11 20:29:26 +00:00
|
|
|
* Generate buffer list
|
2020-08-09 22:16:59 +00:00
|
|
|
*/
|
|
|
|
#pragma code-name (push, "LC")
|
2020-08-11 20:29:26 +00:00
|
|
|
void buffer_list(void) {
|
|
|
|
uint8_t o_aux = l_auxbank, row = 0;
|
|
|
|
uint8_t i;
|
|
|
|
cursor(0);
|
2020-08-14 04:10:38 +00:00
|
|
|
for (i = 1; i <= banktbl[0]; ++i) {
|
2020-08-11 20:29:26 +00:00
|
|
|
if (row == 0) {
|
|
|
|
clrscr();
|
2020-09-02 20:23:53 +00:00
|
|
|
revers(1);
|
|
|
|
cprintf("Active Buffer List (Total number of buffers: %u)", banktbl[0]);
|
|
|
|
revers(0);
|
2020-09-03 00:48:36 +00:00
|
|
|
gotoxy(0, row += 2);
|
2020-08-12 03:04:46 +00:00
|
|
|
cprintf(" Buf Size Mod Part Filename\r");
|
2020-08-11 20:29:26 +00:00
|
|
|
gotoxy(0, ++row);
|
|
|
|
}
|
|
|
|
change_aux_bank(i);
|
2020-08-13 03:31:20 +00:00
|
|
|
if (DATASIZE() > 0) {
|
|
|
|
cprintf("[%03u] %05u | %c | %3u | %s\r",
|
|
|
|
i, DATASIZE(), (status[0] ? '*' : ' '), status[2], filename);
|
2020-08-11 20:29:26 +00:00
|
|
|
gotoxy(0, ++row);
|
2020-08-13 03:31:20 +00:00
|
|
|
}
|
2020-08-11 20:29:26 +00:00
|
|
|
if (row == 22) {
|
|
|
|
cprintf("[Press Any Key]");
|
|
|
|
cgetc();
|
|
|
|
row = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
change_aux_bank(o_aux);
|
|
|
|
gotoxy(0, 23);
|
|
|
|
cprintf("[Press Any Key]");
|
|
|
|
cgetc();
|
|
|
|
}
|
|
|
|
#pragma code-name (pop)
|
|
|
|
|
2020-08-13 03:11:11 +00:00
|
|
|
/*
|
|
|
|
* Rename a file, taking care of multi-bank files
|
|
|
|
*/
|
|
|
|
void name_file(void) {
|
|
|
|
uint8_t bank = find_first_bank();
|
|
|
|
uint8_t origbank = l_auxbank;
|
|
|
|
uint8_t retval = 0, modified = 0, first = 1;
|
|
|
|
uint8_t filebank;
|
2020-09-03 01:37:39 +00:00
|
|
|
file_ui("Set Filename", openfilemsg, namefilemsg);
|
2020-09-02 20:23:53 +00:00
|
|
|
if (strlen(userentry) == 0) {
|
|
|
|
draw_screen();
|
2020-08-13 03:11:11 +00:00
|
|
|
return;
|
2020-09-02 20:23:53 +00:00
|
|
|
}
|
2020-08-13 03:11:11 +00:00
|
|
|
if (bank != origbank)
|
|
|
|
change_aux_bank(bank);
|
|
|
|
if (status[2] == 0) { // Oh, it's actually just a single bank file
|
|
|
|
strcpy(filename, userentry);
|
|
|
|
status[1] = 1; // Should prompt if overwriting file on save
|
2020-09-02 20:23:53 +00:00
|
|
|
draw_screen();
|
2020-08-13 03:11:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (status[2] != 1) {
|
2020-09-02 20:23:53 +00:00
|
|
|
draw_screen();
|
2020-08-13 03:11:11 +00:00
|
|
|
show_error("SBF error"); // Should never happen
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
filebank = status[2];
|
|
|
|
strcpy(filename, userentry);
|
|
|
|
status[1] = 1; // Should prompt if overwriting file on save
|
|
|
|
change_aux_bank(++l_auxbank);
|
|
|
|
} while (status[2] == filebank + 1);
|
|
|
|
change_aux_bank(origbank);
|
2020-09-02 20:23:53 +00:00
|
|
|
draw_screen();
|
2020-08-13 03:11:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 20:29:26 +00:00
|
|
|
/*
|
|
|
|
* Save all modified buffers
|
|
|
|
*/
|
|
|
|
void save_all(void) {
|
|
|
|
uint8_t o_aux = l_auxbank;
|
|
|
|
uint8_t i;
|
|
|
|
cursor(0);
|
2020-08-14 21:33:00 +00:00
|
|
|
for (i = 1; i <= banktbl[0]; ++i) {
|
2020-08-11 20:29:26 +00:00
|
|
|
change_aux_bank(i);
|
|
|
|
if (status[0]) { // If buffer is modified
|
2020-08-16 21:19:23 +00:00
|
|
|
if (strlen(filename) > 0)
|
|
|
|
snprintf(userentry, 80, "Save '%s'", filename);
|
|
|
|
else
|
|
|
|
strcpy(userentry, "Save <scratch> buffer");
|
|
|
|
if (prompt_okay(userentry) != 0)
|
|
|
|
continue;
|
2020-08-11 20:29:26 +00:00
|
|
|
draw_screen();
|
2020-08-12 23:16:47 +00:00
|
|
|
save();
|
2020-08-11 20:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
change_aux_bank(o_aux);
|
2020-08-09 22:16:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 20:29:26 +00:00
|
|
|
/*
|
|
|
|
* Sort startsel / endsel in ascending order to allow backwards selection
|
|
|
|
*/
|
2020-08-10 04:41:54 +00:00
|
|
|
void order_selection(void) {
|
|
|
|
uint16_t tmp;
|
|
|
|
if (startsel > endsel) {
|
|
|
|
tmp = endsel;
|
|
|
|
endsel = startsel;
|
|
|
|
startsel = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 01:17:30 +00:00
|
|
|
/*
|
|
|
|
* Remember current gapbuf settings to support undo
|
|
|
|
*/
|
|
|
|
void mark_undo(void) {
|
|
|
|
oldgapbegin = gapbegin;
|
|
|
|
oldgapend = gapend;
|
|
|
|
canundo = 1;
|
|
|
|
}
|
|
|
|
|
2020-09-02 00:13:25 +00:00
|
|
|
struct tabent {
|
2020-09-02 23:51:44 +00:00
|
|
|
char name[16];
|
|
|
|
uint8_t type;
|
|
|
|
uint32_t size;
|
2020-09-02 00:13:25 +00:00
|
|
|
} *entry;
|
|
|
|
|
2020-09-02 03:46:43 +00:00
|
|
|
#define FILELINES 16
|
2020-09-02 00:13:25 +00:00
|
|
|
|
|
|
|
/*
|
2020-09-02 03:46:43 +00:00
|
|
|
* Draw one line in file chooser UI
|
|
|
|
* i - index of file to draw
|
|
|
|
* first - index of first file on screen
|
|
|
|
* selected - index of currently selected file
|
|
|
|
* entries - total number of file entries in directory
|
2020-09-02 00:13:25 +00:00
|
|
|
*/
|
2020-09-02 22:11:38 +00:00
|
|
|
void file_ui_draw(uint16_t i, uint16_t first, uint16_t selected, uint16_t entries) {
|
2020-09-02 00:13:25 +00:00
|
|
|
struct tabent *entry;
|
2020-09-03 01:37:39 +00:00
|
|
|
gotoxy(5, i - first + 6);
|
2020-09-02 03:46:43 +00:00
|
|
|
if (i < entries) {
|
2020-09-02 00:13:25 +00:00
|
|
|
entry = (struct tabent*)iobuf + i;
|
2020-09-02 23:51:44 +00:00
|
|
|
if (entry->type == 0x0f) {
|
|
|
|
sprintf(userentry, "[ %s ] ", entry->name);
|
|
|
|
userentry[34] = '\0';
|
|
|
|
} else {
|
|
|
|
sprintf(userentry, " %s ", entry->name);
|
|
|
|
sprintf(&userentry[18], " %8lu ", entry->size);
|
|
|
|
switch (entry->type) {
|
|
|
|
case 0x04:
|
|
|
|
sprintf(&userentry[30], "TXT ");
|
|
|
|
break;
|
|
|
|
case 0x06:
|
|
|
|
sprintf(&userentry[30], "BIN ");
|
|
|
|
break;
|
|
|
|
case 0x19:
|
|
|
|
sprintf(&userentry[30], "ADB ");
|
|
|
|
break;
|
|
|
|
case 0x1a:
|
|
|
|
sprintf(&userentry[30], "AWP ");
|
|
|
|
break;
|
|
|
|
case 0x1b:
|
|
|
|
sprintf(&userentry[30], "ASP ");
|
|
|
|
break;
|
|
|
|
case 0xfc:
|
|
|
|
sprintf(&userentry[30], "BAS ");
|
|
|
|
break;
|
|
|
|
case 0xff:
|
|
|
|
sprintf(&userentry[30], "SYS ");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(&userentry[30], "$%02x ", entry->type);
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 00:13:25 +00:00
|
|
|
if (i == selected)
|
|
|
|
revers(1);
|
|
|
|
cputs(userentry);
|
|
|
|
if (i == selected)
|
|
|
|
revers(0);
|
2020-09-02 03:46:43 +00:00
|
|
|
} else {
|
2020-09-02 23:51:44 +00:00
|
|
|
strcpy(userentry, " ");
|
2020-09-02 03:46:43 +00:00
|
|
|
cputs(userentry);
|
2020-09-02 00:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File chooser UI
|
2020-09-02 20:23:53 +00:00
|
|
|
* first - index of first file on screen
|
|
|
|
* selected - index of currently selected file
|
|
|
|
* entries - total number of file entries in directory
|
2020-09-02 00:13:25 +00:00
|
|
|
*/
|
2020-09-02 03:46:43 +00:00
|
|
|
void file_ui_draw_all(uint16_t first, uint16_t selected, uint16_t entries) {
|
|
|
|
uint16_t i;
|
|
|
|
uint16_t last = first + FILELINES;
|
|
|
|
for (i = first; i < last; ++i)
|
|
|
|
file_ui_draw(i, first, selected, entries);
|
|
|
|
}
|
|
|
|
|
2020-09-02 22:11:38 +00:00
|
|
|
/*
|
|
|
|
* Perform ProDOS MLI ON_LINE call to
|
|
|
|
* write all online volume names into iobuf[]
|
|
|
|
* Return the number of entries
|
|
|
|
*/
|
|
|
|
uint16_t online(void) {
|
|
|
|
uint16_t entries = 0;
|
|
|
|
struct tabent *entry;
|
|
|
|
uint8_t i, j, len;
|
|
|
|
__asm__("lda #$00"); // All devices
|
|
|
|
__asm__("sta mliparam + 1");
|
|
|
|
__asm__("lda #<%v", iobuf); // iobuf LSB
|
|
|
|
__asm__("sta mliparam + 2");
|
|
|
|
__asm__("lda #>%v", iobuf); // iobuf MSB
|
|
|
|
__asm__("ina"); // Bump up 256 bytes into iobuf
|
|
|
|
__asm__("sta mliparam + 3");
|
|
|
|
__asm__("lda #$c5"); // ON_LINE
|
|
|
|
__asm__("ldx #$02"); // Two parms
|
|
|
|
__asm__("jsr callmli");
|
|
|
|
entry = (struct tabent*)iobuf;
|
|
|
|
for (i = 0; i < 16; ++i) {
|
|
|
|
len = iobuf[256 + i * 16] & 0x0f;
|
|
|
|
if (len > 0) {
|
|
|
|
entry->type = 0x0f;
|
|
|
|
entry->name[0] = '/';
|
|
|
|
for (j = 0; j < len; ++j)
|
|
|
|
entry->name[j + 1] = iobuf[256 + i * 16 + j + 1];
|
|
|
|
entry->name[j + 1] = '\0';
|
|
|
|
++entry;
|
|
|
|
++entries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2020-09-02 03:46:43 +00:00
|
|
|
/*
|
|
|
|
* File chooser UI
|
|
|
|
* Leaves file name in userentry[], or empty string if error/cancel
|
2020-09-02 20:23:53 +00:00
|
|
|
* msg1 - Message for top line
|
|
|
|
* msg2 - Message for second line
|
2020-09-03 01:37:39 +00:00
|
|
|
* msg3 - Message for third line
|
2020-09-02 03:46:43 +00:00
|
|
|
*/
|
2020-09-03 01:37:39 +00:00
|
|
|
void file_ui(char *msg1, char *msg2, char *msg3) {
|
2020-09-02 00:13:25 +00:00
|
|
|
struct tabent *entry;
|
|
|
|
DIR *dp;
|
|
|
|
struct dirent *ent;
|
|
|
|
char c;
|
2020-09-02 01:01:39 +00:00
|
|
|
uint16_t entries, current, first;
|
2020-09-02 22:11:38 +00:00
|
|
|
uint8_t toplevel = 0;
|
2020-09-02 01:01:39 +00:00
|
|
|
restart:
|
2020-09-02 03:46:43 +00:00
|
|
|
clrscr();
|
|
|
|
gotoxy(0,0);
|
|
|
|
revers(1);
|
2020-09-02 20:23:53 +00:00
|
|
|
cprintf("%s", msg1);
|
2020-09-02 03:46:43 +00:00
|
|
|
revers(0);
|
2020-09-02 20:23:53 +00:00
|
|
|
gotoxy(0,1);
|
|
|
|
cprintf("%s", msg2);
|
2020-09-03 01:37:39 +00:00
|
|
|
gotoxy(0,2);
|
|
|
|
cprintf("%s", msg3);
|
2020-09-02 22:42:00 +00:00
|
|
|
getcwd(userentry, 80);
|
2020-09-03 01:37:39 +00:00
|
|
|
gotoxy(0,4);
|
2020-09-02 20:23:53 +00:00
|
|
|
revers(1);
|
2020-09-02 22:11:38 +00:00
|
|
|
cprintf("%s", (toplevel ? "Volumes" : userentry));
|
2020-09-02 20:23:53 +00:00
|
|
|
revers(0);
|
2020-09-02 01:01:39 +00:00
|
|
|
entries = current = first = 0;
|
2020-09-02 00:13:25 +00:00
|
|
|
cutbuflen = 0;
|
2020-09-02 22:11:38 +00:00
|
|
|
if (toplevel) {
|
|
|
|
entries = online();
|
|
|
|
} else {
|
|
|
|
entry = (struct tabent*)iobuf;
|
|
|
|
strcpy(entry->name, ".."); // Add fake '..' entry
|
|
|
|
entry->type = 0x0f;
|
2020-09-02 00:13:25 +00:00
|
|
|
++entry;
|
|
|
|
++entries;
|
2020-09-02 22:11:38 +00:00
|
|
|
cursor(0);
|
|
|
|
dp = opendir(".");
|
|
|
|
while (1) {
|
|
|
|
ent = readdir(dp);
|
|
|
|
if (!ent)
|
|
|
|
break;
|
|
|
|
memcpy(entry->name, ent->d_name, 16);
|
|
|
|
entry->type = ent->d_type;
|
2020-09-02 23:51:44 +00:00
|
|
|
entry->size = ent->d_size;
|
2020-09-02 22:11:38 +00:00
|
|
|
++entry;
|
|
|
|
++entries;
|
2020-09-02 23:51:44 +00:00
|
|
|
if ((char*)entry > (char*)iobuf + CUTBUFSZ - 100) {
|
|
|
|
beep();
|
|
|
|
break;
|
|
|
|
}
|
2020-09-02 22:11:38 +00:00
|
|
|
}
|
|
|
|
closedir(dp);
|
2020-09-02 00:13:25 +00:00
|
|
|
}
|
2020-09-02 03:46:43 +00:00
|
|
|
redraw:
|
|
|
|
file_ui_draw_all(first, current, entries);
|
2020-09-02 00:13:25 +00:00
|
|
|
while (1) {
|
|
|
|
c = cgetc();
|
|
|
|
switch (c) {
|
|
|
|
case 0x0b: // Up
|
|
|
|
if (current > 0)
|
|
|
|
--current;
|
|
|
|
if (current < first) {
|
|
|
|
if (first > FILELINES)
|
|
|
|
first -= FILELINES;
|
|
|
|
else
|
|
|
|
first = 0;
|
2020-09-02 03:46:43 +00:00
|
|
|
goto redraw;
|
2020-09-02 00:13:25 +00:00
|
|
|
}
|
2020-09-02 03:46:43 +00:00
|
|
|
file_ui_draw(current, first, current, entries);
|
|
|
|
file_ui_draw(current + 1, first, current, entries);
|
2020-09-02 00:13:25 +00:00
|
|
|
break;
|
|
|
|
case 0x0a: // Down
|
2020-09-02 03:46:43 +00:00
|
|
|
if (current < entries - 1)
|
2020-09-02 00:13:25 +00:00
|
|
|
++current;
|
|
|
|
if (current >= first + FILELINES) {
|
|
|
|
first += FILELINES;
|
2020-09-02 03:46:43 +00:00
|
|
|
goto redraw;
|
2020-09-02 00:13:25 +00:00
|
|
|
}
|
2020-09-02 03:46:43 +00:00
|
|
|
file_ui_draw(current - 1, first, current, entries);
|
|
|
|
file_ui_draw(current, first, current, entries);
|
2020-09-02 00:13:25 +00:00
|
|
|
break;
|
|
|
|
case EOL:
|
|
|
|
entry = (struct tabent*)iobuf + current;
|
2020-09-02 01:01:39 +00:00
|
|
|
switch (entry->type) {
|
|
|
|
case 0x0f: // Directory
|
2020-09-02 22:42:00 +00:00
|
|
|
getcwd(userentry, 80);
|
2020-09-02 01:01:39 +00:00
|
|
|
if (strcmp(entry->name, "..") == 0) {
|
|
|
|
for (c = strlen(userentry); c > 0; --c)
|
|
|
|
if (userentry[c] == '/') {
|
|
|
|
userentry[c] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2020-09-02 22:11:38 +00:00
|
|
|
if (c <= 1)
|
|
|
|
toplevel = 1;
|
|
|
|
else
|
|
|
|
chdir(userentry);
|
2020-09-02 01:01:39 +00:00
|
|
|
goto restart;
|
|
|
|
} else {
|
2020-09-02 22:11:38 +00:00
|
|
|
if (toplevel) {
|
|
|
|
strcpy(userentry, entry->name);
|
|
|
|
chdir(userentry);
|
|
|
|
} else {
|
2020-09-02 22:42:00 +00:00
|
|
|
getcwd(userentry, 80);
|
2020-09-02 22:11:38 +00:00
|
|
|
strcat(userentry, "/");
|
|
|
|
strcat(userentry, entry->name);
|
|
|
|
chdir(userentry);
|
|
|
|
}
|
|
|
|
toplevel = 0;
|
2020-09-02 01:01:39 +00:00
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x04: // ASCII text
|
2020-09-02 03:46:43 +00:00
|
|
|
strcpy(userentry, entry->name);
|
2020-09-02 01:01:39 +00:00
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
default:
|
2020-09-02 22:42:00 +00:00
|
|
|
if (prompt_okay("Not a text file, open anyhow") != 0) {
|
2020-09-02 03:46:43 +00:00
|
|
|
strcpy(userentry, "");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
strcpy(userentry, entry->name);
|
2020-09-02 01:01:39 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2020-09-02 03:46:43 +00:00
|
|
|
break;
|
2020-09-02 00:13:25 +00:00
|
|
|
case ESC:
|
2020-09-02 03:46:43 +00:00
|
|
|
strcpy(userentry, "");
|
|
|
|
goto done;
|
|
|
|
break;
|
2020-09-03 01:37:39 +00:00
|
|
|
case 0x09: // Tab
|
2020-09-02 03:46:43 +00:00
|
|
|
if (prompt_for_name("Enter filename", 0) == 255)
|
|
|
|
goto restart; // ESC pressed
|
|
|
|
if (userentry[0] == '/') // Absolute path
|
|
|
|
goto done;
|
2020-09-02 22:42:00 +00:00
|
|
|
getcwd(replace, 80); // Otherwise relative path
|
2020-09-02 03:46:43 +00:00
|
|
|
strcat(replace, "/");
|
|
|
|
strcat(replace, userentry);
|
|
|
|
strcpy(userentry, replace);
|
|
|
|
strcpy(replace, "");
|
2020-09-02 01:01:39 +00:00
|
|
|
goto done;
|
2020-09-02 00:13:25 +00:00
|
|
|
}
|
2020-09-02 01:01:39 +00:00
|
|
|
}
|
|
|
|
done:
|
2020-09-02 03:46:43 +00:00
|
|
|
clrscr();
|
2020-09-02 01:01:39 +00:00
|
|
|
cursor(1);
|
2020-09-02 00:13:25 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 21:21:59 +00:00
|
|
|
/*
|
|
|
|
* Main editor routine
|
2020-08-17 14:45:52 +00:00
|
|
|
* fname - filename to open or ""
|
2020-07-15 21:21:59 +00:00
|
|
|
*/
|
2020-07-16 23:16:59 +00:00
|
|
|
int edit(char *fname) {
|
2020-08-07 03:42:52 +00:00
|
|
|
char c;
|
2020-08-13 19:46:16 +00:00
|
|
|
uint16_t position, tmp;
|
2020-08-13 03:11:11 +00:00
|
|
|
uint8_t i, ask;
|
2020-07-12 21:34:11 +00:00
|
|
|
videomode(VIDEOMODE_80COL);
|
2020-07-16 23:16:59 +00:00
|
|
|
if (fname) {
|
|
|
|
strcpy(filename, fname);
|
2020-07-19 21:53:49 +00:00
|
|
|
cprintf("Loading file %s ", filename);
|
2020-08-17 14:45:52 +00:00
|
|
|
if (load_file(filename, 1, 0)) {
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "Can't load '%s'", filename);
|
2020-07-16 21:38:37 +00:00
|
|
|
show_error(userentry);
|
2020-07-19 05:25:29 +00:00
|
|
|
strcpy(filename, "");
|
2020-07-16 04:00:34 +00:00
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
draw_screen();
|
|
|
|
while (1) {
|
2020-07-16 04:00:34 +00:00
|
|
|
cursor(1);
|
2020-07-12 21:34:11 +00:00
|
|
|
c = cgetc();
|
2020-08-02 00:29:19 +00:00
|
|
|
if (mode == SRCH3) // Reset 'Not found'
|
|
|
|
mode = SEL_NONE;
|
2020-07-12 21:34:11 +00:00
|
|
|
switch (c) {
|
2020-08-04 23:54:38 +00:00
|
|
|
case ESC: // Escape from block mode operations
|
|
|
|
startsel = endsel = 65535U;
|
|
|
|
mode = SEL_NONE;
|
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-07-18 02:33:25 +00:00
|
|
|
case 0x80 + '1': // Top
|
|
|
|
jump_pos(0);
|
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '2':
|
|
|
|
jump_pos(DATASIZE() / 8);
|
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '3':
|
2020-08-07 02:14:26 +00:00
|
|
|
jump_pos(2L * DATASIZE() / 8);
|
2020-07-18 02:33:25 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '4':
|
2020-08-07 02:14:26 +00:00
|
|
|
jump_pos(3L * DATASIZE() / 8);
|
2020-07-18 02:33:25 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '5':
|
2020-08-07 02:14:26 +00:00
|
|
|
jump_pos(4L * DATASIZE() / 8);
|
2020-07-18 02:33:25 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '6':
|
2020-08-07 02:14:26 +00:00
|
|
|
jump_pos(5L * DATASIZE() / 8);
|
2020-07-18 02:33:25 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '7':
|
2020-08-07 02:14:26 +00:00
|
|
|
jump_pos(6L * DATASIZE() / 8);
|
2020-07-18 02:33:25 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '8':
|
2020-08-07 02:14:26 +00:00
|
|
|
jump_pos(7L * DATASIZE() / 8);
|
2020-07-18 02:33:25 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + '9': // Bottom
|
|
|
|
jump_pos(DATASIZE());
|
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
case 0x80 + 0x08: // OA-Left "Word left"
|
|
|
|
word_left();
|
2020-07-12 21:34:11 +00:00
|
|
|
break;
|
2020-07-18 02:33:25 +00:00
|
|
|
case 0x80 + 0x15: // OA-Right "Word right"
|
|
|
|
word_right();
|
|
|
|
break;
|
|
|
|
case 0x80 + ',': // OA-< "Home"
|
|
|
|
case 0x80 + '<':
|
2020-08-10 04:41:54 +00:00
|
|
|
case 0x01: // Ctrl-A (Emacs style)
|
2020-07-18 02:33:25 +00:00
|
|
|
goto_bol();
|
2020-07-12 21:34:11 +00:00
|
|
|
break;
|
2020-07-18 02:33:25 +00:00
|
|
|
case 0x80 + '.': // OA-> "End"
|
|
|
|
case 0x80 + '>':
|
2020-08-10 04:41:54 +00:00
|
|
|
case 0x05: // Ctrl-E (Emacs style)
|
2020-07-12 21:34:11 +00:00
|
|
|
goto_eol();
|
2020-07-18 02:33:25 +00:00
|
|
|
break;
|
|
|
|
case 0x8b: // OA-Up "Page Up"
|
|
|
|
page_up();
|
2020-07-12 21:34:11 +00:00
|
|
|
break;
|
2020-07-16 04:00:34 +00:00
|
|
|
case 0x8a: // OA-Down "Page Down"
|
2020-07-12 21:34:11 +00:00
|
|
|
page_down();
|
2020-07-18 00:08:26 +00:00
|
|
|
break;
|
2020-08-10 04:41:54 +00:00
|
|
|
case 0x80 + ' ': // OA-SPACE start/end selection
|
2020-08-17 16:44:13 +00:00
|
|
|
tmp = (startsel == 65535U ? 0 : 1); // Prev selection active?
|
|
|
|
if (tmp) {
|
2020-08-10 04:41:54 +00:00
|
|
|
endsel = gapbegin;
|
|
|
|
mode = SEL_NONE;
|
|
|
|
draw_screen();
|
|
|
|
} else {
|
|
|
|
startsel = endsel = gapbegin;
|
2020-08-13 19:46:16 +00:00
|
|
|
mode = SEL_SELECT;
|
2020-08-10 04:41:54 +00:00
|
|
|
update_status_line();
|
|
|
|
}
|
|
|
|
break;
|
2020-08-17 15:43:51 +00:00
|
|
|
case 0x80 + 'A': // OA-A "Select All"
|
|
|
|
case 0x80 + 'a': // OA-a
|
|
|
|
startsel = 0;
|
|
|
|
endsel = DATASIZE();
|
|
|
|
mode = SEL_NONE;
|
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-08-11 00:05:18 +00:00
|
|
|
case 0x80 + 'X': // OA-X "Cut"
|
|
|
|
case 0x80 + 'x': // OA-x
|
2020-08-10 04:41:54 +00:00
|
|
|
case 0x18: // ^X "Cut"
|
2020-08-11 00:05:18 +00:00
|
|
|
tmp = 65535U;
|
|
|
|
case 0x80 + 'C': // OA-C "Copy"
|
|
|
|
case 0x80 + 'c': // OA-c
|
|
|
|
case 0x03: // ^C "Copy"
|
|
|
|
++tmp;
|
2020-08-10 04:57:10 +00:00
|
|
|
mode = SEL_NONE;
|
2020-08-11 00:05:18 +00:00
|
|
|
if (startsel == 65535U) { // No selection
|
2020-08-10 17:02:19 +00:00
|
|
|
beep();
|
|
|
|
break;
|
|
|
|
}
|
2020-08-10 04:41:54 +00:00
|
|
|
order_selection();
|
2020-08-13 19:46:16 +00:00
|
|
|
position = gapbegin;
|
|
|
|
if (endsel - startsel <= CUTBUFSZ) {
|
|
|
|
cutbuflen = endsel - startsel;
|
|
|
|
jump_pos(startsel);
|
2020-08-13 20:08:51 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-09-06 20:47:03 +00:00
|
|
|
copyaux((char*)GAPBUFADDR + gapend + 1, iobuf, cutbuflen, FROMAUX);
|
2020-08-13 20:08:51 +00:00
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-08-13 19:46:16 +00:00
|
|
|
} else {
|
|
|
|
cutbuflen = 0;
|
|
|
|
if (save_file(1, 0) == 1) {
|
|
|
|
show_error("Can't save CLIPBOARD");
|
|
|
|
draw_screen();
|
|
|
|
break;
|
|
|
|
}
|
2020-08-10 04:41:54 +00:00
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
if (tmp == 0) { // Cut
|
2020-09-01 01:17:30 +00:00
|
|
|
mark_undo();
|
2020-08-10 04:41:54 +00:00
|
|
|
jump_pos(startsel);
|
|
|
|
gapend += (endsel - startsel);
|
|
|
|
set_modified(1);
|
2020-08-13 19:46:16 +00:00
|
|
|
} else // Copy
|
|
|
|
jump_pos(position);
|
2020-08-10 04:41:54 +00:00
|
|
|
startsel = endsel = 65535U;
|
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-08-11 00:05:18 +00:00
|
|
|
case 0x80 + 'V': // OA-V "Paste"
|
|
|
|
case 0x80 + 'v': // OA-v
|
2020-08-10 04:41:54 +00:00
|
|
|
case 0x16: // ^V "Paste"
|
2020-08-10 04:57:10 +00:00
|
|
|
mode = SEL_NONE;
|
2020-09-01 01:17:30 +00:00
|
|
|
mark_undo();
|
2020-08-13 19:46:16 +00:00
|
|
|
if (cutbuflen > 0) {
|
2020-08-13 20:08:51 +00:00
|
|
|
__asm__("lda %v", auxbank);
|
|
|
|
__asm__("sta $c073"); // Set aux bank
|
2020-09-06 20:47:03 +00:00
|
|
|
copyaux(iobuf, (char*)GAPBUFADDR + gapbegin, cutbuflen, TOAUX);
|
2020-08-13 20:08:51 +00:00
|
|
|
__asm__("lda #$00");
|
|
|
|
__asm__("sta $c073"); // Set aux bank back to 0
|
2020-08-13 19:46:16 +00:00
|
|
|
gapbegin += cutbuflen;
|
|
|
|
} else {
|
2020-08-17 14:45:52 +00:00
|
|
|
if (load_file("CLIPBOARD", 0, 1))
|
2020-08-13 19:46:16 +00:00
|
|
|
show_error("Can't open CLIPBOARD");
|
|
|
|
}
|
2020-08-10 04:41:54 +00:00
|
|
|
startsel = endsel = 65535U;
|
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-07-18 06:09:14 +00:00
|
|
|
case 0x80 + 'R': // OA-R "Replace"
|
|
|
|
case 0x80 + 'r': // OA-r
|
|
|
|
tmp = 65535U;
|
2020-07-18 04:59:35 +00:00
|
|
|
case 0x80 + 'F': // OA-F "Find"
|
|
|
|
case 0x80 + 'f': // OA-F "Find"
|
2020-07-18 06:09:14 +00:00
|
|
|
++tmp;
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "Find (%s)", search);
|
2020-07-19 15:15:57 +00:00
|
|
|
if (prompt_for_name(userentry, 0) == 255)
|
|
|
|
break; // ESC pressed
|
|
|
|
if (strlen(userentry) > 0)
|
2020-07-18 05:22:33 +00:00
|
|
|
strcpy(search, userentry);
|
2020-08-09 19:32:58 +00:00
|
|
|
else if (strlen(search) == 0)
|
|
|
|
break;
|
|
|
|
cursor_right();
|
2020-07-19 05:25:29 +00:00
|
|
|
if (tmp == 0) { // Replace mode
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "Replace (%s)", replace);
|
2020-07-19 15:15:57 +00:00
|
|
|
if (prompt_for_name(userentry, 0) == 255)
|
|
|
|
break; // ESC pressed
|
|
|
|
if (strlen(userentry) > 0)
|
2020-07-19 05:25:29 +00:00
|
|
|
strcpy(replace, userentry);
|
2020-08-09 19:32:58 +00:00
|
|
|
else if (strlen(replace) == 0)
|
|
|
|
break;
|
2020-08-09 06:37:25 +00:00
|
|
|
ask = 0;
|
|
|
|
if (prompt_okay("Ask for each") == 0)
|
|
|
|
ask = 1;
|
2020-09-01 01:17:30 +00:00
|
|
|
canundo = 0;
|
2020-07-19 05:25:29 +00:00
|
|
|
}
|
2020-08-09 06:37:25 +00:00
|
|
|
do_search_replace(tmp, ask);
|
2020-08-09 19:32:58 +00:00
|
|
|
update_status_line();
|
2020-07-18 04:59:35 +00:00
|
|
|
break;
|
2020-07-25 01:30:16 +00:00
|
|
|
case 0x80 + 'I': // OA-I "Insert file"
|
|
|
|
case 0x80 + 'i':
|
2020-09-03 01:37:39 +00:00
|
|
|
file_ui("Insert File at Cursor", "", openfilemsg);
|
2020-09-02 03:46:43 +00:00
|
|
|
if (strlen(userentry) == 0) {
|
|
|
|
draw_screen();
|
2020-08-01 05:24:38 +00:00
|
|
|
break;
|
2020-09-02 03:46:43 +00:00
|
|
|
}
|
2020-09-01 01:17:30 +00:00
|
|
|
mark_undo();
|
2020-08-17 14:45:52 +00:00
|
|
|
if (load_file(userentry, 0, 0)) {
|
2020-08-17 02:46:47 +00:00
|
|
|
snprintf(iobuf, 80, "Can't open '%s'", userentry);
|
|
|
|
show_error(iobuf);
|
|
|
|
}
|
2020-08-01 05:24:38 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-08-14 05:03:45 +00:00
|
|
|
case 0x80 + 'O': // OA-O "Open"
|
|
|
|
case 0x80 + 'o':
|
2020-09-04 02:49:21 +00:00
|
|
|
if (status[0]) { // Buffer is modified
|
|
|
|
if (strlen(filename) == 0)
|
|
|
|
strcpy(userentry, "Save <scratch> buffer");
|
|
|
|
else
|
|
|
|
snprintf(userentry, 80, "Save '%s'", filename);
|
|
|
|
if (prompt_okay(userentry) == 0)
|
|
|
|
save();
|
|
|
|
}
|
2020-09-03 01:37:39 +00:00
|
|
|
file_ui("Open File", "", openfilemsg);
|
2020-09-02 03:46:43 +00:00
|
|
|
if (strlen(userentry) == 0) {
|
|
|
|
draw_screen();
|
2020-07-19 15:15:57 +00:00
|
|
|
break;
|
2020-09-02 03:46:43 +00:00
|
|
|
}
|
2020-07-16 21:38:37 +00:00
|
|
|
strcpy(filename, userentry);
|
2020-08-17 14:45:52 +00:00
|
|
|
if (load_file(filename, 1, 0)) {
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "Can't open '%s'", filename);
|
2020-07-16 21:38:37 +00:00
|
|
|
show_error(userentry);
|
2020-07-19 16:25:55 +00:00
|
|
|
strcpy(filename, "");
|
2020-07-16 21:38:37 +00:00
|
|
|
}
|
2020-09-01 01:17:30 +00:00
|
|
|
canundo = 0;
|
2020-07-17 21:30:16 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-07-19 04:01:59 +00:00
|
|
|
case 0x80 + 'N': // OA-N "Name"
|
2020-07-16 21:38:37 +00:00
|
|
|
case 0x80 + 'n': // OA-n
|
2020-08-13 03:11:11 +00:00
|
|
|
name_file();
|
2020-07-16 21:38:37 +00:00
|
|
|
break;
|
|
|
|
case 0x80 + 'Q': // OA-Q "Quit"
|
|
|
|
case 0x80 + 'q': // OA-q
|
2020-08-11 20:29:26 +00:00
|
|
|
save_all();
|
2020-09-03 22:58:47 +00:00
|
|
|
switch (email_mode) {
|
|
|
|
case 2:
|
2020-08-09 06:37:25 +00:00
|
|
|
if (prompt_okay("Add attachments") == 0)
|
2020-07-28 21:14:43 +00:00
|
|
|
load_attacher();
|
2020-09-03 22:58:47 +00:00
|
|
|
// Fall through
|
|
|
|
case 1:
|
2020-08-09 06:37:25 +00:00
|
|
|
if (prompt_okay("Quit to EMAIL") == 0)
|
2020-07-16 21:38:37 +00:00
|
|
|
load_email();
|
2020-09-03 22:58:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-08-09 06:37:25 +00:00
|
|
|
if (prompt_okay("Quit to ProDOS") == 0) {
|
2020-07-16 21:38:37 +00:00
|
|
|
revers(0);
|
|
|
|
clrscr();
|
2020-09-06 20:47:03 +00:00
|
|
|
reconnect_ramdisk();
|
2020-07-16 21:38:37 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
break;
|
2020-08-01 19:38:56 +00:00
|
|
|
case 0x80 + 'U': // OA-U "Unwrap"
|
|
|
|
case 0x80 + 'u': // OA-w
|
2020-09-01 01:17:30 +00:00
|
|
|
canundo = 0;
|
2020-08-01 19:38:56 +00:00
|
|
|
word_wrap_para(0);
|
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-08-01 05:53:56 +00:00
|
|
|
case 0x80 + 'W': // OA-W "Wrap"
|
|
|
|
case 0x80 + 'w': // OA-w
|
2020-09-01 01:17:30 +00:00
|
|
|
canundo = 0;
|
2020-08-01 19:38:56 +00:00
|
|
|
word_wrap_para(1);
|
2020-08-01 05:53:56 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-07-16 21:38:37 +00:00
|
|
|
case 0x80 + 'S': // OA-S "Save"
|
|
|
|
case 0x80 + 's': // OA-s
|
2020-07-18 05:45:36 +00:00
|
|
|
save();
|
2020-07-19 21:53:49 +00:00
|
|
|
draw_screen();
|
2020-07-15 21:56:40 +00:00
|
|
|
break;
|
2020-09-01 01:17:30 +00:00
|
|
|
case 0x80 + 'Z': // OA-Z "Undo"
|
|
|
|
case 0x80 + 'z': // OA-z
|
|
|
|
case 0x1a: // Ctrl-Z
|
|
|
|
if (canundo) {
|
2020-09-01 03:35:55 +00:00
|
|
|
tmp = gapbegin;
|
|
|
|
gapbegin = oldgapbegin;
|
|
|
|
oldgapbegin = tmp;
|
|
|
|
tmp = gapend;
|
|
|
|
gapend = oldgapend;
|
|
|
|
oldgapend = tmp;
|
2020-09-01 01:17:30 +00:00
|
|
|
draw_screen();
|
|
|
|
} else
|
|
|
|
beep();
|
|
|
|
break;
|
2020-07-16 21:38:37 +00:00
|
|
|
case 0x80 + DELETE: // OA-Backspace
|
2020-07-16 04:00:34 +00:00
|
|
|
case 0x04: // Ctrl-D "DELETE"
|
2020-07-18 00:08:26 +00:00
|
|
|
if (mode == SEL_NONE) {
|
2020-09-01 16:30:52 +00:00
|
|
|
mark_undo();
|
2020-07-18 00:08:26 +00:00
|
|
|
delete_char_right();
|
|
|
|
update_after_delete_char_right();
|
2020-08-02 00:29:19 +00:00
|
|
|
set_modified(1);
|
2020-07-18 00:08:26 +00:00
|
|
|
}
|
2020-07-16 00:46:43 +00:00
|
|
|
break;
|
2020-07-18 04:03:27 +00:00
|
|
|
case 0x80 + '?': // OA-? "Help"
|
2020-08-14 03:21:42 +00:00
|
|
|
help1:
|
|
|
|
help(1);
|
|
|
|
c = cgetc();
|
2020-09-03 00:48:36 +00:00
|
|
|
if (c == ESC)
|
2020-08-14 03:21:42 +00:00
|
|
|
goto donehelp;
|
|
|
|
help(2);
|
|
|
|
c = cgetc();
|
|
|
|
switch (c) {
|
|
|
|
case 0x0b: // Up
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
|
|
|
goto help1;
|
|
|
|
}
|
|
|
|
donehelp:
|
2020-07-18 04:03:27 +00:00
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-07-16 04:00:34 +00:00
|
|
|
case 0x0c: // Ctrl-L "REFRESH"
|
|
|
|
draw_screen();
|
2020-07-12 21:34:11 +00:00
|
|
|
break;
|
2020-07-16 21:38:37 +00:00
|
|
|
case DELETE: // DEL "BACKSPACE"
|
2020-08-23 23:49:30 +00:00
|
|
|
if (startsel == 65535U) { // No selection
|
|
|
|
if (mode == SEL_NONE) {
|
2020-09-01 16:30:52 +00:00
|
|
|
mark_undo();
|
2020-08-23 23:49:30 +00:00
|
|
|
delete_char();
|
|
|
|
update_after_delete_char();
|
|
|
|
set_modified(1);
|
2020-08-10 21:15:39 +00:00
|
|
|
}
|
2020-08-23 23:49:30 +00:00
|
|
|
} else {
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80,
|
|
|
|
"Delete selection (%d chars)", abs(endsel - startsel));
|
2020-08-10 21:15:39 +00:00
|
|
|
if (prompt_okay(userentry) != 0)
|
|
|
|
break;
|
|
|
|
order_selection();
|
|
|
|
mode = SEL_NONE;
|
2020-09-01 01:17:30 +00:00
|
|
|
mark_undo();
|
2020-08-10 21:15:39 +00:00
|
|
|
jump_pos(startsel);
|
|
|
|
gapend += (endsel - startsel);
|
|
|
|
set_modified(1);
|
|
|
|
startsel = endsel = 65535U;
|
|
|
|
draw_screen();
|
|
|
|
break;
|
2020-07-18 00:08:26 +00:00
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
break;
|
2020-07-12 23:05:25 +00:00
|
|
|
case 0x09: // Tab
|
2020-07-18 00:08:26 +00:00
|
|
|
if (mode == SEL_NONE) {
|
2020-09-01 16:30:52 +00:00
|
|
|
mark_undo();
|
2020-07-18 00:08:26 +00:00
|
|
|
c = next_tabstop(curscol) - curscol;
|
|
|
|
for (i = 0; i < c; ++i) {
|
|
|
|
insert_char(' ');
|
|
|
|
update_after_insert_char();
|
|
|
|
}
|
2020-08-02 00:29:19 +00:00
|
|
|
set_modified(1);
|
2020-07-12 23:05:25 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-07-16 04:00:34 +00:00
|
|
|
case 0x08: // Left
|
|
|
|
cursor_left();
|
|
|
|
break;
|
2020-07-12 21:34:11 +00:00
|
|
|
case 0x15: // Right
|
|
|
|
cursor_right();
|
|
|
|
break;
|
|
|
|
case 0x0b: // Up
|
|
|
|
cursor_up();
|
|
|
|
break;
|
|
|
|
case 0x0a: // Down
|
|
|
|
cursor_down();
|
|
|
|
break;
|
2020-07-17 21:30:16 +00:00
|
|
|
case EOL: // Return
|
2020-08-24 01:38:18 +00:00
|
|
|
if (mode == SEL_NONE) {
|
2020-09-01 16:30:52 +00:00
|
|
|
mark_undo();
|
2020-07-18 00:08:26 +00:00
|
|
|
insert_char(c);
|
|
|
|
update_after_insert_char();
|
2020-08-02 00:29:19 +00:00
|
|
|
set_modified(1);
|
2020-08-11 00:05:18 +00:00
|
|
|
}
|
2020-07-17 21:30:16 +00:00
|
|
|
break;
|
2020-07-12 21:34:11 +00:00
|
|
|
default:
|
2020-08-10 19:34:18 +00:00
|
|
|
if (*(uint8_t*)0xc062 & 0x80) { // Closed Apple depressed
|
|
|
|
// CA-number (1-9) - quick jump to first 9 buffers
|
|
|
|
if ((c >= '1') && (c <= '9')) {
|
|
|
|
change_aux_bank(c - '0');
|
2020-08-11 20:29:26 +00:00
|
|
|
startsel = endsel = 65535U;
|
|
|
|
draw_screen();
|
|
|
|
} else if ((c == 'B') || (c == 'b')) { // CA-B "Buffer"
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80, "Buffer # (1 - %u)", banktbl[0]);
|
2020-08-14 04:10:38 +00:00
|
|
|
if (prompt_for_name(userentry, 0) == 255) {
|
|
|
|
update_status_line();
|
2020-08-11 00:05:18 +00:00
|
|
|
break;
|
2020-08-14 04:10:38 +00:00
|
|
|
}
|
|
|
|
if (strlen(userentry) == 0) {
|
|
|
|
update_status_line();
|
2020-08-11 00:05:18 +00:00
|
|
|
break;
|
2020-08-14 04:10:38 +00:00
|
|
|
}
|
2020-08-11 00:05:18 +00:00
|
|
|
tmp = atoi(userentry);
|
2020-08-14 05:19:21 +00:00
|
|
|
if ((tmp < 1) || (tmp > banktbl[0])) {
|
2020-08-11 00:05:18 +00:00
|
|
|
beep();
|
2020-08-14 04:10:38 +00:00
|
|
|
update_status_line();
|
2020-08-11 00:05:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
change_aux_bank(tmp);
|
2020-08-11 20:29:26 +00:00
|
|
|
startsel = endsel = 65535U;
|
|
|
|
draw_screen();
|
2020-09-03 00:48:36 +00:00
|
|
|
} else if ((c == '-') || (c == '_')) { // CA-minus
|
|
|
|
tmp = (l_auxbank - 2) % banktbl[0] + 1;
|
2020-09-02 20:23:53 +00:00
|
|
|
change_aux_bank(tmp);
|
|
|
|
startsel = endsel = 65535U;
|
|
|
|
draw_screen();
|
2020-09-03 00:48:36 +00:00
|
|
|
} else if ((c == '+') || (c == '=')) { // CA-plus
|
|
|
|
tmp = l_auxbank % banktbl[0] + 1;
|
|
|
|
change_aux_bank(tmp);
|
2020-09-02 20:23:53 +00:00
|
|
|
startsel = endsel = 65535U;
|
|
|
|
draw_screen();
|
2020-08-13 00:59:36 +00:00
|
|
|
} else if ((c == 'E') || (c == 'e')) { // CA-E "Extend file"
|
|
|
|
i = status[2];
|
|
|
|
if (i == 0) // If this was single buf file, make it part 1
|
|
|
|
i = 1;
|
|
|
|
if (open_new_aux_bank(i) == 1) {
|
2020-08-16 21:19:23 +00:00
|
|
|
snprintf(userentry, 80,
|
2020-08-14 05:03:45 +00:00
|
|
|
"Buffer [%03u] not avail. Can't extend.", l_auxbank + 1);
|
2020-08-13 00:59:36 +00:00
|
|
|
show_error(userentry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
status[2] = i + 1;
|
|
|
|
draw_screen();
|
2020-08-11 20:29:26 +00:00
|
|
|
} else if ((c == 'L') || (c == 'l')) {
|
|
|
|
buffer_list();
|
|
|
|
draw_screen();
|
2020-08-13 00:59:36 +00:00
|
|
|
} else if ((c == 'T') || (c == 't')) { // CA-T "Truncate file"
|
|
|
|
if (prompt_okay("Truncate file here") == 0) {
|
2020-08-13 03:11:11 +00:00
|
|
|
tmp = l_auxbank;
|
2020-08-13 00:59:36 +00:00
|
|
|
gapend = BUFSZ - 1;
|
|
|
|
draw_screen();
|
2020-08-13 03:11:11 +00:00
|
|
|
if (status[2] > 0) { // If multipart
|
2020-08-13 03:17:54 +00:00
|
|
|
if (status[2] == 1) // Truncating in first bank
|
|
|
|
status[2] = 0; // Make it a singleton
|
2020-08-13 03:11:11 +00:00
|
|
|
change_aux_bank(++l_auxbank);
|
2020-08-13 00:59:36 +00:00
|
|
|
do {
|
|
|
|
gapbegin = 0;
|
|
|
|
gapend = BUFSZ - 1;
|
|
|
|
filename[0] = '\0';
|
2020-08-13 03:11:11 +00:00
|
|
|
i = status[2];
|
2020-08-13 00:59:36 +00:00
|
|
|
status[0] = status[1] = status[2] = 0;
|
2020-08-13 03:11:11 +00:00
|
|
|
change_aux_bank(++l_auxbank);
|
|
|
|
} while (status[2] == i + 1);
|
|
|
|
change_aux_bank(tmp);
|
2020-08-13 00:59:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-01 01:17:30 +00:00
|
|
|
set_modified(1);
|
|
|
|
canundo = 0;
|
2020-08-14 21:33:00 +00:00
|
|
|
} else if ((c =='S') || (c == 's')) { // CA-S "Save all"
|
|
|
|
save_all();
|
|
|
|
draw_screen();
|
2020-08-11 00:05:18 +00:00
|
|
|
}
|
2020-08-10 19:34:18 +00:00
|
|
|
}
|
2020-08-13 00:59:36 +00:00
|
|
|
else if ((c >= 0x20) && (c < 0x80) && (mode == SEL_NONE)) {
|
2020-09-01 16:30:52 +00:00
|
|
|
mark_undo();
|
2020-07-13 04:05:15 +00:00
|
|
|
insert_char(c);
|
|
|
|
update_after_insert_char();
|
2020-08-02 00:29:19 +00:00
|
|
|
set_modified(1);
|
2020-07-13 04:05:15 +00:00
|
|
|
}
|
2020-07-12 21:34:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 22:58:47 +00:00
|
|
|
/*
|
|
|
|
* Usage message
|
|
|
|
*/
|
|
|
|
void usage(void) {
|
|
|
|
printf("Usage: -EDIT.SYSTEM [filename.txt]");
|
|
|
|
printf(" or -EDIT.SYSTEM [-reademail|-compose] filename.txt");
|
2020-09-06 20:47:03 +00:00
|
|
|
reconnect_ramdisk();
|
2020-09-03 22:58:47 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-07-20 00:25:49 +00:00
|
|
|
void main(int argc, char *argv[]) {
|
2020-08-17 02:59:23 +00:00
|
|
|
uint8_t *pp = (uint8_t*)0xbf98;
|
|
|
|
if (!(*pp & 0x02)) {
|
|
|
|
printf("Need 80 cols");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((*pp & 0x30) != 0x30) {
|
|
|
|
printf("Need 128K");
|
|
|
|
return;
|
|
|
|
}
|
2020-08-17 02:46:47 +00:00
|
|
|
disconnect_ramdisk();
|
2020-08-09 23:36:46 +00:00
|
|
|
avail_aux_banks();
|
2020-08-09 22:16:59 +00:00
|
|
|
init_aux_banks();
|
2020-09-02 22:42:00 +00:00
|
|
|
getcwd(startdir, 80);
|
2020-09-03 22:58:47 +00:00
|
|
|
email_mode = 0;
|
|
|
|
switch (argc) {
|
|
|
|
case 3:
|
|
|
|
if (strcmp(argv[1], "-reademail") == 0)
|
|
|
|
email_mode = 1;
|
|
|
|
else if (strcmp(argv[1], "-compose") == 0)
|
|
|
|
email_mode = 2;
|
|
|
|
else
|
|
|
|
usage();
|
|
|
|
edit(argv[2]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (argv[1][0] == '-')
|
|
|
|
usage();
|
2020-07-16 00:15:57 +00:00
|
|
|
edit(argv[1]);
|
2020-09-03 22:58:47 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-16 00:15:57 +00:00
|
|
|
edit(NULL);
|
2020-09-03 22:58:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
2020-07-16 21:38:37 +00:00
|
|
|
}
|
2020-07-15 21:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|