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


Mark_wllms


ikonsgr

Quote from: Fran123 on 11:06, 13 June 21
I tried to run CPM (disk 1) with |MG and |FDC and it doesn't work  :(
The disk are http://www.cpcwiki.eu/imgs/b/b1/CPC6128_System_Disks_%28SP%29.zip
Have you tried?

CPM 2.2 (disk 3) works fine but it seems that CPM3/plus can't be used from dsk image as it uses a completely different boot method:

https://www.youtube.com/watch?v=PYur2S_pByk
And this somehow causes problems when loading from image. But i suppose you can copy cpm/plus image to a real disk and use it from disk  ;)

ikonsgr

Quote from: TotO on 10:38, 12 June 21
The USIfAC II is a great expansion. May be the FDC emulation can be improved by 3rd party?
FDC emultion is implemented entirely in PIC mcu code using cowbasic. If anyone has experience with cowbasic, he can check the source code inside "inner workings" folder for further details.

ikonsgr

New utility:

Finally, the most wanted (by some....  :D) FILEMANAGER is READY! You can download it from here
Folder contains  small guide (readme.txt) and the source codes (.txt and .asm files) for anyone interested.
I made 2 versions:
One that uses a new RSX command: |MAN (this will be added to a new fw from now on).
and,
One that loads the assmebly routine from a file (can be used with any board),"MANAG.BIN" binary,which is the same RSX routine in file form:
memory &17ff:load"manag.bin",&1800;call &1800

Once executed (either with |MAN or call &1800), it will outputs into RAM ,all the file names inside the current usb directory, starting from address &2000 and in the form of:
1name1name1name1....1name12  ('1' is the separator and '2' points the end of the list)

Using this, it's easy to grab the names and place them inside an array of strings for further proccess.
Now, as i previuolsy noted, i used turbobasic to compile the main Basic program (which contains the navigation and page creation code), in order to achieve fast respond, when you change pages or directories. You can view this code in  MANAGER.TXT Basic file (which is compiled to MANAGER.BIN used). And you can also see a BASIC example of placing names into a string of arrays too.

Finally here is the quick guide:

Copy contents of the folder to usb flash drive root dir,and give to Basic prompt: RUN"FM
Select 'Y'/'y' (Check with |STAT if you board has rev_4d firmware or newer, and then you can also choose "n"/"N")

Use keys:
- Left-Right arrows for changing pages.
- Up/Down arrows for seeking file/dir names into each page.
- <Return> for taking action: If selected name is a directory it will move into it, if it's a "DSK" image it will give you a catalogue of the disk image(CPC6128/664) or it will reset (CPC464) and then  you can access image by giving "CAT".Finally, if it's a file,it will try to execute it. 
- <SPACE> Moves up a directory, if you are inside a sub folder you can also use "." or ".." at the top of first page

notes:

  - by continiously pressing up/down arrows you will get faster movement for quicker seeking,press momentarily for slower "row by row" seeking.
  -.txt and .asm contains the source codes.
  - FM file is a small BASIC program, if you want,you can customize it, to remove the initial question,changing colors of letters/background etc.

eto


Devlin

Thanks for the gentle prod! this will be extremely useful :)


