Skip to content

Commit 2a7b18c

Browse files
Fixed mode switching logic, disable control key operation (like page mode) during editing
1 parent ce5a19a commit 2a7b18c

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

mos/nano.bin

29 Bytes
Binary file not shown.

mos_api.inc

+26-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; Title: AGON MOS - API for user projects
33
; Author: Dean Belfield
44
; Created: 03/08/2022
5-
; Last Updated: 15/04/2023
5+
; Last Updated: 11/11/2023
66
;
77
; Modinfo:
88
; 05/08/2022: Added mos_feof
@@ -20,8 +20,12 @@
2020
; 29/03/2023: Added mos_uopen, mos_uclose, mos_ugetc, mos_uputc
2121
; 13/04/2023: Added FatFS file structures (FFOBJID, FIL, DIR, FILINFO)
2222
; 15/04/2023: Added mos_getfil, mos_fread, mos_fwrite and mos_flseek
23-
; Changed: 08/04/2924 adapt to ez80asm
24-
23+
; 19/05/2023: Added sysvar_scrMode
24+
; 05/06/2023: Added sysvar_rtcEnable
25+
; 03/08/2023: Added mos_setkbvector
26+
; 10/08/2023: Added mos_getkbmap
27+
; 11/11/2023: Added mos_i2c_open, mos_i2c_close, mos_i2c_write and mos_i2c_read
28+
; 09/04/2024: Adapter to ez80asm
2529
; VDP control (VDU 23, 0, n)
2630
;
2731
vdp_gp: EQU 80h
@@ -67,6 +71,13 @@ mos_getfil: EQU 19h
6771
mos_fread: EQU 1Ah
6872
mos_fwrite: EQU 1Bh
6973
mos_flseek: EQU 1Ch
74+
mos_setkbvector: EQU 1Dh
75+
mos_getkbmap: EQU 1Eh
76+
mos_i2c_open: EQU 1Fh
77+
mos_i2c_close: EQU 20h
78+
mos_i2c_write: EQU 21h
79+
mos_i2c_read: EQU 22h
80+
7081

7182
; FatFS file access functions
7283
;
@@ -150,10 +161,19 @@ sysvar_scrpixelIndex: EQU 16h ; 1: Index of pixel data read from screen
150161
sysvar_vkeycode: EQU 17h ; 1: Virtual key code from FabGL
151162
sysvar_vkeydown: EQU 18h ; 1: Virtual key state from FabGL (0=up, 1=down)
152163
sysvar_vkeycount: EQU 19h ; 1: Incremented every time a key packet is received
153-
sysvar_rtc: EQU 1Ah ; 8: Real time clock data
164+
sysvar_rtc: EQU 1Ah ; 6: Real time clock data
165+
sysvar_spare: EQU 20h ; 2: Spare, previously used by rtc
154166
sysvar_keydelay: EQU 22h ; 2: Keyboard repeat delay
155167
sysvar_keyrate: EQU 24h ; 2: Keyboard repeat reat
156168
sysvar_keyled: EQU 26h ; 1: Keyboard LED status
169+
sysvar_scrMode: EQU 27h ; 1: Screen mode
170+
sysvar_rtcEnable: EQU 28h ; 1: RTC enable flag (0: disabled, 1: use ESP32 RTC)
171+
sysvar_mouseX: EQU 29h ; 2: Mouse X position
172+
sysvar_mouseY: EQU 2Bh ; 2: Mouse Y position
173+
sysvar_mouseButtons: EQU 2Dh ; 1: Mouse button state
174+
sysvar_mouseWheel: EQU 2Eh ; 1: Mouse wheel delta
175+
sysvar_mouseXDelta: EQU 2Fh ; 2: Mouse X delta
176+
sysvar_mouseYDelta: EQU 31h ; 2: Mouse Y delta
157177
158178
; Flags for the VPD protocol
159179
;
@@ -163,6 +183,8 @@ vdp_pflag_point: EQU 00000100b
163183
vdp_pflag_audio: EQU 00001000b
164184
vdp_pflag_mode: EQU 00010000b
165185
vdp_pflag_rtc: EQU 00100000b
186+
vdp_pflag_mouse: EQU 01000000b
187+
; vdp_pflag_buffered: EQU 10000000b
166188

167189
;
168190
; FatFS structures

nano.asm

