Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability for Disk II to write. #780

Merged
merged 7 commits into from
Oct 3, 2024

Conversation

FozzTexx
Copy link
Contributor

This enables doing writes from the Apple II using the Disk II interface. Essential for old games to be able to update their high score tables. 😉

Current known limitations:

  • Only works with sector based images such as .dsk, .do, .po
  • Only sectors using standard 6 and 2 encoding can be written
  • No ability to handle formatting a blank disk
  • The CONFIG autorun.po disk image has been modified to allow write to be enabled on Disk II, but doesn't allow it when selecting a disk (simple #if 0 around lines 204-213 in src/hosts_and_devices.c)

Capturing of SP_WRDATA is done by using the existing spirx from the SmartPort device. It is put into continuous ring buffer mode so that it will already be capturing data when the Apple II suddenly switches to write mode. I added spi_continuous.c in lib/bus/iwm, this may not be the right place for it, but currently it is only used by iwm_ll.

@FozzTexx FozzTexx changed the title Added ability for Disk II to write. Adds ability for Disk II to write. Sep 10, 2024
@tschak909
Copy link
Collaborator

This needed a re-base, so I am waiting for build checks to complete, before marking ready for review. -Thom

@tschak909 tschak909 added this to the disk ii writing milestone Sep 10, 2024
@tschak909 tschak909 marked this pull request as ready for review September 10, 2024 20:50
@FozzTexx
Copy link
Contributor Author

FozzTexx commented Sep 10, 2024

To test:

  • Boot into CONFIG and mount a ProDOS disk on a SmartPort drive and a DOS 3.3 disk on first Disk II
  • Set first Disk II to writable
  • Boot into DOS 3.3
  • Type in NEW and a short "Hello World" program
    • SAVE TEST
    • NEW
    • LIST and make sure it's gone
    • LOAD TEST
    • LIST and make sure the program you typed in is back
  • If all that is good, then while DOS 3.3 is still booted, PR#n into your SmartPort disk and make sure it boots

Be sure to test with both .do/.dsk and .po images containing DOS 3.3 on the Disk II.

If you're using a IIc then you'll need to boot DOS 3.3 from the internal floppy drive and write to a DOS 3.3 disk on slot 6 drive 2: SAVE TEST,S6,D2

You'll need to use the attached disk image to configure the Disk II as writable.

dist.po.zip

DOS 3.3 test images:

DOS33-d2w.zip

@FozzTexx FozzTexx force-pushed the disk2-write branch 4 times, most recently from 054ad24 to 34a7dbb Compare September 12, 2024 18:46
@FozzTexx
Copy link
Contributor Author

Pre-built firmware for Apple FujiNet from commit ID 79b22ad:

fujinet-APPLE-79b22adb.zip

@tschak909
Copy link
Collaborator

Write works for me on IIc with rom0, putting disk in Disk ][ slot 1, and referencing as S6,D2.

Copy link
Collaborator

@tschak909 tschak909 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me putting disk in first disk ][ slot, and referencing as ,s6,d2. Apple //c rom0.

@tschak909
Copy link
Collaborator

image

@tschak909
Copy link
Collaborator

Can someone please perform this test? My FujiNet crashes, am wondering if it is due to OOM or some other factor:

ZIP attached with a DOS 3.3 disk, and a completely blank disk.

copy-test.zip

Boot from DOS 3.3
Mount blank disk read/write

] BRUN FID
select COPY FILES

Select slot 6 drive 1 as source
Select slot 6 drive 2 as destination.
Filename is =
DO YOU WANT PROMPTING? N

Success is all files being copied to destination disk.

