6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 5:05 pm

All times are UTC




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sun Jul 21, 2019 5:00 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
So, I was looking at datasheet differences between the 6526 and 8520 chips earlier and found the only real difference is the TOD clock logic of the 6526 is replaced with a 24-bit binary counter on the 8520. I also noticed many years ago that the 1581 drive schematics do show the select line to the CIA marked as "6526". The schematic also shows that a jumper is placed on the PCB when using a WD1770 FDC and left open when using a WD1772 FDC. The jumper connects the PH2 clock line to the TOD line, which drives the 24-bit counter on the 8520. This seemed a bit odd.

Note that a functional difference between the WD1770 and WD1772 FDCs are the step rates. There are 4 available step rates, but the first two between the chips are the same. I went back to the source code and found out what they're doing... albeit it doesn't makes any sense! Turns out the code preloads memory locations with the FDC commands from ROM. The command options are part of the command, which includes step rates for Type I commands, which move the R/W heads. The hardware uses the jumper to increment the counter, which is checked in the controller reset code... if the counter has NOT been incremented (meaning, no jumper is on the PCB), they take a different path and increment the Type I commands which also has the default step rates. As the step rates are the lower two bits, they change from 00 to 01. Here's the problem however...

for the WD1770, step rates are:

0 0 = 6ms
0 1 = 12 ms
1 0 = 20 ms
1 1 = 30 ms

for the WD1772, step rates are:

0 0 = 6ms
0 1 = 12 ms
1 0 = 2 ms
1 1 = 3 ms

So, without the jumper, the step rate changes from 6ms to 12ms. Logically, it would appear that Commodore was attempting to switch step rates if a WD1772 was installed and leave the defaults if a WD1770 was installed. Problem is, the code doesn't actually address the different step rates... it just increases it for the WD1772 (when the jumper is absent). Perhaps they had a preliminary datasheet that was marked incorrectly which could account for the bad code. Here's the source code section that does this:

Code:
reset_ctl      ; reset disk controller
   ldy  #all
   jsr  xms   ; no access for 500 mS
   ldy  #all
   jsr  xms   ; *

   lda  #bit7
   sta  cachetrk   ; *
   lda  #0
   sta  dirty
   jsr  psetdef
   jsr  setdef

   lda  #$4e
   sta  ctltimh
   lda  #$20
   sta  ctltiml   ; IRQ's
   jsr  resetim   ; reset controller timers
   lda  #$08   ; setup wd177x commands
   sta  wdrestore
   lda  #$18
   sta  wdseek   
   lda  #$28
   sta  wdstep   
   lda  #$48
   sta  wdstepin      
   lda  #$68
   sta  wdstepout
   lda  #$88
   sta  wdreadsector
   lda  #$aa
   sta  wdwritesector
   lda  #$c8
   sta  wdreadaddress
   lda  #$e8
   sta  wdreadtrack
   lda  #$fa
   sta  wdwritetrack
   lda  #$d0
   sta  wdforceirq

   lda  #18
   sta  setval   ; 18 mS
   ldy  #all   ; test registers
1?   sty  wdtrk
   sty  wdsec
   sty  wddat
   jsr  delay16      
   cpy  wdtrk
   bne  3?

   cpy  wdsec
   bne  3?

   cpy  wddat
   bne  3?

   dey
   bne  1?

   jsr  wdabort   ; abort the wd17xx
   lda  #0
   sta  todlsb
   jsr  delay40   ; wait for 40 uS
   lda  todlsb
   bne  2?      ; default wd1770

   inc  wdrestore
   inc  wdseek   
   inc  wdstep   
   inc  wdstepin      
   inc  wdstepout

2?   bne  okdone   ; bra

3?   lda  #$0d   ; controller error
   .byte skip2
okdone   lda  #0      ; ok
done   jmp  errr   
;


As a result, adding the jumper would result in faster step rates and improve the performance of the 1581 Drive. Also, as it turns out, if you have no need to have a jumper on the PCB, you can simply replace the 8520 CIA with a 6526 CIA and the drive will function the same. As 6526 chips can still be found more easily than 8520 chips, anyone who would either like to build a drive from parts or need to repair one (assuming a bad 8520), using the 6526 would be a easy swap.