However, I already broke it :( . It tries to run folders as programs if it doesn't have the <DIR> marker at the end of it
CPC464 & CPC6128 + USIfAC II + Revaldinho 512k(universal cpld ver) - Schneider CRT TV
Administrator of Amstrad Discord : https://discord.gg/ksWvApv

ikonsgr

Quote from: Devlin on 19:27, 13 June 21
Thanks for the gentle prod! this will be extremely useful :)
However, I already broke it :( . It tries to run folders as programs if it doesn't have the <DIR> marker at the end of it

If you have a lot of such "un marked" folders, then maybe we can change a bit the code of the BASIC program in order to change the behavior:
10 MODE 2:posi=1:total=0:endline=0:page=1:delay=1000:keypress=0
16 CALL &1800
20 DIM name$(25),startmem(100)
25 FOR i=1 TO 100:startmem(i)=0:NEXT i               
40 page=1:i=0:mem=&2000:GOSUB 2000     
100 CLS:posi=1:total=i:i=1:IF total<25 THEN endline=total-1 ELSE endline=25   
105 PAPER 0:PEN 1
110 WHILE (i<=endline)         
120 PRINT name$(i):i=i+1
130 WEND
140 GOSUB 3005
145 FOR l=1 TO delay:NEXT l     
150 IF INKEY(0)=0 AND posi>1 THEN GOSUB 3000:posi=posi-1:GOSUB 3005:IF (keypress=1) THEN delay=1:GOTO 145 ELSE delay=1000:keypress=1:GOTO 145   
160 IF INKEY(2)=0 AND posi<endline THEN GOSUB 3000:posi=posi+1:GOSUB 3005:IF (keypress=2) THEN delay=1:GOTO 145 ELSE delay=1000:keypress=2:GOTO 145         
170 IF INKEY(8)=0 AND page>1 THEN page=page-1:posi=1:mem=startmem(page):GOTO 2000
180 IF INKEY(1)=0 AND b<>2 THEN page=page+1:posi=1:GOTO 2000
190 IF INKEY(18)=0 THEN GOSUB 1000
195 IF INKEY(47)=0 THEN |CD:CALL &1800:GOTO 40       
196 keypress=0   
200 GOTO 145
500 WHILE LEN(name$(i))>0:PRINT name$(i):i=i+1:WEND
510 END
1000 A$=RIGHT$(NAME$(POSI),3):IF A$="IR>" THEN 1050   
1010 POKE &17F0,LEN(name$(posi))
1015 FOR i=0 TO LEN(name$(posi))-1     
1020 POKE &17F1+i,ASC(MID$(name$(posi),i+1,1))
1030 NEXT i:END           
1050 IF LEFT$(name$(posi),1)="." THEN |CD ELSE A$=LEFT$(NAME$(POSI),(LEN(NAME$(POSI))-6)):|CD,@A$     
1060 CALL &1800:GOTO 40     
2000 i=0
2005 IF startmem(page)=0 THEN startmem(page)=mem       
2010 b=PEEK(mem)
2020 IF (b=1) AND (i<25) THEN i=i+1:mem=mem+1:name$(i)="":GOTO 2010
2030 IF (b=1) AND (i=25) THEN 100
2040 IF b=2 THEN 100
2050 name$(i)=name$(i)+CHR$(b):mem=mem+1:GOTO 2010       
3000 PAPER 0:PEN 1:GOTO 3010
3005 PAPER 1:PEN 0
3010 LOCATE 1,posi:PRINT name$(posi):PAPER 0:PEN 1:RETURN


Perhaps if i assign one more key where when you press it, it will ommit the checking if string name ending in <DIR> and treat name as DIRECTORY will solve the problem.
And you could be informed by a small message on the right corner of screen if this is enabled or not too!  ;)


Devlin

That's pretty much exactly what I was thinking for now (and am somewhat halfway through editing) - have an override key for browsing into directories that don't mark themselves as such as a workaround.


Am I correct in understanding MANAG.BIN is a compiled version of MANAGER.TXT?
CPC464 & CPC6128 + USIfAC II + Revaldinho 512k(universal cpld ver) - Schneider CRT TV
Administrator of Amstrad Discord : https://discord.gg/ksWvApv

ikonsgr

Not worry,i've already done it! just reload the file manager folder.
I've added key <1>, when pressed all names are treated as directories and you will get a notification at the top right of screen! And if you press it again it's deactivated! And the best thing is , even if you have this mode enabled and try to run a real file or dsk image, it's just give an instant error (no directory found) and... it continues without problem!  :)
So, even if you forgot to deactivate it, for running a file, you just press '1' and you are ready to go!
And now, i think we solve the problem for good!  ;)

"Manag.bin", is the binary of the aseembly routine that extracts directory lists to ram (the equivalent of the new |MAN command). FMANAGER.TXT is the source code for the compiled "FMANAGER.BIN" binary file.

Devlin

I've done a bit of tinkering here too, and discovered that folders will show their correct directory status *IF* that folder doesn't have the *archive* bit set in Windows - If it does, it doesn't show the <DIR> part CPC-side - downloading the new manager now anyway. having the option to override is helpful.