10:54:15.568 > Disk II iwm queue receive 3072 31963 34779 50304
10:54:15.569 > Disk II write Qtrack/sector: 104/10  bit_len: 2816
10:54:15.578 > Disk II used: 3072
10:54:15.578 > Disk II sector data: 9Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
10:54:15.590 > 
10:54:15.590 > Core  1 register dump:
10:54:15.590 > PC      : 0x4008f764  PS      : 0x00060230  A0      : 0x802231d6  A1      : 0x3ffd49f0  
10:54:15.593 > A2      : 0x00000068  A3      : 0x3ffff6c0  A4      : 0x00000080  A5      : 0x00000068  
10:54:15.594 > A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffd49c0  
10:54:15.595 > A10     : 0x00000080  A11     : 0x3ffd7338  A12     : 0x3ffff6c0  A13     : 0x00000080  
10:54:15.598 > A14     : 0x00000001  A15     : 0x0000abab  SAR     : 0x00000008  EXCCAUSE: 0x0000001d  
10:54:15.599 > EXCVADDR: 0x00000068  LBEG    : 0x4008f760  LEND    : 0x4008f77c  LCOUNT  : 0x00000007  
10:54:15.602 > 
10:54:15.602 > 
10:54:15.602 > Backtrace: 0x4008f761:0x3ffd49f0 0x402231d3:0x3ffd4a00 0x4022328d:0x3ffd4a40 0x400f3b2e:0x3ffd4a60 0x402426a1:0x3ffd4a80 0x40081c62:0x3ffd4aa0 0x400820c8:0x3ffd4c50 0x400d2e18:0x3ffd4c70 0x40098495:0x3ffd4c90
10:54:15.800 > 
10:54:15.800 >   #0  0x4008f761:0x3ffd49f0 in memcpy at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/memcpy.S:175
10:54:15.800 >   #1  0x402231d3:0x3ffd4a00 in _fread_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fread.c:223
10:54:15.800 >   #2  0x4022328d:0x3ffd4a40 in fread at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fread.c:266
10:54:15.800 >   #3  0x400f3b2e:0x3ffd4a60 in FileHandlerLocal::read(void*, unsigned int, unsigned int) at lib/FileSystem/fnFileLocal.cpp:56
10:54:15.800 >   #4  0x402426a1:0x3ffd4a80 in iwmDisk2::write_sector(int, int, unsigned char*) at lib/device/iwm/disk2.cpp:166
10:54:15.800 >   #5  0x40081c62:0x3ffd4aa0 in iwmBus::serviceDiskIIWrite() at lib/bus/iwm/iwm.cpp:681
10:54:15.800 >   #6  0x400820c8:0x3ffd4c50 in iwmBus::service() at lib/bus/iwm/iwm.cpp:447
10:54:15.800 >   #7  0x400d2e18:0x3ffd4c70 in fn_service_loop(void*) at src/main.cpp:502 (discriminator 1)
10:54:15.800 >   #8  0x40098495:0x3ffd4c90 in vPortTaskWrapper at /home/thomc/.platformio/packages/[email protected]/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154
10:54:15.800 > 
10:54:15.800 > 
10:54:15.800 > 
10:54:15.800 > 
10:54:15.800 > ELF file SHA256: 0e21d0f689b8ed10
10:54:15.800 > 
10:54:15.800 > Rebooting...

@FozzTexx
Copy link
Contributor Author

Can someone please perform this test? My FujiNet crashes, am wondering if it is due to OOM or some other factor:

ZIP attached with a DOS 3.3 disk, and a completely blank disk.

What do you mean by "completely blank"? All sector data is 0x00? Disk II write only works with formatted disk images.

@tschak909
Copy link
Collaborator

tschak909 commented Sep 21, 2024 via email

@dillera
Copy link
Contributor

dillera commented Sep 21, 2024

I'm trying out normal apps and they are all failing for me.

  • IIS - fails on this pr, works fine on master
  • Weather - fails on this pr, works fine on master

Fail means it just locks up pretty much on the initial API HTTP fetch of data. Logs just stop on the FN, there is no error logged out via USB.

For instance, loaded Weather app, logs:

