USIfAC II:Convert a PC or USB stick to Amstrad HDD,access dsk's,and many more!

Started by ikonsgr, 08:17, 01 December 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Fran123

I want to create DSK files of my old disks.
I will follow your advices this afternoon
Thank you!

ikonsgr

My pleasure  :)
And if you need anything else feel free to ask!  ;)

ajcasado

Quote from: ikonsgr on 18:02, 15 June 21So  if we want to support large directories with many filenames (up to ~1000) we will need plenty of room in ram

You could use a temporary file in the USB drive instead of RAM.
CPC 664

Empiezas a envejecer cuando dejas de aprender.
You start to get old when you stop learning.

Fran123

I only removed |USB from my code and it works now!
In the PC, I remove the 128-byte header of each file, join them and get the raw disk image.
For getting the dsk file I have my own program.

ikonsgr

Quote from: ajcasado on 09:49, 16 June 21
You could use a temporary file in the USB drive instead of RAM.
I'm afraid using a usb file will still need a buffer to store all names in ram first. You see, usb host module is not multitasking, meaning that, when you ask to get the name list of a directory, you CAN'T have a file opened and write it at the same time! The only way to do it, is to store all names in a buffer, and then write them to a usb file.
One other alternative would be to use the RAM of the PIC Microcontroller (usb host module uses only 128bytes for buffering, so we would have ~3,5KB of ram ), but this could store ~250 names....

ikonsgr

Quote from: Fran123 on 19:57, 16 June 21
I only removed |USB from my code and it works now!
In the PC, I remove the 128-byte header of each file, join them and get the raw disk image.
For getting the dsk file I have my own program.
Great! Perhaps you could write a small guide for anyone want to get a dsk image from floppy disks too  :)

Mark_wllms

I wonder if there is any way to get CP/M Plus discs to boot? I was trying to run some Infocom games, which I think would work better under CP/M plus. I considered running a snapshot, but I can't think how to load a disk image and a snapshot at the same time.

ikonsgr

Quote from: Mark_wllms on 15:23, 17 June 21
I wonder if there is any way to get CP/M Plus discs to boot? I was trying to run some Infocom games, which I think would work better under CP/M plus. I considered running a snapshot, but I can't think how to load a disk image and a snapshot at the same time.
Well, you can always use |DSK to copy image to a real disk and boot from the disk  ;)

Fran123

Quote from: ikonsgr on 22:35, 16 June 21
Great! Perhaps you could write a small guide for anyone want to get a dsk image from floppy disks too  :)



It's easy.


Steps:


From CPC: Copy each track of disk to file in USB, 40 tracks -> 40 files
Each track has 9 sectors of 512 bytes, then the track file size is 128+512*9


From PC: Remove the AMSDOS header of each file (the first 128 bytes) and join them. You have your disk on RAW format.




How to read a sector:


You have to store these bytes in #a000. It's a function coded in asm.
DATA

&21,&1c,&a0,&cd,&d4,&bc,&22,&1d, &a0,&79,&32,&1f,&a0,&21,&20,&a0
&5e,&23,&56,&23,&4e,&21,&30,&a0, &df,&1d,&a0,&c0,&84 

setting parameters:

POKE &A017, addrh : POKE &A016, 0
'address where sector bytes will be stored = addrh*256
POKE &A020, drive : POKE &A021, track : POKE &A022, sector

Invoquing the function
CALL &A000

Now sector bytes are in (addrh*256)


Creating DSK file
The truth is out there:
https://www.cpcwiki.eu/index.php/Format:DSK_disk_image_file_format

ikonsgr

The "approach" you used of getting the raw sector data and then create the dsk image, gave me an idea:
Since creation of a dsk image "from the scratch" would need a lot of code (and effort), why don't we use a ready made dsk image and then just place sector data into it, something much easier and simpler thing to do!  ;)
And since 99% of old disks we had back in the 80's was standard "Data format" disks, we can use a standard 40tracks/ 9sectors/track disk image!
The whole procedure would look like this:
- First, select the pre-made (i use CPCDISKXP to make such an empty image in 2 seconds :-) ), using the currently existed RSX command: |MG.
- Run a loop for tracks 0 to 39
- Run  a nested loop for sectors C1 to C9 with the simple code:
            - Disable fdc emulation and call READ SECTOR routine for reading Disk drive (with the appropriate Drive,Track,sector numbers)
            - Enable fdc emulation and call WRITE SECTOR routine (this will redirect amsdos calls to usb host module and the selected DSK image)

