Jump to content
  • 0

PETSCII text in assembly best practice?


JohnGill
 Share

Question

Hi all, 

After a long time of neglect, I'm back on with my hex tiles adventure / strategy game engine that some of you may remember.  This is an update and a question please:

To generate the screen (see mock up attached to see where I'm up to with the look and feel of the thing) I'm using a 2bpp layer 0 tile map to create the hex shapes and the user interaction panel on the right, then overlaying a 4bpp tile map with the icons to create the rivers / roads / bridges / hex graphics etc. I've got the memory banks planned out now - the entire playable area is 64 x 64 hexes, made up of 32 different types of terrain, each hex with its own individual resources/attributes/roads/rivers - I've worked out a neat little system to get ALL the rivers/roads/bridges into 6 bits per hex which I'm dead chuffed with - the whole hex map now fits in 3 x 8k memory banks.

I have got a working scrolling hex-map explorer routine working in assembly that just updates the colour attributes of layer 0 to "move" the hexes around, but I'm still VERY much an assembly noob, just reading up on instructions here and there to get something working on screen, so I've got no good "overview" of assembly coding in general.

I need to code up lots and lots of messages that will be required  - (example in screenshot) - this strategy/resource management/adventure game is going to have a large dollop of text-adventure flavour. At the moment, I'm using CBM PRG studio to hard code the binary files, entering text as tile index/attribute byte pairs (see second screen shot below) and exporting it to a bin file to load directly into VRAM / RAM banks as appropriate. And whilst this is working for me, typing in "byte 01,$0F" just to display the letter A on screen is a complete and utter BALLACHE (please excuse the language!) - it'll take until Christmas just to enter all the text....

 

tl/dr: please can someone tell me there's a better way of getting text into the assembler!!

Many thanks in advance.

John

screen mockup with layer 1 overlay.png

CODE1.png

  • Like 1
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Yes there is. I'm probably not able to code this out of my head right now, but all 6502 assemblers support converting ascii to petscii strings like this.

Label:        .byte "Hello World",0

You then have the string 'Hello World' followed by a NULL byte at address 'label'.

Then you can set the X register to 0 and walk over the string:

loop:
lda (Label), x
clc
cmp #$00
beq loopend
sta (VeraPort)
lda #$0F
sta (VeraPort)
inx
jmp loop
loopend:
...

I hope I got this about right. This code is untested.

Edited by Sandmage
  • Like 1
Link to comment
Share on other sites

  • 0
44 minutes ago, Sandmage said:

Yes there is. I'm probably not able to code this out of my head right now, but all 6502 assemblers support converting ascii to petscii strings like this.

Label:        .byte "Hello World",0

You then have the string 'Hello World' followed by a NULL byte at address 'label'.

Then you can set the X register to 0 and walk over the string:

loop:
lda (Label), x
clc
cmp #$00
beq loopend
sta (VeraPort)
lda #$0F
sta (VeraPort)
inx
jmp loop
loopend:
...

I hope I got this about right. This code is untested.

thanks for this Sandmage, much appreciated

  • Like 1
Link to comment
Share on other sites

  • 0
Hi all, 
After a long time of neglect, I'm back on with my hex tiles adventure / strategy game engine that some of you may remember.  This is an update and a question please:

To generate the screen (see mock up attached to see where I'm up to with the look and feel of the thing) I'm using a 2bpp layer 0 tile map to create the hex shapes and the user interaction panel on the right, then overlaying a 4bpp tile map with the icons to create the rivers / roads / bridges / hex graphics etc. I've got the memory banks planned out now - the entire playable area is 64 x 64 hexes, made up of 32 different types of terrain, each hex with its own individual resources/attributes/roads/rivers - I've worked out a neat little system to get ALL the rivers/roads/bridges into 6 bits per hex which I'm dead chuffed with - the whole hex map now fits in 3 x 8k memory banks.

I have got a working scrolling hex-map explorer routine working in assembly that just updates the colour attributes of layer 0 to "move" the hexes around, but I'm still VERY much an assembly noob, just reading up on instructions here and there to get something working on screen, so I've got no good "overview" of assembly coding in general.
I need to code up lots and lots of messages that will be required  - (example in screenshot) - this strategy/resource management/adventure game is going to have a large dollop of text-adventure flavour. At the moment, I'm using CBM PRG studio to hard code the binary files, entering text as tile index/attribute byte pairs (see second screen shot below) and exporting it to a bin file to load directly into VRAM / RAM banks as appropriate. And whilst this is working for me, typing in "byte 01,$0F" just to display the letter A on screen is a complete and utter BALLACHE (please excuse the language!) - it'll take until Christmas just to enter all the text....
 
tl/dr: please can someone tell me there's a better way of getting text into the assembler!!

Many thanks in advance.
John

686674933_screenmockupwithlayer1overlay.thumb.png.74e94c38c29d0e838b9a90b3ac19ed84.png

CODE1.png.22176675a395558bed8ab36bcf5606cb.png

That’s looks GReAt! I want to play it....

So the cc65 assembler supports the .asciiz control code.

https://www.cc65.org/doc/ca65-11.html#ss11.5

I am by no means any kind of assembly expert, I think this is what your looking for.


Sent from my iPad using Tapatalk
  • Like 1
Link to comment
Share on other sites

  • 0
On 6/27/2020 at 5:06 AM, Sandmage said:

Yes there is. I'm probably not able to code this out of my head right now, but all 6502 assemblers support converting ascii to petscii strings like this.

Label:        .byte "Hello World",0

You then have the string 'Hello World' followed by a NULL byte at address 'label'.

Then you can set the X register to 0 and walk over the string:

loop:
lda (Label), x
clc
cmp #$00
beq loopend
sta (VeraPort)
lda #$0F
sta (VeraPort)
inx
jmp loop
loopend:
...

I hope I got this about right. This code is untested.

I have some optimizations:

  • You don't need CLC and CMP. LDA already sets the Z flag if the byte is zero.
  • You can have the color byte stored in the Y register, using an STY instead of an LDA/STA pair.
  • The JMP can be replaced with a BRA to save one byte.

Also note that in 6502 ASM, parentheses are used for indirect addressing. The "LDA Label,X" instruction uses the "absolute,X" mode, and the two store instructions use the "absolute" mode to affect $9F23/$9F24 (VERA data port 0/1).

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use