How to compile assembly with a basic start line?

Basic and Machine Language

Moderator: Moderators

User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

How to compile assembly with a basic start line?

Post by Witzo »

I've mucked about in Power20's monitor, but it's about time I learn to use a proper macro assembler.
I'm using Aart Bik's 6502 cross assembler:
http://www.aartbik.com/MISC/c64.html

I got my first hello world running by changing his C64 example to an unexpanded VIC available memory location (Yay!).

Code: Select all

chrout  .equ   $ffd2   ; kernal addresss

main    .org   $1200   ; start at free RAM
        ldx    #0
loop    lda    text,x
        jsr    chrout    
        inx
        cpx    #11
        bne    loop 
        rts
text    .byte  "HELLO WORLD"
And then I start it with sys4608.
Start at $1200 is a rather random place I chose, for lack of knowledge of efficient memory usage.

Now I'd like to have a basic line with:
10 sys[whatever the closest address is after this line]

Aart gives an example for the C64:

Code: Select all

;
; encode SYS 2064 line in BASIC program space
;
        .org  $0800                          
        .byte $00 $0c $08 $0a $00 $9e $20 $32
        .byte $30 $36 $34 $00 $00 $00 $00 $00
lab2064 jmp main
But I don't manage to change that into something that works for an unexpanded VIC.
I've tried .org at $1000 and $1001, with the number after 'sys' changed to #4112. And some other combinations. But I get a screwed-up basic line.

What should it be?
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: How to compile assembly with a basic start line?

Post by Mike »

The example of the BASIC stub which is given in the instructions of this assembler has several issues.

The start of BASIC programs on the C64 is $0801, not $0800, and a file which is loaded with ',8' as BASIC program does not contain the 0 placed at $0800. As this is not honoured here, the result needs to be loaded with ',8,1' instead, which we don't want.

On an unexpanded VIC-20, the correct *.prg start address is $1001. If you want, say, '2012' as line number (to indicate the production year), and add another space behind the SYS statement for a nicer layout, you get:

Code: Select all

$0C $10         ; link to next line, pointing to: --+
$DC $07         ; line number, 2012                 |
$9E             ; "SYS"                             |
$20             ; space                             |
$34 $31 $31 $30 ; "4110"                            |
$00             ; end of line                       |
$00 $00         ; end of program <------------------+
resulting in (for this assembler):

Code: Select all

        .org  $1001                          
        .byte $0C $10 $DC $07
        .byte $9E $20 $34 $31 $31 $30
        .byte $00 $00 $00
lab4110 inc $900F ; ** increment background/border VIC register
        rts
which should be assembled with the '-r' option, 'raw bytes format (with header)', i.e. *.prg with load address.

Greetings,

Michael
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

Thanks, it works and I have made notes of everything.
Looked like I was reaching too high for a moment, thinking I could just understand how basic calls machine language like that, haha.

For completeness and other newbies like me, here's the whole hello-world-including-basic-start as it works for Aart Bik's compiler, on a Mac, using Power20:

Code: Select all

chrout  .equ   $ffd2   ; kernal addresss

;	2012 SYS 4110
        .org  $1001                          
        .byte $0C $10 $DC $07 
        .byte $9E $20 $34 $31 $31 $30 
        .byte $00 $00 $00 
lab4110 jmp main			; after basic start line
						; machine code starts at $100e = #4110

main    ldx    #0
loop    lda    text,x
        jsr    chrout    
        inx
        cpx    #11
        bne    loop 
        rts
text    .byte  "HELLO WORLD"
compile with:
>./mac2c64 -r hw.s
This gives hw.rw, which can be dragged into Power20's D64-window.
Doubleclick and it runs on an unexpanded VIC.
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

For unexpanded Vics you may save a byte with this code:

Code: Select all

;   2012 SYS4109
        .org  $1001                         
        .byte $0B $10 $DC $07
        .byte $9E $34 $31 $30 $39
        .byte $00 $00 $00 
For 3K vics you may use this code:

Code: Select all

;   2012 SYS1037
        .org  $401                         
        .byte $0B $04 $DC $07
        .byte $9E $31 $30 $33 $37
        .byte $00 $00 $00 
And for For 8K or plus vics you may use this code:

Code: Select all