The code for the above procedure would be a rather easy thing to, and you will get an image from a floppy disk in a single step! I'll see if i can make it in the weekend!  ;)

Mark_wllms

Quote from: eto on 18:32, 13 June 21Finally, the most wanted (by some....  ) FILEMANAGER is READY! You can download it from here
This is very helpful. I have used it like this:
I have got rid of CPCLoader Basic shortcuts and put the file manager into the root of the USB. Then I made folders for #,A..Z and put all my direct load folders, snapshots and disk files into the appropriate folder.
Now I ¦USB: RUN"FM and then just select a folder, select a snapshot / disk image / folder and then run the game. It's very easy, and straight forward to maintain. None of my folders runs more than 2 pages at the moment.

Fran123

Quote from: ikonsgr on 11:56, 18 June 21
The "approach" you used of getting the raw sector data and then create the dsk image, gave me an idea:
Since creation of a dsk image "from the scratch" would need a lot of code (and effort), why don't we use a ready made dsk image and then just place sector data into it, something much easier and simpler thing to do!  ;)
And since 99% of old disks we had back in the 80's was standard "Data format" disks, we can use a standard 40tracks/ 9sectors/track disk image!
The whole procedure would look like this:
- First, select the pre-made (i use CPCDISKXP to make such an empty image in 2 seconds :-) ), using the currently existed RSX command: |MG.
- Run a loop for tracks 0 to 39
- Run  a nested loop for sectors C1 to C9 with the simple code:
            - Disable fdc emulation and call READ SECTOR routine for reading Disk drive (with the appropriate Drive,Track,sector numbers)
            - Enable fdc emulation and call WRITE SECTOR routine (this will redirect amsdos calls to usb host module and the selected DSK image)

The code for the above procedure would be a rather easy thing to, and you will get an image from a floppy disk in a single step! I'll see if i can make it in the weekend!  ;)
I did a java program to generate the dsk file, it's very simple, I'll try to post this evening.
Anyway I like your idea and I'll try do it as you say.Other question, is it possible to create an empty disk (as dsk file) from basic?  Is there any command?   If I want to pass X disks, I have to have X dsk files previously.

Fran123