I think I'm going to modify the code... use a table to load up the RAM locations and remove the code that checks the 24-bit timer and get the faster step rates. Granted, I do need to get my 1581 out, along withe a C64 and Monitor to do final testing... so I'm also looking at another problem area in the source code that could hang the drive if a certain error happens with the FDC.

This one is a bit tricky... as it tests for the FDC to no longer be busy, then checks the status register for specific errors, sets a controller_status byte with an error code and exits. The problem here is stack usage in the code for testing an initial status bit, the S2 bit (Data Lost).... if it's a problem, the stack is left with the CPU status register (PHP instruction) and no PLP to get it back, so the return address pulled via the RTS will be incorrect and result in a hang condition. I'm going to look at changing this code as well and likely fix an odd error that would hang the drive once in a great while.

Code:
getwdstat
;
   jsr  wdunbusy   ; wait for unbusy first
;
wdstatus
;
   php
   WDTEST
   lda  wdstat     ; get status
   lsr  a
   lsr  a
   lsr  a
   bcs  1?
;
   and  #bit3+bit1+bit0
   tax
   plp             ; restore carry
   lda  wdtrans,x
   .byte skip2
1?      lda  #9
   sta  controller_stat
   lda  controller_stat
   rts
;
wdtrans .byte 0,5,2,0,0,0,0,0,8
;


Some years ago, I started working on the 1581 and have a handful of changes to the source code to reduce it's overall ROM size. Fixing a couple extra bugs really can't hurt. I also have a few NOS 6526A parts and will try one of these in the drive as well. Fun time... :D

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 05, 2019 5:39 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
I've done some work on the source code.... cleaned up the formatting a ton, so the source and listing is easier to read.

I also changed the stepping rates to reflect the Chinon drive specification, which is a 3ms step rate (default was 12ms). The WD1772 handles this rate and the drive is significantly quieter in operation using the new step rate values. A long assembly using over 50 source files is just a tad bit quicker, but not that significant.

I've also tried some 6526A CIAs in place of the 8520A, but no joy... so I'm thinking they're either non working parts or not truly rated at 2MHz, i.e., remarked 1MHz parts. I think I tried these in a C64 when I got them a few years ago... so will need to test them again.

