P65 vernacular

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
P65 vernacular
by on (#22058)
I've been tooling around with P65 as an assembler (python version) and though it doesn't seem many of you use it, I thought you might be able to help me sort out some of the assembler-specific 'language' it uses. For instance, in the NES 101 tutorial, there is the following code:

Code:
; Allocate memory in the zero page segment
.segment zp
.org $0000
.space dx 1
.space a 1
.space scroll 1


.org makes sense as a memory starting address, but the .segment and .space directives don't make much sense to me, and the P65 documentation isn't much help.

I am similarly in the dark about .word and .text. For example:

Code:
; Actual program code.  We only have one PRG-ROM chip here, so the
; origin is $C000.
.text
.org $C000


I understand what this is doing, but not why .text is used.

Anyone have any input on this?

by on (#22065)
The CA65 toolchain also uses segments; see its manual's section 5.2 on segments. See also GNU Assembler Manual: Sections to see the rationale behind "sections", the name under UNIX for segments.

Under a typical CC65 configuration, there are a couple standard segments for variables that start at a given value: RODATA for constant data that should stay in ROM and DATA for data copied from ROM to RAM at reset. There are also a couple standard segments for variables that are simply cleared at reset: ZP for variables in $00-$FF and BSS for variables in $0200-$07FF or $6000-$7FFF depending on the board you described in the linker script.

by on (#22236)
http://hkn.berkeley.edu/~mcmartin/P65/ref.html

that's where the p65 documentation for directives is.

Code:
.space dx 1


this sort of sets aside one byte of space that you can refer to as "dx" later on. in nes101 it's used to basically declare dx as a variable. you can use higher numbers if you need more bytes. in nes101 the author uses "FF" in that space to mean the diamond moves to the left and "01" to mean the diamond moves to the right.

.word defines a 16-bit area of memory. i.e.

Code:
.org $200
.word $FF00

this makes the first 16 bits of page two read 1111111100000000.


on the other hand i am a beginner so i could be totally wrong.