View Source for *.PRG

You need an actual VIC.

Moderator: Moderators

Post Reply
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

View Source for *.PRG

Post by Legacy »

how is this accomplished? changing *.prg into readable code :o
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: View Source for *.PRG

Post by nippur72 »

Legacy wrote:how is this accomplished? changing *.prg into readable code :o
that can be done with a disassembler, like the da65 contained in the "cc65" compiler.

Edit: if the .prg code is a basic program, just do a LIST command on the vic after loading the file.
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

would you mind explaining how to get cc65 up and running please? :D :D thank you!
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Post by nippur72 »

da65, the disassembler for the 6502 CPU, is a command line tool contained in the cc65 package, so you simply run it from the command prompt.

Anyway disassembling a .prg isn't a one-step process. It's something like this: you disassemble a first time and look at the generated (readable) code. Then you identify machine code and data and disassemble again. Repeat the process several times untill all data and machine code are separated.

Might I suggest, if you just want to have a quick look a .prg, use the disassemble function ("D" command) of a monitor program like the one contained in the VICE emulator.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Hm, how does da65 compare to recomment? Frankly I've never thought about the cc65 package should have a disassembler included.

Legacy, what are you trying to do? If you have a Basic program you want to convert to text, use a detokenizer like "petcat", a command line tool that comes with VICE. If you have a machine code program you want to turn into assembly source for adjusting and re-assemble, you need to use the disassembler(s) mentioned above.
Anders Carlsson

Image Image Image Image Image
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

I already know how to look at BASIC source, just type the LIST command and appropriate line number , I understand VIC 20 runs on Microsoft BASIC V2.0 that is loaded directly into the systems RAM, which is why we only have 3583 BYTES available from the 5K included with the system.

Sometimes there are programs that can't be RUN/STOP . I think those are machine or assembly. I've come to the conclusion(and I'm probably wrong) the only way to get real performance out of the vic is to use assembly or ML. As you may have seen my last project included custom character sets and that was taken from the Programmers Reference Guide, and the next phase in the manual is of course HIGH RESOLUTION GRAPHICS , bit mapping , pixel plotting, etc... and there comes a point you want smooth movement of objects etc... so you make your 64x64 hi-res grid and load up the sine wave and... wow what speed! How come the demos I see look flawless, have tons of speed, and their drawing a lot more then a broken up sine wave at 1 pixel per hour? Must be assembly, right?

So essentially what I want to do is pick apart all the software I've been gathering, find useful routines, source, function calls, etc... and implement that into my own working runtime. The question is now how to dissect those programs and gather relevant data needed to accomplish this task. No problem right? - Leg

ps-nip i used the monitor D command and got hundreds of lines of assembly! there must be an easier way
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Well, the 3583 bytes free has very little to do with Basic. Depending on how you count, Basic only uses three bytes out of those plus some workspace in the lower 1K that you normally can't access.

However you're right that machine code executes much faster than Basic, which must be parsed line by line through the built-in interpreter. A middle way would be to use a Basic compiler, which generates machine code once and for all, but not as optimized as a skilled programmer would be able to do it by hand.

With runtime, you mean a machine code module called from Basic like Super Expander or why not Mike's MINI-GRAFIK? While neither of those supports software sprites, there was a discussion about writing generic such routines that I believe could be called from Basic too. Many of the routines you will find in existing programs are specialized in their task so they may be hard to lift out of their context, but you can always try.

Personally when I disassemble a machine code program, I use recomment, a Perl script best run in an Un*x environment. It generates mostly readable assembly source code in one run, for you to further take apart and enhance.

The source code, more or less a text file, is then fed through a cross assembler: DASM, ca65, xa, TASM or whichever you prefer. In theory you could work natively on the VIC-20 but it would cause you a lot of gritting teeth, in particular as you try to extract parts of code and rewrite it wherever possible.

Sorry if I may sound harsh, but how fluent are you in 6502 machine code programming? Taking routines from different places and stiching them together, preferrably with some kind of calling interface, won't be trivial. Possibly this could be a community effort, even better if you start from a known good Basic extention and improve it.
Anders Carlsson

Image Image Image Image Image
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Post by nippur72 »

Legacy, you are right, machine language is the answer to speed but I am afraid that reverse engineering isn't the best way to learn how things are done in ML.

Machine language is cryptic and obscure by its own even when it's full commented and formatted. In its disassembled form it's simply undreadable and takes lot of work and commitment before you start to understand anything.

For example: when I've disassembled the ROM dump of the cartdrige "Raid on fort knox" it took me a whole weekend of intense work (read the story here).
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

Thats what I kinda figured guys, ML , the next chapter after Graphics is Chapter 3, Machine Language Programming might as well start somewhere. But I do appreciate the help and knowledge of my questions, without people like you I would surely be lost in the dark. Thanks again and I'll be back! -Leg
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

i've been working on machine language for beginners , the online manual and im trying to get the first program to compile using dasm with little success, it seems dasm does not recognize conventions used in that book. is all assembly code diffrent, and how do i know what will work and what wont? here is the program from the instruction manual:

.BA $1000 ; START ADDR $1000 (4096)
TWO .DE 2 ;DEFINE LABLE "TWO" AS 2.
ADDER .DE 5 ;DEFINE "ADDER" AS A 5.
STORAGE .DE $0FA0 ;DEFINE STORAGE ADDR.
;
START LDA #TWO ; LOAD A WITH 2
ADC #ADDER ; ADD 5
STA STORAGE ; STORE AT DECIMAL 4000
RTS ; RETURN
.EN ; END OF ASSEMBLY

I see all the posts about Machine Language for Beginners, this cant be converted to VICmon either, so I don't know what todo, I need to be able to make real working models here, not just theory. Thank You!
Richard James
Vic 20 Devotee
Posts: 270
Joined: Mon Feb 04, 2008 6:06 am

Post by Richard James »

That code would look like this in DASM

Code: Select all

          processor 6502
          org $1000        ; START ADDR $1000 (4096)
TWO       equ 2            ;DEFINE LABLE "TWO" AS 2.
ADDER     equ 5            ;DEFINE "ADDER" AS A 5.
STORAGE   equ $0FA0        ;DEFINE STORAGE ADDR.

START     LDA #TWO         ; LOAD A WITH 2
          ADC #ADDER       ; ADD 5
          STA STORAGE      ; STORE AT DECIMAL 4000
          RTS              ; RETURN
The main differences are that the equ is the same as .DE
equ is short for equates to or is equal to
DASM uses org to mark the beginning, your code uses .BA .BA probably means Begin Assembly. DASM does not have any End assembly statement.
Change is inevitable except from a vending machine.
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

Well I got it to compile thank you, need to make sure pound (number sign) is before #processor 6502 or nothin will work. I loaded her up into the unexpanded VICE and did a SYS4096. But I can't seem to see the contents of addr 4000 and when I do a LIST command it tells me : 36101 CLOSE-Y
maybe this program wasnt intended to be run, only used as an example. but at least I know the proper syntax now , thank you Richard
Richard James
Vic 20 Devotee
Posts: 270
Joined: Mon Feb 04, 2008 6:06 am

Post by Richard James »

It won't work because BASIC clobbers the program at address $1002. It puts a $10 in place of what it should be. Also memory location 4000 is in the lower 3K RAM expansion area. If you tried it with 3K RAM expansion enabled it should work.
Change is inevitable except from a vending machine.
Post Reply