Redefine the charset with 8K+ RAM

Basic and Machine Language

Moderator: Moderators

User avatar
Mike
Herr VC
Posts: 4830
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Redefine the charset with 8K+ RAM

Post by Mike »

Boray wrote:the compiled version is 6.64 times faster [...] As a comparison, this would be as the difference between running a CPU at 350 MHz or 2.3 GHz. I've done both with Windows and... strangely I prefer 2.3 GHz.
Doesn't matter if it's the 3x or 4x or the 6.64(...any more digits for more accuracy?)x figure you quoted.

Compiled BASIC code simply is no match for hand-written assembly code. For me, it feels like putting ones feet down simultaneously on both brake (BASIC) and gas pedal (Compiler). Where speed isn't critical, and ease of use/implementation is more important, those parts can easily be left in uncompiled BASIC, and time-critical parts can be done in machine language. Those parts in machine language then easily surpass the mark of 10x speed increase. That should go without saying.

The other reason I don't use Austro-Comp specifically relates to the problems with displays, when anything other than PETSCII graphics is asked for: when it comes to the VIC accessible memory in $1000..$1FFF, exactly that sparse resource is blocked by the compiled binary to a large extent. There goes bitmap graphics. Oh well, too bad. And Austro wouldn't support BASIC extensions anyway.
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Re: Redefine the charset with 8K+ RAM

Post by Boray »

Mike wrote:(...any more digits for more accuracy?)x
Well, lets sa 7 times then if that makes you happy.
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
User avatar
Mike
Herr VC
Posts: 4830
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Redefine the charset with 8K+ RAM

Post by Mike »

You ever heard of rhetorical questions? :lol:
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Re: Redefine the charset with 8K+ RAM

Post by vicist »

I have been trying to port a board game to the vic for months now. I had to take a break from it because the method I'm using to track/verify valid moves involves some complicated (for me anyway) string/array manipulation. I am not using any udg's as it's a simple 5x5 board. The gameplay may be a bit confusing so I decided to include a trainer mode to highlight all possible moves. At the start, there isn't that much to calculate, but later on in the game, there is a lot of data to process. Using basic for these calculations is not very practical as it can take up to 3 minutes just to show the possible moves.

I'm not so good with m/c programming and don't think I would be able to write the routines in assembler without frying what's left of my tiny brain. Compiling the basic code gets the most complicated moves down to about 17 seconds which at least makes the game tolerable to play (other than warping my way through it in VICE).

People who enjoy the challenge of programming but are not that good at m/c must either use a basic compiler to achieve the speed they need or give the routines to someone willing to convert them into pure m/c, which is not always practical or possible.

I know that BorayGammon is compiled and I enjoy playing it immensely, but I don't think I would enjoy it so much as a pure basic program.
Last edited by vicist on Wed Mar 23, 2016 1:20 pm, edited 1 time in total.
User avatar
Mike
Herr VC
Posts: 4830
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Redefine the charset with 8K+ RAM

Post by Mike »

vicist wrote:People who enjoy the challenge of programming but are not that good at m/c must either use a basic compiler to achieve the speed they need or give the routines to someone willing to convert them into pure m/c, which is not always practical or possible.
If the basics are there, why not take such a project as incentive to master the finer aspects of machine code?

And what's wrong about teaming up with other people? A good deal of the nicer releases in the last few years here at Denial were by no means single person acts.

I won't deny, that programming in machine language is more difficult than doing so in BASIC. It also requires a different mind set, and the willingness to distill a problem down to the smallest details. Ultimately, the resulting code avoids the implied overhead, which a BASIC compiler just hasn't any chance to eliminate:

If you take the simple assignment statement "X=X+1", the higher language necessarily needs to assume, that X as variable is contained in some memory addresses. The interpreted BASIC needs to scan the variable list for a match. The compiled object code might be more lucky when the address of the variable is encoded as constant. Then, the original contents of X are transferred to a dedicated area in the zeropage for arithmetic processing. The literal "1" is converted to the internal number format. CBM BASIC redoes this everytime the literal is encountered. Once again, compilers can pre-process all literals. A routine in the interpreter is called to do the addition - no difference between interpreter and compiler here. Finally, the result is transferred from zeropage back to main memory. There's no decisive difference between (16-bit) integers and floats - CBM BASIC adds int<->float conversion to the overhead and compilers might supply extra, faster routines for 16-bit integer, provided the programmer can supply the compiler with hints, that what he meant with X really is supposed to be an integer.

But all this dwarfs against what can happen, when the above statement is embedded into a larger context. Suppose this "X=X+1" is part of the following routine, which is supposed to clear the screen:

Code: Select all

1 X=0
2 POKE7680+X,32
3 POKE7933+X,32
4 X=X+1
5 IFX<253THEN2
It's difficult to imagine, how a BASIC compiler is supposed to infer, that it is sufficient to hold X in a CPU register! The whole processing of the longer paragraph above just collapses into a single instruction in machine language: INX! The whole routine then looks like this in assembly:

Code: Select all

 LDX #0
 LDA #32
.loop
 STA $1E00,X
 STA $1EFD,X
 INX
 CPX #$FD
 BCC loop
...

Anyway, we've gone a long way from doing UDGs with larger RAM expansions to the (assumed) benefits of BASIC compilers.

In the context of user defined graphics, the BASIC compilers add a restriction which should not be overlooked. If the programmer is already beyond the stage of having a working/good/efficient implementation of the program logic (albeit still a bit slow) in interpreted BASIC, then goes to design a nice graphic design, and only then realises, that these two stages - namely getting a compiled (fast) version, and having user defined graphics - are mutually incompatible, then he has all the right to feel conned.

Doesn't happen with the use of machine language. It just adds to the capabilities a program is supposed to show.
groepaz
Vic 20 Scientist
Posts: 1180
Joined: Wed Aug 25, 2010 5:30 pm

Re: Redefine the charset with 8K+ RAM

Post by groepaz »

is there no basic compiler that works like "basic boss" for the vic20? basic boss would actually be able to convert that basic code into pretty much the asm code you wrote :) remember austro-comp doesnt even compile to ml - it still uses an interpreter and just converts the basic into bytecode.
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
Post Reply