How to start programming in ML

You need an actual VIC.

Moderator: Moderators

Liono
Vic 20 Newbie
Posts: 1
Joined: Tue Jan 18, 2005 5:20 am

How to start programming in ML

Post by Liono »

First post here, so sorry to ask such a newbie question.

When I first has a Vic-20 I was around 8 years old, so only ever programmed in BASIC, and most of that was just edited type-ins from magazines. But after reading through a lot of posts on this forum I'd really like to try my hand at ML and was wondering if anyone could point me in the right direction of where to start?

Many thanks :)
Signature???
Only NERDS use signatures on forums......

....dam it!
hoggums
Vic 20 Newbie
Posts: 2
Joined: Thu Jan 06, 2005 4:26 am

ML programming

Post by hoggums »

I've just started this myself and the best way forward is to get yourself a cross assembler. ACME is the best version I've seen, makes things very easy, allows you to create and use macros, converts text into Vic screen codes and PETScii plus has a useful maths parser built in meaning you can do stuff like this which writes hello world on the last line of the screen:

ldx #0
.loop lda mytext,x
sta 7680 + 22*22,x
inx
cpx #mytextend-mytext
bne .loop
rts
mytext !scr "hello world"
mytextend

I'm running the code through VICE which has a basic machine code monitor so you can step through your m/c if it's causing probs.

You can find it all at www.6502.org

Also if you're thinking of writing basic programs then I recommend tok64 and rlccbm.
billlagr
Vic 20 Amateur
Posts: 64
Joined: Wed Sep 22, 2004 7:27 pm

Post by billlagr »

actually, this is a very timely post. I had been considering writing a game for the vic, which is something I havent done in maybe 15 or so years. I have the time at the moment, no college, so I'm going to check out ACME now!
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

You need:

1. An assembler, either running on the VIC-20 or a cross-assember. If you resort to a machine code monitor (i.e. a lower level than assembler) or decide to cross-develop on your PC + cable/emulator, it is rather easy to find a solution.

2. A list of instructions is also very easy to find, more or less documented and explained.

3. A tutorial or course in how to think and use the instructions. It is probably the one hardest to find, but depending how much programming experience you had since before and how determined you are, you may survive with some programming examples and the list of instructions.

I'm not sure where to start, but learning hexadecimal numbers ($xxxx) and how to POKE are the first two steps, at least it was for me. It involves learning the accumulator and possibly the two registers X and Y:

LDA #81
STA 7680 ; rem put a filled ball (shift-Q) on top of screen, POKE 7680,81

LDX #81
STX $1e00 ; does the same, but going through the X register

LDY #$51
STY $1e00 ; again the same thing, but all numbers referenced in hex

Then try some radically more advanced example:

LDX #$05
LDA #$51
STA $1e00,X ; what does this one do, really?!

Oops. We just discovered that 6502 assembler relies a lot on different addressing modes. Not all instructions work with all modes though, which you will learn later.

You may find some tutorial, instruction list and other useful documents here:

http://lilly.csoft.net/~jeffryj/compile ... brary.html

You can also browse the 6502 website: http://www.6502.org/

Later on, you can get memory maps, documentation about VIC-20 custom chips etc here:

http://www.ftp.funet.fi/pub/cbm/documents/

Aleksi Eeben previously had put together a collection of technical docs for the aspiring programmer, but unfortunately I can't find it online anymore.
Anders Carlsson

Image Image Image Image Image
billlagr
Vic 20 Amateur
Posts: 64
Joined: Wed Sep 22, 2004 7:27 pm

Post by billlagr »

its come a long way...i used to be armed with a pen, paper, graph paper, Programmers Reference Guide, and a ML monitor on my unexpanded Vic and datasette. Now I can cross assemble, test it on VICE and step through it if it crashes.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Yup. It is really progress. Logic errors however, I have not found any remedy for.
Anders Carlsson

Image Image Image Image Image
billlagr
Vic 20 Amateur
Posts: 64
Joined: Wed Sep 22, 2004 7:27 pm

Post by billlagr »

but at least now it doesnt require you to turn your crashed machine off then on again and start wading through your code to find the error ;)
User avatar
Mike
Herr VC
Posts: 4817
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Logic errors

Post by Mike »

carlsson wrote:Yup. It is really progress. Logic errors however, I have not found any remedy for.
I've found quite a simple remedy. I try to refrain from non-obvious code. As I write a piece of code, I always think about what would happen if I were about to extend its functionality.

