Updated BASIC and KERNAL disassembly

Basic and Machine Language

Moderator: Moderators

Bobbi
Vic 20 Afficionado
Posts: 355
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: Updated BASIC and KERNAL disassembly

Post by Bobbi »

The disassembly is a fascinating read!
Bobbi
Vic 20 Afficionado
Posts: 355
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: Updated BASIC and KERNAL disassembly

Post by Bobbi »

Incidentally, it doesn't assemble using xa65 for Linux (my usual asm.)

Here is the error log if you are interested. The -M flag tells the assembler to allow colons within comments, which is otherwise an error.

Looking at this closer it seem the lines that fail have a colon literal (for example

Code: Select all

SBC #':'
) so I am going to guess this is actually a bug in how xa65 handles colons in the input!

The branch out of range errors are more interesting. I will have to look at those and see if they are false positives.

I will have to see who, if anyone, maintains xa65. It seems the package has a Debian maintainer.

Code: Select all

bobbi@fluffy:~/VIC20$ xa -M -o foo combined_ROMs.asm 
 SBC #':'   ; subtract ":"
combined_ROMs.asm:line 2204: c5d6:Syntax error
combined_ROMs.asm:line 2204: c5d6:Syntax error
 CMP #TK_DATA-':'  ; compare with the token for DATA-':'
combined_ROMs.asm:line 2208: c5da:Syntax error
combined_ROMs.asm:line 2208: c5da:Syntax error
 SBC #TK_REM-':'  ; subtract the token for REM-':'
combined_ROMs.asm:line 2216: c5e1:Syntax error
combined_ROMs.asm:line 2216: c5e1:Syntax error
 CMP #':'   ; compare with ":"
combined_ROMs.asm:line 2710: c809:Syntax error
combined_ROMs.asm:line 2710: c809:Syntax error
 LDX #':'   ; set look for character = ":"
combined_ROMs.asm:line 2980: c908:Syntax error
combined_ROMs.asm:line 2980: c908:Syntax error
 LDA #':'   ; set ":"
combined_ROMs.asm:line 3774: cc6d:Syntax error
combined_ROMs.asm:line 3774: cc6d:Syntax error
 ADC #':'   ; add character ":" ($30+$0A, result is 10 less that value)
combined_ROMs.asm:line 8061: def6:Syntax error
combined_ROMs.asm:line 8061: def6:Syntax error
 CMP #':'   ; compare with ":"
combined_ROMs.asm:line 8955: e392:Syntax error
combined_ROMs.asm:line 8955: e392:Syntax error
combined_ROMs.asm:line 4058: cdd1:Branch out of range error
combined_ROMs.asm:line 4062: cdd5:Branch out of range error
combined_ROMs.asm:line 4844: d0fc:Branch out of range error
combined_ROMs.asm:line 5041: d1c2:Branch out of range error
Break after 20 errors
EDIT: Reported the bug to the maintainer. BTW, the website for this assembler is http://www.floodgap.com/retrotech/xa/.
Bobbi
Vic 20 Afficionado
Posts: 355
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: Updated BASIC and KERNAL disassembly

Post by Bobbi »

If I replace all instances of ':' by $3a, then it assembles fine.

Code: Select all

sed s/\':\'/\$3a/g <combined_ROMs.asm >combined_ROMS2.asm
xa -M -o rom.img combined_ROMS2.asm
So that was the only issue.
groepaz
Vic 20 Scientist
Posts: 1180
Joined: Wed Aug 25, 2010 5:30 pm

Re: Updated BASIC and KERNAL disassembly

Post by groepaz »

andre fachat is the author of xa, you should be able to contact him via 6502.org or sth
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
Bobbi
Vic 20 Afficionado
Posts: 355
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: Updated BASIC and KERNAL disassembly

Post by Bobbi »

The maintainer email address I have is ckaiser@floodgap.com.

I don't know whether Andre still maintains it (it dates back to the 90s I believe, or even 80s).
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Updated BASIC and KERNAL disassembly

Post by srowe »

I use xa and have already reported the issue. I run with a local patch but I think it caused a unit test to fail so hasn't been included.

Code: Select all

