Print String

Posts about Z80 programming that do not relate to a particular computer
Post Reply
Kog
Posts: 2
Joined: Mon May 23, 2022 10:29 pm

Print String

Post by Kog » Tue May 24, 2022 11:59 am

Hi,

For some reason this doesn't work, compiling for game gear

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ifdef vasm
include "\SrcALL\VasmBuildCompat.asm"
else
read "\SrcALL\WinApeBuildCompat.asm"
endif
read "QuickHeader.asm"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Start Your Program Here
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


msg: db 'v',255 ;255 terminated string
ld hl, msg

call PrintString ;Print Message
halt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; End of Your program
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

read "QuickFooter.asm"


Cant really understand why my program crashes with a small v works with capital V or with a space in front of it, its a bit advanced for me to debug

Thanks in advance

Keith

User avatar
akuyou
Posts: 562
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Print String

Post by akuyou » Tue May 24, 2022 12:23 pm

Your 'V' text is in the same part as the program as your code.

The Z80 is trying to run it, and it's causing a crash.

You need to put it somewhere the CPU will never run - for example after the HALT.

Oh, the tabs were a bit messed up in the code comment, but that may just be a copy-paste issue.
Remember, anything at the far left will be considered a comment - indented will be treated as commands.

working example attached
Attachments
IWorkNow.asm.zip
(439 Bytes) Downloaded 188 times
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Kog
Posts: 2
Joined: Mon May 23, 2022 10:29 pm

Re: Print String

Post by Kog » Tue May 24, 2022 4:16 pm

Yeah sorry i was trying to simplify my code to post is this the best way todo a switch statement

Code: Select all

;This is a place for program code - don't put any data here
	ld a, 0
	cp 0
	call z, loadmsg
	cp 1
	call z, loadmsg2
	
	call PrintString ;Print Message
	
	halt

;Here is fine for data!
loadmsg		ld hl, msg
				ret
loadmsg2:		ld hl, msg2
				ret
				
msg: db 'I Work now!',255
msg2: db 'I Work now! also',255

User avatar
akuyou
Posts: 562
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Print String

Post by akuyou » Tue May 24, 2022 9:25 pm

Yes, that's what I'd recommend you use.
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Post Reply

Return to “General Z80 Programming”