In any case, I've managed to squeeze the code size down by about 3.6KB, now less than 20KB total ROM space required. It's also using a fair number of CMOS opcodes now to help reduce ROM space. Once I get further along on code changes and more testing (I've already cratered a couple diskettes), I'll post an updated source.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 05, 2019 10:25 am 
Offline

Joined: Wed Feb 12, 2014 1:39 am
Posts: 173
Location: Sweden
Great posts! As I've been playing around with floppies on my own system of late I had a look at the schematics for the commodore drives and was wondering why there was jumper selects for different makes of the drive mechanism which has now been answered :)


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 06, 2019 6:04 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
LIV2 wrote:
Great posts! As I've been playing around with floppies on my own system of late I had a look at the schematics for the commodore drives and was wondering why there was jumper selects for different makes of the drive mechanism which has now been answered :)


I've only got two different Commodore drives; a 1541 drive (original in white casing to match the Vic-20) and a pair of 1581 drives. The older 1541 only has jumpers for changing the Drive ID number. The drive mechanism used was an Alps unit only. Later versions also had other options, but the only noted jumper (J6) to change to a different drive mechanism didn't change anything related to stepping rates, but appears related to the R/W circuitry and a bias change by shorting out a resistor. Unless of course I missed something, which could be the case.

As a follow-up, I tested all 3 of my 6526A CIA chips in a C64... all appear to be dead (triple-damn)! I picked these up from UtSource back in 2014 and they did work, as I tried them in the C64 and they were working. All I can figure is they used some process for cleaning them which eventually leeched into the encapsulation and killed them over time :shock:

On the good side, I've completed a first blush at modifying the 1581 source code. From the testing I've done so far, everything seems to work fine, albeit I've not tested every drive function, e.g., creating partitions and some other specific commands. I'm using many CMOS instructions (PHX, PHY, PLX, PLY, BRA, STA, etc.) and at least one new addressing mode. Code size is about 3.8K smaller and the drive stepping rates default to 3ms instead of being bumped to 12ms by the original code.

I've got another round of changes in the works for initial boot up which should get some additional bytes back and I found another minor anomaly in the original code. The Power LED can be set for two brightness levels via a port bit on the 8520A CIA. This is used in a blink mode to show certain errors. Turns out the standard ROM code sets it in high brightness mode initially, but shortly after some commands are executed (scratch, validate and others) it drops to normal brightness. I'll likely fix that as part of the next set of updates.

Finally, if anyone has some good programs (assembler or BASIC) that can exercise the functions of the 1581, I'd like to try those for final testing to see of all the code changes work properly.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 15, 2019 6:02 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Some additional progress to report...

I now have a modified version of the 1581 ROM code which is under 20KB. There are quite a few CMOS opcodes used and the JMP (ABS,X) addressing mode is also used. As much as I can test (with a C64 and the Macro Assembler package) everything seems to work fine. I removed the section that tests for the WD1770 and just set the step rate correctly for 3ms, so you don't need an 8520A, a 6526A will work. I also fixed one bug that I found earlier, which doesn't clear the stack correctly.

Another odd part is that Commodore bypassed the error check for the ROM checksum with the -02 ROM version. They did however leave the same checksum byte and signature bytes, just didn't branch on the error. I'm looking at fixing that as well, but the check routine doesn't seem to adhere to any standard routine that my programmer supports (Dataman 40Pro), so I need to take a different approach on fixing that.

I've also been successful at using a different diskette drive. I have a small quantity of the Teac FD-05 series drives, both HF and HG versions, which can readily be bought online. These are the slimline laptop drives that were used in the early ThinkPad machines and also in external cases for same. All I needed to do was build up a small cable for the 26-pin drive connector and then use some jumpers to the 1581 34-pin drive connector. These are lower power and require 5-volts only. You can simply ignore the HD out line (for 1.44MB HD diskettes) and the motor speed line on the HG version (speeds up to 360 RPM) and leave them floating.

So as it turns out, if you can source the 8520A (or a 6526A) and the WD1772 FDC, you can build yourself a working 1581 diskette drive with little issue. Using the FD-05 drive, a much smaller drive could be built. Once I get a few more changes completed on the ROM code, I'll post a new source file.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 06, 2019 4:47 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
I've completed about as much testing as I can on code changes. I've also managed to fix the base power up checksum (working again), as the -02 ROM version disabled it) and also the ROM Signature test under Burst Commands. As I thought, the -02 version of the ROM also fails this test, resulting in 4 flashes of the access light. The test takes toughly 10 seconds to complete. On working code, you get one short flash after completion of the ROM test.

With the new step rates (3ms versus 12ms), an assembled code base of 50+ files went from 12:00 minutes to complete, to 11:55 minutes. Granted not that much savings, but the drive is much quieter on accesses.

I'll look at packaging up all of the files and post them, in case anyone has an interest. Do note however, that the new code requires a CMOS processor, as there are many CMOS only opcodes used and at least one CMOS addressing mode used.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 07, 2019 3:38 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Here's the compressed ZIP for for a CMOS version of the 1581 source code. The source has been heavily cleaned up and is very consistent in format for all files. It's also been formatted for the WDC assembler linker (as it's the only one I use). I'll likely take the official -02 ROM binary and fix it so the base ROM checksum works and the ROM signature test works. That will be a little while, but will also post to this thread when I finish it. Have fun...

Attachment:
1581_Source.zip [343.11 KiB]
Downloaded 174 times

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 11, 2019 8:30 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
I read through this again today. Good stuff. It would be interesting to make a homemade 1581 but the WD1770/2 are rather dear these days. It looks like there were also compatible alternative though.

FD179x series from SMC Microelectronics
MB887x series from Fujitsu
VL177x series from VLSI Technology.

from: https://en.wikipedia.org/wiki/Western_Digital_FD1771

I suspect though it would come down to salvaging some parts from old gear.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 12, 2019 11:09 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Well, I picked up a few of the VLSI sourced chips a few years ago from UTsource.. all worked fine. Turns out they still show stock and you can also get them through Newegg as a reseller... who knew.

https://www.newegg.com/p/2A3-0029-1X8V8

