TOS 1.04 sources reconstructed

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

mikro
Hardware Guru
Hardware Guru
Posts: 2997
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: TOS 1.04 sources reconstructed

Post by mikro »

Yeah, I think it's better to separate those code bases, as they are basically static, nobody from Atari is going to change them. ;-)

So this will lead to a cleaner source code and anyone brave enough can take first steps towards customizing it (for instance switching to vbcc/gcc).
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

Initially i thought it would be a good idea to have the ifdefs, so you can see the where the TOS versions differ. However it turned out that there are just too many small changes, and also some "hacks" (marked by BINEXACT) where i had to work around some compiler oddities. So i guess i will clean that up a bit, and if you you want to compare the versions, you'll have to look at both sources.
anyone brave enough can take first steps towards customizing it (for instance switching to vbcc/gcc).
Not impossible, but still quite some work. About the same it took to get a working version of EmuTOS at the beginning. BTW i experimented a bit with Pure-C (won't work of course because of the different register usage, just compiles) and got a ROM image of ~175k
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

mikro wrote: Thu Dec 23, 2021 7:50 pm I'm pretty sure that the most wide-spread version of TOS 1.04/2.06 was translated into Czech by Petr Stehlik a.k.a. Joy
Yes, that' s also what i remember.
The list of fixed bugs in the Czech version of 2.06 is as follows:

- set the shell-pointer to null after reset
That was done in the 2.06 version i found, but not in 1.04
- fixed boot device, bad booting from other logical partitions
Done here: https://github.com/th-otto/tos1x/blob/1 ... tup.S#L657
- fixed stack pointer after execution in AUTO
Done here: https://github.com/th-otto/tos1x/blob/1 ... tup.S#L657

Although i'm not sure whether that bug really causes problems. The stack correction is wrong, but the whole routine (autoscan) is executed as a separate GEMDOS process, so that should not cause any harm to the rest of the startup. Same bug is also present in TOS 2.x/3.x, and not fixed by TOS14FIX.
- fixed "Applikationsstatus anders abfragen"
I think this is this one: https://github.com/th-otto/tos1x/blob/1 ... lib.c#L348

To be honest, i still don't understand what problem this patch is supposed to fix. The code for TOS 1.x is:

Code: Select all

/*
 *	Routine to take a full path, and scan back from the end to 
 *	find the starting byte of the particular filename
 */
char *sh_name(char *ppath)
{
	register char *pname;

	pname = ppath;
	while (*pname++)
		;

	while (pname >= ppath && *pname != '\\' && *pname != ':')
		--pname;
	return ++pname;
}
The code from later versions looks like this:

Code: Select all

char *sh_name(char *ppath)
{
	register char *pname;

	pname = ppath;
	while (*pname++)
		;

	do
	{
		--pname;
	} while (pname >= ppath && *pname != '\\' && *pname != ':');

	return ++pname;
}
The patch from the assembler version would correspond to

Code: Select all

char *sh_name(char *ppath)
{
	register char *pname;
	char ch;
	
	pname = ppath;
	while (*pname++)
		;

	do
	{
		ch = *--pname;
		if (pname < ppath)
			break;
	} while (ch != '\\' && *ch != ':');

	return ++pname;
}
In all cases, "pname" will point to the byte *behind* the terminating zero byte after the first loop, so there should be no difference between the outcome of all three versions.
"Warteroutine von ARROW-Repeat ändern"
I guess you mean the fixes done by ARROWFIX here. These don't seem to be applied, neither in 1.04 nor in 2.06
orionfuzion
Atari freak
Atari freak
Posts: 50
Joined: Fri Nov 11, 2016 1:57 pm
Location: Paris, France
Contact:

Re: TOS 1.04 sources reconstructed

Post by orionfuzion »

What a great Christmas present!
Where do the original sources come from?
Are there any completely reverse engineered parts or are they original sources that have been modified to be rebuildable?

-- Orion / Reps
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

"original sources" were the ones from tos 2.x for large parts, which i posted some years ago, and in turn were based on some leaked Atari sources. For the BIOS that means for example:

- take a disassembly from original TOS
- take a disassembly from the compiled sources
- look at were they start to differ
- fix the instructions for 1.04
- rinse and repeat

GEMDOS and VDI are not much different, and had already been mostly completed when i worked on TOS 2.x. AES is also very similar, just with lots of hacks to save code bytes (the dispatcher from gembind.c for example looks like the whole source was once compiled to assembler, then the result manually "optimized"). The desktop is completely different from later TOS versions, but rather similar to the original DRI version instead. The DRI version is also where most of the function/variables come from. Some parts of it (like the copy and format dialog, which are not present in PC-GEM) have been completely reverse engineered.
orionfuzion
Atari freak
Atari freak
Posts: 50
Joined: Fri Nov 11, 2016 1:57 pm
Location: Paris, France
Contact:

Re: TOS 1.04 sources reconstructed

Post by orionfuzion »

Thanks for the precise answer.
For my recent projects, I needed to reverse-engineer some parts of the TOS.
I had only found the sources of the Bios on the Internet, but I was completely unaware that the sources of the other parts were also available.
This is a mine of information!
Thanks again.

-- Orion / Reps
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

I have now also finished the BIOS part of 1.06 (other parts are still missing so you can't build a complete 1.06 version yet). For the curious, there are not much surprises. Differences include:
  • at places where the hardware video base is set/read, also the low byte is read/written
  • during boot, the microwire interface is initialized. Other than that, there is no support for that hardware.
  • The ramtop/ramvalid system variables are set, but no attempt is made to probe for TT-RAM
  • A small cookiejar is installed (with 8 entries), containing values for _CPU, _MCH, _SND and _SWI. Strangely, no _VDO cookie is set.
  • the system variables kcl_hook and bell_hook are supported, to allow for custom sounds.
  • The bios/xbios entry points are aware of the longframe variable, just like TOS 2.06
  • A simple priviledge violation handler is installed, to catch "move SR,dn" in user mode. This is an allowed instruction on 68000, but gives an exception on 68010+. However unlike later TOS versions, the handler only catches move to data-register, changing that into a "move ccr,dn"
  • The floppy routines use the hz_200 variable for timeouts instead of a fixed counter (again, that is also done in 2.06)
  • The default palette includes the additional bit for all white values. Similarly, Setcolor() does not mask that out.
1.62 is not finished yet, however it seems that the BIOS is completely identical to 1.06.

Edit: GEMDOS part of 1.06 now also finished. Differences there:
  • just like BIOS, the GEMDOS entry point checks for the _longframe variable. There is however a serious bug in the internal function that starts a new gemdos process, where that check is missing.
  • A small fix in the function that checks for Ctrl-C. Same fix is also present in later GEMDOS versions (although it still reports version 0.15)
  • When a process terminates, GEMDOS internalls updates the system time from BIOS. That is now done with a proper XBIOS call instead of calling the internal BIOS function directly.
Edit2: VDI of 1.06 is also finished. Not much changed compared to 1.04, mostly vs_color/vq_color to handle the STE colors.
Last edited by ThorstenOtto on Mon Dec 27, 2021 12:40 pm, edited 2 times in total.
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 2721
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: TOS 1.04 sources reconstructed

Post by Cyprian »

ThorstenOtto wrote: Fri Dec 24, 2021 4:19 pm "original sources" were the ones from tos 2.x for large parts, which i posted some years ago, and in turn were based on some leaked Atari sources. For the BIOS that means for example:

- take a disassembly from original TOS
- take a disassembly from the compiled sources
- look at were they start to differ
- fix the instructions for 1.04
- rinse and repeat
that's a lot of work
congrats and thanks
Lynx I / Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
OL
Atari Super Hero
Atari Super Hero
Posts: 718
Joined: Fri Apr 01, 2005 6:59 am
Contact:

Re: TOS 1.04 sources reconstructed

Post by OL »

ThorstenOtto wrote: Sun Dec 26, 2021 4:21 pm I have now also finished the BIOS part of 1.06 (other parts are still missing so you can't build a complete 1.06 version yet). For the curious, there are not much surprises. Differences include:
  • at places where the hardware video base is set/read, also the low byte is read/written
  • during boot, the microwire interface is initialized. Other than that, there is no support for that hardware.
  • The ramtop/ramvalid system variables are set, but no attempt is made to probe for TT-RAM
  • A small cookiejar is installed (with 8 entries), containing values for _CPU, _MCH, _SND and _SWI. Strangely, no _VDO cookie is set.
  • the system variables kcl_hook and bell_hook are supported, to allow for custom sounds.
  • The bios/xbios entry points are aware of the longframe variable, just like TOS 2.06
  • A simple priviledge violation handler is installed, to catch "move SR,dn" in user mode. This is an allowed instruction on 68000, but gives an exception on 68010+. However unlike later TOS versions, the handler only catches move to data-register, changing that into a "move ccr,dn"
  • The floppy routines use the hz_200 variable for timeouts instead of a fixed counter (again, that is also done in 2.06)
  • The default palette includes the additional bit for all white values. Similarly, Setcolor() does not mask that out.
1.62 is not finished yet, however it seems that the BIOS is completely identical to 1.06.

Edit: GEMDOS part of 1.06 now also finished. Differences there:
  • just like BIOS, the GEMDOS entry point checks for the _longframe variable. There is however a serious bug in the internal function that starts a new gemdos process, where that check is missing.
  • A small fix in the function that checks for Ctrl-C. Same fix is also present in later GEMDOS versions (although it still reports version 0.15)
  • When a process terminates, GEMDOS internalls updates the system time from BIOS. That is now done with a proper XBIOS call instead of calling the internal BIOS function directly.
Otto, this is amazing work!

Olivier
OL
User avatar
troed
Atari God
Atari God
Posts: 1635
Joined: Mon Apr 30, 2012 6:20 pm
Location: Sweden

Re: TOS 1.04 sources reconstructed

Post by troed »

ThorstenOtto wrote: Sun Dec 26, 2021 4:21 pm [*] The floppy routines use the hz_200 variable for timeouts instead of a fixed counter (again, that is also done in 2.06)
But TOS 1.06/1.62 doesn't run Timer C like TOS 2.06 does ... right?
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

Of course it does. Timer C is always used for the hz_200 timer. In 1.04 it is just not used for timeouts most of the time. Only for very short delays, 2.06 uses the Timer A (or Timer-C of the TTMFP in 3.06)
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: TOS 1.04 sources reconstructed

Post by czietz »

ThorstenOtto wrote: Sun Dec 26, 2021 4:21 pm [*] A simple priviledge violation handler is installed, to catch "move SR,dn" in user mode. This is an allowed instruction on 68000, but gives an exception on 68010+. However unlike later TOS versions, the handler only catches move to data-register, changing that into a "move ccr,dn"
As far as I can see, it handles the other addressing modes just as well, converting every MOVE SR,... to the respective MOVE CCR,... and re-running the instruction.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

czietz wrote: Mon Dec 27, 2021 11:15 am As far as I can see, it handles the other addressing modes just as well, converting every MOVE SR,... to the respective MOVE CCR,... and re-running the instruction.
Maybe the rerunning is the problem, or the fact that the users text area is patched, but in TOS 2.x that code looks much different, and handles decoding of the addressing modes manually: https://github.com/Kochise/atari-docs/b ... iv.inc#L21

At least you would have to flush caches if running on 68020+, like emutos does.
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 2721
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: TOS 1.04 sources reconstructed

Post by Cyprian »

ThorstenOtto wrote: Mon Dec 27, 2021 5:07 am Of course it does. Timer C is always used for the hz_200 timer. In 1.04 it is just not used for timeouts most of the time. Only for very short delays, 2.06 uses the Timer A (or Timer-C of the TTMFP in 3.06)
that strange 2.06 uses Timer A,.
does it mean the user application can't rely on that timer anymore?

ThorstenOtto wrote: Sun Dec 26, 2021 4:21 pm [*] A simple priviledge violation handler is installed, to catch "move SR,dn" in user mode. This is an allowed instruction on 68000, but gives an exception on 68010+. However unlike later TOS versions, the handler only catches move to data-register, changing that into a "move ccr,dn"

does it mean 1.62 support e.g. 68030?
Lynx I / Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: TOS 1.04 sources reconstructed

Post by czietz »

Cyprian wrote: Mon Dec 27, 2021 12:59 pm does it mean 1.62 support e.g. 68030?
TOS 1.06/1.62 does not handle the caches of 68020 and up (nor does it activate them). The changes that Thorsten describes (w.r.t. stack frames and MOVE SR,... handling) were presumably made to support the 68010.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

Cyprian wrote: Mon Dec 27, 2021 12:59 pm that strange 2.06 uses Timer A,.
does it mean the user application can't rely on that timer anymore?
If i did not miss any, 2.06 just uses this during boot, when resetting the IKBD. You can grep for "mfpdelay" in the 2.x sources, most of the places are for TTMFP_SUPPORT only.
ThorstenOtto wrote: Sun Dec 26, 2021 4:21 pm does it mean 1.62 support e.g. 68030?
Not really. Only the exception handlers are aware of the _longframe variable. There is no handling of caches, MMU etc.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

Version 1.62 is now also complete and can be compiled from sources. I've added the differences to the README
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: TOS 1.04 sources reconstructed

Post by czietz »

Nice. Could it be, though, that you forgot to push the commits related to 1.62? I find no reference to them in https://github.com/th-otto/tos1x.

PS: As for the 1.06 note...
However unlike later TOS versions, the handler only catches move to data-register, changing that into a "move ccr,dn"
... I can only refer to the remark that I made before in this thread.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

You are too fast ;) Just pushed
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

BTW. i have a bit trouble with the swedish version of 1.62. Could it be that there never has been an official version? The 1.04 & 1.06 are version that already had some patches applied, but the 1.62 does not. Are all the swedish versions just patched ones, like czech?

Edit: same problem with the czech version of 1.62.
Last edited by ThorstenOtto on Sat Jan 01, 2022 6:13 pm, edited 1 time in total.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

Another strangeness with the uk version from avtandil's site. My compiled versions differs in two bytes.

The first is

Code: Select all

his version:
[00e15760] 3b40 1004                 move.w     d0,4100(a5)
My version:
[00e15760] 3b40 0004                 move.w     d0,4(a5)
That code is the assignment from
https://github.com/th-otto/tos1x/blob/6 ... pp1.c#L441

The second is

Code: Select all

His version:
[00e269a2] 3eae fff8                 move.w     -8(a6),(a7)
My version:
[00e269a2] 2eae fff8                 move.l     -8(a6),(a7)
That code results from https://github.com/th-otto/tos1x/blob/6 ... lib.c#L720 and his version pushes only a word for the fname parameter, which is a pointer. Both look like serious bugs to me in his image.
ijor
Hardware Guru
Hardware Guru
Posts: 4346
Joined: Sat May 29, 2004 7:52 pm
Contact:

Re: TOS 1.04 sources reconstructed

Post by ijor »

ThorstenOtto wrote: Sat Jan 01, 2022 5:22 pm Version 1.62 is now also complete and can be compiled from sources. I've added the differences to the README
Great job again! But I expect you won't stop there ... still 1.02 and 1.00 to go :)
ThorstenOtto wrote: Sat Jan 01, 2022 6:10 pm Another strangeness with the uk version from avtandil's site. My compiled versions differs in two bytes.
That is a known corrupted TOS image that has been around for years. Yours is correct and the one that matches actual Atari ROMs.
Fx Cast: Atari St cycle accurate fpga core
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

ijor wrote: Sat Jan 01, 2022 8:59 pm But I expect you won't stop there ... still 1.02 and 1.00 to go :)
I don''t think that this make much sense. It is quite well known what was changed in version 1.04 compared to 1.02, and i expect supporting that in the source would add again lots of ifdefs.
That is a known corrupted TOS image that has been around for years. Yours is correct and the one that matches actual Atari ROMs.
Ah, good to know. That leaves only the question about the swedish and czech versions of 1.62.
mikro
Hardware Guru
Hardware Guru
Posts: 2997
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: TOS 1.04 sources reconstructed

Post by mikro »

I can answer the Czech one -- there wasn't any. 1.04 was chosen as the last ST-compatible and 2.06 as the last ST/STE compatible, there was no reason to translate more versions. The 1.62 one on Dima's website is some "un-unofficial" translation by some random dude.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: TOS 1.04 sources reconstructed

Post by ThorstenOtto »

Yes i know that the czech version is a patched one (probably made by Petr Stehlik), it is only a bit strange that 1.04 and 1.06 build just fine, but 1.62 differs again. Maybe 1.62 is the one from davemacblack?

Same could be true for swedish, although i've always thought swedish was an original TOS image.
Post Reply

Return to “Coding”