14:57:54.785 > aux1: 4 aux2: 0 path N:http://ip-api.com/json/?fields=status,city,countryCode,lon,lat
14:57:54.788 > open()
14:57:54.788 > iwmNetwork::instantiate_protocol() - Protocol http created.
14:57:54.821 >
14:57:54.821 > handling control command
14:57:54.821 > Net Device 87 Control Code fc('.') net_unit 00
14:57:54.824 > channelMode = JSON
14:57:54.848 >
14:57:54.848 > handling control command
14:57:54.848 > Net Device 87 Control Code 50('P') net_unit 00

That's it- i had to ctrl c out- it just stops and locks up.

@dillera
Copy link
Contributor

dillera commented Sep 21, 2024

Testing contiki and i get this over and over:

15:10:25.909 > Status code complete, sending response
15:10:25.921 > handling status command
15:10:25.921 > [NETWORK] Device 87 Status Code 53('S') net_unit 01
15:10:25.922 > Bytes Waiting: 0x00, Connected: 1, Error: 144
15:10:25.922 >
15:10:25.925 > Status code complete, sending response
15:10:25.936 > handling status command
15:10:25.936 > [NETWORK] Device 87 Status Code 53('S') net_unit 01
15:10:25.938 > Bytes Waiting: 0x00, Connected: 1, Error: 144

The app (contiki) is frozen at the 'Connecting...' output.

@dillera
Copy link
Contributor

dillera commented Sep 21, 2024

testing mastodon app...
Asks to "press a key"
then locks up.

Output:

15:12:56.765 > NETWORK: Sending DIB reply
15:12:59.242 >
15:12:59.242 > handling open command
15:12:59.275 > handling control command
15:12:59.275 > Net Device 87 Control Code 4f('O') net_unit 00
15:12:59.277 >
15:12:59.277 > aux1: 4 aux2: 0 path n:https://oldbytes.space/api/v1/timelines/public?limit=1
15:12:59.279 > open()
15:12:59.279 > iwmNetwork::instantiate_protocol() - Protocol https created.
15:12:59.313 >
15:12:59.313 > handling control command
15:12:59.313 > Net Device 87 Control Code fc('.') net_unit 00
15:12:59.315 > channelMode = JSON
15:12:59.340 >
15:12:59.340 > handling control command
15:12:59.340 > Net Device 87 Control Code 50('P') net_unit 00

no output after that.

@FozzTexx
Copy link
Contributor Author

I'm trying out normal apps and they are all failing for me.

The only time the new Disk II write code is running is when a disk in the FN Disk II slot is mounted in write mode and that disk is being accessed. If the FN disk isn't even mounted in write mode it then the write code isn't being used. Similarly if a SmartPort device is being used then the Disk II write additions aren't being used.

@FozzTexx
Copy link
Contributor Author

Testing contiki and i get this over and over:

I was able to load google.com and hackaday.com:

UNADJUSTEDNONRAW_thumb_78a5
UNADJUSTEDNONRAW_thumb_78a6

@FozzTexx
Copy link
Contributor Author

Current status:

  • @tschak909 and europlus have both verified that the new Disk II write feature works
  • SmartPort disk functionality works fine, nobody has had problems with using disks on FN and @tschak909 did additional testing with reading and writing a 32MB volume
  • When using SmartPort to fetch http data the FujiNet gets stuck after a few packets and stops sending the network packets to the Apple II, experienced by @tschak909, @mozzwald, @dillera, europlus
    • Problem occurs even with both Disk II slots empty which prevents the Disk II write feature from ever being called
    • Tried commenting out the new serviceDiskIIWrite(); call in iwmBus::service(), no change
    • Tried reverting the SP_WREQ GPIO config to not use pullups or enable interrupts, no change
    • The FujiNet does not crash/Guru error/wdt timeout, possibly waiting for a lock to release?
    • Web interface is still responsive when FujiNet is stuck
    • Problem so far only happens on a2_rev0 build, have been completely unable to reproduce on a2_d32pro

@FozzTexx
Copy link
Contributor Author

Problem seems to be RAM related. Stopped allocating the track buffer at the beginning and instead allocate it when disk starts and release it when disk stops. Seems to make a2_rev0 build happy.

