Author Topic: USIfAC II:Convert a PC or USB stick to Amstrad HDD,access dsk's,and many more!  (Read 43246 times)

0 Members and 4 Guests are viewing this topic.

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
I want copy the disk image to file, then I read a track and then write to usb (each track is a file and later I join them on PC). I use a 2-second delay between rsx commands.  You have to do something similar for |2PC command.
Perhaps you mean you write a dsk image to a floppy disk (with |DSK)  and then read a track from disk and save it to a usb file?
Anyway, you don't have to use |USB for enabling/disabling the disk drive,this command is intended to be used ONLY once, after initial powering of amstrad!
In order to read/write from floppy disk drive, you just give |DIS (or an out &fbd1,4 which is essentially the same thing, you can see that in the first lines, if you get a list of the BASIC listing of the |2PC) , this will direct all amsdos routines (like CAS IN OPEN, CAS OUT OPEN, BIOS READ SECTOR, BIOS WRITE SECTOR, BIOS FORMAT TRACK etc) to the disk drive!
At the same time, access to a usb file can be made without problem, as this is done using the I/O serial port of USIfAC II  (&FBD0) that comunicates directly with USB host module!  ;)
So in 2 words if you want to read from disk drive and write to a usb file at the same time, the only thing you need to do is to give |DIS or OUT &FBD1,4 . And ofcourse you can always use |EN -or out &fbd1,5- to re-enable redirection of all Amsdos routines back to usb!  ;)
« Last Edit: 09:56, 16 June 21 by ikonsgr »
like
0
No reactions

Offline Fran123

  • CPC664
  • ***
  • Posts: 60
  • Country: es
    • Awards
I want to create DSK files of my old disks.
I will follow your advices this afternoon
Thank you!
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
My pleasure  :)
 And if you need anything else feel free to ask!  ;)
like
0
No reactions

Offline ajcasado

  • Supporter
  • CPC664
  • *
  • Posts: 70
  • Country: es
    • Awards
So  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.
like
0
No reactions
CPC 664

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

Offline Fran123

  • CPC664
  • ***
  • Posts: 60
  • Country: es
    • Awards
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.
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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....
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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  :)
like
0
No reactions

Offline Mark_wllms

  • CPC464
  • **
  • Posts: 17
  • Country: gb
  • CPC6128 and USIFAC II owner.
    • Awards
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.
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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  ;)
like
0
No reactions

Offline Fran123

  • CPC664
  • ***
  • Posts: 60
  • Country: es
    • Awards

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
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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!  ;)
« Last Edit: 13:59, 18 June 21 by ikonsgr »
like
0
No reactions

Offline Mark_wllms

  • CPC464
  • **
  • Posts: 17
  • Country: gb
  • CPC6128 and USIFAC II owner.
    • Awards
Finally, 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.
like
0
No reactions

Offline Fran123

  • CPC664
  • ***
  • Posts: 60
  • Country: es
    • Awards
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.
like
0
No reactions

Offline Fran123

  • CPC664
  • ***
  • Posts: 60
  • Country: es
    • Awards
I have tested some DSK of CPM and none of them works with |CPM  :(
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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.
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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.
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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...  ::)
« Last Edit: 20:10, 18 June 21 by ikonsgr »
like
0
No reactions

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 4.022
  • Country: fr
    • ?area=showdonations;u=4
    • Awards
May be adding a "write track" feature can be a work around? (don't exist on the UPD765, but on other FDC like WD)
like
0
No reactions
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline Fran123

  • CPC664
  • ***
  • Posts: 60
  • Country: es
    • Awards
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  :(
« Last Edit: 21:30, 18 June 21 by Fran123 »
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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:
Code: [Select]
;; 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.
« Last Edit: 23:29, 19 June 21 by ikonsgr »
like
0
No reactions

Offline Fran123

  • CPC664
  • ***
  • Posts: 60
  • Country: es
    • Awards
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.
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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):

Code: [Select]
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)
« Last Edit: 00:08, 20 June 21 by ikonsgr »
like
0
No reactions

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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.  ;)
« Last Edit: 13:30, 20 June 21 by ikonsgr »
like
0
No reactions

Offline Devlin

  • CPC664
  • ***
  • Posts: 149
  • Country: gb
    • Magicbane
    • Awards
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.  ;)



i needs it :3
like
0
No reactions
Amstrad fan! | CPC464 + USIfAC II | Administrator of Amstrad Discord : https://discord.gg/ksWvApv

Offline ikonsgr

  • 6128 Plus
  • ******
  • Posts: 565
  • Country: gr
    • ikonsgr 80's Home Micros WorkBench
    • Awards
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!  ;)
like
0
No reactions