• Re: Question concerning Disk II emulation / timing

    From Michael AppleWin Debugger Dev@michael.pohoreski@gmail.com to comp.emulators.apple2 on Sat Mar 25 06:44:01 2023
    From Newsgroup: comp.emulators.apple2

    On Friday, March 24, 2023 at 3:21:51rC>PM UTC-7, Jens Gaulke wrote:
    I tried to do Disk II emulation and implemented all softswitches and the functions as far as I understood them from Jim Sather. The only disk image start starts for me is "Apple Galaxian". A standard DOS 3.3 System Master reads some tracks and then crashes with an illegal opcode. What am I missing?
    Many nights of poring over boot traces. /s
    Seriously, the "secret sauce" is nothing more then hard work of logging to tell where things are going off the rails.
    i.e.
    When you boot DOS 3.3, what are the PC & regs when it crashes? What stage of DOS doe the PC reach? Stage 0? Stage 1? Stage 2?
    Do I have some timing problems in my emulation? Did I not correctly implement the softswitch functions?
    The easiest way to debug this would probably be to use a process of elimination as you verify the softswitches one-one by one.
    0. Write a small test program to select drive 0, wait, select drive 1, wait to rule our DRVSEL_1 and DRVSEL_2. Yes, this is trivial. Yes, you need to eliminate this.
    1. I would then rule out the MOTORON, MOTOROFF. Yes this is again trivial, and yes you need to eliminate this.
    2 I would test the four PHASE0..PHASE3 softswitches by writing a small assembly program to move the track outwards 40 tracks and then inwards 40 tracks logging the track number. That leaves four softswitches to test SHIFT, LOAD, READ, WRITE. You don't need to worry about WRITE for now, so this leaves SHIFT, LOAD, and READ.
    3. Prepare a "raw disk" so that each of 35 tracks contains nothing but FF filler and only ONE disk nibble of an unique track marker. Modify the utility from step (1) to read the raw 4&4 disk nibble, and step the 35 tracks. This SO question may be helpful as Nick was kind enough to provide some nibble counting code:
    https://retrocomputing.stackexchange.com/questions/503/absolute-maximum-number-of-nibbles-on-an-apple-ii-floppy-disk-track/664#664
    4. Get .do/.dsk working first before .woz. I don't see your 6&2 decode logic? Have you verified this is correct?
    5. You may want to use a "simpler" program to trace. I'm extremely biased so something like Fantavision since I have already written up the boot-tracing :-) but any program/game where you already have boot-tracing notes (say from 4AM) would work.
    https://github.com/Michaelangel007/apple2_fantavision_reloaded#ye-olde-boot-tracing
    6. I already mentioned the DOS 3.3 System Master above.
    7. Use another emulator to debug your emulator. i.e In AppleWin see the disk logging defines, LOG_DISK_PHASES, LOG_DISK_NIBBLES_SPIN, LOG_DISK_NIBBLES_READ, etc. in source/Disk.cpp.
    There are also some interesting comments in DataLatchReadWriteWOZ().
    I attached my code (I hope the formatting will not be corrupted)
    Unfortunately, Python uses the retarded decision of using whitespace for code blocks which sadly means indentation will usually be completely lost due to HTML defaulting to sequences of white space being collapsed. Do you have a git repository where it is easier to read that python code?
    Pro-Tip: (Almost) no one wants to read a dump of code, but we can give you pointers if you share more details of what you have tried and where exactly things have stopped working.
    Good luck! Keep us posted as you trace through the issue.
    Michael
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Jens Gaulke@jegali70@gmail.com to comp.emulators.apple2 on Wed Mar 29 08:09:48 2023
    From Newsgroup: comp.emulators.apple2

    On Saturday, March 25, 2023 at 2:44:03rC>PM UTC+1, Michael AppleWin Debugger Dev wrote:
    On Friday, March 24, 2023 at 3:21:51rC>PM UTC-7, Jens Gaulke wrote:
    I tried to do Disk II emulation and implemented all softswitches and the functions as far as I understood them from Jim Sather. The only disk image start starts for me is "Apple Galaxian". A standard DOS 3.3 System Master reads some tracks and then crashes with an illegal opcode. What am I missing?
    Many nights of poring over boot traces. /s

    Seriously, the "secret sauce" is nothing more then hard work of logging to tell where things are going off the rails.
    i.e.
    When you boot DOS 3.3, what are the PC & regs when it crashes? What stage of DOS doe the PC reach? Stage 0? Stage 1? Stage 2?
    Do I have some timing problems in my emulation? Did I not correctly implement the softswitch functions?
    The easiest way to debug this would probably be to use a process of elimination as you verify the softswitches one-one by one.

    0. Write a small test program to select drive 0, wait, select drive 1, wait to rule our DRVSEL_1 and DRVSEL_2. Yes, this is trivial. Yes, you need to eliminate this.

    1. I would then rule out the MOTORON, MOTOROFF. Yes this is again trivial, and yes you need to eliminate this.

    2 I would test the four PHASE0..PHASE3 softswitches by writing a small assembly program to move the track outwards 40 tracks and then inwards 40 tracks logging the track number. That leaves four softswitches to test SHIFT, LOAD, READ, WRITE. You don't need to worry about WRITE for now, so this leaves SHIFT, LOAD, and READ.

    3. Prepare a "raw disk" so that each of 35 tracks contains nothing but FF filler and only ONE disk nibble of an unique track marker. Modify the utility from step (1) to read the raw 4&4 disk nibble, and step the 35 tracks. This SO question may be helpful as Nick was kind enough to provide some nibble counting code:
    https://retrocomputing.stackexchange.com/questions/503/absolute-maximum-number-of-nibbles-on-an-apple-ii-floppy-disk-track/664#664

    4. Get .do/.dsk working first before .woz. I don't see your 6&2 decode logic? Have you verified this is correct?

    5. You may want to use a "simpler" program to trace. I'm extremely biased so something like Fantavision since I have already written up the boot-tracing :-) but any program/game where you already have boot-tracing notes (say from 4AM) would work.
    https://github.com/Michaelangel007/apple2_fantavision_reloaded#ye-olde-boot-tracing

    6. I already mentioned the DOS 3.3 System Master above.

    7. Use another emulator to debug your emulator. i.e In AppleWin see the disk logging defines, LOG_DISK_PHASES, LOG_DISK_NIBBLES_SPIN, LOG_DISK_NIBBLES_READ, etc. in source/Disk.cpp.

    There are also some interesting comments in DataLatchReadWriteWOZ().
    I attached my code (I hope the formatting will not be corrupted)
    Unfortunately, Python uses the retarded decision of using whitespace for code blocks which sadly means indentation will usually be completely lost due to HTML defaulting to sequences of white space being collapsed. Do you have a git repository where it is easier to read that python code?

    Pro-Tip: (Almost) no one wants to read a dump of code, but we can give you pointers if you share more details of what you have tried and where exactly things have stopped working.

    Good luck! Keep us posted as you trace through the issue.

    Michael
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Jens Gaulke@jegali70@gmail.com to comp.emulators.apple2 on Wed Mar 29 08:15:16 2023
    From Newsgroup: comp.emulators.apple2

    On Saturday, March 25, 2023 at 2:44:03rC>PM UTC+1, Michael AppleWin Debugger Dev wrote:
    On Friday, March 24, 2023 at 3:21:51rC>PM UTC-7, Jens Gaulke wrote:
    I tried to do Disk II emulation and implemented all softswitches and the functions as far as I understood them from Jim Sather. The only disk image start starts for me is "Apple Galaxian". A standard DOS 3.3 System Master reads some tracks and then crashes with an illegal opcode. What am I missing?
    Many nights of poring over boot traces. /s

    Seriously, the "secret sauce" is nothing more then hard work of logging to tell where things are going off the rails.
    i.e.
    When you boot DOS 3.3, what are the PC & regs when it crashes? What stage of DOS doe the PC reach? Stage 0? Stage 1? Stage 2?
    Do I have some timing problems in my emulation? Did I not correctly implement the softswitch functions?
    The easiest way to debug this would probably be to use a process of elimination as you verify the softswitches one-one by one.

    0. Write a small test program to select drive 0, wait, select drive 1, wait to rule our DRVSEL_1 and DRVSEL_2. Yes, this is trivial. Yes, you need to eliminate this.

    1. I would then rule out the MOTORON, MOTOROFF. Yes this is again trivial, and yes you need to eliminate this.

    2 I would test the four PHASE0..PHASE3 softswitches by writing a small assembly program to move the track outwards 40 tracks and then inwards 40 tracks logging the track number. That leaves four softswitches to test SHIFT, LOAD, READ, WRITE. You don't need to worry about WRITE for now, so this leaves SHIFT, LOAD, and READ.

    3. Prepare a "raw disk" so that each of 35 tracks contains nothing but FF filler and only ONE disk nibble of an unique track marker. Modify the utility from step (1) to read the raw 4&4 disk nibble, and step the 35 tracks. This SO question may be helpful as Nick was kind enough to provide some nibble counting code:
    https://retrocomputing.stackexchange.com/questions/503/absolute-maximum-number-of-nibbles-on-an-apple-ii-floppy-disk-track/664#664

    4. Get .do/.dsk working first before .woz. I don't see your 6&2 decode logic? Have you verified this is correct?

    5. You may want to use a "simpler" program to trace. I'm extremely biased so something like Fantavision since I have already written up the boot-tracing :-) but any program/game where you already have boot-tracing notes (say from 4AM) would work.
    https://github.com/Michaelangel007/apple2_fantavision_reloaded#ye-olde-boot-tracing

    6. I already mentioned the DOS 3.3 System Master above.

    7. Use another emulator to debug your emulator. i.e In AppleWin see the disk logging defines, LOG_DISK_PHASES, LOG_DISK_NIBBLES_SPIN, LOG_DISK_NIBBLES_READ, etc. in source/Disk.cpp.

    There are also some interesting comments in DataLatchReadWriteWOZ().
    I attached my code (I hope the formatting will not be corrupted)
    Unfortunately, Python uses the retarded decision of using whitespace for code blocks which sadly means indentation will usually be completely lost due to HTML defaulting to sequences of white space being collapsed. Do you have a git repository where it is easier to read that python code?

    Pro-Tip: (Almost) no one wants to read a dump of code, but we can give you pointers if you share more details of what you have tried and where exactly things have stopped working.

    Good luck! Keep us posted as you trace through the issue.

    Michael
    Hi all,
    I found a very stupid error. To do some testing, I had implemented a Routine for changing values in the ROM.
    The call to this Routine was still active, and so while booting up DOS, DOS tried to access ROM addresses and changed contents of the ROM. This caused the illegal Instruction I talked about. I disabled the writing to the ROM and the dsk booted up. So I learned, that DOS tries to access the 16k RAM Card.
    On top of that I remembered that french_postcards needed a RAM expansion to boot up properly and I implemented the 16k language Card. The 16k are working well and some dsk are booting up properly.
    At the moment , I try to unify the woz and dsk routines to make handling easier.
    There are just two things that bother me. Booting up karateka does not switch to graphics mode correctly though I Implemented all the softswitches and they work correctly When testing via AppleSoft. Second topic: booting a Disk is slooooow. I have no idea how to Speed that up at the Moment.
    That's how it is going at the moment. Thank you all for your support!
    Cheers, Jens
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From D Finnigan@dog_cow@macgui.com to comp.emulators.apple2 on Wed Mar 29 20:11:29 2023
    From Newsgroup: comp.emulators.apple2

    Jens Gaulke wrote:

    To do some testing, I had implemented a
    Routine for changing values in the ROM.
    The call to this Routine was still active, and so while booting up DOS,
    DOS
    tried to access ROM addresses and changed contents of the ROM. This caused the illegal Instruction I talked about.

    Back in the old days, Apple Computer used to always guarantee that the
    contents of ROM would never change during execution of your program.
    Probably this is the reason why.

    ;-)
    --
    ]DF$
    The New Apple II User's Guide:
    https://macgui.com/newa2guide/

    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Michael AppleWin Debugger Dev@michael.pohoreski@gmail.com to comp.emulators.apple2 on Thu Mar 30 11:25:57 2023
    From Newsgroup: comp.emulators.apple2

    On Wednesday, March 29, 2023 at 8:15:18rC>AM UTC-7, Jens Gaulke wrote:
    I found a very stupid error. To do some testing, I had implemented a Routine for changing values in the ROM.
    The call to this Routine was still active, and so while booting up DOS, DOS tried to access ROM addresses and changed contents of the ROM. This caused the illegal Instruction I talked about. I disabled the writing to the ROM and the dsk booted up. So I learned, that DOS tries to access the 16k RAM Card.
    Yes, sadly DOS 3.3 rudely futzes with the language card at 3FCB:
    3FCB:AD 81 C0 022 LDA $C081 ; magic number If only ROMIN = $C081 for Language Card (LC)
    3FCE:AD 81 C0 023 LDA $C081 ; magic number 1st read = read ROM, 2nd read = write enable LC Bank 2
    3FD1:A9 00 024 LDA #0
    3FD3:8D 00 E0 025 STA $E000
    On top of that I remembered that french_postcards needed a RAM expansion to boot up properly and I implemented the 16k language Card. The 16k are working well and some dsk are booting up properly.
    Awesome to hear!
    There are just two things that bother me. Booting up karateka does not switch to graphics mode correctly though I Implemented all the softswitches and they work correctly
    Hmm, I just took a quick look at the Karateka and it is hitting these softswitches (low byte stored $1020 .. $1028):
    1000:A0 00 LDY #$00
    1015:BC 20 10 LDY $1020,X
    1018:99 00 C0 STA KEYBOARD,Y
    101B:F0 0D BEQ $102A
    101D:E8 INX
    101E:D0 F5 BNE $1015
    1020:5F B_1020 db #$5F
    1021:57 B_1021 db #$57
    1022:52 B_1022 db #$52
    1023:54 B_1023 db #$54
    1024:50 B_1024 db #$50
    1025:0C B_1025 db #$0C
    1026:08 B_1026 db #$08
    1027:04 B_1027 db #$04
    1028:02 B_1028 db #$02
    1029:00 B_1029 db #$00
    102A:A6 2B LDX BAS2H
    i.e.
    C05F
    C057
    C052
    C054
    C050
    C00C
    C008
    C004
    C002
    Might be a place to start?
    When testing via AppleSoft. Second topic: booting a Disk is slooooow. I have no idea how to Speed that up at the Moment.
    In AppleWin check the variable: bool m_enhanceDisk
    It looks like we omit the spinning up time in Disk2InterfaceCard::ReadWrite(): i.e.
    if (!m_enhanceDisk && pDrive->m_spinning)
    That's how it is going at the moment. Thank you all for your support!
    Thanks for the update!
    Michael
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From peter....@gmail.com@peter.ferrie@gmail.com to comp.emulators.apple2 on Sat Apr 1 12:37:09 2023
    From Newsgroup: comp.emulators.apple2

    DOS turns off the drive on exit, and skips spin-up if the parameters are the same on the next call and the disk appears to be still spinning. Maybe that's causing the read failure?
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From I am Rob@gids.rs@sasktel.net to comp.emulators.apple2 on Sun Apr 2 17:29:25 2023
    From Newsgroup: comp.emulators.apple2

    There are just two things that bother me. Booting up karateka does not switch to graphics mode correctly though I Implemented all the softswitches and they work correctly When testing via AppleSoft. Second topic:

    Might be the order in which the soft switches are accessed. Sweet16 has the same problem. $C050 has to be accessed before any other softswitch.



    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Steve Nickolas@usotsuki@buric.co to comp.emulators.apple2 on Mon Apr 3 00:41:23 2023
    From Newsgroup: comp.emulators.apple2

    On Sun, 2 Apr 2023, I am Rob wrote:

    There are just two things that bother me. Booting up karateka does not
    switch to graphics mode correctly though I Implemented all the
    softswitches and they work correctly When testing via AppleSoft. Second
    topic:

    Might be the order in which the soft switches are accessed. Sweet16 has
    the same problem. $C050 has to be accessed before any other softswitch.

    For what it's worth, I frequently hit them from the bottom up, C057, C054, C052, C050.

    I just looked at one of my file cracks: it says that it relies on the
    firmware to hit C052 and C054 (in no defined order, but fwiw, it's the FE84-FE89-FE93-FB2F dance you see some variation of in a lot of software)
    and then it hits C057, and only some time later hits C050.

    So you're going to need to be prepared for the softswitches to be hit in
    any arbitrary order.

    -uso.
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Jens Gaulke@jegali70@gmail.com to comp.emulators.apple2 on Mon Apr 3 13:23:55 2023
    From Newsgroup: comp.emulators.apple2

    Hi all,
    the errors in the graphical representation were due to the fact that I overestimated the performance of Python. I refreshed the screen completely every 20 ms, as I know it from game programming. The setting of all pixels including the calculation of the color values blew up these 20ms. I now use a surfarray3d and set the respective pixel when it is set in RAM. Then I flash every 20ms the content of the surfarray3d on the screen. for this I use a surfarray3d for hires1 and one for hires2. Depending on the softswitch I flash the corresponding surfarray3d. This works surprisingly well. What I don't like so much is that my object-oriented structure has suffered a bit.
    That sometimes softswitches are set wildly and I have to take this into account in the graphics output, I have noticed in the meantime. I try to map this behavior by my new graphics routines.
    Now that Karateka runs graphically, I took care of the joystick implementation. In most cases this works as well.
    Actually I just wanted to resurrect my old Apple II, but here one more function and there one more function... that's really fun.
    Thank you all for your input and the exchange, I really appreciate that!
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Jens Gaulke@jegali70@gmail.com to comp.emulators.apple2 on Mon Apr 3 13:31:21 2023
    From Newsgroup: comp.emulators.apple2

    I also got the speed problem with the floppy drive under control.
    first i restructured the gameloop and then realized that i was providing each sector "on demand" in the DSK routine. but since some sectors are read multiple times, i was wasting clock cycles here. I then converted the DSK file completely, stored it in an array and access the array on demand.
    Stupid me
    --- Synchronet 3.21b-Linux NewsLink 1.2