Jump to content
IGNORED

[Testing] Altirra v3.40 softkick OS for UNOCart/A8PicoCart ATR loading


Wrathchild

Recommended Posts

I have produced a patch Altirra OS version that provides the PIO patch utilized by the UNO & A8Pico carts for the loading of ATR images.

After @electrotrains's recommendation to put this out for testing before it replaces the OS provided in the firmware by default.

 

The default soft-OS can be overridden by placing the attached 16K file (UNO_OS.ROM) into the root of the UNO's SD-Card or the A8-PICOCART share and so a firmware update is not necessary.

 

Due to the nature of a soft-OS, titles on the XL/XE needing 64K (using the memory under the OS) won't work and there will be certain titles that might inadvertently enable the stock-OS, losing the sector-read redirect and so likely to crash. 

 

UNO_OS.ROM

  • Like 5
Link to comment
Share on other sites

I tried it on my a8picocart and I have the same problems with the games and programs that I said in the main thread. 😅

 

in short the ones that don't work:

  • TurboBasicXL.atr (extended density) is half loaded.
  • VisiCalc.atr (simple density) loads, but the program crashes.
  • SpartaDOS_3.2g_with_DOS.atr (single density) does not load.
  • SpartaDOS_3.2g_720K.atr (double density) does not load.
  • Arcadia.atr (single density) loads, but the program crashes.
Link to comment
Share on other sites

Arcadia I'd already fixed as it was one of the things that drew me to getting involved.

It is the fault of the loading mechanism the game uses.

This involves loading blocks and then moving them elsewhere in memory.

This is handled around the code at $2041.
 

    2041: AD 01 D3          LDA PORTB
    2044: A8                TAY
    2045: 29 01             AND #$01
    2047: F0 17             BEQ $2060
    2049: 8C 6C 20          STY $206C
    204C: A9 EA             LDA #$EA
    204E: 8D 65 20          STA $2065
    2051: AD 0B D4          LDA VCOUNT
    2054: D0 FB             BNE $2051
    2056: 78                SEI
    2057: EE 0E D4          INC NMIEN
    205A: A9 FE             LDA #$FE
    205C: 8D 01 D3          STA PORTB
    205F: 60                RTS
;--------------------------------------------------
    2060: A9 60             LDA #$60
    2062: 8D 65 20          STA $2065
    2065: EA                NOP
    2066: AD 0B D4          LDA VCOUNT
    2069: D0 FB             BNE $2066
    206B: A9 FF             LDA #$FF
    206D: 8D 01 D3          STA PORTB
    2070: CE 0E D4          DEC NMIEN
    2073: 58                CLI
    2074: 60                RTS

 

Blocks are loaded at $2075 that call this to setup (switch out OS) and then copy ($2000) and then continue (switch in OS).

 

    2075: 20 41 20          JSR $2041              ;[expand]
    2078: A9 96             LDA #$96
    207A: 85 88             STA $88
    207C: A9 20             LDA #$20
    207E: 85 89             STA $89
    2080: A9 00             LDA #$00
    2082: 85 8C             STA $8C
    2084: A9 93             LDA #$93
    2086: 85 8D             STA $8D
    2088: A9 6F             LDA #$6F
    208A: 85 84             STA $84
    208C: A9 00             LDA #$00
    208E: 85 85             STA $85
    2090: 20 00 20          JSR $2000              ;[expand]
    2093: 4C 65 20          JMP $2065              ;[expand]

 

So, the $2041 routine detects a soft-OS and so turns $2065 to an RTS rather than a NOP, hence both calls do nothing.

 

However, when a hard-OS is present the INC, DEC "trick" is potentially dangerous.

The initial state from the OS boot is $40, i.e. VBI only.
leaves the NMI with DLI enabled which works because the default display list doesn't ask for any.

 

(9172:  0,  7) A=00 X=10 Y=FF S=F3 P=33 (    ZC)  2056: 78                SEI
Altirra> .antic
NMIEN  = 40  : vbi
(9172:  0, 13) A=00 X=10 Y=FF S=F3 P=37 (   IZC)  2057: EE 0E D4          INC NMIEN    [$D40E]
Altirra> .antic
NMIEN  = C0  : dli vbi

 

And oddly the loading works with two INCs followed by two DECs so the sequence is $C0, $00 (disabled), do copy, $00, $C0.