I have tested some DSK of CPM and none of them works with |CPM  :(

ikonsgr

Quote from: Fran123 on 13:03, 18 June 21
Other question, is it possible to create an empty disk (as dsk file) from basic?  Is there any command?   If I want to pass X disks, I have to have X dsk files previously.
I'm afraid it's not possible. But it might help to use the multiple dsk image function, where you can load up to 4 empty dsk images and select them using the dsk_swap button.

ikonsgr

Quote from: Fran123 on 16:56, 18 June 21
I have tested some DSK of CPM and none of them works with |CPM  :(
Did you try to copy them to disks (using |DSK) and see if they work?
I think that this problem with cpm plus images, has to do, not so with the FDC emulation itslef, but rather with amsdos calls when fdc emulation is enabled.

ikonsgr

I have tried the above method i described, i manage to copy a floppy disk to a dsk image successfully, but the "Side effect" is that WRITE SECTOR routine somehow destroys the disk!
I suspect that although fdc emulation takes control of the communication with asmtrad, because disk drive is also attached ,it receives the commands and somehow this, results in detroying disk sectors! I've tried to write protect disk, but unfortunately this didn't help either (i got an error message or if i disable error messages amstrad crashes)
One solution might be to write the readed sector in both usb file and disk drive , or we throw away write sector routine and use cutom routines that write data to usb file directly...  ::)

TotO

May be adding a "write track" feature can be a work around? (don't exist on the UPD765, but on other FDC like WD)
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Fran123

Quote from: ikonsgr on 18:08, 18 June 21
I have tried the above method i described, i manage to copy a floppy disk to a dsk image successfully, but the "Side effect" is that WRITE SECTOR routine somehow destroys the disk!
I suspect that although fdc emulation takes control of the communication with asmtrad, because disk drive is also attached ,it receives the commands and somehow this, results in detroying disk sectors! I've tried to write protect disk, but unfortunately this didn't help either (i got an error message or if i disable error messages amstrad crashes)
One solution might be to write the readed sector in both usb file and disk drive , or we throw away write sector routine and use cutom routines that write data to usb file directly...  ::)
In that case, we have to remove the amsdos header in a pc

I'm trying copy a disk in winape firstly, but my write sector function crashes the emulator  :(

ikonsgr

Finally, i finished it!
So, another new utility, for creating disk images from old floppy disks in just 40 seconds!
You can use it with older and newer boards, just extract the zip file to usb stick and run "disk2img.bas".

You will be asked to give a disk image name (you can use the included TEMP.DSK or any other standard DATA format dsk image).
For root directory you should also add a  '/' in front of name, e.g.: '/TEMP.DSK', but if you use a folder, you don't need to add '/'.
Utility can transfer only standard "data format" floppy disks (40 tracks with 9sectors/track, 512 byte/sector), which i believe was, the vast majority of disks used back in the '80s. 
And here is the code:
;; firmware function to find a RSX
.kl_find_command equ &bcd4

write"get.BIN" 
name_adr equ &9000
org &8000
;nolist

;;------------------------------------------------
;; find BIOS: READ SECTOR command

ld hl,2
ld (position),hl
ld hl,cmd_bios_read_sector
call kl_find_command
ret nc

;; command found
;; store address of command
ld (bios_read_sector),hl
;; store "rom select" of command
ld a,c
ld (bios_read_sector+2),a

ld bc,&fbd1
ld a,4
out (c),a
ld a,7
out (c),a
ld hl,message1
call print_msg

dec bc
ld a,&57
out (c),a
ld a,&ab
out (c),a
ld a,&2f
out (c),a
ld hl,name_adr
name_loop:
ld a,(hl)
or a
jr z,contin
out (c),a
inc hl
jr nz,name_loop
contin:
xor a
out (c),a
call clear_buffer
ld a,&57
out (c),a
ld a,&ab
out (c),a
ld a,&32
out (c),a

call check_responce
ld A,&FB
        in A,(&D0) 
cp &14
jp nz,no_file

call seek
in a,(c)
cp &14
jp nz,no_file
;;------------------------------------------------

;; disable FDC emualation for reading sector data from disk drive


cont1:

;; D = track number
xor a
ld (track),a

;; C = sector id
ld bc,sector_list
ld (current_sector),bc
ld a,(bc)
ld c,a

main_loop:

;; disable FDC emualation for writing sector data to selected image file
;; E = drive number (0 or 1)
ld e,0
ld hl,buffer
ld a,(track)
ld d,a
ld bc,(current_sector)
ld a,(bc)
ld c,a
;; execute command
rst 3
defw bios_read_sector
call write_sector

;; C = sector id
ld bc,(current_sector)
inc bc
ld a,(bc)
or a
jr z,reset_sector
ld (current_sector),bc
ld c,a
jr main_loop

reset_sector:
ld a,"."
call &bb5a
ld bc,sector_list
ld (current_sector),bc
ld a,(sector_list)
ld c,a
;; D = track number
;; (change this value to define the track to write to)
ld a,(track)
inc a
cp 40
jr z,end_routine
ld (track),a
ld hl,(position)
ld bc,&13
add hl,bc
ld (position),hl
call seek
in a,(c)
cp &14
jp nz,no_file
jr main_loop

end_routine:

ld a,&57 ;close file
out (c),a
ld a,&ab
out (c),a
ld a,&36
out (c),a
xor a
out (c),a
ret

write_sector:
ld bc,&fbd0
ld hl,buffer
ld d,4
next_chunk:
ld e,128
call clear_buffer
ld a,&57
out (c),a
ld a,&ab
out (c),a
ld a,&3c
out (c),a

out (c),e
xor a
out (c),a
call check_responce


call clear_buffer
ld a,&57
out (c),a
ld a,&ab
out (c),a
ld a,&2d
out (c),a
call check_responce
ld A,&FB
        in A,(&D0)

loading:
inc b
outi
dec e
jr nz, loading

call clear_buffer
ld a,&57
out (c),a
ld a,&ab
out (c),a
ld a,&3d
out (c),a
call check_responce
dec d
ld a,d
or a
jp nz,next_chunk
ret
;------------------------------------------------------------

check_responce:
        LD A,&FB
        iN A,(&D1) 
        DEC A
        JR Z,check_responce
ret

clear_buffer:
inc bc ;clear buffer
ld a,1
out (c),a
dec bc
ret

seek:
ld hl,(position)
ld d,0
ld e,h
ld h,l
ld l,0
ld bc,&fbd0
call clear_buffer
ld a,&57
out (c),a
ld a,&ab
out (c),a
ld a,&39
out (c),a
out (c),l
out (c),h
out (c),e
out (c),d
call check_responce
ret

print_msg:
ld a,(hl)
or a
ret z
call &bb5a
inc hl
jr print_msg


no_file:
ld hl,no_file_msg
call print_msg
ret

no_file_msg:
defb "Image file not found!",13,10,0

message1:
defb "Copying to dsk image:",13,10,0

;; this is initialised when the "BIOS: READ SECTOR" RSX has been found.
bios_read_sector:
defw 0                    ;; address of function
defb 0                    ;; "rom select" for function

cmd_bios_read_sector:
defb 4+&80 ;; this is the "BIOS: READ SECTOR" RSX

;;------------------------------------------------------------------
sector_list:
defb &c1,&c6,&c2,&c7,&c3,&c8,&c4,&c9,&c5,0
; defb &c1,&c2,&c3,&c4,&c5,&c6,&c7,&c8,&c9,0

current_sector:
defw 0
position:
defw 0
track:
defb 0
buffer:
defs 1


By modifying the bytes under "sector list" tag, it would be easy to modify routine to take backup images of different disks too (like system/cpm disks or with more tracks or sectors/track) but note that you should use the appropriate image file too. Empty Disk images can be easily made using cpcdiskxp utility.

Fran123

Thank you!!


The difference between standard and system disks is the name of sectors (&c1-&c9 and &41-&49). Maybe you can support any kind of parameter.

ikonsgr

Ok, i made a slight mod to the assembly code and the Basic program, and now you can take backup from either DATA or SYSTEM disks!  ;)
Program will also ask to choose for DATA or SYSTEM disk. I've included in the zip file DATA.DSK and CPM.DSK images to use.
The sector list is now accesible from BASIC program (lines 250-260), so it's easier to modify it for any special needs (like a disk with more than 40 tracks and/or more than 9sectors/track):

