peek(197) & more

Basic and Machine Language

Moderator: Moderators

Post Reply
edinky
Vic 20 Newbie
Posts: 18
Joined: Sat Apr 07, 2018 10:34 am

peek(197) & more

Post by edinky »

Hi there!

I'm well on my way to coding my first vic 20 game. Currently I'm writing the framework in basic (nearly done) before trying to move over to assembly so I can begin saving space and detailing out the game experience with more detail, sound and graphics. I'm aiming for unexpanded if I can.

I read the Butterfield Machine Language book, and now reading Mastering the Vic 20. I'll probably have loads of questions along the line so looking forward to getting to know you guys in this awesome little community!

For the moment, I have two questions to keep me going:

I'm retrieving the keycode by peek(197) and it looks like I'm getting:

1: 0
2: 56
3: 1
4: 57
5: 2
6: 58

etc..

i'm using cbm studio.. its kinda annoying having to remap each result.

is this normal? it doesnt seem so in some books and I've been looking for keycode mappers online but can't find one that confirms this?

also another random question: is there a way of shifting the CBM key in the vice emulator?

I'm also considering learning some C so I can use the 6502 compiler. Is this worth it or should I just stick to assembly in CMB prg?

Thanks!!!!

(windows)
User avatar
eslapion
ultimate expander
Posts: 5037
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Re: peek(197) & more

Post by eslapion »

edinky wrote:I'm retrieving the keycode by peek(197) and it looks like I'm getting:

1: 0
2: 56
3: 1
4: 57
5: 2
6: 58

etc..

i'm using cbm studio.. its kinda annoying having to remap each result.
Remap?

What you listed there matches exactly what's on page 179 of the VIC-20 Programmer's reference guide.

There's no remap...
Be normal.
groepaz
Vic 20 Scientist
Posts: 1228
Joined: Wed Aug 25, 2010 5:30 pm

Re: peek(197) & more

Post by groepaz »

I'm also considering learning some C so I can use the 6502 compiler. Is this worth it or should I just stick to assembly in CMB prg?
while C _can_ be useful on small platforms like vic20, they are really a bad platform for _learning_ C. dont do that - use a C-compiler on your PC. also to use C effectively on such small platforms, you really need to have a good understanding of the platform itself, the constraints and limits of the compiler, and how to decide what things should go into custom assembly functions and what can be kept in C code.

ie: for a start - learn assembly, you will need it :)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
beamrider
Vic 20 Scientist
Posts: 1456
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: peek(197) & more

Post by beamrider »

I think learning C is useful exercise in itself and a much nicer and more readable language than BASIC and more powerful - I wrote tank battalion in C and Misfit's games also are written in it. C will also be a good foundation for most other modern languages such as Javascript or c#.

Learning the basics of C outside of the Vic is probably a good idea but I don't see why you would necessarily need to learn assembly first. 6502 can be very tedious and take a long time to see meaningful results with plenty of head scratching.

Also see this post as a possible jump-start to producing fairly high end games on the Vic with a minimum of effort.
edinky
Vic 20 Newbie
Posts: 18
Joined: Sat Apr 07, 2018 10:34 am

Re: peek(197) & more

Post by edinky »

eslapion wrote:
edinky wrote:I'm retrieving the keycode by peek(197) and it looks like I'm getting:

1: 0
2: 56
3: 1
4: 57
5: 2
6: 58

etc..

i'm using cbm studio.. its kinda annoying having to remap each result.
Remap?

What you listed there matches exactly what's on page 179 of the VIC-20 Programmer's reference guide.

There's no remap...
hah ok will have to put that on my reading list so! thanks!
edinky
Vic 20 Newbie
Posts: 18
Joined: Sat Apr 07, 2018 10:34 am

Re: peek(197) & more

Post by edinky »

beamrider wrote:I think learning C is useful exercise in itself and a much nicer and more readable language than BASIC and more powerful - I wrote tank battalion in C and Misfit's games also are written in it. C will also be a good foundation for most other modern languages such as Javascript or c#.

Learning the basics of C outside of the Vic is probably a good idea but I don't see why you would necessarily need to learn assembly first. 6502 can be very tedious and take a long time to see meaningful results with plenty of head scratching.