Run into another issue though - Some games don't load their loading screens correctly, or just outright fail to load when launched through the file manager - I think it's down to memory, is there a way to clear the ram before launching something
CPC464 & CPC6128 + USIfAC II + Revaldinho 512k(universal cpld ver) - Schneider CRT TV
Administrator of Amstrad Discord : https://discord.gg/ksWvApv

ikonsgr

I execute a: "CLEAR:MEMORY 42600" before running the selected file (check the "FM" BASIC program, you can easily change it if you want). Most games work fine with that, but some might have problems.
In that case you can reset (by having the "return to root dir" disabled in order to maintain the current game dir), give a cat, and run the file from "clean start"  ;)
btw,i noticed a couple of games that report "out of memory" error (for example gauntlet), but this turns out to be an incompatibility with cpc464 as the games runned fine (using the Filemanager) on a cpc6128, and also, i got the same error on cpc464, even when i tried to run them from "clean start"....

Quote from: Devlin on 20:57, 13 June 21
I've done a bit of tinkering here too, and discovered that folders will show their correct directory status *IF* that folder doesn't have the *archive* bit set in Windows - If it does, it doesn't show the <DIR> part CPC-side.
WOW! That's a great discovery!  I'll add this tip into user's guide!
So if you just remove all archive bits from all dirs in the usb stick, then all Directories will be shown correctly  ;)

DoctorCPC

My Amstrad Products: Amstrad CPC 464, Amstrad CPC 6128, Schneider CPC 6128, Amstrad NC 100, Amstrad HiFi EX330, Amstrad Fidelity CKX100 Music Keyboard, Amstrad Penpad 600, Amstrad Emailer Plus, Amstrad E3 Emailer, Amstrad VCR Programmable Remote Control, Amstrad DVD/Divx Player, Amstrad GT 65, Schneider CTM640

CPC Hardware: USIFACII, M4Wifi, ZMEM, MotherX4, GOTEK, PS2 Mouse Adapter, RSF3 (Soon), DES Mini (Soon)
PCW Hardware: GOTEK, PCWIO, uIDE (Soon), uRTC (Soon)

Editor-In-Chief / ACUC Magazine - Amstrad CPC User Club Magazine (Soon)
www.dizzyradio.com  / Amstrad CPC, Commodore 64, Amiga and Other Home Computer's Musics
www.cpcuserclub.com / +90 555 498 36 55 for adding WhatsApp Group

Fran123

What is the source of FMANAG.BIN?
New boards only need FMANAG.BIN

Fran123


Fran123

Quote from: Mark_wllms on 14:11, 13 June 21
Did you try on an (unmodified) 6128? Was it CP/M Plus?


I tried to run CP/M plus, the first disk


CP/M 2.2 runs

Devlin

Quote from: ikonsgr on 23:47, 13 June 21
So if you just remove all archive bits from all dirs in the usb stick, then all Directories will be shown correctly  ;)

Seems to be the case. The override is still useful though, so don't ditch it because there's an alternative solution.

Any plans to add a bootloader/auto-update feature to the usifac2? I don't mind getting the kit to reprogram it but would massively prefer an easier way to update
CPC464 & CPC6128 + USIfAC II + Revaldinho 512k(universal cpld ver) - Schneider CRT TV
Administrator of Amstrad Discord : https://discord.gg/ksWvApv

ikonsgr

Quote from: Fran123 on 12:44, 14 June 21
What is the source of FMANAG.BIN?
New boards only need FMANAG.BIN

  The source code for FMANAG.BIN is the "file_manager.asm". This is needed for all boards with current or older firmwares, but, as i manage to add it as RSX command ("|MAN"), it will not be needed for newer boards. Practically the only difference in utilizing the routine in a BASIC program is that, instead of initially loading the binary in memory:
MEMORY &17FF:LOAD"FMANAG.BIN",&1800
and use it by giving a CALL &1800,
You will just give a: "|MAN", which loads and executes the routine directly from USIfAC with the new firmware.