10 CLS
15 MEMORY &7FFF:LOAD"GETIMG.BIN",&8000
20 INPUT"Dsk image name";A$ 
30 SIZE=LEN(A$)
40 FOR i=1 TO SIZE
50 POKE &8FFF+i,ASC(MID$(a$,i,1)) 
60 NEXT i
70 INPUT"Data(1) or System(2)";a
80 IF a<1 OR a>2 THEN 70
90 IF a=1 THEN GOTO 200 ELSE 210
200 RESTORE 250:GOTO 220
210 RESTORE 260
220 FOR I=0 TO 9
230 READ a:POKE &8500+i,a
240 NEXT i
245 CALL &8000:PRINT:GOTO 20
250 DATA &C1,&C6,&C2,&C7,&C3,&C8,&C4,&C9,&C5,0
260 DATA &41,&46,&42,&47,&43,&48,&44,&49,&45,0


Note also that, if some disks use sequential order of sectors instead of interleaved (&c1,&c2,&c3... instead of the usual &c1,&c6,&c2...), you can easily change the order of sectors too (along with using an appropriate disk image of course)

ikonsgr

I've made some modifications to the File manager too.
I've increased the delay for key press to get more accurate and smooth movement. Also, i move buffer for directory and code higher in ram @&2900 (instead of previous &1800, it can now support less names but still ~1000/directory which i think is more than enough  ::) ), so now you will have ~10k available for any BASIC program that needs to utilize the directory routine.  ;)

Devlin

Quote from: ikonsgr on 11:28, 20 June 21I've made some modifications to the File manager too. I've increased the delay for key press to get more accurate and smooth movement. Also, i move buffer for directory and code higher in ram @&2900 (instead of previous &1800, it can now support less names but still ~1000/directory which i think is more than enough  ::) ), so now you will have ~10k available for any BASIC program that needs to utilize the directory routine.  ;)



i needs it :3
CPC464 & CPC6128 + USIfAC II + Revaldinho 512k(universal cpld ver) - Schneider CRT TV
Administrator of Amstrad Discord : https://discord.gg/ksWvApv

ikonsgr

btw,i've just copy (using |DSK) the cpm/plus disk 1 (that doesn't seem to work using FDC emulation, and the image) to a floppy disk, and now it can loads fine from disk!  ;)

Fran123


Powered by SMFPacks Menu Editor Mod