+3-2
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ Show_Status: ; Show status line at bottom of screen
940940
RST.LIL 10h
941941
LD HL, (num_lines)
942942
CALL Print_Decimal
943-
LD A, $2c ; Commaa
943+
LD A, ','
944944
RST.LIL 10h
945945
LD A, ' '
946946
RST.LIL 10h
@@ -1944,7 +1944,8 @@ s_LINETOOLONG: DB "Line too long!",0
19441944
s_NOMEM: DB "Buffer full!",0
19451945
; RAM variables
19461946

1947-
Saved_Rows: DS 1 ; Rows of video mode in which editor started, so we can return to that mode.
1947+
Saved_Mode: DS 1 ; video mode in which editor started, so we can return to that mode.
1948+
Current_Mode: DS 1 ; Current video mode.
19481949
Current_Rows: DS 1 ; Number of rows in current video mode
19491950
Current_Cols: DS 1 ; Number of columns in current video mode.
19501951
filename: DS 256 ; Name of file being edited.

output.inc

+24-19
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,26 @@ True_Video: LD HL, c_TRUEVID
8383

8484
; Put VDU in 80 column mode, of not already there.
8585
Setup_Screen: PUSH IX
86+
LD HL, c_FIXSETTINGS
87+
CALL Print_CString ; Cancel text window control keys, page mode
8688
MOSCALL mos_sysvars
8789
RES 4, (IX+sysvar_vpd_pflags) ; Clear mode flag
8890
LD HL, c_GETMODE
8991
CALL Print_CString ; Get screen mode parameters.
9092
@@: BIT 4, (IX+sysvar_vpd_pflags)
9193
JR Z, @B ; Wait until received.
92-
LD A, (IX+sysvar_scrRows)
93-
LD (Saved_Rows),A
94+
LD A, (IX+sysvar_scrMode)
95+
LD (Saved_Mode),A
9496
LD A, (IX+sysvar_scrCols)
9597
CP 80
96-
JR NC, Setup_End ; Apparently mode 3 or 0, do not switch
98+
JR NC, Setup_End ; We have a mode with at least 80 columns, keep that.
9799
LD A, 22
98100
RST.LIL 10h
99101
LD A, 3
100-
RST.LIL 10h ; Enter Mode 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
101106
Setup_End: RES 4, (IX+sysvar_vpd_pflags) ; Clear mode flag
102107
LD HL, c_GETMODE
103108
CALL Print_CString ; Get screen mode parameters.
@@ -106,24 +111,22 @@ Setup_End: RES 4, (IX+sysvar_vpd_pflags) ; Clear mode flag
106111
LD A, (IX+sysvar_scrRows)
107112
LD (Current_Rows),A
108113
LD A, (IX+sysvar_scrCols)
109-
LD (Current_Cols),A
114+
LD (Current_Cols),A
115+
LD A, (IX+sysvar_scrMode)
116+
LD (Current_Mode),A
110117
POP IX
111118
RET
112119
113120
; Restore original video mode.
114-
Restore_Screen: LD A, (Saved_Rows)
115-
CP 60
116-
RET Z ; Do nothing if we were already in mode 0
117-
CP 25
118-
JR NZ, @F
119-
LD L, 2
120-
JR Restore1
121-
@@: CP 48
122-
JR NZ, @F
123-
LD L, 1
124-
JR Restore1
125-
@@: RET ; We do not know about other modes, so please return.
126-
Restore1: LD A, 22
121+
Restore_Screen: LD HL, c_ENABLECTRL ; Re-enable control keys
122+
CALL Print_CString
123+
124+
LD A, (Saved_Mode)
125+
LD L, A
126+
LD A, (Current_Mode)
127+
CP L
128+
RET Z ; Do nothing if we had not changed modes.
129+
LD A, 22
127130
RST.LIL 10h
128131
LD A, L
129132
RST.LIL 10h
@@ -170,6 +173,8 @@ c_INVVID: DB 4
170173
c_TRUEVID: DB 4
171174
DB 17, 15 ; Foreground white
172175
DB 17, 128 ; Background black
173-
c_GETMODE: DB 5, 15,26,23,0,vdp_mode ; Get screen mode parameters. Switch off paged mode, cancels text window.
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
178+
c_GETMODE: DB 3, 23,0,vdp_mode ; Get screen mode parameters. Switch off paged mode, cancels text window.
174179
; RAM
175180
;

0 commit comments

Comments
 (0)