This file is a direct reply to Martin Thorpe who asked how to get font graphics into a program and then onto the screen. Here is an extract from the letter sent: ******************** 'lets get straight to the point, these friends of mine only showed me how to display pics and move a bar vertically up and down the screen. What i'm having a great deal of trouble with and not having a clue where to start, is with writing a routine to display any Font on screen without using a picture with text on it. In other words using a font from a fonts disk or ripped one from someones nice demo for my own use using a routine that picks the right letter and prints it on the screen. I know that i must first lay out my font on a paint package and save as a brush but what do i do next and what order do i lay out this font on a paint package? I was hoping you could help me on this, any document or example would be appreciated. Ive written to a few coders who have sent me source code for massive intro's with scrollers, sprites and picture fading which i haven't a cat in hells chance of understanding due to me being a novice, and the books ive bought don't seem to help a great deal especially as none of them tell you about scrolling text and doing fade routines. I understand hex and binary and fairly simple code like killing the operating system etc, but it's routines using the blitter and how to make a bar move off the bottom of the screen and re-appear at the top without making the computer bomb out when it reaches the bottom, little things like that. I hope you can help me because i really want to learn this language and no not in a few days, i know it takes ages but i don't care how long it takes i will learn it eventually. Please could you send me the tutorial on Sprites that most people in your mag keep praising along with the font code/doc if you have time. Thanks... **************** Refering to the ACC index, thanks again Mike, I can refer you to the following disks/articles: ACC6 Programming The Blitter Mike Cross Screen Printer Mark Flemans ACC7+ Text Scrolling Mike Cross Various Scrollers Mike Cross ACC10 Fonts Neil Johnston Scrollers Neil Johnston ACC15 The Blitter Tutorial Raistlin ACC17 Blitter Line Drawing Tutorial TreeBeard Screen Typer Tutorial Mike Cross Negative Blitter Modulos Tutorial Raistlin ACC22 Writing Sine Scrollers Tutorial Mike Cross For the time being here is a step by step guide of what I did to get text printed on the screen from the IFF font sent to me by Martin: 1. The font is not much use in IFF format, it has to be converted into a raw data file to make the graphics more accesable: 1/ Load the font into an IFFConverter. 2/ Save the colour map as a source file. 3/ Save the font as a Bitmap file with no colour map. 4/ Use 'incbin' to get the raw data into a source file. 'incbin' includes a binary file straight into a source file when assembling. eg. IFF font file is called 'fontletters' Save as bitmap to file 'fontletters.bm' bring into a source file using the following: Letters incbin 'fontletters.bm' The font is 32 pixels wide, 31 lines high and four planes deep. The IFF file contained the letters in a vertical strip, so the raw data file created by the iffconverter will have the following format: Bitplane 1, consisting of the following: Plane1 Letter A Plane1 Letter B Plane1 Letter C " " Plane1 Letter Z Bitplane 2, consisting of the following: Plane2 Letter A Plane2 Letter B Plane2 Letter C " " Plane2 Letter Z Bitplane 3, consisting of the following: Plane3 Letter A Plane3 Letter B Plane3 Letter C " " Plane3 Letter Z Bitplane 4, consisting of the following: Plane4 Letter A Plane4 Letter B Plane4 Letter C " " Plane4 Letter Z To get the graphics for a letter to appear on the screen, plane 1 of the graphic must be copied into plane 1 of the display, plane 2 of the graphic must be copied into plane 2 of the display, plane 3 of the graphic must be copied into plane 3 of the display, plane 4 of the graphic must be copied into plane 4 of the display. To copy graphics data for a character from the raw data the start address of the graphic in each bitplane must be calculated. To calculate this proceed as follows: calculate address in 1st bitplane add size of bitplane = address in second bitplane add size of bitplane = address in third bitplane add size of bitplane = address in fourth bitplane The size of each bitplane is 832 bytes, gleaned from the IFFConverter! This was a little odd, I expected 26*31 = 806 bytes so there must be an odd character tagged on the end of the file! The font consisted only of the letters of the alphabet. To calculate the offset to the start of the graphics for any letter, proceed as follows: subtract ASCII code of letter A from the ASCII code of letter. multiply by size of 1 plane of letter graphics. Each plane of a letter consists of 31 lines of data. Each line is 32 pixels or 4 bytes wide. This makes the size of one plane of the graphics = 31x4 = 124 bytes. Summing all this up, the following fragment of code will locate the first byte of graphics data for a letter: ; d0 = ascii code of letter to locate graphics for *************************** sub.b #'A',d0 mulu #31*4,d0 byte offset add.l #Letters,d0 addr of gfx in plane1 Letters incbin fontletters.bm *************************** The screen bitplane is 320 pixels ( 40 bytes ) wide, a letter is only 32 pixels ( 4 bytes ) wide. The problem involved in copying a plane from the graphics into a plane of the display can be seen from the following: - = one byte of display * = one byte of graphic Display Bitplane --------------------------------------- --------------------------------------- --------------------------------------- --------------------------------------- --------------------------------------- Graphics Bitplane **** **** **** **** We Require ****----------------------------------- ****----------------------------------- ****----------------------------------- ****----------------------------------- --------------------------------------- To step down a line of the display, add 40 bytes! Since there are 31 lines in the graphic, this needs to be done 30 times for each plane. A suitable loop for copying one plane of a graphic into a plane of the display is: *********************** ; a0 = address of graphic data ; a1 = address in display bitplane moveq.l #30,d0 num lines -1 loop move.l (a0)+,(a1) copy line of gfx adda.l #40,a1 next line of display dbra d0,loop for all lines ************************ Note that move.l has been used to copy all four bytes from a line of graphics data in one go, for this reason this loop is only suitable for even addresses in the display! A loop such as this needs to be executed for each plane of the graphics, so it would need to be contained in a loop that updates the address of the graphic and the address of the display bitplane: ************************ ; a2 = address of 1st plane of gfx data ; a3 = address in 1st plane of display moveq.l #3,d1 num planes -1 loop2 move.l a2,a0 a0->gfx move.l a3,a1 a1->display << plane copy loop goes here >> adda.l #832,a2 a2->next gfx plane adda.l #40*256,a3 a3->next screen plane dbra d1,loop2 ************************ Bringing all the above together, a routine can be written that will copy the graphics for any given letter ( A->Z ) into the display at a given address: ************************ ; d0 = letter to draw into display ; a0 = address in display DrawLetter sub.b #'A',d0 calculate offset mulu #31*4,d0 add.l #Letters,d0 calc addr in gfx pl1 move.l d0,a2 a2->gfx address move.l a0,a3 a3->display address * Outer loop controlling bitplanes ; a2 = address of 1st plane of gfx data ; a3 = address in 1st plane of display moveq.l #3,d1 num planes -1 loop2 move.l a2,a0 a0->gfx move.l a3,a1 a1->display * Inner loop controlling lines in a bitplane ; a0 = address of graphic data ; a1 = address in display bitplane moveq.l #30,d0 num lines -1 loop move.l (a0)+,(a1) copy line of gfx adda.l #40,a1 next line of display dbra d0,loop for all lines adda.l #4*832,a2 a2->next gfx plane adda.l #40*256,a3 a3->next screen plane dbra d1,loop2 ************************ All that is required now is a routine to read letters and pass them to the above routine. An example of such a routine can be found in the accomapnying source file which also sets up the display etc. The accompanying source file also contains an equivalent Blitter routine. I am not going to cover that again here, see the last two ACC disks for details of using the Blitter. Mark.