--- xa-2.3.6/src/xa.c.org       2014-07-10 20:22:32.000000000 +0100
+++ xa-2.3.6/src/xa.c   2014-08-14 21:01:33.757777896 +0100
@@ -1056,7 +1056,7 @@
           do {
                c=s[j]=l[i++];
 
-               if (c=='\"')
+               if (c=='"' || c=='\'')
                     hkfl^=1;
                if (c==';' && !hkfl)
                        comcom = 1;
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Updated BASIC and KERNAL disassembly

Post by srowe »

I've been steadily working through the remaining gaps in this, there are major updates to the RS-232 and screen routines. There's still some work to do, I could do with a maths wizard taking a look at some of the BASIC floating point routines and the low-level tape routines are incomplete.
basic_kernel.zip
(145.39 KiB) Downloaded 94 times
The latest copy is always available here http://eden.mose.org.uk/gitweb/?p=rom-r ... ;a=summary
Bobbi
Vic 20 Afficionado
Posts: 355
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: Updated BASIC and KERNAL disassembly

Post by Bobbi »

Thank you so much for this!

I refer to your annotated disassembly quite a bit!!

Has anyone ever done this for the C64 ROMs? I am guessing they are not that different, but it would be interesting to compare and account for the differences.
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Updated BASIC and KERNAL disassembly

Post by srowe »

There's some on GitHub

https://github.com/mist64/c64rom
sjgray
Vic 20 Hobbyist
Posts: 115
Joined: Thu May 03, 2007 6:46 pm
Location: Markham, ON, Canada

Re: Updated BASIC and KERNAL disassembly

Post by sjgray »

Here's another version with combined VIC/64 source:

https://github.com/sjgray/cbm-edit-rom/ ... rtKirk.asm

My site, but contributed by Edilbert. Included in one of my github projects.

Steve
Bobbi
Vic 20 Afficionado
Posts: 355
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: Updated BASIC and KERNAL disassembly

Post by Bobbi »

Thank you --- I have some reading for the weekend now!!
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Updated BASIC and KERNAL disassembly

Post by srowe »

sjgray wrote:Here's another version with combined VIC/64 source:
This is very useful for comparing VIC vs C64 code. Any ideas which C64 ROM version this is?

Simon
sjgray
Vic 20 Hobbyist
Posts: 115
Joined: Thu May 03, 2007 6:46 pm
Location: Markham, ON, Canada

Re: Updated BASIC and KERNAL disassembly

Post by sjgray »

srowe wrote:
sjgray wrote:Here's another version with combined VIC/64 source:
This is very useful for comparing VIC vs C64 code. Any ideas which C64 ROM version this is?

Simon
It's version 3 as seen at line 17283.

Steve
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Updated BASIC and KERNAL disassembly

Post by srowe »

Just a note that there is a new release of xa that fixes the issue mentioned above.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Updated BASIC and KERNAL disassembly

Post by Mike »

Hi, Simon,

in line 263 of your (at the time I write this most recent) Super Expander source, it reads:

Code: Select all

263         JMP (CBINV)             ; ?? handle restore via BRK vector ??
Some time ago I also had stumbled across this, as that one leads to unexpected behaviour of the [RESTORE] key with MINIMON. MINIMON itself plays nice as it checks for the A0CBM signature and lets a cartridge take precedence, however the BRK vector is also diverted and tapping [RESTORE] on its own now breaks into the monitor. :(

In the original course of action, the KERNAL BRK routine calls the lead out of the KERNAL NMI routine to do the BASIC warmstart, not the other way round. One can only think that indirect JMP in the SE code is a brainf*rt ... it really should have been JMP $A2C2 instead:

Image

(... of course fixing it that way is only possible with a soft loaded copy of SE ...)

...

On a related note, I have a suggestion for your latest RS 232 fix (the one in BLK5). You set the warmstart entry to point to $0000, ...

Code: Select all

*	=	$A000

	.WORD	RSCOLD
	.WORD	0			; unused
	.BYT	"A0",'C'+$80,'B'+$80,'M'+$80
... as some software could however divert the NMI vector or re-initialise it to the KERNAL default, you should rather point that entry to $FEC7 instead.

This continues the original NMI code after $FEC4 JMP ($A002), so when the KERNAL or some other program (like MINIMON) checks for the A0CBM signature, the KERNAL vectors are reset but at least it does not crash.

Greetings,

Michael
Post Reply