6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 9:15 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: commodore 64 basic v2
PostPosted: Wed Nov 03, 2010 7:22 pm 
Offline
User avatar

Joined: Sun Feb 13, 2005 9:58 am
Posts: 85
looking around i didn't find any kind of basic re-implementation using hi level languages or, better, actual languages.

so i start a post dinner lecture of the c64 rom disasm, for example this http://myoperatingsystem.org/Commodore/Annotated_ROM_Listings.htm

i was trying to figure out how much time it will costs to rewrite, for example in javascript or native c, the original rom without changing it too much.

(yes, i know that already exist a "porting" (see http://www.pagetable.com/?p=48) but that's not what i mean.

ehm, not so easy!
some topics:
* lot of float math...slow
* lot of jsr to jump to jsr to 2-3 instruct code...again slow but also strange
* not so much kernel subs independent code: forth is very clean about it

i'm not saying that it's easy to write a 8k basic in '80 (in that period i also write lot of spaghetti code) but now i'm really curious about the commodore basic genesis/porting and if someone can give me more info for realizing a good porting without becoming crazy.

btw:
i'm doing a bit of work also in js 6502 code, that forum seems death, so if someone is interested...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 3:38 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
Deeply-nested call-graphs (JSRs to JSRs to JSRs, etc) are a hallmark of writing software in a well-factored manner. You start out with basic primitives written in a stream of instructions, and you then can JSR to them as though they were a higher-level assembly instruction.

If you look at most high-level compiler output of the era, you'll notice that "subroutine-threaded code" like this was the norm, not the exception. Note that Forth is singularly famous for this style of code generation, although the technique technically predates Forth.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 4:40 pm 
Offline
User avatar

Joined: Sun Feb 13, 2005 9:58 am
Posts: 85
kc5tja wrote:
Deeply-nested call-graphs (JSRs to JSRs to JSRs, etc) are a hallmark of writing software in a well-factored manner. You start out with basic primitives written in a stream of instructions, and you then can JSR to them as though they were a higher-level assembly instruction.

If you look at most high-level compiler output of the era, you'll notice that "subroutine-threaded code" like this was the norm, not the exception. Note that Forth is singularly famous for this style of code generation, although the technique technically predates Forth.


thank you for your reply, let me try to explain with some code.
...but anyway if basic was written with another high level language, i'm really curious about it!!!

here a piece of code, quite near the warm boot because it is used during the print of the banner using this core routine

Code:
; print string form AY
 
 AB1E   20 87 B4   JSR $B487
 
 
 ; print string from $22/$23
 
 AB21   20 A6 B6   JSR $B6A6
 AB24   AA         TAX
 AB25   A0 00      LDY #$00
 AB27   E8         INX
 
 AB28   CA         DEX
 
 AB29   F0 BC      BEQ $AAE7
 AB2B   B1 22      LDA ($22),Y
 AB2D   20 47 AB   JSR $AB47
 AB30   C8         INY
 AB31   C9 0D      CMP #$0D
 AB33   D0 F3      BNE $AB28
 AB35   20 E5 AA   JSR $AAE5
 AB38   4C 28 AB   JMP $AB28


look at jsr $AB47, that more or less is output one char.

it jump at:
Code:
; print character on CMD output file
 
 AB3B   A5 13      LDA $13
 AB3D   F0 03      BEQ $AB42
 AB3F   A9 20      LDA #$20   ; space
 AB41   .BY $2C
 AB42   A9 1D      LDA #$1D   ; csr right
 AB44   .BY $2C
 
 AB45   A9 3F      LDA #$3F   ; question mark
 
 
 AB47   20 0C E1   JSR $E10C
 
 AB4A   29 FF      AND #$FF
 AB4C   60         RTS


this is good, a little reuse of and #$ff
but now the jsr $e10c (kernel rom)

Code:
 E10C   20 D2 FF   JSR $FFD2


and..
Code:
FFD2   6C 26 03   JMP ($0326)   ; (F1CA) output char on current device


again: i dont wanna say that it's easy (better it was easy) to write code in 8k space, but now i can understand why a PRINT was so slow!

anyway i'd love to find out if there is a project for reimplement the original asm code in a new highlevel language, that's why i'm playing rom digging.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 9:06 pm 
Offline
User avatar

Joined: Fri Dec 12, 2003 7:22 am
Posts: 259
Location: Heerlen, NL
ptorric wrote:
but now i can understand why a PRINT was so slow!

You would find the CHROUT routine at $FFD2 at all Commodore machines. This meant that various ML programs could run at various machines with different hardware. A large part of the $FF page was filled with these kind of vectors.
The indirect jump enabled you to redirect a vector to your own routines.

First CP/M and then IBM used these tricks as well. And it worked well. Until some programmers started to cut edges to speed up things. And then owners of some MS-DOS computers found out that some programs didn't run on their machines anymore: the now famous IBM incompatibility.

First after written the above I realise that I forgot an other, maybe more important argument. The JMP $FFD2 isn't slow at all; the interpretation of the Basic command PRINT is!

_________________
Code:
    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       URL: www.baltissen.org



Last edited by Ruud on Sat Nov 06, 2010 10:35 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 05, 2010 3:53 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
I think I understand now. The indirect jump for CHROUT is used to implement redirected I/O.

To produce a hard-copy listing of a BASIC program, for example, you'd use the CMD command to cause output to route to device 4 (e.g., OPEN 4,4:CMD 4:LIST:CLOSE 4). It's like file redirection logic in Unix or Windows.

I once wrote a quick-n-dirty hack that patched into these routines to provide a hierarchical directory system on which device drivers and filesystems could be mounted. Without having that extra layer of indirection, such a feature would have required I reprogrammed the entire KERNAL ROM, which is clearly not feasible for anyone else who might want to use the code.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: