Druzyek wrote:
Could you use a macro to declare all the strings inline for readability but put their actual declaration somewhere else like a compiler does? Something like this:
Code:
Print .macro msg
???
.endm
Print "Hello!"
Print "Test"
After expansion:
Code:
LDA #<str1
LDX #>str1
JSR print_sub
LDA #<str2
LDX #>str2
JSR print_sub
...
str1: .DB "Hello!"
str2: .DB "Test"
Not 100% sure about doing it via a macro, however if using ca65 then you can use separate data and code segments, however it will require writing a suitable config file for it and arranging the loader (or eprom burner) to work out where to put the sections.. So:
Code:
.code
ldx #>msg1
ldy #<msg1
jsr strout
.data
msg1: .byte "Hello, world",13,10,0
.code ; Back to the code segment
... more 6502 program code here
This is almost exactly what happens behind the scenes when using cc65 (and other C compilers on operating systems such as Unix/Linux, etc.) It then becomes the linkers problem to work out how to create a file that the loader can recognise and put the sections into the right place in RAM or ROM.
I've had a look at the macro features of ca65 and I'm not sure it can do that though - however if you were clever with something like m4 (that runs under Unix/Linux, etc.) then it's possible - you effectively divert the generated output (ie. the string data) into a temporary file as part of your PRINT macro, then you need an ending macro that pulls the diverted text into the main document at the end. It should be possible to write a macro that uses the segments though - let me check... I don't think so.
It looks like you can change segments - that's fine, but can't change segments inside a macro - at least not with ca65
This is my test file:
Code:
strout = $F000 ; Faking it
.org $1000
;
; .macro print string
; .code
; ldx #>:+
; ldy #<:+
; jsr strout
; .data
;:
; .asciiz string
; .code
; .endmacro
;
;
; print "Hello, world"
; print "Another test"
;
;
.code
ldx #>:+
ldy #<:+
jsr strout
.data
:
.asciiz "Hello World"
.code
ldx #>:+
ldy #<:+
jsr strout
.data
:
.asciiz "Another Test"
And the assemble & link commands if you want to test it:
Code:
ca65 -g --cpu 65c02 -l test2.lst test2.s
ld65 -t none -S 0x1000 -vm -m test2.map -o test2 test2.o
the one using the macros gets the output file in the right order, but has the wrong addresses for the ldx & ldy instructions. This may well be a bug in ca65 though.
So have a look at the .lst and .map files and comment out the bottom and un-comment the top to experiment.
.... but before I hit submit, I did a few more tests and it looks like you CAN use the macros, however only if you keep it all relocatable until the link state, so no .ORG in the source file, but keep that -S 0x1000 (or whatever) in the link command.
So using the macros, assembling, linking to $1000 (the data segment follows on), the hex output file looks like:
Code:
000000 a2 10 a0 0e 20 00 f0 a2 10 a0 1b 20 00 f0 48 65 >.... ...... ..He<
000010 6c 6c 6f 2c 20 77 6f 72 6c 64 00 41 6e 6f 74 68 >llo, world.Anoth<
000020 65 72 20 74 65 73 74 00 >er test.<
Which has the offset for the first string at $100e which looks correct... the map file is somewhat confusing, but the relevant lines are:
Code:
Name Start End Size Align
CODE 001000 00100D 00000E 00001
DATA 00100E 001027 00001A 00001
Now all you need do is create the right config file for cc65 and a loader that can read the .map file and you're there
Cheers,
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/