2016-10-16 15:11:04 +00:00
|
|
|
;
|
|
|
|
; 4LIVE
|
2016-11-03 16:03:56 +00:00
|
|
|
; Copyright (c) 2016 by 4am && qkumba
|
|
|
|
; 100% open source, see LICENSE file
|
2016-10-16 15:11:04 +00:00
|
|
|
;
|
|
|
|
!cpu 6502
|
2016-11-11 02:50:30 +00:00
|
|
|
!ct "lcase.ct"
|
2016-10-28 16:09:53 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
;user-defined
|
|
|
|
HOTKEY = $80 ; CTRL-@
|
2016-11-23 00:39:34 +00:00
|
|
|
HIGHLIGHTKEY = $82 ; CTRL-B
|
|
|
|
CLEARKEY = $83 ; CTRL-C
|
|
|
|
PREVPAGEKEY = $92 ; CTRL-R
|
|
|
|
ADDPAGEKEY = $94 ; CTRL-T
|
|
|
|
NEXTPAGEKEY = $99 ; CTRL-Y
|
|
|
|
IMPORTKEY = $9E ; CTRL-^
|
2016-11-15 07:23:57 +00:00
|
|
|
|
2016-11-23 06:40:43 +00:00
|
|
|
VERBOSE = $0 ; set to 1 to show memory usage during build
|
2016-10-16 15:11:04 +00:00
|
|
|
;
|
2016-10-16 18:32:54 +00:00
|
|
|
!addr KSWL = $38
|
2016-10-26 21:02:52 +00:00
|
|
|
!addr KSWH = $39
|
2016-11-15 07:23:57 +00:00
|
|
|
!addr FCBFOP = $40
|
2016-10-27 19:16:02 +00:00
|
|
|
!addr GETIOB = $3E3
|
2016-10-16 18:32:54 +00:00
|
|
|
!addr WARMDOS = $3D0
|
2016-10-27 19:16:02 +00:00
|
|
|
!addr DOSBASE = $3D2
|
|
|
|
!addr FILEMAN = $3D6
|
|
|
|
!addr GETPARM = $3DC
|
2016-10-16 18:32:54 +00:00
|
|
|
!addr KBD = $C000
|
|
|
|
!addr STROBE = $C010
|
2016-10-28 16:55:05 +00:00
|
|
|
!addr LCBANK2 = $C083
|
2016-11-10 23:35:25 +00:00
|
|
|
!addr ROMIN1 = $C089
|
|
|
|
!addr LCBANK1 = $C08B
|
2016-11-01 05:14:14 +00:00
|
|
|
!addr APLDETECT = $FBB3 ;#06 if IIe or later
|
2016-10-26 21:02:52 +00:00
|
|
|
!addr KEYIN = $FD1B
|
2016-11-01 16:23:03 +00:00
|
|
|
!addr RDCHAR = $FD35
|
|
|
|
!addr COUT = $FDED
|
2016-10-16 18:32:54 +00:00
|
|
|
|
2016-11-16 06:56:26 +00:00
|
|
|
;private arbitrary addresses, shared with DOS to avoid conflict
|
|
|
|
!addr OPSRC1L = $40
|
|
|
|
!addr OPSRC1H = $41
|
|
|
|
!addr OPDST1L = $42
|
|
|
|
!addr OPDST1H = $43
|
|
|
|
!addr OPSRC2L = $44
|
|
|
|
!addr OPSRC2H = $45
|
|
|
|
!addr OPDST2L = $46
|
|
|
|
!addr OPDST2H = $47
|
|
|
|
!addr SCROLLLINE = $48
|
2016-10-16 18:32:54 +00:00
|
|
|
|
2016-10-26 21:02:52 +00:00
|
|
|
;constants
|
2016-11-01 05:14:14 +00:00
|
|
|
A2E = $06
|
|
|
|
INVSPACE = $20
|
2016-11-18 00:53:00 +00:00
|
|
|
LTARROW = $88 ; CTRL-H
|
|
|
|
DNARROW = $8A ; CTRL-J
|
|
|
|
UPARROW = $8B ; CTRL-K
|
|
|
|
RETURN = $8D ; CTRL-M
|
|
|
|
RTARROW = $95 ; CTRL-U
|
2016-10-28 16:09:53 +00:00
|
|
|
ESC = $9B
|
2016-11-18 00:53:00 +00:00
|
|
|
SPACE = $A0
|
2016-11-01 05:14:14 +00:00
|
|
|
DELETE = $FF
|
2016-11-15 07:23:57 +00:00
|
|
|
|
2016-10-27 19:16:02 +00:00
|
|
|
IOBSLOT = 1
|
|
|
|
IOBDRIVE = 2
|
|
|
|
NAMELEN = 30
|
|
|
|
CREATEFILE = 0
|
|
|
|
OPENEXISTING = 1
|
2016-10-28 16:55:05 +00:00
|
|
|
SPECIAL = 8
|
2016-10-27 19:16:02 +00:00
|
|
|
CMDOPEN = 1
|
|
|
|
CMDCLOSE = 2
|
|
|
|
CMDREAD = 3
|
2016-11-23 00:39:34 +00:00
|
|
|
CMDWRITE = 4
|
2016-10-27 19:16:02 +00:00
|
|
|
READRANGE = 2
|
2016-11-23 00:39:34 +00:00
|
|
|
POSRDWRRANGE = 4
|
2016-11-15 07:23:57 +00:00
|
|
|
WIDTH = 40
|
|
|
|
HEIGHT = 24
|
2016-12-02 19:28:29 +00:00
|
|
|
LDRBASE = $2E9
|
|
|
|
INSTALLBUFFER = $23B ; yes, the overlay overwrites the loader...
|
2016-11-23 07:17:51 +00:00
|
|
|
; see also "warning!" below
|
2016-11-16 06:56:26 +00:00
|
|
|
SWAPBUFFER = $900 ; (LoadSaveEnd - LoadSaveStart) size
|
2016-12-02 19:28:29 +00:00
|
|
|
; needed by Diversi-DOS, must be page-aligned
|
2016-11-16 06:56:26 +00:00
|
|
|
; region is preserved across calls
|
2016-12-02 19:28:29 +00:00
|
|
|
; do not set below $900 if *size* of buffer is not page-aligned
|
|
|
|
SWAPSIZEALIGNED = 0 ; set to 1 if (LoadSaveEnd - LoadSaveStart) size is page-aligned
|
|
|
|
; an aligned size reduces code size by a bit but increases memory usage by a lot
|
2016-10-26 21:02:52 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
*=LDRBASE-4
|
|
|
|
LdrHeader
|
|
|
|
!word LDRBASE, LdrEnd - LdrStart
|
2016-10-16 18:32:54 +00:00
|
|
|
|
2016-11-17 06:53:50 +00:00
|
|
|
;loader loads to pages 2-3, loads discardable install code also to pages 2-3
|
2016-12-02 19:28:29 +00:00
|
|
|
;and carries proxy routines including file manager and banked RAM exchange for Diversi-DOS
|
2016-11-10 23:35:25 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
LdrStart
|
2016-11-16 06:56:26 +00:00
|
|
|
;set filename pointer in MLI request packet
|
2016-10-28 16:55:05 +00:00
|
|
|
|
2016-11-16 06:56:26 +00:00
|
|
|
lda FCBFOP
|
|
|
|
sta FileName
|
|
|
|
lda FCBFOP + 1
|
|
|
|
sta FileName + 1
|
2016-10-28 16:55:05 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
;set slot and drive in MLI request packet
|
2016-10-28 16:55:05 +00:00
|
|
|
|
2016-11-16 06:56:26 +00:00
|
|
|
jsr GETIOB
|
2016-11-17 05:32:28 +00:00
|
|
|
pha ;save for later
|
2016-11-16 06:56:26 +00:00
|
|
|
sty OPSRC1L
|
|
|
|
sta OPSRC1H
|
2016-11-15 07:23:57 +00:00
|
|
|
ldy #IOBDRIVE
|
2016-11-16 06:56:26 +00:00
|
|
|
lda (OPSRC1L), y
|
2016-11-15 07:23:57 +00:00
|
|
|
sta FileDrive
|
|
|
|
dey ;ldy #IOBSLOT
|
2016-11-16 06:56:26 +00:00
|
|
|
lda (OPSRC1L), y
|
2016-11-15 07:23:57 +00:00
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
sta FileSlot
|
|
|
|
dey ;ldy #00
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
;open self and read first overlay
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-16 06:56:26 +00:00
|
|
|
jsr OpenMainFile
|
2016-11-15 07:23:57 +00:00
|
|
|
jsr DOSMLI
|
|
|
|
!byte LdrReadMLI_e - LdrReadMLI_b
|
|
|
|
LdrReadMLI_b
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte CMDREAD ;command
|
|
|
|
!byte POSRDWRRANGE ;subcommand
|
2016-11-15 07:23:57 +00:00
|
|
|
!word 0 ;record number
|
|
|
|
!word LdrEnd - LdrHeader ;offset
|
|
|
|
!word InstallEnd - InstallStart
|
|
|
|
;number of bytes
|
|
|
|
!word INSTALLBUFFER ;buffer
|
|
|
|
LdrReadMLI_e
|
|
|
|
|
|
|
|
;no need to close read-only files
|
|
|
|
;DOS simply returns in that case
|
|
|
|
;written files are the important ones
|
|
|
|
;but we're not writing anything here
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
JmpInstall
|
2016-11-15 07:23:57 +00:00
|
|
|
jmp INSTALLBUFFER
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
;set input name
|
|
|
|
|
|
|
|
OpenDataFile
|
2016-11-16 06:56:26 +00:00
|
|
|
ldy #(NAMELEN - 1)
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
OpenMainFile ;called with Y=0 for main file (copies one character)
|
2016-11-15 07:23:57 +00:00
|
|
|
lda FileName
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST1L
|
2016-11-15 07:23:57 +00:00
|
|
|
lda FileName + 1
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST1H
|
|
|
|
lda LCBANK2
|
|
|
|
lda LCBANK2
|
2016-10-27 19:16:02 +00:00
|
|
|
|
|
|
|
;set input name
|
|
|
|
|
2016-11-18 19:05:16 +00:00
|
|
|
lda #SPACE
|
2016-10-27 19:16:02 +00:00
|
|
|
- cpy #(FileName_e - FileName_b)
|
|
|
|
bcs +
|
|
|
|
lda FileName_b, y
|
2016-11-16 06:56:26 +00:00
|
|
|
+ sta (OPDST1L), y
|
2016-10-27 19:16:02 +00:00
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
OpenFile
|
|
|
|
jsr DOSMLI
|
|
|
|
!byte OpenMLI_e - OpenMLI_b
|
|
|
|
OpenMLI_b
|
|
|
|
!byte CMDOPEN
|
|
|
|
!byte 0 ;unused
|
|
|
|
!word 0 ;variable records
|
|
|
|
!byte 0 ;any volume
|
|
|
|
FileDrive
|
|
|
|
!text "Q" ;self-modified
|
|
|
|
FileSlot
|
|
|
|
!text "Q" ;self-modified
|
|
|
|
!byte SPECIAL ;file type for when we save
|
|
|
|
FileName
|
|
|
|
!text "4s" ;self-modified
|
|
|
|
OpenMLI_e
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
ReuseRts
|
2016-11-15 07:23:57 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
FileName_b
|
2016-11-23 00:39:34 +00:00
|
|
|
!text "_4LIVE DATA" ;first character must match first character of binary name
|
2016-11-15 07:23:57 +00:00
|
|
|
FileName_e
|
|
|
|
|
|
|
|
;first byte fetched is number of byte to follow,
|
|
|
|
;copy parameters to file manager parameter list,
|
|
|
|
;and then dispatch the request
|
|
|
|
|
|
|
|
DOSMLI
|
|
|
|
pla
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
iny
|
2016-11-16 06:56:26 +00:00
|
|
|
sty OPSRC1L
|
2016-11-15 07:23:57 +00:00
|
|
|
bne +
|
|
|
|
inx
|
2016-11-16 06:56:26 +00:00
|
|
|
+ stx OPSRC1H
|
2016-11-10 23:35:25 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
;get file manager parameter list
|
2016-11-10 23:35:25 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
jsr GETPARM
|
2016-11-16 06:56:26 +00:00
|
|
|
sty OPDST1L
|
|
|
|
sta OPDST1H
|
2016-11-15 07:23:57 +00:00
|
|
|
ldy #0
|
2016-11-16 06:56:26 +00:00
|
|
|
lda (OPSRC1L), y
|
2016-11-15 07:23:57 +00:00
|
|
|
tay
|
|
|
|
clc
|
2016-11-16 06:56:26 +00:00
|
|
|
adc OPSRC1L
|
2016-11-15 07:23:57 +00:00
|
|
|
tax
|
2016-11-16 06:56:26 +00:00
|
|
|
lda OPSRC1H
|
2016-11-15 07:23:57 +00:00
|
|
|
adc #0
|
|
|
|
pha
|
|
|
|
txa
|
|
|
|
pha
|
2016-11-16 06:56:26 +00:00
|
|
|
- lda (OPSRC1L), y
|
2016-11-10 23:35:25 +00:00
|
|
|
dey
|
2016-11-16 06:56:26 +00:00
|
|
|
sta (OPDST1L), y
|
2016-11-10 23:35:25 +00:00
|
|
|
bne -
|
2016-11-15 07:23:57 +00:00
|
|
|
XREG
|
|
|
|
ldx #OPENEXISTING
|
|
|
|
|
|
|
|
SwapFILEMAN
|
|
|
|
jmp FILEMAN ;self-modified from JMP to JSR
|
2016-11-23 00:39:34 +00:00
|
|
|
;to allow fall-through to bank-in RAM
|
2016-11-15 07:23:57 +00:00
|
|
|
BankInRAM1
|
|
|
|
bit LCBANK1
|
|
|
|
bit LCBANK1
|
|
|
|
rts
|
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;read file content into memory
|
|
|
|
;with swapping of the memory contents in Diversi-DOS,
|
|
|
|
;in order to preserve the original memory region
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
ReadFile
|
|
|
|
jsr ExchangeBanked1
|
2016-12-02 19:28:29 +00:00
|
|
|
ReadFileNoXchg
|
|
|
|
WriteFile
|
2016-11-15 07:23:57 +00:00
|
|
|
jsr DOSMLI
|
|
|
|
!byte ReadMLI_e - ReadMLI_b
|
|
|
|
ReadMLI_b
|
|
|
|
ReadWriteCmd
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte CMDREAD ;command
|
|
|
|
!byte POSRDWRRANGE ;sub-command
|
2016-11-15 07:23:57 +00:00
|
|
|
!word 0 ;record number
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
ReadOffset
|
|
|
|
WriteOffset
|
|
|
|
!word 0 ;offset, self-modified according to page number
|
2016-11-15 07:23:57 +00:00
|
|
|
|
|
|
|
ReadSize
|
|
|
|
WriteSize
|
2016-11-23 00:39:34 +00:00
|
|
|
!text "4s" ;number of bytes, self-modified
|
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
ReadBuffer
|
|
|
|
WriteBuffer
|
2016-12-02 19:28:29 +00:00
|
|
|
!word LoadSaveStart ;buffer, self-modified in Diversi-DOS
|
2016-11-15 07:23:57 +00:00
|
|
|
ReadMLI_e
|
|
|
|
;fall through to ExchangeBanked1
|
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;swap banked memory region with main memory region
|
|
|
|
;call again to restore the main memory region
|
2016-11-15 07:23:57 +00:00
|
|
|
;sorry, I couldn't find a simpler way...
|
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
ExchangeBanked1
|
2016-12-02 19:28:29 +00:00
|
|
|
rts ;self-modified to CLC in Diversi-DOS environment
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
;fill banked dynamic region with spaces
|
|
|
|
|
|
|
|
ClearVirtualBuffer ;called with carry set
|
|
|
|
lda #>(LoadSaveStart - <(LoadSaveStart - LastLine))
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST1H
|
2016-11-23 00:39:34 +00:00
|
|
|
ldx #>(LastLine - LoadSaveStart)
|
|
|
|
ldy #<(LoadSaveStart - LastLine)
|
|
|
|
lda #<(LastLine - LoadSaveStart)
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPSRC1L
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #<LastLine
|
2016-11-15 07:23:57 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;can also swap banked dynamic region with spare region also in banked memory
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
ExchangeBankedSet ;called with A=buffer offset, carry clear
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST1L
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
ExchangeBankedPatch
|
|
|
|
lda #>(SWAPBUFFER - <(LoadSaveStart - LastLine))
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPSRC1H
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #SPACE
|
|
|
|
- bcs + ;the ClearVirtualBuffer path
|
|
|
|
lda (OPSRC1L), y
|
2016-11-15 07:23:57 +00:00
|
|
|
pha
|
2016-11-16 06:56:26 +00:00
|
|
|
lda (OPDST1L), y
|
|
|
|
sta (OPSRC1L), y
|
2016-11-15 07:23:57 +00:00
|
|
|
pla
|
2016-11-23 00:39:34 +00:00
|
|
|
+ sta (OPDST1L), y
|
2016-11-10 23:35:25 +00:00
|
|
|
iny
|
2016-11-16 06:56:26 +00:00
|
|
|
bne -
|
|
|
|
inc OPSRC1H
|
|
|
|
inc OPDST1H
|
2016-11-10 23:35:25 +00:00
|
|
|
dex
|
2016-11-16 06:56:26 +00:00
|
|
|
bpl -
|
2016-11-15 07:23:57 +00:00
|
|
|
rts
|
|
|
|
LdrEnd
|
2016-12-03 22:03:58 +00:00
|
|
|
!ifdef PASS2 {
|
|
|
|
!if (LdrEnd > $3D0) {
|
|
|
|
!error "LDRBASE too high, change to ", LdrStart + $3D0 - LdrEnd
|
|
|
|
} else {
|
|
|
|
!if (LdrEnd < $3D0) {
|
|
|
|
!error "LDRBASE too low, change to ", LdrStart + $3D0 - LdrEnd
|
|
|
|
}
|
2016-11-23 00:39:34 +00:00
|
|
|
}
|
2016-11-15 07:23:57 +00:00
|
|
|
}
|
2016-11-10 23:35:25 +00:00
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
;install routine is an overlay that is loaded by loader routine above
|
|
|
|
;loads editor code and data file into banked RAM either directly for DOS 3.3
|
2016-12-02 19:28:29 +00:00
|
|
|
;or via RAM exchange for Diversi-DOS
|
2016-11-15 07:23:57 +00:00
|
|
|
|
|
|
|
!pseudopc INSTALLBUFFER {
|
2016-11-23 00:39:34 +00:00
|
|
|
InstallStart
|
2016-12-02 19:28:29 +00:00
|
|
|
;check for Diversi-DOS
|
2016-11-15 07:23:57 +00:00
|
|
|
|
2016-11-17 05:32:28 +00:00
|
|
|
pla
|
2016-11-16 06:56:26 +00:00
|
|
|
eor #$BF
|
2016-12-02 19:28:29 +00:00
|
|
|
pha
|
2016-11-16 06:56:26 +00:00
|
|
|
bne + ;regular DOS
|
2016-11-15 07:23:57 +00:00
|
|
|
sta ReadBuffer
|
|
|
|
lda #>SWAPBUFFER
|
|
|
|
sta ReadBuffer + 1
|
|
|
|
sta InstallReadBuffer + 1
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #$18 ;CLC
|
|
|
|
sta ExchangeBanked2
|
2016-12-02 19:28:29 +00:00
|
|
|
sta ExchangeBanked1
|
2016-11-15 07:23:57 +00:00
|
|
|
+
|
|
|
|
;enable reading directly into banked RAM
|
|
|
|
|
|
|
|
jsr BankInRAM1
|
|
|
|
|
|
|
|
;read second overlay to banked RAM
|
|
|
|
|
2016-11-17 05:32:28 +00:00
|
|
|
jsr ReadEditor
|
2016-12-02 19:28:29 +00:00
|
|
|
pla
|
|
|
|
bne +
|
|
|
|
lda #$90
|
|
|
|
sta PatchDiversi
|
|
|
|
+
|
2016-11-23 00:39:34 +00:00
|
|
|
;open source file and read header if available
|
2016-11-15 07:23:57 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr LoadSaveHeader
|
2016-11-03 06:32:10 +00:00
|
|
|
bcs +
|
2016-11-23 00:39:34 +00:00
|
|
|
lda SaveCH
|
|
|
|
sta Pages + 1
|
|
|
|
ldx SaveCV
|
|
|
|
stx CurPage + 1
|
|
|
|
jsr SeekReadWrite
|
2016-11-03 06:32:10 +00:00
|
|
|
+
|
2016-11-01 05:14:14 +00:00
|
|
|
;set to true if no data file found (carry is set)
|
|
|
|
|
|
|
|
rol ClearOnFirstKeypress + 1
|
2016-12-02 19:28:29 +00:00
|
|
|
rol PreventAddPage + 1 ;tri-state flag because Diversi-DOS
|
2016-11-01 05:14:14 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr SetTextCoords1
|
2016-10-27 19:16:02 +00:00
|
|
|
|
|
|
|
;switch to write mode for future accesses
|
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
inc ReadWriteCmd ;lda #CMDWRITE / sta ReadWriteCmd
|
2016-11-15 07:23:57 +00:00
|
|
|
dec XREG + 1 ;lda #CREATEFILE / sta XREG + 1
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-10 23:35:25 +00:00
|
|
|
lda ROMIN1
|
2016-10-28 16:55:05 +00:00
|
|
|
|
2016-11-16 06:56:26 +00:00
|
|
|
;switch cursor type depending on Apple revision
|
|
|
|
|
|
|
|
lda APLDETECT
|
|
|
|
cmp #A2E
|
|
|
|
beq +
|
|
|
|
lda #INVSPACE
|
|
|
|
sta CharDel + 1
|
2016-12-02 19:28:29 +00:00
|
|
|
lda #$DF
|
2016-11-16 06:56:26 +00:00
|
|
|
sta CharMap1 + 1
|
|
|
|
sta CharMap2 + 1
|
|
|
|
+
|
2016-10-27 19:16:02 +00:00
|
|
|
;display the welcome message, now that we're finally done
|
|
|
|
|
2016-10-16 18:32:54 +00:00
|
|
|
ldy #0
|
2016-11-11 02:50:30 +00:00
|
|
|
beq ++
|
2016-12-02 19:28:29 +00:00
|
|
|
- cmp #$E0
|
2016-11-11 02:50:30 +00:00
|
|
|
bcc +
|
2016-12-02 19:28:29 +00:00
|
|
|
CharMap1
|
|
|
|
and #$FF ;self-modified in Apple II+ environment
|
2016-11-11 02:50:30 +00:00
|
|
|
+ jsr COUT
|
|
|
|
++ iny
|
2016-10-26 21:02:52 +00:00
|
|
|
lda _WelcomeMessage-1,y
|
2016-12-02 19:28:29 +00:00
|
|
|
bne -
|
|
|
|
lda #<GlobalKeyboardHook
|
2016-10-16 18:32:54 +00:00
|
|
|
sta KSWL
|
|
|
|
lda #>GlobalKeyboardHook
|
2016-10-26 21:02:52 +00:00
|
|
|
sta KSWH
|
2016-11-23 00:39:34 +00:00
|
|
|
jmp WARMDOS ;DOS will reconnect the vector itself
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;read the main code into banked RAM
|
|
|
|
;uses the memory swapping technique in Diversi-DOS
|
|
|
|
|
2016-11-17 05:32:28 +00:00
|
|
|
ReadEditor
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr ExchangeBanked2
|
2016-11-18 19:05:16 +00:00
|
|
|
lda #$20 ;JSR
|
2016-11-17 05:32:28 +00:00
|
|
|
sta SwapFILEMAN
|
|
|
|
jsr DOSMLI
|
|
|
|
!byte InstallReadMLI_e - InstallReadMLI_b
|
|
|
|
InstallReadMLI_b
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte CMDREAD ;command
|
|
|
|
!byte POSRDWRRANGE ;subcommand
|
2016-11-17 05:32:28 +00:00
|
|
|
!word 0 ;record number
|
|
|
|
!word BankedCopyStart - LdrHeader
|
|
|
|
;offset
|
|
|
|
!word BankedCopyEnd - BankedCopyStart
|
|
|
|
;number of bytes
|
|
|
|
InstallReadBuffer
|
|
|
|
!word $D000 ;buffer
|
|
|
|
InstallReadMLI_e
|
2016-12-02 19:28:29 +00:00
|
|
|
;fall through to restore buffer
|
2016-11-17 05:32:28 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
ExchangeBanked2
|
2016-12-02 19:28:29 +00:00
|
|
|
rts ;self-modified to CLC (for compatibility) in Diversi-DOS environment
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #>($D000 - <(BankedCopyStart - BankedCopyEnd))
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST1H
|
2016-11-15 07:23:57 +00:00
|
|
|
ldx #>(BankedCopyEnd - BankedCopyStart)
|
|
|
|
ldy #<(BankedCopyStart - BankedCopyEnd)
|
|
|
|
lda #<(BankedCopyEnd - BankedCopyStart)
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPSRC1L
|
2016-11-23 00:39:34 +00:00
|
|
|
jmp ExchangeBankedSet
|
2016-11-15 07:23:57 +00:00
|
|
|
|
|
|
|
_WelcomeMessage
|
2016-11-16 19:37:26 +00:00
|
|
|
!text $8D, "4LIVE ready. Press Ctrl+", HOTKEY + $40, " to activate.", $8D, 0
|
2016-11-18 00:53:00 +00:00
|
|
|
|
2016-11-18 19:05:16 +00:00
|
|
|
;show original DOS cursor first, whatever it was
|
2016-11-18 00:53:00 +00:00
|
|
|
|
|
|
|
GlobalKeyboardHook
|
|
|
|
jsr KEYIN
|
|
|
|
|
|
|
|
GetKey
|
|
|
|
;are we on?
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
cmp #HOTKEY
|
|
|
|
|
|
|
|
;no -> return to DOS
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
bne ReuseRts
|
|
|
|
|
|
|
|
jsr BankInRAM1
|
|
|
|
jsr RunFromBankedRAM
|
|
|
|
lda ROMIN1
|
|
|
|
|
|
|
|
;lather, rinse, repeat
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
jsr RDCHAR ;returns non-zero
|
|
|
|
bne GetKey ;always
|
2016-11-15 07:23:57 +00:00
|
|
|
InstallEnd
|
2016-12-03 22:03:58 +00:00
|
|
|
!ifdef PASS2 {
|
|
|
|
!if (LdrEnd = $3D0) {
|
|
|
|
!if (InstallEnd > JmpInstall) {
|
|
|
|
!error "INSTALLBUFFER too large, change to ", InstallStart + JmpInstall - InstallEnd
|
|
|
|
} else {
|
|
|
|
!if (InstallEnd < JmpInstall) {
|
|
|
|
!error "INSTALLBUFFER too low, change to ", InstallStart + JmpInstall - InstallEnd
|
|
|
|
}
|
|
|
|
}
|
2016-11-23 00:39:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-10 23:35:25 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 07:23:57 +00:00
|
|
|
;editor code is an overlay that is loaded by install routine above
|
|
|
|
|
2016-11-10 23:35:25 +00:00
|
|
|
BankedCopyStart
|
|
|
|
!pseudopc $D000 {
|
|
|
|
RunFromBankedRAM
|
2016-11-01 05:14:14 +00:00
|
|
|
;preserve X across calls
|
|
|
|
;it's important for DOS
|
|
|
|
|
2016-11-10 23:35:25 +00:00
|
|
|
txa
|
2016-10-31 13:51:00 +00:00
|
|
|
pha
|
|
|
|
|
2016-10-30 19:17:45 +00:00
|
|
|
;first, scroll the edit buffer onto the screen
|
|
|
|
;(this also swaps the current screen contents out so we can restore it later)
|
2016-12-02 19:28:29 +00:00
|
|
|
|
2016-11-16 18:57:20 +00:00
|
|
|
jsr ScrollEditBufferIn ;returns Y=FF
|
2016-11-01 05:14:14 +00:00
|
|
|
|
|
|
|
;do the thing
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
iny ;Y=0
|
2016-11-23 00:39:34 +00:00
|
|
|
sty WriteIfDirty2 + 1 ;0=false, non-0=true
|
2016-10-30 19:17:45 +00:00
|
|
|
|
|
|
|
;do the thing
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-10-26 21:02:52 +00:00
|
|
|
jsr EditorMode
|
|
|
|
|
2016-10-30 19:17:45 +00:00
|
|
|
;scroll the edit buffer out and the original screen back in
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-10-30 19:17:45 +00:00
|
|
|
jsr ScrollEditBufferOut
|
|
|
|
|
2016-10-31 13:51:00 +00:00
|
|
|
;save to disk (if necessary)
|
2016-11-01 05:14:14 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr WriteIfDirty1
|
2016-11-01 05:14:14 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
pla
|
2016-10-31 13:51:00 +00:00
|
|
|
tax
|
2016-11-10 23:35:25 +00:00
|
|
|
rts
|
2016-10-30 19:17:45 +00:00
|
|
|
|
|
|
|
ScrollEditBufferIn
|
2016-11-23 00:39:34 +00:00
|
|
|
ldy #(<(ScrollParmsDown - ScrollParms) - 1)
|
|
|
|
jsr SetScrollLine
|
2016-10-30 19:17:45 +00:00
|
|
|
|
|
|
|
;copy last line on screen to temporary buffer
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-10-30 01:17:18 +00:00
|
|
|
-- ldy #(WIDTH - 1)
|
2016-10-30 19:17:45 +00:00
|
|
|
- lda $07D0, y
|
2016-11-16 06:56:26 +00:00
|
|
|
sta (OPSRC1L), y
|
2016-10-30 01:17:18 +00:00
|
|
|
dey
|
|
|
|
bpl -
|
2016-10-30 19:17:45 +00:00
|
|
|
|
|
|
|
;copy each line on screen down to next line (leaves top line untouched)
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-10-30 01:17:18 +00:00
|
|
|
jsr ScrollTextScreenDown
|
2016-10-30 19:17:45 +00:00
|
|
|
|
|
|
|
;copy last line of edit buffer to top line on screen
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-10-30 01:17:18 +00:00
|
|
|
ldy #(WIDTH - 1)
|
2016-11-16 06:56:26 +00:00
|
|
|
- lda (OPDST1L), y
|
2016-12-02 19:28:29 +00:00
|
|
|
jsr MapCase
|
2016-11-23 07:30:18 +00:00
|
|
|
sta $0400, y
|
2016-10-30 01:17:18 +00:00
|
|
|
dey
|
|
|
|
bpl -
|
2016-10-30 19:17:45 +00:00
|
|
|
|
|
|
|
;animation delay
|
2016-12-02 19:28:29 +00:00
|
|
|
|
2016-11-17 05:32:28 +00:00
|
|
|
jsr Delay
|
2016-10-30 19:17:45 +00:00
|
|
|
|
2016-11-03 06:32:10 +00:00
|
|
|
lda #-WIDTH
|
2016-11-16 06:56:26 +00:00
|
|
|
ldy #$FF
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr UpdateVirtualOff ;returns Z/NZ state of SCROLLLINE
|
2016-10-30 01:17:18 +00:00
|
|
|
bne --
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
;display current/total page numbering
|
|
|
|
;99 pages should be enough for everyone
|
|
|
|
|
|
|
|
PrintPage
|
|
|
|
ldx #(HEIGHT - 1)
|
|
|
|
jsr SetTextCalc
|
|
|
|
ldy #4
|
|
|
|
ldx Pages + 1
|
|
|
|
inx
|
|
|
|
jsr HexToDec
|
|
|
|
lda #"/"
|
|
|
|
sta (OPSRC2L), y
|
|
|
|
dey
|
|
|
|
ldx CurPage + 1
|
|
|
|
inx
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
HexToDec ;called with X=hex value to print
|
2016-11-23 00:39:34 +00:00
|
|
|
txa
|
|
|
|
ldx #0
|
|
|
|
- cmp #$0A
|
|
|
|
bcc +
|
2016-11-25 18:50:23 +00:00
|
|
|
sbc #$0A
|
2016-11-23 00:39:34 +00:00
|
|
|
inx
|
|
|
|
bne -
|
|
|
|
+ jsr AToScr
|
|
|
|
txa
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
AToScr ;called with A=dec value to print
|
2016-11-23 00:39:34 +00:00
|
|
|
ora #"0"
|
|
|
|
sta (OPSRC2L), y
|
|
|
|
dey
|
2016-10-30 01:17:18 +00:00
|
|
|
rts
|
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
MapCase
|
|
|
|
cmp #$E0
|
2016-11-23 07:30:18 +00:00
|
|
|
bcc +
|
2016-12-02 19:28:29 +00:00
|
|
|
CharMap2
|
|
|
|
and #$FF ;self-modified in Apple II+ environment
|
2016-11-23 07:30:18 +00:00
|
|
|
+ rts
|
|
|
|
|
2016-10-30 19:17:45 +00:00
|
|
|
ScrollEditBufferOut
|
2016-11-23 00:39:34 +00:00
|
|
|
ldy #(<(ScrollParmsUp - ScrollParms) - 1)
|
|
|
|
jsr SetScrollLine
|
2016-10-30 19:17:45 +00:00
|
|
|
|
|
|
|
;copy first line on screen to temporary buffer
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-10-27 19:16:02 +00:00
|
|
|
-- ldy #(WIDTH - 1)
|
2016-11-17 05:32:28 +00:00
|
|
|
- lda $0400, y
|
2016-11-16 06:56:26 +00:00
|
|
|
sta (OPSRC1L), y
|
2016-10-26 21:02:52 +00:00
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
;copy each line on screen up to next line (leaves bottom line untouched)
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
jsr ScrollTextScreenUp
|
2016-10-26 21:02:52 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
;copy first line of edit buffer to last line on screen
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-10-30 19:17:45 +00:00
|
|
|
ldy #(WIDTH - 1)
|
2016-11-16 06:56:26 +00:00
|
|
|
- lda (OPDST1L), y
|
2016-11-01 05:14:14 +00:00
|
|
|
sta $07D0, y
|
2016-10-26 21:02:52 +00:00
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
|
2016-10-30 19:17:45 +00:00
|
|
|
;animation delay
|
2016-12-02 19:28:29 +00:00
|
|
|
|
2016-11-17 05:32:28 +00:00
|
|
|
jsr Delay ;returns A=0
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-16 06:56:26 +00:00
|
|
|
tay
|
2016-11-03 06:32:10 +00:00
|
|
|
lda #WIDTH
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr UpdateVirtualOff ;returns Z/NZ state of SCROLLLINE
|
2016-10-26 21:02:52 +00:00
|
|
|
bne --
|
2016-10-30 01:17:18 +00:00
|
|
|
rts
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
SetScrollLine ;called with Y=offset of scroll parameter
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #HEIGHT
|
|
|
|
sta SCROLLLINE
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
SetScrollParms ;called with Y=offset of scroll parameter
|
2016-11-17 05:32:28 +00:00
|
|
|
ldx #3
|
2016-11-23 00:39:34 +00:00
|
|
|
- lda ScrollParms, y
|
2016-11-17 05:32:28 +00:00
|
|
|
sta OPSRC1L, x
|
|
|
|
dey
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
2016-11-03 06:32:10 +00:00
|
|
|
;set up copy addresses for next line
|
2016-11-16 06:56:26 +00:00
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
UpdateVirtualOff ;called with A=delta to apply to offsets
|
2016-11-16 06:56:26 +00:00
|
|
|
ldx #2
|
|
|
|
- pha
|
2016-11-03 06:32:10 +00:00
|
|
|
clc
|
2016-11-16 06:56:26 +00:00
|
|
|
adc OPSRC1L, x
|
|
|
|
sta OPSRC1L, x
|
|
|
|
tya
|
|
|
|
adc OPSRC1H, x
|
|
|
|
sta OPSRC1H, x
|
2016-11-03 06:32:10 +00:00
|
|
|
pla
|
2016-11-16 06:56:26 +00:00
|
|
|
dex
|
|
|
|
dex
|
|
|
|
bpl -
|
2016-11-17 05:32:28 +00:00
|
|
|
dec SCROLLLINE
|
2016-11-03 06:32:10 +00:00
|
|
|
rts
|
|
|
|
|
2016-10-30 01:17:18 +00:00
|
|
|
ScrollTextScreenDown
|
2016-11-01 05:14:14 +00:00
|
|
|
ldx #(HEIGHT - 2)
|
2016-11-16 06:56:26 +00:00
|
|
|
- jsr SetTextCalc
|
2016-10-30 01:17:18 +00:00
|
|
|
lda TextCalcLo+1, x
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST2L
|
2016-10-30 01:17:18 +00:00
|
|
|
lda TextCalcHi+1, x
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST2H
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr CopyRow
|
2016-10-30 01:17:18 +00:00
|
|
|
dex
|
|
|
|
bpl -
|
2016-10-26 21:02:52 +00:00
|
|
|
rts
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
SetTextCalc ;called with X=line number to resolve
|
2016-11-16 06:56:26 +00:00
|
|
|
lda TextCalcLo, x
|
|
|
|
sta OPSRC2L
|
|
|
|
lda TextCalcHi, x
|
|
|
|
sta OPSRC2H
|
|
|
|
rts
|
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
ScrollTextScreenUp
|
2016-11-23 00:39:34 +00:00
|
|
|
ldx #(1 - HEIGHT) ;negative indexing to avoid a compare
|
2016-11-01 05:14:14 +00:00
|
|
|
- lda (TextCalcLo + HEIGHT - $101) +1, x
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPSRC2L
|
2016-11-01 05:14:14 +00:00
|
|
|
lda TextCalcLo + HEIGHT - $101, x
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST2L
|
2016-11-01 05:14:14 +00:00
|
|
|
lda (TextCalcHi + HEIGHT - $101) +1, x
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPSRC2H
|
2016-11-01 05:14:14 +00:00
|
|
|
lda TextCalcHi + HEIGHT - $101, x
|
2016-11-16 06:56:26 +00:00
|
|
|
sta OPDST2H
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr CopyRow
|
2016-11-01 05:14:14 +00:00
|
|
|
inx
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
CopyRow
|
2016-11-16 06:56:26 +00:00
|
|
|
ldy #(WIDTH - 1)
|
|
|
|
- lda (OPSRC2L), y
|
|
|
|
sta (OPDST2L), y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
2016-10-26 21:02:52 +00:00
|
|
|
Delay
|
2016-10-28 20:07:13 +00:00
|
|
|
lda #1
|
2016-10-26 21:02:52 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;straight from ROM
|
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
MyWAIT
|
|
|
|
sec
|
|
|
|
-- pha
|
|
|
|
- sbc #1
|
|
|
|
bne -
|
|
|
|
pla
|
|
|
|
sbc #1
|
|
|
|
bne --
|
|
|
|
rts
|
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
MyKEYIN
|
|
|
|
ldx MyCH + 1
|
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;fetch the character at the current cursor position
|
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
ScreenBuff2
|
|
|
|
lda $34f3, x ;self-modified
|
|
|
|
sta ToggleChar + 1
|
|
|
|
|
2016-11-18 19:05:16 +00:00
|
|
|
;since we flash the cursor manually by toggling with an inverse space,
|
|
|
|
;detect if cursor is over an inverse space and use normal space instead
|
|
|
|
;otherwise cursor won't be visible
|
2016-11-18 00:53:00 +00:00
|
|
|
|
|
|
|
CharDel
|
2016-11-18 19:05:16 +00:00
|
|
|
ldy #DELETE ;self-modified to INVSPACE in Apple II+ environment
|
2016-11-18 00:53:00 +00:00
|
|
|
bmi +
|
|
|
|
cmp #INVSPACE
|
|
|
|
bne +
|
|
|
|
ldy #SPACE
|
|
|
|
+ tya
|
2016-11-01 05:14:14 +00:00
|
|
|
sec
|
2016-11-18 00:53:00 +00:00
|
|
|
!byte $24 ;mask CLC
|
|
|
|
ToggleCarry
|
|
|
|
clc
|
2016-11-01 05:14:14 +00:00
|
|
|
bcs +
|
2016-11-18 00:53:00 +00:00
|
|
|
|
|
|
|
ToggleChar
|
|
|
|
lda #"Q" ;self-modified
|
|
|
|
|
|
|
|
+ ldx MyCH + 1
|
|
|
|
|
|
|
|
ScreenBuff3
|
|
|
|
sta $34f3, x ;self-modified
|
|
|
|
|
|
|
|
;timing is taken from extended ROM
|
|
|
|
;code is optimised for size
|
|
|
|
|
|
|
|
ldx #$31
|
|
|
|
ldy #0
|
|
|
|
- bit KBD
|
|
|
|
bmi +
|
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
bcc CharDel
|
|
|
|
+ bcs ToggleCarry ;restore original character, also on exit
|
|
|
|
lda KBD
|
|
|
|
bit STROBE
|
|
|
|
rts
|
2016-10-26 21:02:52 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
;print anything that isn't a special key
|
|
|
|
;wrap around screen position when we hit edges
|
2016-11-16 06:56:26 +00:00
|
|
|
|
2016-10-26 21:02:52 +00:00
|
|
|
EditorMode
|
2016-11-01 05:14:14 +00:00
|
|
|
jsr MyKEYIN
|
2016-11-18 00:53:00 +00:00
|
|
|
ldx #(KeyTable_e - KeyTable_b)
|
|
|
|
- ldy DispatchTableLow, x
|
|
|
|
sty DispatchCommand + 1
|
|
|
|
ldy DispatchTableHigh, x
|
|
|
|
sty DispatchCommand + 2
|
|
|
|
dex
|
2016-11-23 00:39:34 +00:00
|
|
|
bmi +
|
2016-11-18 00:53:00 +00:00
|
|
|
cmp KeyTable_b, x
|
|
|
|
bne -
|
|
|
|
cpx #(IgnoreClear - KeyTable_b)
|
|
|
|
bcc DispatchCommand
|
2016-11-23 00:39:34 +00:00
|
|
|
+ cpx #(IgnoreDirty - KeyTable_b)
|
2016-11-18 19:05:16 +00:00
|
|
|
;save result in carry
|
2016-11-01 05:14:14 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;the first keypress that clears the screen is also a trigger that the first page is dirty
|
|
|
|
;we require this trigger to allow us to work around a bug in Diversi-DOS
|
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
ClearOnFirstKeypress
|
2016-11-18 00:53:00 +00:00
|
|
|
ldy #0 ;self-modified
|
2016-11-01 05:14:14 +00:00
|
|
|
beq +
|
|
|
|
dec ClearOnFirstKeypress + 1
|
2016-11-23 06:40:43 +00:00
|
|
|
php ;save carry (don't care about the rest)
|
2016-11-18 19:05:16 +00:00
|
|
|
pha
|
2016-12-02 19:28:29 +00:00
|
|
|
jsr ClearScreen ;returns Y=FF
|
|
|
|
sty PreventAddPage + 1 ;trigger first write
|
2016-11-18 19:05:16 +00:00
|
|
|
pla
|
|
|
|
plp ;restore carry
|
2016-11-18 00:53:00 +00:00
|
|
|
+ bcc DispatchCommand
|
2016-12-02 19:28:29 +00:00
|
|
|
sta WriteIfDirty2 + 1 ;remember if page was modified in the general case
|
2016-11-18 00:53:00 +00:00
|
|
|
|
|
|
|
DispatchCommand
|
2016-11-23 06:40:43 +00:00
|
|
|
jsr $34f3 ;self-modified, currently both bytes
|
2016-11-18 19:05:16 +00:00
|
|
|
;but could be just one if all routines begin in the same page...
|
2016-11-18 00:53:00 +00:00
|
|
|
jmp EditorMode
|
2016-11-16 18:57:20 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
SetTextCoords1
|
|
|
|
ldx SaveCH
|
|
|
|
ldy SaveCV
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
SetTextCoords2 ;called with X/Y=horizontal/vertical coords to set
|
2016-11-23 00:39:34 +00:00
|
|
|
stx MyCH + 1
|
|
|
|
sty MyCV + 1
|
|
|
|
bpl MyBASCALC ;always
|
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
_doneEditorMode
|
2016-11-18 00:53:00 +00:00
|
|
|
pla
|
|
|
|
pla
|
|
|
|
|
|
|
|
DispatchReturn
|
2016-10-31 15:11:32 +00:00
|
|
|
rts
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
MyCOUT ;called with A=character to print
|
2016-11-18 19:05:16 +00:00
|
|
|
MyCH
|
|
|
|
ldx #"Q" ;self-modified
|
|
|
|
|
|
|
|
ScreenBuff4
|
|
|
|
sta $34f3, x ;self-modified
|
|
|
|
inx
|
|
|
|
cpx #WIDTH
|
|
|
|
bne SetCH
|
|
|
|
ldx #0
|
|
|
|
MyCV
|
|
|
|
ldy #"Q" ;self-modified
|
2016-12-02 19:28:29 +00:00
|
|
|
iny ;move to next line on horizontal typed wraparound
|
2016-11-18 19:05:16 +00:00
|
|
|
cpy #(HEIGHT - 1)
|
|
|
|
bne MyBASCALC
|
2016-12-02 19:28:29 +00:00
|
|
|
ldy #0 ;move to top left on vertical typed wraparound
|
|
|
|
beq MyBASCALC ;always
|
2016-11-18 19:05:16 +00:00
|
|
|
|
2016-10-31 15:11:32 +00:00
|
|
|
HandleKeyLineLeft
|
2016-11-01 05:14:14 +00:00
|
|
|
dec MyCH + 1
|
2016-11-18 00:53:00 +00:00
|
|
|
bpl DispatchReturn
|
2016-12-02 19:28:29 +00:00
|
|
|
lda #(WIDTH - 1) ;wrap to same line on horizontal arrow wraparound
|
2016-10-28 16:09:53 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
SetColumn
|
|
|
|
sta MyCH + 1
|
2016-11-18 00:53:00 +00:00
|
|
|
bpl DispatchReturn ;always
|
2016-10-28 16:09:53 +00:00
|
|
|
|
2016-10-31 15:11:32 +00:00
|
|
|
HandleKeyLineRight
|
2016-11-01 05:14:14 +00:00
|
|
|
inc MyCH + 1
|
|
|
|
lda MyCH + 1
|
2016-10-28 16:09:53 +00:00
|
|
|
eor #WIDTH ;zero on match
|
2016-11-18 00:53:00 +00:00
|
|
|
bne DispatchReturn
|
2016-12-02 19:28:29 +00:00
|
|
|
beq SetColumn ;always, wrap to same line on horizontal arrow wraparound
|
2016-10-28 16:09:53 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
HandleKeyLineUp
|
2016-11-01 17:08:48 +00:00
|
|
|
ldy MyCV + 1
|
|
|
|
dey
|
2016-11-01 05:14:14 +00:00
|
|
|
bpl SetRow
|
|
|
|
ldy #(HEIGHT - 2)
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
SetRow
|
|
|
|
ldx MyCH + 1
|
2016-11-18 19:05:16 +00:00
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
MyBASCALC ;called with Y=line number to resolve
|
2016-11-18 19:05:16 +00:00
|
|
|
sty MyCV + 1
|
|
|
|
lda TextCalcLo, y
|
|
|
|
sta ScreenBuff2 + 1
|
|
|
|
sta ScreenBuff3 + 1
|
|
|
|
sta ScreenBuff4 + 1
|
|
|
|
lda TextCalcHi, y
|
|
|
|
sta ScreenBuff2 + 2
|
|
|
|
sta ScreenBuff3 + 2
|
|
|
|
sta ScreenBuff4 + 2
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-11-18 19:05:16 +00:00
|
|
|
SetCH
|
|
|
|
stx MyCH + 1
|
|
|
|
rts
|
2016-10-31 15:11:32 +00:00
|
|
|
|
|
|
|
HandleKeyClearScreen
|
2016-11-16 18:57:20 +00:00
|
|
|
jsr ClearScreen
|
2016-11-01 05:14:14 +00:00
|
|
|
dey ;-2
|
|
|
|
sty MyCV + 1 ;use big store to trigger wraparound
|
|
|
|
;fall through
|
|
|
|
|
|
|
|
HandleKeyReturn
|
|
|
|
lda #0
|
2016-12-02 19:28:29 +00:00
|
|
|
sta MyCH + 1 ;move to left of next line on return
|
2016-11-01 05:14:14 +00:00
|
|
|
;fall through
|
|
|
|
|
|
|
|
HandleKeyLineDown
|
|
|
|
ldy MyCV + 1
|
|
|
|
iny
|
2016-11-23 00:39:34 +00:00
|
|
|
cpy #(HEIGHT - 1)
|
2016-11-01 05:14:14 +00:00
|
|
|
bcc SetRow ;not BNE to allow big store use
|
|
|
|
ldy #0
|
|
|
|
beq SetRow ;always
|
2016-10-31 15:11:32 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
;clear real screen
|
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
ClearScreen ; does not clear status line
|
|
|
|
clc
|
2016-11-01 05:14:14 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
;copy from virtual buffer to real screen
|
|
|
|
;;todo: add camera flash and click effect ;-)
|
2016-11-18 00:53:00 +00:00
|
|
|
HandleKeyImportScreen ;called with carry set
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #<(LoadSaveEnd - WIDTH)
|
2016-11-18 00:53:00 +00:00
|
|
|
sta OPSRC1L
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #>(LoadSaveEnd - WIDTH)
|
2016-11-18 00:53:00 +00:00
|
|
|
sta OPSRC1H
|
2016-11-01 05:14:14 +00:00
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
ldx #(HEIGHT - 2)
|
|
|
|
-- jsr SetTextCalc
|
|
|
|
ldy #(WIDTH - 1)
|
2016-12-02 19:28:29 +00:00
|
|
|
lda #SPACE
|
2016-11-18 00:53:00 +00:00
|
|
|
- bcc + ;ClearScreen path
|
|
|
|
lda (OPSRC1L), y
|
|
|
|
+ sta (OPSRC2L), y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
bcc + ;ClearScreen path
|
2016-11-01 05:14:14 +00:00
|
|
|
sec
|
2016-11-18 00:53:00 +00:00
|
|
|
lda OPSRC1L
|
|
|
|
sbc #WIDTH
|
|
|
|
sta OPSRC1L
|
2016-11-01 05:14:14 +00:00
|
|
|
bcs +
|
2016-11-18 00:53:00 +00:00
|
|
|
dec OPSRC1H
|
2016-11-18 19:05:16 +00:00
|
|
|
sec ;maintain carry for ImportScreen path
|
2016-11-18 00:53:00 +00:00
|
|
|
+ dex
|
|
|
|
bpl --
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
PageReturn
|
|
|
|
rts
|
|
|
|
|
|
|
|
;write an empty page to disk
|
|
|
|
;then select that page
|
|
|
|
|
|
|
|
HandleKeyAddPage
|
2016-12-02 19:28:29 +00:00
|
|
|
PreventAddPage
|
2016-11-26 00:22:03 +00:00
|
|
|
lda #0 ;self-modified
|
2016-12-02 19:28:29 +00:00
|
|
|
beq + ;page 1 exists already, go directly to add
|
|
|
|
bpl PageReturn ;page 1 doesn't exist and nothing to write
|
|
|
|
|
|
|
|
;Diversi-DOS (not DOS 3.3) has a critical bug when writing to a newly-created file
|
|
|
|
;if the first write occurs beyond the first sector, then no preceding entries are created in the TS list!
|
|
|
|
;instead, it leaves the entries blank, causing read errors when attempting to read earlier content
|
|
|
|
;the disk space is also not reclaimed when deleting the file because the TS list looks empty
|
|
|
|
;to work around this, we detect when we are writing to the file for the first time,
|
|
|
|
;and just force the write to occur before the page is added
|
|
|
|
|
|
|
|
jsr WriteIfDirty2 ;page 1 is ready to write for the first time
|
|
|
|
|
|
|
|
;the problem is that the wrong screen was active at the time that we wrote the initial content
|
|
|
|
;so we have to perform a second write after the screen is scrolled properly
|
|
|
|
;performance is bad, but fortunately it's a one-time thing
|
|
|
|
|
|
|
|
inc WriteIfDirty2 + 1 ;force it to write again
|
|
|
|
+ lda Pages + 1
|
2016-11-25 18:50:23 +00:00
|
|
|
cmp #(99 - 1) ;maximum 99 pages
|
|
|
|
beq PageReturn
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr ExchangeVirtualBuffer
|
|
|
|
sec
|
|
|
|
jsr ClearVirtualBuffer
|
|
|
|
jsr OpenDataFile
|
|
|
|
inc Pages + 1
|
|
|
|
jsr SetPrevPage ;returns A=Pages
|
|
|
|
sta CurPage + 1
|
|
|
|
tax
|
|
|
|
lda MyCH + 1
|
|
|
|
pha
|
|
|
|
lda MyCV + 1
|
|
|
|
pha
|
|
|
|
lda #0
|
|
|
|
sta MyCH + 1
|
|
|
|
sta MyCV + 1
|
|
|
|
jsr SeekReadWrite
|
|
|
|
pla
|
|
|
|
sta MyCV + 1
|
|
|
|
pla
|
|
|
|
sta MyCH + 1
|
|
|
|
sec
|
|
|
|
php ;save carry (don't care about the rest)
|
|
|
|
bcs +++ ;always
|
|
|
|
|
|
|
|
;move to next page if possible
|
|
|
|
|
|
|
|
HandleKeyNextPage
|
|
|
|
jsr SetPrevPage
|
|
|
|
|
|
|
|
Pages
|
|
|
|
lda #0 ;self-modified
|
|
|
|
beq PageReturn
|
|
|
|
inc CurPage + 1
|
|
|
|
|
|
|
|
CurPage
|
|
|
|
cmp #0 ;self-modified
|
|
|
|
bcs ++
|
|
|
|
|
|
|
|
;or wrap to first page
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
sec
|
|
|
|
bcs + ;always
|
|
|
|
|
|
|
|
;move to previous page if possible
|
|
|
|
|
|
|
|
HandleKeyPrevPage
|
|
|
|
jsr SetPrevPage ;returns A=Pages, Z/NZ state of Pages
|
|
|
|
beq PageReturn
|
|
|
|
clc
|
|
|
|
dec CurPage + 1
|
|
|
|
bpl ++
|
|
|
|
|
|
|
|
;or wrap to last page
|
|
|
|
|
|
|
|
+ sta CurPage + 1
|
|
|
|
++ php ;save carry (don't care about the rest)
|
|
|
|
jsr ExchangeVirtualBuffer
|
2016-11-23 05:20:20 +00:00
|
|
|
|
|
|
|
;update header to specify new page count and current page
|
|
|
|
|
|
|
|
+++ jsr LoadSaveHeader
|
2016-12-02 19:28:29 +00:00
|
|
|
|
|
|
|
;Diversi-DOS has a critical bug when reading from a just-written sector
|
|
|
|
;IT RETURNS THE ORIGINAL DATA UNLESS YOU CLOSE THE FILE AND RE-OPEN IT
|
|
|
|
;so that's what we do
|
|
|
|
|
|
|
|
jsr CloseFile
|
|
|
|
jsr OpenDataFile
|
|
|
|
|
2016-11-23 06:40:43 +00:00
|
|
|
dec ReadWriteCmd ;lda #CMDREAD / sta ReadWriteCmd
|
2016-11-23 00:39:34 +00:00
|
|
|
lda ReadBuffer
|
|
|
|
pha
|
|
|
|
adc #WIDTH
|
|
|
|
sta ReadBuffer
|
|
|
|
lda ReadBuffer + 1
|
|
|
|
pha
|
|
|
|
adc #0
|
|
|
|
sta ReadBuffer + 1
|
2016-11-23 05:20:20 +00:00
|
|
|
ldx SaveCV
|
2016-11-23 00:39:34 +00:00
|
|
|
jsr SeekReadWrite
|
|
|
|
pla
|
|
|
|
sta ReadBuffer + 1
|
|
|
|
pla
|
|
|
|
sta ReadBuffer
|
2016-11-23 06:40:43 +00:00
|
|
|
inc ReadWriteCmd ;lda #CMDWRITE / sta ReadWriteCmd
|
2016-11-23 00:39:34 +00:00
|
|
|
plp ;restore carry
|
|
|
|
lda SaveCH + WIDTH
|
|
|
|
pha
|
|
|
|
lda SaveCV + WIDTH
|
|
|
|
pha
|
|
|
|
|
|
|
|
bcc + ;the PrevPage path
|
|
|
|
|
|
|
|
jsr ScrollEditBufferLeft ;returns Z
|
|
|
|
beq ++ ;always
|
|
|
|
|
|
|
|
+ jsr ScrollEditBufferRight
|
|
|
|
|
|
|
|
++ jsr WriteIfDirty2
|
|
|
|
ldy CurPage + 1
|
|
|
|
jsr PrintPage
|
|
|
|
|
|
|
|
pla
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
jsr SetTextCoords2
|
2016-11-23 23:17:30 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;fall through to restore buffer
|
|
|
|
|
2016-11-23 23:17:30 +00:00
|
|
|
;copy virtual buffer to another virtual buffer
|
|
|
|
;hack existing buffer copy to redirect target,
|
|
|
|
;since it copies exactly the size that we want
|
|
|
|
|
|
|
|
ExchangeVirtualBuffer
|
|
|
|
lda #>(TEMPBUFFER - <(LoadSaveStart - LastLine))
|
|
|
|
sta ExchangeBankedPatch + 1
|
2016-12-02 19:28:29 +00:00
|
|
|
clc ;enable full path even if not Diversi-DOS
|
2016-11-23 23:17:30 +00:00
|
|
|
jsr ExchangeBanked1 + 1
|
|
|
|
lda #>(SWAPBUFFER - <(LoadSaveStart - LastLine))
|
|
|
|
sta ExchangeBankedPatch + 1
|
|
|
|
rts
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
SetPrevPage
|
|
|
|
lda CurPage + 1
|
|
|
|
sta PrevPage + 1
|
|
|
|
lda Pages + 1
|
2016-11-18 19:05:16 +00:00
|
|
|
rts
|
2016-11-01 05:14:14 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;turn everything to inverse or normal
|
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
HandleKeyHighlight
|
|
|
|
ldx MyCV + 1
|
|
|
|
jsr SetTextCalc
|
|
|
|
ldy #(WIDTH - 1)
|
|
|
|
- lda (OPSRC2L), y
|
2016-11-18 19:05:16 +00:00
|
|
|
|
|
|
|
;lowercase to uppercase
|
|
|
|
;otherwise it's unreadable when inverted
|
|
|
|
;however, the conversion is not reversible
|
|
|
|
|
|
|
|
cmp #$E0
|
|
|
|
bcc +
|
|
|
|
and #$DF
|
|
|
|
|
|
|
|
;normal range to control range
|
|
|
|
|
|
|
|
+ and #$BF
|
|
|
|
|
|
|
|
;invert character and print if inverse
|
|
|
|
|
2016-11-18 00:53:00 +00:00
|
|
|
eor #$80
|
2016-11-18 19:05:16 +00:00
|
|
|
bpl +
|
|
|
|
|
|
|
|
;control range to normal range
|
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
cmp #SPACE
|
2016-11-18 19:05:16 +00:00
|
|
|
bcs +
|
|
|
|
ora #$40
|
|
|
|
|
|
|
|
+ sta (OPSRC2L), y
|
2016-11-01 05:14:14 +00:00
|
|
|
dey
|
2016-11-18 00:53:00 +00:00
|
|
|
bpl -
|
2016-10-31 15:11:32 +00:00
|
|
|
rts
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-23 07:30:18 +00:00
|
|
|
ScrollEditBufferLeft ;called with carry set
|
2016-11-23 00:39:34 +00:00
|
|
|
lda #-WIDTH
|
|
|
|
sta SCROLLLINE
|
|
|
|
ldx #(WIDTH - 1)
|
|
|
|
ldy #0
|
|
|
|
lda #(<(ScrollParmsLeft - ScrollParms) - 1)
|
|
|
|
bcs + ;always
|
|
|
|
|
2016-11-23 07:30:18 +00:00
|
|
|
ScrollEditBufferRight ;called with carry clear
|
2016-11-23 00:39:34 +00:00
|
|
|
ldx #0
|
|
|
|
ldy #(WIDTH - 1)
|
|
|
|
sty SCROLLLINE
|
|
|
|
lda #(<(ScrollParmsRight - ScrollParms) - 1)
|
2016-11-23 07:30:18 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
+ sta ScrollEditPatch1 + 1
|
|
|
|
stx ScrollEditPatch2 + 1
|
|
|
|
|
|
|
|
;copy first/last column on screen to stack (no temporary buffer available)
|
|
|
|
|
|
|
|
-- php ;save carry (don't care about the rest)
|
|
|
|
ldx #(HEIGHT - 2)
|
|
|
|
- jsr SetTextCalc
|
|
|
|
lda (OPSRC2L), y
|
|
|
|
pha
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
bcc + ;the ScrollRight path
|
|
|
|
|
|
|
|
;copy each column on screen to previous column
|
|
|
|
|
|
|
|
jsr ScrollTextScreenLeft ;returns carry set
|
|
|
|
bcs ScrollEditPatch1 ;always
|
|
|
|
|
|
|
|
;copy each column on screen to next column
|
|
|
|
|
|
|
|
+ jsr ScrollTextScreenRight ;maintains carry (clear)
|
|
|
|
|
|
|
|
;copy first column of edit buffer to last column on screen
|
|
|
|
;or
|
|
|
|
;copy last column of edit buffer to first column on screen
|
|
|
|
|
|
|
|
ScrollEditPatch1
|
|
|
|
ldy #"Q" ;self-modified
|
|
|
|
jsr SetScrollParms
|
|
|
|
ldx #(HEIGHT - 2)
|
|
|
|
- jsr SetTextCalc
|
|
|
|
ldy SCROLLLINE
|
|
|
|
lda (OPSRC1L), y
|
2016-11-23 07:30:18 +00:00
|
|
|
jsr CharMap2
|
2016-11-23 00:39:34 +00:00
|
|
|
ScrollEditPatch2
|
|
|
|
ldy #"Q" ;self-modified
|
|
|
|
sta (OPSRC2L), y
|
|
|
|
lda OPSRC1L
|
|
|
|
sec
|
|
|
|
sbc #WIDTH
|
|
|
|
sta OPSRC1L
|
|
|
|
bcs +
|
|
|
|
dec OPSRC1H
|
|
|
|
+ dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
;place saved column in edit buffer
|
|
|
|
|
|
|
|
ldy SCROLLLINE
|
|
|
|
ldx #(HEIGHT - 2)
|
|
|
|
- pla
|
|
|
|
sta (OPDST1L), y
|
|
|
|
lda OPDST1L
|
|
|
|
clc
|
|
|
|
adc #WIDTH
|
|
|
|
sta OPDST1L
|
|
|
|
bcc +
|
|
|
|
inc OPDST1H
|
|
|
|
+ dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
;animation delay
|
|
|
|
|
|
|
|
jsr Delay ;returns A=0
|
|
|
|
plp ;restore carry
|
|
|
|
bcc + ;the ScrollRight path
|
|
|
|
tay
|
|
|
|
inc SCROLLLINE
|
|
|
|
bne --
|
|
|
|
rts
|
|
|
|
|
|
|
|
+ ldy #(WIDTH - 1)
|
|
|
|
dec SCROLLLINE
|
|
|
|
bpl --
|
|
|
|
rts
|
|
|
|
|
|
|
|
ScrollTextScreenLeft
|
|
|
|
ldy #1
|
|
|
|
- lda #$88 ;DEY
|
|
|
|
jsr CopyColumn
|
|
|
|
iny
|
|
|
|
cpy #WIDTH
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
|
|
|
|
ScrollTextScreenRight
|
|
|
|
ldy #(WIDTH - 2)
|
|
|
|
- lda #$C8 ;INY
|
|
|
|
jsr CopyColumn
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
2016-11-23 05:20:20 +00:00
|
|
|
CopyColumn ;called with A=opcode to specify direction
|
2016-11-23 00:39:34 +00:00
|
|
|
sta CopyColumnPatch1
|
|
|
|
eor #$40
|
|
|
|
sta CopyColumnPatch2
|
|
|
|
ldx #(HEIGHT - 2)
|
|
|
|
- jsr SetTextCalc
|
|
|
|
lda (OPSRC2L), y
|
|
|
|
CopyColumnPatch1
|
|
|
|
nop ;self-modified to DEY/INY
|
|
|
|
sta (OPSRC2L), y
|
|
|
|
CopyColumnPatch2
|
|
|
|
nop ;self-modified to INY/DEY
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
|
|
|
WriteIfDirty1
|
|
|
|
jsr SetPrevPage
|
|
|
|
|
|
|
|
WriteIfDirty2
|
|
|
|
lda #"Q" ;self-modified
|
|
|
|
beq OpenReturn
|
|
|
|
lda #0
|
|
|
|
sta WriteIfDirty2 + 1
|
|
|
|
|
|
|
|
jsr OpenDataFile
|
|
|
|
|
|
|
|
PrevPage
|
|
|
|
ldx #0 ;self-modified
|
|
|
|
|
|
|
|
SeekReadWrite ;also writes, called with X=page to read/write
|
|
|
|
lda #<(FirstLine - LoadSaveStart)
|
|
|
|
ldy #>(FirstLine - LoadSaveStart)
|
|
|
|
- dex
|
|
|
|
bmi +
|
|
|
|
clc
|
|
|
|
adc #<(LoadSaveEnd - LoadSaveStart)
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
adc #>(LoadSaveEnd - LoadSaveStart)
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
bcc - ;always
|
|
|
|
+ sta WriteOffset ;also ReadOffset
|
|
|
|
sty WriteOffset + 1 ;also ReadOffset
|
|
|
|
lda #<(LoadSaveEnd - LoadSaveStart)
|
|
|
|
sta WriteSize ;also ReadSize
|
|
|
|
lda #>(LoadSaveEnd - LoadSaveStart)
|
|
|
|
sta WriteSize + 1 ;also ReadSize
|
2016-11-01 05:14:14 +00:00
|
|
|
lda MyCH + 1
|
2016-10-30 19:17:45 +00:00
|
|
|
sta SaveCH
|
2016-11-01 05:14:14 +00:00
|
|
|
lda MyCV + 1
|
2016-10-30 19:17:45 +00:00
|
|
|
sta SaveCV
|
2016-12-02 19:28:29 +00:00
|
|
|
jsr WriteFileBuff ;also used by ReadFile
|
2016-11-23 05:20:20 +00:00
|
|
|
|
|
|
|
CloseFile
|
2016-11-01 05:14:14 +00:00
|
|
|
jsr DOSMLI
|
|
|
|
!byte CloseMLI_e - CloseMLI_b
|
|
|
|
CloseMLI_b
|
|
|
|
!byte CMDCLOSE
|
|
|
|
CloseMLI_e
|
2016-11-10 23:35:25 +00:00
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
OpenReturn
|
|
|
|
rts
|
|
|
|
|
|
|
|
;open the file, load/save the page count and current page
|
2016-12-02 19:28:29 +00:00
|
|
|
;leaves the file open for additional accesses
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
LoadSaveHeader
|
|
|
|
jsr OpenDataFile
|
|
|
|
bcs OpenReturn
|
|
|
|
lda #2
|
|
|
|
sta WriteSize ;also ReadSize
|
|
|
|
lda #0
|
|
|
|
sta WriteOffset ;also ReadOffset
|
|
|
|
sta WriteOffset + 1 ;also ReadOffset
|
|
|
|
sta WriteSize + 1 ;also ReadSize
|
|
|
|
lda Pages + 1
|
|
|
|
sta SaveCH
|
|
|
|
lda CurPage + 1
|
|
|
|
sta SaveCV
|
2016-12-02 19:28:29 +00:00
|
|
|
|
|
|
|
WriteFileBuff
|
|
|
|
lda ReadWriteCmd
|
|
|
|
lsr ;read has bit 0 set, write does not
|
|
|
|
bcs JumpFileIO
|
|
|
|
|
|
|
|
PatchDiversi
|
|
|
|
bcs InitDiversiWrite ;self-modified to BCC if Diversi-DOS
|
|
|
|
|
|
|
|
;write size must be one less than required value because of course it must
|
|
|
|
|
|
|
|
AdjustWriteSize
|
|
|
|
lda WriteSize
|
|
|
|
bne +
|
|
|
|
dec WriteSize + 1
|
|
|
|
+ dec WriteSize
|
|
|
|
|
|
|
|
JumpFileIO
|
2016-11-23 05:20:20 +00:00
|
|
|
jmp WriteFile ;also ReadFile
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-12-02 19:28:29 +00:00
|
|
|
;Diversi-DOS (not DOS 3.3) has a critical bug when writing within a sector
|
|
|
|
;the bug is that it does not read the original sector and then replace the data before writing
|
|
|
|
;instead, it uses the last-read sector to supply the content to replace!
|
|
|
|
;to work around this, we detect when we are writing within a sector
|
|
|
|
;that can be either the write offset is non-zero, and/or the low size is non-zero
|
|
|
|
;in either case, we perform as expected: read the original sector, replace the content, write the sector
|
|
|
|
|
|
|
|
InitDiversiWrite
|
|
|
|
jsr ExchangeSectorBuffer
|
|
|
|
lda WriteSize
|
|
|
|
sta WriteSizeLow + 1
|
|
|
|
lda WriteSize + 1
|
|
|
|
sta WriteSizeHigh + 1
|
|
|
|
lda WriteOffset
|
|
|
|
sta DiversiWriteBuffer + 1
|
2016-12-03 22:03:58 +00:00
|
|
|
!if (SWAPSIZEALIGNED = 0) {
|
2016-12-02 19:28:29 +00:00
|
|
|
dec WriteBuffer + 1
|
|
|
|
}
|
|
|
|
lda #<LoadSaveStart
|
|
|
|
sta DiversiReadBuffer + 1
|
|
|
|
lda #>LoadSaveStart
|
|
|
|
sta DiversiReadBuffer + 2
|
|
|
|
|
|
|
|
;disable swapping temporarily
|
|
|
|
|
|
|
|
lda #$60 ;RTS
|
|
|
|
sta ExchangeBanked1
|
|
|
|
|
|
|
|
;read the existing sector
|
|
|
|
|
|
|
|
FixDiversiWrite
|
|
|
|
ldx #0
|
|
|
|
stx ReadSize
|
|
|
|
stx ReadOffset
|
|
|
|
inx
|
|
|
|
stx ReadSize + 1
|
|
|
|
dec ReadWriteCmd ;lda #CMDREAD / sta ReadWriteCmd
|
|
|
|
jsr ReadFileNoXchg
|
|
|
|
inc ReadWriteCmd ;lda #CMDWRITE / sta ReadWriteCmd
|
|
|
|
|
|
|
|
;replace existing content
|
|
|
|
;slow copy operation, but it works
|
|
|
|
|
|
|
|
DiversiReadBuffer
|
|
|
|
lda $34f3 ;self-modified
|
|
|
|
inc DiversiReadBuffer + 1
|
|
|
|
bne DiversiWriteBuffer
|
|
|
|
inc DiversiReadBuffer + 2
|
|
|
|
|
|
|
|
DiversiWriteBuffer
|
|
|
|
sta (SWAPBUFFER - <(LoadSaveStart - LastLine)) and $FF00
|
|
|
|
;low byte is self-modified
|
|
|
|
ldx WriteSizeLow + 1
|
|
|
|
bne +
|
|
|
|
dec WriteSizeHigh + 1
|
|
|
|
+ dex
|
|
|
|
stx WriteSizeLow + 1
|
|
|
|
txa
|
|
|
|
ora WriteSizeHigh + 1
|
|
|
|
beq +
|
|
|
|
inc DiversiWriteBuffer + 1
|
|
|
|
bne DiversiReadBuffer
|
|
|
|
|
|
|
|
;reaching this path means that we copy an entire sector on next pass
|
|
|
|
;but it happens only twice currently, which seems to be acceptable
|
|
|
|
;and it reduces the complexity of the code
|
|
|
|
+
|
|
|
|
;write new sector
|
|
|
|
|
|
|
|
jsr AdjustWriteSize
|
|
|
|
inc WriteOffset + 1
|
|
|
|
|
|
|
|
WriteSizeLow
|
|
|
|
lda #"Q" ;self-modified
|
|
|
|
|
|
|
|
WriteSizeHigh
|
|
|
|
ora #"Q" ;self-modified
|
|
|
|
bne FixDiversiWrite
|
|
|
|
|
|
|
|
;re-enable swapping
|
|
|
|
|
2016-12-03 22:03:58 +00:00
|
|
|
!if (SWAPSIZEALIGNED = 0) {
|
2016-12-02 19:28:29 +00:00
|
|
|
inc WriteBuffer + 1
|
|
|
|
}
|
|
|
|
lda #$18 ;CLC
|
|
|
|
sta ExchangeBanked1
|
|
|
|
|
|
|
|
;fall through to restore buffer
|
|
|
|
|
|
|
|
ExchangeSectorBuffer
|
|
|
|
lda #>SECTORBUFFER
|
|
|
|
sta OPDST1H
|
|
|
|
lda #0
|
|
|
|
tax
|
|
|
|
tay
|
|
|
|
sta OPSRC1L
|
|
|
|
jmp ExchangeBankedSet
|
|
|
|
|
2016-10-30 01:17:18 +00:00
|
|
|
TextCalcHi
|
|
|
|
!byte $04, $04, $05, $05, $06, $06, $07, $07
|
|
|
|
!byte $04, $04, $05, $05, $06, $06, $07, $07
|
|
|
|
!byte $04, $04, $05, $05, $06, $06, $07, $07
|
|
|
|
TextCalcLo
|
|
|
|
!byte $00, $80, $00, $80, $00, $80, $00, $80
|
|
|
|
!byte $28, $A8, $28, $A8, $28, $A8, $28, $A8
|
|
|
|
!byte $50, $D0, $50, $D0, $50, $D0, $50, $D0
|
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
ScrollParms
|
2016-11-18 00:53:00 +00:00
|
|
|
!word LastLine, LastLine - WIDTH
|
2016-11-23 00:39:34 +00:00
|
|
|
ScrollParmsDown ;meaningful labels for last character instead of first
|
2016-11-18 00:53:00 +00:00
|
|
|
|
|
|
|
!word FirstLine, FirstLine + WIDTH
|
2016-11-23 00:39:34 +00:00
|
|
|
ScrollParmsUp
|
|
|
|
|
|
|
|
!byte <(LoadSaveEnd + WIDTH), >(LoadSaveEnd - <(LoadSaveEnd + WIDTH)), <(FirstLine + WIDTH), >(FirstLine - <(FirstLine + WIDTH))
|
|
|
|
ScrollParmsLeft
|
|
|
|
|
|
|
|
!word LoadSaveEnd, FirstLine
|
|
|
|
ScrollParmsRight
|
2016-11-18 00:53:00 +00:00
|
|
|
|
|
|
|
KeyTable_b
|
|
|
|
!byte HOTKEY, ESC
|
2016-11-23 00:39:34 +00:00
|
|
|
IgnoreClear ;everything above this line will not clear title screen
|
|
|
|
!byte LTARROW, DNARROW, UPARROW, RTARROW, RETURN, ADDPAGEKEY, NEXTPAGEKEY, PREVPAGEKEY
|
|
|
|
IgnoreDirty ;everything above this line will not trigger a save on their own
|
|
|
|
;the page keys will save the previous page if it was dirty
|
2016-11-18 00:53:00 +00:00
|
|
|
!byte IMPORTKEY, CLEARKEY, HIGHLIGHTKEY
|
|
|
|
KeyTable_e
|
|
|
|
|
|
|
|
DispatchTableLow
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte <MyCOUT ;catch-all entry, the rest follow the KeyTable ordering
|
2016-11-18 00:53:00 +00:00
|
|
|
!byte <_doneEditorMode, <_doneEditorMode
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte <HandleKeyLineLeft, <HandleKeyLineDown, <HandleKeyLineUp, <HandleKeyLineRight, <HandleKeyReturn, <HandleKeyAddPage, <HandleKeyNextPage, <HandleKeyPrevPage
|
2016-11-18 00:53:00 +00:00
|
|
|
!byte <HandleKeyImportScreen, <HandleKeyClearScreen, <HandleKeyHighlight
|
|
|
|
|
|
|
|
DispatchTableHigh
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte >MyCOUT ;catch-all entry, the rest follow the KeyTable ordering
|
2016-11-18 00:53:00 +00:00
|
|
|
!byte >_doneEditorMode, >_doneEditorMode
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte >HandleKeyLineLeft, >HandleKeyLineDown, >HandleKeyLineUp, >HandleKeyLineRight, >HandleKeyReturn, >HandleKeyAddPage, >HandleKeyNextPage, >HandleKeyPrevPage
|
2016-11-18 00:53:00 +00:00
|
|
|
!byte >HandleKeyImportScreen, >HandleKeyClearScreen, >HandleKeyHighlight
|
|
|
|
|
2016-11-23 00:39:34 +00:00
|
|
|
LoadSaveStart ;replaced by file content if exists
|
2016-10-30 19:17:45 +00:00
|
|
|
SaveCH
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte 0
|
2016-10-30 19:17:45 +00:00
|
|
|
SaveCV
|
2016-11-23 00:39:34 +00:00
|
|
|
!byte 0
|
|
|
|
|
|
|
|
;our screen contains 23 user-defined lines
|
|
|
|
;the 24th line is reserved for the status bar
|
|
|
|
;however, we define an extra line for better vertical scrolling performance
|
|
|
|
;it works like this to scroll down:
|
|
|
|
|
|
|
|
;the last line on the screen is copied into the extra line in this buffer;
|
|
|
|
;the screen is scrolled down;
|
|
|
|
;the last line in the virtual buffer is copied into the first line of the screen;
|
|
|
|
;the last line on the screen (was the second-last line on the original screen) is copied into the last line in this buffer;
|
|
|
|
;this copy overwrites the line in the virtual buffer that was just copied onto the screen;
|
|
|
|
;the screen is scrolled down;
|
|
|
|
;the second-last line in the virtual buffer is copied into the first line of the screen;
|
|
|
|
;...
|
|
|
|
;the last line on the screen (was the first line on the original screen) is copied into the second line in this buffer;
|
|
|
|
;the screen is scrolled down;
|
|
|
|
;the first line in the virtual buffer is copied into the first line of the screen;
|
|
|
|
|
|
|
|
;to scroll up, we reverse the order of the operations
|
|
|
|
|
|
|
|
;this allows us to copy whole lines without duplicating the entire screen or performing a content exchange
|
|
|
|
;...in case you were wondering...
|
|
|
|
|
|
|
|
;sigh, but it also introduces a problem with multi-screen support...
|
|
|
|
;which is that we load directly from file into this buffer but it requires that we load to the second line,
|
|
|
|
;instead of the first line, which was not the plan originally
|
|
|
|
;if only we had decided to scroll in the other way...
|
|
|
|
;is the design flaw in the scrolling or the reading? you decide.
|
2016-10-27 19:16:02 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
FirstLine ;lines are stored sequentially, not like text page in memory
|
2016-12-02 19:28:29 +00:00
|
|
|
!fill WIDTH, SPACE
|
2016-11-23 00:39:34 +00:00
|
|
|
|
|
|
|
SecondLine
|
2016-12-03 22:03:58 +00:00
|
|
|
!if (>SecondLine != >LoadSaveStart) {
|
2016-11-23 06:40:43 +00:00
|
|
|
!error "first two lines of text buffer must not cross a page"
|
|
|
|
}
|
2016-12-02 19:28:29 +00:00
|
|
|
!fill WIDTH * 7, SPACE
|
2016-11-08 04:53:07 +00:00
|
|
|
!text " 4LIVE by 4am && qkumba "
|
2016-12-02 19:28:29 +00:00
|
|
|
!fill WIDTH, SPACE
|
2016-11-23 23:17:30 +00:00
|
|
|
!text " Revision 03 / Serial number 161123 "
|
2016-12-02 19:28:29 +00:00
|
|
|
!fill WIDTH * 2, SPACE
|
2016-11-08 04:53:07 +00:00
|
|
|
!text " https://github.com/a2-4am/4live "
|
2016-12-02 19:28:29 +00:00
|
|
|
!fill WIDTH * 9, SPACE
|
2016-10-26 21:02:52 +00:00
|
|
|
|
2016-10-27 19:16:02 +00:00
|
|
|
LoadSaveEnd
|
2016-10-31 15:11:32 +00:00
|
|
|
!fill (WIDTH - 5), $20
|
2016-11-11 02:50:30 +00:00
|
|
|
!text "4LIVE"
|
2016-10-30 19:17:45 +00:00
|
|
|
|
2016-11-01 05:14:14 +00:00
|
|
|
LastLine
|
2016-12-02 19:28:29 +00:00
|
|
|
!fill WIDTH, SPACE
|
2016-11-23 00:39:34 +00:00
|
|
|
|
2016-11-23 06:40:43 +00:00
|
|
|
TEMPBUFFER=(*+255) and not 255
|
2016-12-03 22:03:58 +00:00
|
|
|
!ifdef PASS2 {
|
|
|
|
!if (TEMPBUFFER > $DB00) {
|
|
|
|
!error "banked code is too large, ends at ", *, ", ", *-$DB00, " bytes too many"
|
|
|
|
}
|
2016-11-23 06:40:43 +00:00
|
|
|
}
|
2016-12-02 19:28:29 +00:00
|
|
|
SECTORBUFFER=TEMPBUFFER+$400
|
2016-12-03 22:03:58 +00:00
|
|
|
!ifdef PASS2 {
|
|
|
|
!if (VERBOSE = 1) {
|
|
|
|
!warn "banked code end=", *, ", data end=", SECTORBUFFER+$FF, ", bytes free=", $DB00-*
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
;define pass-dependent label to reduce output noise
|
|
|
|
!set PASS2 = 1
|
2016-11-23 00:39:34 +00:00
|
|
|
}
|
2016-11-10 23:35:25 +00:00
|
|
|
}
|
|
|
|
BankedCopyEnd
|