6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 9:43 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Jan 21, 2019 4:28 pm 
Offline

Joined: Fri Nov 16, 2018 8:55 pm
Posts: 71
I'm very new at this. I know that on the C64 you have to have a BASIC call your assembly and so all ASM projects have a few bytes of BASIC in them. But, it's really kind of annoying to write .byte statements that are just BASIC keywords and any parameters they need.

I'd like to clean that up using either some assembler macros or some BASIC tokenizer. I'd prefer the former but I'm open to the later.

With 64tass and Linux is it possible to build a macro that functions like a BASIC keyword? So, basically #print, "Hello World!" or #sys, "2061" or similar? Failing that, is there a tokenizer that can be leveraged to do this and "play friendly" with both the BASIC and ASM sources during the build process? I'm sure Make would be involved in this latter case, but that's fine. Lots of ASM projects use make to drive the build process.

I've used the BASIC loader as a convenient example but I know this sort of thing comes up in other contexts. Let me know if I'm going about this the wrong way, I just want clean readable code even when I have to mix in some BASIC in the process.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 21, 2019 6:11 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
There's no reason that a C64 based assembler couldn't take some raw PETSCII data, literally "type it in" to BASIC, and then extract out the tokenized result and store it in to the assembled binary.

But it's most likely not worth the effort on a cross assembler beyond simply typing what you want it to a C64, doing a memory dump, and stuffing that in your assembly with reasonable documentation.

If you do little more than add a "10 SYS 12345" call to the beginning of your program, that too would be trivial to make in to a macro.

But outside of a few select BASIC statements, it's likely not worth the effort for something more general.

You could easily make a macro like: 'PRINT 10, "Hello World"', where the 10 is the line number.

A half hour with a way to dump memory should make it pretty easy to spit out a couple of handy macros without having to copy all of BASIC. Just make some rough templates, one statement per line.
Code:
    ORG $4000 ; wherever it is BASIC program memory starts
    BASIC_PRINT 10, "Hello world!"
    BASIC_PRINT 20, "Starting up..."
    BASIC_SYS 30, MYCODE
    BASIC_END 40
MYCODE:
    LDA #0
...

You can see the BASIC_PRINT macro some line this:
Code:
    MACRO BASIC_PRINT LINE_NO, STR
    .db LINE_NO
    .db line_end ; pointer to next line
    .db $12 ; whatever the print token is
    .db $STR ; however your assembler works with strings.
$line_end:
    END_MACRO


Mind, I don't know anything about the C64. But the approach should be sound.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 22, 2019 6:02 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 674
The BASIC stump tends to just be boilerplate, so not much work goes into it. If you actually do want a few lines of BASIC, I think it's best to have that in a separate file than your asm code. Treat it as a binary blob that your machine code gets appended to.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 22, 2019 5:55 pm 
Offline

Joined: Fri Nov 16, 2018 8:55 pm
Posts: 71
White Flame wrote:
The BASIC stump tends to just be boilerplate, so not much work goes into it. If you actually do want a few lines of BASIC, I think it's best to have that in a separate file than your asm code. Treat it as a binary blob that your machine code gets appended to.


Right. I used the BASIC boilerplate as a handy example that we all have to deal with. But, some programs are written in large chunks of BASIC with optimizations in ASM. Take Pirates! for an example, if you load the game and escape it and then run the LIST command you'll see a lot of BASIC. Now, that's not all of the game's code, a good chunk of it is written in ASM as well.

If I wanted to build a project that had anything like that mix of ASM and BASIC, I'd want some other way to handle it. Thinking about how I'd handle it made me think of ASM macros that point to BASIC functions. That's probably not optimal. There are BASIC tokenizer's and detokenizers out there, the most famous of which is probably C64List, but I'm not sure I'd want to leverage that program specifically in a Make mainly because it would make my build environment dependent upon Wine.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 22, 2019 11:39 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
A reasonable option in that case is to assemble the machine code segment separately, then have the BASIC program load it into memory as part of its initialisation. The program is then two files on disk, and you can use the standard BASIC editing tools on the BASIC portion of the program. It can even be reasonable to draw a loading screen (or start off an intro demo) before loading the machine code.

On the BBC Micro, the assembler is actually part of the BASIC interpreter, but holding the source and object code in memory at the same time can be painful. There are some big games whose source code is actually several very densely-written BASIC programs specifically built to assemble parts of the object code, which are then slotted together like a jigsaw puzzle by a tiny loader program.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 23, 2019 5:59 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Back in the day, assembly was simply represented by DATA statements and POKEd in to RAM.

But for a "game", it probably made more sense to concatenate the binary to a BASIC file that was hacked and saved to disk, so when it was loaded, the binary image was loaded with the machine language already in place. But you have a real issue here if you're doing a lot of BASIC and assembly at the same time as the BASIC program RAM will start encroaching on your machine language data area.

It wouldn't be a lot to have a program that could "link" the machine language and BASIC programs together in to a single image to be loaded.

But I imagine the development process was pretty tedious going through all of the steps.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 24, 2019 5:46 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 674
load81 wrote:
There are BASIC tokenizer's and detokenizers out there, the most famous of which is probably C64List, but I'm not sure I'd want to leverage that program specifically in a Make mainly because it would make my build environment dependent upon Wine.


I would think the most used is petcat, which comes bundled in VICE, and that's certainly applicable for Make style use.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: