17 October 2018, 21:56 | #1 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Using VPrintf
I'm trying to print a simple string to the shell. I get screens full of HçHçHç.. when I run the code below. Any idea what I'm doing wrong? TIA!
Code:
SECTION TestCLI,CODE INCDIR "F:\Amiga\_MountHD\dev\include" INCLUDE "LVOs.i" ;-- init/startup init: movem.l d1-a6,-(sp) move.l 4.w,a6 ;execbase (permanently open lib) moveq #0,d0 ;return value in d0 ;open dos.library move.l #dosName,a1 jsr _LVOOldOpenLibrary(a6) move.l d0,dosBase test: move.l dosBase,a6 move.l #text1Format,d1 move.l #text1,d2 jsr _LVOVPrintf(a6) exit: move.l 4.w,a6 ;execbase (permanently open lib) moveq #0,d0 ;return value in d0 ;close dos.library move.l dosBase,a1 jsr _LVOCloseLibrary(a6) movem.l (sp)+,d1-a6 moveq #0,d0 ;return value in d0 rts SECTION TestCLIData,DATA EVEN text1: dc.b "Just testing..",0 EVEN text1Format: dc.b "%s",0 EVEN dosName: dc.b "dos.library",0 EVEN dosBase: ds.l 1,0 |
17 October 2018, 22:16 | #2 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
You are using wrong parameters. d1 is the text to print, d2 is the formatting array.
Change your code like this: move.l #text1,d1 move.l #text1format,d2 and text1format needs to be changed to look like this: text1format dc.l arg1 ; ptr to argument 1 arg1 dc.b "%s",0 and your code should work. This is all untested so no guarantees or anything. |
17 October 2018, 22:59 | #3 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
And how about decimals, btw? If I write this: Code:
EVEN text1: dc.w 555 EVEN argv11: dc.b "%d",0 EVEN text1Format: dc.l argv11,0 |
|
17 October 2018, 23:15 | #4 |
Semi-Retired
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
|
that's weird. How I have learned it, is VPrintf(fmt, argv)
with fmt pointing to something like dc.b "my address is %08lx",10 and argv pointing to the actual value (argument) you want to be formatted into that string. so: Code:
move.l DosBase,a6 lea fmt(pc),a1 move.l a1,d1 lea argv(pc),a1 move.l a1,d2 jmp _LVOVPrintf(a6) fmt dc.b "register d0 = %08lx ; register d1 = %08lx",10 cnop 0,4 argv dc.l $deadbeef,12345678 Last edited by Hedeon; 17 October 2018 at 23:36. |
17 October 2018, 23:17 | #5 | |
Semi-Retired
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
|
Quote:
Code:
text1: dc.b "%d",0 EVEN text1format dc.w 555 Last edited by Hedeon; 17 October 2018 at 23:28. |
|
17 October 2018, 23:39 | #6 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
I would say you read the right docs, but you interpret it wrongly.
The first argument is the string to be printed. It may but does not need to contain format specifiers. The second argument points to an array. Or rather a list of values. For each format specifier in the first argument, the array has to contain a corresponding value. For %s the value must be a pointer to a string. Not the string itself. For %d the value must be a 16bit word. For %ld the value must be 32bit long word. If the array does not align with the format specifiers, all values are printed wrong. Here is a working example: |
17 October 2018, 23:44 | #7 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
Code:
test: move.l dosBase,a6 move.l #text1Format,d1 move.l #text1Values,d2 jsr _LVOVPrintf(a6) <snip> SECTION TestCLIData,DATA EVEN text1Format: dc.b "%s is %d cm wide and %d cm high",0 text1TestVal: dc.b "My window",0 EVEN text1Values: dc.l text1TestVal dc.w 288,144 |
|
17 October 2018, 23:50 | #8 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
|
|
17 October 2018, 23:52 | #9 | |
Semi-Retired
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
|
Quote:
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help with VPrintf | Nightfox | Coders. Asm / Hardware | 7 | 12 August 2016 16:41 |
|
|