@europlus
Copy link

europlus commented Sep 23, 2024

Problem seems to be RAM related. Stopped allocating the track buffer at the beginning and instead allocate it when disk starts and release it when disk stops. Seems to make a2_rev0 build happy.

Happy to test zip, but I’m currently rebuilding here (I think…I’m at git “look-it-up-on-Google” expert level).

@FozzTexx
Copy link
Contributor Author

Pre-built firmware for Apple FujiNet from commit ID 8beafbd:

fujinet-APPLE-8beafbd5.zip

@dillera
Copy link
Contributor

dillera commented Sep 23, 2024

This is working much better for me.
ISS, Mastodon, Weather all load and function as expected.

@dillera
Copy link
Contributor

dillera commented Sep 23, 2024

More updates after continuing to use this latest push- it's not perfect. I get "SEND REQ TIMEOUTS" about 30% of the time booting IIc - I always reset the FN device before booting - so it's always a fresh boot...

12:14:43.834 > trk pos 039 on d1
12:14:43.854 > trk pos 037 on d1
12:14:43.873 > trk pos 035 on d1
12:14:43.892 > trk pos 033 on d1
12:14:43.912 > trk pos 031 on d1
12:14:43.931 > trk pos 029 on d1
12:14:43.950 > trk pos 027 on d1
12:14:43.970 > trk pos 025 on d1
12:14:43.989 > trk pos 023 on d1
12:14:44.008 > trk pos 021 on d1
12:14:44.027 > trk pos 019 on d1
12:14:44.047 > trk pos 017 on d1
12:14:44.066 > trk pos 015 on d1
12:14:44.085 > trk pos 013 on d1
12:14:44.105 > trk pos 011 on d1
12:14:44.124 > trk pos 009 on d1
12:14:44.143 > trk pos 007 on d1
12:14:44.162 > trk pos 005 on d1
12:14:44.182 > trk pos 003 on d1
12:14:44.201 > trk pos 001 on d1
12:14:44.220 > trk pos 000 on d1
12:14:47.183 > disk ii enable states: 00
12:14:47.183 > stop diskII
12:14:47.183 > disk ii enable states: 00
12:14:47.185 > Reset
12:14:47.265 > Reset Cleared
12:14:47.265 > en35Host = 0
12:14:47.276 > handling status command
12:14:47.276 > Sending Device Status for device 0x00
12:14:47.279 > DIB number of blocks 280
12:14:47.279 >
12:14:47.279 > Send REQ timeout
12:14:47.289 > Send REQ timeout
12:14:47.299 > Send REQ timeout
12:14:47.310 > Send REQ timeout
12:14:47.321 > Send REQ timeout

At that point I have to reset FN (via button) and power cycle the IIc.

@FozzTexx
Copy link
Contributor Author

12:14:47.279 > Send REQ timeout
12:14:47.289 > Send REQ timeout
12:14:47.299 > Send REQ timeout
12:14:47.310 > Send REQ timeout
12:14:47.321 > Send REQ timeout

