Skip to content

Commit 4e9a80a

Browse files
Made nano/more keep currently selected colours; support pause after command in mc
1 parent 6b63b78 commit 4e9a80a

11 files changed

+157
-68
lines changed

bin/12amc.cfg

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Select video mode
22
mode 0
3-
# Select font (buffer ID or sys). Don't chang if omitted.
3+
# Select font (buffer ID or sys). Don't change if omitted.
44
#font sys
55
font 10
66
# Select colors for foreground, background and highlight.
@@ -17,4 +17,5 @@ edit nano %s &90000
1717
exec bas bbcbasic24 %s
1818
exec bbc bbcbasic24 %s
1919
exec 4th forth24 %s
20-
20+
# bmpb viewer will pause after displaying
21+
execp bmp bmpb %s

bin/12amc.hlp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
12AM COMMANDER
22

33
A Midnight Commander look-alike for Agon Light.
4-
v0.01 (c) 2024 L.C. Benschop.
4+
v0.02 (c) 2024 L.C. Benschop.
55

66
Keys used:
77

@@ -88,6 +88,10 @@ exec <ext> <commandline>
8888
This specifies the command that will be executed when pressing ENTER on a
8989
file with a specific extension.
9090

91+
execp <ext> <commandline>
92+
93+
Like exec, but it will pause after executing the command.
94+
9195
Any line starting with a # is a comment. Can be used to comment out all but
9296
one viewer or editor.
9397

bin/12amc.ovl

96 Bytes
Binary file not shown.

mc/src/display.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void display_init(void)
4848
23, 16, 1, 0, // Scroll protection.
4949
23, 0, 152, 0, // No actions from control keys.
5050
15, // No paged mode.
51-
18, 0, 15 // Graphics colour to white
51+
18, 0, // Graphics colour, still needs a byte
5252
};
5353

