started unification of floppy and ramdisk code
This commit is contained in:
1 parent
3a05ee4807
commit
2acf32fb68
10 files changed
+7
-1
No files matched your search
@@ -0,0 +1,13 @@
|
||||
|
||||
;
|
||||
; Close currently opened file
|
||||
;
|
||||
|
||||
|
||||
unit_fd_cmd_CLOSE:
|
||||
|
||||
; XXX provide implementation
|
||||
|
||||
jsr lowlevel_fdc_motor_off ; disable drive motor XXX only do this if no channel is opened
|
||||
|
||||
jmp dos_EXIT_SEC
|
||||
@@ -0,0 +1,75 @@
|
||||
|
||||
;
|
||||
; Open file for reading
|
||||
;
|
||||
|
||||
; XXX add support for both floppies
|
||||
|
||||
|
||||
unit_fd_cmd_OPEN:
|
||||
|
||||
lda #$01 ; mode: receive command or file name
|
||||
sta F0_MODE
|
||||
|
||||
jmp dos_EXIT_CLC
|
||||
|
||||
unit_fd_cmd_OPEN_EOI:
|
||||
|
||||
; XXX this dispatcher is temporary
|
||||
|
||||
; Erase filter pattern XXX this should be moved to common part
|
||||
|
||||
ldy #$0F
|
||||
lda #$A0
|
||||
@lp1:
|
||||
sta PAR_FPATTERN, y
|
||||
dey
|
||||
bpl @lp1
|
||||
|
||||
; XXX add support for second floppy
|
||||
|
||||
lda F0_CMDFN_BUF
|
||||
cmp #'$'
|
||||
beq unit_fd_cmd_OPEN_dir
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
unit_fd_cmd_OPEN_file:
|
||||
|
||||
; Copy the filter from command XXX this should be moved to common part and deduplicated with directory opening
|
||||
|
||||
ldy #$00
|
||||
@lp1:
|
||||
lda F0_CMDFN_BUF, y
|
||||
cmp #$A0
|
||||
beq @lp1_end
|
||||
sta PAR_FPATTERN, y
|
||||
iny
|
||||
cpy #$10
|
||||
bne @lp1
|
||||
|
||||
@lp1_end:
|
||||
|
||||
jmp fs_cbm_read_file_open
|
||||
|
||||
|
||||
unit_fd_cmd_OPEN_dir:
|
||||
|
||||
lda #$02 ; mode: read directory
|
||||
sta F0_MODE
|
||||
|
||||
; Copy the filter from command XXX this should be moved to common part and deduplicated with file opening
|
||||
|
||||
ldy #$00
|
||||
@lp1:
|
||||
lda F0_CMDFN_BUF+1, y
|
||||
cmp #$A0
|
||||
beq @lp1_end
|
||||
sta PAR_FPATTERN, y
|
||||
iny
|
||||
cpy #$10
|
||||
bne @lp1
|
||||
|
||||
@lp1_end:
|
||||
|
||||
jmp fs_cbm_read_dir_open
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
;
|
||||
; Read more data into the buffer
|
||||
;
|
||||
|
||||
|
||||
unit_f0_cmd_READ:
|
||||
|
||||
; XXX provide implementation
|
||||
|
||||
unit_f1_cmd_READ:
|
||||
|
||||
; XXX provide implementation
|
||||
|
||||
unit_fd_cmd_READ:
|
||||
|
||||
lda F0_MODE
|
||||
cmp #$03
|
||||
+beq fs_cbm_nextfileblock
|
||||
|
||||
lda F0_DIR_PHASE
|
||||
cmp #$01
|
||||
+beq fs_cbm_read_dir
|
||||
cmp #$02
|
||||
+beq fs_cbm_read_dir_blocksfree
|
||||
|
||||
sec ; mark EOI
|
||||
rts
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
;
|
||||
; Initializes DOS part of floppy controller
|
||||
;
|
||||
|
||||
|
||||
unit_fd_init:
|
||||
|
||||
; Copy status string
|
||||
|
||||
ldx #$00
|
||||
|
||||
stx F0_STATUS_IDX
|
||||
stx F0_CMDFN_IDX
|
||||
stx F0_MODE
|
||||
stx F0_ACPTR_LEN+0
|
||||
stx F0_ACPTR_LEN+1
|
||||
stx F0_ACPTR_PTR+0
|
||||
stx F0_ACPTR_PTR+1
|
||||
|
||||
stx F1_STATUS_IDX
|
||||
stx F1_CMDFN_IDX
|
||||
stx F1_MODE
|
||||
stx F1_ACPTR_LEN+0
|
||||
stx F1_ACPTR_LEN+1
|
||||
stx F1_ACPTR_PTR+0
|
||||
stx F1_ACPTR_PTR+1
|
||||
|
||||
dex
|
||||
@1:
|
||||
inx
|
||||
lda dos_sts_init_floppy,x
|
||||
sta F0_STATUS_BUF,x
|
||||
sta F1_STATUS_BUF,x
|
||||
bne @1
|
||||
|
||||
; Initialize the controller
|
||||
|
||||
lda #$80 ; default track stepping rate
|
||||
sta FDC_STEP
|
||||
lda #$FF
|
||||
sta FDC_CLOCK
|
||||
|
||||
; End of initialization
|
||||
|
||||
rts
|
||||
@@ -0,0 +1,134 @@
|
||||
|
||||
;
|
||||
; Initializes DOS part of RAM disk
|
||||
;
|
||||
|
||||
|
||||
unit_rd_init:
|
||||
|
||||
|
||||
; Copy status string
|
||||
|
||||
ldx #$00
|
||||
stx RD_STATUS_IDX
|
||||
stx RD_CMDFN_IDX
|
||||
stx RD_MODE
|
||||
stx RD_ACPTR_LEN+0
|
||||
stx RD_ACPTR_LEN+1
|
||||
stx RD_ACPTR_PTR+0
|
||||
stx RD_ACPTR_PTR+1
|
||||
dex
|
||||
@1:
|
||||
inx
|
||||
lda dos_sts_init_ramdisk,x
|
||||
sta RD_STATUS_BUF,x
|
||||
bne @1
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
unit_rd_init_test_ram: ; non-destructive ATTIC/CELLAR RAM test
|
||||
|
||||
; Preserve temporary address area on stack
|
||||
|
||||
ldx #$03
|
||||
@2:
|
||||
lda PNTR, x
|
||||
pha
|
||||
dex
|
||||
bpl @2
|
||||
|
||||
stx RD_MSG ; $FF - mark no message to be displayed
|
||||
|
||||
; For the start, mark extended RAM as not present
|
||||
|
||||
stx RD_STARTSEG ; by default $FF, to mark no RAM disk
|
||||
inx
|
||||
stx RD_VALIDIMG ; mark no valid image loaded
|
||||
stx RAM_ATTIC ; set ATTIC/CELLAR RAM as not present
|
||||
stx RAM_CELLAR
|
||||
|
||||
; Prepare address - CELLAR RAM, $0880:$0000
|
||||
|
||||
stx PNTR+0
|
||||
stx PNTR+1
|
||||
lda #$80
|
||||
sta PNTR+2
|
||||
lda #$08
|
||||
sta PNTR+3
|
||||
|
||||
ldz #$00
|
||||
|
||||
; Test for CELLAR RAM
|
||||
|
||||
jsr @perform_ram_test
|
||||
bne @done_cellar
|
||||
dec RAM_ATTIC ; test passed
|
||||
lda #$08
|
||||
sta RD_STARTSEG ; RAM DISK start segment - CELLAR RAM
|
||||
|
||||
@done_cellar:
|
||||
|
||||
; Prepare address - ATTIC RAM, $0800:$0000
|
||||
|
||||
lda #$00
|
||||
sta PNTR+2
|
||||
|
||||
; Test for ATTIC RAM
|
||||
|
||||
jsr @perform_ram_test
|
||||
bne @done_attic
|
||||
dec RAM_CELLAR ; test passed
|
||||
lda #$00
|
||||
sta RD_STARTSEG ; RAM DISK start segment - ATTIC RAM
|
||||
|
||||
@done_attic:
|
||||
|
||||
; Restore temporary address area content
|
||||
|
||||
ldx #$00
|
||||
@3:
|
||||
pla
|
||||
sta PNTR, x
|
||||
inx
|
||||
cpx #$04
|
||||
bne @3
|
||||
|
||||
; Clear RAM disk device number if no Hyper RAM available
|
||||
|
||||
jsr util_check_rd_ram
|
||||
|
||||
; End of initialization
|
||||
|
||||
rts
|
||||
|
||||
@perform_ram_test:
|
||||
|
||||
; Try to change one byte in extended RAM
|
||||
|
||||
lda [PNTR], z
|
||||
tax
|
||||
eor #$FF
|
||||
sta [PNTR], z
|
||||
|
||||
; Make sure the cache does not contain the value any more
|
||||
|
||||
tay
|
||||
dez
|
||||
lda [PNTR], z
|
||||
inz
|
||||
tya
|
||||
|
||||
; Check if byte still contains the new value
|
||||
|
||||
cmp [PNTR], z
|
||||
php
|
||||
|
||||
; Restore byte content
|
||||
|
||||
txa
|
||||
sta [PNTR], z
|
||||
|
||||
; Return test result
|
||||
|
||||
plp
|
||||
rts
|
||||
@@ -0,0 +1,212 @@
|
||||
|
||||
;
|
||||
; Preload RAM disk image from SD card
|
||||
;
|
||||
|
||||
|
||||
!addr __stoptrack = RD_DIR_PHASE ; helper value for detecting too large image
|
||||
|
||||
|
||||
unit_rd_preload:
|
||||
|
||||
; Check if RAM disk is enabled (should be disabled if no Hyper RAM is present)
|
||||
|
||||
lda UNIT_RAMDISK
|
||||
+beq unit_rd_preload_err_common_noclose
|
||||
|
||||
; Select SD card buffer
|
||||
|
||||
lda #$80
|
||||
tsb SD_BUFCTL
|
||||
|
||||
; Set file name
|
||||
|
||||
jsr util_shadow
|
||||
ldx #$FF
|
||||
@lp1:
|
||||
inx
|
||||
lda ramdisk_filename, x
|
||||
sta MEM_BUF, x
|
||||
bne @lp1
|
||||
|
||||
ldy #>MEM_BUF
|
||||
ldx #<MEM_BUF
|
||||
jsr util_htrap_dos_setname
|
||||
jsr util_shadow_restore
|
||||
|
||||
+bcc @error_not_found ; branch if error
|
||||
|
||||
; Try to find the file
|
||||
|
||||
jsr util_htrap_dos_findfile
|
||||
+bcc @error_not_found ; branch if file not found
|
||||
|
||||
; Calculate maximum amount of tracks possible to load
|
||||
|
||||
; XXX clean this up, for the loop counter it should be enough to use DMAJOB_DST_ADDR
|
||||
|
||||
lda #$FF
|
||||
sta RD_MAXTRACK ; maximum track number of loaded image, for now set $FF
|
||||
sta __stoptrack
|
||||
|
||||
lda RAM_ATTIC
|
||||
beq @added_attic
|
||||
jsr unit_rd_preload_addram
|
||||
|
||||
@added_attic:
|
||||
|
||||
lda RAM_CELLAR
|
||||
beq @added_cellar
|
||||
jsr unit_rd_preload_addram
|
||||
|
||||
@added_cellar:
|
||||
|
||||
; Load the image
|
||||
|
||||
lda #$08 ; set the ram disk start address
|
||||
sta DMAJOB_DST_MB
|
||||
lda #$00
|
||||
sta DMAJOB_DST_ADDR+0
|
||||
sta DMAJOB_DST_ADDR+1
|
||||
lda RD_STARTSEG
|
||||
sta DMAJOB_DST_ADDR+2
|
||||
|
||||
jsr util_htrap_dos_openfile
|
||||
sta SD_DESC ; XXX consider using separate variable
|
||||
|
||||
lda #$FF
|
||||
sta RD_MAXTRACK
|
||||
|
||||
bra @load_track_check_done
|
||||
|
||||
@load_track:
|
||||
|
||||
lda RD_MAXTRACK
|
||||
cmp __stoptrack
|
||||
beq @load_image_mem_full
|
||||
inc DMAJOB_DST_ADDR+2
|
||||
|
||||
@load_track_check_done:
|
||||
|
||||
inc RD_MAXTRACK
|
||||
ldx #$00 ; counter of 512-byte blocks to load
|
||||
|
||||
@load_track_loop:
|
||||
|
||||
phx
|
||||
|
||||
; Read 512 bytes
|
||||
|
||||
jsr util_htrap_dos_readfile
|
||||
|
||||
cpx #$00
|
||||
bne @error_wrong_size_plx ; file size not multiplicity of 64K
|
||||
|
||||
cpy #$00
|
||||
beq @load_image_end
|
||||
|
||||
cpy #$02
|
||||
bne @error_wrong_size_plx ; file size not multiplicity of 64K
|
||||
|
||||
jsr util_dma_launch_from_hwbuf ; copy data to Hyper RAM
|
||||
|
||||
inc DMAJOB_DST_ADDR+1 ; advance pointer to the next block
|
||||
inc DMAJOB_DST_ADDR+1
|
||||
|
||||
; Next 512-byte block or next track
|
||||
|
||||
plx
|
||||
inx
|
||||
inx
|
||||
bne @load_track_loop ; next 512-byte block of the same track
|
||||
|
||||
bra @load_track ; next track
|
||||
|
||||
@load_image_mem_full:
|
||||
|
||||
; Make sure this is the end of the file
|
||||
|
||||
jsr util_htrap_dos_readfile
|
||||
|
||||
cpx #$00
|
||||
bne @error_too_large
|
||||
cpy #$00
|
||||
bne @error_too_large
|
||||
|
||||
@load_image_end:
|
||||
|
||||
plx
|
||||
cpx #$00
|
||||
bne @error_wrong_size ; file empty or file size not multiplicity of 64K
|
||||
|
||||
lda RD_MAXTRACK
|
||||
cmp #$02
|
||||
bcc @error_wrong_size ; file too small, at least 128K required
|
||||
|
||||
ldx SD_DESC
|
||||
jsr util_htrap_dos_closefile
|
||||
|
||||
; End of initialization
|
||||
|
||||
lda #$FF
|
||||
sta RD_VALIDIMG ; mark image as valid
|
||||
|
||||
lda #$00 ; temporary storage needs to be restored to 0
|
||||
sta __stoptrack
|
||||
|
||||
lda #$00 ; set message to OK
|
||||
sta RD_MSG
|
||||
|
||||
rts
|
||||
|
||||
|
||||
|
||||
@error_wrong_size_plx:
|
||||
|
||||
plx
|
||||
|
||||
@error_wrong_size:
|
||||
|
||||
lda #$01
|
||||
jmp unit_rd_preload_err_common
|
||||
|
||||
@error_too_large:
|
||||
|
||||
lda #$02
|
||||
jmp unit_rd_preload_err_common
|
||||
|
||||
@error_not_found:
|
||||
|
||||
lda #$03
|
||||
sta RD_MSG
|
||||
|
||||
jmp unit_rd_preload_err_common_noclose
|
||||
|
||||
|
||||
unit_rd_preload_err_common:
|
||||
|
||||
sta RD_MSG ; set code for startup screen
|
||||
|
||||
jsr util_htrap_dos_closefile ; XXX set descriptor
|
||||
|
||||
; FALLTROUGH
|
||||
|
||||
unit_rd_preload_err_common_noclose:
|
||||
|
||||
lda #$00 ; temporary storage needs to be restored to 0
|
||||
sta __stoptrack
|
||||
sta RD_VALIDIMG ; mark image as invalid
|
||||
|
||||
rts
|
||||
|
||||
|
||||
|
||||
unit_rd_preload_addram:
|
||||
|
||||
; Add allowed number of tracks due to attic/cellar block presence
|
||||
|
||||
clc
|
||||
lda #$80
|
||||
adc __stoptrack
|
||||
sta __stoptrack
|
||||
rts
|
||||
Reference in new issue
Block a user