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