refactor to reduce size

page 2 is now free after load
This commit is contained in:
Peter Ferrie 2016-11-15 22:56:26 -08:00
parent 715fca1992
commit 1986f5ce04

View File

@ -12,11 +12,6 @@
CLEARKEY = $8E ; CTRL-N
SAVEKEY = $93 ; CTRL-S
INSTALLBUFFER = $800 ; max 256 bytes, not preserved
SWAPBUFFER = $900 ; (LoadSaveEnd - LoadSaveStart) size
; needed by DiversiDOS, must be page-aligned
; region is preserved across calls
;
!addr KSWL = $38
!addr KSWH = $39
@ -37,11 +32,16 @@
!addr RDCHAR = $FD35
!addr COUT = $FDED
;private arbitrary addresses, currently shared with DOS to avoid conflict
!addr OPSRCL = $42
!addr OPSRCH = $43
!addr OPDSTL = $44
!addr OPDSTH = $45
;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
;constants
A2E = $06
@ -67,7 +67,11 @@
POSREADRANGE = 4
WIDTH = 40
HEIGHT = 24
LDRBASE = $2ae
LDRBASE = $2d9
INSTALLBUFFER = $800 ; max 256 bytes, not preserved
SWAPBUFFER = $900 ; (LoadSaveEnd - LoadSaveStart) size
; needed by DiversiDOS, must be page-aligned
; region is preserved across calls
*=LDRBASE-4
LdrHeader
@ -78,31 +82,6 @@ LdrHeader
;also carries proxy routines including file manager and banked RAM exchange for DiversiDOS
LdrStart
jsr GETIOB
sty OPSRCL
sta OPSRCH
;remember if DiversiDOS
cmp #$BF
php
bne +
lda LCBANK2
lda LCBANK2
+
;set slot and drive in MLI request packet
ldy #IOBDRIVE
lda (OPSRCL), y
sta FileDrive
dey ;ldy #IOBSLOT
lda (OPSRCL), y
lsr
lsr
lsr
lsr
sta FileSlot
;set filename pointer in MLI request packet
lda FCBFOP
@ -110,15 +89,26 @@ LdrStart
lda FCBFOP + 1
sta FileName + 1
;restore input name
;set slot and drive in MLI request packet
lda #"_"
jsr GETIOB
sty OPSRC1L
sta OPSRC1H
ldy #IOBDRIVE
lda (OPSRC1L), y
sta FileDrive
dey ;ldy #IOBSLOT
lda (OPSRC1L), y
lsr
lsr
lsr
lsr
sta FileSlot
dey ;ldy #00
sta (FCBFOP), y
;open self and read first overlay
jsr OpenFile
jsr OpenMainFile
jsr DOSMLI
!byte LdrReadMLI_e - LdrReadMLI_b
LdrReadMLI_b
@ -141,21 +131,23 @@ LdrReadMLI_e
;set input name
OpenDataFile
lda LCBANK2
lda LCBANK2
ldy #(NAMELEN - 1)
OpenMainFile
lda FileName
sta OPDSTL
sta OPDST1L
lda FileName + 1
sta OPDSTH
sta OPDST1H
lda LCBANK2
lda LCBANK2
;set input name
ldy #(NAMELEN - 1)
lda #$A0
- cpy #(FileName_e - FileName_b)
bcs +
lda FileName_b, y
+ sta (OPDSTL), y
+ sta (OPDST1L), y
dey
bpl -
@ -192,30 +184,30 @@ DOSMLI
pla
tax
iny
sty OPSRCL
sty OPSRC1L
bne +
inx
+ stx OPSRCH
+ stx OPSRC1H
;get file manager parameter list
jsr GETPARM
sty OPDSTL
sta OPDSTH
sty OPDST1L
sta OPDST1H
ldy #0
lda (OPSRCL), y
lda (OPSRC1L), y
tay
clc
adc OPSRCL
adc OPSRC1L
tax
lda OPSRCH
lda OPSRC1H
adc #0
pha
txa
pha
- lda (OPSRCL), y
- lda (OPSRC1L), y
dey
sta (OPDSTL), y
sta (OPDST1L), y
bne -
XREG
ldx #OPENEXISTING
@ -266,10 +258,6 @@ ReadWriteCmd
!word 0 ;record number
!word 0 ;offset
;;in the future, ReadSize will be initially 2
;;and ReadBuffer will point to ReadSize
;;so that the initial file size will be read into the Size field
;;for subsequent read of remaining bytes
ReadSize
WriteSize
!word (LoadSaveEnd - LoadSaveStart)
@ -284,41 +272,30 @@ ReadMLI_e
ExchangeSwapBanked1
rts ;self-modified to LDA in DiversiDOS environment
!byte >(LoadSaveStart - >((<(LoadSaveEnd - LoadSaveStart)) + 255))
sta ExchangeSwapSource2 + 2
sta ExchangeSwapTarget2 + 2
!byte (>LoadSaveStart) - >((<(LoadSaveEnd - LoadSaveStart)) + 255)
sta OPDST1H
ldx #>(LoadSaveEnd - LoadSaveStart)
ldy #<(LoadSaveStart - LoadSaveEnd)
lda #<(LoadSaveEnd - LoadSaveStart)
sta ExchangeSwapSource1 + 1
sta ExchangeSwapTarget1 + 1
sta OPSRC1L
lda #<LoadSaveEnd
ExchangeSwapSet
sta ExchangeSwapSource2 + 1
sta ExchangeSwapTarget2 + 1
lda #((>SWAPBUFFER) - >((<(LoadSaveEnd - LoadSaveStart)) + 255))
sta ExchangeSwapSource1 + 2
sta ExchangeSwapTarget1 + 2
ExchangeSwapSource1
lda $34f3, y ;self-modified
sta OPDST1L
lda #(>SWAPBUFFER) - >((<(LoadSaveEnd - LoadSaveStart)) + 255)
sta OPSRC1H
- lda (OPSRC1L), y
pha
ExchangeSwapSource2
lda $34f3, y ;self-modified
ExchangeSwapTarget1
sta $34f3, y ;self-modified
lda (OPDST1L), y
sta (OPSRC1L), y
pla
ExchangeSwapTarget2
sta $34f3, y ;self-modified
sta (OPDST1L), y
iny
bne ExchangeSwapSource1
inc ExchangeSwapSource1 + 2
inc ExchangeSwapSource2 + 2
inc ExchangeSwapTarget1 + 2
inc ExchangeSwapTarget2 + 2
bne -
inc OPSRC1H
inc OPDST1H
dex
bpl ExchangeSwapSource1
bpl -
rts
LdrEnd
!if ((LDRBASE + LdrEnd - LdrStart) > $3d0) {
@ -331,22 +308,11 @@ LdrEnd
InstallStart
!pseudopc INSTALLBUFFER {
;switch cursor type depending on Apple revision
;check for DiversiDOS
ldx #$20 ;also used as INVSPACE cursor below!
stx SwapFILEMAN
lda APLDETECT
cmp #A2E
beq +
stx CharDel + 1 + BankedCopyStart - $D000
lda #("z" + 1)
sta CharMap1 + 1
sta CharMap2 + 1 + BankedCopyStart - $D000
+
plp ;DiversiDOS state
bcc + ;regular DOS
lda #0
jsr GETIOB
eor #$BF
bne + ;regular DOS
sta ReadBuffer
lda #>SWAPBUFFER
sta ReadBuffer + 1
@ -362,6 +328,8 @@ InstallStart
;read second overlay to banked RAM
jsr ExchangeSwapBanked2
lda #$20
sta SwapFILEMAN
jsr DOSMLI
!byte InstallReadMLI_e - InstallReadMLI_b
InstallReadMLI_b
@ -382,20 +350,8 @@ InstallReadMLI_e
jsr OpenDataFile
bcs +
;;in the future, the read size will come from the saved file
;;for now, we use a fixed size
;read file size from file
;; jsr ReadFile
;; lda #<LoadSaveStart
;; sta ReadBuffer
;; lda #>LoadSaveStart
;; sta ReadBuffer + 1
jsr ReadFile
+
;set to true if no data file found (carry is set)
rol ClearOnFirstKeypress + 1
@ -413,6 +369,17 @@ InstallReadMLI_e
lda ROMIN1
;switch cursor type depending on Apple revision
lda APLDETECT
cmp #A2E
beq +
lda #INVSPACE
sta CharDel + 1
lda #("z" + 1)
sta CharMap1 + 1
sta CharMap2 + 1
+
;display the welcome message, now that we're finally done
ldy #0
@ -437,13 +404,11 @@ CharMap1
ExchangeSwapBanked2
rts ;self-modified to LDA in DiversiDOS environment
!byte ((>$D000) - >((<(BankedCopyEnd - BankedCopyStart)) + 255))
sta ExchangeSwapSource2 + 2
sta ExchangeSwapTarget2 + 2
sta OPDST1H
ldx #>(BankedCopyEnd - BankedCopyStart)
ldy #<(BankedCopyStart - BankedCopyEnd)
lda #<(BankedCopyEnd - BankedCopyStart)
sta ExchangeSwapSource1 + 1
sta ExchangeSwapTarget1 + 1
sta OPSRC1L
jmp ExchangeSwapSet
_WelcomeMessage
@ -492,23 +457,21 @@ IsDirty
ScrollEditBufferIn
lda #<LastLine
sta VirtualBuff1 + 1
sta OPSRC1L
lda #>LastLine
sta VirtualBuff1 + 2
sta OPSRC1H
lda #<(LastLine - WIDTH)
sta VirtualBuff2 + 1
sta OPDST1L
lda #>(LastLine - WIDTH)
sta VirtualBuff2 + 2
sta OPDST1H
ldx #HEIGHT
stx ScrollLine1 + 1
lda #HEIGHT
sta SCROLLLINE
;copy last line on screen to temporary buffer
-- ldy #(WIDTH - 1)
- lda $07D0, y
VirtualBuff1
sta $34f3, y ;self-modified
sta (OPSRC1L), y
dey
bpl -
@ -517,9 +480,7 @@ VirtualBuff1
;copy last line of edit buffer to top line on screen
ldy #(WIDTH - 1)
VirtualBuff2
- lda $34f3, y ;self-modified
- lda (OPDST1L), y
CharMap2
cmp #0 ;self-modified
bcs +
@ -533,36 +494,30 @@ CharMap2
;animation delay
jsr Delay ;returns carry set
tay
lda #-WIDTH
ldx #$FF
ldy #$FF
jsr UpdateVirtualOff
dec ScrollLine1 + 1
ScrollLine1
ldx #"Q" ;self-modified
dec SCROLLLINE
bne --
rts
ScrollEditBufferOut
lda #<FirstLine
sta VirtualBuff3 + 1
sta OPSRC1L
lda #>FirstLine
sta VirtualBuff3 + 2
sta OPSRC1H
lda #<(FirstLine + WIDTH)
sta VirtualBuff4 + 1
sta OPDST1L
lda #>(FirstLine + WIDTH)
sta VirtualBuff4 + 2
sta OPDST1H
ldx #HEIGHT
stx ScrollLine2 + 1
lda #HEIGHT
sta SCROLLLINE
;copy first line on screen to temporary buffer
-- ldy #(WIDTH - 1)
- lda $0400, y ;self-modified
VirtualBuff3
sta $34f3, y ;self-modified
sta (OPSRC1L), y
dey
bpl -
@ -571,9 +526,7 @@ VirtualBuff3
;copy first line of edit buffer to last line on screen
ldy #(WIDTH - 1)
VirtualBuff4
- lda $34f3, y ;self-modified
- lda (OPDST1L), y
sta $07D0, y
dey
bpl -
@ -581,73 +534,72 @@ VirtualBuff4
;animation delay
jsr Delay ;returns carry set
tax
tay
lda #WIDTH
ldy #<(VirtualBuff3 - VirtualBuff1)
jsr UpdateVirtualOff
dec ScrollLine2 + 1
ScrollLine2
ldx #"Q" ;self-modified
dec SCROLLLINE
bne --
rts
UpdateVirtualOff
clc
pha
;set up copy addresses for next line
adc VirtualBuff1 + 1, y
sta VirtualBuff1 + 1, y
txa
adc VirtualBuff1 + 2, y
sta VirtualBuff1 + 2, y
ldx #2
- pha
clc
adc OPSRC1L, x
sta OPSRC1L, x
tya
adc OPSRC1H, x
sta OPSRC1H, x
pla
+ adc VirtualBuff2 + 1, y
sta VirtualBuff2 + 1, y
txa
adc VirtualBuff2 + 2, y
sta VirtualBuff2 + 2, y
dex
dex
bpl -
rts
ScrollTextScreenDown
ldx #(HEIGHT - 2)
- lda TextCalcLo, x
sta _a+1
- jsr SetTextCalc
lda TextCalcLo+1, x
sta _b+1
lda TextCalcHi, x
sta _a+2
sta OPDST2L
lda TextCalcHi+1, x
sta _b+2
ldy #(WIDTH - 1)
_a lda $FFFF, y ; self-modified, above
_b sta $FFFF, y ; self-modified, above
dey
bpl _a
sta OPDST2H
jsr CopyLine
dex
bpl -
rts
SetTextCalc
lda TextCalcLo, x
sta OPSRC2L
lda TextCalcHi, x
sta OPSRC2H
rts
ScrollTextScreenUp
ldx #1 - HEIGHT
- lda (TextCalcLo + HEIGHT - $101) +1, x
sta _c+1
sta OPSRC2L
lda TextCalcLo + HEIGHT - $101, x
sta _d+1
sta OPDST2L
lda (TextCalcHi + HEIGHT - $101) +1, x
sta _c+2
sta OPSRC2H
lda TextCalcHi + HEIGHT - $101, x
sta _d+2
ldy #(WIDTH - 1)
_c lda $FFFF, y ; self-modified, above
_d sta $FFFF, y ; self-modified, above
dey
bpl _c
sta OPDST2H
jsr CopyLine
inx
bne -
rts
CopyLine
ldy #(WIDTH - 1)
- lda (OPSRC2L), y
sta (OPDST2L), y
dey
bpl -
rts
Delay
lda #1
@ -663,35 +615,29 @@ MyWAIT
HandleKeyImportScreen
lda #<(LastLine - WIDTH)
sta VirtualBuff5 + 1
sta OPSRC1L
lda #>(LastLine - WIDTH)
sta VirtualBuff5 + 2
sta OPSRC1H
ldx #(HEIGHT - 2)
-- lda TextCalcLo, x
sta ScreenBuff1 + 1
lda TextCalcHi, x
sta ScreenBuff1 + 2
-- jsr SetTextCalc
ldy #(WIDTH - 1)
VirtualBuff5
- lda $34f3, y ;self-modified
ScreenBuff1
sta $34f3, y ;self-modified
- lda (OPSRC1L), y
sta (OPSRC2L), y
dey
bpl -
sec
lda VirtualBuff5 + 1
lda OPSRC1L
sbc #WIDTH
sta VirtualBuff5 + 1
sta OPSRC1L
bcs +
dec VirtualBuff5 + 2
dec OPSRC1H
+ dex
bpl --
;print anything that isn't a special key
;wrap around screen position when we hit edges
EditorMode
jsr MyKEYIN
cmp #HOTKEY
@ -777,15 +723,12 @@ HandleKeyLineDown
ClearScreen ; does not clear status line
pha
ldx #(HEIGHT - 2)
lda #$A0
-- ldy TextCalcLo, x
sty _e+1
ldy TextCalcHi, x
sty _e+2
-- jsr SetTextCalc
ldy #(WIDTH - 1)
_e sta $FFFF, y ; self-modified, above
lda #$A0
- sta (OPSRC2L), y
dey
bpl _e
bpl -
dex
bpl --
pla
@ -869,13 +812,6 @@ SaveFile
CreateWriteFile
jsr OpenDataFile
bcs OpenRet
;set write length
;; lda #<something
;; sta WriteSize
;; lda #>something
;; sta WriteSize + 1
jsr WriteFile
jsr DOSMLI
!byte CloseMLI_e - CloseMLI_b
@ -896,10 +832,6 @@ TextCalcLo
!byte $50, $D0, $50, $D0, $50, $D0, $50, $D0
LoadSaveStart
;;in the future, this field will contain the number of bytes following for write
;;FileSize ;must be first!
;; !text "4s" ;self-modified
SaveCH
!byte 0 ;loaded from file if exists
SaveCV
@ -909,7 +841,7 @@ FirstLine ;lines are stored sequentially, not like
!fill WIDTH * 8, $A0
!text " 4LIVE by 4am && qkumba "
!fill WIDTH, $A0
!text " Revision 02 / Serial number 161114 "
!text " Revision 02 / Serial number 161115 "
!fill WIDTH * 2, $A0
!text " https://github.com/a2-4am/4live "
!fill WIDTH * 9, $A0