;   2012 SYS4621
        .org  $1201                         
        .byte $0B $12 $DC $07
        .byte $9E $34 $36 $32 $31
        .byte $00 $00 $00 
Mega-Cart: the cartridge you plug in once and for all.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

nbla000 wrote:[...] you may save a byte with [...]
Fine. It saves the byte for a space I inserted on purpose ...
Mike wrote:[...] behind the SYS statement for a nicer layout, [...]
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

Mike wrote:
nbla000 wrote:[...] you may save a byte with [...]
Fine. It saves the byte for a space I inserted on purpose ...
Mike wrote:[...] behind the SYS statement for a nicer layout, [...]
Hi Mike, it was just an introduction to post a sample for 3k and 8k+ programs too :wink:
Mega-Cart: the cartridge you plug in once and for all.
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

All you replies are much appreciated!
I've started reading the book http://www.brucesmith.info/C64.html and managed to translate the monitor-written machine code for a scroll text I once made on the VIC, into something that compiles in mac2c64.
User avatar
darkatx
Vic 20 Afficionado
Posts: 471
Joined: Wed Feb 04, 2009 2:17 pm
Location: Canada

Post by darkatx »

I have a confession to make...I'm as sharp as a bag of rocks.
Been trying to use CC65 with the same program for about 3 days now and well...if it wasn't for this thread or forum I'd have been banging my head upon this eternally.
Thanks so much - now I can continue with my ambitious project. :)
Learning all the time... :)
User avatar
buzbard
Vic 20 Devotee
Posts: 213
Joined: Sun Jul 03, 2005 9:10 am

Post by buzbard »

Here's a DASM BASIC stub I wrote for any VIC memory configuration:

Code: Select all

;DASM VIC20 BASIC stub
          processor 6502

					;Use only one of these
					;org $401  ;3k
               ;org $1001 ;Unexpanded
					;org $1201 ;8k+

BASICstub dc.w nxt_line    ; Calculate pointer to next BASIC line
          dc.w 2012        ; BASIC Line# (change this to any # you want)
          hex 9e           ; BASIC token for SYS
       if ml_start         ; If ml_start hasn't been defined, skip it for now
          dc.b [ml_start]d ; ML start address (use any address you like here)
       endif
          hex 00           ; End of BASIC line
nxt_line  hex 00 00        ; The next BASIC line would start here

ml_start      ;Start your ML code here.
The SYS address will be automatically calculated to wherever the "ml_start" label is located in your code.
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

Useful code, thanks.
Mega-Cart: the cartridge you plug in once and for all.
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

Thanks for the advice, it was one of the things I needed to make my first VIC demo in assembly:

http://raoulm.home.xs4all.nl/products/D ... ll.D64.zip

Image

A scroll text made by shifting the lower lines of the screen 4 and 8 pixels to the right and back.

Apologies for the sloppy code; it grew as a I went along and this was my first time with a cross assembler.
I'm pretty happy that I finally managed to do a thing like this :D
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Witzo wrote:my first VIC demo in assembly
Nice! :)

You've surely found out, that the horizontal positioning register of the VIC (with its 4 pixel granularity) does not exactly allow for soft-scrolling.

Instead, you could realise the banner as small bitmap with 22 redefined characters + 1 hidden char to the right. Starting with the hidden char you do 1x ASL + 22x ROL over each of the 8 lines of the bitmap. The 6502 is fast enough for this. You refresh the hidden char every 8 steps. If you sync this to the screen refresh, you get a nice soft-scroll, even if it is done in a different way to the C64.

P.S.: Thank you for the greetings. :)
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

That sounds like a good next try!
I have yet to start on hires graphics on the VIC. My understanding is that I can change the 256 symbols in the charmap and then distribute them over the 506 places on the screen where I want a picture.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

POKE 36869,255

Post by Mike »

You may start off with POKE 36869,255 on an unexpanded VIC-20. This gives you 64 user defined characters from 7168 to 7679 to toy with. You should protect this range from BASIC with POKE55,0:POKE56,28:CLR in the first line of your programs.

One nice feature of this POKE is that it allows access to the original (non-inverted) upper-case character set by PRINTing characters in inverse. :)

For an example, take a look at MOON PATROL.
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

I managed to do that!

Top left is a kind of bull face that I designed in 1986 but didn't know how to actually draw on the screen. I also had to fix some embarrassing mistakes in the bit values...

Image
Post Reply