Quote from: Fran123 on 13:18, 14 June 21
Is it possible to retrieve file sizes at same time?
There is actually a function that returns the file size, but i think you can use it, only after a file is opened, and not when you get a catalogue of files. I have to see it more carefully, if it's easy to implement and doesn't take much space, i might add another RSX command to get size of a specific file.

ikonsgr

Quote from: Devlin on 15:52, 14 June 21
Any plans to add a bootloader/auto-update feature to the usifac2? I don't mind getting the kit to reprogram it but would massively prefer an easier way to update

Actually,there is a project for bootloaders with PIC mcu: https://sourceforge.net/projects/tinypicbootload/
But i don't know if the specific PIC is supported and also, bootloaders need some program memory too, and currently we left with less than a 1kb.
In anycase, you would still need to use a programmer for the initial flashing of firmware with the bootloader, so practically you can't avoid the ICSP programmer...  ::)
Still, i don't think there will be any significant fw updates in the future, even the latest addtion of |MAN RSX command for the file manager, is not required for older boards  ;D

Fran123

Is it possible to put DIR info into a higher address than &1800?Or an option to select that initial address?

I would make a file explorer with more functions
Thank you

ikonsgr

Quote from: Fran123 on 10:28, 15 June 21
Is it possible to put DIR info into a higher address than &1800?Or an option to select that initial address?

I would make a file explorer with more functions
Thank you