My original 1581 came with the VLSI chip, as I imagine WD was running slim on them back in the day, as Atari was also using these heavily.

On the other side, the Atari Ajax chip is also available, albeit a bit pricey, at $29.95 each. Here's more detail on that one:

http://www.best-electronics-ca.com/custom-i.htm#Ajax

I picked up a few of these some years ago as well. I tried one in the 1581 and it works fine. It will also support the 1.44MB (formatted) data rates, which the standard WD chips won't. WD did offer a slightly modified version, spec'd as WD1772PH02-02. This particular chip does support the 1.44MB data rate, but I think Atari snagged every one, and still had to come up with the Ajax chip after WD stopped making them.

Getting the 6526 or 8520 will be more of a problem, but you can probably work around that by using a 65C22 and rewriting some of the code. The down side is that Commodore used the serial port of the 8520/6526 for the high speed transfer feature. As all 65x22 chips have a problem with the serial port, you'd have to work around that. Still, it could be an interesting project.

Since I finished working on the code, I did find a Commodore disk utility that won't run with the modified code... I'm pretty sure it's calling absolute ROM addresses for several functions, as the original 1581 code has numerous bits of code at specific ROM addresses. There were lots of holes ($FF) in between sections of code in the original source. These would be trivial to put back, as all of the ode segments are still assembled in the same order.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 13, 2019 5:04 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
I just found that BGMicro was WD1773-PH which look like they are WD1770-PH but not quite 100% software compatible? After a cursory glance at the datasheet I'm a bit unsure still what the differences are.

http://www.bgmicro.com/ICS1050.aspx


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 13, 2019 6:23 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
I read the datasheet a bit more closely on my lunch break and it looks like the difference between the WD-110 and WD1773 is all in pin #20. Since this is not used on the 1581 it should not matter I think.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 14, 2019 3:25 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Jeff_Birt wrote:
I just found that BGMicro was WD1773-PH which look like they are WD1770-PH but not quite 100% software compatible? After a cursory glance at the datasheet I'm a bit unsure still what the differences are.

http://www.bgmicro.com/ICS1050.aspx


Well, according to the 1986 WD Storage Handbook, the 1773 is 100% software compatible with the WD179X, albeit it lacks Motor Control (pin 20) versus the 1770/1772. Instead, pin 20 is for Ready/Enable Write precomp. Also, the 1770/1773 have step rates which match the 179X controllers, while the 1772 has faster step rates. That's about it. In any case, you should be able to use it in a 1581 clone build, as you can easily change the step rates in the config and by default, motor control is done by the 8520, not the built-in motor control from the floppy controller.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 17, 2023 4:32 pm 
Offline

Joined: Fri Mar 17, 2023 4:09 pm
Posts: 4
I need help with the with comments last . I found this thread while searching the net. I made Commodore 1581 replica boards. Normally I used WD1770 and they work fine.I received 5 pieces WD1773 from someone else. I also tried C1581 and it didn't work. Problem ; The game reads a little from the floppy disk and won't load. I looked at the required pdfs, as in the comments, the only difference is 20.pin, but C1581 does not use it either. my english is not good i hope i explained the problemAny ideas on this? thanks


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 17, 2023 4:55 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
(Welcome!) Pin 20 is an output in the 1770, so the 1581 can leave it unconnected. But on the 1773 it's an input, so it shouldn't normally be left unconnected. Whether you can get away with tying it low, or high, I don't know, but you could try it each way. If you want to allow a 1770 in the same board, you'd need to tie the pin through a high value resistor. The datasheets should help.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 18, 2023 10:43 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
As Ed noted, pin 20 is an input, but is used for two different indications; a drive ready signal or an enable for write precompensation. In any case, this line should probably be tied up to +5V via a resistor... 1K should be fine.

On the software side, the 1581 code manages the write precompensation against track 43 or greater by flipping bit1 in the write sector command. According to the datasheet, this is valid for all versions of the FDC. Note however that there are a few other differences between the status register and some bits in the command structure. Notably, the 1773 uses bit3 for Type II commands as a side compare, which, on the 1770/1772, is for Motor Spin Up. Scanning the source code, it's not clear if this difference will cause any issues for sector reads and writes.

Do post back once you do some additional testing and let us know if you have it working.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 29 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: