diff --git a/src/4cade.a b/src/4cade.a index 6a7343341..efa25ba22 100644 --- a/src/4cade.a +++ b/src/4cade.a @@ -45,7 +45,6 @@ Reenter jsr DisableAccelerator ; back to 1 MHz (especially important on IIgs ; which restores default speed on Ctrl-Reset) jsr CloseHandles ; close any open handles to restore ProRWTS - jsr SaveOrRestoreScreenHoles ; restore original screen hole contents ldx #5 - lda ResetVector,x ; copy reentry wrapper to bottom of stack sta $100,x ; (used as reset vector because ][+ always @@ -132,10 +131,10 @@ SwitchToBank2 ; 7 6 5 4 3 2 1 0 ; | | | | | | | +- bit 0 reserved ; | | | | | | +--- bit 1 reserved -; | | | | | +----- bit 2 = 1 if cheats are enabled -; | | | | +------- bit 3 = 1 if IIc -; | | | +--------- bit 4 = 1 if IIgs -; | | +----------- bit 5 = 1 if VidHD +; | | | | | +----- bit 2 reserved +; | | | | +------- bit 3 reserved +; | | | +--------- bit 4 = 1 if cheats are enabled +; | | +----------- bit 5 = 1 if VidHD or IIgs ; | +------------- bit 6 = 1 if 128K ; +--------------- bit 7 = 1 if joystick ; Use the bit masks defined in constants.a @@ -194,7 +193,7 @@ EvenLasterMover !ifdef PASS2 { } else { ;PASS2 !set PASS2=1 - !warn "ProRWTS ends at ", hddcodeend - 1 + !warn "ProRWTS ends at ", hdddataend - 1 !warn "STACK at ", STACKBASE !warn "LCRAM2 ends at ", LCRAM2_END - 1 !warn "RELBASE = ", $10000 - (LastMover - FirstMover) diff --git a/src/4cade.init.a b/src/4cade.init.a index 7e096aac0..28a595f6a 100644 --- a/src/4cade.init.a +++ b/src/4cade.init.a @@ -30,34 +30,26 @@ + lda #0 sta zpMachineStatus - lda ROM_MACHINEID - cmp #$06 - bne @NotIIc - lda $FBC0 - beq @IsIIc -@NotIIc clc -@IsIIc ror zpMachineStatus - sec - jsr $FE1F ; check for IIgs (allows super hi-res artwork) - bcs NotGS - jsr ROM_TEXT2COPY ; set alternate display mode on IIgs (required for some games) -+ sec - +HIDE_NEXT_BYTE -NotGS clc - ror zpMachineStatus sta SETC3ROM jsr HasVidHDCard ; check for VidHD card (allows super hi-res artwork even on non-IIgs machines) - ror zpMachineStatus sta CLRC3ROM - jsr Has128K ; check for 128K (allows DHGR slideshows and 128K games) + ror zpMachineStatus + lda ROM_MACHINEID + cmp #$06 + bne @NotGS + sec + jsr $FE1F ; check for IIgs (allows super hi-res artwork) + bcs @NotGS + jsr ROM_TEXT2COPY ; set alternate display mode on IIgs (required for some games) + lda #$80 + sta zpMachineStatus +@NotGS jsr Has128K ; check for 128K (allows DHGR slideshows and 128K games) ror zpMachineStatus jsr HasJoystick ; check for joystick (absence is OK but we filter out some games that require a joystick) - ror zpMachineStatus ; now bit 3 = 1 if IIc - ; bit 4 = 1 if IIgs - ; bit 5 = 1 if VidHD + ror zpMachineStatus ; now bit 5 = 1 if VidHD or IIgs ; bit 6 = 1 if 128K ; bit 7 = 1 if joystick - ; and all other bits are 0 (we'll set bit 2 after copying it to LC RAM) + ; and all other bits are 0 (we'll set bit 4 after copying it to LC RAM) lda ROM_MACHINEID cmp #$06 @@ -241,9 +233,6 @@ PrintAsDecimal OneTimeSetup lda zpMachineStatus sta MachineStatus ; save machine status in LC RAM - jsr SaveOrRestoreScreenHoles ; save initial copy of screen hole content - lda #$91 - sta holepatch ; enable restoring of copy from now on ldy #$0b CopyDevs lda $BF13,y diff --git a/src/constants.a b/src/constants.a index fd01fb90f..5f2e4037e 100644 --- a/src/constants.a +++ b/src/constants.a @@ -9,14 +9,14 @@ ; D000..E611 - persistent data structures (per-game cheat categories, ; gGlobalPrefsStore, gGamesListStore) ; ...unused... -; ECC8..FFF9 - main program code +; ECC6..FFF9 - main program code ; FFFA..FFFF - NMI, reset, IRQ vectors ; ; LC RAM BANK 2 ; D000..D3FF - ProRWTS data -; D400..D5F7 - ProRWTS code -; D5F8..DB52 - HGR font code & ProRWTS glue code -; DB53..DB6E - backup of stack (during gameplay and self-running demos) +; D400..D671 - ProRWTS code +; D672..DB6D - HGR font code & ProRWTS glue code +; DB6E..DB7D - backup of stack (during gameplay and self-running demos) ; ...unused... ; DBB6..DBFF - (de)acceleration function ; DC00..DFFF - HGR font data @@ -116,6 +116,5 @@ DisableAccelerator = $DBB6 EnableAccelerator = DisableAccelerator+3 ; AND masks for MachineStatus -SUPPORTS_SHR = %00110000 -IS_IIC = %00001000 -CHEATS_ENABLED = %00000100 +SUPPORTS_SHR = %00100000 +CHEATS_ENABLED = %00010000 diff --git a/src/fx/hw.vbl.a b/src/fx/hw.vbl.a index 0c7b69850..197813bcf 100644 --- a/src/fx/hw.vbl.a +++ b/src/fx/hw.vbl.a @@ -16,12 +16,10 @@ WaitForVBL pha +READ_ROM_NO_WRITE lda $FBB3 - +READ_RAM1_WRITE_RAM1 cmp #$06 bne @nop - lda MachineStatus - and #IS_IIC - bne @iic + lda $FBC0 + beq @iic +LDADDR WaitForVBL_iie bne + @iic @@ -38,6 +36,7 @@ WaitForVBL lda #$4C ; JMP opcode sta WaitForVBL + +READ_RAM1_WRITE_RAM1 pla tay pla @@ -71,5 +70,4 @@ UnwaitForVBL sta $C07F ; enable access to VBL register sta $C05A ; enable VBL polling sta $C07E ; disable access to VBL register - cli rts diff --git a/src/glue.launch.lc2.a b/src/glue.launch.lc2.a index daa68a607..69fab9b5a 100644 --- a/src/glue.launch.lc2.a +++ b/src/glue.launch.lc2.a @@ -8,7 +8,6 @@ ; which handle bank switching for you. LaunchInternal - jsr SaveOrRestoreScreenHoles ; save screen hole contents ldy #$F1 - lda $100,y sta STACKBASE - $F0,y ; back up stack diff --git a/src/prodos.impl.lc2.a b/src/prodos.impl.lc2.a index 238a7ffc4..cd02e338d 100644 --- a/src/prodos.impl.lc2.a +++ b/src/prodos.impl.lc2.a @@ -528,42 +528,3 @@ ProDOS_prefix=gPathname ; !fill $2e } end_promote - - -;------------------------------------------------------------------------------ -; SaveOrRestoreScreenHoles -; preserve screen hole contents across demo execution -; to avoid crashing later on disk access -; -; in: nothing -; out: all flags clobbered -; all registers clobbered -;------------------------------------------------------------------------------ - -SaveOrRestoreScreenHoles - lda #4 - sta namhi - ldx #0 - stx namlo - sta bloklo --- ldy #$78 -- lda (namlo),y - pha - lda holey_stuff,x -holepatch ;sta->lda - lda (namlo),y - pla - sta holey_stuff,x - inx - tya - eor #$80 - tay - bmi - - iny - bpl - - inc namhi - dec bloklo - bne -- - rts -holey_stuff - !fill 64 diff --git a/src/prorwts2.a b/src/prorwts2.a index 57bf0f83a..dfa20df03 100644 --- a/src/prorwts2.a +++ b/src/prorwts2.a @@ -24,36 +24,52 @@ ver_02 = 1 enable_write = 1 ;set to 1 to enable write support ;file must exist already and its size cannot be altered ;writes occur in multiples of block size + enable_format= 0 ;used only by RWTS mode, requires enable_write and fast_subindex enable_seek = 1 ;set to 1 to enable seek support ;seeking with aligned_read=1 requires non-zero offset allow_multi = 0 ;set to 1 to allow multiple floppies + allow_zerovol= 0 ;set to 1 to support volume 0 (=last used volume) check_chksum = 0 ;set to 1 to enforce checksum verification for floppies allow_subdir = 1 ;set to 1 to allow opening subdirectories to access files might_exist = 0 ;set to 1 if file is not known to always exist already ;makes use of status to indicate success or failure + many_files = 0 ;set to 1 to support more than 256 files in a directory allow_aux = 1 ;set to 1 to allow read/write directly to/from aux memory ;requires load_high to be set for arbitrary memory access ;else driver must be running from same memory target ;i.e. running from main if accessing main, running from aux if accessing aux allow_saplings=1 ;enable support for saplings allow_trees = 0 ;enable support for tree files, as opposed to only seedlings and saplings + ;required in RWTS mode if file > 128kb fast_trees = 0 ;keep tree block in memory, requires an additional 512 bytes of RAM always_trees = 0 ;set to 1 if the only file access involves tree files ;not compatible with allow_subdir, allow_saplings + ;required in RWTS mode if allow_trees is enabled detect_treof = 0 ;detect EOF during read of tree files + fast_subindex= 0 ;keep subindex block in memory, requires an additional 512 bytes of RAM + ;halves the disk access for double the speed (ideal for RWTS mode) allow_sparse = 1 ;enable support for reading sparse files ;recommended if enable_write is enabled, to prevent writing to sparse blocks bounds_check = 1 ;set to 1 to prevent access beyond the end of the file ;but limits file size to 64k-2 bytes. + return_size = 0 ;set to 1 to receive file size on open in read-only mode + one_shot = 0 ;set to 1 to load entire file in one pass (avoids the need to specify size) no_interrupts= 0 ;set to 1 to disable interrupts across calls detect_err = 0 ;set to 1 to to detect errors in no_interrupt mode swap_zp = 0 ;set to 1 to include code to preserve zpage - ;used only by rwts_mode + ;used only by RWTS mode + swap_scrn = 1 ;set to 1 to preserve screen hole contents across SmartPort calls + ;reading directly into screen memory that includes holes (either main or aux) is not recommended + ;because SCSI firmware writes there (i.e. whichever bank is active) on exit, which will damage read content + ;recommended if allow_aux is used, to avoid device reset + ;requires 64 bytes to save all holes rwts_mode = 0 ;set to 1 to enable emulation of DOS RWTS when running from hard disk ;uses a one-time open of a tree file, no other file access allowed ;use unique volume numbers to distinguish between images in the same file - ;requires override_adr, enable_seek, allow_trees, always_trees - ;not compatible with enable_floppy, aligned_read, allow_subdir, might_exist, bounds_check + ;requires override_adr, allow_trees, always_trees + ;not compatible with enable_floppy, allow_subdir, might_exist, bounds_check + mem_swap = 0 ;set to 1 if zpage can be swapped between main and aux, and swap_zp is unsuitable + ;(caches index registers in code instead of zpage) load_high = 0 ;set to 1 to load to top of RAM (either main or banked, enables a himem check) load_aux = 0 ;load to aux memory load_banked = 1 ;set to 1 to load into banked RAM instead of main RAM (can be combined with load_aux for aux banked) @@ -69,7 +85,7 @@ ver_02 = 1 } ;PASS2 } else { ;load_high = 0 reloc = $d400 ;page-aligned, but otherwise wherever you want - } ;load_high + } ;load_high = 1 } else { ;load_banked = 0 !if load_high = 1 { !ifdef PASS2 { @@ -78,8 +94,8 @@ ver_02 = 1 } ;PASS2 } else { ;load_high = 0 reloc = $bc00 ;page-aligned, but otherwise wherever you want ($BC00 is common for rwts_mode) - } ;load_high -} ;load_banked + } ;load_high = 1 +} ;load_banked = 1 ;there are also buffers that can be moved if necessary: ;dirbuf, encbuf, treebuf (and corresponding hdd* versions that load to the same place) @@ -92,17 +108,17 @@ ver_02 = 1 !if (might_exist + poll_drive) > 0 { status = $50 ;returns non-zero on error -} ;might_exist or poll_drive +} ;might_exist = 1 or poll_drive = 1 !if allow_aux = 1 { auxreq = $51 ;set to 1 to read/write aux memory, else main memory is used -} ;allow_aux +} ;allow_aux = 1 sizelo = $52 ;set if enable_write=1 and writing, or reading, or if enable_seek=1 and seeking sizehi = $53 ;set if enable_write=1 and writing, or reading, or if enable_seek=1 and seeking !if (enable_write + enable_seek + allow_multi + rwts_mode) > 0 { reqcmd = $54 ;set (read/write/seek) if enable_write=1 or enable_seek=1 ;if allow_multi=1, bit 7 selects floppy drive in current slot (clear=drive 1, set=drive 2) during open call ;bit 7 must be clear for read/write/seek on opened file -} ;enable_write or enable_seek or allow_multi +} ;enable_write = 1 or enable_seek = 1 or allow_multi = 1 or rwts_mode = 1 ldrlo = $55 ;set to load address if override_adr=1 ldrhi = $56 ;set to load address if override_adr=1 namlo = $57 ;name of file to access @@ -111,12 +127,13 @@ ver_02 = 1 ldrhi2 = $5a ;original load address read from filesystem sizelo2 = $5b ;original file size read from filesystem sizehi2 = $5c ;original file size read from filesystem + !set last_zp = $5c ;highest address to save if swap_zp enabled (max 127 entries later) !if enable_floppy = 1 { tmpsec = $3c ;(internal) sector number read from disk reqsec = $3d ;(internal) requested sector number curtrk = $40 ;(internal) track number read from disk -} ;enable_floppy +} ;enable_floppy = 1 command = $42 ;ProDOS constant unit = $43 ;ProDOS constant @@ -125,40 +142,55 @@ ver_02 = 1 bloklo = $46 ;ProDOS constant blokhi = $47 ;ProDOS constant - entries = $3f ;(internal) total number of entries in directory + scratchlo = $48 ;(internal) + scratchhi = $49 ;(internal) -!if rwts_mode = 1 { + entries = $3f ;(internal) total number of entries in directory +!if many_files = 1 { + entrieshi = $3b ;(internal) total number of entries in directory +} ;many_files = 1 + +!if mem_swap = 0 { + !if rwts_mode = 1 { lasttree = $59 ;(internal) last used index in tree buffer - lastvol = $5a ;(internal) last used volume number -} ;rwts_mode -!if allow_trees = 1 { - treeidx = $5b ;(internal) index into tree block - !if always_trees = 0 { - istree = $5c ;(internal) flag to indicate tree file - } ;always_trees - !if fast_trees = 0 { - treeblklo = $5d - treeblkhi = $5e - } ;fast_trees -} ;allow_trees - blkidx = $5f ;(internal) index into sapling block list -!if rwts_mode = 1 { - lastblk = $60 ;(internal) previous index into sapling block list -} ;rwts_mode -!if bounds_check = 1 { - bleftlo = $61 ;(internal) bytes left in file - blefthi = $62 ;(internal) bytes left in file -} ;bounds_check -!if (aligned_read + rwts_mode) = 0 { - blkofflo = $63 ;(internal) offset within cache block - blkoffhi = $64 ;(internal) offset within cache block -} ;not aligned_read and not rwts_mode + } ;rwts_mode = 1 + !if allow_trees = 1 { + treeidx = $5a ;(internal) index into tree block + !set last_zp = $5a ;highest address to save if swap_zp enabled (max 127 entries later) + !if always_trees = 0 { + istree = $5b ;(internal) flag to indicate tree file + } ;always_trees = 0 + !if fast_trees = 0 { + treeblklo = $5c + treeblkhi = $5d + !set last_zp = $5d ;highest address to save if swap_zp enabled (max 127 entries later) + } ;fast_trees = 0 + } ;allow_trees = 1 + blkidx = $5e ;(internal) index into sapling block list + !if rwts_mode = 1 { + lastblk = $5f ;(internal) previous index into sapling block list + !set last_zp = $5f ;highest address to save if swap_zp enabled (max 127 entries later) + } ;rwts_mode = 1 + !if (bounds_check + return_size + one_shot) > 0 { + bleftlo = $60 ;(internal) bytes left in file + } ;bounds_check = 1 or return_size = 1 or one_shot = 1 + !if (bounds_check + return_size + aligned_read + one_shot) > 0 { + blefthi = $61 ;(internal) bytes left in file + !set last_zp = $61 ;highest address to save if swap_zp enabled (max 127 entries later) + } ;bounds_check = 1 or return_size = 1 or aligned_read = 1 or one_shot = 1 + !if aligned_read = 0 { + blkofflo = $62 ;(internal) offset within cache block + blkoffhi = $63 ;(internal) offset within cache block + !set last_zp = $63 ;highest address to save if swap_zp enabled (max 127 entries later) + } ;aligned_read = 0 +} ;mem_swap = 0 !if enable_floppy = 1 { - step = $65 ;(internal) state for stepper motor - tmptrk = $66 ;(internal) temporary copy of current track - phase = $67 ;(internal) current phase for seek -} ;enable_floppy + step = $64 ;(internal) state for stepper motor + tmptrk = $65 ;(internal) temporary copy of current track + phase = $66 ;(internal) current phase for seek + !set last_zp = $66 ;highest address to save if swap_zp enabled (max 127 entries later) +} ;enable_floppy = 1 ;constants cmdseek = 0 ;requires enable_seek=1 @@ -198,11 +230,10 @@ ver_02 = 1 SETAUXZP = $c009 first_zp = $40 ;lowest address to save if swap_zp enabled - last_zp = $64 ;highest address to save if swap_zp enabled (max 127 entries later) + ;last_zp is calculated automatically D1S1 = 1 ;disk 1 side 1 volume ID if rwts_mode enabled - init jsr SETKBD jsr SETVID lda DEVNUM @@ -214,7 +245,7 @@ init jsr SETKBD sta unrslot2 + 1 sta unrslot3 + 1 sta unrslot4 + 1 -} ;enable_floppy and enable_write +} ;enable_floppy = 1 and enable_write = 1 pha !if enable_floppy = 1 { ora # 0 { sta unrdrvoff2 + 1 - } ;might_exist or poll_drive + } ;might_exist = 1 or poll_drive = 1 !if (aligned_read + allow_aux) = 0 { sta unrdrvoff3 + 1 - } ;not aligned_read and not allow_aux + } ;aligned_read = 0 and allow_aux = 0 sta unrdrvoff4 + 1 tax inx ;MOTORON !if allow_multi = 1 { stx unrdrvon1 + 1 - } ;allow_multi + } ;allow_multi = 1 stx unrdrvon2 + 1 !if aligned_read = 0 { stx unrdrvon3 + 1 - } ;aligned_read + } ;aligned_read = 0 stx unrdrvon4 + 1 inx ;DRV0EN !if allow_multi = 1 { stx unrdrvsel2 + 1 - } ;allow_multi + } ;allow_multi = 1 inx !if allow_multi = 1 { stx unrdrvsel1 + 1 - } ;allow_multi + } ;allow_multi = 1 inx ;Q6L stx unrread1 + 1 !if (poll_drive + allow_multi) > 0 { stx unrread2 + 1 stx unrread3 + 1 - } ;poll_drive or allow_multi + } ;poll_drive = 1 or allow_multi = 1 stx unrread4 + 1 stx unrread5 + 1 !if check_chksum = 1 { stx unrread6 + 1 - } ;check_chksum -} ;enable_floppy + } ;check_chksum = 1 +} ;enable_floppy = 1 ldx #1 stx namlo inx @@ -273,11 +304,11 @@ init jsr SETKBD ldx $200 dex stx sizelo + sec bmi +++ ;find current directory name in directory - sec php readblock jsr MLI @@ -285,16 +316,16 @@ readblock jsr MLI !word x80_parms lda #<(readbuff + NAME_LENGTH) - sta bloklo + sta scratchlo lda #>(readbuff + NAME_LENGTH) - sta blokhi + sta scratchhi inextent ldy #0 - lda (bloklo), y + lda (scratchlo), y pha and #$0f tax -- iny - lda (bloklo), y + lda (scratchlo), y cmp (namlo), y beq ifoundname @@ -303,16 +334,16 @@ inextent ldy #0 - pla skiphdr clc - lda bloklo + lda scratchlo adc #ENTRY_SIZE - sta bloklo + sta scratchlo bcc + ;there can be only one page crossed, so we can increment instead of adc - inc blokhi + inc scratchhi + cmp #<(readbuff + $1ff) ;4 + ($27 * $0d) - lda blokhi + lda scratchhi sbc #>(readbuff + $1ff) bcc inextent @@ -356,14 +387,14 @@ adjpath tya ;as starting position for subsequent searches ldy #(KEY_POINTER + 1) - lda (bloklo), y + lda (scratchlo), y tax dey - lda (bloklo), y + lda (scratchlo), y !if enable_floppy = 1 { sta unrblocklo + 1 stx unrblockhi + 1 -} ;enable_floppy +} ;enable_floppy = 1 sta unrhddblocklo + 1 stx unrhddblockhi + 1 + sta x80_parms + 4 @@ -384,7 +415,7 @@ adjpath tya bcc set_slot1 !if use_smartport = 1 { php -} ;use_smartport +} ;use_smartport = 1 !if enable_floppy = 1 { ;check if current device is floppy @@ -392,80 +423,95 @@ adjpath tya lsr ora #$c0 tax - stx blokhi + stx scratchhi ldy #0 - sty bloklo + sty scratchlo iny - lda (bloklo), y + lda (scratchlo), y cmp #$20 bne not_floppy iny iny - lda (bloklo), y + lda (scratchlo), y bne not_floppy iny iny - lda (bloklo), y + lda (scratchlo), y cmp #3 bne not_floppy ldy #$ff - lda (bloklo), y - beq set_slot + lda (scratchlo), y + beq set_slot1 not_floppy -} ;enable_floppy +} ;enable_floppy = 1 ;find SmartPort device for basic MicroDrive support ldx #$c8 - dex - stx blokhi + stx scratchhi ldy #0 - sty bloklo + sty scratchlo iny - lda (bloklo), y + lda (scratchlo), y cmp #$20 bne - iny iny - lda (bloklo), y + lda (scratchlo), y bne - iny iny - lda (bloklo), y + lda (scratchlo), y cmp #3 bne - ldy #$ff - lda (bloklo), y + lda (scratchlo), y beq - !if use_smartport = 1 { set_slot plp -} ;use_smartport +} ;use_smartport = 1 set_slot1 stx slot + 2 -!if use_smartport = 1 { - stx unrentry1 + 2 -} ;use_smartport - stx unrentry2 + 2 + stx unrentry + 2 slot ldx $cfff - stx unrentry2 + 1 + stx unrentry + 1 +!if enable_floppy = 1 { + php +} ;enable_floppy = 1 !if use_smartport = 1 { - bcs + !if enable_floppy = 1 { - bne + - } ;enable_floppy - jmp bankram + beq + + } ;enable_floppy = 1 + bcs ++ ++ jmp bankram -+ lda #$8c ;STY +++ lda #$8c ;STY + !if (rwts_mode + enable_write) > 1 { sta unrcommand1 + } ;rwts_mode = 1 and enable_write = 1 + sta unrcommand3 lda # 1 { sta unrcommand1 + 1 + } ;rwts_mode = 1 and enable_write = 1 + !if (rwts_mode + aligned_read + (enable_write xor 1)) = 0 { sta unrcommand2 + 1 + } ;rwts_mode = 0 and aligned_read = 0 and enable_write = 1 + sta unrcommand3 + 1 lda #>pcommand + !if (rwts_mode + enable_write) > 1 { sta unrcommand1 + 2 + } ;rwts_mode = 1 and enable_write = 1 + !if (rwts_mode + aligned_read + (enable_write xor 1)) = 0 { sta unrcommand2 + 2 + } ;rwts_mode = 0 and aligned_read = 0 and enable_write = 1 + sta unrcommand3 + 2 lda #$8e ;STX + !if (rwts_mode + aligned_read + (enable_write xor 1)) = 0 { sta unrcommand2 + } ;rwts_mode = 0 and aligned_read = 0 and enable_write = 1 sta unrbloklo lda #(readbuff + $200) ldx #2 stx x80_parms + 4 lda #0 @@ -506,33 +548,37 @@ slot ldx $cfff jsr MLI !byte $80 !word x80_parms + lda #cmdread + sta unrpcommand + lda #$ea + sta hackstar iterunit inc unrunit2 - -unrentry1 jsr $d1d1 - !byte cmdread - !word unrpacket + jsr unrentry bcs iterunit - ldy #$0f -- lda readbuff + 4, y - cmp readbuff + $204, y ++ ldy #$10 +- lda readbuff + 3, y + cmp readbuff + $203, y bne iterunit dey - bpl - -} ;use_smartport + bne - + lda #$68 + sta hackstar + lda #packet + sta unrppacket + 1 +} ;use_smartport = 1 bankram -!if enable_floppy = 1 { - php -} ;enable_floppy !if load_banked = 1 { lda LCBANK2 + 2 - ((lc_bank - 1) * 8) lda LCBANK2 + 2 - ((lc_bank - 1) * 8) -} ;load_banked +} ;load_banked = 1 !if load_aux = 1 { sta SETAUXWR + (load_banked * 4) ;SETAUXWR or SETAUXZP -} ;load_aux +} ;load_aux = 1 !if enable_floppy = 1 { ldx #>unrelocdsk ldy #unrelochdd ldy #((codeend - rdwrpart) + $ff) ldy #0 -- lda (bloklo), y +- lda (scratchlo), y reladr sta reloc, y iny bne - - inc blokhi + inc scratchhi inc reladr + 2 dex bne - @@ -560,12 +606,12 @@ reladr sta reloc, y ;build 6-and-2 denibbilisation table ldx #$16 --- stx bloklo +-- stx scratchlo txa asl - bit bloklo + bit scratchlo beq + - ora bloklo + ora scratchlo eor #$ff and #$7e - bcs + @@ -579,7 +625,7 @@ reladr sta reloc, y txa ora #$80 sta xlattbl, y - } ;enable_write + } ;enable_write = 1 iny + inx bpl -- @@ -601,7 +647,7 @@ unrdrvsel1 lda DRV0EN + 1 lda curtrk sta trackd2 + - } ;allow_multi + } ;allow_multi = 1 unrdrvoff1 lda MOTOROFF ++ } else { ;enable_floppy = 0 @@ -616,13 +662,20 @@ unrdrvoff1 lda MOTOROFF lda unrelochdd + $100, y sta reloc + $100, y - } ;one_page + lda unrelochdd + $200, y + sta reloc + $200, y + } ;one_page = 0 iny bne - -} ;enable_floppy +} ;enable_floppy = 1 +!if swap_scrn = 1 { + jsr saveslot + lda #$91 + sta initpatch +} ;swap_scrn = 1 !if load_aux = 1 { sta CLRAUXWR + (load_banked * 4) ;CLRAUXWR or CLRAUXZP -} ;load_aux +} ;load_aux = 1 !if rwts_mode = 1 { ;read volume directory key block @@ -636,18 +689,18 @@ unrhddblockhi = * hddreaddir1 jsr hddreaddirsel hddfirstent lda #NAME_LENGTH - sta bloklo + sta scratchlo lda #>(hdddirbuf - 1) - sta blokhi + sta scratchhi ;there can be only one page crossed, so we can increment here -hddnextent1 inc blokhi +hddnextent1 inc scratchhi hddnextent ldy #0 ;match name lengths before attempting to match names - lda (bloklo), y + lda (scratchlo), y and #$0f tax inx @@ -657,9 +710,9 @@ hddnextent ldy #0 ;match failed, move to next entry in this block, if possible + clc - lda bloklo + lda scratchlo adc #ENTRY_SIZE - sta bloklo + sta scratchlo bcs hddnextent1 cmp #$ff ;4 + ($27 * $0d) bne hddnextent @@ -671,52 +724,76 @@ hddnextent ldy #0 bcs hddreaddir1 hddfoundname iny - lda (bloklo), y + lda (scratchlo), y dex bne - - !if swap_zp = 0 { + !if ((swap_zp xor 1) + mem_swap) > 0 { !if allow_trees = 1 { stx treeidx sty lasttree ;guarantee no match - } ;allow_trees + } ;allow_trees = 1 stx blkidx sty lastblk ;guarantee no match - } else { ;swap_zp = 1 + } else { ;swap_zp = 1 and mem_swap = 0 !if allow_trees = 1 { stx zp_array + treeidx - first_zp sty zp_array + lasttree - first_zp ;guarantee no match - } ;allow_trees + } ;allow_trees = 0 stx zp_array + blkidx - first_zp sty zp_array + lastblk - first_zp ;guarantee no match - } ;swap_zp + } ;swap_zp = 0 or mem_swap = 1 + !if allow_trees = 1 { ;fetch KEY_POINTER ldy #KEY_POINTER - lda (bloklo), y + lda (scratchlo), y + !if fast_trees = 0 { + !if ((swap_zp xor 1) + mem_swap) > 0 { + sta treeblklo + } else { ;swap_zp = 1 and mem_swap = 0 + sta zp_array + treeblklo - first_zp + } ;swap_zp = 0 or mem_swap = 1 + } else { ;fast_trees = 1 tax + } ;fast_trees = 0 iny - lda (bloklo), y + lda (scratchlo), y + !if fast_trees = 0 { + !if ((swap_zp xor 1) + mem_swap) > 0 { + sta treeblkhi + } else { ;swap_zp = 1 and mem_swap = 0 + sta zp_array + treeblkhi - first_zp + } ;swap_zp = 0 or mem_swap = 1 + } else { ;fast_trees = 1 + ldy #>hddtreebuf jsr hddreaddirsect - ldx #2 - stx sizehi - dex - stx reqcmd - dex - stx sizelo - stx ldrlo - lda #$b6 - sta ldrhi - jsr hddrdfile + } ;fast_trees = 0 + } ;allow_trees = 1 + + lda #>iob + ldy #iob + ldy # 0 { jmp rdwrfile - } ;enable_readseq or allow_subdir + } ;enable_readseq = 1 or allow_subdir = 1 opendir !if no_interrupts = 1 { !if detect_err = 1 { clc - } ;detect_err + } ;detect_err = 1 php sei jsr + @@ -743,11 +820,11 @@ opendir pla adc #0 pha - } ;detect_err + } ;detect_err = 1 plp rts + - } ;no_interrupts + } ;no_interrupts = 1 ;read volume directory key block ;self-modified by init code @@ -760,21 +837,25 @@ unrblockhi = unrelocdsk + (* - reloc) readdir ;note that calling this location directly limits subdirectories to 14 entries! lda #NAME_LENGTH + ENTRY_SIZE -firstent sta bloklo +firstent sta scratchlo lda #>(dirbuf - 1) - sta blokhi + sta scratchhi !if might_exist = 1 { lda dirbuf + FILE_COUNT ;assuming only 256 files per subdirectory sta entries - } ;might_exist + !if many_files = 1 { + lda dirbuf + FILE_COUNT + 1 + sta entrieshi + } ;many_files = 1 + } ;might_exist = 1 ;there can be only one page crossed, so we can increment here -nextent1 inc blokhi +nextent1 inc scratchhi nextent ldy #0 - !if (might_exist + allow_subdir + allow_saplings + (allow_trees and (always_trees xor 1))) > 0 { - lda (bloklo), y + !if (might_exist + allow_subdir + allow_saplings + (always_trees xor 1)) > 0 { + lda (scratchlo), y !if might_exist = 1 { sty status @@ -782,9 +863,9 @@ nextent ldy #0 and #MASK_ALL beq + - } ;might_exist + } ;might_exist = 1 - !if (allow_subdir + allow_saplings + (allow_trees and (always_trees xor 1))) > 0 { + !if (allow_subdir + allow_saplings + (always_trees xor 1)) > 0 { ;remember type ;now bits 5-4 are represented by carry (subdirectory), sign (sapling) @@ -797,14 +878,14 @@ nextent ldy #0 sta treeidx bit treeidx - } ;allow_trees + } ;allow_trees = 1 php - } ;allow_subdir or allow_saplings or (allow_trees and not always_trees) - } ;might_exist or allow_subdir or allow_saplings or (allow_trees and not always_trees) + } ;allow_subdir = 1 or allow_saplings = 1 or always_trees = 0 + } ;might_exist = 1 or allow_subdir = 1 or allow_saplings = 1 or always_trees = 0 ;match name lengths before attempting to match names - lda (bloklo), y + lda (scratchlo), y and #$0f tax inx @@ -813,27 +894,35 @@ nextent ldy #0 ;match failed, check if any directory entries remain - !if (allow_subdir + allow_saplings + (allow_trees and (always_trees xor 1))) > 0 { + !if (allow_subdir + allow_saplings + (always_trees xor 1)) > 0 { plp - } ;allow_subdir or allow_saplings or (allow_trees and not always_trees) + } ;allow_subdir = 1 or allow_saplings = 1 or always_trees = 0 !if might_exist = 1 { dec entries bne + - } ;might_exist + !if many_files = 1 { + lda entrieshi + bne ++ + } ;many_files = 1 + } ;might_exist = 1 !if (might_exist + poll_drive) > 0 { nodisk unrdrvoff2 = unrelocdsk + (* - reloc) lda MOTOROFF inc status rts - } ;might_exist or poll_drive + } ;might_exist = 1 or poll_drive = 1 + + !if (might_exist + many_files) > 1 { +++ dec entrieshi + } ;might_exist = 1 and many_files = 1 ;move to next entry in this block, if possible + clc - lda bloklo + lda scratchlo adc #ENTRY_SIZE - sta bloklo + sta scratchlo bcs nextent1 cmp #$ff ;4 + ($27 * $0d) bne nextent @@ -847,7 +936,7 @@ unrdrvoff2 = unrelocdsk + (* - reloc) bne firstent foundname iny - lda (bloklo), y + lda (scratchlo), y dex bne - @@ -857,17 +946,20 @@ foundname iny stx treeidx !if always_trees = 0 { stx istree - } ;always_trees - } ;allow_trees + } ;always_trees = 0 + } ;allow_trees = 1 stx blkidx - !if aligned_read = 0 { + !if (aligned_read + one_shot) = 0 { stx blkofflo stx blkoffhi - } ;aligned_read + } ;aligned_read = 0 and one_shot = 0 !if enable_write = 1 { + !if aligned_read = 0 { ldy reqcmd cpy #cmdwrite ;control carry instead of zero bne + + } ;aligned_read = 0 + !if one_shot = 0 { ;round requested size up to nearest block if writing @@ -877,24 +969,25 @@ foundname iny adc #1 and #$fe sta sizehi - !if aligned_read = 0 { + !if aligned_read = 0 { stx sizelo - !if bounds_check = 1 { + !if bounds_check = 1 { sec - } ;bounds_check - } ;aligned_read + } ;bounds_check = 1 + } ;aligned_read = 0 + } ;one_shot = 0 + - } ;enable_write + } ;enable_write = 1 - !if bounds_check = 1 { + !if (bounds_check + return_size + one_shot) > 0 { ;cache EOF (file size, loaded backwards) ldy #EOF_HI - lda (bloklo), y + lda (scratchlo), y !if (enable_write + aligned_read) > 0 { tax dey ;EOF_LO - lda (bloklo), y + lda (scratchlo), y ;round file size up to nearest block if writing without aligned reads ;or always if using aligned reads @@ -904,8 +997,8 @@ foundname iny } else { ;aligned_read = 1 !if enable_write = 1 { sec - } ;enable_write - } ;aligned_read + } ;enable_write = 1 + } ;aligned_read = 0 adc #$fe txa adc #1 @@ -913,40 +1006,57 @@ foundname iny !if aligned_read = 0 { tax lda #0 + !if one_shot = 0 { + stx blefthi sta bleftlo + } else { ;one_shot = 1 ++ stx sizehi + sta sizelo + } ;one_shot = 0 } else { ;aligned_read = 1 + !if one_shot = 0 { sta blefthi - } ;aligned_read + } else { ;one_shot = 1 + sta sizehi + } ;one_shot = 0 + } ;aligned_read = 0 } else { ;enable_write = 0 and aligned_read = 0 + !if one_shot = 0 { sta blefthi + } else { ;one_shot = 1 + sta sizehi + } ;one_shot = 0 dey ;EOF_LO - lda (bloklo), y + lda (scratchlo), y + !if one_shot = 0 { sta bleftlo - } ;enable_write or aligned_read - } ;bounds_check + } else { ;one_shot = 1 + sta sizelo + } ;one_shot = 0 + } ;enable_write = 1 or aligned_read = 1 + } ;bounds_check = 1 or return_size = 1 or one_shot = 1 ;cache AUX_TYPE (load offset for binary files) !if override_adr = 0 { ldy #AUX_TYPE - lda (bloklo), y + lda (scratchlo), y !if (allow_subdir + allow_saplings + allow_trees + (aligned_read xor 1)) > 0 { sta ldrlo iny - lda (bloklo), y + lda (scratchlo), y sta ldrhi } else { ;allow_subdir = 0 and allow_saplings = 0 and allow_trees = 0 and aligned_read = 1 pha iny - lda (bloklo), y + lda (scratchlo), y pha - } ;allow_subdir or allow_saplings or allow_trees or not aligned_read - } ;override_adr + } ;allow_subdir = 1 or allow_saplings = 1 or allow_trees = 1 or aligned_read = 0 + } ;override_adr = 0 ;cache KEY_POINTER ldy #KEY_POINTER - lda (bloklo), y + lda (scratchlo), y tax !if (allow_subdir + allow_saplings + allow_trees) > 0 { sta dirbuf @@ -954,43 +1064,42 @@ foundname iny sta treeblklo } ;allow_trees = 1 and fast_trees = 0 iny - lda (bloklo), y + lda (scratchlo), y sta dirbuf + 256 !if (allow_trees + (fast_trees xor 1)) > 1 { sta treeblkhi } ;allow_trees = 1 and fast_trees = 0 - !if (allow_trees and always_trees) = 0 { + + !if always_trees = 0 { plp bpl ++ !if allow_subdir = 1 { php - } ;allow_subdir + } ;allow_subdir = 1 !if allow_trees = 1 { ldy #>dirbuf bvc + !if fast_trees = 1 { ldy #>treebuf - } ;fast_trees + } ;fast_trees = 1 sty istree + - } ;allow_trees - } else { ;allow_trees = 0 or always_trees = 1 - !if (allow_trees + always_trees) > 1 { + } ;allow_trees = 1 + } else { ;always_trees = 1 ldy #>treebuf - } ;allow_trees and always_trees - } ;allow_trees or always_trees + } ;always_trees = 0 } else { ;allow_subdir = 0 and allow_saplings = 0 and allow_trees = 0 iny - lda (bloklo), y - } ;allow_subdir or allow_saplings or allow_trees + lda (scratchlo), y + } ;allow_subdir = 1 or allow_saplings = 1 or allow_trees = 1 ;read index block in case of sapling or tree - jsr readdirsect + jsr readdirsect !if allow_subdir = 1 { plp - } ;allow_subdir + } ;allow_subdir = 1 ++ ;skip some stuff ;drive is on already @@ -1003,14 +1112,13 @@ unrdrvon2 = unrelocdsk + (* - reloc) lda MOTORON !if allow_subdir = 1 { clc - } ;allow_subdir - + } ;allow_subdir = 1 !if no_interrupts = 1 { !if detect_err = 1 { !if allow_subdir = 0 { clc - } ;allow_subdir - } ;detect_err + } ;allow_subdir = 0 + } ;detect_err = 1 php sei jsr + @@ -1018,11 +1126,11 @@ unrdrvon2 = unrelocdsk + (* - reloc) pla adc #0 pha - } ;detect_err + } ;detect_err = 1 plp rts + - } ;no_interrupts + } ;no_interrupts = 1 rdwrfilei !if (override_adr + allow_subdir + allow_saplings + allow_trees + (aligned_read xor 1)) > 0 { @@ -1040,9 +1148,9 @@ rdwrfilei lda #0 !if aligned_read = 0 { sta sizelo - } ;aligned_read + } ;aligned_read = 0 + - } ;allow_subdir + } ;allow_subdir = 1 sta adrlo stx adrhi } else { ;override_adr = 0 and allow_subdir = 0 and allow_saplings = 0 and allow_trees = 0 and aligned_read = 1 @@ -1050,7 +1158,7 @@ rdwrfilei sta adrhi pla sta adrlo - } ;override_adr or allow_subdir or allow_saplings or allow_trees and not aligned_read + } ;override_adr = 1 or allow_subdir = 1 or allow_saplings = 1 or allow_trees = 1 or aligned_read = 0 ;set requested size to min(length, requested size) @@ -1064,18 +1172,22 @@ rdwrfilei bcs copyblock sty sizelo stx sizehi - } ;bounds_check + } ;bounds_check = 1 copyblock !if allow_aux = 1 { ldx auxreq jsr setaux - } ;allow_aux - !if enable_write = 1 { + } ;allow_aux = 1 + !if one_shot = 0 { + !if enable_write = 1 { lda reqcmd lsr bne rdwrloop - } ;enable_write + } ;enable_write = 1 + + ;if offset is non-zero then we return from cache + lda blkofflo tax ora blkoffhi @@ -1085,9 +1197,9 @@ copyblock lda sizelo pha lda adrhi - sta blokhi + sta scratchhi lda adrlo - sta bloklo + sta scratchlo stx adrlo lda #>encbuf clc @@ -1111,14 +1223,17 @@ copyblock sty sizelo stx sizehi + - !if enable_seek = 1 { + !if enable_seek = 1 { lda sizehi - } else { ;enable_seek = 0 + } else { ;enable_seek = 0 ldy sizehi - } ;enable_seek + } ;enable_seek = 1 jsr copycache unrdrvon3 = unrelocdsk + (* - reloc) lda MOTORON ;copycache turns it off + + ;align to next block and resume read + lda ldrlo adc sizelo sta ldrlo @@ -1133,17 +1248,24 @@ unrdrvon3 = unrelocdsk + (* - reloc) sbc sizehi sta sizehi ora sizelo - !if allow_subdir = 1 { + !if allow_subdir = 1 { + !if no_interrupts = 1 { clc - } ;allow_subdir bne rdwrfilei - !if allow_aux = 0 { + } else { ;no_interrupts = 0 + bne rdwrfile + } ;no_interrupts = 1 + } else { ;allow_subdir = 0 + bne rdwrfilei + } ;allow_subdir = 1 + !if allow_aux = 0 { unrdrvoff3 = unrelocdsk + (* - reloc) lda MOTOROFF rts - } else { ;allow_aux = 1 + } else { ;allow_aux = 1 beq rdwrdonedrv - } ;allow_aux + } ;allow_aux = 0 + } ;one_shot = 0 } else { ;aligned_read = 1 !if bounds_check = 1 { lda blefthi @@ -1151,18 +1273,18 @@ unrdrvoff3 = unrelocdsk + (* - reloc) bcs + sta sizehi + - } ;bounds_check + } ;bounds_check = 1 !if allow_aux = 1 { ldx auxreq jsr setaux - } ;allow_aux - } ;aligned_read + } ;allow_aux = 1 + } ;aligned_read = 0 rdwrloop !if aligned_read = 0 { !if (enable_write + enable_seek) > 0 { ldx reqcmd - } ;enable_write or enable_seek + } ;enable_write = 1 or enable_seek = 1 ;set read/write size to min(length, $200) @@ -1170,8 +1292,6 @@ rdwrloop cmp #2 bcs + pha - lda #2 - sta sizehi ;redirect read to private buffer for partial copy @@ -1186,15 +1306,15 @@ rdwrloop stx adrlo !if (enable_write + enable_seek) > 0 { inx ;ldx #cmdread - } ;enable_write or enable_seek + } ;enable_write = 1 or enable_seek = 1 } else { ;ver_02 = 0 stz adrlo !if (enable_write + enable_seek) > 0 { ldx #cmdread - } ;enable_write or enable_seek - } ;ver_02 + } ;enable_write = 1 or enable_seek = 1 + } ;ver_02 = 1 + - } ;aligned_read + } ;aligned_read = 0 !if allow_trees = 1 { ;read tree data block only if tree and not read already @@ -1205,7 +1325,7 @@ rdwrloop !if always_trees = 0 { lda istree beq + - } ;always_trees + } ;always_trees = 0 lda adrhi pha lda adrlo @@ -1216,57 +1336,96 @@ rdwrloop pha } else { ;ver_02 = 0 phx - } ;ver_02 - } ;(not aligned_read) and (enable_write or enable_seek) + } ;ver_02 = 1 + } ;aligned_read = 0 and (enable_write = 1 or enable_seek = 1) + !if aligned_read = 0 { + php + } ;aligned_read = 0 lda #>dirbuf sta adrhi sty adrlo ;fetch tree data block and read it + !if fast_trees = 0 { + ldx treeblklo + lda treeblkhi + jsr readdirsel + } ;fast_trees = 0 ldy treeidx inc treeidx ldx treebuf, y lda treebuf + 256, y - !if aligned_read = 0 { - php - } ;aligned_read + !if detect_treof = 1 { + bne noteof1 + tay + txa + bne fixy1 + !if aligned_read = 0 { + plp + bcs fewpop + pla + pla + pla +fewpop + } ;aligned_read = 0 + pla + pla + sec + rts +fixy1 tya +noteof1 + } ;detect_treof = 1 + !if fast_trees = 0 { jsr seekrd + } else { ;fast_trees = 1 + jsr readdirsel + } ;fast_trees = 0 !if aligned_read = 0 { plp - !if (enable_write + enable_seek) > 0 { - !if ver_02 = 1 { + } ;aligned_read = 0 + !if ((aligned_read xor 1) + (enable_write or enable_seek)) > 1 { + !if ver_02 = 1 { pla tax - } else { ;ver_02 = 0 + } else { ;ver_02 = 0 plx - } ;ver_02 - } ;enable_write or enable_seek - } ;aligned_read + } ;ver_02 = 1 + } ;aligned_read = 0 and (enable_write = 1 or enable_seek = 1) pla sta adrlo pla sta adrhi - } ;allow_trees + } ;allow_trees = 1 ;fetch data block and read/write it - ldy blkidx +skiptree ldy blkidx + inc blkidx !if aligned_read = 0 { !if enable_seek = 1 { txa ;cpx #cmdseek, but that would require php at top beq + - } ;enable_seek + } ;enable_seek = 1 !if enable_write = 1 { stx command - } ;enable_write - } ;aligned_read + } ;enable_write = 1 + } ;aligned_read = 0 ldx dirbuf, y lda dirbuf + 256, y + !if detect_treof = 1 { + bne noteof2 + tay + txa + bne fixy2 + sec + rts +fixy2 tya +noteof2 + } ;detect_treof = 1 !if allow_sparse = 1 { pha ora dirbuf, y @@ -1274,34 +1433,35 @@ rdwrloop pla dey iny ;don't affect carry - } ;allow_sparse + } ;allow_sparse = 1 !if aligned_read = 0 { php - } ;aligned_read + } ;aligned_read = 0 !if allow_sparse = 1 { beq issparse - } ;allow_sparse - !if (aligned_read + (enable_write or enable_seek)) > 1 { + } ;allow_sparse = 1 + !if (aligned_read and (enable_write or enable_seek)) = 1 { ldy reqcmd - !if enable_seek = 1 { + !if enable_seek = 1 { beq + - } ;enable_seek - } ;aligned_read and (enable_write or enable_seek) + } ;enable_seek = 1 + } ;aligned_read = 1 and (enable_write = 1 or enable_seek = 1) !if enable_write = 1 { jsr seekrdwr } else { ;enable_write = 0 jsr seekrd - } ;enable_write + } ;enable_write = 1 + resparse !if aligned_read = 0 { plp - !if bounds_check = 1 { + bcc + + !if bounds_check = 1 { dec blefthi dec blefthi - } ;bounds_check - } ;aligned_read -+ dec sizehi + } ;bounds_check = 1 + } ;aligned_read = 0 + dec sizehi dec sizehi bne rdwrloop @@ -1309,16 +1469,15 @@ rdwrdonedrv unrdrvoff4 = unrelocdsk + (* - reloc) lda MOTOROFF !if aligned_read = 0 { - bcc + lda sizelo bne rdwrloop - } ;aligned_read + } ;aligned_read = 0 rdwrdone !if allow_aux = 1 { ldx #0 setaux sta CLRAUXRD, x sta CLRAUXWR, x - } ;allow_aux + } ;allow_aux = 1 rts !if allow_sparse = 1 { @@ -1332,17 +1491,19 @@ issparse bne - dec adrhi bne resparse - } ;allow_sparse + } ;allow_sparse = 1 !if aligned_read = 0 { ;cache partial block offset + pla - sta bloklo + sta scratchlo pla - sta blokhi + sta scratchhi pla + !if one_shot = 0 { sta sizehi + } ;one_shot = 0 dec adrhi dec adrhi @@ -1355,23 +1516,24 @@ copycache } else { ;enable_seek = 0 tay copycache - } ;enable_seek + } ;enable_seek = 1 beq + dey - lda (adrlo), y - sta (bloklo), y + sta (scratchlo), y iny bne - - inc blokhi + inc scratchhi inc adrhi bne + - lda (adrlo), y - sta (bloklo), y + sta (scratchlo), y iny + cpy sizelo bne - ++ - !if bounds_check = 1 { + !if one_shot = 0 { + !if bounds_check = 1 { lda bleftlo sec sbc sizelo @@ -1379,13 +1541,13 @@ copycache lda blefthi sbc sizehi sta blefthi - } ;bounds_check + } ;bounds_check = 1 clc - !if enable_seek = 1 { + !if enable_seek = 1 { lda sizelo - } else { ;enable_seek = 0 + } else { ;enable_seek = 0 tya - } ;enable_seek + } ;enable_seek = 1 adc blkofflo sta blkofflo lda sizehi @@ -1393,7 +1555,10 @@ copycache and #$fd sta blkoffhi bcc rdwrdone ;always - } ;aligned_read + } else { ;one_shot = 1 + rts + } ;one_shot = 0 + } ;aligned_read = 0 spinup ldy #6 - jsr delay @@ -1426,7 +1591,7 @@ copy_cur tax eor #$ff } else { ;ver_02 = 0 inc - } ;ver_02 + } ;ver_02 = 1 inx bcc ++ + @@ -1434,7 +1599,7 @@ copy_cur tax sbc #1 } else { ;ver_02 = 0 dec - } ;ver_02 + } ;ver_02 = 1 dex ++ cmp step bcc + @@ -1449,7 +1614,7 @@ copy_cur tax pha } else { ;ver_02 = 0 phx - } ;ver_02 + } ;ver_02 = 1 ldx step1, y +++ php bne + @@ -1523,7 +1688,7 @@ unrread3 = unrelocdsk + (* - reloc) bne - sec + rts - } ;poll_drive or allow_multi + } ;poll_drive = 1 or allow_multi = 1 readdirsel !if ver_02 = 1 { @@ -1533,7 +1698,7 @@ readdirsel } else { ;ver_02 pha phx - } ;ver_02 + } ;ver_02 = 1 unrdrvon4 = unrelocdsk + (* - reloc) lda MOTORON @@ -1542,13 +1707,13 @@ unrdrvon4 = unrelocdsk + (* - reloc) sty adrlo !if poll_drive = 1 { sty status - } ;poll_drive + } ;poll_drive = 1 } else { ;ver_02 = 0 and allow_multi = 0 stz adrlo !if poll_drive = 1 { stz status - } ;poll_drive - } ;ver_02 or allow_multi + } ;poll_drive = 1 + } ;ver_02 = 1 or allow_multi = 1 !if allow_multi = 1 { asl reqcmd bcc seldrive @@ -1562,7 +1727,7 @@ unrdrvsel2 = unrelocdsk + (* - reloc) jsr spinup nodelay - } ;allow_multi + } ;allow_multi = 1 !if poll_drive = 1 { jsr poll bcc + @@ -1572,7 +1737,7 @@ nodelay pla jmp nodisk + - } ;poll_drive + } ;poll_drive = 1 !if ver_02 = 1 { pla tax @@ -1580,7 +1745,7 @@ nodelay } else { ;ver_02 plx pla - } ;ver_02 + } ;ver_02 = 1 readdirsec !if allow_trees = 0 { @@ -1588,7 +1753,7 @@ readdirsect ldy #>dirbuf } else { ;allow_trees = 1 ldy #>dirbuf readdirsect - } ;allow_trees + } ;allow_trees = 1 sty adrhi seekrd ldy #cmdread !if (aligned_read + enable_write) > 1 { @@ -1596,7 +1761,7 @@ seekrdwr sty command } else { ;aligned_read = 0 or enable_write = 0 sty command seekrdwr - } ;aligned_read and enable_write + } ;aligned_read = 1 and enable_write = 1 ;convert block number to track/sector @@ -1637,7 +1802,7 @@ cmpsecrd jsr readadr ldy command cpy #cmdwrite ;we need Y=2 below beq encsec - } ;enable_write + } ;enable_write = 1 cmp reqsec bne cmpsecrd @@ -1645,7 +1810,7 @@ cmpsecrd jsr readadr jsr readd5aa eor #$ad ;zero A if match - bne cmdsecrd + bne cmpsecrd unrread4 = unrelocdsk + (* - reloc) - ldx Q6L bpl - @@ -1666,7 +1831,7 @@ unrread6 = unrelocdsk + (* - reloc) bpl - eor nibtbl - $96, x bne cmpsecrd - } ;check_chksum + } ;check_chksum = 1 -- ldx #$a9 - inx beq -- @@ -1746,9 +1911,6 @@ loopchk1 cmp $ea ;3 cycles loopchk2 - lda prolog - 1, y ;4 cycles - !if >(prolog - 1) != >prolog_e { - !serious "prologue crosses a page" - } jsr writenib2 ;(17 cycles) ;32 cycles if branch taken @@ -1825,9 +1987,6 @@ loopchk6 ;belongs to the "bcs +" above nop ;2 cycles loopchk7 - lda epilog - 1, y ;4 cycles - !if >(epilog - 1) != >epilog_e { - !serious "epilogue crosses a page" - } jsr writenib2 ;(17 cycles) ;32 cycles if branch taken @@ -1853,9 +2012,15 @@ writeret rts ;6 cycles prolog !byte $ad, $aa, $d5 prolog_e + !if >(prolog - 1) != >prolog_e { + !serious "prologue crosses a page" + } epilog !byte $ff, $eb, $aa, $de epilog_e - } ;enable_write + !if >(epilog - 1) != >epilog_e { + !serious "epilogue crosses a page" + } + } ;enable_write = 1 codeend trackd1 !byte 0 trackd2 !byte 0 @@ -1867,28 +2032,33 @@ xlattbl = nibtbl + 106 dataend = xlattbl + 64 } else { ;enable_write = 0 dataend = nibtbl + 106 - } ;enable_write -} ;enable_floppy + } ;enable_write = 1 +} ;enable_floppy = 1 } ;reloc unrelochdd !pseudopc reloc { !if rwts_mode = 1 { + !if no_interrupts = 1 { + php + sei + jsr + + plp + rts ++ + } ;no_interrupts = 1 !if swap_zp = 1 { jsr swap_zpg - } ;swap_zp + } ;swap_zp = 1 sta namhi sty namlo !if ver_02 = 1 { - ldx #0 - stx reqcmd ;seek - stx sizehi - stx adrhi + lda #0 + sta sizehi } else { ;ver_02 - stz reqcmd ;seek stz sizehi - stz adrhi - } ;ver_02 + } ;ver_02 = 1 + !if enable_format = 1 { ldy #$0c ;command lda (namlo),y cmp #2 ;write (or format if greater) @@ -1896,28 +2066,32 @@ unrelochdd bcc skipinit ;read beq skipinit ;write ldy #5 ;sector - !if ver_02 = 1 { + !if ver_02 = 1 { txa - } else { ;ver_02 + } else { ;ver_02 lda #0 - } ;ver_02 + } ;ver_02 = 1 sta (namlo),y dey ;track sta (namlo),y -skipinit ldy #3 ;volume +skipinit + } ;enable_format = 1 + !if allow_multi = 1 { + ldy #3 ;volume lda (namlo),y + !if allow_zerovol = 1 { bne + - lda lastvol -+ cmp lastvol - sta lastvol - bne + - ror adrhi ;bit 7 set if same volume -+ ldy #$0e ;returned volume +lastvol = * + 1 + lda #D1S1 ++ sta lastvol + } ;allow_zerovol = 1 + ldy #$0e ;returned volume sta (namlo),y ldx #vollist_e-vollist_b - dex cmp vollist_b,x bne - + } ;allow_multi = 1 ldy #4 ;track lda (namlo),y asl @@ -1928,6 +2102,7 @@ skipinit ldy #3 ;volume rol sizehi iny ;sector ora (namlo),y + !if allow_multi = 1 { ldy sizehi - dex bmi ++ @@ -1938,65 +2113,97 @@ skipinit ldy #3 ;volume + iny iny bne - -++ tax +++ + } ;allow_multi = 1 + !if allow_trees = 1 { + tax + !if allow_multi = 1 { tya + } else { ;allow_multi = 0 + lda sizehi + } ;allow_multi = 1 lsr sta treeidx - tay txa + } else { ;allow_trees = 0 + lsr sizehi + } ;allow_trees = 1 ror php - -+ bit adrhi - bpl newtree - cpy lasttree - beq newblock - - ;volume or tree changed, so tree changed - -newtree sty lasttree - tax - beq newblock ;block zero will automatically read tree - pha - lda #0 jsr seek1 - pla - - ;block changed, read it - -newblock jsr seek1 plp + !if fast_subindex = 0 { + lda #>hddencbuf + adc #0 + sta adrhi + } else { ;fast_subindex = 1 bcc + inc adrhi -+ ldy #9 ;adrhi ++ + } ;fast_subindex = 0 + ldy #9 ;adrhi lda (namlo),y - sta blokhi + sta scratchhi dey ;adrlo lda (namlo),y - sta bloklo + sta scratchlo + !if enable_format = 1 { ldy #0 + ldx #0 plp bcs runinit - !if swap_zp = 0 { - jmp hddcopycache - } else { ;swap_zp - jsr hddcopycache - beq swap_zpg - } ;swap_zp + } else { ;enable_format = 0 + !if enable_write = 1 { + ldy #$0c ;command + lda (namlo),y + ldy #0 + lsr + bne runinit + } else { ;enable_write = 0 + ldy #0 + } ;enable_write = 1 + } ;enable_format = 1 -runinit php - dec blkidx - bne + - dec treeidx -+ ldx #0 - plp +- lda (adrlo),y + sta (scratchlo),y + iny + bne - + !if swap_zp = 0 { + clc + rts + } else { ;swap_zp = 1 + !if enable_write = 1 { + beq swap_zpg + } ;enable_write = 1 + } ;swap_zp = 0 + + !if enable_write = 1 { +runinit + !if enable_format = 1 { bne format -- lda (bloklo),y + } ;enable_format = 1 +- lda (scratchlo),y sta (adrlo),y iny bne - - lda #1 - bne writesec + lda adrhi + and #$fe + sta adrhi + ldy #cmdwrite +unrcommand1 = unrelochdd + (* - reloc) + sty command + !if use_smartport = 1 { + nop ;allow replacing "sty command" with "sty pcommand" in extended SmartPort mode + } ;use_smartport = 1 + !if swap_zp = 1 { + jsr hddwriteimm + !if enable_format = 1 { + bcc swap_zpg ;always + } ;enable_format = 1 + } else { ;swap_zp = 0 + jmp hddwriteimm + } ;swap_zp = 1 + !if enable_format = 1 { clrcarry clc inc adrhi format lda blanksec,x @@ -2012,53 +2219,63 @@ format lda blanksec,x stx lasttree iny lda #$18 ;blocks - -writesec sta namlo + sta namlo sty namhi lda adrhi and #$fe sta adrhi -- lda #cmdwrite ;also size - sta sizehi + lda #cmdwrite sta reqcmd - jsr hddrdwrloop - dec adrhi - dec adrhi - dec namlo + inc lastblk ;force mismatch +- jsr hddrdwrloop + inc blkidx + bne + + inc treeidx ++ dec namlo bne - dec namhi bpl - - clc + } ;enable_format = 1 + } ;enable_write = 1 !if swap_zp = 1 { -swap_zpg - pha +swap_zpg pha tya pha ldx #(last_zp - first_zp) - lda first_zp,x - ldy hddcodeend,x - sta hddcodeend,x + ldy zp_array,x + sta zp_array,x sty first_zp,x dex bpl - pla tay pla - } ;swap_zp - rts + } ;swap_zp = 1 + !if (enable_write + swap_zp) > 0 { + !if no_interrupts = 0 { + clc + } ;no_interrupts = 0 + rts + } ;enable_write = 1 or swap_zp = 1 + + !if enable_format = 1 { blanksec !text "SAN INC." + } ;enable_format = 1 seek1 sta blkidx - lda #1 - sta sizehi -} else { ;rwts_mode + !if enable_write = 1 { + lda #cmdread + sta reqcmd + } ;enable_write = 1 +} else { ;rwts_mode = 0 hddopendir !if no_interrupts = 1 { !if detect_err = 1 { clc - } ;detect_err + } ;detect_err = 1 php sei jsr + @@ -2066,11 +2283,11 @@ hddopendir pla adc #0 pha - } ;detect_err + } ;detect_err = 1 plp rts + - } ;no_interrupts + } ;no_interrupts = 1 ;read volume directory key block ;self-modified by init code @@ -2086,26 +2303,30 @@ unrhddblockhi = unrelochdd + (* - reloc) ;essential padding to match offset with floppy version !fill (readdir - opendir) - (* - hddopendir), $ea } - } ;enable_floppy + } ;enable_floppy = 1 hddreaddir ;note that calling this location directly limits subdirectories to 14 entries! lda #NAME_LENGTH + ENTRY_SIZE -hddfirstent sta bloklo +hddfirstent sta scratchlo dirbufpatch1 lda #>(hdddirbuf - 1) - sta blokhi + sta scratchhi !if might_exist = 1 { lda hdddirbuf + FILE_COUNT ;assuming only 256 files per subdirectory sta entries - } ;might_exist + !if many_files = 1 { + lda hdddirbuf + FILE_COUNT + 1 + sta entrieshi + } ;many_files = 1 + } ;might_exist = 1 ;there can be only one page crossed, so we can increment here -hddnextent1 inc blokhi +hddnextent1 inc scratchhi hddnextent ldy #0 - !if (might_exist + allow_subdir + allow_saplings + (allow_trees and (always_trees xor 1))) > 0 { - lda (bloklo), y + !if (might_exist + allow_subdir + allow_saplings + (always_trees xor 1)) > 0 { + lda (scratchlo), y !if might_exist = 1 { sty status @@ -2113,9 +2334,9 @@ hddnextent ldy #0 and #MASK_ALL beq + - } ;might_exist + } ;might_exist = 1 - !if (allow_subdir + allow_saplings + (allow_trees and (always_trees xor 1))) > 0 { + !if (allow_subdir + allow_saplings + (always_trees xor 1)) > 0 { ;remember type ;now bits 5-4 are represented by carry (subdirectory), sign (sapling) @@ -2128,14 +2349,14 @@ hddnextent ldy #0 sta treeidx bit treeidx - } ;allow_trees + } ;allow_trees = 1 php - } ;allow_subdir or allow_saplings or allow_trees - } ;might_exist or allow_subdir or allow_saplings or allow_trees + } ;allow_subdir = 1 or allow_saplings = 1 or always_trees = 0 + } ;might_exist = 1 or allow_subdir = 1 or allow_saplings = 1 or always_trees = 0 ;match name lengths before attempting to match names - lda (bloklo), y + lda (scratchlo), y and #$0f tax inx @@ -2145,22 +2366,30 @@ hddnextent ldy #0 ;match failed, check if any directory entries remain - !if (allow_subdir + allow_saplings + (allow_trees and (always_trees xor 1))) > 0 { + !if (allow_subdir + allow_saplings + (always_trees xor 1)) > 0 { plp - } ;allow_subdir or allow_saplings or (allow_trees and not always_trees) + } ;allow_subdir = 1 or allow_saplings = 1 or always_trees = 0 !if might_exist = 1 { dec entries bne + + !if many_files = 1 { + lda entrieshi + bne ++ + } ;many_files = 1 inc status rts - } ;might_exist + + !if many_files = 1 { +++ dec entrieshi + } ;many_files = 1 + } ;might_exist = 1 ;move to next entry in this block, if possible + clc - lda bloklo + lda scratchlo adc #ENTRY_SIZE - sta bloklo + sta scratchlo bcs hddnextent1 cmp #$ff ;4 + ($27 * $0d) bne hddnextent @@ -2176,7 +2405,7 @@ dirbufpatch3 bne hddfirstent hddfoundname iny - lda (bloklo), y + lda (scratchlo), y dex bne - @@ -2186,32 +2415,48 @@ hddfoundname iny stx treeidx !if always_trees = 0 { stx istree - } ;always_trees - } ;allow_trees + } ;always_trees = 0 + } ;allow_trees = 1 stx blkidx - !if aligned_read = 0 { + !if (aligned_read + one_shot) = 0 { stx blkofflo stx blkoffhi - } ;aligned_read + } ;aligned_read = 0 and one_shot = 0 !if enable_write = 1 { + !if aligned_read = 0 { ldy reqcmd cpy #cmdwrite ;control carry instead of zero bne + - !if aligned_read = 0 { - stx sizelo - } ;aligned_read -+ - } ;enable_write + } ;aligned_read = 0 + !if one_shot = 0 { - !if bounds_check = 1 { + ;round requested size up to nearest block if writing + + lda sizelo + adc #$fe + lda sizehi + adc #1 + and #$fe + sta sizehi + !if aligned_read = 0 { + stx sizelo + !if bounds_check = 1 { + sec + } ;bounds_check = 1 + } ;aligned_read = 0 + } ;one_shot = 0 ++ + } ;enable_write = 1 + + !if (bounds_check + return_size + one_shot) > 0 { ;cache EOF (file size, loaded backwards) ldy #EOF_HI - lda (bloklo), y + lda (scratchlo), y !if (enable_write + aligned_read) > 0 { tax dey ;EOF_LO - lda (bloklo), y + lda (scratchlo), y ;round file size up to nearest block if writing without aligned reads ;or always if using aligned reads @@ -2221,8 +2466,8 @@ hddfoundname iny } else { ;aligned_read = 1 !if enable_write = 1 { sec - } ;enable_write - } ;aligned_read + } ;enable_write = 1 + } ;aligned_read = 0 adc #$fe txa adc #1 @@ -2230,54 +2475,65 @@ hddfoundname iny !if aligned_read = 0 { tax lda #0 + !if one_shot = 0 { + stx blefthi sta bleftlo + } else { ;one_shot = 1 ++ stx sizehi + sta sizelo + } ;one_shot = 0 } else { ;aligned_read = 1 + !if one_shot = 0 { sta blefthi - } ;aligned_read + } else { ;one_shot = 1 + sta sizehi + } ;one_shot = 0 + } ;aligned_read = 0 } else { ;enable_write = 0 and aligned_read = 0 + !if one_shot = 0 { sta blefthi + } else { ;one_shot = 1 + sta sizehi + } ;one_shot = 0 dey ;EOF_LO - lda (bloklo), y + lda (scratchlo), y + !if one_shot = 0 { sta bleftlo - } ;enable_write or aligned_read - } ;bounds_check + } else { ;one_shot = 1 + sta sizelo + } ;one_shot = 0 + } ;enable_write = 1 or aligned_read = 1 + } ;bounds_check = 1 or return_size = 1 or one_shot = 1 ;cache AUX_TYPE (load offset for binary files) !if override_adr = 0 { - lda reqcmd - lsr - bne + ;cmdwrite ldy #AUX_TYPE - lda (bloklo), y + lda (scratchlo), y !if (allow_subdir + allow_saplings + allow_trees + (aligned_read xor 1)) > 0 { sta ldrlo - sta ldrlo2 iny - lda (bloklo), y + lda (scratchlo), y sta ldrhi - sta ldrhi2 -+ - } else { ;allow_subdir = 0 and allow_saplings = 0 and allow_trees = 0 and aligned_read = 1 + } else { ;allow_subdir = 0 and allow_saplings = 0 and allow_trees = 0 and aligned_read = 1 pha iny - lda (bloklo), y + lda (scratchlo), y pha - } ;allow_subdir or allow_saplings or allow_trees or not aligned_read - } ;override_adr + } ;allow_subdir = 1 or allow_saplings = 1 or allow_trees = 1 or aligned_read = 0 + } ;override_adr = 0 ;;allow query even in override mode ldy #AUX_TYPE - lda (bloklo), y + lda (scratchlo), y sta ldrlo2 iny - lda (bloklo), y + lda (scratchlo), y sta ldrhi2 ;cache KEY_POINTER ldy #KEY_POINTER - lda (bloklo), y + lda (scratchlo), y tax !if (allow_subdir + allow_saplings + allow_trees) > 0 { dirbufpatch4 @@ -2286,48 +2542,47 @@ dirbufpatch4 sta treeblklo } ;allow_trees = 1 and fast_trees = 0 iny - lda (bloklo), y + lda (scratchlo), y dirbufpatch5 sta hdddirbuf + 256 !if (allow_trees + (fast_trees xor 1)) > 1 { sta treeblkhi } ;allow_trees = 1 and fast_trees = 0 - !if (allow_trees and always_trees) = 0 { + !if always_trees = 0 { plp attribpatch bpl ++ !if allow_subdir = 1 { php - } ;allow_subdir + } ;allow_subdir = 1 !if allow_trees = 1 { ldy #>hdddirbuf bvc + !if fast_trees = 1 { ldy #>hddtreebuf - } ;fast_trees + } ;fast_trees = 1 sty istree + - } ;allow_trees - } else { ;allow_trees = 0 or always_trees = 1 - !if (allow_trees + always_trees) > 1 { + } ;allow_trees = 1 + } else { ;always_trees = 1 ldy #>hddtreebuf - } ;allow_trees and always_trees - } ;allow_trees or always_trees + } ;always_trees = 0 } else { ;allow_subdir = 0 and allow_saplings = 0 and allow_trees = 0 iny - lda (bloklo), y - } ;allow_subdir or allow_saplings or allow_trees + lda (scratchlo), y + } ;allow_subdir = 1 or allow_saplings = 1 or allow_trees = 1 - ;read index block in case of sapling + ;read index block in case of sapling or tree jsr hddreaddirsect !if allow_subdir = 1 { plp bcs hddrdwrfilei - } ;allow_subdir + } else { ;allow_subdir = 0 ++ -} ;rwts_mode + } ;allow_subdir = 1 +} ;rwts_mode = 1 hddrdwrpart hddrdfile @@ -2337,13 +2592,14 @@ hddrdwrfile hddrdwrfilex !if allow_subdir = 1 { clc -} ;allow_subdir -!if no_interrupts = 1 { +++ +} ;allow_subdir = 1 +!if (no_interrupts + (rwts_mode xor 1)) > 1 { !if detect_err = 1 { !if allow_subdir = 0 { clc - } ;allow_subdir - } ;detect_err + } ;allow_subdir = 0 + } ;detect_err = 1 php sei jsr + @@ -2351,11 +2607,11 @@ hddrdwrfilex pla adc #0 pha - } ;detect_err + } ;detect_err = 1 plp rts + -} ;no_interrupts +} ;no_interrupts = 1 and rwts_mode = 0 hddrdwrfilei !if rwts_mode = 0 { @@ -2375,9 +2631,9 @@ dirbufpatch6 lda #0 !if aligned_read = 0 { sta sizelo - } ;aligned_read + } ;aligned_read = 0 + - } ;allow_subdir + } ;allow_subdir = 1 sta adrlo stx adrhi } else { ;override_adr = 0 and allow_subdir = 0 and allow_saplings = 0 and allow_trees = 0 and aligned_read = 1 @@ -2385,7 +2641,7 @@ dirbufpatch6 sta adrhi pla sta adrlo - } ;override_adr or allow_subdir or allow_saplings or allow_trees and not aligned_read + } ;override_adr = 1 or allow_subdir = 1 or allow_saplings = 1 or allow_trees = 1 or aligned_read = 0 ;set requested size to min(length, requested size) @@ -2399,7 +2655,7 @@ dirbufpatch6 bcs hddcopyblock sty sizelo stx sizehi - } ;bounds_check + } ;bounds_check = 1 hddcopyblock ldx sizehi2 @@ -2413,12 +2669,13 @@ hddcopyblock !if allow_aux = 1 { ldx auxreq jsr hddsetaux - } ;allow_aux - !if enable_write = 1 { + } ;allow_aux = 1 + !if one_shot = 0 { + !if enable_write = 1 { lda reqcmd lsr bne hddrdwrloop - } ;enable_write + } ;enable_write = 1 ;if offset is non-zero then we return from cache @@ -2431,9 +2688,9 @@ hddcopyblock lda sizelo pha lda adrhi - sta blokhi + sta scratchhi lda adrlo - sta bloklo + sta scratchlo stx adrlo encbufpatch1 lda #>hddencbuf @@ -2458,11 +2715,11 @@ encbufpatch1 sty sizelo stx sizehi + - !if enable_seek = 1 { + !if enable_seek = 1 { lda sizehi - } else { ;enable_seek = 0 + } else { ;enable_seek = 0 ldy sizehi - } ;enable_seek + } ;enable_seek = 1 jsr hddcopycache ;align to next block and resume read @@ -2481,8 +2738,23 @@ encbufpatch1 sbc sizehi sta sizehi ora sizelo + !if allow_subdir = 1 { + !if no_interrupts = 1 { + clc + bne hddrdwrfilei + } else { ;no_interrupts = 0 beq hddrdwrdone jmp hddrdwrfilex + } ;no_interrupts = 1 + } else { ;allow_subdir = 0 + bne hddrdwrfilei + } ;allow_subdir = 1 + !if allow_aux = 0 { + rts + } else { ;allow_aux = 1 + beq hddrdwrdone + } ;allow_aux = 0 + } ;one_shot = 0 } else { ;aligned_read = 1 !if bounds_check = 1 { lda blefthi @@ -2490,20 +2762,19 @@ encbufpatch1 bcs + sta sizehi + - } ;bounds_check + } ;bounds_check = 1 !if allow_aux = 1 { ldx auxreq jsr hddsetaux - } ;allow_aux - } ;aligned_read -} ;rwts_mode + } ;allow_aux = 1 + } ;aligned_read = 0 +} ;rwts_mode = 0 hddrdwrloop -!if aligned_read = 0 { - !if rwts_mode = 0 { - !if (enable_write + enable_seek) > 0 { +!if (aligned_read + rwts_mode) = 0 { + !if (enable_write + enable_seek) > 0 { ldx reqcmd - } ;enable_write or enable_seek + } ;enable_write = 1 or enable_seek = 1 ;set read/write size to min(length, $200) @@ -2518,26 +2789,23 @@ hddrdwrloop pha lda adrlo pha - lda #2 - sta sizehi - } ;rwts_mode encbufpatch2 lda #>hddencbuf sta adrhi !if ver_02 = 1 { ldx #0 stx adrlo - !if ((enable_write + enable_seek) and (rwts_mode - 1)) > 0 { + !if (enable_write + enable_seek) > 0 { inx ;ldx #cmdread - } ;(enable_write or enable_seek) and not rwts_mode + } ;enable_write = 1 or enable_seek = 1 } else { ;ver_02 = 0 stz adrlo - !if ((enable_write + enable_seek) and (rwts_mode - 1)) > 0 { + !if (enable_write + enable_seek) > 0 { ldx #cmdread - } ;(enable_write or enable_seek) and not rwts_mode - } ;ver_02 + } ;enable_write = 1 or enable_seek = 1 + } ;ver_02 = 1 + -} ;aligned_read +} ;aligned_read = 0 and rwts_mode = 0 !if allow_trees = 1 { ;read tree data block only if tree and not read already @@ -2549,203 +2817,276 @@ encbufpatch2 !if always_trees = 0 { lda istree beq + - } ;always_trees - } else { ;rwts_mode = 1 - ldy #>hddtreebuf - } ;rwts_mode + } ;always_trees = 0 lda adrhi pha lda adrlo pha - !if rwts_mode = 0 { !if ((aligned_read xor 1) + (enable_write or enable_seek)) > 1 { !if ver_02 = 1 { txa pha } else { ;ver_02 = 0 phx - } ;ver_02 - } ;(not aligned_read) and (enable_write or enable_seek) + } ;ver_02 = 1 + } ;aligned_read = 0 and (enable_write = 1 or enable_seek = 1) !if aligned_read = 0 { php - } ;aligned_read + } ;aligned_read = 0 lda #>hdddirbuf sta adrhi sty adrlo } else { ;rwts_mode = 1 - ;or in this case, read whenever tree index changes + !if fast_subindex = 0 { + ;read whenever block index changes + + !if mem_swap = 0 { + ldy blkidx + cpy lastblk + } else { ;mem_swap = 1 +blkidx = * + 1 + ldy #$d1 +lastblk = * + 1 + cpy #$d1 + } ;mem_swap = 0 + sty lastblk + php + pla + !if mem_swap = 0 { + ;read whenever tree index changes - sty adrhi ldy treeidx cpy lasttree - beq skiptree + } else { ;mem_swap = 1 +treeidx = * + 1 + ldy #$d1 +lasttree = * + 1 + cpy #$d1 + } ;mem_swap = 0 + + sty lasttree + bne readtree + pha + plp + beq skipblk + +readtree + } else { ;fast_subindex = 1 + ;read whenever tree index changes + + !if mem_swap = 0 { + ldy treeidx + cpy lasttree + beq hddskiptree sty lasttree ldx blkidx + } else { ;mem_swap = 1 +treeidx = * + 1 + ldy #$d1 +lasttree = * + 1 + cpy #$d1 + beq hddskiptree + sty lasttree +blkidx = * + 1 + ldx #$d1 + } ;mem_swap = 0 inx stx lastblk - } ;rwts_mode + } ;fast_subindex = 0 + } ;rwts_mode = 0 ;fetch tree data block and read it !if fast_trees = 0 { ldx treeblklo lda treeblkhi - jsr hddseekrd + jsr hddreaddirsel ldy treeidx !if rwts_mode = 0 { inc treeidx - } ;rwts_mode + } ;rwts_mode = 0 ldx hdddirbuf, y lda hdddirbuf + 256, y } else { ;fast_trees = 1 ldy treeidx !if rwts_mode = 0 { inc treeidx - } ;rwts_mode + } ;rwts_mode = 0 ldx hddtreebuf, y lda hddtreebuf + 256, y - } ;fast_trees + } ;fast_trees = 0 !if detect_treof = 1 { - bne noteof1 + bne hddnoteof1 tay txa - bne fixy1 + bne hddfixy1 + !if aligned_read = 0 { + plp + bcs hddfewpop + pla + pla + pla +hddfewpop + } ;aligned_read = 0 pla pla sec rts -fixy1 tya -noteof1 - } ;detect_treof - !if aligned_read = 0 { - php - } ;aligned_read +hddfixy1 tya +hddnoteof1 + } ;detect_treof = 1 + !if fast_trees = 0 { jsr hddseekrd + } else { ;fast_trees = 1 + jsr hddreaddirsel + } ;fast_trees = 0 -skiptree !if rwts_mode = 0 { !if aligned_read = 0 { plp - } ;aligned_read + } ;aligned_read = 0 !if ((aligned_read xor 1) + (enable_write or enable_seek)) > 1 { !if ver_02 = 1 { pla tax } else { ;ver_02 = 0 plx - } ;ver_02 - } ;(not aligned_read) and (enable_write or enable_seek) - } ;rwts_mode + } ;ver_02 = 1 + } ;aligned_read = 0 and (enable_write = 1 or enable_seek = 1) pla sta adrlo pla sta adrhi -} ;allow_trees + } ;rwts_mode = 0 +} ;allow_trees = 1 ;fetch data block and read/write it -!if rwts_mode = 1 { -+ -} ;rwts_mode - ldy blkidx +hddskiptree ldy blkidx !if rwts_mode = 0 { + inc blkidx !if aligned_read = 0 { !if enable_seek = 1 { txa ;cpx #cmdseek, but that would require php at top beq + - } ;enable_seek + } ;enable_seek = 1 !if enable_write = 1 { unrcommand2 = unrelochdd + (* - reloc) stx command !if use_smartport = 1 { nop ;allow replacing "stx command" with "stx pcommand" in extended SmartPort mode - } ;use_smartport - } ;enable_write - } ;aligned_read + } ;use_smartport = 1 + } ;enable_write = 1 + } ;aligned_read = 0 } else { ;rwts_mode = 1 + !if fast_subindex = 1 { + lda #>hddencbuf + sta adrhi + ;read whenever block index changes + !if mem_swap = 0 { cpy lastblk + } else { ;mem_swap = 1 +lastblk = * + 1 + cpy #$d1 + } ;mem_swap = 0 beq skipblk sty lastblk -} ;rwts_mode + } ;fast_subindex = 1 +} ;rwts_mode = 0 dirbufpatch7 ldx hdddirbuf, y dirbufpatch8 lda hdddirbuf + 256, y !if detect_treof = 1 { - bne noteof2 + bne hddnoteof2 tay txa - bne fixy2 + bne hddfixy2 sec rts -fixy2 tya -noteof2 -} ;detect_treof -!if allow_sparse = 1 { +hddfixy2 tya +hddnoteof2 +} ;detect_treof = 1 +!if allow_sparse = 0 { + !if rwts_mode = 1 { + !if enable_write = 0 { + jmp hddseekrd + } else { ;enable_write = 1 + ldy reqcmd + jmp hddseekrdwr + } ;enable_write = 0 + } ;rwts_mode = 1 +} else { ;allow_sparse = 1 pha dirbufpatch9 ora hdddirbuf, y tay pla + !if rwts_mode = 0 { dey iny ;don't affect carry -} ;allow_sparse -!if (aligned_read + rwts_mode) = 0 { - php -} ;aligned_read or rwts_mode -!if allow_sparse = 1 { - !if rwts_mode = 0 { - beq hddissparse } else { ;rwts_mode = 1 + !if enable_write = 1 { + cpy #1 + ldy reqcmd + bcs hddseekrdwr + tay + } else { ;enable_write = 0 + dey + iny ;don't affect carry bne hddseekrd - } ;rwts_mode -} ;allow_sparse + } ;enable_write = 1 + } ;rwts_mode = 0 +} ;allow_sparse = 0 !if rwts_mode = 0 { + !if aligned_read = 0 { + php + } ;aligned_read = 0 + !if allow_sparse = 1 { + beq hddissparse + } ;allow_sparse = 1 !if (aligned_read and (enable_write or enable_seek)) = 1 { ldy reqcmd !if enable_seek = 1 { beq + - } ;enable_seek - } ;aligned_read and (enable_write or enable_seek) + } ;enable_seek = 1 + } ;aligned_read = 1 and (enable_write = 1 or enable_seek = 1) !if enable_write = 1 { jsr hddseekrdwr } else { ;enable_write = 0 jsr hddseekrd - } ;enable_write + } ;enable_write = 1 + hddresparse !if aligned_read = 0 { plp - !if bounds_check = 1 { + bcc + + !if bounds_check = 1 { dec blefthi dec blefthi - } ;bounds_check - } ;aligned_read + } ;bounds_check = 1 + } ;aligned_read = 0 inc adrhi inc adrhi -+ dec sizehi + dec sizehi dec sizehi bne hddrdwrloop !if aligned_read = 0 { - !if bounds_check = 1 { - bcc + - } ;bounds_check lda sizelo bne hddrdwrloop - } ;aligned_read + } ;aligned_read = 0 hddrdwrdone !if allow_aux = 1 { ldx #0 hddsetaux sta CLRAUXRD, x sta CLRAUXWR, x - } ;allow_aux + } ;allow_aux = 1 rts -} ;rwts_mode +} ;rwts_mode = 0 !if allow_sparse = 1 { hddissparse @@ -2757,62 +3098,50 @@ hddissparse bne - !if rwts_mode = 0 { beq hddresparse - } ;rwts_mode -} ;allow_sparse -!if rwts_mode = 1 { + } else { ;rwts_mode = 1 skipblk rts -} ;rwts_mode - -!if aligned_read = 0 { + } ;rwts_mode = 0 +} ;allow_sparse = 1 +!if rwts_mode = 0 { + !if aligned_read = 0 { ;cache partial block offset + pla - sta bloklo + sta scratchlo pla - sta blokhi + sta scratchhi pla + !if one_shot = 0 { sta sizehi - !if bounds_check = 0 { - dec adrhi - dec adrhi - } ;bounds_check + } ;one_shot = 0 - !if enable_seek = 1 { - !if rwts_mode = 0 { + !if enable_seek = 1 { hddcopycache - } ;rwts_mode ldy reqcmd ;cpy #cmdseek - !if rwts_mode = 0 { beq ++ tay - } else { ;rwts_mode - beq hddrdwrdone -hddcopycache - } ;rwts_mode - } else { ;enable_seek = 0 + } else { ;enable_seek = 0 tay hddcopycache - } ;enable_seek - !if rwts_mode = 0 { + } ;enable_seek = 1 beq + dey - } ;rwts_mode - lda (adrlo), y - sta (bloklo), y + sta (scratchlo), y iny bne - - !if rwts_mode = 0 { - inc blokhi + inc scratchhi inc adrhi bne + - lda (adrlo), y - sta (bloklo), y + sta (scratchlo), y iny + cpy sizelo bne - ++ - !if bounds_check = 1 { + !if one_shot = 0 { + !if bounds_check = 1 { lda bleftlo sec sbc sizelo @@ -2820,13 +3149,13 @@ hddcopycache lda blefthi sbc sizehi sta blefthi - } ;bounds_check + } ;bounds_check = 1 clc - !if enable_seek = 1 { + !if enable_seek = 1 { lda sizelo - } else { ;enable_seek = 0 + } else { ;enable_seek = 0 tya - } ;enable_seek + } ;enable_seek = 1 adc blkofflo sta blkofflo lda sizehi @@ -2834,10 +3163,19 @@ hddcopycache and #$fd sta blkoffhi bcc hddrdwrdone ;always - } else { ;rwts_mode = 1 -hddrdwrdone rts - } ;rwts_mode -} ;aligned_read + } else { ;one_shot = 1 + !if allow_aux = 1 { + beq hddrdwrdone + } else { ;allow_aux = 0 + rts + } ;allow_aux = 1 + } ;one_shot = 0 + } ;aligned_read = 0 +} else { ;rwts_mode = 1 + !if allow_sparse = 0 { +skipblk rts + } ;allow_sparse = 0 +} ;rwts_mode = 0 hddreaddirsel !if ver_02 = 1 { @@ -2845,18 +3183,18 @@ hddreaddirsel sty adrlo !if might_exist = 1 { sty status - } ;might_exist + } ;might_exist = 1 } else { ;ver_02 = 0 stz adrlo !if might_exist = 1 { stz status - } ;might_exist -} ;ver_02 + } ;might_exist = 1 +} ;ver_02 = 1 -!if allow_multi = 1 { +!if (enable_floppy + allow_multi) > 1 { asl reqcmd lsr reqcmd -} ;allow_multi +} ;enable_floppy = 1 and allow_multi = 1 hddreaddirsec !if allow_trees = 0 { @@ -2865,50 +3203,83 @@ hddreaddirsect ldy #>hdddirbuf } else { ;allow_trees = 1 ldy #>hdddirbuf hddreaddirsect -} ;allow_trees +} ;allow_trees = 0 sty adrhi hddseekrd ldy #cmdread -!if (aligned_read + enable_write) > 1 { +!if ((rwts_mode or aligned_read) + enable_write) > 1 { hddseekrdwr -} ;aligned_read and enable_write -unrcommand1 = unrelochdd + (* - reloc) +} ;(rwts_mode = 1 or aligned_read = 1) and enable_write = 1 +unrcommand3 = unrelochdd + (* - reloc) sty command !if use_smartport = 1 { nop ;allow replacing "sty command" with "sty pcommand" in extended SmartPort mode -} ;use_smartport +} ;use_smartport = 1 !if (aligned_read and enable_write) = 0 { hddseekrdwr -} ;aligned_read and enable_write +} ;aligned_read = 0 or enable_write = 0 unrbloklo = unrelochdd + (* - reloc) stx bloklo !if use_smartport = 1 { nop ;allow replacing "stx bloklo" with "stx pblock" in extended SmartPort mode -} ;use_smartport +} ;use_smartport = 1 unrblokhi = unrelochdd + (* - reloc) sta blokhi !if use_smartport = 1 { nop ;allow replacing "sta blokhi" with "sta pblock + 1" in extended SmartPort mode -} ;use_smartport +} ;use_smartport = 1 unrunit1 = unrelochdd + (* - reloc) lda #$d1 sta unit !if use_smartport = 1 { nop ;allow replacing "lda #$d1/sta unit" with "lda adrlo/sta paddr" in extended SmartPort mode -} ;use_smartport - lda adrhi ;for Trackstar support +} ;use_smartport = 1 +hddwriteimm lda adrhi ;for Trackstar support pha !if use_smartport = 1 { sta paddr + 1 -} ;use_smartport -unrentry2 = unrelochdd + (* - reloc) +} ;use_smartport = 1 +!if swap_scrn = 1 { + jsr saveslot +} ;swap_scrn = 1 + +unrentry = unrelochdd + (* - reloc) jsr $d1d1 !if use_smartport = 1 { +unrpcommand = unrelochdd + (* - reloc) pcommand !byte $2c ;hide packet in non-SmartPort mode - !word packet -} ;use_smartport +unrppacket = unrelochdd + (* - reloc) + !word unrelochdd + (packet - reloc) +} ;use_smartport = 1 +hackstar = unrelochdd + (* - reloc) pla sta adrhi ;Trackstar does not preserve adrhi + +!if swap_scrn = 1 { +saveslot + lda #4 + sta $49 + ldx #0 + stx $48 + sta $4a +-- ldy #$78 +- lda ($48), y + pha + lda scrn_array, x +initpatch lda ($48), y + pla + sta scrn_array, x + inx + tya + eor #$80 + tay + bmi - + iny + bpl - + inc $49 + dec $4a + bne -- +} ;swap_scrn = 1 rts !if use_smartport = 1 { @@ -2918,18 +3289,30 @@ unrunit2 = unrelochdd + (* - reloc) !byte 0 paddr !word readbuff + $200 pblock !byte 2, 0, 0 -} ;use_smartport +} ;use_smartport = 1 -!if rwts_mode = 1 { +!if (rwts_mode + allow_multi) > 1 { vollist_b !byte D1S1 vollist_e -} ;rwts_mode +} ;rwts_mode = 1 and allow_multi = 1 hddcodeend -!if swap_zp = 1 { -zp_array !fill last_zp - first_zp -} ;swap_zp +!if swap_scrn = 1 { +scrn_array + !if swap_zp = 1 { +zp_array = scrn_array + 64 +hdddataend = zp_array + last_zp - first_zp + } else { ;swap_zp = 0 +hdddataend = scrn_array + 64 + } ;swap_zp = 1 +} else { ;swap_scrn = 0 + !if swap_zp = 1 { +zp_array +hdddataend = zp_array + last_zp - first_zp + } else { ;swap_zp = 0 hdddataend + } ;swap_zp = 1 +} ;swap_scrn = 1 } ;reloc ;[music] you can't touch this [music] @@ -2946,17 +3329,73 @@ hdddataend !warn "initial reloc too low, adjust to ", $c000 - (((dataend + $ff) & -256) - reloc) } ;dataend dirbuf = reloc - $200 - encbuf = dirbuf - $200 + !if ((aligned_read xor 1) + enable_write) > 0 { + encbuf = dirbuf - $200 + } ;aligned_read = 0 or enable_write = 1 !if allow_trees = 1 { - treebuf = encbuf - $200 + !if fast_trees = 1 { + !if ((aligned_read xor 1) + enable_write) > 0 { + treebuf = encbuf - $200 + } else { ;aligned_read = 1 and enable_write = 0 + treebuf = dirbuf - $200 + } ;aligned_read = 0 or enable_write = 1 + } else { ;fast_trees = 0 + treebuf = dirbuf + } ;fast_trees } ;allow_trees } else { ;load_high = 0 !pseudopc ((dataend + $ff) & -256) { dirbuf = * + !if (dirbuf + $200) > $c000 { + !if dirbuf < $d000 { + !set dirbuf = reloc - $200 + } ;dirbuf + } ;dirbuf } - encbuf = dirbuf + $200 + !if ((aligned_read xor 1) + enable_write) > 0 { + !if fast_subindex = 0 { + encbuf = dirbuf ;writes come from cache + } else { ;fast_subindex = 1 + !if dirbuf < reloc { + encbuf = dirbuf - $200 + } else { ;dirbuf + encbuf = dirbuf + $200 + !if (encbuf + $200) > $c000 { + !if encbuf < $d000 { + !set encbuf = reloc - $200 + } ;encbuf + } ;encbuf + } ;dirbuf + } ;fast_subindex + } ;aligned_read = 0 or enable_write = 1 !if allow_trees = 1 { - treebuf = encbuf + $200 + !if fast_trees = 1 { + !if ((aligned_read xor 1) + rwts_mode) > 0 { + !if encbuf < reloc { + treebuf = encbuf - $200 + } else { ;encbuf + treebuf = encbuf + $200 + !if (treebuf + $200) > $c000 { + !if treebuf < $d000 { + !set treebuf = reloc - $200 + } ;treebuf + } ;treebuf + } ;encbuf + } else { ;aligned_read = 1 and rwts_mode = 0 + !if dirbuf < reloc { + treebuf = dirbuf - $200 + } else { ;dirbuf + treebuf = dirbuf + $200 + !if (treebuf + $200) > $c000 { + !if treebuf < $d000 { + !set treebuf = reloc - $200 + } ;treebuf + } ;treebuf + } ;dirbuf + } ;aligned_read = 0 or rwts_mode = 1 + } else { ;fast_trees = 0 + treebuf = dirbuf + } ;fast_trees } ;allow_trees } ;load_high } else { ;reloc > $c000 @@ -2970,17 +3409,37 @@ hdddataend !warn "initial reloc too low, adjust to ", (0 - (((dataend + $ff) & -256) - reloc)) & $ffff } ;dataend dirbuf = reloc - $200 - encbuf = dirbuf - $200 + !if aligned_read = 0 { + encbuf = dirbuf - $200 + } ;aligned_read !if allow_trees = 1 { - treebuf = encbuf - $200 + !if fast_trees = 1 { + !if ((aligned_read xor 1) + enable_write) > 0 { + treebuf = encbuf - $200 + } else { ;aligned_read = 1 and enable_write = 0 + treebuf = dirbuf - $200 + } ;aligned_read = 0 or enable_write = 1 + } else { ;fast_trees = 0 + treebuf = dirbuf + } ;fast_trees } ;allow_trees } else { ;load_high = 0 !pseudopc ((dataend + $ff) & -256) { dirbuf = * } - encbuf = dirbuf + $200 + !if aligned_read = 0 { + encbuf = dirbuf + $200 + } ;aligned_read !if allow_trees = 1 { - treebuf = encbuf + $200 + !if fast_trees = 1 { + !if ((aligned_read xor 1) + enable_write) > 0 { + treebuf = encbuf + $200 + } else { ;aligned_read = 1 and enable_write = 0 + treebuf = dirbuf + $200 + } ;aligned_read = 0 or enable_write = 1 + } else { ;fast_trees = 0 + treebuf = dirbuf + } ;fast_trees } ;allow_trees } ;load_high } ;reloc @@ -2991,9 +3450,9 @@ hdddataend !if aligned_read = 0 { !warn "floppy encbuf: ", encbuf, "-", encbuf + $1ff } ;aligned_read - !if (allow_trees + fast_trees) > 1 { + !if allow_trees = 1 { !warn "floppy treebuf: ", treebuf, "-", treebuf + $1ff - } ;allow_trees and fast_trees + } ;allow_trees !warn "floppy driver start: ", unrelocdsk - init } ;verbose_info } ;enable_floppy @@ -3010,45 +3469,69 @@ hdddataend hddencbuf = hdddirbuf - $200 } ;aligned_read !if allow_trees = 1 { - !if aligned_read = 0 { - hddtreebuf = hddencbuf - $200 - } else { ;aligned_read = 1 - hddtreebuf = hdddirbuf - $200 - } ;aligned_read + !if fast_trees = 1 { + !if ((aligned_read xor 1) + enable_write) > 0 { + hddtreebuf = hddencbuf - $200 + } else { ;aligned_read = 1 and enable_write = 0 + hddtreebuf = hdddirbuf - $200 + } ;aligned_read = 0 or enable_write = 1 + } else { ;fast_trees = 0 + hddtreebuf = hdddirbuf + } ;fast_trees } ;allow_trees } else { ;load_high = 0 !pseudopc ((hdddataend + $ff) & -256) { hdddirbuf = * + !if (hdddirbuf + $200) > $c000 { + !if hdddirbuf < $d000 { + !set hdddirbuf = reloc - $200 + } ;hdddirbuf + } ;hdddirbuf } - !if aligned_read = 0 { - hddencbuf = hdddirbuf + $200 - !if (hddencbuf + $200) > $c000 { - !if hddencbuf < $d000 { - !set hddencbuf = reloc - $200 - } - } - } ;aligned_read + !if ((aligned_read xor 1) + rwts_mode) > 0 { + !if fast_subindex = 0 { + hddencbuf = hdddirbuf ;writes come from cache + } else { ;fast_subindex = 1 + !if hdddirbuf < reloc { + hddencbuf = hdddirbuf - $200 + } else { ;hdddirbuf + hddencbuf = hdddirbuf + $200 + !if (hddencbuf + $200) > $c000 { + !if hddencbuf < $d000 { + !set hddencbuf = reloc - $200 + } ;hddencbuf + } ;hddencbuf + } ;hdddirbuf + } ;fast_subindex + } ;aligned_read = 0 or rwts_mode = 1 !if allow_trees = 1 { - !if aligned_read = 0 { - hddtreebuf = hddencbuf + $200 - !if hddtreebuf >= reloc { - !if hddencbuf < hddcodeend { - !set hddtreebuf = hddencbuf - $200 + !if fast_trees = 1 { + !if ((aligned_read xor 1) + rwts_mode) > 0 { + !if hddencbuf < reloc { + hddtreebuf = hddencbuf - $200 + } else { ;hddencbuf + hddtreebuf = hddencbuf + $200 !if (hddtreebuf + $200) > $c000 { !if hddtreebuf < $d000 { !set hddtreebuf = reloc - $200 - } - } - } - } - } else { ;aligned_read = 1 - hddtreebuf = hdddirbuf + $200 - !if (hddtreebuf + $200) > $c000 { - !if hddtreebuf < $d000 { - !set hddtreebuf = reloc - $200 - } - } - } ;aligned_read + } ;hddtreebuf + } ;hddtreebuf + } ;hddencbuf + } else { ;aligned_read = 1 + !if hdddirbuf < reloc { + hddtreebuf = hdddirbuf - $200 + } else { ;hdddirbuf + hddtreebuf = hdddirbuf + $200 + !if (hddtreebuf + $200) > $c000 { + !if hddtreebuf < $d000 { + !set hddtreebuf = reloc - $200 + } ;hddtreebuf + } ;hddtreebuf + } ;hdddirbuf + } ;aligned_read + } else { ;fast_trees = 0 + hddtreebuf = hdddirbuf + } ;fast_trees } ;allow_trees } ;load_high } else { ;reloc > $c000 @@ -3068,11 +3551,15 @@ hdddataend hddencbuf = hdddirbuf - $200 } ;aligned_read !if allow_trees = 1 { - !if aligned_read = 0 { - hddtreebuf = hddencbuf - $200 - } else { ;aligned_read = 1 - hddtreebuf = hdddirbuf - $200 - } ;aligned_read + !if fast_trees = 1 { + !if ((aligned_read xor 1) + enable_write) > 0 { + hddtreebuf = hddencbuf - $200 + } else { ;aligned_read = 1 and enable_write = 0 + hddtreebuf = hdddirbuf - $200 + } ;aligned_read = 0 or enable_write = 1 + } else { ;fast_trees = 0 + hddtreebuf = hdddirbuf + } ;fast_trees } ;allow_trees } else { ;load_high = 0 !pseudopc ((hdddataend + $ff) & -256) { @@ -3082,11 +3569,15 @@ hdddataend hddencbuf = hdddirbuf - $200 } ;aligned_read !if allow_trees = 1 { - !if aligned_read = 0 { - hddtreebuf = hddencbuf + $200 - } else { ;aligned_read = 1 - hddtreebuf = hdddirbuf + $200 - } ;aligned_read + !if fast_trees = 1 { + !if ((aligned_read xor 1) + enable_write) > 0 { + hddtreebuf = hddencbuf + $200 + } else { ;aligned_read = 1 and enable_write = 0 + hddtreebuf = hdddirbuf + $200 + } ;aligned_read = 0 or enable_write = 1 + } else { ;fast_trees = 0 + hddtreebuf = hdddirbuf + } ;fast_trees } ;allow_trees } ;load_high } ;reloc @@ -3096,15 +3587,15 @@ hdddataend !warn "hdd data: ", hddcodeend, "-", hdddataend - 1 } !warn "hdd dirbuf: ", hdddirbuf, "-", hdddirbuf + $1ff - !if aligned_read = 0 { + !if ((aligned_read xor 1) + rwts_mode) > 0 { !warn "hdd encbuf: ", hddencbuf, "-", hddencbuf + $1ff - } ;aligned_read - !if (allow_trees + fast_trees) > 1 { + } ;aligned_read = 0 or rwts_mode = 1 + !if allow_trees = 1 { !warn "hdd treebuf: ", hddtreebuf, "-", hddtreebuf + $1ff - } ;allow_trees and fast_trees + } ;allow_trees !warn "hdd driver start: ", unrelochdd - init !if (one_page + enable_floppy) = 0 { - !if ((hddcodeend - hddopendir) < $100) { + !if ((hddcodeend - reloc) < $100) { !warn "one_page can be enabled, code is small enough" } ;hddcodeend } ;not one_page and not enable_floppy