There is a reason for why i put this code so "low" in ram: The compiled Basic program (using Hisoft Turbobasic compiler) for file manager ,starts &5AC0 ,this is where turbo basic puts all binaries (and i don't think you can change it). Now, the code for creating directory in RAM, pre-loads the ENTIRE directory, not only the current page. So  if we want to support large directories with many filenames (up to ~1000) we will need plenty of room in ram. And since each file name usually takes ~15 bytes , means that for ~1000 names we will need ~15k. So if you subtract 15000 from &5AC0 you will end up ~&2000. The code for DIR is ~500bytes, e.g. start would be ~&1800  ;)
Of course, if you want to support less filenames for example ~500, you can put DIR code maybe ~&3800, which will leave plenty of room for a rather large Basic program.
Now,changing the address for the DIR binary, is something you can do yourself, rather easy! Inside file manager folder, you will find the asm code for the DIR code, "file_manager.asm":
write"DIRECT_ROM.BIN" 
ORG &1800
data equ &2000
.txt_output equ &bb5a
.km_read_char equ &bb09

ld a,&FB
        in a,(&De)
or a
jp z,no_usb

;CATALOGUE A USB DIRECTORY

call set_directory

ld bc,&fbd0
call clear_buffer
call usb_cmd

ld a,&2f
out (c),a

ld c,&d9
ld a,1
out (c),a
ld a,&FB
        in a,(&D3)
or a
jp nz,continue_man

ld c,&d0
ld a,"/"
out (c),a

continue_man:
ld bc,&fbd0
ld a,"*"
out (c),a
ld a,0
out (c),a
call usb_cmd
ld a,&32
out (c),a

call check_responce2
ld A,&FB
        in A,(&D0) 
cp &1d
jp nz,error_4

ld hl,data
ld a,1
ld (hl),a

loop_mancatalogue:

ld bc,&fbd0
call clear_buffer
call usb_cmd
ld a,&27
out (c),a

call check_responce2
ld A,&FB
        in A,(&D0)
or a
jp z,ending_mancatalogue

ld b,8
call print_man_loop

call check_responce2
ld A,&FB
        in A,(&D0) 
cp &20
jp z,continue2_mancat

ld b,a
ld a,"."
inc hl
ld (hl),a
ld a,b
inc hl
ld (hl),a
continue2_mancat:
ld b,2
call print_man_loop

continue_mancat:

call check_responce2
ld A,&FB
        in A,(&D0) 
cp &10
jr nz,continue_manloop
ld a," "
inc hl
ld (hl),a
ld a,"<"
inc hl
ld (hl),a
ld a,"D"
inc hl
ld (hl),a
ld a,"I"
inc hl
ld (hl),a
ld a,"R"
inc hl
ld (hl),a
ld a,">"
inc hl
ld (hl),a

continue_manloop:
ld a,1
inc hl
ld (hl),a

call clear_buffer
call usb_cmd
ld a,&33
out (c),a

call check_responce2
ld a,&FB
        in a,(&D0) 
cp &1d
jp z,loop_mancatalogue

ending_mancatalogue:
ld a,2
inc hl
ld (hl),a
ret

print_man_loop:
call check_responce2
ld A,&FB
        in A,(&D0) 
cp &20
jr z,cont_print_man
inc hl
ld (hl),a

cont_print_man:
djnz ,print_man_loop

ret

no_usb:
ld hl,message_no_usb_msg
call printmessage
ret


;-----------------------------------------------------------------------------------------
set_directory:
add_sub_dirs2:
ld bc,&fbd9
ld a,1
out (c),a
ld a,&FB
        in a,(&D3)
cp "/"
jp nz,continue_usbcat

add_sub_dirs:
;Add sub dirs
ld bc,&fbd0
call clear_buffer
call usb_cmd
ld a,&2f
out (c),a

ld a,&FB
        in a,(&D6)
CP 2
jr nz,dir_catname

ld a,"/"
out (c),a

dir_catname:
ld a,&FB
        in a,(&D3)
cp "/"
jr z,continue_subdir_loop
or a
jr z,continue_subdir_loop
out (c),a
jr dir_catname

continue_subdir_loop:
ld d,a
ld a,0
out (c),a
call clear_buffer
call usb_cmd
ld a,&32
out (c),a
call check_responce2

ld A,&FB
        in A,(&D0) 
cp &41
jp nz,error_ucd

ld a,d
or a
jr z,continue_usbcat
jp add_sub_dirs

continue_usbcat:
ret
;-----------------------------------------------------------------------------------------
usb_cmd:
ld a,&57
out (c),a
ld a,&ab
out (c),a
ret
;-----------------------------

;---------------------------------------------------------------------------------------
check_responce2:
        ld a,&FB
        in a,(&D1) 
        dec a
        jr z,check_responce2
ret
clear_buffer:
inc c ;clear buffer
ld a,1
out (c),a
dec c
ret

;-----------------------------------------------------------------------------------------
error_4:
ld bc,&fbd1
ld a,9
out (c),a
ld hl,error4_message
call printmessage
ret
;-----------------------------------------------------------------------------------------
printmessage:
ld a,(hl)
or a
ret z
call &bb5a
inc hl
jr printmessage
;-----------------------------------------------------------------------------------------
error_ucd:
ei
ld hl,error3_message
call printmessage
ret

message_no_usb_msg:
defb "Usb Device not enabled!",13,10,0

error4_message:
defb "No File(s) or Dir(s) Found!",13,10,0

error3_message:
defb "Unexpected error!",13,10,0


As you can see, you can easily change the starting address by replacing the ORG directive and data tag ,at the top of the code. Then you can simply use an assembler (i use winape's assembler, but i suppose you can use any other assembler you want) to produce the binary file. Finally i use CPDDISKXP to create the amsdos header for the binary (just create  new dsk image and add the binary, program will ask you if you want to add header and give start&execution addresses, which both should be the address used in ORG directive). Then you simply  extract the file created by cpcdiskxp which can be used with any basic program by giving: Memory addr-1:load"FMANGER.BIN",addr:call &addr (where addr is the address given in ORG directive)

Fran123

is there any error when you put some commands??


I have done a program that sends |DIS, |USB and |EN several times in a minute, and CPC freezes or reboots

ikonsgr

 Why on earth you need to do such a thing? :)
In anycase, i doubt that |DIS and |EN commands can cause any problem (they are simple out commands to the board), but |USB, especially when it activates the usb host module, does a lot of things (in order to enable and activate module and any usb device attached),so i wouldn't recommend to "play" with that. But maybe  issuing a delay between enable/disable of usb host module, could avoid unpleasant behaviors

Fran123

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.

ikonsgr

Quote from: Fran123 on 07:01, 16 June 21
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!  ;)

Powered by SMFPacks Menu Editor Mod