CompuServe Thread

#OpenDiskFont()

6 messages in this thread
#47219From: Bart MathiasJun 15, 1995 2:44 PM
I wanted to specify a text font and size in a program under development. So I (successfully) open diskfont.library and save its address as DFLbase. Then I attempt to open the font, with the following code: move.l ascfont,a0 my TextAttr structure move.l DFLbase,a6 SYS OpenDiskFont(a6) move.l d0,txtfnt beq close [Followed by the rest of the program] [Then down in the data section I have this:] cnop 0,2 ascfont: dc.l fontname fntheight: dc.w 18 dc.b 0,1 ta_Style(0=normal),ta_Flags(1=on disk) fontname: dc.b 'times.font',0 cnop 0,2 I compile with CAPE2.5, and run the program from RAM: in WShell. OpenDiskFont fails, and the program closes neatly without doing anything. I have tried other fontnames. Noticing that "times.font" is not in Fonts: I tried just "times." I have also tried "topaz.font," as in the examples in RKM _Libraries_, even though there is no "topaz.font" in Fonts:. And I have tried some things that are listed as "xxx.font" in Fonts:, all to no avail. Can anyone see what I am doing wrong? Thanks for reading this. Bart Mathias
#47228From: Phillip WoollerJun 16, 1995 7:34 AM
From your code, which due to formatting problems I cannot read to well, your first move should either be a move # or the lea instruction (I prefer to use lea). Instead of getting the address of the structure, you are actually reading the first long word of the structure. I will take another look at the code and see if I spot anything else (the code has now scrolled off my screen,damn terminal emulation). Phill
#47233From: Bart MathiasJun 16, 1995 3:21 PM
> From your code, which due to formatting problems I cannot read to well Sorry about that, Phill. I write code with Memacs, and when I imported it into AutoPilot the <HT>s were all ignored, so I tried to fix it with spaces. I suspect you got both the tabs and the spaces… You saw the problem, of course. I can't believe I didn't spot that–it's the mistake I make over and over, and usually find it right away. It should certainly be the first thing I consciously look for. Two other things I was wrong about. I misinterpreted the Flag; what I need for disk fonts is xxxxxx10, so I changed the "dc.b 0,1" to "dc.b 0,2." And apparently as a result of running Fixfont, I now have a times.font file in Fonts: (I wonder where it, topaz.font, etc., etc., had disappeared to since the last time I ran Fixfont?) I just ran one quick test of the fix, and the function succeeds, although the results at the printer are still Topaz8. I guess SetFont isn't working, very likely for exactly the same reason. Thanks for the help. I'd about given up. Bart
#47229From: Phillip WoollerJun 16, 1995 7:47 AM
I couldn't see anything else wrong except you need to change the line move.l ascfont,a0 to move.l #ascfont,a0 or preferably lea ascfont,a0 Some people don't like the lea instruction because it can't be used to load a value into a data register, only address registers. What you would find if you used a debugger (codeprobe or equivalent) is that a0 is actually being set to the address of the font name (the font name address is the first long word in your textattr structure). When OpenDiskFont came to open your font it would take the first 4letters of the fontname and use that as an address, so if you were trying to open the font "times" it would then look at the address 0x74696D65 for the font name. As you won't have any memory at that address, it is no wonder it didn't work (weird you didn't get a system crash on that one). I have made that mistake in assember on 8086,68000 & 6502, so don't feel to bad 🙂 Try it, it should then work. Phill
#47240From: Jim ButterfieldJun 17, 1995 7:29 AM
>> Some people don't like the LEA instruction…. Of course, one advantage of LEA over MOVE.L # is that you get a richer set of addressing modes. In particular, programmers writing a "small code" model can do: LEA ASCFONT(PC),A0 which makes the instruction shorter and faster, and also saves you a relocation vector in the executable code. It may be that we're long past the days where we count bytes and microseconds. But when we want to get an address into a register, LEA still seems more, well, elegant. Even if it sometimes is followed by a move into a data register (darn some of those clumsy library calls!). –Jim
#47323From: Phillip WoollerJun 22, 1995 2:43 PM
I agree about using lea jim, it also helps with the problem of missing out the # (something I had problems with 6502 as well). As I only have an a500 at present (my a1200 doesn't have a big enough hard drive or enough memory for me to use as a main machine yet, also curiously my monitor is alot darker on the a1200 (have to buy a new one 🙁 )) I have to worry about clock cycles 🙁 (strange, the section in brackets there was longer than the sentence, need more sleep). I agree with elegance, the amiga may not be perfect, but it is more elegant than the pc. If you ignore some of the dodgy aspects of the OS (like bcpl hangovers and putting addresses in data registers and, and, and….) it is pretty good (and still better than coding for windows). Anyway, too much rambling (I cannot think too straight at the moment), see ya. Phill