VIC20 and CBM prg Studio

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

VIC20 and CBM prg Studio

Post by mythic66 »

Hello,

I'm trying to run a quite simple asm program compiled with CBM prg, but I'm always getting an error on VICE ( unexp )

Code: Select all

;***********************************
; Test
;***********************************

*=$1100


        LDA #28
        STA $900F
        RTS
VICE give me ?Syntax Error in 3981

I even try to move this same single byte to $1200 and get the same error. It's my first step with this soft and the 6502. I have good skill with x86 asm so the coding background is there.

Any hint to put this on the right track ?

thanks.
marco.bergomi
Vic 20 Drifter
Posts: 24
Joined: Tue Mar 31, 2020 7:37 am
Location: Lodi Italy
Occupation: eng.

Re: VIC20 and CBM prg Studio

Post by marco.bergomi »

Hello,
for example: insert the 3k exp, and set the start address to: *=$0400
Or use: Tools --> Generate BASIC loader
bye.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: VIC20 and CBM prg Studio

Post by Mike »

You get the same behaviour on real hardware when you load the object file to the start of BASIC RAM (with ",8") and then (try to) RUN it. From the view of the BASIC interpreter, it is an invalid BASIC program. Some parts of it are interpreted as line number - the byte sequence $8D $0F, which is part of the STA $900F instruction, gets interpreted as $0F8D = 3981.

Some time ago, the standard autostart behaviour of VICE was changed from loading with ",8,1" ("absolute", to the original address once saved from) to ",8" ("relative", to the BASIC RAM start). That is the main reason your example does not work.

When you load the object file with ",8,1" and start the execution of the included machine code with SYS 4352, you should get the expected result: storing $28 into VIC register $900F results in a red background with black exterior border and non-inverted, i.e. normal characters. You should follow up the load procedure with NEW to correct some pointers of the BASIC interpreter.

As Marco already wrote, one method to 'harden' machine code programs against these issues is to pre-face them with a BASIC stub that includes the SYS instruction necessary to start the machine code. This way, one also does not need to remember that start address, and can simply RUN the loaded program. You find more details in the thread "How to compile assembly with a basic start line?".
User avatar
thegg
Vic 20 Amateur
Posts: 69
Joined: Mon Aug 30, 2021 4:49 am
Location: England
Occupation: retired

Re: VIC20 and CBM prg Studio

Post by thegg »

CBM prg Studio can produce the BASIC stub for you. Position the cursor just before your start address and select Tools/Generate Sys() Call from the menu bar. Then enter your code start address and OK the dialogue and hey presto the stub appears at the cursor position.
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

Re: VIC20 and CBM prg Studio

Post by mythic66 »

Thanks a lot guys for the detailed info, I was not familiar with this "stub" procedure.

I used the SYS call function as @thegg said and it works perfectly, beside that the debugger don't like it, so my
work around is to set the PC to my start address and skip the basic header.

When I'll have some more advance in my project, I'll post the details.. :wink:

Thanks Mike for the explanation, now I know where the number that the vic was spitting out come from :)
MartinC
Vic 20 Drifter
Posts: 33
Joined: Tue Oct 25, 2022 12:18 pm
Website: https://winterfam.co.uk
Location: Kent,uk
Occupation: Author

Re: VIC20 and CBM prg Studio

Post by MartinC »

Hey mythic,

Nice to know I'm not the only newbie out here :D - although, you're coming from the x86 asm world. Good luck with your project!

Martin
Post Reply