5454
/* set the mode */
@@ -61,6 +61,7 @@ void display_init(void)
6161
display_setattr(false,false);
6262
vdp_cursor_enable(false);
6363
mos_puts(&disp_str[0],sizeof disp_str, 0);
64+
putch(fgcol);
6465
time = getsysvar_time();
6566
while (getsysvar_time() == time) {
6667
}
@@ -98,7 +99,6 @@ void display_init(void)
9899
void display_finish(void)
99100
{
100101
static char disp_str[] = {
101-
17, 15, 17, 128, // colours back to white fg/black bg
102102
26, // Cancel text viewport
103103
12, // Clear screen
104104
23, 0, 192, 1, // Set logical coordinates.

mc/src/main.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ void cmd_reload_dir(void)
164164
struct {
165165
char *ext;
166166
char *cmdline;
167+
bool do_pause;
167168
} cmd_extensions[N_EXTENSIONS];
168169
unsigned int n_extensions;
169170

@@ -207,6 +208,7 @@ void read_cfg_file(void)
207208
{
208209
FILE * infile = fopen("/bin/12amc.cfg","r");
209210
char *p;
211+
bool do_pause;
210212
if (infile != 0) {
211213
while(my_fgets(cmdbuf, 256, infile) != NULL) {
212214
if (cmdbuf[0] == '\n' || cmdbuf[0] == '#') continue;
@@ -217,14 +219,17 @@ void read_cfg_file(void)
217219
strcpy(viewer_cmd,p);
218220
} else if (strcmp(pathbuf,"edit") == 0) {
219221
strcpy(editor_cmd,p);
220-
} else if (strcmp(pathbuf,"exec") == 0) {
222+
} else if (strcmp(pathbuf,"exec") == 0 || strcmp(pathbuf,"execp") == 0) {
223+
do_pause = strcmp(pathbuf,"execp") == 0;
221224
p = scan_word(pathbuf,p);
222225
while (*p++==' ')
223226
;
224227
p--;
225228
if (n_extensions < N_EXTENSIONS && strlen(pathbuf) != 0) {
226229
cmd_extensions[n_extensions].ext = strdup(pathbuf);
227230
cmd_extensions[n_extensions].cmdline = strdup(p);
231+
cmd_extensions[n_extensions].do_pause = do_pause;
232+
228233
n_extensions++;
229234
}
230235
} else if (strcmp(pathbuf,"mode") == 0) {
@@ -338,7 +343,7 @@ main(int argc, char *argv[])
338343
for (i=0; i<n_extensions; i++) {
339344
if (has_ext(pathbuf,cmd_extensions[i].ext)) {
340345
sprintf(cmdbuf, cmd_extensions[i].cmdline, pathbuf);
341-
execute_command(cmdbuf,false);
346+
execute_command(cmdbuf,cmd_extensions[i].do_pause);
342347
break;
343348
}
344349
}

more.asm

+39-6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ main_waitmode: BIT 4, (IX+sysvar_vpd_pflags)
5252
LD (prev_cr), A
5353
LD (current_col), A
5454
LD (num_lines), A
55+
LD A, 128
56+
CALL get_colour
57+
LD (fg_norm), A
58+
ADD A, 128
59+
LD (bg_inv), A
60+
LD A, 129
61+
CALL get_colour
62+
LD (fg_inv), A
63+
ADD A, 128
64+
LD (bg_norm), A
5565
; Load one byte per character.
5666
main_byte_loop:
5767
MOSCALL mos_feof
@@ -159,9 +169,10 @@ nl_nocrlf: XOR A
159169
LD (num_lines), A ; Clear line counter
160170
LD HL, c_MORE
161171
CALL PRCNTSTR ; Print More message
162-
@@: MOSCALL mos_getkey
172+
@@:
173+
MOSCALL mos_getkey
163174
AND A
164-
JR Z, @B
175+
JR Z, @B
165176
CP 'Q'
166177
JR Z, do_quit
167178
CP 'q'
@@ -181,14 +192,36 @@ do_quit: LD HL, c_CLEAR
181192
s_ERROR_SRC: DB " Cannot open source file\r\n", 0
182193
s_USAGE: DB " Usage: more <txtfile>\r\n", 0
183194
c_MORE: DB 16 ;String length
184-
DB 17, 0 ;foregrond black
185-
DB 17, 143 ; background white
195+
DB 17
196+
fg_inv: DB 0 ; foregrond reverse
197+
DB 17
198+
bg_inv: DB 0 ; background reverse
186199
DB "--More--"
187-
DB 17, 15 ; foreground white
188-
DB 17, 128 ; background black
200+
DB 17
201+
fg_norm: DB 0 ; foreground normal
202+
DB 17
203+
bg_norm: DB 0 ; background normal
189204
c_CLEAR: DB 10,13,32,32,32,32,32,32,32,32,13 ; Clear the --More-- output
190205
c_GETMODE: DB 4, 15, 23,0,vdp_mode ; Get screen mode parameters. Also switch off paged mode.
191206

207+
; Input A, index to get colour (128 = foreground, 129 = background).
208+
; output: A scolour index of fg or bg colour.
209+
get_colour: RES 2,(IX+sysvar_vpd_pflags)
210+
LD L, A
211+
LD A, 23
212+
RST.L 10h
213+
XOR A
214+
RST.L 10h
215+
LD A, 148
216+
RST.L 10h
217+
LD A, L
218+
RST.L 10h
219+
@@: BIT 2, (IX+sysvar_vpd_pflags)
220+
JR Z, @B ; Wait until received.
221+
LD A,(IX+sysvar_scrpixelIndex)
222+
RET
223+
224+
192225
current_col: DS 1 ; Current column on the screen.
193226
num_lines: DS 1 ; Number of lines printed since last pause
194227
prev_cr: DS 1 ; flag to indicate previous char was CR.

mos/more.bin

61 Bytes
Binary file not shown.

mos/nano.bin

683 Bytes
Binary file not shown.

nano.asm

+7-2
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ Next_AtEnd: POP HL
11201120
SCF
11211121
RET
11221122
; Move the combination of line addres and line number n lines forward in the text.
1123-
; Never go beyont the last line.
1123+
; Never go beyond the last line.
11241124
;
11251125
; Inputs: IX is the address of either cur_lineaddr or top_lineaddr
11261126
; BC is the number of lines to move forward (limited to 16 bits).
@@ -1904,7 +1904,7 @@ s_NAME: DB "Editor for Agon ",0
19041904
s_LINE: DB "Line ",0
19051905
s_HELP_Small: DB " bytes -- Esc to exit, Ctrl-G for help ",0
19061906

1907-
s_HELP_Large: DB 12, "Text editor for Agon v0.10, Copyright 2023-2024, L.C. Benschop\r\n"
1907+
s_HELP_Large: DB 12, "Text editor for Agon v0.11, Copyright 2023-2024, L.C. Benschop\r\n"
19081908
DB "\r\n"
19091909
DB "Cursor movement:\r\n"
19101910
DB "Ctrl-B or cursor left, Ctrl-F or cursor right\r\n"
@@ -1990,6 +1990,11 @@ file_modified: DS 1 ; Flag that tells if a file is modified.
19901990
cut_continue: DS 1 ; Flag to indicate that we want to continue cut/copy the next line and add to cut buffer.
19911991
save_sp: DS 3 ; Saved stack pointer for error return.
19921992
; The default Edit buffer is in the space between the end of the program and the top of the MOS command space.
1993+
current_fg: DS 1 ; Foreground colour.
1994+
current_bg: DS 1 ; Background colour.
19931995
default_buf:
1996+
; Initialization code can overlap with text buffer, no longer required
1997+
; after initialization.
1998+
include "scr_init.inc"
19941999
default_buf_end: EQU 0B8000h
19952000

output.inc

+28-53
Original file line numberDiff line numberDiff line change
@@ -74,47 +74,27 @@ Print_String: LD A,(HL)
7474
7575

7676
; Set display to inverse video
77-
Inverse_Video: LD HL, c_INVVID
78-
JR Print_CString
79-
77+
Inverse_Video: LD A, 17
78+
RST.L 10h
79+
LD A, (current_bg)
80+
RST.L 10h
81+
LD A, 17
82+
RST.L 10h
83+
LD A, (current_fg)
84+
ADD A, $80
85+
RST.L 10h
86+
RET
87+
8088
; Set display to true video
81-
True_Video: LD HL, c_TRUEVID
82-
JR Print_CString
83-
84-
; Put VDU in 80 column mode, of not already there.
85-
Setup_Screen: PUSH IX
86-
LD HL, c_FIXSETTINGS
87-
CALL Print_CString ; Cancel text window control keys, page mode
88-
MOSCALL mos_sysvars
89-
RES 4, (IX+sysvar_vpd_pflags) ; Clear mode flag
90-
LD HL, c_GETMODE
91-
CALL Print_CString ; Get screen mode parameters.
92-
@@: BIT 4, (IX+sysvar_vpd_pflags)
93-
JR Z, @B ; Wait until received.
94-
LD A, (IX+sysvar_scrMode)
95-
LD (Saved_Mode),A
96-
LD A, (IX+sysvar_scrCols)
97-
CP 80
98-
JR NC, Setup_End ; We have a mode with at least 80 columns, keep that.
99-
LD A, 22
100-
RST.LIL 10h
101-
LD A, 3
102-
RST.LIL 10h ; Enter Mode 3 (80x30)
103-
LD A,(IX+0)
104-
@@: CP (IX+0)
105-
JR Z, @B ; Wait for VBLANK
106-
Setup_End: RES 4, (IX+sysvar_vpd_pflags) ; Clear mode flag
107-
LD HL, c_GETMODE
108-
CALL Print_CString ; Get screen mode parameters.
109-
@@: BIT 4, (IX+sysvar_vpd_pflags)
110-
JR Z, @B ; Wait until received.
111-
LD A, (IX+sysvar_scrRows)
112-
LD (Current_Rows),A
113-
LD A, (IX+sysvar_scrCols)
114-
LD (Current_Cols),A
115-
LD A, (IX+sysvar_scrMode)
116-
LD (Current_Mode),A
117-
POP IX
89+
True_Video: LD A, 17
90+
RST.L 10h
91+
LD A, (current_fg)
92+
RST.L 10h
93+
LD A, 17
94+
RST.L 10h
95+
LD A, (current_bg)
96+
ADD A, $80
97+
RST.L 10h
11898
RET
11999
120100
; Restore original video mode.
@@ -149,11 +129,12 @@ Clear_EOL: PUSH IX
149129
JR Z, @B ; Wait for result.
150130
LD A, (Current_Cols)
151131
LD B, A ; Number of columns to B
152-
LD A, (Current_Rows)
153-
DEC A
154-
CP (IX+sysvar_cursorY)
155-
JR NZ, @F ; Are we on bottom row?
156-
DEC B ; Then only fill out up to last column, do not write a space there.
132+
LD A, (Current_Rows)
133+
DEC A
134+
CP (IX+sysvar_cursorY)
135+
JR NZ, @F ; Are we on bottom row?
136+
DEC B ; Then only fill out up to last column, do not write a space there.
137+
157138
@@: LD A, (IX+sysvar_cursorX)
158139
SUB B
159140
NEG
@@ -167,14 +148,8 @@ Clear_EOL: PUSH IX
167148

168149
s_CRLF: DB 13,10,0
169150

170-
c_INVVID: DB 4
171-
DB 17, 0 ; Forgeground black
172-
DB 17, 143 ; Background white
173-
c_TRUEVID: DB 4
174-
DB 17, 15 ; Foreground white
175-
DB 17, 128 ; Background black
176-
c_FIXSETTINGS: DB 6, 23,0,$98,0,15,26 ; Switch off control keys, cancel page mode, text window.
177-
c_ENABLECTRL: DB 4, 23,0,$98,1 ; Switch on control keys
151+
c_FIXSETTINGS: DB 6, 23,0,$98,0,15,26 ; Switch off control keys, cancel page mode, text window
152+
c_ENABLECTRL: DB 4, 23,0,$98,1 ; Switch on control keys
178153
c_GETMODE: DB 3, 23,0,vdp_mode ; Get screen mode parameters. Switch off paged mode, cancels text window.
179154
; RAM
180155
;

scr_init.inc

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
;
2+
; Title: Screen initialization functions.
3+
; Author: Lennart Benschop
4+
;
5+
; Created: 27/06/2024 Adapted to ez80asm
6+
7+
8+
; Put VDU in 80 column mode, if not already there.
9+
Setup_Screen: PUSH IX
10+
LD HL, c_FIXSETTINGS
11+
CALL Print_CString ; Cancel text window control keys, page mode
12+
MOSCALL mos_sysvars
13+
RES 4, (IX+sysvar_vpd_pflags) ; Clear mode flag
14+
LD HL, c_GETMODE
15+
CALL Print_CString ; Get screen mode parameters.
16+
@@: BIT 4, (IX+sysvar_vpd_pflags)
17+
JR Z, @B ; Wait until received.
18+
LD A, (IX+sysvar_scrMode)
19+
LD (Saved_Mode),A
20+
LD A, (IX+sysvar_scrCols)
21+
CP 80
22+
JR NC, Setup_End ; We have a mode with at least 80 columns, keep that.
23+
LD A, 22
24+
RST.LIL 10h
25+
LD A, 3
26+
RST.LIL 10h ; Enter Mode 3 (80x30)
27+
LD A,(IX+0)
28+
@@: CP (IX+0)
29+
JR Z, @B ; Wait for VBLANK
30+
Setup_End: RES 4, (IX+sysvar_vpd_pflags) ; Clear mode flag
31+
LD HL, c_GETMODE
32+
CALL Print_CString ; Get screen mode parameters.
33+
@@: BIT 4, (IX+sysvar_vpd_pflags)
34+
JR Z, @B ; Wait until received.
35+
LD A, (IX+sysvar_scrRows)
36+
LD (Current_Rows),A
37+
LD A, (IX+sysvar_scrCols)
38+
LD (Current_Cols),A
39+
LD A, (IX+sysvar_scrMode)
40+
LD (Current_Mode),A
41+
LD A, 128 ; Obtain foreground colour.
42+
CALL get_colour
43+
LD (current_fg),A
44+
LD A, 129 ; Obtain background colour.
45+
CALL get_colour
46+
LD (current_bg),A
47+
POP IX
48+
RET
49+
50+
; Input A, index to get colour (128 = foreground, 129 = background).
51+
; output: A scolour index of fg or bg colour.
52+
get_colour: RES 2,(IX+sysvar_vpd_pflags)
53+
LD L, A
54+
LD A, 23
55+
RST.L 10h
56+
XOR A
57+
RST.L 10h
58+
LD A, 148
59+
RST.L 10h
60+
LD A, L
61+
RST.L 10h
62+
@@: BIT 2, (IX+sysvar_vpd_pflags)
63+
JR Z, @B ; Wait until received.
64+
LD A,(IX+sysvar_scrpixelIndex)
65+
RET
66+

0 commit comments

Comments
 (0)