One simple example (this is in BASIC, not ML, but generalises quite well):

In a loop, I want to call 3 different sub-routines each time the loop is repeated. I would cycle a variable through 3 different values, and call the sub-routine dependent on that value. So far, nothing wrong about that.

I could do it like this:

[S is either 1, 2, or 3 on entry:]
ON S GOSUB aa,bb,cc:S=(-1.5*S+5.5)*S-2

One other way would be:

IF S=1 THEN GOSUB aa:S=2:GOTO xx
IF S=2 THEN GOSUB bb:S=3:GOTO xx
IF S=3 THEN GOSUB cc:S=1:GOTO xx
STOP:REM NEVER GET HERE
xx [... execution continues here]

...

Sure, Example 1 is shorter. But how did I derive this formula? How do I need to modify the code, if I'd wanted to include more sub-routines? What happens, when S (by accident) is not one of the values 1, 2, or 3? With Example 2, none of these questions pose a problem.

Just my 2 cents,

Michael
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I would probably use ON S GOSUB aa,bb,cc:S=S+1-INT((S+1)/4)*3

It is not extremely readable, but at least you can understand what is happening with the formula. As long as the incoming S is within the expected range 1..3 it will work. If you define a variable B% which holds the number of values, you can write S=S+1-INT((S+1)/(B%+1))*B%
Anders Carlsson

Image Image Image Image Image
martin_f
Vic 20 Amateur
Posts: 46
Joined: Mon Jun 28, 2004 6:22 pm

Post by martin_f »

Geeting back to ACME mentioned above. I checked it out over the weekend. Looks pretty nifty. I am going to use it for the next couple of months to get a good feel for it (its better than what I was using).

One thing with it, anyone know if you can split a line of a macro (probably applies to any line) across multiple lines without it complaining (I tried using the \ character which is the standard for most programming languages / compilers etc, but it didn't work) ?

Some of the lines in my macros have a quite a few computations going on, with variable definitions that have useful names (i.e. about 10-15 chars). I guess I could break the lines up into multiple real lines, introducing a couple of temps, but would prefer not to.

Other than that one thing, I like it.

Martin
hoggums
Vic 20 Newbie
Posts: 2
Joined: Thu Jan 06, 2005 4:26 am

ACME macro

Post by hoggums »

Yep you can do that - in acme macros have the format

!macro <macroname> , [<param> , ...] {
line1
line2
....
}

have fun!
martin_f
Vic 20 Amateur
Posts: 46
Joined: Mon Jun 28, 2004 6:22 pm

Post by martin_f »

What I was actually after was to have line1 say split over multiple lines, eg:

MY_VARIABLE = OTHER_VARIABLE1 + OTHER_VARIABLE2 +
<indentation here> OTHER_VARIABLE3

The above doesn't seem to be allowed.

I have a macro in my stuff at home, where I have a few &, << and | operations in it. Throw in a few IDs / tags for the data being manipulated and boomba, the line is > 80 columns long (I tend to stick to an 80 column line).

I can split the line up into multiple real lines, but then I have to introduce a temp variable or more.

Just wondering if there was a token such as "\" (commonlu used) to indicate continuation of the current line ? No worries if there isn't, I will just split the line up into multiple lines.

Cheers

Martin
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

I found this article in a mag. i picked up at a local Goodwill, a few months ago:

http://web.ncf.ca/ex809/ml.zip

it comes from issue #53 of kilobaud Microcomputing, back in 1983.

chris
6502dude
megacart
Posts: 1581
Joined: Wed Dec 01, 2004 9:53 am

Post by 6502dude »

Atrai (ugh) site has a couple of very basic ML books online by Richard Mansfield

a) Machine Language for Beginners

http://www.atariarchives.org/mlb/

b) The Second Book of Machine Langauge

http://www.atariarchives.org/2bml/

Better and more technical books are:

6502 Assembly Langauge Programming - by Lance Leventhal

and Programming the 6502 - by Rodnay Zaks (3rd edition or later)

Best way to learn is have references available and write your own stuff.

www.6502.org is great site and has plenty of info
idrougge
Vic 20 Hobbyist
Posts: 100
Joined: Wed Oct 06, 2004 8:57 am

Post by idrougge »

What's the difference between the different editions of Zaks's book?
C128, C128D, C64, C64C, ABC80, ABC800, ABC806, 130XE, ZX81, Spectrum 48k, Dragon 32, TI99/4A, Laser 200, Spectravideo 328, Sord M5, VIC20...
Post Reply