(additional note: the game doesn't use memory under the OS and so the above mechanism is redundant)

 

So the upshot is that when the game launches, DLIs are enabled.

When using the soft-OS, none of the NMI manipulation is done so is left as $40 as per the OS setting it.
Fortunately the game code isn't launched until the final block is done.
So to fix this was to insert a segment block to load $C0 to NMIEN.
The patched AUTORUN.SYS was updated in the attached ATR.


So not sure if this is the authors code or from the (Pascal?) framework.

arcadia.atr

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Oh, one thing I forgot to mention.

 

For this OS I have defaulted the OS to not load basic by default and so you do not need to hold-down OPTION when you boot an ATR.

So therefore if the ATR does require basic enabled then hold down option to boot with BASIC.

Edited by Wrathchild
  • Like 2
Link to comment
Share on other sites

TURBO BASIC XL

 

During its startup this is doing some stuff to copy hard-OS to soft-OS and then makes assumptions about the locations of routines and so really messes up the already loaded Altirra soft-OS.

 

    6000: AE 24 E4          LDX $E424
    6003: AC 25 E4          LDY $E425
    6006: E8                INX
    6007: D0 01             BNE $600A
    6009: C8                INY
    600A: 8E F8 24          STX $24F8
    600D: 8C F9 24          STY $24F9
    6010: A9 00             LDA #$00
    6012: 8D 0E D4          STA NMIEN
    6015: 78                SEI
    6016: A9 FE             LDA #$FE
    6018: 8D 01 D3          STA PORTB
    601B: A9 AB             LDA #$AB
    601D: 8D FA FF          STA $FFFA
    6020: A9 24             LDA #$24
    6022: 8D FB FF          STA $FFFB
    6025: A9 D0             LDA #$D0
    6027: 8D FE FF          STA $FFFE
    602A: A9 24             LDA #$24
    602C: 8D FF FF          STA $FFFF
    602F: A9 CC             LDA #$CC
    6031: 20 DB 60          JSR $60DB              ;[expand]
    6034: A9 E0             LDA #$E0
    6036: 20 DB 60          JSR $60DB              ;[expand]
    6039: A9 40             LDA #$40
    603B: 8D 0E D4          STA NMIEN
    603E: 58                CLI
    603F: A9 FF             LDA #$FF
    6041: 8D 01 D3          STA PORTB
    6044: 20 01 61          JSR $6101              ;[expand]
    6047: A9 00             LDA #$00
    6049: 85 09             STA $09
    604B: A5 0C             LDA DOSINI
    604D: A4 0D             LDY DOSINI+1
    604F: 8D 8E 20          STA $208E
    6052: 8C 8F 20          STY $208F
    6055: A9 80             LDA #$80
    6057: A0 20             LDY #$20
    6059: 85 0C             STA DOSINI
    605B: 84 0D             STY DOSINI+1
    605D: A9 FE             LDA #$FE
    605F: 8D 01 D3          STA PORTB
    6062: 85 CA             STA $CA
    6064: A2 01             LDX #$01
    6066: 8E F8 03          STX BASICF
    6069: 86 09             STX $09
    606B: CA                DEX
    606C: 8E 44 02          STX COLDST
    606F: 20 04 E6          JSR $E604              ;[expand]
    6072: A9 00             LDA #$00
    6074: 85 A0             STA $A0
    6076: 85 A1             STA $A1
    6078: 20 5F C9          JSR $C95F              ;[expand]
    607B: A0 1F             LDY #$1F
    607D: A2 8A             LDX #$8A
    607F: 20 86 25          JSR $2586              ;[expand]
    6082: A0 1E             LDY #$1E
    6084: B9 A7 60          LDA $60A7,Y
    6087: 91 97             STA ($97),Y
    6089: 88                DEY
    608A: 10 F8             BPL $6084
    608C: 20 C5 C9          JSR $C9C5              ;[expand]
    608F: A9 FF             LDA #$FF
    6091: 48                PHA
    6092: A9 AE             LDA #$AE
    6094: 48                PHA
    6095: 20 C6 60          JSR $60C6              ;[expand]
    6098: CE 01 D3          DEC PORTB
    609B: A9 00             LDA #$00
    609D: A8                TAY
    609E: 99 00 B0          STA $B000,Y
    60A1: 88                DEY
    60A2: 10 FA             BPL $609E
    60A4: 4C 3A F5          JMP $F53A              ;[expand]

 

If that is the only area it maybe possible to patch, or even build a compatible version from sources?

  

  • Thanks 1
Link to comment
Share on other sites

OK, so having looked at dmsc's TB-XL sources, on top of moving old-OS parts into soft-OS the TB-XL code is also loaded under the OS, so "titles on the XL/XE needing 64K (using the memory under the OS) won't work" holds here.

 

So for now go with the cart version which runs with your hard-OS although for now the language cart's are practical if only saving to existing devices as they can't use the UNO/A8Pico storage.

 

Something like an 'H:' handler could be employed to map to a folder on the UNO/A8Pico set before launching the cartridge but that's future work.

tbasic_sxegs.rom

  • Thanks 1
Link to comment
Share on other sites

VISICALC


The code uses a direct jump into the OS which of course messes up when using the Altirra OS.

This occurs at $1CAB, calling $E959 which is actually the SIOV jumped to when calling $E459.

So changing the byte at offset $16F0 from $E9 to $E4 (in the ATX crack attached) permits this to load under Altirra OS.

 

Further testing maybe needed to make sure no other direct calls are made though.

 

    1C7E: A9 50             LDA #$50
    1C80: 8D 00 03          STA DDEVIC
    1C83: A9 01             LDA #$01
    1C85: 8D 01 03          STA DUNIT
    1C88: A9 21             LDA #$21
    1C8A: 8D 02 03          STA DCOMND
    1C8D: A9 40             LDA #$40
    1C8F: 8D 03 03          STA DSTATS
    1C92: A9 14             LDA #$14
    1C94: 8D 06 03          STA DTIMLO
    1C97: A9 00             LDA #$00
    1C99: 8D 04 03          STA DBUFLO
    1C9C: A9 05             LDA #$05
    1C9E: 8D 05 03          STA DBUFHI
    1CA1: A9 01             LDA #$01
    1CA3: 8D 09 03          STA DBYTHI
    1CA6: A9 59             LDA #$59
    1CA8: 8D 08 03          STA DBYTLO
    1CAB: 20 59 E9          JSR $E959              ;[expand]
    1CAE: 30 10             BMI $1CC0
    1CB0: A5 08             LDA WARMST
    1CB2: 48                PHA
    1CB3: A9 00             LDA #$00
    1CB5: 85 08             STA WARMST
    1CB7: 20 06 05          JSR $0506              ;[expand]
    1CBA: 20 C1 1C          JSR $1CC1              ;[expand]
    1CBD: 68                PLA
    1CBE: 85 08             STA WARMST
    1CC0: 60                RTS

 

VisiCalc v1.74a (1980)(VisiCorp)(US)[!].atr

  • Thanks 1
Link to comment
Share on other sites

first of all thank you very much @Wrathchild for the explanation and the detail. i thought it would be something simpler to fix without patching the original programs. but as you say it corrupts the altirra OS.

 

I will try your atr later as I am still at work. Thinking what happens if you use the Altirra OS as a diagnostic cartridge from what I understand it disables the OS but I don't know if you can use that memory area.

 

8 hours ago, Wrathchild said:

For this OS I have defaulted the OS to not load basic by default and so you do not need to hold-down OPTION when you boot an ATR.

So therefore if the ATR does require basic enabled then hold down option to boot with BASIC.

I was thinking of doing it from the menu to activate or deactivate basic, but you already did it. 😅

 

About the TBXL or Basic, I thought it could be read directly like the other files. although what you say about the H: drive would be interesting so you could use many programming language cartridges or programs that can record their data directly into the cart without going through an ATR.

Link to comment
Share on other sites

Hi!

15 hours ago, Wrathchild said:

OK, so having looked at dmsc's TB-XL sources, on top of moving old-OS parts into soft-OS the TB-XL code is also loaded under the OS, so "titles on the XL/XE needing 64K (using the memory under the OS) won't work" holds here.

 

So for now go with the cart version which runs with your hard-OS although for now the language cart's are practical if only saving to existing devices as they can't use the UNO/A8Pico storage.

 

Something like an 'H:' handler could be employed to map to a folder on the UNO/A8Pico set before launching the cartridge but that's future work.

tbasic_sxegs.rom 64 kB · 5 downloads

 

As TB-XL really needs a DOS, won't be easier to simply load a DOS supporting the UNO/A8Pico SIO emulation?

 

The attached proof of concept image is an 1MB ATR with BW-DOS (my current devel version) that loads an untested driver for the A8PICO, allowing to read/write from the mounted ATR image. The ATR also includes TurboBasic XL. The MADS sources of the driver (that should work in BW-DOS and SpartaDOS 2 and 3) is attached here: a8pico.src

 

How can I test this in an emulator?

 

Have Fun!

 

bwdos-a8pico.zip

print1.inc print.inc

Edited by dmsc
Added the missing include files for the a8pico.src assembly.
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

5 hours ago, dmsc said:

How can I test this in an emulator?

You can't currently

5 hours ago, dmsc said:

As TB-XL really needs a DOS, won't be easier to simply load a DOS supporting the UNO/A8Pico SIO emulation?

The image used already has a DOS? (from https://atariwiki.org/wiki/Wiki.jsp?page=Turbo-BASIC XL#section-Turbo-BASIC+XL-ATRImages)

The issue was that the TB (autorun.sys) was transferring itself under the OS, trashing the Altirra soft-OS used to load the ATR in the first place.
image.png.405646a55f09f48e7f8aa2b9cbce944a.png

 

QUICK 101 on UNO/A8Pico (from hereon referred to as Pico) Boot & ATR handling...

 

The Pico boots into a mode where the Pico ROM (responsible for the menuing) is emulated (i.e. Pico responds to S5 reads) and the Pico also provides a mechanism via the $D5xx bus for exchanging directory information from the sd/flash drive.

 

So the cart code displays the menu and permits the navigation, submission of searches etc and ultimately the selection of a file.

 

The extension of the file determines the next action:

 

XEX - installs an XEX loader code at $700 and transfer control to that (discarding the menu cart) and swapping to a $D5xx bus-sniffer that feeds the XEX from the chosen file through small chunks supplied in the cat-bus window.

CAR/ROM - loads the selected image into memory (using the header to identify the type & expected size, or using the stock mappers for the ROM extension, e.g. 8K/16K or XEGS for 32K/64K or 128K).
                 Pico execution therefore swaps to a dedicated $D5xx bus-sniffer to handle the (if any) banking model and exposure of memory from the cart image to the S5/S4 areas.

ATR - installs an soft-OS swap routine that uses memory under the OS to provide an alternative OS with a patch to intercept D1 requests to read/write sectors within the selected ATR file on the Pico's drive.

         The menu code issues commands to the Pico to LOAD_SOFT_OS, which first reads the UNO_OS.ROM file (if present) or uses the in-built image.

         It then get this data via SOFT_OS_CHUNK requests 128 bytes at a time through the $D5xx cart-bus to transfer that into memory under the OS.

         The ATR support begins by the Pico mounting the from the sd/flash drive, so permitting the r/w access. The header is read and kept and initially exposed at $D502.

         Once the soft-OS is in place the Atari is rebooted. As the Atari tries to boot from D1 the SIO calls are intercepted and Status & Sector read/writes requested from the cart-bus.
         Pico execution has swapped to a dedicated $D5xx bus-sniffer to handle those 3 ATR command requests.

 

 

So, regarding the "untested driver for the A8PICO, allowing to read/write from the mounted ATR image" the soft-OS is already providing this via the intercept for D1.

So to swap back to using a hard-OS would require the driver to use drive 1 and so you might have a chicken and egg situation as to where you swap over?

 

The concept for the driver as I saw it was more-akin to the function provided by Altirra's H: device to a folder on the Pico storage selected alongside the ATR booted. 

Link to comment
Share on other sites

Hi!

9 hours ago, Wrathchild said:

You can't currently

So, I will need to build an A8PICO to test myself 🙂 .... debugging on emulators is so much easier.

 

9 hours ago, Wrathchild said:

The image used already has a DOS? (from https://atariwiki.org/wiki/Wiki.jsp?page=Turbo-BASIC XL#section-Turbo-BASIC+XL-ATRImages)

The issue was that the TB (autorun.sys) was transferring itself under the OS, trashing the Altirra soft-OS used to load the ATR in the first place.

Yes, I understand. So, the ATR that I posted should work, the procedure is:

- Boot with the ATR using A8PICO, it will use the replacement RAM OS and load the driver as "D8".

- You can test A8PICO driver by accessing D8:, for example "DIR D8:" should give the directory.

- Now type " A8PICO 1 " to replace the standard SIO D1 with the D1 through the A8PICO driver.

- Type " TB " to load TurboBasic, after initial loading, it will swap the ROM OS back on, and continue from there.

 

This will work given that the Altirra based OS replacement is "mostly compatible" at the RAM level with the original ROM, I think this is ok.

 

You can now LOAD and SAVE to "D1:" using the driver, so it will behave in the correct way.

 

9 hours ago, Wrathchild said:

So, regarding the "untested driver for the A8PICO, allowing to read/write from the mounted ATR image" the soft-OS is already providing this via the intercept for D1.

So to swap back to using a hard-OS would require the driver to use drive 1 and so you might have a chicken and egg situation as to where you swap over?

As explained, it can be swapped on A8PICO driver load (you can edit the STARTUP.BAT file and change from 8 to 1)

 

Have Fun!

Link to comment
Share on other sites

Hi!

5 hours ago, Wrathchild said:

Have tried the disk image on real h/w and although it begins to process TB it hangs on the brown title screen and doesn't progress to the "Ready" prompt. (so steps 1-3 above are OK but not the 2nd half of 4)

That is great, thank you for testing!!

 

It means that the A8PICO driver actually works (at least for read operations), but when swapping the Altirra OS with the original ROM, it hangs. This is because the interrupt handlers have different initialization values, so at the first IRQ or NMI the kernel hangs. To solve this, we need to perform a warm-start after swapping the kernel.

 

Attached is a new image, with a new program "ROM.COM" that performs the swap, you need to boot the image and answer "Y" to both, load the A8PICO driver and swap the ROM kernel in. After this, the computer resets and you can type "TB" to load tb-xl.

 

Please, if @ascrnet or you can test this, I hope this time will work 🙂 , and I can include the A8PICO driver in my BW-DOS branch.

 

Have Fun!

bwdos-a8pico-v2.zip

Edited by dmsc
Really attach file now
Link to comment
Share on other sites

Hi!

12 hours ago, Wrathchild said:

sadly no, upon saying "y" to the ROM swap, the normal blue screen is shown but blank with an "!" about a quarter of the way on bottom line.

Oh, bummer. I tried it in atari800 emulator using your Altirra OS "softkick" sources, and it worked.

 

So, I added minimal support of A8PicoCart to Atari800 emulator, and found the problem - the included OS replacement rewrites DOSINI during the VBI, this means that you can't install loadable drivers into any DOS, as those depend on chaining the DOSINI on reboot.

 

I think that disabling this DOSINI rewriting is the best course of action, as it is not really needed for most of the use case of the softkick OS.

 

Attached is my patch to current atari800 git. I used the ROM from the headers from your A8PicoCart sources.

 

Have Fun!

atari800-a8pico.patch.gz

Edited by dmsc
Link to comment
Share on other sites

Thanks @dmsc, this DOSINI chaining is an area I've parked as awaiting some info on its history as I felt it could be a workaround to something potentially fixable in the ATR loader.

 

NOPing out the call in the rom image permits the ATR to cold-start the stock-OS.

 

[Edit] have tried a few ATRs out with the rom in this post and these still work fine.

UNO_OS.ROM

Edited by Wrathchild
  • Like 1
Link to comment
Share on other sites

Fun times. I think a combined cart handler and atr sector handler should be possible for certain cart models, e.g. pick a cart first and launch with Select which doesn't launch but then when you launch an ATR will emulate the cart too. However this requires moving the $D5xx atr buffer up so that the lower area can be used by the bank switching of a cart. 

 

I'll try a proof of concept with say Logo and MAC/65.

  • Like 1
Link to comment
Share on other sites

Hi!

3 hours ago, Wrathchild said:

Thanks @dmsc, this DOSINI chaining is an area I've parked as awaiting some info on its history as I felt it could be a workaround to something potentially fixable in the ATR loader.

The code in CheckDOSINI and ResetHandler code has a few problems:

- The code resides in $160-$171, limiting the usable stack to $8F bytes, about half of the 256 bytes. Many programs need more stack and will crash the OS.

- The code will be called from the ROM OS after setting up the interrupt vectors - so after the OS is swapped with the RAM one, the machine will crash at the first NMI or IRQ.

- Any program that sets up DOSINI and then tries to read using indirect addressing from it will not work.

 

I think that with this code, the machine will always crash after pressing RESET.

 

So, IMHO, the code should be completely removed - it only makes the OS less compatible.

 

Have Fun!

 

Link to comment
Share on other sites

On 9/28/2023 at 3:58 AM, dmsc said:

The MADS sources of the driver (that should work in BW-DOS and SpartaDOS 2 and 3) is attached here:

Can you please post chkdos.inc? I'm wanting to build a driver with these changes:

 

CART_RESPONSE        equ    $D5C0
CART_STATUS        equ    $D5C1
CART_ATR_HEADER        equ    $D5C2

CART_DCB_DEVICE        equ    $D5C0
CART_DCB_SECTOR_LO    equ    $D5C1
CART_DCB_SECTOR_HI    equ    $D5C2
CART_DCB_PAGE        equ    $D5C3

CART_SECTOR_BUFFER_READ    equ    $D540
CART_SECTOR_BUFFER_WRITE    equ    $D540
 

[Edit] I've built an A8PICO.COM file with the include commented out and this runs ok for testing purposes 

Edited by Wrathchild
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...