I get these more like 60% of the time on master on my IIe when booting SmartPort. This is a problem with the SmartPort packet capture not starting fast enough (PR #794). There's no change in this PR to SmartPort timing.

I also wonder if you're seeing them more since you moved the FujiNet to the internal connector.

@europlus
Copy link

I’m getting I/O ERRORs most times when I first try to start the FN via PR#X, disk2-write is currently loaded. Sometimes it will then load CONFIG on the second or third attempt. Resetting the FN or restarting the IIe, etc. don’t always clear the issue. I have some more checking to do, but I don’t recall it doing this with stock v1.4 firmware. Just thought I’d mention it in case anyone else here was experiencing the issue.

I know I’m doing some odd things, like loading a .po as R/W while having SP disks loaded. Results are mixed (I need to document my testing a bit more thoroughly, but I’m just trying various things to get a feel for it at the moment).

I do have success loading 140K ProDOS 2.4.2 .po disk images in Disk II alone and writing to them, same with .dsk images, and when I don’t have anything R/W in Disk II slots Weather program will successfully get the forecast (haven’t tested with R/O images in Disk II).

I’ll try to document what I do and report back if of any use. Are the logs above from Flasher while USB-connected?

@dillera
Copy link
Contributor

dillera commented Sep 27, 2024

Running Exorcisor.

Locked up after a few moments... 40 tries.

11:20:20.248 > Sending Device Status for device 0x00
11:20:20.251 > DIB number of blocks 280
11:20:20.251 > 
11:20:20.251 > Send REQ timeout
11:20:20.261 > Send REQ timeout
11:20:20.272 > Send REQ timeout
11:20:20.283 > Send REQ timeout
11:20:20.294 > Send REQ timeout

Screenshot 2024-09-27 at 11 21 33 AM

@dillera
Copy link
Contributor

dillera commented Sep 27, 2024

Update: reset via CTL-OA-RESET and re-ran from basic.
Got thru 575 cycles..

11:44:31.213 > 
11:44:31.213 > THE_FUJI: Sending DIB reply
11:44:31.219 > 
11:44:31.219 > [PRINTER]: Device: 89 Status Code 03
11:44:31.219 > 
11:44:31.219 > PRINTER: Sending DIB reply
11:44:31.225 > 
11:44:31.226 > handling status command
11:44:31.226 > [MODEM] Device 8a Status Code 03
11:44:31.226 > 
11:44:31.226 > MODEM: Sending DIB reply
11:44:31.294 > 
11:44:31.294 > Reset
11:44:31.375 > Reset Cleared
11:44:31.375 > en35Host = 0
11:44:31.385 > 
11:44:31.385 > handling init command
11:44:31.385 > Sending INIT Response Packet...
11:44:31.385 > Drive: 81
11:44:31.387 > 
11:44:31.387 > handling status command
11:44:31.387 > Sending Device Status for device 0x00
11:44:31.390 > Send REQ timeout
11:44:31.400 > Send REQ timeout
11:44:31.411 > Send REQ timeout
11:44:31.422 > Send REQ timeout
11:44:31.433 > Send REQ timeout
Screenshot 2024-09-27 at 11 45 18 AM

@benjamink
Copy link
Contributor

benjamink commented Oct 1, 2024

Tested the Disk-II write with the latest commit to this PR & it works as expected.

My system: Apple //e Enhanced w/ Lolin D32 Pro FujiNet

Just in case it helps someone else here's my instructions. MAKE SURE HELLO.DSK IS STORED ON HOST THAT IS WRITABLE:

  1. Boot into stock CONFIG
  2. Mount DIST.PO (attached to 1st comment here) to SmartPort Disk 1
  3. Reboot to the new CONFIG (on DIST.PO)
  4. Eject DIST.PO from SmartPort Disk 1
  5. Mount HELLO.DSK to DISK-II Disk 1
  6. Press ESC to get back to main CONFIG
  7. Press Tab & move down to the HELLO.DSK in Disk-II Disk 1
  8. Press W to make the mounted disk writable
  9. Press ESC to reboot the HELLO.DSK (boots to a ] prompt - BASIC)
  10. Type NEW to clear the default BASIC program
  11. Enter a new program:
 10 PRINT "HELLO"
 20 GOTO 10

12 Type SAVE TEST
13. Type NEW to clear the program
14. Type LIST to confirm no program is loaded
15. Type LOAD TEST
16. Type LIST to confirm program is loaded from disk

If all that works then this PR is working

@benjamink
Copy link
Contributor

Tested on the IIgs with both the Lolin D32 Pro variant as well as an official Rev000 dev unit. Both worked as expected for this PR 👍
image

@tschak909
Copy link
Collaborator

Thank you, Chris. I think this is good. I think we've shaken this thing as much as we can.

Thank you for your patience.
-The FujiNet Team

@tschak909 tschak909 merged commit db82a5d into FujiNetWIFI:master Oct 3, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants