How to start programming in ML
Moderator: Moderators
How to start programming in ML
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
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!
Only NERDS use signatures on forums......
....dam it!
ML programming
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.
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.
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.
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
- Mike
- Herr VC
- Posts: 4817
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Logic errors
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.carlsson wrote:Yup. It is really progress. Logic errors however, I have not found any remedy for.
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
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%
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
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
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
ACME macro
Yep you can do that - in acme macros have the format
!macro <macroname> , [<param> , ...] {
line1
line2
....
}
have fun!
!macro <macroname> , [<param> , ...] {
line1
line2
....
}
have fun!
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
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
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
http://web.ncf.ca/ex809/ml.zip
it comes from issue #53 of kilobaud Microcomputing, back in 1983.
chris
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
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