Petscii strings in Vasm

You need an actual VIC.

Moderator: Moderators

Post Reply
charles92027
Vic 20 Newbie
Posts: 8
Joined: Tue Jun 14, 2022 12:57 pm
Location: California
Occupation: software engineer

Petscii strings in Vasm

Post by charles92027 »

When I declare a string of bytes in vasm, using the .byte directive, it assumes the characters are ascii

Code: Select all

	.byte “HELLOWORLD”, $00	; 11 bytes
but, I obviously want petscii codes, so everything has to be encoded:

Code: Select all

	;     H    E    L    L    O    W    O    R    L    D
	.byte $08, $05, $0C, $0C, $0F, $17, $0F, $12, $0C, $04, $00	; 11 bytes
Does anyone know of a directive, or command-line flag, for vasm, that will make it use petscii for byte strings?
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Petscii strings in Vasm

Post by chysn »

For most uppercase textual strings, PETSCII and ASCII are likely to be the same. Certainly that's the case for "HELLOWORLD" where PETSCII and ASCII values intersect.

I use XA's .asc pseudo op for text, and it works fine with uppercase letters, numbers, punctuation, since both character sets overlap; but for other things I create labels and use them in the data table:

Code: Select all

RVS_ON      = $12               ; Reverse on
RVS_OFF     = $92               ; Reverse off
; Then later...
    .asc RVS_ON,"SCORE=",RVS_OFF
However, note that you're not asking for PETSCII, you're asking for Commodore screen codes.

Code: Select all

.byte $08, $05, $0C, $0C, $0F, $17, $0F, $12, $0C, $04, $00	; 11 bytes
I don't know VASM, but I know that no ASCII-to-screen code conversion pseudo op exists in XA. Consider making your own set of labels in a separate included file to ease the process, like

Code: Select all

A = $01
B = $02
; etc...
Z = $1a
;then
.byte H,E,L,L,O," ",W,O,R,L,D
That would at least make screen code entry more easily writable and the code more readable. The screen codes for some characters, including space, intersect with PETSCII, so those can be inserted as literals.

Shameless self plug: My own wAx assembler cartridge has syntax for assembling screen code data with a prefixed /

Code: Select all

.A 1800 /"HELLO, WORLD!"
But, this is a native VIC-20 assembler and not a cross assembler. I'm always mulling the idea of a cross assembler version, though.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Petscii strings in Vasm

Post by Mike »

For completeness, one should add that the OP (likely) refers to the cross-assembler vasm as found here:

http://www.compilers.de/vasm.html

There also exists a native VIC-20 assembler called VASM (download: http://www.zimmers.net/anonftp/pub/cbm/ ... ogramming/):
zimmers.net wrote:VASM is a VIC-20 assembly language environment featuring a full-screen editor, TASM-like error-notification and a two pass assembler. It is key-compatible with TASM for the subset of commands it supports to avoid brainfarts. The only requirement is that you have at least a 16k RAM expansion. Source code included (under the GNU General Public License). See [...] for the Siders homepage.
(the given URL is defunct)
charles92027 wrote:[...]
As chysn already wrote, on 8-bit CBMs you need to differentiate between PETSCII and screen codes. PETSCII was derived from an early ASCII standard and especially has lower and upper case switched around in comparison to today's 7-bit ASCII.

It is somewhat unlikely that a multi-platform cross-assembler like vasm has built-in support specifically for CBM 8-bit screen codes, but then, a "Hello World!" program can also easily be implemented with KERNAL CHROUT (JSR $FFD2).
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Petscii strings in Vasm

Post by chysn »

Mike wrote: Sun Jun 26, 2022 5:30 am There also exists a native VIC-20 assembler called VASM (download: http://www.zimmers.net/anonftp/pub/cbm/ ... ogramming/):
Unfortunately, I haven't been able to get this working. The edit screen comes up, but it immediately crashes. No data table pseudo-ops are mentioned in the documentation, only a single byte or word at a time. This seems like something that the author intended to complete some day, but probably life got in the way.
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 174
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: Petscii strings in Vasm

Post by MrSterlingBS »

I also use VASM. But only because it is included in the Chibi development environment.
https://www.chibiakumas.com/6502/
The text string can be entered a little easier.
See attached code.

I hope this helps.

Best regards
Sven

Code: Select all

TextColor				equ $18
TextPointerLow				equ $20
TextPointerHigh 			equ $21

PosLow					equ $22
PosHigh					equ $23

ColorPosLow				equ $24
ColorPosHigh				equ $25
YPosTemp					equ $30

*=$1201
        dB	$0B, $12, $0A, $00, $9E
		dB	$38, $31, $39, $32			; SYS8192 = $2000
		dB	$00, $00, $00
*=$2000

        	sei
		jsr $E55F		; clear screen
		
		lda #>HelloWorld		;Load address of message into Zeropage $20/1
		sta TextPointerHigh
		lda #<HelloWorld
		sta TextPointerLow
		
		lda #$02				; Load color - red
		sta TextColor

		ldy #5					; x-Position
		tya
		sta YPosTemp
		ldx #3					; y-Position

		jsr PrintText
		
		jmp *
		
PrintText:
		lda screenLo,x		
		adc YPosTemp
		sta PosLow				
		sta ColorPosLow
		lda screenHi,x		
		sta PosHigh				
		adc #$84
		sta ColorPosHigh
PrintStr:
        	ldy #0						;Reset Y
PrintStr_again:
        	lda (TextPointerLow),y		;Read in a character
		cmp #255
        	beq PrintStr_Done			;Return if we've reached a 255
		cmp #$40					; text char > #$40 (64)
		bcc charokay				; yes, then print
		sec							; set carry
		sbc #$40					; minus #$40 (64)
charokay:				
        	sta (PosLow),y				;Print to screen
        	lda TextColor
        	sta (ColorPosLow),y		
        	iny
        	jmp PrintStr_again			;repeat
PrintStr_Done:						;Return when done			
        	rts
	
HelloWorld:
	db "HELLO WORLD !!!"
	db 255

screenLo:
		DB $00,$16,$2C,$42,$58,$6E,$84,$9A,$B0,$C6,$DC,$F2,$08,$1E,$34,$4A,$60,$76,$8C,$A2,$B8,$CE,$E4		
screenHi:
		DB $10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11
Post Reply