Also see this post as a possible jump-start to producing fairly high end games on the Vic with a minimum of effort.
thanks for the advice guys. i work with c#, also learning c++ at the moment. didnt mean to but looks like i'm learning backwards chronologically!
Kakemoms
Vic 20 Nerd
Posts: 722
Joined: Sun Feb 15, 2015 8:45 am

Re: peek(197) & more

Post by Kakemoms »

edinky wrote:
beamrider wrote:I think learning C is useful exercise in itself and a much nicer and more readable language than BASIC and more powerful - I wrote tank battalion in C and Misfit's games also are written in it. C will also be a good foundation for most other modern languages such as Javascript or c#.

Learning the basics of C outside of the Vic is probably a good idea but I don't see why you would necessarily need to learn assembly first. 6502 can be very tedious and take a long time to see meaningful results with plenty of head scratching.

Also see this post as a possible jump-start to producing fairly high end games on the Vic with a minimum of effort.
thanks for the advice guys. i work with c#, also learning c++ at the moment. didnt mean to but looks like i'm learning backwards chronologically!
Well, some people don't like machine language, but if you are really up to the task of learning the most efficient way of making code for a computer with only 5KiB, assembly is certainly the way to go. C++ has too much overhead for my taste, so a RAM expansion will be needed for (most) programs.

I used C++ and other object oriented languages at the university. They are nice to make larger programs, but if you are really at scratch, I would start with small assembly routines and integrated them into your basic program.

A really good programming environment is CBM programming studio, which can be found here: http://sleepingelephant.com/ipw-web/bul ... =14&t=5019

If you want to see what can be achieved with assembly, check out my small mouse pointer and driver for the unexpanded Vic-20.
User avatar
beamrider
Vic 20 Scientist
Posts: 1456
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: peek(197) & more

Post by beamrider »

Obviously machine code is best but if you are results focused rather than an efficiency zealot, then C especially with a sprite library and memory expansion will get you comparable(ish) results much faster. I'd say it takes about 5+ times more development time in assembly compared to C. Also the code is much more readable and maintainable than either BASIC or 6502. C++ is a different matter, I don't even think there is a compiler for the Vic.
Kakemoms
Vic 20 Nerd
Posts: 722
Joined: Sun Feb 15, 2015 8:45 am

Re: peek(197) & more

Post by Kakemoms »

beamrider wrote:Obviously machine code is best but if you are results focused rather than an efficiency zealot, then C especially with a sprite library and memory expansion will get you comparable(ish) results much faster. I'd say it takes about 5+ times more development time in assembly compared to C. Also the code is much more readable and maintainable than either BASIC or 6502. C++ is a different matter, I don't even think there is a compiler for the Vic.
https://github.com/puppeh/gcc-6502
User avatar
beamrider
Vic 20 Scientist
Posts: 1456
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: peek(197) & more

Post by beamrider »

see: http://www.6502.org/tools/lang/


"A port of the Gnu Compiler Collection to the 6502 processor family, also including the semi65x command line 6502 simulator. See also this support project. Described as a work in progress and not yet free of bugs."
groepaz
Vic 20 Scientist
Posts: 1228
Joined: Wed Aug 25, 2010 5:30 pm

Re: peek(197) & more

Post by groepaz »

to use that gcc port you'll *really* have to know what you are doing, including how to spot (and circumvent) the many compiler bugs :)

with cc65 on the other hand... it produces not so great code, especially not if you dont know what to take care of. it'd be challenging to make anything non trivial with it that works on a stock vic20.
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
malcontent
Vic 20 Hobbyist
Posts: 128
Joined: Sun Dec 26, 2010 1:51 pm

Re: peek(197) & more

Post by malcontent »

The number you get from the poke 0-64 (64 being no key pressed) you put in either x or y regs and use lda $ec5e,x (unshifted decode table) to convert to PETSCII. The quirky numbers are a result of how the keyboard is wired. Remember it's PETSCII that is returned, not screen codes, so it is expected that the kernal will also print it, as opposed to you just poking it to the screen.

But in BASIC just use GET.

You detect shift and C= yourself (too lazy to keep looking at manuals, it's some other ZP location) then use the tables 64 or 128 bytes past that first table, respectively.
Post Reply